WIP Undo / Redo : serialization / deserialization of object selection.

This commit is contained in:
bubnikv 2019-07-04 14:35:04 +02:00
parent 5a2ace1a6e
commit 1798e2a84c
6 changed files with 85 additions and 58 deletions

View file

@ -1645,6 +1645,7 @@ private:
void update_fff_scene();
void update_sla_scene();
void update_after_undo_redo();
// path to project file stored with no extension
wxString m_project_filename;
@ -3497,22 +3498,26 @@ void Plater::priv::show_action_buttons(const bool is_ready_to_slice) const
void Plater::priv::undo()
{
if (this->undo_redo_stack.undo(model, const_cast<GUI::Selection&>(view3D->get_canvas3d()->get_selection()))) {
this->update(false);
//YS_FIXME update obj_list from the deserialized model (maybe store ObjectIDs into the tree?)
// wxGetApp().obj_list()->update_selections();
// selection_changed();
}
if (this->undo_redo_stack.undo(model))
this->update_after_undo_redo();
}
void Plater::priv::redo()
{
if (this->undo_redo_stack.redo(model, const_cast<GUI::Selection&>(view3D->get_canvas3d()->get_selection()))) {
this->update(false);
//YS_FIXME update obj_list from the deserialized model (maybe store ObjectIDs into the tree?)
if (this->undo_redo_stack.redo(model))
this->update_after_undo_redo();
}
void Plater::priv::update_after_undo_redo()
{
this->view3D->get_canvas3d()->get_selection().clear();
this->update(false); // update volumes from the deserializd model
//YS_FIXME update obj_list from the deserialized model (maybe store ObjectIDs into the tree?) (no selections at this point of time)
this->view3D->get_canvas3d()->get_selection().set_deserialized(GUI::Selection::EMode(this->undo_redo_stack.selection_deserialized().mode), this->undo_redo_stack.selection_deserialized().volumes_and_instances);
// wxGetApp().obj_list()->update_selections();
// selection_changed();
}
//FIXME what about the state of the manipulators?
//FIXME what about the focus? Cursor in the side panel?
}
void Sidebar::set_btn_label(const ActionButtonType btn_type, const wxString& label) const

View file

@ -311,6 +311,24 @@ void Selection::add_all()
this->set_bounding_boxes_dirty();
}
void Selection::set_deserialized(EMode mode, const std::vector<std::pair<ObjectID, ObjectID>> &volumes_and_instances)
{
if (! m_valid)
return;
m_mode = mode;
for (unsigned int i : m_list)
(*m_volumes)[i]->selected = false;
m_list.clear();
for (unsigned int i = 0; i < (unsigned int)m_volumes->size(); ++ i) {
const GLVolume::CompositeID &id = (*m_volumes)[i]->composite_id;
if (std::binary_search(volumes_and_instances.begin(), volumes_and_instances.end(), std::make_pair<ObjectID, ObjectID>(id.volume_id, id.instance_id)))
this->do_add_volume(i);
}
update_type();
this->set_bounding_boxes_dirty();
}
void Selection::clear()
{
if (!m_valid)

View file

@ -3,7 +3,6 @@
#include <set>
#include "libslic3r/Geometry.hpp"
#include "libslic3r/ObjectID.hpp"
#include "3DScene.hpp"
#if ENABLE_RENDER_SELECTION_CENTER
@ -67,7 +66,7 @@ private:
Enum m_value;
};
class Selection : public Slic3r::ObjectBase
class Selection
{
public:
typedef std::set<unsigned int> IndicesList;
@ -238,6 +237,9 @@ public:
void add_all();
// To be called after Undo or Redo once the volumes are updated.
void set_deserialized(EMode mode, const std::vector<std::pair<ObjectID, ObjectID>> &volumes_and_instances);
// Update the selection based on the new instance IDs.
void instances_changed(const std::vector<size_t> &instance_ids_selected);
// Update the selection based on the map from old indices to new indices after m_volumes changed.