Refactoring of BedShapePanel and BedShapeDialog
This commit is contained in:
parent
ce5618fb27
commit
75c53a53b6
4 changed files with 28 additions and 29 deletions
|
@ -16,7 +16,7 @@
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
void BedShapeDialog::build_dialog(ConfigOptionPoints* default_pt)
|
void BedShapeDialog::build_dialog(const ConfigOptionPoints& default_pt)
|
||||||
{
|
{
|
||||||
SetFont(wxGetApp().normal_font());
|
SetFont(wxGetApp().normal_font());
|
||||||
m_panel = new BedShapePanel(this);
|
m_panel = new BedShapePanel(this);
|
||||||
|
@ -51,7 +51,7 @@ void BedShapeDialog::on_dpi_changed(const wxRect &suggested_rect)
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BedShapePanel::build_panel(ConfigOptionPoints* default_pt)
|
void BedShapePanel::build_panel(const 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());
|
sbsizer->GetStaticBox()->SetFont(wxGetApp().bold_font());
|
||||||
|
@ -113,7 +113,7 @@ void BedShapePanel::build_panel(ConfigOptionPoints* default_pt)
|
||||||
|
|
||||||
// right pane with preview canvas
|
// right pane with preview canvas
|
||||||
m_canvas = new Bed_2D(this);
|
m_canvas = new Bed_2D(this);
|
||||||
m_canvas->m_bed_shape = default_pt->values;
|
m_canvas->m_bed_shape = default_pt.values;
|
||||||
|
|
||||||
// main sizer
|
// main sizer
|
||||||
auto top_sizer = new wxBoxSizer(wxHORIZONTAL);
|
auto top_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
@ -155,20 +155,20 @@ ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(const wxString& tit
|
||||||
// Deduce the bed shape type(rect, circle, custom)
|
// Deduce the bed shape type(rect, circle, custom)
|
||||||
// This routine shall be smart enough if the user messes up
|
// This routine shall be smart enough if the user messes up
|
||||||
// with the list of points in the ini file directly.
|
// with the list of points in the ini file directly.
|
||||||
void BedShapePanel::set_shape(ConfigOptionPoints* points)
|
void BedShapePanel::set_shape(const ConfigOptionPoints& points)
|
||||||
{
|
{
|
||||||
auto polygon = Polygon::new_scale(points->values);
|
auto polygon = Polygon::new_scale(points.values);
|
||||||
|
|
||||||
// is this a rectangle ?
|
// is this a rectangle ?
|
||||||
if (points->size() == 4) {
|
if (points.size() == 4) {
|
||||||
auto lines = polygon.lines();
|
auto lines = polygon.lines();
|
||||||
if (lines[0].parallel_to(lines[2]) && lines[1].parallel_to(lines[3])) {
|
if (lines[0].parallel_to(lines[2]) && lines[1].parallel_to(lines[3])) {
|
||||||
// okay, it's a rectangle
|
// okay, it's a rectangle
|
||||||
// find origin
|
// find origin
|
||||||
coordf_t x_min, x_max, y_min, y_max;
|
coordf_t x_min, x_max, y_min, y_max;
|
||||||
x_max = x_min = points->values[0](0);
|
x_max = x_min = points.values[0](0);
|
||||||
y_max = y_min = points->values[0](1);
|
y_max = y_min = points.values[0](1);
|
||||||
for (auto pt : points->values)
|
for (auto pt : points.values)
|
||||||
{
|
{
|
||||||
x_min = std::min(x_min, pt(0));
|
x_min = std::min(x_min, pt(0));
|
||||||
x_max = std::max(x_max, pt(0));
|
x_max = std::max(x_max, pt(0));
|
||||||
|
@ -219,8 +219,8 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (points->size() < 3) {
|
if (points.size() < 3) {
|
||||||
// Invalid polygon.Revert to default bed dimensions.
|
// Invalid polygon.Revert to default bed dimensions.
|
||||||
m_shape_options_book->SetSelection(SHAPE_RECTANGULAR);
|
m_shape_options_book->SetSelection(SHAPE_RECTANGULAR);
|
||||||
auto optgroup = m_optgroups[SHAPE_RECTANGULAR];
|
auto optgroup = m_optgroups[SHAPE_RECTANGULAR];
|
||||||
optgroup->set_value("rect_size", new ConfigOptionPoints{ Vec2d(200, 200) });
|
optgroup->set_value("rect_size", new ConfigOptionPoints{ Vec2d(200, 200) });
|
||||||
|
@ -232,7 +232,7 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
|
||||||
// This is a custom bed shape, use the polygon provided.
|
// This is a custom bed shape, use the polygon provided.
|
||||||
m_shape_options_book->SetSelection(SHAPE_CUSTOM);
|
m_shape_options_book->SetSelection(SHAPE_CUSTOM);
|
||||||
// Copy the polygon to the canvas, make a copy of the array.
|
// Copy the polygon to the canvas, make a copy of the array.
|
||||||
m_loaded_bed_shape = points->values;
|
m_loaded_bed_shape = points.values;
|
||||||
update_shape();
|
update_shape();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ void BedShapePanel::load_stl()
|
||||||
try {
|
try {
|
||||||
model = Model::read_from_file(file_name);
|
model = Model::read_from_file(file_name);
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
catch (std::exception &) {
|
||||||
show_error(this, _(L("Error! Invalid model")));
|
show_error(this, _(L("Error! Invalid model")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,15 +23,15 @@ public:
|
||||||
BedShapePanel(wxWindow* parent) : wxPanel(parent, wxID_ANY) {}
|
BedShapePanel(wxWindow* parent) : wxPanel(parent, wxID_ANY) {}
|
||||||
~BedShapePanel() {}
|
~BedShapePanel() {}
|
||||||
|
|
||||||
void build_panel(ConfigOptionPoints* default_pt);
|
void build_panel(const ConfigOptionPoints& default_pt);
|
||||||
|
|
||||||
// Returns the resulting bed shape polygon. This value will be stored to the ini file.
|
// 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; }
|
std::vector<Vec2d> get_bed_shape() { return m_canvas->m_bed_shape; }
|
||||||
|
|
||||||
private:
|
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(const ConfigOptionPoints& points);
|
||||||
void update_preview();
|
void update_preview();
|
||||||
void update_shape();
|
void update_shape();
|
||||||
void load_stl();
|
void load_stl();
|
||||||
|
|
||||||
|
@ -49,8 +49,8 @@ public:
|
||||||
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {}
|
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {}
|
||||||
~BedShapeDialog() {}
|
~BedShapeDialog() {}
|
||||||
|
|
||||||
void build_dialog(ConfigOptionPoints* default_pt);
|
void build_dialog(const ConfigOptionPoints& default_pt);
|
||||||
std::vector<Vec2d> GetValue() { return m_panel->GetValue(); }
|
std::vector<Vec2d> get_bed_shape() { return m_panel->get_bed_shape(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void on_dpi_changed(const wxRect &suggested_rect) override;
|
void on_dpi_changed(const wxRect &suggested_rect) override;
|
||||||
|
|
|
@ -532,15 +532,14 @@ PageBedShape::PageBedShape(ConfigWizard *parent)
|
||||||
{
|
{
|
||||||
append_text(_(L("Set the shape of your printer's bed.")));
|
append_text(_(L("Set the shape of your printer's bed.")));
|
||||||
|
|
||||||
shape_panel->build_panel(wizard_p()->custom_config->option<ConfigOptionPoints>("bed_shape"));
|
shape_panel->build_panel(*wizard_p()->custom_config->option<ConfigOptionPoints>("bed_shape"));
|
||||||
append(shape_panel);
|
append(shape_panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageBedShape::apply_custom_config(DynamicPrintConfig &config)
|
void PageBedShape::apply_custom_config(DynamicPrintConfig &config)
|
||||||
{
|
{
|
||||||
const auto points(shape_panel->GetValue());
|
const auto points(shape_panel->get_bed_shape());
|
||||||
auto *opt = new ConfigOptionPoints(points);
|
config.set_key_value("bed_shape", new ConfigOptionPoints(points));
|
||||||
config.set_key_value("bed_shape", opt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PageDiameters::PageDiameters(ConfigWizard *parent)
|
PageDiameters::PageDiameters(ConfigWizard *parent)
|
||||||
|
|
|
@ -1856,9 +1856,9 @@ void TabPrinter::build_fff()
|
||||||
btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e)
|
btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e)
|
||||||
{
|
{
|
||||||
BedShapeDialog dlg(this);
|
BedShapeDialog dlg(this);
|
||||||
dlg.build_dialog(m_config->option<ConfigOptionPoints>("bed_shape"));
|
dlg.build_dialog(*m_config->option<ConfigOptionPoints>("bed_shape"));
|
||||||
if (dlg.ShowModal() == wxID_OK) {
|
if (dlg.ShowModal() == wxID_OK) {
|
||||||
std::vector<Vec2d> shape = dlg.GetValue();
|
std::vector<Vec2d> shape = dlg.get_bed_shape();
|
||||||
if (!shape.empty())
|
if (!shape.empty())
|
||||||
{
|
{
|
||||||
load_key_value("bed_shape", shape);
|
load_key_value("bed_shape", shape);
|
||||||
|
@ -2062,9 +2062,9 @@ void TabPrinter::build_sla()
|
||||||
btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e)
|
btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e)
|
||||||
{
|
{
|
||||||
BedShapeDialog dlg(this);
|
BedShapeDialog dlg(this);
|
||||||
dlg.build_dialog(m_config->option<ConfigOptionPoints>("bed_shape"));
|
dlg.build_dialog(*m_config->option<ConfigOptionPoints>("bed_shape"));
|
||||||
if (dlg.ShowModal() == wxID_OK) {
|
if (dlg.ShowModal() == wxID_OK) {
|
||||||
std::vector<Vec2d> shape = dlg.GetValue();
|
std::vector<Vec2d> shape = dlg.get_bed_shape();
|
||||||
if (!shape.empty())
|
if (!shape.empty())
|
||||||
{
|
{
|
||||||
load_key_value("bed_shape", shape);
|
load_key_value("bed_shape", shape);
|
||||||
|
|
Loading…
Reference in a new issue