From 7d29a7b45a28ce32a35d687cfb81281cfe0bac0e Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 30 Jan 2018 12:10:12 +0100 Subject: [PATCH] BedShapeDialog and Bed_2D (as a part of it) are completed. Added new_scale function to Polyline. Fixed small bug in PointCtrl. Extended change_opt_value for coPoints case. --- xs/src/libslic3r/Polyline.hpp | 8 ++ xs/src/slic3r/GUI/2DBed.cpp | 204 +++++++++++++++------------ xs/src/slic3r/GUI/2DBed.hpp | 19 ++- xs/src/slic3r/GUI/BedShapeDialog.cpp | 159 ++++++++++++--------- xs/src/slic3r/GUI/BedShapeDialog.hpp | 9 +- xs/src/slic3r/GUI/Field.cpp | 2 +- xs/src/slic3r/GUI/GUI.cpp | 6 +- xs/src/slic3r/GUI/Tab.cpp | 4 +- 8 files changed, 239 insertions(+), 172 deletions(-) diff --git a/xs/src/libslic3r/Polyline.hpp b/xs/src/libslic3r/Polyline.hpp index ac59c6378..ffeafaa80 100644 --- a/xs/src/libslic3r/Polyline.hpp +++ b/xs/src/libslic3r/Polyline.hpp @@ -21,6 +21,14 @@ public: Polyline(Polyline &&other) : MultiPoint(std::move(other.points)) {} Polyline& operator=(const Polyline &other) { points = other.points; return *this; } Polyline& operator=(Polyline &&other) { points = std::move(other.points); return *this; } + static Polyline new_scale(std::vector points) { + Polyline pl; + Points int_points; + for (auto pt : points) + int_points.push_back(Point::new_scale(pt.x, pt.y)); + pl.append(int_points); + return pl; + } void append(const Point &point) { this->points.push_back(point); } void append(const Points &src) { this->append(src.begin(), src.end()); } diff --git a/xs/src/slic3r/GUI/2DBed.cpp b/xs/src/slic3r/GUI/2DBed.cpp index f89514d03..c5d68400d 100644 --- a/xs/src/slic3r/GUI/2DBed.cpp +++ b/xs/src/slic3r/GUI/2DBed.cpp @@ -3,14 +3,14 @@ #include #include "BoundingBox.hpp" #include "Geometry.hpp" +#include "ClipperUtils.hpp" namespace Slic3r { namespace GUI { void Bed_2D::repaint() { -// auto dc = new wxAutoBufferedPaintDC(this); - wxClientDC dc(this); + wxAutoBufferedPaintDC dc(this); auto cw = GetSize().GetWidth(); auto ch = GetSize().GetHeight(); // when canvas is not rendered yet, size is 0, 0 @@ -22,23 +22,23 @@ void Bed_2D::repaint() // and on Linux / GTK the background is erased to gray color. // Fill DC with the background on Windows & Linux / GTK. auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); //GetSystemColour - dc.SetPen(/**new wxPen(color, 1, wxPENSTYLE_SOLID)*/*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID)); + dc.SetPen(*new wxPen(color, 1, wxPENSTYLE_SOLID)); dc.SetBrush(*new wxBrush(color, wxBRUSHSTYLE_SOLID)); auto rect = GetUpdateRegion().GetBox(); dc.DrawRectangle(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight()); } // turn cw and ch from sizes to max coordinates -/* cw--; + cw--; ch--; auto cbb = BoundingBoxf(Pointf(0, 0),Pointf(cw, ch)); // leave space for origin point - cbb.min.translate(4, 0); // cbb.set_x_min(cbb.min.x + 4); - cbb.max.translate(-4, -4); // cbb.set_x_max(cbb.max.x - 4);cbb.set_y_max(cbb.max.y - 4); + cbb.min.translate(4, 0); + cbb.max.translate(-4, -4); // leave space for origin label - cbb.max.translate(0, -13); // $cbb->set_y_max($cbb->y_max - 13); + cbb.max.translate(0, -13); // read new size cw = cbb.size().x; @@ -66,91 +66,87 @@ void Bed_2D::repaint() shift.y - (cbb.max.y - GetSize().GetHeight())); // draw bed fill -// { - dc->SetPen(*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID)); - dc->SetBrush(*new wxBrush(*new wxColour(255, 255, 255), wxSOLID)); - wxPointList pt_list; - for (auto pt: m_bed_shape) - { - Point pt_pix = to_pixels(pt); - pt_list.push_back(new wxPoint(pt_pix.x, pt_pix.y)); - } - dc->DrawPolygon(&pt_list, 0, 0); -// } -*/ - // draw grid -// { -// auto step = 10; // 1cm grid -// Polylines polylines; -// for (auto x = bb.min.x - (bb.min.x % step) + step; x < bb.max.x; x += step) { -// // push @polylines, Slic3r::Polyline->new_scale([$x, $bb->y_min], [$x, $bb->y_max]); -// } -// for (auto y = bb.min.y - (bb.min.y % step) + step; y < bb.max.y; y += step) { -// // push @polylines, Slic3r::Polyline->new_scale([$bb->x_min, $y], [$bb->x_max, $y]); -// } -// // @polylines = @{intersection_pl(\@polylines, [$bed_polygon])}; -// -// dc->SetPen(*new wxPen(*new wxColour(230, 230, 230), 1, wxSOLID)); -// // for (auto pl: polylines) -// // dc->DrawLine(map @{$self->to_pixels([map unscale($_), @$_])}, @$_[0, -1]); -// } -// -// // draw bed contour -// { -// dc->SetPen(*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID)); -// dc->SetBrush(*new wxBrush(*new wxColour(255, 255, 255), wxTRANSPARENT)); -// // dc->DrawPolygon([map $self->to_pixels($_), @$bed_shape], 0, 0); -// } + dc.SetBrush(*new wxBrush(*new wxColour(255, 255, 255), wxSOLID)); + wxPointList pt_list; + for (auto pt: m_bed_shape) + { + Point pt_pix = to_pixels(pt); + pt_list.push_back(new wxPoint(pt_pix.x, pt_pix.y)); + } + dc.DrawPolygon(&pt_list, 0, 0); -// auto origin_px = to_pixels(Pointf(0, 0)); -// -// // draw axes -// { -// auto axes_len = 50; -// auto arrow_len = 6; -// auto arrow_angle = Geometry::deg2rad(45); -// dc->SetPen(*new wxPen(*new wxColour(255, 0, 0), 2, wxSOLID)); // red -// auto x_end = Pointf(origin_px.x + axes_len, origin_px.y); -// dc->DrawLine(wxPoint(origin_px), wxPoint(x_end)); -// foreach my $angle(-$arrow_angle, +$arrow_angle) { -// auto end = x_end.clone; -// end->translate(-arrow_len, 0); -// end->rotate(angle, x_end); -// dc->DrawLine(x_end, end); -// } -// -// dc->SetPen(*new wxPen(*new wxColour(0, 255, 0), 2, wxSOLID)); // green -// auto y_end = Pointf(origin_px.x, origin_px.y - axes_len); -// dc->DrawLine(origin_px, y_end); -// foreach my $angle(-$arrow_angle, +$arrow_angle) { -// auto end = y_end->clone; -// end->translate(0, +arrow_len); -// end->rotate(angle, y_end); -// dc->DrawLine(y_end, end); -// } -// } -// -// // draw origin -// { -// dc->SetPen(*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID)); -// dc->SetBrush(*new wxBrush(*new wxColour(0, 0, 0), wxSOLID)); -// dc->DrawCircle(origin_px.x, origin_px.y, 3); -// -// dc->SetTextForeground(*new wxColour(0, 0, 0)); -// dc->SetFont(*new wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL)); -// dc->DrawText("(0,0)", origin_px.x + 1, origin_px.y + 2); -// } -// -// // draw current position -// if (m_pos) { -// auto pos_px = to_pixels(m_pos); -// dc->SetPen(*new wxPen(*new wxColour(200, 0, 0), 2, wxSOLID)); -// dc->SetBrush(*new wxBrush(*new wxColour(200, 0, 0), wxTRANSPARENT)); -// dc->DrawCircle(pos_px, 5); -// -// dc->DrawLine(pos_px.x - 15, pos_px.y, pos_px.x + 15, pos_px.y); -// dc->DrawLine(pos_px.x, pos_px.y - 15, pos_px.x, pos_px.y + 15); -// } + // draw grid + auto step = 10; // 1cm grid + Polylines polylines; + for (auto x = bb.min.x - fmod(bb.min.x, step) + step; x < bb.max.x; x += step) { + Polyline pl = Polyline::new_scale({ Pointf(x, bb.min.y), Pointf(x, bb.max.y) }); + polylines.push_back(pl); + } + for (auto y = bb.min.y - fmod(bb.min.y, step) + step; y < bb.max.y; y += step) { + polylines.push_back(Polyline::new_scale({ Pointf(bb.min.x, y), Pointf(bb.max.x, y) })); + } + polylines = intersection_pl(polylines, bed_polygon); + + dc.SetPen(*new wxPen(*new wxColour(230, 230, 230), 1, wxSOLID)); + for (auto pl : polylines) + { + for (size_t i = 0; i < pl.points.size()-1; i++){ + Point pt1 = to_pixels(Pointf::new_unscale(pl.points[i])); + Point pt2 = to_pixels(Pointf::new_unscale(pl.points[i+1])); + dc.DrawLine(pt1.x, pt1.y, pt2.x, pt2.y); + } + } + + // draw bed contour + dc.SetPen(*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID)); + dc.SetBrush(*new wxBrush(*new wxColour(0, 0, 0), wxTRANSPARENT)); + dc.DrawPolygon(&pt_list, 0, 0); + + auto origin_px = to_pixels(Pointf(0, 0)); + + // draw axes + auto axes_len = 50; + auto arrow_len = 6; + auto arrow_angle = Geometry::deg2rad(45.0); + dc.SetPen(*new wxPen(*new wxColour(255, 0, 0), 2, wxSOLID)); // red + auto x_end = Pointf(origin_px.x + axes_len, origin_px.y); + dc.DrawLine(wxPoint(origin_px.x, origin_px.y), wxPoint(x_end.x, x_end.y)); + for (auto angle : { -arrow_angle, arrow_angle }){ + auto end = x_end; + end.translate(-arrow_len, 0); + end.rotate(angle, x_end); + dc.DrawLine(wxPoint(x_end.x, x_end.y), wxPoint(end.x, end.y)); + } + + dc.SetPen(*new wxPen(*new wxColour(0, 255, 0), 2, wxSOLID)); // green + auto y_end = Pointf(origin_px.x, origin_px.y - axes_len); + dc.DrawLine(wxPoint(origin_px.x, origin_px.y), wxPoint(y_end.x, y_end.y)); + for (auto angle : { -arrow_angle, arrow_angle }) { + auto end = y_end; + end.translate(0, +arrow_len); + end.rotate(angle, y_end); + dc.DrawLine(wxPoint(y_end.x, y_end.y), wxPoint(end.x, end.y)); + } + + // draw origin + dc.SetPen(*new wxPen(*new wxColour(0, 0, 0), 1, wxSOLID)); + dc.SetBrush(*new wxBrush(*new wxColour(0, 0, 0), wxSOLID)); + dc.DrawCircle(origin_px.x, origin_px.y, 3); + + dc.SetTextForeground(*new wxColour(0, 0, 0)); + dc.SetFont(*new wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL)); + dc.DrawText("(0,0)", origin_px.x + 1, origin_px.y + 2); + + // draw current position + if (m_pos!= Pointf(0, 0)) { + auto pos_px = to_pixels(m_pos); + dc.SetPen(*new wxPen(*new wxColour(200, 0, 0), 2, wxSOLID)); + dc.SetBrush(*new wxBrush(*new wxColour(200, 0, 0), wxTRANSPARENT)); + dc.DrawCircle(pos_px.x, pos_px.y, 5); + + dc.DrawLine(pos_px.x - 15, pos_px.y, pos_px.x + 15, pos_px.y); + dc.DrawLine(pos_px.x, pos_px.y - 15, pos_px.x, pos_px.y + 15); + } m_painted = true; } @@ -163,5 +159,31 @@ Point Bed_2D::to_pixels(Pointf point){ return Point(p.x, GetSize().GetHeight() - p.y); } +void Bed_2D::mouse_event(wxMouseEvent event){ + if (!m_interactive) return; + if (!m_painted) return; + + auto pos = event.GetPosition(); + auto point = to_units(Point(pos.x, pos.y)); + if (event.LeftDown() || event.Dragging()) { + if (m_on_move) + m_on_move(point) ; + Refresh(); + } +} + +// convert pixels into G - code coordinates +Pointf Bed_2D::to_units(Point point){ + auto p = Pointf(point.x, GetSize().GetHeight() - point.y); + p.translate(m_shift.negative()); + p.scale(1 / m_scale_factor); + return p; +} + +void Bed_2D::set_pos(Pointf pos){ + m_pos = pos; + Refresh(); +} + } // GUI } // Slic3r \ No newline at end of file diff --git a/xs/src/slic3r/GUI/2DBed.hpp b/xs/src/slic3r/GUI/2DBed.hpp index 942edd8d3..859417efb 100644 --- a/xs/src/slic3r/GUI/2DBed.hpp +++ b/xs/src/slic3r/GUI/2DBed.hpp @@ -9,25 +9,30 @@ class Bed_2D : public wxPanel bool m_user_drawn_background = false; bool m_painted = false; + bool m_interactive = false; double m_scale_factor; Pointf m_shift; - Point m_pos; + Pointf m_pos; + std::function m_on_move = nullptr; Point to_pixels(Pointf point); + Pointf to_units(Point point); void repaint(); + void mouse_event(wxMouseEvent event); + void set_pos(Pointf pos); + public: Bed_2D(wxWindow* parent) { Create(parent, wxID_ANY, wxDefaultPosition, wxSize(250, -1), wxTAB_TRAVERSAL); // m_user_drawn_background = $^O ne 'darwin'; m_user_drawn_background = true; - Bind(wxEVT_PAINT, ([this](wxPaintEvent e) - { - repaint(); - })); + Bind(wxEVT_PAINT, ([this](wxPaintEvent e) { repaint(); })); // EVT_ERASE_BACKGROUND($self, sub{}) if $self->{user_drawn_background}; -// Bind(wxEVT_MOUSE_EVENTS, ([this](wxCommandEvent){/*mouse_event()*/; })); - Bind(wxEVT_SIZE, ([this](wxSizeEvent){Refresh(); })); +// Bind(EVT_MOUSE_EVENTS, ([this](wxMouseEvent event){/*mouse_event()*/; })); + Bind(wxEVT_LEFT_DOWN, ([this](wxMouseEvent event){ mouse_event(event); })); + Bind(wxEVT_MOTION, ([this](wxMouseEvent event){ mouse_event(event); })); + Bind(wxEVT_SIZE, ([this](wxSizeEvent e) { Refresh(); })); } ~Bed_2D(){} diff --git a/xs/src/slic3r/GUI/BedShapeDialog.cpp b/xs/src/slic3r/GUI/BedShapeDialog.cpp index e05702918..dd372b3e2 100644 --- a/xs/src/slic3r/GUI/BedShapeDialog.cpp +++ b/xs/src/slic3r/GUI/BedShapeDialog.cpp @@ -6,6 +6,8 @@ #include "Polygon.hpp" #include "BoundingBox.hpp" #include +#include "Model.hpp" +#include "boost/nowide/iostream.hpp" namespace Slic3r { namespace GUI { @@ -17,7 +19,7 @@ void BedShapeDialog::build_dialog(ConfigOptionPoints* default_pt) auto main_sizer = new wxBoxSizer(wxVERTICAL); main_sizer->Add(m_panel, 1, wxEXPAND); - main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, /*wxEXPAND*/wxALIGN_CENTER_HORIZONTAL | wxBOTTOM/*ALL*/, 10); + main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10); SetSizer(main_sizer); SetMinSize(GetSize()); @@ -158,11 +160,6 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points) if (x_max < 0) x_max = 0; if (y_min < 0) y_min = 0; if (y_max < 0) y_max = 0; -// auto x_min = min(map $_->[X], @$points) || 0; -// auto x_max = max(map $_->[X], @$points) || 0; -// auto y_min = min(map $_->[Y], @$points) || 0; -// auto y_max = max(map $_->[Y], @$points) || 0; -// auto origin = [-x_min, -y_min]; auto origin = new ConfigOptionPoints{ Pointf(-x_min, -y_min) }; m_shape_options_book->SetSelection(SHAPE_RECTANGULAR); @@ -177,11 +174,8 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points) // is this a circle ? { // Analyze the array of points.Do they reside on a circle ? -// auto polygon;// = Slic3r::Polygon->new_scale(@$points); - auto center = polygon.bounding_box().center();// ->bounding_box->center; -// auto /*@*/vertex_distances;// = map $center->distance_to($_), @$polygon; -// auto avg_dist = sum(/*@*/vertex_distances) / /*@*/vertex_distances; - std::vector vertex_distances;// = map $center->distance_to($_), @$polygon; + auto center = polygon.bounding_box().center(); + std::vector vertex_distances; double avg_dist = 0; for (auto pt: polygon.points) { @@ -193,16 +187,16 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points) bool defined_value = true; for (auto el: vertex_distances) { - if (abs(el - avg_dist) > 10 * SCALED_EPSILON/*scaled_epsilon*/) + if (abs(el - avg_dist) > 10 * SCALED_EPSILON) defined_value = false; break; } - if (defined_value/*!defined first{ abs($_ - $avg_dist) > 10 * scaled_epsilon } @vertex_distances*/) { + if (defined_value) { // all vertices are equidistant to center m_shape_options_book->SetSelection(SHAPE_CIRCULAR); auto optgroup = m_optgroups[SHAPE_CIRCULAR]; boost::any ret = wxNumberFormatter::ToString(unscale(avg_dist * 2), 0); - optgroup->set_value("diameter", ret /*sprintf("%.0f", unscale(avg_dist * 2))*/); + optgroup->set_value("diameter", ret); update_shape(); return; } @@ -227,7 +221,7 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points) void BedShapePanel::update_preview() { - if (m_canvas) m_canvas->Refresh(); + if (m_canvas) m_canvas->Refresh(); Refresh(); } @@ -236,44 +230,57 @@ void BedShapePanel::update_shape() { auto page_idx = m_shape_options_book->GetSelection(); if (page_idx == SHAPE_RECTANGULAR) { - auto rect_size = m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size"); - auto rect_origin = m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_origin"); -/* auto x = rect_size->x; - auto y = rect_size->y; + Pointf rect_size, rect_origin; + try{ + rect_size = boost::any_cast(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size")); } + catch (const std::exception &e){ + return;} + try{ + rect_origin = boost::any_cast(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_origin")); + } + catch (const std::exception &e){ + return;} + + auto x = rect_size.x; + auto y = rect_size.y; // empty strings or '-' or other things -// if (!looks_like_number(x) || !looks_like_number(y)) return; - if ((!x || !y) || x == 0 || y == 0) return; -// my($x0, $y0) = (0, 0); -// my($x1, $y1) = ($x, $y); -// { -// my($dx, $dy) = @$rect_origin; -// return if !looks_like_number($dx) || !looks_like_number($dy); # empty strings or '-' or other things -// $x0 -= $dx; -// $x1 -= $dx; -// $y0 -= $dy; -// $y1 -= $dy; -// } -// m_canvas->bed_shape([ -// [$x0, $y0], -// [$x1, $y0], -// [$x1, $y1], -// [$x0, $y1], -// ]); + if (x == 0 || y == 0) return; + double x0 = 0.0; + double y0 = 0.0; + double x1 = x; + double y1 = y; + + auto dx = rect_origin.x; + auto dy = rect_origin.y; + + x0 -= dx; + x1 -= dx; + y0 -= dy; + y1 -= dy; + m_canvas->m_bed_shape = { Pointf(x0, y0), + Pointf(x1, y0), + Pointf(x1, y1), + Pointf(x0, y1)}; } else if(page_idx == SHAPE_CIRCULAR) { -// auto diameter = m_optgroups[SHAPE_CIRCULAR]->get_value("diameter"); -// if (!diameter || diameter == 0) return ; -// r = diameter / 2; -// twopi = 2 * PI; -// edges = 60; -// polygon = Slic3r::Polygon->new_scale( -// map[$r * cos $_, $r * sin $_], -// map{ $twopi / $edges*$_ } 1..$edges -// ); -// m_canvas->bed_shape([ -// map[unscale($_->x), unscale($_->y)], @$polygon #)) -// ]); -*/ } + double diameter; + try{ + diameter = boost::any_cast(m_optgroups[SHAPE_CIRCULAR]->get_value("diameter")); + } + catch (const std::exception &e){ + return; + } + if (diameter == 0.0) return ; + auto r = diameter / 2; + auto twopi = 2 * PI; + auto edges = 60; + std::vector points; + for (size_t i = 1; i <= 60; ++i){ + auto angle = i * twopi / edges; + points.push_back(Pointf(r*cos(angle), r*sin(angle))); + } + m_canvas->m_bed_shape = points; + } // $self->{on_change}->(); update_preview(); @@ -282,8 +289,14 @@ void BedShapePanel::update_shape() // Loads an stl file, projects it to the XY plane and calculates a polygon. void BedShapePanel::load_stl() { + t_file_wild_card vec_FILE_WILDCARDS = get_file_wild_card(); + std::vector file_types = { "known", "stl", "obj", "amf", "prusa"}; + wxString MODEL_WILDCARD; + for (auto file_type: file_types) + MODEL_WILDCARD += vec_FILE_WILDCARDS.at(file_type) + "|"; + auto dialog = new wxFileDialog(this, "Choose a file to import bed shape from (STL/OBJ/AMF/PRUSA):", "", "", - wxFileSelectorDefaultWildcardStr/* &Slic3r::GUI::MODEL_WILDCARD*/, wxFD_OPEN | wxFD_FILE_MUST_EXIST); + MODEL_WILDCARD, wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (dialog->ShowModal() != wxID_OK) { dialog->Destroy(); return; @@ -292,21 +305,35 @@ void BedShapePanel::load_stl() dialog->GetPaths(input_file); dialog->Destroy(); -// auto model = Slic3r::Model->read_from_file(input_file); -// auto mesh = model->mesh; -// auto expolygons = mesh->horizontal_projection; -// -// if (expolygons.size() == 0) { -// show_error(this, "The selected file contains no geometry."); -// return; -// } -// if (expolygons.size() > 1) { -// show_error(this, "The selected file contains several disjoint areas. This is not supported."); -// return; -// } -// -// auto polygon = expolygons[0]->contour; -// m_canvas->bed_shape([map[unscale($_->x), unscale($_->y)], @$polygon]); + std::string file_name = input_file[0].ToStdString(); + + Model model; + try { + model = Model::read_from_file(file_name); + } + catch (std::exception &e) { + std::string msg = "Error! " + file_name + ": " + e.what() + "."; + show_error(this, msg); + exit(1); + } + + auto mesh = model.mesh(); + auto expolygons = mesh.horizontal_projection(); + + if (expolygons.size() == 0) { + show_error(this, "The selected file contains no geometry."); + return; + } + if (expolygons.size() > 1) { + show_error(this, "The selected file contains several disjoint areas. This is not supported."); + return; + } + + auto polygon = expolygons[0].contour; + std::vector points; + for (auto pt : polygon.points) + points.push_back(Pointf::new_unscale(pt)); + m_canvas->m_bed_shape = points; update_preview(); } diff --git a/xs/src/slic3r/GUI/BedShapeDialog.hpp b/xs/src/slic3r/GUI/BedShapeDialog.hpp index b4849cbba..f2219f455 100644 --- a/xs/src/slic3r/GUI/BedShapeDialog.hpp +++ b/xs/src/slic3r/GUI/BedShapeDialog.hpp @@ -24,14 +24,15 @@ public: ~BedShapePanel(){} void build_panel(ConfigOptionPoints* default_pt); - - // Returns the resulting bed shape polygon. This value will be stored to the ini file. - int GetValue() { return 1/*m_canvas->bed_shape*/; } + ConfigOptionsGroupShp init_shape_options_page(std::string 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 GetValue() { return m_canvas->m_bed_shape; } }; class BedShapeDialog : public wxDialog @@ -43,7 +44,7 @@ public: ~BedShapeDialog(){} void build_dialog(ConfigOptionPoints* default_pt); - int GetValue() { return m_panel->GetValue(); } + std::vector GetValue() { return m_panel->GetValue(); } }; } // GUI diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 995eff17a..c0e907be3 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -491,7 +491,7 @@ void PointCtrl::BUILD() temp->Add(y_textctrl); x_textctrl->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e/*$self->option->opt_id*/); }), x_textctrl->GetId()); - y_textctrl->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e/*$self->option->opt_id*/); }), x_textctrl->GetId()); + y_textctrl->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e/*$self->option->opt_id*/); }), y_textctrl->GetId()); // // recast as a wxWindow to fit the calling convention sizer = dynamic_cast(temp); diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index f7365ccf7..ca6e764e2 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -292,7 +292,11 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); } break; - case coPoints: + case coPoints:{ + ConfigOptionPoints points; + points.values = boost::any_cast>(value); + config.set_key_value(opt_key, new ConfigOptionPoints(points)); + } break; case coNone: break; diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index 668680659..1f2b014c6 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -953,8 +953,7 @@ void TabPrinter::build() auto dlg = new BedShapeDialog(this); dlg->build_dialog(m_config->option("bed_shape")); if (dlg->ShowModal() == wxID_OK) -// load_key_value("bed_shape", dlg->GetValue()); - ; + load_key_value("bed_shape", dlg->GetValue()); })); return sizer; @@ -1567,6 +1566,7 @@ void Tab::save_preset(std::string name /*= ""*/) } catch (const std::exception &e) { + show_error(this, "Something is wrong. It can't be saved."); return; }