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 (C) 2017-2023 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef PREVIEW_ITEMS_MULTISTEP_GEOMETRY_MANAGER_H
25#define PREVIEW_ITEMS_MULTISTEP_GEOMETRY_MANAGER_H
26
27#include <math/vector2d.h>
28#include <algorithm>
29#include <core/kicad_algo.h>
30
31namespace KIGFX {
32namespace PREVIEW {
33
48{
49public:
51 {}
52
61 void AddPoint( const VECTOR2I& aPt, bool aLockIn )
62 {
63 // hold onto the raw point separately to the managed geometry
64 m_lastPoint = aPt;
65
66 // update the geometry
67 bool accepted = acceptPoint( aPt );
68
69 // advance or regress the manager
70 if( aLockIn )
71 performStep( accepted );
72
74 }
75
80 {
81 performStep( false );
82
83 // process the last point again, but in the previous step mode it doesn't matter if
84 // accepted or not, as long as the geometry is regenerated if needed.
87 }
88
92 bool IsReset() const
93 {
94 return m_step == 0;
95 }
96
100 void Reset()
101 {
102 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...
void Reset()
Reset the manager to the initial state.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247