EventModel.hpp
1 #pragma once
2 #include <State/Expression.hpp>
3 
4 #include <Process/TimeValue.hpp>
5 
6 #include <Scenario/Document/Event/ExecutionStatus.hpp>
7 #include <Scenario/Document/Metatypes.hpp>
8 
9 #include <score/model/Component.hpp>
10 #include <score/model/EntityImpl.hpp>
11 #include <score/model/IdentifiedObject.hpp>
12 #include <score/model/Identifier.hpp>
13 #include <score/selection/Selectable.hpp>
14 #include <score/tools/Metadata.hpp>
15 #include <score/tools/std/Optional.hpp>
16 
17 #include <score_plugin_scenario_export.h>
18 
19 #include <verdigris>
20 class DataStream;
21 class JSONObject;
22 class QObject;
23 
24 namespace Process
25 {
26 struct Style;
27 }
28 
29 namespace Scenario
30 {
31 class StateModel;
32 class ScenarioInterface;
33 class TimeSyncModel;
34 
35 class SCORE_PLUGIN_SCENARIO_EXPORT EventModel final : public score::Entity<EventModel>
36 {
37  W_OBJECT(EventModel)
38 
39  SCORE_SERIALIZE_FRIENDS
40 
41 public:
43  Selectable selection{this};
44 
46  EventModel(
47  const Id<EventModel>&, const Id<TimeSyncModel>& timesync, const TimeVal& date,
48  QObject* parent);
49 
50  template <typename DeserializerVisitor>
51  EventModel(DeserializerVisitor&& vis, QObject* parent)
52  : Entity{vis, parent}
53  {
54  vis.writeTo(*this);
55  }
56 
57  // Timenode
58  void changeTimeSync(const Id<TimeSyncModel>& elt);
59  const Id<TimeSyncModel>& timeSync() const noexcept { return m_timeSync; }
60 
61  // States
62  void addState(const Id<StateModel>& ds);
63  void removeState(const Id<StateModel>& ds);
64  void clearStates();
65  using StateIdVec = ossia::small_vector<Id<StateModel>, 2>;
66  const StateIdVec& states() const noexcept;
67 
68  // Other properties
69  const State::Expression& condition() const noexcept;
70  OffsetBehavior offsetBehavior() const noexcept;
71  const TimeVal& date() const noexcept;
72  void translate(const TimeVal& deltaTime);
73  ExecutionStatus status() const noexcept;
74 
75  bool active() const noexcept;
76 
77  void setCondition(const State::Expression& arg);
78  void setDate(const TimeVal& date);
79  void setStatus(Scenario::ExecutionStatus status, const Scenario::ScenarioInterface&);
80  void setOffsetBehavior(Scenario::OffsetBehavior);
81 
82  const QBrush& color(const Process::Style&) const noexcept;
83 
84 public:
85  void dateChanged(const TimeVal& arg_1)
86  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, dateChanged, arg_1)
87  void conditionChanged(const State::Expression& arg_1)
88  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, conditionChanged, arg_1)
89  void statesChanged() E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, statesChanged)
90  void statusChanged(Scenario::ExecutionStatus status)
91  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, statusChanged, status)
92  void offsetBehaviorChanged(OffsetBehavior arg_1)
93  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, offsetBehaviorChanged, arg_1)
94  void
95  timeSyncChanged(Id<Scenario::TimeSyncModel> oldt, Id<Scenario::TimeSyncModel> newt)
96  E_SIGNAL(SCORE_PLUGIN_SCENARIO_EXPORT, timeSyncChanged, oldt, newt)
97 
98 private:
99  Id<TimeSyncModel> m_timeSync;
100  StateIdVec m_states;
101  State::Expression m_condition;
102  TimeVal m_date{TimeVal::zero()};
103 
104  ExecutionStatusProperty m_status{};
105  OffsetBehavior m_offset{};
106 
107  W_PROPERTY(
108  Scenario::OffsetBehavior,
109  offsetBehavior READ offsetBehavior WRITE setOffsetBehavior NOTIFY
110  offsetBehaviorChanged,
111  W_Final)
112 };
113 }
114 
115 DEFAULT_MODEL_METADATA(Scenario::EventModel, "Event")
116 TR_TEXT_METADATA(, Scenario::EventModel, PrettyName_k, "Event")
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: EventModel.hpp:36
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
Definition: TimeValue.hpp:21