Loading...
Searching...
No Matches
ScenarioSelectionState.hpp
1#pragma once
2#include <Scenario/Document/Event/EventView.hpp>
3#include <Scenario/Document/Interval/Temporal/TemporalIntervalView.hpp>
4#include <Scenario/Document/State/StateView.hpp>
5#include <Scenario/Document/TimeSync/TimeSyncView.hpp>
6#include <Scenario/Palette/Tools/StateSelection.hpp>
7#include <Scenario/Process/ScenarioGlobalCommandManager.hpp>
8
9#include <score/statemachine/CommonSelectionState.hpp>
10
11#include <QPointF>
12
13namespace Scenario
14{
15class ToolPalette;
16class ScenarioPresenter;
17template <typename ToolPalette_T, typename View_T>
19{
20private:
21 QPointF m_initialPoint;
22 QPointF m_movePoint;
23 const ToolPalette_T& m_parentSM;
24 View_T& m_scenarioView;
25
26public:
28 score::SelectionStack& stack, const ToolPalette_T& parentSM, View_T& scenarioview,
29 QState* parent)
30 : CommonSelectionState{stack, &scenarioview, parent}
31 , m_parentSM{parentSM}
32 , m_scenarioView{scenarioview}
33 {
34 }
35
36 const QPointF& initialPoint() const { return m_initialPoint; }
37 const QPointF& movePoint() const { return m_movePoint; }
38
39 void on_pressAreaSelection() override { m_initialPoint = m_parentSM.scenePoint; }
40
41 void on_moveAreaSelection() override
42 {
43 m_movePoint = m_parentSM.scenePoint;
44 auto area
45 = QRectF{m_scenarioView.mapFromScene(m_initialPoint), m_scenarioView.mapFromScene(m_movePoint)}
46 .normalized();
47 m_scenarioView.setSelectionArea(area);
48 setSelectionArea(area);
49 }
50
51 void on_releaseAreaSelection() override
52 {
53 if(m_parentSM.scenePoint == m_initialPoint)
54 {
55 dispatcher.deselect();
56 dispatcher.select(m_parentSM.model());
57 }
58
59 m_scenarioView.setSelectionArea(QRectF{});
60 }
61
62 void on_deselect() override
63 {
64 dispatcher.deselect();
65 m_scenarioView.setSelectionArea(QRectF{});
66 }
67
68 void setSelectionArea(const QRectF& area)
69 {
70 using namespace std;
71 Selection sel;
72
73 auto& presenter = m_parentSM.presenter();
74 auto& model = m_parentSM.model();
75
76 for(const auto& elt : presenter.getIntervals())
77 {
78 if(area.intersects(elt.view()->boundingRect().translated(elt.view()->pos())))
79 {
80 sel.append(elt.model());
81 }
82 }
83
84 if constexpr(std::is_same_v<
85 std::remove_const_t<std::remove_reference_t<decltype(presenter)>>,
87 {
88 for(const auto& elt : presenter.getGraphIntervals())
89 {
90 if(area.intersects(elt.boundingRect().translated(elt.pos())))
91 {
92 sel.append(elt.model());
93 }
94 }
95 }
96
97 for(const auto& elt : presenter.getTimeSyncs())
98 {
99 if(area.intersects(elt.view()->boundingRect().translated(elt.view()->pos())))
100 {
101 sel.append(elt.model());
102 }
103 else if(
104 elt.model().active()
105 && area.intersects(elt.trigger().boundingRect().translated(elt.view()->pos())))
106 {
107 sel.append(elt.model());
108 }
109 }
110 for(const auto& elt : presenter.getEvents())
111 {
112 if(area.intersects(elt.view()->boundingRect().translated(elt.view()->pos())))
113 {
114 sel.append(elt.model());
115 }
116 else if(
117 elt.view()->conditionItem().isVisible()
118 && area.intersects(
119 elt.view()->conditionItem().boundingRect().translated(elt.view()->pos())))
120 {
121 sel.append(elt.model());
122 }
123 }
124 for(const auto& elt : presenter.getStates())
125 {
126 auto& m = elt.model();
127 if(area.intersects(elt.view()->boundingRect().translated(elt.view()->pos())))
128 {
129 doStateSelection(sel, m, model);
130 }
131 }
132
133 dispatcher.select(
134 filterSelections(sel, m_parentSM.model().selectedChildren(), multiSelection()));
135 }
136};
137}
The CommonSelectionState class.
Definition CommonSelectionState.hpp:27
Definition ScenarioPresenter.hpp:29
Definition ScenarioSelectionState.hpp:19
Definition Selection.hpp:12
The SelectionStack class.
Definition SelectionStack.hpp:24
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13
STL namespace.