From 352183131a797bbcaa871a69d72b2272b4fa38a5 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Mon, 30 Apr 2018 22:33:54 -0500 Subject: [PATCH] Finished update_bed_size, shuffled LogChannel position in the class. updated a few comments. --- src/GUI/Plater/Plate2D.cpp | 53 +++++++++++++++++++++++++++++++++----- src/GUI/Plater/Plate2D.hpp | 8 +++--- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 72d14e414..2f747f2a2 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -2,7 +2,9 @@ // libslic3r includes #include "Geometry.hpp" +#include "Point.hpp" #include "Log.hpp" +#include "ClipperUtils.hpp" // wx includes #include @@ -27,6 +29,7 @@ Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vectorSetBackgroundStyle(wxBG_STYLE_PAINT); + } void Plate2D::repaint(wxPaintEvent& e) { @@ -69,8 +72,11 @@ void Plate2D::repaint(wxPaintEvent& e) { dc->SetTextForeground(wxColor(0,0,0)); dc->SetFont(wxFont(10, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); - dc->DrawLabel("X = ", wxRect(0,0, center.x*2, this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM); - dc->DrawRotatedText("Y = ", 0, center.y + 15, 90); + wxString val {}; + val.Printf("X = %.0f", this->print_center.x); + dc->DrawLabel(val , wxRect(0,0, center.x*2, this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM); + val.Printf("Y = %.0f", this->print_center.y); + dc->DrawRotatedText(val, 0, center.y + 15, 90); } } @@ -157,7 +163,7 @@ void Plate2D::nudge(MoveDirection dir) { if (this->selected_instance < this->objects.size()) { auto i = 0U; for (auto& obj : this->objects) { - if (obj.selected()) { + if (obj.selected) { if (obj.selected_instance != -1) { } } @@ -176,17 +182,47 @@ void Plate2D::update_bed_size() { const auto& canvas_h {canvas_size.GetHeight()}; if (canvas_w == 0) return; // Abort early if we haven't drawn canvas yet. - this->bed_polygon = Slic3r::Polygon(); + this->bed_polygon = Slic3r::Polygon(scale(dynamic_cast(config->optptr("bed_shape"))->values)); + const auto& polygon = bed_polygon; const auto& bb = bed_polygon.bounding_box(); const auto& size = bb.size(); - this->scaling_factor = std::min(static_cast(canvas_w) / unscale(size.x), - static_cast(canvas_h) / unscale(size.y)); + this->scaling_factor = std::min(canvas_w / unscale(size.x), canvas_h / unscale(size.y)); - assert(this->scaling_factor != 0); + this->bed_origin = wxPoint( + canvas_w / 2 - (unscale(bb.max.x + bb.min.x)/2 * this->scaling_factor), + canvas_h - (canvas_h / 2 - (unscale(bb.max.y + bb.min.y)/2 * this->scaling_factor)) + ); + const auto& center = bb.center(); + this->print_center = wxPoint(unscale(center.x), unscale(center.y)); + + // Cache bed contours and grid + { + const auto& step { scale_(10) }; + auto grid {Polylines()}; + + for (coord_t x = (bb.min.x - (bb.min.x % step) + step); x < bb.max.x; x += step) { + grid.push_back(Polyline()); + grid.back().append(Point(x, bb.min.y)); + grid.back().append(Point(x, bb.max.y)); + }; + + for (coord_t y = (bb.min.y - (bb.min.y % step) + step); y < bb.max.y; y += step) { + grid.push_back(Polyline()); + grid.back().append(Point(bb.min.x, y)); + grid.back().append(Point(bb.max.x, y)); + }; + + grid = intersection_pl(grid, polygon); + for (auto& i : grid) { + const auto& tmpline { this->scaled_points_to_pixel(i, 1) }; + this->grid.insert(this->grid.end(), tmpline.begin(), tmpline.end()); + } + } +} std::vector Plate2D::scaled_points_to_pixel(const Slic3r::Polygon& poly, bool unscale) { return this->scaled_points_to_pixel(Polyline(poly), unscale); @@ -200,4 +236,7 @@ std::vector Plate2D::scaled_points_to_pixel(const Slic3r::Polyline& pol } return result; } + + + } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 39457bc71..9b33c80eb 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -84,11 +84,10 @@ private: in.y * this->scaling_factor + (zero.y - canvas_height)); } - /// Read print bed size from config. + /// Read print bed size from config and calculate the scaled rendition of the bed given the draw canvas. void update_bed_size(); - const std::string LogChannel {"GUI_2D"}; - + /// private class variables to stash bits for drawing the print bed area. wxPoint bed_origin {}; wxPoint print_center {}; Slic3r::Polygon bed_polygon {}; @@ -97,11 +96,12 @@ private: /// Set up the 2D canvas blank canvas text. /// Easter egg: Sept. 13, 2006. The first part ever printed by a RepRap to make another RepRap. const wxString CANVAS_TEXT { today_is_special ? _(L"What do you want to print today?™") : _("Drag your objects here") }; - /// How much to scale the points to fit in the draw bounding box area. /// Expressed as pixel / mm double scaling_factor {1.0}; + + const std::string LogChannel {"GUI_2D"}; };