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};
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);