Copy and paste -> Disabled paste of volumes when nothing is selected and fixed enabling/disabling of paste item in toolbar and edit menu

This commit is contained in:
Enrico Turri 2019-04-11 14:21:08 +02:00
parent 4718c839f6
commit 4046d517c9
4 changed files with 36 additions and 27 deletions

View File

@ -3711,10 +3711,12 @@ void Plater::paste_from_clipboard()
{ {
p->view3D->get_canvas3d()->get_selection().paste_from_clipboard(); p->view3D->get_canvas3d()->get_selection().paste_from_clipboard();
} }
bool Plater::can_paste_from_clipboard() const
bool Plater::is_selection_clipboard_empty() 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(); } 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_arrange() const { return p->can_arrange(); }
bool Plater::can_layers_editing() const { return p->can_layers_editing(); } bool Plater::can_layers_editing() const { return p->can_layers_editing(); }
bool Plater::can_copy() const { return !is_selection_empty(); } 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 }} // namespace Slic3r::GUI

View File

@ -184,7 +184,7 @@ public:
void copy_selection_to_clipboard(); void copy_selection_to_clipboard();
void paste_from_clipboard(); void paste_from_clipboard();
bool is_selection_clipboard_empty() const; bool can_paste_from_clipboard() const;
bool can_delete() const; bool can_delete() const;
bool can_delete_all() const; bool can_delete_all() const;

View File

@ -1067,15 +1067,21 @@ void Selection::paste_from_clipboard()
if (!m_valid || m_clipboard.is_empty()) if (!m_valid || m_clipboard.is_empty())
return; return;
if ((m_clipboard.get_mode() == Volume) && is_from_single_instance()) switch (m_clipboard.get_mode())
paste_volumes_from_clipboard(); {
else case Volume:
paste_objects_from_clipboard(); {
} if (is_from_single_instance())
paste_volumes_from_clipboard();
bool Selection::is_clipboard_empty() break;
{ }
return m_clipboard.is_empty(); case Instance:
{
paste_objects_from_clipboard();
break;
}
}
} }
void Selection::update_valid() void Selection::update_valid()

View File

@ -138,19 +138,6 @@ public:
typedef std::set<int> InstanceIdxsList; typedef std::set<int> InstanceIdxsList;
typedef std::map<int, InstanceIdxsList> ObjectIdxsToInstanceIdxsMap; typedef std::map<int, InstanceIdxsList> 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 class Clipboard
{ {
Model m_model; Model m_model;
@ -168,6 +155,19 @@ private:
void set_mode(Selection::EMode mode) { m_mode = mode; } 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. // Volumes owned by GLCanvas3D.
GLVolumePtrs* m_volumes; GLVolumePtrs* m_volumes;
// Model, not owned. // Model, not owned.
@ -287,7 +287,8 @@ public:
void copy_to_clipboard(); void copy_to_clipboard();
void paste_from_clipboard(); void paste_from_clipboard();
bool is_clipboard_empty();
const Clipboard& get_clipboard() const { return m_clipboard; }
private: private:
void update_valid(); void update_valid();