From 4046d517c9f9564e414a3309fbd5401c72a319b4 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 11 Apr 2019 14:21:08 +0200 Subject: [PATCH] Copy and paste -> Disabled paste of volumes when nothing is selected and fixed enabling/disabling of paste item in toolbar and edit menu --- src/slic3r/GUI/Plater.cpp | 10 ++++++---- src/slic3r/GUI/Plater.hpp | 2 +- src/slic3r/GUI/Selection.cpp | 22 ++++++++++++++-------- src/slic3r/GUI/Selection.hpp | 29 +++++++++++++++-------------- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index ebe7e2c75..a34562d85 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3711,10 +3711,12 @@ void Plater::paste_from_clipboard() { p->view3D->get_canvas3d()->get_selection().paste_from_clipboard(); } - -bool Plater::is_selection_clipboard_empty() const +bool Plater::can_paste_from_clipboard() const { - return p->view3D->get_canvas3d()->get_selection().is_clipboard_empty(); + const Selection& selection = p->view3D->get_canvas3d()->get_selection(); + const Selection::Clipboard& clipboard = selection.get_clipboard(); + Selection::EMode mode = clipboard.get_mode(); + return !clipboard.is_empty() && ((mode == Selection::Instance) || selection.is_from_single_instance()); } bool Plater::can_delete() const { return p->can_delete(); } @@ -3726,6 +3728,6 @@ bool Plater::can_split_to_volumes() const { return p->can_split_to_volumes(); } bool Plater::can_arrange() const { return p->can_arrange(); } bool Plater::can_layers_editing() const { return p->can_layers_editing(); } bool Plater::can_copy() const { return !is_selection_empty(); } -bool Plater::can_paste() const { return !is_selection_clipboard_empty(); } +bool Plater::can_paste() const { return can_paste_from_clipboard(); } }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index a70656c58..708c07f39 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -184,7 +184,7 @@ public: void copy_selection_to_clipboard(); void paste_from_clipboard(); - bool is_selection_clipboard_empty() const; + bool can_paste_from_clipboard() const; bool can_delete() const; bool can_delete_all() const; diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 705f02d33..41313d5ed 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -1067,15 +1067,21 @@ void Selection::paste_from_clipboard() if (!m_valid || m_clipboard.is_empty()) return; - if ((m_clipboard.get_mode() == Volume) && is_from_single_instance()) - paste_volumes_from_clipboard(); - else - paste_objects_from_clipboard(); -} + switch (m_clipboard.get_mode()) + { + case Volume: + { + if (is_from_single_instance()) + paste_volumes_from_clipboard(); -bool Selection::is_clipboard_empty() -{ - return m_clipboard.is_empty(); + break; + } + case Instance: + { + paste_objects_from_clipboard(); + break; + } + } } void Selection::update_valid() diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index 9fa9f1869..a8b0c06dc 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -138,19 +138,6 @@ public: typedef std::set InstanceIdxsList; typedef std::map ObjectIdxsToInstanceIdxsMap; -private: - struct Cache - { - // Cache of GLVolume derived transformation matrices, valid during mouse dragging. - VolumesCache volumes_data; - // Center of the dragged selection, valid during mouse dragging. - Vec3d dragging_center; - // Map from indices of ModelObject instances in Model::objects - // to a set of indices of ModelVolume instances in ModelObject::instances - // Here the index means a position inside the respective std::vector, not ModelID. - ObjectIdxsToInstanceIdxsMap content; - }; - class Clipboard { Model m_model; @@ -168,6 +155,19 @@ private: void set_mode(Selection::EMode mode) { m_mode = mode; } }; +private: + struct Cache + { + // Cache of GLVolume derived transformation matrices, valid during mouse dragging. + VolumesCache volumes_data; + // Center of the dragged selection, valid during mouse dragging. + Vec3d dragging_center; + // Map from indices of ModelObject instances in Model::objects + // to a set of indices of ModelVolume instances in ModelObject::instances + // Here the index means a position inside the respective std::vector, not ModelID. + ObjectIdxsToInstanceIdxsMap content; + }; + // Volumes owned by GLCanvas3D. GLVolumePtrs* m_volumes; // Model, not owned. @@ -287,7 +287,8 @@ public: void copy_to_clipboard(); void paste_from_clipboard(); - bool is_clipboard_empty(); + + const Clipboard& get_clipboard() const { return m_clipboard; } private: void update_valid();