StateModel.hpp
1 #pragma once
2 #include <Process/Instantiations.hpp>
3 #include <Process/Process.hpp>
4 
5 #include <Scenario/Document/Event/EventModel.hpp>
6 #include <Scenario/Document/Event/ExecutionStatus.hpp>
7 #include <Scenario/Document/Metatypes.hpp>
8 #include <Scenario/Document/State/ItemModel/ControlItemModel.hpp>
9 #include <Scenario/Document/State/ItemModel/MessageItemModel.hpp>
10 
11 #include <score/model/Component.hpp>
12 #include <score/model/EntityImpl.hpp>
13 #include <score/model/IdentifiedObject.hpp>
14 #include <score/model/Identifier.hpp>
15 #include <score/selection/Selectable.hpp>
16 #include <score/serialization/VisitorInterface.hpp>
17 #include <score/tools/Metadata.hpp>
18 #include <score/tools/std/Optional.hpp>
19 
20 #include <nano_signal_slot.hpp>
21 #include <score_plugin_scenario_export.h>
22 
23 #include <list>
24 #include <set>
25 #include <vector>
26 #include <verdigris>
27 class DataStream;
28 class JSONObject;
29 namespace Process
30 {
31 class ProcessModel;
32 }
34 
35 namespace score
36 {
37 class CommandStackFacade;
38 }
39 namespace Scenario
40 {
41 class EventModel;
42 class IntervalModel;
43 class MessageItemModel;
44 class ProcessStateWrapper final : public QObject
45 {
46 private:
48 
49 public:
51  : m_proc{proc}
52  {
53  }
54  ~ProcessStateWrapper() override;
55 
56  ProcessStateDataInterface& process() const { return *m_proc; }
57 };
58 
59 // Model for the graphical state in a scenario.
60 class SCORE_PLUGIN_SCENARIO_EXPORT StateModel final
61  : public score::Entity<StateModel>
62  , public Nano::Observer
63 {
64  W_OBJECT(StateModel)
65 
66  SCORE_SERIALIZE_FRIENDS
67 public:
68  using ProcessVector = std::list<ProcessStateWrapper>;
69 
71  Selectable selection{this};
72 
73  StateModel(
74  const Id<StateModel>& id, const Id<EventModel>& eventId, double yPos,
75  const score::DocumentContext& ctx, QObject* parent);
76 
77  ~StateModel() override;
78 
79  // Load
80  template <IsDeserializer DeserializerVisitor>
81  StateModel(
82  DeserializerVisitor&& vis, const score::DocumentContext& ctx, QObject* parent)
83  : Entity{vis, parent}
84  , m_context{ctx}
85  {
86  vis.writeTo(*this);
87  init();
88  }
89 
90  const score::DocumentContext& context() const noexcept { return m_context; }
91 
92  double heightPercentage() const;
93 
94  MessageItemModel& messages() const;
95  ControlItemModel& controlMessages() const;
96 
97  const Id<EventModel>& eventId() const;
98  void setEventId(const Id<EventModel>&);
99 
100  const OptionalId<IntervalModel>& previousInterval() const;
101  const OptionalId<IntervalModel>& nextInterval() const;
102 
103  // Note : the added interval shall be in
104  // the scenario when this is called.
105  void setNextInterval(const OptionalId<IntervalModel>&);
106  void setPreviousInterval(const OptionalId<IntervalModel>&);
107 
108  ProcessVector& previousProcesses() { return m_previousProcesses; }
109  ProcessVector& followingProcesses() { return m_nextProcesses; }
110  const ProcessVector& previousProcesses() const { return m_previousProcesses; }
111  const ProcessVector& followingProcesses() const { return m_nextProcesses; }
112 
113  void setStatus(ExecutionStatus);
114  ExecutionStatus status() const { return m_status.get(); }
115 
116  void setHeightPercentage(double y);
117 
118  bool empty() const { return !messages().rootNode().hasChild(0); }
119 
120 public:
121  void sig_statesUpdated() E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, sig_statesUpdated)
122  void sig_controlMessagesUpdated()
123  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, sig_controlMessagesUpdated)
124 
125  void heightPercentageChanged()
126  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, heightPercentageChanged)
127  void statusChanged(Scenario::ExecutionStatus arg_1)
128  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, statusChanged, arg_1)
129 
130  void eventChanged(Id<Scenario::EventModel> oldev, Id<Scenario::EventModel> newev)
131  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, eventChanged, oldev, newev)
132 
133  PROPERTY(
134  double, heightPercentage READ heightPercentage WRITE setHeightPercentage NOTIFY
135  heightPercentageChanged)
136 private:
137  void statesUpdated_slt();
138  void init(); // TODO check if other model elements need an init method too.
139 
140  const score::DocumentContext& m_context;
141 
142  ProcessVector m_previousProcesses;
143  ProcessVector m_nextProcesses;
144  Id<EventModel> m_eventId;
145 
146  // OPTIMIZEME if we shift to Id = int, put this std::optional
147  OptionalId<IntervalModel> m_previousInterval;
148  OptionalId<IntervalModel> m_nextInterval;
149 
150  double m_heightPercentage{0.5}; // In the whole scenario
151 
152  MessageItemModel* m_messageItemModel{};
153  ControlItemModel* m_controlItemModel{};
154  ExecutionStatusProperty m_status{};
155 };
156 }
157 
158 DEFAULT_MODEL_METADATA(Scenario::StateModel, "State")
159 TR_TEXT_METADATA(, Scenario::StateModel, PrettyName_k, "State")
Definition: VisitorInterface.hpp:53
Definition: VisitorInterface.hpp:61
Metadata to get the name that will be shown in the user interface.
Definition: lib/score/tools/Metadata.hpp:42
Definition: ProcessStateDataInterface.hpp:24
Definition: ControlItemModel.hpp:14
The MessageItemModel class.
Definition: MessageItemModel.hpp:38
Definition: StateModel.hpp:45
Definition: StateModel.hpp:63
The Selectable class.
Definition: Selectable.hpp:14
The id_base_t class.
Definition: Identifier.hpp:57
Base for complex model objects.
Definition: EntityBase.hpp:24
Base classes and tools to implement processes and layers.
Definition: JSONVisitor.hpp:1324
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Utilities for OSSIA data structures.
Definition: DeviceInterface.hpp:33
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: ExecutionStatus.hpp:33
Definition: DocumentContext.hpp:18