2 #include "ScenarioCreationState.hpp"
4 #include <Scenario/Commands/Scenario/Creations/CreateInterval.hpp>
5 #include <Scenario/Commands/Scenario/Displacement/MoveEventMeta.hpp>
6 #include <Scenario/Commands/Scenario/Displacement/MoveNewEvent.hpp>
7 #include <Scenario/Document/TimeSync/TimeSyncModel.hpp>
8 #include <Scenario/Palette/Tools/ScenarioRollbackStrategy.hpp>
9 #include <Scenario/Palette/Transitions/AnythingTransitions.hpp>
10 #include <Scenario/Palette/Transitions/EventTransitions.hpp>
11 #include <Scenario/Palette/Transitions/IntervalTransitions.hpp>
12 #include <Scenario/Palette/Transitions/NothingTransitions.hpp>
13 #include <Scenario/Palette/Transitions/StateTransitions.hpp>
14 #include <Scenario/Palette/Transitions/TimeSyncTransitions.hpp>
16 #include <QFinalState>
20 template <
typename Scenario_T,
typename ToolPalette_T>
25 const ToolPalette_T& stateMachine,
const Scenario_T& scenarioPath,
28 stateMachine, stack, std::move(scenarioPath), parent}
30 using namespace Scenario::Command;
31 auto finalState =
new QFinalState{
this};
32 QObject::connect(finalState, &QState::entered, [&]() { this->clearCreatedIds(); });
34 auto mainState =
new QState{
this};
36 auto pressed =
new QState{mainState};
37 auto released =
new QState{mainState};
38 auto move_nothing =
new StrongQState<MoveOnNothing>{mainState};
39 auto move_state =
new StrongQState<MoveOnState>{mainState};
40 auto move_event =
new StrongQState<MoveOnEvent>{mainState};
41 auto move_timesync =
new StrongQState<MoveOnTimeSync>{mainState};
44 mainState->setInitialState(pressed);
45 released->addTransition(finalState);
48 score::make_transition<ReleaseOnAnything_Transition>(mainState, released);
51 auto t_pressed_moving_nothing
52 = score::make_transition<MoveOnNothing_Transition<Scenario_T>>(
53 pressed, move_nothing, *
this);
55 QObject::connect(t_pressed_moving_nothing, &QAbstractTransition::triggered, [&]() {
62 score::make_transition<MoveOnNothing_Transition<Scenario_T>>(
63 move_nothing, move_nothing, *
this);
66 this->add_transition(move_nothing, move_state, [&]() {
72 this->add_transition(move_nothing, move_event, [&]() {
73 if(this->hoveredEvent && this->createdEvents.contains(*this->hoveredEvent))
83 this->add_transition(move_nothing, move_timesync, [&]() {
84 if(this->hoveredTimeSync
85 && this->createdTimeSyncs.contains(*this->hoveredTimeSync))
95 this->add_transition(move_state, move_nothing, [&]() {
104 this->add_transition(move_state, move_event, [&]() {
110 this->add_transition(move_state, move_timesync, [&]() {
117 this->add_transition(move_event, move_nothing, [&]() {
123 this->add_transition(move_event, move_state, [&]() {
129 score::make_transition<MoveOnEvent_Transition<Scenario_T>>(
130 move_event, move_event, *
this);
133 this->add_transition(move_event, move_timesync, [&]() {
134 if(this->hoveredTimeSync
135 && this->createdTimeSyncs.contains(*this->hoveredTimeSync))
145 this->add_transition(move_timesync, move_nothing, [&]() {
151 this->add_transition(move_timesync, move_state, [&]() {
157 this->add_transition(move_timesync, move_event, [&]() {
158 if(this->hoveredEvent && this->createdEvents.contains(*this->hoveredEvent))
168 score::make_transition<MoveOnTimeSync_Transition<Scenario_T>>(
169 move_timesync, move_timesync, *
this);
172 QObject::connect(pressed, &QState::entered, [&]() {
173 this->m_clickedPoint = this->currentPoint;
174 createInitialEventAndState();
177 QObject::connect(move_nothing, &QState::entered, [&]() {
178 if(this->createdEvents.empty() || this->createdIntervals.empty())
184 this->currentPoint.date = stateMachine.magnetic().getPosition(
185 &stateMachine.model(), this->currentPoint.date);
187 if(this->currentPoint.date <= this->m_clickedPoint.date)
189 this->currentPoint.date = this->m_clickedPoint.date + TimeVal::fromMsecs(10);
194 this->m_dispatcher.template submit<MoveNewEvent>(
195 this->m_scenario, this->createdIntervals.last(), this->createdEvents.last(),
196 this->currentPoint.date, this->currentPoint.y,
197 stateMachine.editionSettings().tool() == Tool::CreateSequence);
200 QObject::connect(move_timesync, &QState::entered, [&]() {
201 if(this->createdEvents.empty())
207 if(this->currentPoint.date <= this->m_clickedPoint.date)
212 this->m_dispatcher.template submit<MoveEventMeta>(
213 this->m_scenario, this->createdEvents.last(), TimeVal::zero(), 0.,
214 stateMachine.editionSettings().expandMode(), LockMode::Free);
217 QObject::connect(released, &QState::entered,
this, &Creation_FromTimeSync::commit);
220 auto rollbackState =
new QState{
this};
221 score::make_transition<score::Cancel_Transition>(mainState, rollbackState);
222 rollbackState->addTransition(finalState);
224 rollbackState, &QState::entered,
this, &Creation_FromTimeSync::rollback);
226 this->setInitialState(mainState);
230 void createInitialEventAndState()
232 if(this->clickedTimeSync)
234 auto cmd =
new Command::CreateEvent_State{
235 this->m_scenario, *this->clickedTimeSync, this->currentPoint.y};
236 this->m_dispatcher.submit(cmd);
238 this->createdStates.append(cmd->createdState());
239 this->createdEvents.append(cmd->createdEvent());
243 void createToNothing()
245 createInitialEventAndState();
246 this->createToNothing_base(this->createdStates.first());
250 createInitialEventAndState();
251 this->createToState_base(this->createdStates.first());
255 createInitialEventAndState();
256 this->createToEvent_base(this->createdStates.first());
258 void createToTimeSync()
261 createInitialEventAndState();
262 this->createToTimeSync_base(this->createdStates.first());
Definition: ScenarioCreation_FromTimeSync.hpp:22
Creation_FromTimeSync(const ToolPalette_T &stateMachine, const Scenario_T &scenarioPath, const score::CommandStackFacade &stack, QState *parent)
Definition: ScenarioCreation_FromTimeSync.hpp:24
Definition: ScenarioCreationState.hpp:66
A small abstraction layer over the score::CommandStack.
Definition: CommandStackFacade.hpp:20
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14