Loading...
Searching...
No Matches
CurveCommandObjectBase.hpp
1#pragma once
2#include <Curve/Segment/CurveSegmentData.hpp>
3
4#include <score/command/Dispatchers/SingleOngoingCommandDispatcher.hpp>
5#include <score/model/Identifier.hpp>
6#include <score/model/path/Path.hpp>
7#include <score/tools/IdentifierGeneration.hpp>
8#include <score/tools/std/Optional.hpp>
9
10#include <ossia/detail/hash_map.hpp>
11
12#include <QByteArray>
13#include <QPoint>
14#include <QVector>
15
16#include <score_plugin_curve_export.h>
17
18#include <span>
19#include <vector>
20
21namespace score
22{
23class CommandStackFacade;
24} // namespace score
25
26/*
27concept CommandObject
28{
29 public:
30 void instantiate();
31 void update();
32 void commit();
33 void rollback();
34};
35*/
36// CreateSegment
37// CreateSegmentBetweenPoints
38
39// RemoveSegment -> easy peasy
40// RemovePoint -> which segment do we merge ? At the left or at the right ?
41// A point(view) has pointers to one or both of its curve segments.
42
43namespace Curve
44{
45class UpdateCurve;
46class Model;
47class Presenter;
48class StateBase;
49class SegmentModel;
50
52void checkValidity(std::span<const SegmentData> segts);
53
56SCORE_PLUGIN_CURVE_EXPORT
57void createPointAt(std::vector<SegmentData>& segments, Curve::Point pt);
58
62SCORE_PLUGIN_CURVE_EXPORT
63std::vector<SegmentData> removeSegments(
64 const Model& model, const ossia::hash_set<int32_t>& removed, bool fill);
65
66class SCORE_PLUGIN_CURVE_EXPORT CommandObjectBase
67{
68public:
70 const Model& model, Presenter* pres, const score::CommandStackFacade&);
71 virtual ~CommandObjectBase();
72
73 void setCurveState(Curve::StateBase* stateBase) { m_state = stateBase; }
74 void press();
75
76 void handleLocking();
77
78protected:
79 // Creates and pushes an UpdateCurve command
80 // from a vector of segments.
81 // They are removed afterwards
82 void submit(const std::vector<SegmentData>&);
83
84 auto find(std::vector<SegmentData>& segments, const OptionalId<SegmentModel>& id)
85 {
86 return std::find_if(
87 segments.begin(), segments.end(), [&](const auto& seg) { return seg.id == id; });
88 }
89 auto find(const std::vector<SegmentData>& segments, const OptionalId<SegmentModel>& id)
90 {
91 return std::find_if(segments.cbegin(), segments.cend(), [&](const auto& seg) {
92 return seg.id == id;
93 });
94 }
95
96 virtual void on_press() = 0;
97
98 QPointF m_originalPress; // Note : there should be only one per curve...
99
100 const Model& m_model;
101 Presenter* m_presenter{};
102
103 Curve::StateBase* m_state{};
104
106
107 std::vector<SegmentData> m_startSegments;
109 std::vector<SegmentData> m_segments;
110
111 // To prevent behind locked at 0.000001 or 0.9999
112 double m_xmin{-1}, m_xmax{2}, m_xLastPoint{2};
113};
114}
Definition CurveCommandObjectBase.hpp:67
std::vector< SegmentData > m_segments
The curve being submitted: kept across moves for its storage.
Definition CurveCommandObjectBase.hpp:109
Definition CurveModel.hpp:26
Definition CurvePresenter.hpp:34
Definition CurvePaletteBaseStates.hpp:20
The SingleOngoingCommandDispatcher class.
Definition SingleOngoingCommandDispatcher.hpp:18
A small abstraction layer over the score::CommandStack.
Definition CommandStackFacade.hpp:21
Utilities and base classes for 1D curves.
Definition FocusDispatcher.hpp:12
void checkValidity(std::span< const SegmentData > segts)
Debug builds: asserts that segts is a valid curve.
Definition CurveCommandObjectBase.cpp:99
std::vector< SegmentData > removeSegments(const Model &model, const ossia::hash_set< int32_t > &removed, bool fill)
Definition CurveCommandObjectBase.cpp:281
void createPointAt(std::vector< SegmentData > &segments, Curve::Point pt)
Definition CurveCommandObjectBase.cpp:152
Base toolkit upon which the software is built.
Definition Application.cpp:83