2 #include <Explorer/DocumentPlugin/DeviceDocumentPlugin.hpp>
3 #include <Explorer/Explorer/DeviceExplorerModel.hpp>
5 #include <Scenario/Commands/Scenario/Creations/CreateInterval.hpp>
6 #include <Scenario/Commands/Scenario/Creations/CreateInterval_State.hpp>
7 #include <Scenario/Commands/Scenario/Creations/CreateInterval_State_Event.hpp>
8 #include <Scenario/Commands/Scenario/Creations/CreateInterval_State_Event_TimeSync.hpp>
9 #include <Scenario/Commands/Scenario/Creations/CreateSequence.hpp>
10 #include <Scenario/Commands/Scenario/Creations/CreationMetaCommand.hpp>
11 #include <Scenario/Commands/State/AddMessagesToState.hpp>
12 #include <Scenario/Palette/ScenarioPaletteBaseStates.hpp>
13 #include <Scenario/Palette/ScenarioPaletteBaseTransitions.hpp>
14 #include <Scenario/Palette/Tool.hpp>
15 #include <Scenario/Palette/Tools/ScenarioRollbackStrategy.hpp>
16 #include <Scenario/Process/Algorithms/Accessors.hpp>
17 #include <Scenario/Settings/ScenarioSettingsModel.hpp>
18 #include <Scenario/Tools/elementFindingHelper.hpp>
20 #include <score/application/GUIApplicationContext.hpp>
21 #include <score/command/Dispatchers/MultiOngoingCommandDispatcher.hpp>
22 #include <score/document/DocumentInterface.hpp>
23 #include <score/selection/SelectionDispatcher.hpp>
34 static constexpr
auto value() {
return Value; }
38 this->setObjectName(debug_StateMachineIDs<Value>());
42 template <
typename Scenario_T>
48 QVector<Id<StateModel>> createdStates;
49 QVector<Id<EventModel>> createdEvents;
50 QVector<Id<TimeSyncModel>> createdTimeSyncs;
51 QVector<Id<IntervalModel>> createdIntervals;
53 void clearCreatedIds()
55 createdEvents.clear();
56 createdIntervals.clear();
57 createdTimeSyncs.clear();
58 createdStates.clear();
64 template <
typename Scenario_T,
typename ToolPalette_T>
70 const Scenario_T& scenarioPath, QState* parent)
80 if(this->hoveredState)
82 const bool graphal = isCreatingGraph();
83 const bool differentParents
84 = Scenario::parentEvent(originalState, m_parentSM.model()).timeSync()
85 != Scenario::parentEvent(*this->hoveredState, m_parentSM.model()).timeSync();
87 if(graphal && differentParents)
90 this->m_scenario, originalState, *this->hoveredState,
true};
92 m_dispatcher.submit(cmd);
94 this->createdIntervals.append(cmd->createdInterval());
100 if(getDate(m_parentSM.model(), originalState)
101 < getDate(m_parentSM.model(), *this->hoveredState))
104 this->m_scenario, originalState, *this->hoveredState};
106 m_dispatcher.submit(cmd);
108 this->createdIntervals.append(cmd->createdInterval());
116 if(this->hoveredEvent)
118 const bool graphal = isCreatingGraph();
119 const bool differentParents
120 = Scenario::parentEvent(originalState, m_parentSM.model()).timeSync()
121 != m_parentSM.model().event(*this->hoveredEvent).timeSync();
122 const bool timeIsInOrder = getDate(m_parentSM.model(), originalState)
123 < getDate(m_parentSM.model(), *this->hoveredEvent);
126 if((graphal || timeIsInOrder) && differentParents)
129 this->m_scenario, originalState, *this->hoveredEvent, this->currentPoint.y,
132 m_dispatcher.submit(cmd);
134 this->createdIntervals.append(cmd->createdInterval());
135 this->createdStates.append(cmd->createdState());
142 if(this->hoveredTimeSync)
144 const bool graphal = isCreatingGraph();
145 const bool differentParents
146 = Scenario::parentEvent(originalState, m_parentSM.model()).timeSync()
147 != *this->hoveredTimeSync;
148 const bool timeIsInOrder = getDate(m_parentSM.model(), originalState)
149 < getDate(m_parentSM.model(), *this->hoveredTimeSync);
152 if((graphal || timeIsInOrder) && differentParents)
155 this->m_scenario, originalState, *this->hoveredTimeSync,
156 this->currentPoint.y, graphal};
158 m_dispatcher.submit(cmd);
160 this->createdStates.append(cmd->createdState());
161 this->createdEvents.append(cmd->createdEvent());
162 this->createdIntervals.append(cmd->createdInterval());
169 if(m_parentSM.editionSettings().tool() != Tool::CreateSequence)
174 this->currentPoint.date, this->currentPoint.y, isCreatingGraph()};
176 m_dispatcher.submit(cmd);
178 this->createdStates.append(cmd->createdState());
179 this->createdEvents.append(cmd->createdEvent());
180 this->createdTimeSyncs.append(cmd->createdTimeSync());
181 this->createdIntervals.append(cmd->createdInterval());
187 auto cmd = Scenario::Command::CreateSequence::make(
188 this->m_parentSM.context().context, this->m_parentSM.model(),
190 this->currentPoint.date, this->currentPoint.y);
192 m_dispatcher.submitQuiet(cmd);
194 this->createdStates.append(cmd->createdState());
195 this->createdEvents.append(cmd->createdEvent());
196 this->createdTimeSyncs.append(cmd->createdTimeSync());
197 this->createdIntervals.append(cmd->createdInterval());
207 using namespace Command;
208 if(m_parentSM.editionSettings().tool() == Tool::CreateSequence)
211 if(this->createdStates.empty())
214 if(!this->createdIntervals.empty())
216 const auto& cst = m_parentSM.model().intervals.at(this->createdIntervals.last());
217 if(!cst.processes.empty())
226 auto& device_explorer
227 = ctx.template plugin<Explorer::DeviceDocumentPlugin>().explorer();
229 State::MessageList messages = getSelectionSnapshot(device_explorer);
233 m_dispatcher.submit(
new AddMessagesToState{
234 m_parentSM.model().states.at(this->createdStates.last()), messages});
237 template <
typename DestinationState,
typename Function>
238 void add_transition(QState* from, DestinationState* to, Function&& fun)
240 using transition_type =
Transition_T<Scenario_T, DestinationState::value()>;
241 auto trans = score::make_transition<transition_type>(from, to, *
this);
242 trans->setObjectName(QString::number(DestinationState::value()));
243 QObject::connect(trans, &transition_type::triggered,
this, fun);
248 this->makeSnapshot();
249 this->m_dispatcher.template commit<Scenario::Command::CreationMetaCommand>();
253 if(!this->createdStates.empty())
255 auto& s = this->createdStates.back();
256 auto sp = m_parentSM.model().states.find(s);
257 if(sp == m_parentSM.model().states.end())
259 qDebug() <<
"Error: tried to select state but it did not exist";
267 if(!this->createdIntervals.empty())
269 auto& i = this->createdIntervals.back();
270 auto ip = m_parentSM.model().intervals.find(i);
271 if(ip == m_parentSM.model().intervals.end())
273 qDebug() <<
"Error: tried to select interval but it did not exist";
283 this->clearCreatedIds();
288 m_dispatcher.template rollback<ScenarioRollbackStrategy>();
289 this->clearCreatedIds();
292 inline bool isCreatingGraph()
const noexcept
294 return this->m_parentSM.editionSettings().tool() == Scenario::Tool::CreateGraph;
297 const ToolPalette_T& m_parentSM;
The MultiOngoingCommandDispatcher class.
Definition: MultiOngoingCommandDispatcher.hpp:33
Definition: CreateInterval_State_Event_TimeSync.hpp:30
Definition: CreateInterval_State_Event.hpp:26
Definition: CreateInterval_State.hpp:26
The CreateEventAfterEventCommand class.
Definition: CreateInterval.hpp:33
Definition: ScenarioCreationState.hpp:44
Definition: ScenarioCreationState.hpp:66
Definition: ScenarioSettingsModel.hpp:19
Definition: ScenarioPaletteBaseStates.hpp:20
Definition: ScenarioCreationState.hpp:32
Definition: ScenarioPaletteBaseTransitions.hpp:23
Definition: Selection.hpp:12
The id_base_t class.
Definition: Identifier.hpp:57
A small abstraction layer over the score::CommandStack.
Definition: CommandStackFacade.hpp:20
The SelectionDispatcher class.
Definition: SelectionDispatcher.hpp:15
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Definition: ScenarioPoint.hpp:13
T & settings() const
Access a specific Settings model instance.
Definition: ApplicationContext.hpp:40
Definition: DocumentContext.hpp:18