KiCad PCB EDA Suite
Loading...
Searching...
No Matches
multistep_geom_manager.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef PREVIEW_ITEMS_MULTISTEP_GEOMETRY_MANAGER_H
21#define PREVIEW_ITEMS_MULTISTEP_GEOMETRY_MANAGER_H
22
23#include <math/vector2d.h>
24#include <algorithm>
25#include <core/kicad_algo.h>
26
27namespace KIGFX {
28namespace PREVIEW {
29
44{
45public:
47 {}
48
57 void AddPoint( const VECTOR2I& aPt, bool aLockIn )
58 {
59 // hold onto the raw point separately to the managed geometry
60 m_lastPoint = aPt;
61
62 // update the geometry
63 bool accepted = acceptPoint( aPt );
64
65 // advance or regress the manager
66 if( aLockIn )
67 performStep( accepted );
68
70 }
71
76 {
77 performStep( false );
78
79 // process the last point again, but in the previous step mode it doesn't matter if
80 // accepted or not, as long as the geometry is regenerated if needed.
83 }
84
88 bool IsReset() const
89 {
90 return m_step == 0;
91 }
92
99 virtual void Reset()
100 {
101 m_step = 0;
104 }
105
109 bool IsComplete() const
110 {
111 return m_step == getMaxStep();
112 }
113
121 {
122 return m_lastPoint;
123 }
124
129 {
130 return m_changed;
131 }
132
138 {
139 m_changed = false;
140 }
141
142protected:
143
146 {
147 m_changed = true;
148 }
149
151 int getStep() const
152 {
153 return m_step;
154 }
155
156private:
157
160 virtual bool acceptPoint( const VECTOR2I& aPt ) = 0;
161
166 virtual int getMaxStep() const = 0;
167
169 void performStep( bool aForward )
170 {
171 m_step += aForward ? 1 : -1;
172
173 // clamp to allowed values
174 m_step = std::clamp( m_step, 0, getMaxStep() );
175 }
176
178 bool m_changed = false;
179
182
186 int m_step = 0;
187};
188
189} // PREVIEW
190} // KIGFX
191
192#endif // PREVIEW_ITEMS_MULTIPOINT_GEOMETRY_MANAGER_H
A geometry manager that works by accepting a sequence of points and advancing though stages of geomet...
int m_step
The current manager step, from 0 to some highest number that depends on the manager.
VECTOR2I GetLastPoint() const
Get the last point added (locked in or not).
void AddPoint(const VECTOR2I &aPt, bool aLockIn)
Add a point to the construction manager.
void RemoveLastPoint()
Undo the last point, and move the manager back to the previous step.
void setGeometryChanged()
< Mark the geometry as changed for clients to notice
bool m_changed
The last (raw) point added, which is usually the cursor position.
virtual bool acceptPoint(const VECTOR2I &aPt)=0
< Function that accepts a point for a stage, or rejects it to return to the previous stage
void ClearGeometryChanged()
Clear the geometry changed flag, call after the client code has updated everything as needed.
void performStep(bool aForward)
Has the geometry changed such that a client should redraw?
virtual int getMaxStep() const =0
The highest step this manager has - used to recognize completion and to clamp the step as it advances...
virtual void Reset()
Reset the manager to the initial state.
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683