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
51using SegmentMapImpl = ossia::hash_map<Id<SegmentModel>, SegmentData, CurveDataHash>;
52void checkValidity(std::span<SegmentData> segts);
53void checkValidity(SegmentMapImpl& segts);
54
55class SCORE_PLUGIN_CURVE_EXPORT CommandObjectBase
56{
57public:
59 const Model& model, Presenter* pres, const score::CommandStackFacade&);
60 virtual ~CommandObjectBase();
61
62 void setCurveState(Curve::StateBase* stateBase) { m_state = stateBase; }
63 void press();
64
65 void handleLocking();
66
67protected:
68 // Creates and pushes an UpdateCurve command
69 // from a vector of segments.
70 // They are removed afterwards
71 void submit(std::vector<SegmentData>&&);
72
73 auto find(std::vector<SegmentData>& segments, const OptionalId<SegmentModel>& id)
74 {
75 return std::find_if(
76 segments.begin(), segments.end(), [&](const auto& seg) { return seg.id == id; });
77 }
78 auto find(const std::vector<SegmentData>& segments, const OptionalId<SegmentModel>& id)
79 {
80 return std::find_if(segments.cbegin(), segments.cend(), [&](const auto& seg) {
81 return seg.id == id;
82 });
83 }
84
85 virtual void on_press() = 0;
86
87 QVector<QByteArray> m_oldCurveData;
88 QPointF m_originalPress; // Note : there should be only one per curve...
89
90 const Model& m_model;
91 Presenter* m_presenter{};
92
93 Curve::StateBase* m_state{};
94
96
97 std::vector<SegmentData> m_startSegments;
98
99 // To prevent behind locked at 0.000001 or 0.9999
100 double m_xmin{-1}, m_xmax{2}, m_xLastPoint{2};
101};
102}
Definition CurveCommandObjectBase.hpp:56
Definition CurveModel.hpp:25
Definition CurvePresenter.hpp:32
Definition CurvePaletteBaseStates.hpp:20
The SingleOngoingCommandDispatcher class.
Definition SingleOngoingCommandDispatcher.hpp:17
A small abstraction layer over the score::CommandStack.
Definition CommandStackFacade.hpp:20
Utilities and base classes for 1D curves.
Definition FocusDispatcher.hpp:12
Base toolkit upon which the software is built.
Definition Application.cpp:90