2 #include <Scenario/Commands/Scenario/Displacement/MoveEventMeta.hpp>
3 #include <Scenario/Commands/Scenario/Merge/MergeEvents.hpp>
4 #include <Scenario/Document/Event/EventPresenter.hpp>
5 #include <Scenario/Document/Event/EventView.hpp>
6 #include <Scenario/Document/Interval/Temporal/TemporalIntervalPresenter.hpp>
7 #include <Scenario/Document/Interval/Temporal/TemporalIntervalView.hpp>
8 #include <Scenario/Document/State/StatePresenter.hpp>
9 #include <Scenario/Document/State/StateView.hpp>
10 #include <Scenario/Document/TimeSync/TimeSyncPresenter.hpp>
11 #include <Scenario/Document/TimeSync/TimeSyncView.hpp>
12 #include <Scenario/Document/TimeSync/TriggerView.hpp>
13 #include <Scenario/Palette/ScenarioPaletteBaseStates.hpp>
14 #include <Scenario/Palette/Tools/ScenarioRollbackStrategy.hpp>
15 #include <Scenario/Palette/Transitions/AnythingTransitions.hpp>
16 #include <Scenario/Palette/Transitions/EventTransitions.hpp>
17 #include <Scenario/Palette/Transitions/IntervalTransitions.hpp>
18 #include <Scenario/Palette/Transitions/NothingTransitions.hpp>
19 #include <Scenario/Palette/Transitions/TimeSyncTransitions.hpp>
20 #include <Scenario/Process/Algorithms/Accessors.hpp>
22 #include <score/command/Dispatchers/MultiOngoingCommandDispatcher.hpp>
23 #include <score/command/Dispatchers/SingleOngoingCommandDispatcher.hpp>
24 #include <score/locking/ObjectLocker.hpp>
26 #include <QApplication>
27 #include <QFinalState>
32 typename MoveBraceCommand_T,
33 typename Scenario_T,
typename ToolPalette_T>
38 const ToolPalette_T& stateMachine,
const Scenario_T& scenarioPath,
44 this->setObjectName(
"MoveIntervalBraceState");
45 using namespace Scenario::Command;
46 auto finalState =
new QFinalState{
this};
48 auto mainState =
new QState{
this};
50 auto pressed =
new QState{mainState};
51 auto released =
new QState{mainState};
52 auto moving =
new QState{mainState};
54 mainState->setInitialState(pressed);
55 released->addTransition(finalState);
57 score::make_transition<MoveOnAnything_Transition<Scenario_T>>(
58 pressed, moving, *
this);
59 score::make_transition<ReleaseOnAnything_Transition>(pressed, finalState);
61 score::make_transition<MoveOnAnything_Transition<Scenario_T>>(
62 moving, moving, *
this);
63 score::make_transition<ReleaseOnAnything_Transition>(moving, released);
65 QObject::connect(pressed, &QState::entered, [&]() {
66 this->m_initialDate = this->currentPoint.date;
67 if(this->clickedInterval)
69 auto& scenar = stateMachine.model();
70 auto& cstr = scenar.interval(*this->clickedInterval);
71 this->m_initialDuration
73 .*MoveBraceCommand_T::corresponding_member)();
80 QObject::connect(moving, &QState::entered, [&]() {
81 if(this->clickedInterval)
83 auto& scenar = stateMachine.model();
84 auto& cstr = scenar.interval(*this->clickedInterval);
85 auto date = this->currentPoint.date - *m_initialDate + *m_initialDuration;
87 date = stateMachine.magnetic().getPosition(&stateMachine.model(), date);
89 this->m_dispatcher.submit(cstr, date,
false);
94 released, &QState::entered, [&]() { this->m_dispatcher.commit(); });
97 auto rollbackState =
new QState{
this};
98 score::make_transition<score::Cancel_Transition>(mainState, rollbackState);
99 rollbackState->addTransition(finalState);
101 rollbackState, &QState::entered, [&]() { m_dispatcher.rollback(); });
103 this->setInitialState(mainState);
108 std::optional<TimeVal> m_initialDate;
109 std::optional<TimeVal> m_initialDuration;
113 typename MoveTimeSyncCommand_T,
114 typename Scenario_T,
typename ToolPalette_T>
119 const ToolPalette_T& stateMachine,
const Scenario_T& scenarioPath,
123 , m_dispatcher{stack}
125 this->setObjectName(
"MoveTimeSyncState");
126 using namespace Scenario::Command;
127 auto finalState =
new QFinalState{
this};
129 auto mainState =
new QState{
this};
131 auto pressed =
new QState{mainState};
132 auto released =
new QState{mainState};
133 auto moving =
new QState{mainState};
136 mainState->setInitialState(pressed);
137 released->addTransition(finalState);
139 score::make_transition<MoveOnAnything_Transition<Scenario_T>>(
140 pressed, moving, *
this);
141 score::make_transition<ReleaseOnAnything_Transition>(pressed, finalState);
142 score::make_transition<MoveOnAnything_Transition<Scenario_T>>(
143 moving, moving, *
this);
144 score::make_transition<ReleaseOnAnything_Transition>(moving, released);
147 QObject::connect(pressed, &QState::entered, [&]() {
148 if(!this->clickedTimeSync)
151 auto& scenar = stateMachine.model();
154 = previousNonGraphIntervals(scenar.timeSync(*this->clickedTimeSync), scenar);
155 if(!prev_csts.empty())
159 for(
const auto& cst_id : prev_csts)
161 const auto& other_date = scenar.interval(cst_id).date();
165 this->m_pressedPrevious = t;
169 this->m_pressedPrevious = std::nullopt;
173 QObject::connect(moving, &QState::entered, [&]() {
174 if(!this->clickedTimeSync)
178 auto& scenar = stateMachine.model();
179 auto& tn = scenar.timeSync(*this->clickedTimeSync);
180 SCORE_ASSERT(!tn.events().empty());
181 const auto& ev_id = tn.events().front();
182 auto date = this->currentPoint.date;
184 date = stateMachine.magnetic().getPosition(&stateMachine.model(), date);
186 if(this->m_pressedPrevious)
188 date = max(date, *this->m_pressedPrevious);
192 this->m_scenario, ev_id, date, this->currentPoint.y,
193 stateMachine.editionSettings().expandMode(),
194 stateMachine.editionSettings().lockMode());
197 QObject::connect(released, &QState::entered, [&]() {
198 m_dispatcher.commit();
199 m_pressedPrevious = {};
203 auto rollbackState =
new QState{
this};
204 score::make_transition<score::Cancel_Transition>(mainState, rollbackState);
205 rollbackState->addTransition(finalState);
207 rollbackState, &QState::entered, [&]() { m_dispatcher.rollback(); });
209 this->setInitialState(mainState);
213 std::optional<TimeVal> m_pressedPrevious;
Definition: MoveStates.hpp:35
Definition: MoveStates.hpp:116
Definition: ScenarioPaletteBaseStates.hpp:20
A small abstraction layer over the score::CommandStack.
Definition: CommandStackFacade.hpp:20
The ObjectLocker class.
Definition: ObjectLocker.hpp:21
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Definition: TimeValue.hpp:21