Some code review for avoid use of OptionsGroup
This commit is contained in:
parent
51b18fddeb
commit
79a89c4c8f
2 changed files with 77 additions and 74 deletions
|
@ -21,70 +21,87 @@ namespace GUI
|
||||||
ObjectLayers::ObjectLayers(wxWindow* parent) :
|
ObjectLayers::ObjectLayers(wxWindow* parent) :
|
||||||
OG_Settings(parent, true)
|
OG_Settings(parent, true)
|
||||||
{
|
{
|
||||||
m_og->label_width = 1;
|
m_grid_sizer = new wxFlexGridSizer(3, 5, 5); // "Min Z", "Max Z", "Layer height" & buttons sizer
|
||||||
m_og->set_grid_vgap(5);
|
m_grid_sizer->SetFlexibleDirection(wxHORIZONTAL);
|
||||||
|
|
||||||
m_og->m_on_change = std::bind(&ObjectLayers::on_change, this, std::placeholders::_1, std::placeholders::_2);
|
|
||||||
|
|
||||||
// Legend for object layers
|
// Legend for object layers
|
||||||
Line line = Line{ "", "" };
|
|
||||||
|
|
||||||
ConfigOptionDef def;
|
|
||||||
def.label = "";
|
|
||||||
def.gui_type = "legend";
|
|
||||||
def.type = coString;
|
|
||||||
def.width = field_width;
|
|
||||||
|
|
||||||
for (const std::string col : { "Min Z", "Max Z", "Layer height" }) {
|
for (const std::string col : { "Min Z", "Max Z", "Layer height" }) {
|
||||||
def.set_default_value(new ConfigOptionString{ col });
|
auto temp = new wxStaticText(m_parent, wxID_ANY, _(L(col)), wxDefaultPosition, /*size*/wxDefaultSize, wxST_ELLIPSIZE_MIDDLE);
|
||||||
std::string label = boost::algorithm::replace_all_copy(col, " ", "_");
|
temp->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
||||||
boost::algorithm::to_lower(label);
|
temp->SetBackgroundStyle(wxBG_STYLE_PAINT);
|
||||||
line.append_option(Option(def, label + "_legend"));
|
temp->SetFont(wxGetApp().bold_font());
|
||||||
|
|
||||||
m_legends.push_back(label + "_legend");
|
m_grid_sizer->Add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_og->append_line(line);
|
m_og->sizer->Clear(true);
|
||||||
|
m_og->sizer->Add(m_grid_sizer, 0, wxEXPAND | wxALL, wxOSX ? 0 : 5);
|
||||||
|
|
||||||
m_bmp_delete = ScalableBitmap(parent, "remove_copies"/*"cross"*/);
|
m_bmp_delete = ScalableBitmap(parent, "remove_copies"/*"cross"*/);
|
||||||
m_bmp_add = ScalableBitmap(parent, "add_copies");
|
m_bmp_add = ScalableBitmap(parent, "add_copies");
|
||||||
}
|
}
|
||||||
|
|
||||||
static Line create_new_layer(const t_layer_config_ranges::value_type& layer, const int idx)
|
wxSizer* ObjectLayers::create_layer_without_buttons(const t_layer_config_ranges::value_type& layer)
|
||||||
{
|
{
|
||||||
Line line = Line{ "", "" };
|
auto size = wxSize(field_width * em_unit(m_parent), wxDefaultCoord);
|
||||||
ConfigOptionDef def;
|
|
||||||
def.label = "";
|
|
||||||
def.gui_type = "";
|
|
||||||
def.type = coFloat;
|
|
||||||
def.width = field_width;
|
|
||||||
|
|
||||||
std::string label = (boost::format("min_z_%d") % idx).str();
|
// Add control for the "Min Z"
|
||||||
def.set_default_value(new ConfigOptionFloat(layer.first.first));
|
wxString text_value = double_to_string(layer.first.first);
|
||||||
line.append_option(Option(def, label));
|
auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, wxTE_PROCESS_ENTER);
|
||||||
|
temp->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
||||||
|
|
||||||
label = (boost::format("max_z_%d") % idx).str();
|
temp->Bind(wxEVT_TEXT_ENTER, ([this, temp](wxEvent& e)
|
||||||
def.set_default_value(new ConfigOptionFloat(layer.first.second));
|
{
|
||||||
line.append_option(Option(def, label));
|
|
||||||
|
|
||||||
label = (boost::format("layer_height_%d") % idx).str();
|
}), temp->GetId());
|
||||||
def.set_default_value(new ConfigOptionFloat(layer.second.option("layer_height")->getFloat()));
|
|
||||||
line.append_option(Option(def, label));
|
|
||||||
|
|
||||||
return line;
|
temp->Bind(wxEVT_KILL_FOCUS, ([this, temp](wxEvent& e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}), temp->GetId());
|
||||||
|
|
||||||
|
|
||||||
|
temp->Bind(wxEVT_CHAR, ([temp](wxKeyEvent& event)
|
||||||
|
{
|
||||||
|
// select all text using Ctrl+A
|
||||||
|
if (wxGetKeyState(wxKeyCode('A')) && wxGetKeyState(WXK_CONTROL))
|
||||||
|
temp->SetSelection(-1, -1); //select all
|
||||||
|
event.Skip();
|
||||||
|
}));
|
||||||
|
|
||||||
|
m_grid_sizer->Add(temp);
|
||||||
|
|
||||||
|
// Add control for the "Max Z"
|
||||||
|
text_value = double_to_string(layer.first.second);
|
||||||
|
temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, wxTE_PROCESS_ENTER);
|
||||||
|
temp->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
||||||
|
|
||||||
|
m_grid_sizer->Add(temp);
|
||||||
|
|
||||||
|
// Add control for the "Layer height"
|
||||||
|
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
|
||||||
|
text_value = double_to_string(layer.second.option("layer_height")->getFloat());
|
||||||
|
temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, wxTE_PROCESS_ENTER);
|
||||||
|
temp->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
||||||
|
sizer->Add(temp);
|
||||||
|
|
||||||
|
m_grid_sizer->Add(sizer);
|
||||||
|
|
||||||
|
return sizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectLayers::create_layers_list()
|
void ObjectLayers::create_layers_list()
|
||||||
{
|
{
|
||||||
for (const auto layer : m_object->layer_config_ranges)
|
for (const auto layer : m_object->layer_config_ranges)
|
||||||
{
|
{
|
||||||
auto create_btns = [this, layer](wxWindow* parent) {
|
auto sizer = create_layer_without_buttons(layer);
|
||||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
||||||
|
|
||||||
|
wxWindow* parent = m_parent;
|
||||||
auto del_btn = new ScalableButton(parent, wxID_ANY, m_bmp_delete);
|
auto del_btn = new ScalableButton(parent, wxID_ANY, m_bmp_delete);
|
||||||
del_btn->SetToolTip(_(L("Remove layer")));
|
del_btn->SetToolTip(_(L("Remove layer")));
|
||||||
|
|
||||||
sizer->Add(del_btn, 0, wxRIGHT, em_unit(parent));
|
sizer->Add(del_btn, 0, wxRIGHT | wxLEFT, em_unit(parent));
|
||||||
|
|
||||||
del_btn->Bind(wxEVT_BUTTON, [this, layer](wxEvent &event) {
|
del_btn->Bind(wxEVT_BUTTON, [this, layer](wxEvent &event) {
|
||||||
wxGetApp().obj_list()->del_layer_range(layer.first);
|
wxGetApp().obj_list()->del_layer_range(layer.first);
|
||||||
|
@ -98,13 +115,6 @@ void ObjectLayers::create_layers_list()
|
||||||
add_btn->Bind(wxEVT_BUTTON, [this, layer](wxEvent &event) {
|
add_btn->Bind(wxEVT_BUTTON, [this, layer](wxEvent &event) {
|
||||||
wxGetApp().obj_list()->add_layer_range(layer.first);
|
wxGetApp().obj_list()->add_layer_range(layer.first);
|
||||||
});
|
});
|
||||||
|
|
||||||
return sizer;
|
|
||||||
};
|
|
||||||
|
|
||||||
Line line = create_new_layer(layer, m_og->get_grid_sizer()->GetEffectiveRowsCount()-1);
|
|
||||||
line.append_widget(create_btns);
|
|
||||||
m_og->append_line(line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +128,7 @@ void ObjectLayers::create_layer(int id)
|
||||||
id--;
|
id--;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_og->append_line(create_new_layer(*layer_range, m_og->get_grid_sizer()->GetEffectiveRowsCount()-1));
|
create_layer_without_buttons(*layer_range);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectLayers::update_layers_list()
|
void ObjectLayers::update_layers_list()
|
||||||
|
@ -140,19 +150,17 @@ void ObjectLayers::update_layers_list()
|
||||||
|
|
||||||
// Delete all controls from options group except of the legends
|
// Delete all controls from options group except of the legends
|
||||||
|
|
||||||
auto grid_sizer = m_og->get_grid_sizer();
|
const int cols = m_grid_sizer->GetEffectiveColsCount();
|
||||||
const int cols = grid_sizer->GetEffectiveColsCount();
|
const int rows = m_grid_sizer->GetEffectiveRowsCount();
|
||||||
const int rows = grid_sizer->GetEffectiveRowsCount();
|
|
||||||
for (int idx = cols*rows-1; idx >= cols; idx--) {
|
for (int idx = cols*rows-1; idx >= cols; idx--) {
|
||||||
wxSizerItem* t = grid_sizer->GetItem(idx);
|
wxSizerItem* t = m_grid_sizer->GetItem(idx);
|
||||||
if (t->IsSizer())
|
if (t->IsSizer())
|
||||||
t->GetSizer()->Clear(true);
|
t->GetSizer()->Clear(true);
|
||||||
grid_sizer->Remove(idx);
|
else
|
||||||
|
t->DeleteWindows();
|
||||||
|
m_grid_sizer->Remove(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_og->clear_fields_except_of(m_legends);
|
|
||||||
|
|
||||||
|
|
||||||
// Add new control according to the selected item
|
// Add new control according to the selected item
|
||||||
|
|
||||||
if (type & itLayerRoot)
|
if (type & itLayerRoot)
|
||||||
|
@ -177,10 +185,5 @@ void ObjectLayers::msw_rescale()
|
||||||
m_bmp_add.msw_rescale();
|
m_bmp_add.msw_rescale();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectLayers::on_change(t_config_option_key opt_key, const boost::any& value)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} //namespace GUI
|
} //namespace GUI
|
||||||
} //namespace Slic3r
|
} //namespace Slic3r
|
|
@ -18,19 +18,19 @@ class ObjectLayers : public OG_Settings
|
||||||
ScalableBitmap m_bmp_add;
|
ScalableBitmap m_bmp_add;
|
||||||
ModelObject* m_object {nullptr};
|
ModelObject* m_object {nullptr};
|
||||||
|
|
||||||
std::vector<std::string> m_legends;
|
wxFlexGridSizer* m_grid_sizer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ObjectLayers(wxWindow* parent);
|
ObjectLayers(wxWindow* parent);
|
||||||
~ObjectLayers() {}
|
~ObjectLayers() {}
|
||||||
|
|
||||||
void create_layers_list();
|
wxSizer* create_layer_without_buttons(const std::map<std::pair<coordf_t, coordf_t>, DynamicPrintConfig>::value_type& layer);
|
||||||
void create_layer(int id);
|
void create_layer(int id);
|
||||||
|
void create_layers_list();
|
||||||
void update_layers_list();
|
void update_layers_list();
|
||||||
|
|
||||||
void UpdateAndShow(const bool show) override;
|
void UpdateAndShow(const bool show) override;
|
||||||
void msw_rescale();
|
void msw_rescale();
|
||||||
void on_change(t_config_option_key opt_key, const boost::any& value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Reference in a new issue