2 #include "ScenarioCreationState.hpp"
4 #include <Scenario/Application/ScenarioEditionSettings.hpp>
5 #include <Scenario/Commands/Scenario/Creations/CreateInterval.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/Tools/ScenarioRollbackStrategy.hpp>
11 #include <Scenario/Palette/Transitions/AnythingTransitions.hpp>
12 #include <Scenario/Palette/Transitions/EventTransitions.hpp>
13 #include <Scenario/Palette/Transitions/IntervalTransitions.hpp>
14 #include <Scenario/Palette/Transitions/NothingTransitions.hpp>
15 #include <Scenario/Palette/Transitions/StateTransitions.hpp>
16 #include <Scenario/Palette/Transitions/TimeSyncTransitions.hpp>
17 #include <Scenario/Process/Algorithms/Accessors.hpp>
19 #include <QApplication>
20 #include <QFinalState>
24 template <
typename Scenario_T,
typename ToolPalette_T>
29 const ToolPalette_T& stateMachine,
const Scenario_T& scenarioPath,
32 stateMachine, stack, std::move(scenarioPath), parent}
34 using namespace Scenario::Command;
35 auto finalState =
new QFinalState{
this};
36 QObject::connect(finalState, &QState::entered, [&]() { this->clearCreatedIds(); });
38 auto mainState =
new QState{
this};
40 auto pressed =
new QState{mainState};
41 auto released =
new QState{mainState};
42 auto move_nothing =
new StrongQState<MoveOnNothing>{mainState};
43 auto move_state =
new StrongQState<MoveOnState>{mainState};
44 auto move_event =
new StrongQState<MoveOnEvent>{mainState};
45 auto move_timesync =
new StrongQState<MoveOnTimeSync>{mainState};
48 mainState->setInitialState(pressed);
49 released->addTransition(finalState);
52 score::make_transition<ReleaseOnAnything_Transition>(mainState, released);
55 score::make_transition<MoveOnNothing_Transition<Scenario_T>>(
56 pressed, move_state, *
this);
57 score::make_transition<MoveOnNothing_Transition<Scenario_T>>(
58 pressed, move_nothing, *
this);
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, [&]() {
78 this->add_transition(move_nothing, move_timesync, [&]() {
85 this->add_transition(move_state, move_nothing, [&]() {
94 this->add_transition(move_state, move_event, [&]() {
100 this->add_transition(move_state, move_timesync, [&]() {
107 this->add_transition(move_event, move_nothing, [&]() {
113 this->add_transition(move_event, move_state, [&]() {
114 if(this->clickedState && this->hoveredState)
116 if(this->m_parentSM.model().state(*this->clickedState).eventId()
117 != this->m_parentSM.model().state(*this->hoveredState).eventId())
126 score::make_transition<MoveOnEvent_Transition<Scenario_T>>(
127 move_event, move_event, *
this);
130 this->add_transition(move_event, move_timesync, [&]() {
137 this->add_transition(move_timesync, move_nothing, [&]() {
143 this->add_transition(move_timesync, move_state, [&]() {
149 this->add_transition(move_timesync, move_event, [&]() {
155 score::make_transition<MoveOnTimeSync_Transition<Scenario_T>>(
156 move_timesync, move_timesync, *
this);
159 QObject::connect(pressed, &QState::entered, [&]() {
160 this->m_clickedPoint = this->currentPoint;
164 QObject::connect(move_nothing, &QState::entered, [&]() {
165 if(this->createdIntervals.empty() || this->createdEvents.empty())
173 if(settings.tool() == Scenario::Tool::CreateGraph)
175 this->m_dispatcher.template submit<MoveNewEvent>(
176 this->m_scenario, this->createdIntervals.last(),
177 this->createdEvents.last(), this->currentPoint.date, this->currentPoint.y,
182 this->currentPoint.date = stateMachine.magnetic().getPosition(
183 &stateMachine.model(), this->currentPoint.date);
185 if(this->currentPoint.date <= this->m_clickedPoint.date)
187 this->currentPoint.date = this->m_clickedPoint.date + TimeVal::fromMsecs(10);
191 auto sequence = settings.tool() == Tool::CreateSequence;
194 if(this->clickedState)
196 const auto& st = this->m_parentSM.model().state(*this->clickedState);
197 this->currentPoint.y = st.heightPercentage();
201 this->m_dispatcher.template submit<MoveNewEvent>(
202 this->m_scenario, this->createdIntervals.last(), this->createdEvents.last(),
203 this->currentPoint.date, this->currentPoint.y, sequence);
206 QObject::connect(move_event, &QState::entered, [&]() {
207 if(this->createdStates.empty())
214 if(this->currentPoint.date <= this->m_clickedPoint.date)
219 this->m_dispatcher.template submit<MoveNewState>(
220 this->m_scenario, this->createdStates.last(), this->currentPoint.y);
223 QObject::connect(move_timesync, &QState::entered, [&]() {
224 if(this->createdStates.empty())
231 if(this->currentPoint.date <= this->m_clickedPoint.date)
236 this->m_dispatcher.template submit<MoveNewState>(
237 this->m_scenario, this->createdStates.last(), this->currentPoint.y);
240 QObject::connect(released, &QState::entered,
this, &Creation_FromState::commit);
243 auto rollbackState =
new QState{
this};
244 score::make_transition<score::Cancel_Transition>(mainState, rollbackState);
245 rollbackState->addTransition(finalState);
248 rollbackState, &QState::entered,
this, &Creation_FromState::rollback);
249 this->setInitialState(mainState);
253 template <
typename Fun>
254 void creationCheck(Fun&& fun)
256 const auto& scenar = this->m_parentSM.model();
257 if(!this->clickedState)
260 const bool sequence = settings.tool() == Tool::CreateSequence;
261 const bool new_event = qApp->keyboardModifiers() & Qt::ALT;
262 const bool graph_interval = settings.tool() == Scenario::Tool::CreateGraph;
263 auto& st = scenar.state(*this->clickedState);
264 auto& ev = Scenario::parentEvent(st, scenar);
265 if(ev.date() > this->currentPoint.date && !graph_interval)
268 if(new_event && !sequence)
271 auto tn = ev.timeSync();
273 this->m_scenario, tn, this->currentPoint.y};
274 this->m_dispatcher.submit(cmd);
276 this->createdEvents.append(cmd->createdEvent());
277 this->createdStates.append(cmd->createdState());
278 fun(this->createdStates.first());
286 this->m_scenario, st.eventId(), this->currentPoint.y};
287 this->m_dispatcher.submit(cmd);
289 this->createdStates.append(cmd->createdState());
290 fun(this->createdStates.first());
294 if(!st.nextInterval())
296 this->currentPoint.y = st.heightPercentage();
297 fun(*this->clickedState);
303 this->m_scenario, st.eventId(), this->currentPoint.y};
304 this->m_dispatcher.submit(cmd);
306 this->createdStates.append(cmd->createdState());
307 fun(this->createdStates.first());
315 void createToNothing()
317 creationCheck([&](
const Id<StateModel>&
id) { this->createToNothing_base(
id); });
320 void createToTimeSync()
322 creationCheck([&](
const Id<StateModel>&
id) { this->createToTimeSync_base(
id); });
327 if(this->clickedState)
329 if(this->hoveredEvent
330 == this->m_parentSM.model().state(*this->clickedState).eventId())
336 creationCheck([&](
const Id<StateModel>&
id) { this->createToEvent_base(
id); });
343 if(this->hoveredState)
345 auto& st = this->m_parentSM.model().states.at(*this->hoveredState);
346 if(!st.previousInterval())
350 creationCheck([&](
const Id<StateModel>&
id) { this->createToState_base(
id); });
356 this->hoveredEvent = st.eventId();
357 creationCheck([&](
const Id<StateModel>&
id) { this->createToEvent_base(
id); });
Definition: CreateEvent_State.hpp:25
Definition: CreateState.hpp:22
Definition: ScenarioCreation_FromState.hpp:26
Creation_FromState(const ToolPalette_T &stateMachine, const Scenario_T &scenarioPath, const score::CommandStackFacade &stack, QState *parent)
Definition: ScenarioCreation_FromState.hpp:28
Definition: ScenarioCreationState.hpp:66
Definition: ScenarioEditionSettings.hpp:14
The id_base_t class.
Definition: Identifier.hpp:57
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