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
96 void Reset()
97 {
98 m_step = 0;
100 }
101
105 bool IsComplete() const
106 {
107 return m_step == getMaxStep();
108 }
109
117 {
118 return m_lastPoint;
119 }
120
125 {
126 return m_changed;
127 }
128
134 {
135 m_changed = false;
136 }
137
138protected:
139
142 {
143 m_changed = true;
144 }
145
147 int getStep() const
148 {
149 return m_step;
150 }
151
152private:
153
156 virtual bool acceptPoint( const VECTOR2I& aPt ) = 0;
157
162 virtual int getMaxStep() const = 0;
163
165 void performStep( bool aForward )
166 {
167 m_step += aForward ? 1 : -1;
168
169 // clamp to allowed values
170 m_step = std::clamp( m_step, 0, getMaxStep() );
171 }
172
174 bool m_changed = false;
175
178
182 int m_step = 0;
183};
184
185} // PREVIEW
186} // KIGFX
187
188#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...
void Reset()
Reset the manager to the initial state.
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683