Refactoring in class BedShapePanel

This commit is contained in:
Enrico Turri 2019-07-09 13:33:15 +02:00
parent 36049788ac
commit e8461f65df
2 changed files with 63 additions and 64 deletions

View File

@ -54,6 +54,7 @@ void BedShapeDialog::on_dpi_changed(const wxRect &suggested_rect)
void BedShapePanel::build_panel(ConfigOptionPoints* default_pt) void BedShapePanel::build_panel(ConfigOptionPoints* default_pt)
{ {
auto sbsizer = new wxStaticBoxSizer(wxVERTICAL, this, _(L("Shape"))); auto sbsizer = new wxStaticBoxSizer(wxVERTICAL, this, _(L("Shape")));
sbsizer->GetStaticBox()->SetFont(wxGetApp().bold_font());
// shape options // shape options
m_shape_options_book = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, m_shape_options_book = new wxChoicebook(this, wxID_ANY, wxDefaultPosition,
@ -89,7 +90,7 @@ void BedShapePanel::build_panel(ConfigOptionPoints* default_pt)
Line line{ "", "" }; Line line{ "", "" };
line.full_width = 1; line.full_width = 1;
line.widget = [this](wxWindow* parent) { line.widget = [this](wxWindow* parent) {
auto shape_btn = new wxButton(parent, wxID_ANY, _(L("Load shape from STL..."))); wxButton* shape_btn = new wxButton(parent, wxID_ANY, _(L("Load shape from STL...")));
wxSizer* shape_sizer = new wxBoxSizer(wxHORIZONTAL); wxSizer* shape_sizer = new wxBoxSizer(wxHORIZONTAL);
shape_sizer->Add(shape_btn, 1, wxEXPAND); shape_sizer->Add(shape_btn, 1, wxEXPAND);
@ -134,9 +135,8 @@ void BedShapePanel::build_panel(ConfigOptionPoints* default_pt)
// Create a panel for a rectangular / circular / custom bed shape. // Create a panel for a rectangular / circular / custom bed shape.
ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(const wxString& title) ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(const wxString& title)
{ {
auto panel = new wxPanel(m_shape_options_book); wxPanel* panel = new wxPanel(m_shape_options_book);
ConfigOptionsGroupShp optgroup; ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(panel, _(L("Settings")));
optgroup = std::make_shared<ConfigOptionsGroup>(panel, _(L("Settings")));
optgroup->label_width = 10; optgroup->label_width = 10;
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
@ -310,15 +310,13 @@ void BedShapePanel::update_shape()
// Loads an stl file, projects it to the XY plane and calculates a polygon. // Loads an stl file, projects it to the XY plane and calculates a polygon.
void BedShapePanel::load_stl() void BedShapePanel::load_stl()
{ {
auto dialog = new wxFileDialog(this, _(L("Choose a file to import bed shape from (STL/OBJ/AMF/3MF/PRUSA):")), "", "", wxFileDialog dialog(this, _(L("Choose a file to import bed shape from (STL/OBJ/AMF/3MF/PRUSA):")), "", "",
file_wildcards(FT_MODEL), wxFD_OPEN | wxFD_FILE_MUST_EXIST); file_wildcards(FT_MODEL), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (dialog->ShowModal() != wxID_OK) { if (dialog.ShowModal() != wxID_OK)
dialog->Destroy();
return; return;
}
wxArrayString input_file; wxArrayString input_file;
dialog->GetPaths(input_file); dialog.GetPaths(input_file);
dialog->Destroy();
std::string file_name = input_file[0].ToUTF8().data(); std::string file_name = input_file[0].ToUTF8().data();
@ -327,9 +325,8 @@ void BedShapePanel::load_stl()
model = Model::read_from_file(file_name); model = Model::read_from_file(file_name);
} }
catch (std::exception &e) { catch (std::exception &e) {
auto msg = _(L("Error!")) + " " + file_name + " : " + e.what() + "."; show_error(this, _(L("Error! Invalid model")));
show_error(this, msg); return;
exit(1);
} }
auto mesh = model.mesh(); auto mesh = model.mesh();

View File

@ -25,18 +25,20 @@ public:
void build_panel(ConfigOptionPoints* default_pt); void build_panel(ConfigOptionPoints* default_pt);
// Returns the resulting bed shape polygon. This value will be stored to the ini file.
std::vector<Vec2d> GetValue() { return m_canvas->m_bed_shape; }
private:
ConfigOptionsGroupShp init_shape_options_page(const wxString& title); ConfigOptionsGroupShp init_shape_options_page(const wxString& title);
void set_shape(ConfigOptionPoints* points); void set_shape(ConfigOptionPoints* points);
void update_preview(); void update_preview();
void update_shape(); void update_shape();
void load_stl(); void load_stl();
// Returns the resulting bed shape polygon. This value will be stored to the ini file.
std::vector<Vec2d> GetValue() { return m_canvas->m_bed_shape; }
wxChoicebook* m_shape_options_book; wxChoicebook* m_shape_options_book;
std::vector <ConfigOptionsGroupShp> m_optgroups; std::vector <ConfigOptionsGroupShp> m_optgroups;
friend class BedShapeDialog;
}; };
class BedShapeDialog : public DPIDialog class BedShapeDialog : public DPIDialog