KiCad PCB EDA Suite
Loading...
Searching...
No Matches
point_editor_behavior.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, 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
25#pragma once
26
27#include <wx/debug.h>
28
29#include <eda_shape.h>
30#include <tool/edit_points.h>
31
32class SHAPE_POLY_SET;
33
43{
44public:
45 virtual ~POINT_EDIT_BEHAVIOR() = default;
46
53 virtual void MakePoints( EDIT_POINTS& aPoints ) = 0;
54
68 virtual void UpdatePoints( EDIT_POINTS& aPoints ) = 0;
69
86 virtual void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
87 std::vector<EDA_ITEM*>& aUpdatedItems ) = 0;
88
96 virtual OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint,
97 EDIT_POINTS& aPoints ) const
98 {
99 // By default, no constrainer is defined and the caller must decide
100 return std::nullopt;
101 }
102
103protected:
107 static bool isModified( const EDIT_POINT& aEditedPoint, const EDIT_POINT& aPoint )
108 {
109 return &aEditedPoint == &aPoint;
110 }
111};
112
113// Helper macros to check the number of points in the edit points object
114// Still a bug, but at least it won't segfault if the number of points is wrong
115#define CHECK_POINT_COUNT( aPoints, aExpected ) \
116 wxCHECK( aPoints.PointsSize() == aExpected, /* void */ )
117#define CHECK_POINT_COUNT_GE( aPoints, aExpected ) \
118 wxCHECK( aPoints.PointsSize() >= aExpected, /* void */ )
119
120
129{
130public:
132
136 static void BuildForPolyOutline( EDIT_POINTS& aPoints, const SHAPE_POLY_SET& aOutline );
137
143 static void UpdatePointsFromOutline( const SHAPE_POLY_SET& aOutline, EDIT_POINTS& aPoints );
144
148 static void UpdateOutlineFromPoints( SHAPE_POLY_SET& aOutline, const EDIT_POINT& aEditedPoint,
149 EDIT_POINTS& aPoints );
150
151 void MakePoints( EDIT_POINTS& aPoints ) override
152 {
153 BuildForPolyOutline( aPoints, m_polygon );
154 }
155
156 void UpdatePoints( EDIT_POINTS& aPoints ) override
157 {
159 }
160
161 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
162 std::vector<EDA_ITEM*>& aUpdatedItems ) override
163 {
164 UpdateOutlineFromPoints( m_polygon, aEditedPoint, aPoints );
165 }
166
167private:
169};
170
171
179{
180public:
181 // Editing the underlying polygon shape in-place is enough
183 POLYGON_POINT_EDIT_BEHAVIOR( aPolygon.GetPolyShape() )
184 {
185 wxASSERT( aPolygon.GetShape() == SHAPE_T::POLY );
186 }
187};
188
189
194{
195public:
197 {
198 wxASSERT( aSegment.GetShape() == SHAPE_T::SEGMENT );
199 }
200
201 void MakePoints( EDIT_POINTS& aPoints ) override;
202
203 void UpdatePoints( EDIT_POINTS& aPoints ) override;
204
205 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
206 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
207
209 EDIT_POINTS& aPoints ) const override;
210
211protected:
213 {
216
218 };
219
220private:
222};
223
224
229{
230public:
232 {
233 wxASSERT( aCircle.GetShape() == SHAPE_T::CIRCLE );
234 }
235
236 void MakePoints( EDIT_POINTS& aPoints ) override;
237
238 void UpdatePoints( EDIT_POINTS& aPoints ) override;
239
240 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
241 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
242
244 EDIT_POINTS& aPoints ) const override;
245
246protected:
248 {
251
253 };
254
255private:
257};
258
259
264{
265public:
267 {
268 wxASSERT( aBezier.GetShape() == SHAPE_T::BEZIER );
269 }
270
271 void MakePoints( EDIT_POINTS& aPoints ) override;
272
273 void UpdatePoints( EDIT_POINTS& aPoints ) override;
274
275 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
276 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
277
278protected:
280 {
285
287 };
288
289private:
291};
292
293
302{
303public:
305 {
306 // While PCB_TEXTBOXES are not always RECTANGLEs, they are when they
307 // are TABLECELLs.
308 wxASSERT( aCell.GetShape() == SHAPE_T::RECTANGLE );
309 }
310
311 void MakePoints( EDIT_POINTS& aPoints ) override;
312
313 void UpdatePoints( EDIT_POINTS& aPoints ) override;
314
315protected:
317 {
320
322 };
323
324private:
326};
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition: commit.h:74
"Standard" bezier editing behavior for EDA_SHAPE beziers.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
EDA_BEZIER_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aBezier)
void UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
"Standard" circle editing behavior for EDA_SHAPE circles.
OPT_VECTOR2I Get45DegreeConstrainer(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints) const override
Get the 45-degree constrainer for the item, when the given point is moved.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
EDA_CIRCLE_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aCircle)
void UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
"Standard" polygon editing behavior for EDA_SHAPE polygons.
EDA_POLYGON_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aPolygon)
"Standard" segment editing behavior for EDA_SHAPE segments.
OPT_VECTOR2I Get45DegreeConstrainer(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints) const override
Get the 45-degree constrainer for the item, when the given point is moved.
void UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
EDA_SEGMENT_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aSegment)
SHAPE_T GetShape() const
Definition: eda_shape.h:132
"Standard" table-cell editing behavior.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
void UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
EDIT_POINTS is a VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
Definition: edit_points.h:353
Represent a single point that can be used for modifying items.
Definition: edit_points.h:48
A helper class interface to manage the edit points for a single item.
virtual OPT_VECTOR2I Get45DegreeConstrainer(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints) const
Get the 45-degree constrainer for the item, when the given point is moved.
virtual void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems)=0
Update the item with the new positions of the edit points.
virtual ~POINT_EDIT_BEHAVIOR()=default
virtual void MakePoints(EDIT_POINTS &aPoints)=0
Construct the initial set of edit points for the item and append to the given list.
static bool isModified(const EDIT_POINT &aEditedPoint, const EDIT_POINT &aPoint)
Checks if two points are the same instance - which means the point is being edited.
virtual void UpdatePoints(EDIT_POINTS &aPoints)=0
Update the list of the edit points for the item.
Class that implements "standard" polygon editing behavior.
static void UpdateOutlineFromPoints(SHAPE_POLY_SET &aOutline, const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints)
Update the polygon outline with the new positions of the edit points.
static void UpdatePointsFromOutline(const SHAPE_POLY_SET &aOutline, EDIT_POINTS &aPoints)
Update the edit points with the current polygon outline.
POLYGON_POINT_EDIT_BEHAVIOR(SHAPE_POLY_SET &aPolygon)
static void BuildForPolyOutline(EDIT_POINTS &aPoints, const SHAPE_POLY_SET &aOutline)
Build the edit points for the given polygon outline.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
void UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
void UpdateItem(const EDIT_POINT &aEditedPoint, EDIT_POINTS &aPoints, COMMIT &aCommit, std::vector< EDA_ITEM * > &aUpdatedItems) override
Update the item with the new positions of the edit points.
Represent a set of closed polygons.
std::optional< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:39