diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 037c86b40..7ab85fc69 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -159,7 +159,52 @@ void Plate2D::mouse_drag(wxMouseEvent& e) { } void Plate2D::mouse_down(wxMouseEvent& e) { + this->SetFocus(); // Focus needed to move selected instance with keyboard arrows + + const auto& pos = e.GetPosition(); + const auto point = this->point_to_model_units(pos); + this->on_select_object(-1); + this->selected_instance = {-1, -1}; + + Slic3r::Log::info(LogChannel, LOG_WSTRING("Mouse down at scaled point " << point.x << ", " << point.y)); + + // Iterate through the list backwards to catch the highest object (last placed/drawn), which + // is usually what the user wants. + for (auto obj = this->objects.rbegin(); obj != this->objects.rend(); obj++) { + const auto& obj_idx {obj->identifier}; + for (auto thumbnail = obj->instance_thumbnails.crbegin(); thumbnail != obj->instance_thumbnails.crend(); thumbnail++) { + Slic3r::Log::info(LogChannel, LOG_WSTRING("First point: " << thumbnail->contours()[0].points[0].x << "," << thumbnail->contours()[0].points[0].y)); + if (thumbnail->contains(point)) { + const auto& instance_idx {std::distance(thumbnail, obj->instance_thumbnails.crend()) - 1}; + Slic3r::Log::info(LogChannel, LOG_WSTRING(instance_idx << " contains this point")); + this->on_select_object(obj_idx); + if (e.LeftDown()) { + // start dragging + auto& instance {this->model->objects.at(obj_idx)->instances.at(instance_idx)}; + auto instance_origin { Point::new_scale(instance->offset) }; + + this->drag_start_pos { Slic3r::Point( + point.x - instance_origin.x, + point.y - instance_origin.y, + )}; + + this->drag_object = { obj_idx, instance_idx }; + this->selected_instance = this->drag_object; + + obj->selected_instance = instance_idx; + + } else if(e.RightDown()) { + this->on_right_click(pos); + } + } + } + + } + } +void Plate2D::on_select_object(int i) { +} + void Plate2D::mouse_up(wxMouseEvent& e) { } void Plate2D::mouse_dclick(wxMouseEvent& e) { diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 126163158..51f63943d 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -29,6 +29,12 @@ enum class MoveDirection { Up, Down, Left, Right }; +/// simple POD to make referencing this pair of identifiers easy +struct InstanceIdx { + long obj; + long inst; +}; + class Plate2D : public wxPanel { public: Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings); @@ -58,7 +64,10 @@ private: wxPen dark_pen {}; bool user_drawn_background {(the_os == OS::Mac ? false : true)}; - size_t selected_instance; + + /// The object id and selected + InstanceIdx selected_instance; + InstanceIdx drag_object; /// Handle mouse-move events void mouse_drag(wxMouseEvent& e); @@ -66,6 +75,11 @@ private: void mouse_up(wxMouseEvent& e); void mouse_dclick(wxMouseEvent& e); + wxPoint drag_start_pos {}; + + /// Do something on right-clicks. + void on_right_click(const wxPoint& pos) { } + /// Handle repaint events void repaint(wxPaintEvent& e); @@ -119,6 +133,7 @@ private: /// Remove all instance thumbnails. void clean_instance_thumbnails(); + void on_select_object(int); }; } } // Namespace Slic3r::GUI