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

@ -4,6 +4,8 @@
#include <memory>
#include <string>
#include <libslic3r/ObjectID.hpp>
namespace Slic3r {
class Model;
@ -27,6 +29,13 @@ struct Snapshot
bool operator==(const Snapshot &rhs) const { return this->timestamp == rhs.timestamp; }
};
// Excerpt of Slic3r::GUI::Selection for serialization onto the Undo / Redo stack.
struct Selection : public Slic3r::ObjectBase {
unsigned char mode;
std::vector<std::pair<ObjectID, ObjectID>> volumes_and_instances;
template<class Archive> void serialize(Archive &ar) { ar(mode, volumes_and_instances); }
};
class StackImpl;
class Stack
@ -42,14 +51,18 @@ public:
// Store the current application state onto the Undo / Redo stack, remove all snapshots after m_active_snapshot_time.
void take_snapshot(const std::string &snapshot_name, const Slic3r::Model &model, const Slic3r::GUI::Selection &selection);
void load_snapshot(size_t timestamp, Slic3r::Model &model, Slic3r::GUI::Selection &selection);
void load_snapshot(size_t timestamp, Slic3r::Model &model);
bool undo(Slic3r::Model &model, Slic3r::GUI::Selection &selection);
bool redo(Slic3r::Model &model, Slic3r::GUI::Selection &selection);
bool undo(Slic3r::Model &model);
bool redo(Slic3r::Model &model);
// Snapshot history (names with timestamps).
const std::vector<Snapshot>& snapshots() const;
// After load_snapshot() / undo() / redo() the selection is deserialized into a list of ObjectIDs, which needs to be converted
// into the list of GLVolume pointers once the 3D scene is updated.
const Selection& selection_deserialized() const;
private:
friend class StackImpl;
std::unique_ptr<StackImpl> pimpl;