Cleaned up header for Plate2D.hpp; added comments.

This commit is contained in:
Joseph Lenox 2018-05-12 19:43:43 -05:00
parent 2d386053f6
commit 1006abc5b8

View File

@ -8,23 +8,23 @@
#include <vector> #include <vector>
#include <functional> #include <functional>
#include "Plater.hpp"
#include "ColorScheme.hpp" #include "ColorScheme.hpp"
#include "Settings.hpp" #include "Plater.hpp"
#include "Plater/PlaterObject.hpp" #include "Plater/PlaterObject.hpp"
#include "Settings.hpp"
#include "misc_ui.hpp" #include "misc_ui.hpp"
#include "Log.hpp" #include "Log.hpp"
namespace Slic3r { namespace GUI { namespace Slic3r { namespace GUI {
// Setup for an Easter Egg with the canvas text. // Setup for an Easter Egg with the canvas text.
const wxDateTime today_date {wxDateTime::Now()}; const wxDateTime today_date {wxDateTime::Now()};
const wxDateTime special_date {13, wxDateTime::Month::Sep, 2006, 0, 0, 0, 0}; const wxDateTime special_date {13, wxDateTime::Month::Sep, 2006, 0, 0, 0, 0};
const bool today_is_special = {today_date.GetDay() == special_date.GetDay() && today_date.GetMonth() == special_date.GetMonth()}; const bool today_is_special = {today_date.GetDay() == special_date.GetDay() && today_date.GetMonth() == special_date.GetMonth()};
/// Enumeration for object nudges.
enum class MoveDirection { enum class MoveDirection {
Up, Down, Left, Right Up, Down, Left, Right
}; };
@ -37,20 +37,26 @@ struct InstanceIdx {
class Plate2D : public wxPanel { class Plate2D : public wxPanel {
public: public:
Plate2D(wxWindow* parent, const wxSize& size, std::vector<PlaterObject>& _objects, std::shared_ptr<Model> _model, std::shared_ptr<Config> _config, std::shared_ptr<Settings> _settings);
/// Constructor. Keeps a reference to the main configuration, the model, and the gui settings.
Plate2D(wxWindow* parent, const wxSize& size, std::vector<PlaterObject>& _objects, std::shared_ptr<Model> _model, std::shared_ptr<Config> _config, std::shared_ptr<Settings> _settings);
/// Read print bed size from config and calculate the scaled rendition of the bed given the draw canvas. /// Read print bed size from config and calculate the scaled rendition of the bed given the draw canvas.
void update_bed_size(); void update_bed_size();
std::function<void (const unsigned int obj_idx)> on_select_object {};
std::function<void ()> on_double_click {};
/// Do something on right-clicks. /// Do something on right-clicks.
std::function<void (const wxPoint& pos)> on_right_click {}; std::function<void (const wxPoint& pos)> on_right_click {};
/// Do something when right-clicks occur.
std::function<void ()> on_double_click {};
/// Registered function to fire when an instance is moved.
std::function<void ()> on_instances_moved {}; std::function<void ()> on_instances_moved {};
/// Registered function to fire when objects are selected.
std::function<void (const unsigned int obj_idx)> on_select_object {};
/// Set the selected object instance.
void set_selected (long obj, long inst) { this->selected_instance = {obj, inst}; } void set_selected (long obj, long inst) { this->selected_instance = {obj, inst}; }
private: private:
@ -59,7 +65,7 @@ private:
std::shared_ptr<Slic3r::Config> config; std::shared_ptr<Slic3r::Config> config;
std::shared_ptr<Settings> settings; std::shared_ptr<Settings> settings;
// Different brushes to draw with, initialized from settings->Color during the constructor /// Different brushes to draw with, initialized from settings->Color during the constructor
wxBrush objects_brush {}; wxBrush objects_brush {};
wxBrush instance_brush {}; wxBrush instance_brush {};
wxBrush selected_brush {}; wxBrush selected_brush {};
@ -75,8 +81,10 @@ private:
bool user_drawn_background {(the_os == OS::Mac ? false : true)}; bool user_drawn_background {(the_os == OS::Mac ? false : true)};
/// The object id and selected /// Object and instance currently selected.
InstanceIdx selected_instance {-1, -1}; InstanceIdx selected_instance {-1, -1};
/// Currently dragged object.
InstanceIdx drag_object {-1, -1}; InstanceIdx drag_object {-1, -1};
/// Handle mouse-move events /// Handle mouse-move events
@ -85,15 +93,13 @@ private:
void mouse_up(wxMouseEvent& e); void mouse_up(wxMouseEvent& e);
void mouse_dclick(wxMouseEvent& e); void mouse_dclick(wxMouseEvent& e);
wxPoint drag_start_pos {wxPoint(-1, -1)}; wxPoint drag_start_pos {wxPoint(-1, -1)}; //< Start coordinate for object drags
void repaint(wxPaintEvent& e); //< Handle repaint events
/// Handle repaint events void nudge_key(wxKeyEvent& e); //< Handler for wxKeyEvents.
void repaint(wxPaintEvent& e);
void nudge_key(wxKeyEvent& e); void nudge(MoveDirection dir); //< Perform object nudge on plater.
void nudge(MoveDirection dir);
/// Set/Update all of the colors used by the various brushes in the panel. /// Set/Update all of the colors used by the various brushes in the panel.
void set_colors(); void set_colors();
@ -105,15 +111,14 @@ private:
/// For a specific point, unscale it relative to the origin /// For a specific point, unscale it relative to the origin
wxPoint unscaled_point_to_pixel(const wxPoint& in); wxPoint unscaled_point_to_pixel(const wxPoint& in);
/// private class variables for drawing the print bed area.
Slic3r::Polygon bed_polygon {};
std::vector<wxPoint> grid {};
wxRealPoint print_center {};
/// Displacement needed to center bed. /// Displacement needed to center bed.
wxPoint bed_origin {}; wxPoint bed_origin {};
/// private class variables to stash bits for drawing the print bed area.
wxRealPoint print_center {};
Slic3r::Polygon bed_polygon {};
std::vector<wxPoint> grid {};
/// Set up the 2D canvas blank canvas text. /// 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. /// 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") }; const wxString CANVAS_TEXT { today_is_special ? _(L"What do you want to print today?™") : _("Drag your objects here") };
@ -122,8 +127,11 @@ private:
/// Expressed as pixel / mm /// Expressed as pixel / mm
double scaling_factor {1.0}; double scaling_factor {1.0};
const std::string LogChannel {"GUI_2D"};
const std::string LogChannel {"GUI_2D"}; //< Which logging channel to use for this object.
/// Transform a (X,Y) pair relative to the GUI position of the bed
/// and scale. Returns a Slic3r::Point in scaled units.
Slic3r::Point point_to_model_units(coordf_t x, coordf_t y) { Slic3r::Point point_to_model_units(coordf_t x, coordf_t y) {
const auto& zero {this->bed_origin}; const auto& zero {this->bed_origin};
return Slic3r::Point( return Slic3r::Point(
@ -131,9 +139,13 @@ private:
scale_(zero.y - y) / this->scaling_factor scale_(zero.y - y) / this->scaling_factor
); );
} }
/// Overloaded function to accept wxPoint and return scaled and offset Slic3r::Point
Slic3r::Point point_to_model_units(const wxPoint& pt) { Slic3r::Point point_to_model_units(const wxPoint& pt) {
return this->point_to_model_units(pt.x, pt.y); return this->point_to_model_units(pt.x, pt.y);
} }
/// Overloaded function to accept Slic3r::Pointf and return scaled and offset Slic3r::Point
Slic3r::Point point_to_model_units(const Pointf& pt) { Slic3r::Point point_to_model_units(const Pointf& pt) {
return this->point_to_model_units(pt.x, pt.y); return this->point_to_model_units(pt.x, pt.y);
} }