OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::ObjectGrid Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GUI_ObjectTable.hpp>

Inheritance diagram for Slic3r::GUI::ObjectGrid:
Collaboration diagram for Slic3r::GUI::ObjectGrid:

Public Member Functions

 ObjectGrid (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxWANTS_CHARS, const wxString &name=wxASCII_STR(wxGridNameStr))
 ~ObjectGrid ()
bool OnCellLeftClick (wxGridEvent &event, int row, int col, ConfigOptionType type)
void OnRangeSelected (wxGridRangeSelectEvent &ev)
void OnColHeadLeftClick (wxGridEvent &event)
virtual void DrawColLabels (wxDC &dc, const wxArrayInt &cols)
virtual void DrawColLabel (wxDC &dc, int col)

Public Attributes

wxString input_string
wxString m_cell_data

Protected Member Functions

void OnKeyDown (wxKeyEvent &)
void OnKeyUp (wxKeyEvent &)
void OnChar (wxKeyEvent &)

Private Member Functions

 wxDECLARE_EVENT_TABLE ()
void paste_data (wxTextDataObject &text_data)

Private Attributes

wxGridBlockCoords m_selected_block

Friends

class ObjectGridTable
class ObjectTablePanel

Detailed Description

Constructor & Destructor Documentation

◆ ObjectGrid()

Slic3r::GUI::ObjectGrid::ObjectGrid ( wxWindow * parent,
wxWindowID id,
const wxPoint & pos = wxDefaultPosition,
const wxSize & size = wxDefaultSize,
long style = wxWANTS_CHARS,
const wxString & name = wxASCII_STR(wxGridNameStr) )
inline
239 :wxGrid(parent, id, pos, size, style, name)
240 {
241 }
#define style
Definition WipeTowerDialog.cpp:101

References style.

◆ ~ObjectGrid()

Slic3r::GUI::ObjectGrid::~ObjectGrid ( )
inline
243{}

Member Function Documentation

◆ DrawColLabel()

void Slic3r::GUI::ObjectGrid::DrawColLabel ( wxDC & dc,
int col )
virtual
1178{
1179 if ( GetColWidth(col) <= 0 || m_colLabelHeight <= 0 )
1180 return;
1181
1182 ObjectGridTable *table = dynamic_cast<ObjectGridTable *>(this->GetTable());
1183
1184 if (table) {
1185 ObjectGridTable::ObjectGridCol* grid_col = table->get_grid_col(col);
1186 if (grid_col->b_icon)
1187 return;
1188 ObjectGridTable::ObjectGridCol* grid_next_col = table->get_grid_col(col+1);
1189 int colLeft = GetColLeft(col);
1190 int colWidth;
1191
1192 if (grid_next_col&&grid_next_col->b_icon)
1193 colWidth = GetColWidth(col) + GetColWidth(col + 1);
1194 else
1195 colWidth = GetColWidth(col);
1196
1197 wxRect rect(colLeft, 0, colWidth, m_colLabelHeight);
1198 wxGridColumnHeaderRendererDefault render;
1199
1200 // It is reported that we need to erase the background to avoid display
1201 // artefacts, see #12055.
1202 {
1203 wxDCBrushChanger setBrush(dc, m_colLabelWin->GetBackgroundColour());
1204 wxDCPenChanger setPen(dc, *wxTRANSPARENT_PEN);
1205 dc.DrawRectangle(rect);
1206 }
1207
1208 //render.DrawBorder(*this, dc, rect);
1209
1210 int hAlign, vAlign;
1211 GetColLabelAlignment(&hAlign, &vAlign);
1212 const int orient = GetColLabelTextOrientation();
1213
1214 render.DrawLabel(*this, dc, GetColLabelValue(col), rect, hAlign, vAlign, orient);
1215 }
1216}
friend class ObjectGridTable
Definition GUI_ObjectTable.hpp:266
static Orientation orient(const Point &a, const Point &b, const Point &c)
Definition Geometry.hpp:44

References Slic3r::GUI::ObjectGridTable::ObjectGridCol::b_icon, Slic3r::GUI::ObjectGridTable::get_grid_col(), ObjectGridTable, and Slic3r::Geometry::orient().

Here is the call graph for this function:

◆ DrawColLabels()

void Slic3r::GUI::ObjectGrid::DrawColLabels ( wxDC & dc,
const wxArrayInt & cols )
virtual
1173{
1174 wxGrid::DrawColLabels( dc, cols );
1175}

◆ OnCellLeftClick()

bool Slic3r::GUI::ObjectGrid::OnCellLeftClick ( wxGridEvent & event,
int row,
int col,
ConfigOptionType type )

◆ OnChar()

void Slic3r::GUI::ObjectGrid::OnChar ( wxKeyEvent & event)
protected
1164 {
1165 auto keycode = event.GetKeyCode();
1166 if (keycode >= 0x20 && keycode <= 0x7F) {
1167 input_string = event.GetUnicodeKey();
1168 }
1169 event.Skip();
1170}
wxString input_string
Definition GUI_ObjectTable.hpp:269

References input_string.

Referenced by Slic3r::GUI::wxBEGIN_EVENT_TABLE().

Here is the caller graph for this function:

◆ OnColHeadLeftClick()

void Slic3r::GUI::ObjectGrid::OnColHeadLeftClick ( wxGridEvent & event)
916{
917 bool consumed = false;
918 int col = event.GetCol();
919
920 ObjectGridTable *table = dynamic_cast<ObjectGridTable *>(this->GetTable());
921
922 if (table) {
923 table->sort_by_col(col);
924 consumed = true;
925 }
926 if (!consumed)
927 event.Skip();
928 else
929 Refresh();
930}

References ObjectGridTable, and Slic3r::GUI::ObjectGridTable::sort_by_col().

Referenced by Slic3r::GUI::wxBEGIN_EVENT_TABLE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnKeyDown()

void Slic3r::GUI::ObjectGrid::OnKeyDown ( wxKeyEvent & event)
protected
933{
934 // see include/wx/defs.h enum wxKeyCode
935 int keyCode = event.GetKeyCode();
936 int ctrlMask = wxMOD_CONTROL;
937 int shiftMask = wxMOD_SHIFT;
938 // Coordinates of the selected block to copy to clipboard.
939 wxGridBlockCoords selection;
940 wxTextDataObject text_data;
941
942 if ((event.GetModifiers() & ctrlMask) != 0) {
943 // CTRL is pressed
944 switch (keyCode) {
945 case 'c':
946 case 'C':
947 {
948 // Check if we have any selected blocks and if we don't
949 // have too many of them.
950 const wxGridBlocks blocks = GetSelectedBlocks();
951 wxGridBlocks::iterator iter = blocks.begin();
952 if (iter == blocks.end())
953 {
954 // No selection, copy just the current cell.
955 if (m_currentCellCoords == wxGridNoCellCoords)
956 {
957 // But we don't even have it -- nothing to do then.
958 event.Skip();
959 break;
960 }
961
962 selection = wxGridBlockCoords(GetGridCursorRow(),
963 GetGridCursorCol(),
964 GetGridCursorRow(),
965 GetGridCursorCol());
966 }
967 else // We do have at least one selected block.
968 {
969 selection = *blocks.begin();
970
971 }
972 m_selected_block = selection;
973
974 ObjectGridTable* table = dynamic_cast<ObjectGridTable*>(this->GetTable());
975
976 if (GetGridCursorCol() == ObjectGridTable::col_printable ||
977 GetGridCursorCol() == ObjectGridTable::col_enable_support) {
978 m_cell_data = table->GetValueAsBool(GetGridCursorRow(), GetGridCursorCol()) ? wxT("1") : wxT("0");
979 }
980 else if (GetGridCursorCol() == ObjectGridTable::col_filaments) {
981 m_cell_data = table->GetValue(GetGridCursorRow(), GetGridCursorCol());
982 }
983 else {
984 m_cell_data = table->GetValue(GetGridCursorRow(), GetGridCursorCol());
985 }
986
987 break;
988 }
989
990 case 'v':
991 case 'V': {
992 wxTheClipboard->GetData(text_data);
993
994 if (!m_cell_data.empty()) {
995 text_data.SetText(m_cell_data);
996 }
997
998 paste_data(text_data);
999 break;
1000 }
1001 case 'f':
1002 case 'F':
1003 //TODO: search
1004 break;
1005
1006 case 'z':
1007 case 'Z':
1008 //TODO:
1009 break;
1010
1011 default:
1012 event.Skip();
1013 }
1014 }
1015 event.Skip();
1016}
@ col_printable
Definition GUI_ObjectTable.hpp:315
@ col_filaments
Definition GUI_ObjectTable.hpp:320
@ col_enable_support
Definition GUI_ObjectTable.hpp:328
wxGridBlockCoords m_selected_block
Definition GUI_ObjectTable.hpp:279
wxString m_cell_data
Definition GUI_ObjectTable.hpp:270
void paste_data(wxTextDataObject &text_data)
Definition GUI_ObjectTable.cpp:1018

References Slic3r::GUI::ObjectGridTable::col_enable_support, Slic3r::GUI::ObjectGridTable::col_filaments, Slic3r::GUI::ObjectGridTable::col_printable, Slic3r::GUI::ObjectGridTable::GetValue(), Slic3r::GUI::ObjectGridTable::GetValueAsBool(), m_cell_data, m_selected_block, ObjectGridTable, and paste_data().

Referenced by Slic3r::GUI::wxBEGIN_EVENT_TABLE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnKeyUp()

void Slic3r::GUI::ObjectGrid::OnKeyUp ( wxKeyEvent & event)
protected
1160{
1161 event.Skip();
1162}

Referenced by Slic3r::GUI::wxBEGIN_EVENT_TABLE().

Here is the caller graph for this function:

◆ OnRangeSelected()

void Slic3r::GUI::ObjectGrid::OnRangeSelected ( wxGridRangeSelectEvent & ev)
911{
912 ev.Skip();
913}

Referenced by Slic3r::GUI::wxBEGIN_EVENT_TABLE().

Here is the caller graph for this function:

◆ paste_data()

void Slic3r::GUI::ObjectGrid::paste_data ( wxTextDataObject & text_data)
private
1019{
1020 wxString buf = text_data.GetText();
1021 int clip_size = buf.size();
1022
1023 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", clip_size %1%, pasted_data %2%") %clip_size %buf;
1024 if (clip_size <= 0)
1025 return;
1026 int src_top_row = m_selected_block.GetTopRow();
1027 int src_bottom_row = m_selected_block.GetBottomRow();
1028 int src_left_col = m_selected_block.GetLeftCol();
1029 int src_right_col = m_selected_block.GetRightCol();
1030 int src_row_cnt = src_bottom_row - src_top_row + 1;
1031 int src_col_cnt = src_right_col -src_left_col + 1;
1032
1033 const wxGridBlocks blocks = GetSelectedBlocks();
1034 wxGridBlocks::iterator iter = blocks.begin();
1035 wxGridBlockCoords selection;
1036 if (iter == blocks.end())
1037 {
1038 // No selection, copy just the current cell.
1039 if (m_currentCellCoords == wxGridNoCellCoords)
1040 {
1041 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", no selection and no current , can not paste");
1042 return;
1043 }
1044
1045 selection = wxGridBlockCoords(GetGridCursorRow(),
1046 GetGridCursorCol(),
1047 GetGridCursorRow(),
1048 GetGridCursorCol());
1049 }
1050 else // We do have at least one selected block.
1051 {
1052 selection = *blocks.begin();
1053 }
1054
1055 int dst_top_row = selection.GetTopRow();
1056 int dst_bottom_row = selection.GetBottomRow();
1057 int dst_left_col = selection.GetLeftCol();
1058 int dst_right_col = selection.GetRightCol();
1059 int dst_row_cnt = dst_bottom_row - dst_top_row + 1;
1060 int dst_col_cnt = dst_right_col - dst_left_col + 1;
1061 wxArrayString string_array;
1062
1063 auto split = [](wxString& source, wxArrayString& array) {
1064 wxString temp = source;
1065 wxChar split_char1 = '\t';
1066 wxChar split_char2 = '\n';
1067 bool finished = false;
1068 while (!finished && (temp.Length() > 0)) {
1069 int pos = temp.find(split_char2);
1070 if (pos == 0)
1071 {
1072 temp = temp.substr(1);
1073 continue;
1074 }
1075
1076 wxString temp_line;
1077 if (pos == wxString::npos)
1078 {
1079 temp_line = temp;
1080 finished = true;
1081 }
1082 else
1083 {
1084 temp_line = temp.substr(0, pos);
1085 temp = temp.substr(pos+1);
1086 }
1087
1088 while(true) {
1089 pos = temp_line.find(split_char1);
1090 if (pos == 0)
1091 {
1092 temp_line = temp_line.substr(1);
1093 continue;
1094 }
1095 else if (pos == wxString::npos)
1096 {
1097 if (temp_line.Length() > 0)
1098 {
1099 array.push_back(temp_line.Trim());
1100 break;
1101 }
1102 }
1103 else
1104 {
1105 array.push_back(temp_line.substr(0, pos));
1106 temp_line = temp_line.substr(pos+1);
1107 }
1108 }
1109 }
1110 };
1111
1112 ObjectGridTable* grid_table = dynamic_cast <ObjectGridTable * >(GetTable());
1113 if ((src_row_cnt == 1) && (src_col_cnt == 1))
1114 {
1115 if ((dst_col_cnt != 1) || (dst_left_col != src_left_col)) {
1116 wxLogWarning(_L("One cell can only be copied to one or more cells in the same column."));
1117 }
1118 else {
1119 split(buf, string_array);
1120 wxString source_string = string_array[0];
1121 if (string_array.GetCount() <= 0) {
1122 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(", can not split pasted data %1%") % buf;
1123 return;
1124 }
1125 for (int i = 0; i < dst_row_cnt; i++)
1126 {
1127 if (!this->IsReadOnly(dst_top_row + i, dst_left_col)) {
1128 grid_table->SetValue(dst_top_row + i, dst_left_col, source_string);
1129 grid_table->OnCellValueChanged(dst_top_row + i, dst_left_col);
1130 }
1131 }
1132 }
1133
1134 }
1135 else {
1136 wxLogWarning(_L("Copying multiple cells is not supported."));
1137 /*if ((src_col_cnt != 1) || (dst_left_col != src_left_col))
1138 wxLogWarning(_L("Copying multiple columns is not supported."));
1139 else {
1140 split(buf, string_array);
1141 int count = string_array.GetCount();
1142 if ((count <= 0) || (count != src_row_cnt* src_col_cnt )){
1143 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(", can not split pasted data %1%, count %2%, src_row_cnt %3%, src_col_cnt %4%")%buf %count %src_row_cnt %src_col_cnt;
1144 return;
1145 }
1146 for ( int i = 0; i < src_row_cnt; i++ )
1147 for ( int j = 0; j < src_col_cnt; j++ )
1148 {
1149 if (!this->IsReadOnly(dst_top_row+i, dst_left_col+j)) {
1150 grid_table->SetValue(dst_top_row+i, dst_left_col+j, string_array[i*src_col_cnt+j]);
1151 grid_table->OnCellValueChanged(dst_top_row+i, dst_left_col+j);
1152 }
1153 }
1154 }*/
1155 }
1156 this->ForceRefresh();
1157}
#define _L(s)
Definition OBJ.cpp:34
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16

References _L, m_selected_block, ObjectGridTable, Slic3r::GUI::ObjectGridTable::OnCellValueChanged(), and Slic3r::GUI::ObjectGridTable::SetValue().

Referenced by OnKeyDown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wxDECLARE_EVENT_TABLE()

Slic3r::GUI::ObjectGrid::wxDECLARE_EVENT_TABLE ( )
private

◆ ObjectGridTable

friend class ObjectGridTable
friend

◆ ObjectTablePanel

friend class ObjectTablePanel
friend

References ObjectTablePanel.

Referenced by ObjectTablePanel.

Member Data Documentation

◆ input_string

wxString Slic3r::GUI::ObjectGrid::input_string

◆ m_cell_data

wxString Slic3r::GUI::ObjectGrid::m_cell_data

Referenced by OnKeyDown().

◆ m_selected_block

wxGridBlockCoords Slic3r::GUI::ObjectGrid::m_selected_block
private

Referenced by OnKeyDown(), and paste_data().


The documentation for this class was generated from the following files: