FIX:add few extra function for objecttable

1.supports filament sort
2.printable supports batch selection

Change-Id: I231b8add4f43550f4854796cfd804f86251604e7
This commit is contained in:
tao wang 2022-09-06 14:21:06 +08:00 committed by Lane.Wei
parent b8846f675f
commit 77e4599c4a
2 changed files with 71 additions and 17 deletions

View file

@ -540,6 +540,29 @@ wxString GridCellSupportEditor::ms_stringValues[2] = { wxT(""), wxT("") };
void GridCellSupportEditor::DoActivate(int row, int col, wxGrid* grid) void GridCellSupportEditor::DoActivate(int row, int col, wxGrid* grid)
{ {
ObjectGrid* local_table = dynamic_cast<ObjectGrid*>(grid);
wxGridBlocks cell_array = grid->GetSelectedBlocks();
auto left_col = cell_array.begin()->GetLeftCol();
auto right_col = cell_array.begin()->GetRightCol();
auto top_row = cell_array.begin()->GetTopRow();
auto bottom_row = cell_array.begin()->GetBottomRow();
if ((left_col == right_col) &&
(top_row == bottom_row)) {
wxGridCellBoolEditor::DoActivate(row, col, grid);
grid->SelectBlock(row, col, row, col, true);
return;
}
else if( (left_col == right_col) &&
(top_row != bottom_row)){
for (auto i = top_row; i <= bottom_row; i++) {
//grid->GetTable()->SetValueAsBool(i, left_col, false);
wxGridCellBoolEditor::DoActivate(i, left_col, grid);
}
}
wxGridCellBoolEditor::DoActivate(row, col, grid); wxGridCellBoolEditor::DoActivate(row, col, grid);
grid->SelectBlock(row, col, row, col, true); grid->SelectBlock(row, col, row, col, true);
} }
@ -724,11 +747,13 @@ wxBEGIN_EVENT_TABLE( ObjectGrid, wxGrid )
EVT_KEY_UP( ObjectGrid::OnKeyUp ) EVT_KEY_UP( ObjectGrid::OnKeyUp )
EVT_CHAR ( ObjectGrid::OnChar ) EVT_CHAR ( ObjectGrid::OnChar )
EVT_GRID_LABEL_LEFT_CLICK ( ObjectGrid::OnColHeadLeftClick ) EVT_GRID_LABEL_LEFT_CLICK ( ObjectGrid::OnColHeadLeftClick )
EVT_GRID_RANGE_SELECTED(ObjectGrid::OnRangeSelected)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
bool ObjectGrid::OnCellLeftClick(wxGridEvent& event, int row, int col, ConfigOptionType type) bool ObjectGrid::OnCellLeftClick(wxGridEvent& event, int row, int col, ConfigOptionType type)
{ {
input_string = wxEmptyString; input_string = wxEmptyString;
if (type != coBool) if (type != coBool)
return false; return false;
@ -814,6 +839,11 @@ bool ObjectGrid::OnCellLeftClick(wxGridEvent& event, int row, int col, ConfigOpt
return consumed; return consumed;
} }
void ObjectGrid::OnRangeSelected(wxGridRangeSelectEvent& ev)
{
ev.Skip();
}
void ObjectGrid::OnColHeadLeftClick(wxGridEvent& event) void ObjectGrid::OnColHeadLeftClick(wxGridEvent& event)
{ {
bool consumed = false; bool consumed = false;
@ -1795,7 +1825,7 @@ void ObjectGridTable::init_cols(ObjectGrid *object_grid)
m_col_data.push_back(col); m_col_data.push_back(col);
//object layer height //object layer height
col = new ObjectGridCol(coFloat, "layer_height", L("Quality"), true, false, true, true, wxALIGN_CENTRE); col = new ObjectGridCol(coFloat, "layer_height", L("Quality"), true, false, true, true, wxALIGN_LEFT);
col->size = object_grid->GetTextExtent(L("Layer height")).x - 28; col->size = object_grid->GetTextExtent(L("Layer height")).x - 28;
m_col_data.push_back(col); m_col_data.push_back(col);
@ -2325,6 +2355,22 @@ void ObjectGridTable::sort_by_col(int col)
m_sort_col = col; m_sort_col = col;
} }
} }
else if (col == col_filaments) {
if (m_sort_col == col) {
auto sort_func = [](ObjectGridRow* row1, ObjectGridRow* row2) {
return (std::to_string(row2->filaments.value).compare(std::to_string(row1->filaments.value)) < 0);
};
sort_row_data(sort_func);
m_sort_col = -1;
}
else {
auto sort_func = [](ObjectGridRow* row1, ObjectGridRow* row2) {
return (std::to_string(row1->filaments.value).compare(std::to_string(row2->filaments.value)) < 0);
};
sort_row_data(sort_func);
m_sort_col = col;
}
}
//else if (col == col_assemble_name) { //else if (col == col_assemble_name) {
// if (m_sort_col == col) { // if (m_sort_col == col) {
// compare_row_func sort_func = [](ObjectGridRow* row1, ObjectGridRow* row2) { // compare_row_func sort_func = [](ObjectGridRow* row1, ObjectGridRow* row2) {
@ -2789,10 +2835,10 @@ void ObjectTablePanel::load_data()
m_object_grid->SetColLabelValue(ObjectGridTable::col_printable, _L("Printable")); m_object_grid->SetColLabelValue(ObjectGridTable::col_printable, _L("Printable"));
m_object_grid->SetColLabelValue(ObjectGridTable::col_printable_reset, ""); m_object_grid->SetColLabelValue(ObjectGridTable::col_printable_reset, "");
m_object_grid->SetColLabelValue(ObjectGridTable::col_plate_index, wxString::Format("%S%S", _L("Plate"), _L("(Sort)"))); m_object_grid->SetColLabelValue(ObjectGridTable::col_plate_index, wxString::Format("%S%S", _L("Plate"), wxString::FromUTF8("\xe2\x87\x85\x20")));
/*m_object_grid->SetColLabelValue(ObjectGridTable::col_assemble_name, L("Module"));*/ /*m_object_grid->SetColLabelValue(ObjectGridTable::col_assemble_name, L("Module"));*/
m_object_grid->SetColLabelValue(ObjectGridTable::col_name, wxString::Format("%S%S", _L("Name"), _L("(Sort)"))); m_object_grid->SetColLabelValue(ObjectGridTable::col_name, wxString::Format("%S%S", _L("Name"), wxString::FromUTF8("\xe2\x87\x85\x20")));
m_object_grid->SetColLabelValue(ObjectGridTable::col_filaments, _L("Filament")); m_object_grid->SetColLabelValue(ObjectGridTable::col_filaments, wxString::Format("%S%S", _L("Filament"), wxString::FromUTF8("\xe2\x87\x85\x20")));
m_object_grid->SetColLabelValue(ObjectGridTable::col_filaments_reset, ""); m_object_grid->SetColLabelValue(ObjectGridTable::col_filaments_reset, "");
m_object_grid->SetColLabelValue(ObjectGridTable::col_layer_height, _L("Layer height")); m_object_grid->SetColLabelValue(ObjectGridTable::col_layer_height, _L("Layer height"));
m_object_grid->SetColLabelValue(ObjectGridTable::col_layer_height_reset, ""); m_object_grid->SetColLabelValue(ObjectGridTable::col_layer_height_reset, "");
@ -2980,10 +3026,14 @@ void ObjectTablePanel::load_data()
m_object_grid->SetColSize(i, FromDIP(28)); m_object_grid->SetColSize(i, FromDIP(28));
break; break;
case ObjectGridTable::col_wall_loops: case ObjectGridTable::col_wall_loops: {
m_object_grid->SetColSize(i, m_object_grid->GetColSize(i) - FromDIP(28)); auto width = m_object_grid->GetColSize(i) - FromDIP(28);
if (width < m_object_grid->GetTextExtent(("000.00")).x) {
width = m_object_grid->GetTextExtent(("000.00")).x;
}
m_object_grid->SetColSize(i, width);
break; break;
}
case ObjectGridTable::col_wall_loops_reset: case ObjectGridTable::col_wall_loops_reset:
m_object_grid->SetColSize(i, FromDIP(28)); m_object_grid->SetColSize(i, FromDIP(28));
break; break;
@ -3128,13 +3178,10 @@ void ObjectTablePanel::OnCellValueChanged( wxGridEvent& ev )
void ObjectTablePanel::OnRangeSelected( wxGridRangeSelectEvent& ev ) void ObjectTablePanel::OnRangeSelected( wxGridRangeSelectEvent& ev )
{ {
int left_col = ev.GetLeftCol(); range_select_left_col = ev.GetLeftCol();
int right_col = ev.GetRightCol(); range_select_right_col = ev.GetRightCol();
int top_row = ev.GetTopRow(); range_select_top_row = ev.GetTopRow();
int bottom_row = ev.GetBottomRow(); range_select_bottom_row = ev.GetBottomRow();
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format("cell from (%1%, %2%) to (%3%, %4%) selected") %top_row %left_col %bottom_row %right_col;
ev.Skip(); ev.Skip();
} }

View file

@ -242,6 +242,7 @@ public:
}*/ }*/
bool OnCellLeftClick(wxGridEvent& event, int row, int col, ConfigOptionType type); bool OnCellLeftClick(wxGridEvent& event, int row, int col, ConfigOptionType type);
void OnRangeSelected(wxGridRangeSelectEvent& ev);
void OnColHeadLeftClick(wxGridEvent& event); void OnColHeadLeftClick(wxGridEvent& event);
virtual void DrawColLabels( wxDC& dc, const wxArrayInt& cols ); virtual void DrawColLabels( wxDC& dc, const wxArrayInt& cols );
@ -253,7 +254,6 @@ public:
wxString input_string; wxString input_string;
wxString m_cell_data; wxString m_cell_data;
protected: protected:
//void OnSize( wxSizeEvent& ); //void OnSize( wxSizeEvent& );
void OnKeyDown( wxKeyEvent& ); void OnKeyDown( wxKeyEvent& );
@ -522,8 +522,9 @@ public:
int m_icon_col_width{ 0 }; int m_icon_col_width{ 0 };
int m_icon_row_height{ 0 }; int m_icon_row_height{ 0 };
private:
ObjectTablePanel* m_panel{ nullptr }; ObjectTablePanel* m_panel{ nullptr };
private:
std::vector<ObjectGridRow*> m_grid_data; std::vector<ObjectGridRow*> m_grid_data;
std::vector<ObjectGridCol*> m_col_data; std::vector<ObjectGridCol*> m_col_data;
bool m_data_valid{false}; bool m_data_valid{false};
@ -547,6 +548,12 @@ private:
//the main panel //the main panel
class ObjectTablePanel : public wxPanel class ObjectTablePanel : public wxPanel
{ {
public:
int range_select_left_col;
int range_select_right_col;
int range_select_top_row;
int range_select_bottom_row;
void OnCellLeftClick( wxGridEvent& ); void OnCellLeftClick( wxGridEvent& );
void OnRowSize( wxGridSizeEvent& ); void OnRowSize( wxGridSizeEvent& );
void OnColSize( wxGridSizeEvent& ); void OnColSize( wxGridSizeEvent& );