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