plugins/score-plugin-nodal/Nodal/commands.hpp
1 #pragma once
2 #include <Process/ProcessList.hpp>
3 
4 #include <Scenario/Document/ScenarioDocument/ScenarioDocumentModel.hpp>
5 
6 #include <Dataflow/Commands/CableHelpers.hpp>
7 #include <Nodal/CommandFactory.hpp>
8 #include <Nodal/Process.hpp>
9 
10 #include <score/application/ApplicationContext.hpp>
11 #include <score/command/AggregateCommand.hpp>
12 #include <score/command/PropertyCommand.hpp>
13 #include <score/document/DocumentContext.hpp>
14 #include <score/plugins/SerializableHelpers.hpp>
15 #include <score/tools/IdentifierGeneration.hpp>
16 
17 namespace Nodal
18 {
19 class Model;
20 
22 {
23  SCORE_COMMAND_DECL(CommandFactoryName(), DropNodesMacro, "Drop nodes")
24 };
25 
26 class CreateNode final : public score::Command
27 {
28  SCORE_COMMAND_DECL(CommandFactoryName(), CreateNode, "Create a node")
29 public:
30  CreateNode(
31  const Nodal::Model& process, QPointF position,
32  const UuidKey<Process::ProcessModel>& uuid, const QString& dat);
33 
34  void undo(const score::DocumentContext& ctx) const override;
35  void redo(const score::DocumentContext& ctx) const override;
36 
37  const Id<Process::ProcessModel>& nodeId() const noexcept { return m_createdNodeId; }
38 
39 protected:
40  void serializeImpl(DataStreamInput&) const override;
41  void deserializeImpl(DataStreamOutput&) override;
42 
43 private:
44  Path<Nodal::Model> m_path;
45  QPointF m_pos;
47  QString m_data;
48 
49  Id<Process::ProcessModel> m_createdNodeId;
50 };
51 
52 class RemoveNode final : public score::Command
53 {
54  SCORE_COMMAND_DECL(CommandFactoryName(), RemoveNode, "Remove a node")
55 public:
56  RemoveNode(const Nodal::Model& p, const Process::ProcessModel& n);
57 
58 private:
59  void undo(const score::DocumentContext& ctx) const override;
60 
61  void redo(const score::DocumentContext& ctx) const override;
62 
63  void serializeImpl(DataStreamInput& s) const override;
64 
65  void deserializeImpl(DataStreamOutput& s) override;
66 
67  Path<Nodal::Model> m_path;
69  QByteArray m_block;
70  Dataflow::SerializedCables m_cables;
71 };
72 
74 {
75  SCORE_COMMAND_DECL(CommandFactoryName(), RemoveNodes, "Remove nodes")
76 };
77 
78 class ReplaceAllNodes final : public score::Command
79 {
80  SCORE_COMMAND_DECL(CommandFactoryName(), ReplaceAllNodes, "Replace all nodes")
81 public:
82  // Expected data format: see Nodal::Model::savePreset
83  ReplaceAllNodes(const Nodal::Model& p, const QByteArray& new_data);
84 
85  void undo(const score::DocumentContext& ctx) const override;
86  void redo(const score::DocumentContext& ctx) const override;
87 
88  void serializeImpl(DataStreamInput& s) const override;
89  void deserializeImpl(DataStreamOutput& s) override;
90 
91 private:
92  Path<Nodal::Model> m_path;
93  QByteArray m_old_block, m_new_block;
94  Dataflow::SerializedCables m_old_cables, m_new_cables;
95 };
96 }
Definition: plugins/score-plugin-nodal/Nodal/commands.hpp:27
Definition: plugins/score-plugin-nodal/Nodal/commands.hpp:22
Definition: score-plugin-nodal/Nodal/Process.hpp:14
Definition: plugins/score-plugin-nodal/Nodal/commands.hpp:53
Definition: plugins/score-plugin-nodal/Nodal/commands.hpp:74
Definition: plugins/score-plugin-nodal/Nodal/commands.hpp:79
The Process class.
Definition: score-lib-process/Process/Process.hpp:61
The id_base_t class.
Definition: Identifier.hpp:57
Allows for grouping of multiple commands in a single one.
Definition: AggregateCommand.hpp:15
The Command class.
Definition: Command.hpp:34
Definition: DataStreamHelpers.hpp:99
Definition: DataStreamHelpers.hpp:103
Definition: DocumentContext.hpp:18