3 #include <Scenario/Commands/Scenario/Creations/CreateEvent_State.hpp>
4 #include <Scenario/Commands/Scenario/Creations/CreateState.hpp>
5 #include <Scenario/Commands/Scenario/Displacement/MoveNewEvent.hpp>
6 #include <Scenario/Commands/Scenario/Displacement/MoveNewState.hpp>
7 #include <Scenario/Document/TimeSync/TimeSyncModel.hpp>
8 #include <Scenario/Palette/Tools/States/ScenarioCreationState.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};
35 mainState->setObjectName(
"Main state");
37 auto pressed =
new QState{mainState};
38 auto released =
new QState{mainState};
39 auto move_nothing =
new StrongQState<MoveOnNothing>{mainState};
40 auto move_state =
new StrongQState<MoveOnState>{mainState};
41 auto move_event =
new StrongQState<MoveOnEvent>{mainState};
42 auto move_timesync =
new StrongQState<MoveOnTimeSync>{mainState};
44 pressed->setObjectName(
"Pressed");
45 released->setObjectName(
"Released");
46 move_nothing->setObjectName(
"Move on Nothing");
47 move_state->setObjectName(
"Move on State");
48 move_event->setObjectName(
"Move on Event");
49 move_timesync->setObjectName(
"Move on Sync");
52 mainState->setInitialState(pressed);
53 released->addTransition(finalState);
56 score::make_transition<ReleaseOnAnything_Transition>(mainState, released);
59 score::make_transition<MoveOnNothing_Transition<Scenario_T>>(
60 pressed, move_nothing, *
this);
64 score::make_transition<MoveOnNothing_Transition<Scenario_T>>(
65 move_nothing, move_nothing, *
this);
68 this->add_transition(move_nothing, move_state, [&]() {
74 this->add_transition(move_nothing, move_event, [&]() {
80 this->add_transition(move_nothing, move_timesync, [&]() {
87 this->add_transition(move_state, move_nothing, [&]() {
96 this->add_transition(move_state, move_event, [&]() {
102 this->add_transition(move_state, move_timesync, [&]() {
109 this->add_transition(move_event, move_nothing, [&]() {
115 this->add_transition(move_event, move_state, [&]() {
121 score::make_transition<MoveOnEvent_Transition<Scenario_T>>(
122 move_event, move_event, *
this);
125 this->add_transition(move_event, move_timesync, [&]() {
132 this->add_transition(move_timesync, move_nothing, [&]() {
138 this->add_transition(move_timesync, move_state, [&]() {
144 this->add_transition(move_timesync, move_event, [&]() {
150 score::make_transition<MoveOnTimeSync_Transition<Scenario_T>>(
151 move_timesync, move_timesync, *
this);
154 QObject::connect(pressed, &QState::entered, [&]() {
155 this->m_clickedPoint = this->currentPoint;
158 createInitialState();
162 QObject::connect(move_nothing, &QState::entered, [&]() {
163 if(this->createdIntervals.empty() || this->createdEvents.empty())
169 if(this->currentPoint.date <= this->m_clickedPoint.date)
171 this->currentPoint.date = this->m_clickedPoint.date + TimeVal::fromMsecs(10);
175 this->currentPoint.date = stateMachine.magnetic().getPosition(
176 &stateMachine.model(), this->currentPoint.date);
178 this->m_dispatcher.template submit<MoveNewEvent>(
179 this->m_scenario, this->createdIntervals.last(), this->createdEvents.last(),
180 this->currentPoint.date, this->currentPoint.y,
181 stateMachine.editionSettings().tool() == Tool::CreateSequence);
184 QObject::connect(move_timesync, &QState::entered, [&]() {
185 if(this->createdStates.empty())
191 if(this->currentPoint.date <= this->m_clickedPoint.date)
196 this->m_dispatcher.template submit<MoveNewState>(
197 this->m_scenario, this->createdStates.last(), this->currentPoint.y);
200 QObject::connect(move_event, &QState::entered, [&]() {
201 if(this->createdStates.empty())
207 if(this->currentPoint.date <= this->m_clickedPoint.date)
212 this->m_dispatcher.template submit<MoveNewState>(
213 this->m_scenario, this->createdStates.last(), this->currentPoint.y);
216 QObject::connect(released, &QState::entered,
this, &Creation_FromEvent::commit);
219 auto rollbackState =
new QState{
this};
220 rollbackState->setObjectName(
"Rollback");
221 score::make_transition<score::Cancel_Transition>(mainState, rollbackState);
222 rollbackState->addTransition(finalState);
224 rollbackState, &QState::entered,
this, &Creation_FromEvent::rollback);
226 this->setInitialState(mainState);
230 void createInitialState()
232 if(this->clickedEvent)
235 this->m_scenario, *this->clickedEvent, this->currentPoint.y};
236 this->m_dispatcher.submit(cmd);
238 this->createdStates.append(cmd->createdState());
242 void createToNothing()
244 createInitialState();
245 this->createToNothing_base(this->createdStates.first());
250 createInitialState();
251 this->createToState_base(this->createdStates.first());
257 if(this->hoveredEvent != this->clickedEvent)
259 createInitialState();
260 this->createToEvent_base(this->createdStates.first());
264 void createToTimeSync()
266 createInitialState();
267 this->createToTimeSync_base(this->createdStates.first());
Definition: CreateState.hpp:22
Definition: ScenarioCreation_FromEvent.hpp:22
Creation_FromEvent(const ToolPalette_T &stateMachine, const Scenario_T &scenarioPath, const score::CommandStackFacade &stack, QState *parent)
Definition: ScenarioCreation_FromEvent.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