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)
{
auto sbsizer = new wxStaticBoxSizer(wxVERTICAL, this, _(L("Shape")));
sbsizer->GetStaticBox()->SetFont(wxGetApp().bold_font());
// shape options
m_shape_options_book = new wxChoicebook(this, wxID_ANY, wxDefaultPosition,
@ -89,7 +90,7 @@ void BedShapePanel::build_panel(ConfigOptionPoints* default_pt)
Line line{ "", "" };
line.full_width = 1;
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);
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.
ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(const wxString& title)
{
auto panel = new wxPanel(m_shape_options_book);
ConfigOptionsGroupShp optgroup;
optgroup = std::make_shared<ConfigOptionsGroup>(panel, _(L("Settings")));
wxPanel* panel = new wxPanel(m_shape_options_book);
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(panel, _(L("Settings")));
optgroup->label_width = 10;
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.
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);
if (dialog->ShowModal() != wxID_OK) {
dialog->Destroy();
if (dialog.ShowModal() != wxID_OK)
return;
}
wxArrayString input_file;
dialog->GetPaths(input_file);
dialog->Destroy();
dialog.GetPaths(input_file);
std::string file_name = input_file[0].ToUTF8().data();
@ -327,9 +325,8 @@ void BedShapePanel::load_stl()
model = Model::read_from_file(file_name);
}
catch (std::exception &e) {
auto msg = _(L("Error!")) + " " + file_name + " : " + e.what() + ".";
show_error(this, msg);
exit(1);
show_error(this, _(L("Error! Invalid model")));
return;
}
auto mesh = model.mesh();

View File

@ -25,18 +25,20 @@ public:
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);
void set_shape(ConfigOptionPoints* points);
void update_preview();
void update_shape();
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;
std::vector <ConfigOptionsGroupShp> m_optgroups;
friend class BedShapeDialog;
};
class BedShapeDialog : public DPIDialog