2 #include "ScenarioCreationState.hpp"
4 #include <Scenario/Application/ScenarioEditionSettings.hpp>
5 #include <Scenario/Commands/Scenario/Creations/CreateEvent_State.hpp>
6 #include <Scenario/Commands/Scenario/Creations/CreateState.hpp>
7 #include <Scenario/Commands/Scenario/Displacement/MoveNewEvent.hpp>
8 #include <Scenario/Commands/Scenario/Displacement/MoveNewState.hpp>
9 #include <Scenario/Document/TimeSync/TimeSyncModel.hpp>
10 #include <Scenario/Palette/Transitions/AnythingTransitions.hpp>
11 #include <Scenario/Palette/Transitions/EventTransitions.hpp>
12 #include <Scenario/Palette/Transitions/IntervalTransitions.hpp>
13 #include <Scenario/Palette/Transitions/NothingTransitions.hpp>
14 #include <Scenario/Palette/Transitions/StateTransitions.hpp>
15 #include <Scenario/Palette/Transitions/TimeSyncTransitions.hpp>
17 #include <QFinalState>
21 template <
typename Scenario_T,
typename ToolPalette_T>
26 const ToolPalette_T& stateMachine,
const Scenario_T& scenarioPath,
29 stateMachine, stack, scenarioPath, parent}
31 this->setObjectName(
"ScenarioCreation_FromNothing");
32 using namespace Scenario::Command;
33 auto finalState =
new QFinalState{
this};
34 QObject::connect(finalState, &QState::entered, [&]() { this->clearCreatedIds(); });
36 auto mainState =
new QState{
this};
37 mainState->setObjectName(
"Main state");
39 auto pressed =
new QState{mainState};
40 auto released =
new QState{mainState};
41 auto move_nothing =
new StrongQState<MoveOnNothing>{mainState};
42 auto move_state =
new StrongQState<MoveOnState>{mainState};
43 auto move_event =
new StrongQState<MoveOnEvent>{mainState};
44 auto move_timesync =
new StrongQState<MoveOnTimeSync>{mainState};
46 pressed->setObjectName(
"Pressed");
47 released->setObjectName(
"Released");
48 move_nothing->setObjectName(
"Move on Nothing");
49 move_state->setObjectName(
"Move on State");
50 move_event->setObjectName(
"Move on Event");
51 move_timesync->setObjectName(
"Move on Sync");
54 mainState->setInitialState(pressed);
55 released->addTransition(finalState);
58 score::make_transition<ReleaseOnAnything_Transition>(mainState, released);
61 score::make_transition<MoveOnNothing_Transition<Scenario_T>>(
62 pressed, move_nothing, *
this);
66 score::make_transition<MoveOnNothing_Transition<Scenario_T>>(
67 move_nothing, move_nothing, *
this);
70 this->add_transition(move_nothing, move_state, [&]() {
76 this->add_transition(move_nothing, move_event, [&]() {
82 this->add_transition(move_nothing, move_timesync, [&]() {
89 this->add_transition(move_state, move_nothing, [&]() {
98 this->add_transition(move_state, move_event, [&]() {
104 this->add_transition(move_state, move_timesync, [&]() {
111 this->add_transition(move_event, move_nothing, [&]() {
117 this->add_transition(move_event, move_state, [&]() {
123 score::make_transition<MoveOnEvent_Transition<Scenario_T>>(
124 move_event, move_event, *
this);
127 this->add_transition(move_event, move_timesync, [&]() {
134 this->add_transition(move_timesync, move_nothing, [&]() {
140 this->add_transition(move_timesync, move_state, [&]() {
146 this->add_transition(move_timesync, move_event, [&]() {
152 score::make_transition<MoveOnTimeSync_Transition<Scenario_T>>(
153 move_timesync, move_timesync, *
this);
156 QObject::connect(pressed, &QState::entered, [&]() {
157 this->currentPoint.date = stateMachine.magnetic().getPosition(
158 &stateMachine.model(), this->currentPoint.date);
159 this->m_clickedPoint = this->currentPoint;
161 this->clickedEvent = this->m_parentSM.model().startEvent().id();
165 QObject::connect(move_nothing, &QState::entered, [&]() {
166 if(this->createdIntervals.empty() || this->createdEvents.empty())
172 this->currentPoint.date = stateMachine.magnetic().getPosition(
173 &stateMachine.model(), this->currentPoint.date);
175 if(this->clickedEvent != this->m_parentSM.model().startEvent().id()
176 && this->currentPoint.date <= this->m_clickedPoint.date)
178 this->currentPoint.date = this->m_clickedPoint.date + TimeVal::fromMsecs(10);
181 this->clickedEvent == this->m_parentSM.model().startEvent().id()
182 && this->currentPoint.date <= TimeVal::fromMsecs(10))
184 this->currentPoint.date = TimeVal::fromMsecs(10);
188 this->m_dispatcher.template submit<MoveNewEvent>(
189 this->m_scenario, this->createdIntervals.last(), this->createdEvents.last(),
190 this->currentPoint.date, this->currentPoint.y,
191 settings.tool() == Tool::CreateSequence);
194 QObject::connect(move_timesync, &QState::entered, [&]() {
195 if(this->createdStates.empty())
201 if(this->currentPoint.date <= this->m_clickedPoint.date)
206 this->m_dispatcher.template submit<MoveNewState>(
207 this->m_scenario, this->createdStates.last(), this->currentPoint.y);
210 QObject::connect(move_event, &QState::entered, [&]() {
211 if(this->createdStates.empty())
217 if(this->currentPoint.date <= this->m_clickedPoint.date)
222 this->m_dispatcher.template submit<MoveNewState>(
223 this->m_scenario, this->createdStates.last(), this->currentPoint.y);
226 QObject::connect(released, &QState::entered,
this, &Creation_FromNothing::commit);
229 auto rollbackState =
new QState{
this};
230 rollbackState->setObjectName(
"Rollback");
231 score::make_transition<score::Cancel_Transition>(mainState, rollbackState);
232 rollbackState->addTransition(finalState);
235 rollbackState, &QState::entered,
this, &Creation_FromNothing::rollback);
237 this->setInitialState(mainState);
241 void createInitialState()
243 if(this->clickedEvent)
246 this->m_scenario, *this->clickedEvent, this->currentPoint.y};
247 this->m_dispatcher.submit(cmd);
249 this->createdStates.append(cmd->createdState());
253 void createToNothing()
255 createInitialState();
256 this->createToNothing_base(this->createdStates.first());
260 SCORE_ASSERT(
bool(this->hoveredState));
262 const auto& state = this->m_parentSM.model().states.at(*this->hoveredState);
263 if(!
bool(state.previousInterval()))
265 createInitialState();
266 this->createToState_base(this->createdStates.first());
271 if(this->hoveredEvent != this->clickedEvent)
273 createInitialState();
274 this->createToEvent_base(this->createdStates.first());
277 void createToTimeSync()
279 createInitialState();
280 this->createToTimeSync_base(this->createdStates.first());
Definition: CreateState.hpp:22
Definition: ScenarioCreation_FromNothing.hpp:23
Creation_FromNothing(const ToolPalette_T &stateMachine, const Scenario_T &scenarioPath, const score::CommandStackFacade &stack, QState *parent)
Definition: ScenarioCreation_FromNothing.hpp:25
Definition: ScenarioCreationState.hpp:66
Definition: ScenarioEditionSettings.hpp:14
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