KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 m_shape( aPolygon )
185 {
186 wxASSERT( aPolygon.GetShape() == SHAPE_T::POLY );
187 }
188
189 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
190 std::vector<EDA_ITEM*>& aUpdatedItems ) override
191 {
192 POLYGON_POINT_EDIT_BEHAVIOR::UpdateItem( aEditedPoint, aPoints, aCommit, aUpdatedItems );
194 }
195
196private:
198};
199
200
205{
206public:
208 {
209 wxASSERT( aSegment.GetShape() == SHAPE_T::SEGMENT );
210 }
211
212 void MakePoints( EDIT_POINTS& aPoints ) override;
213
214 void UpdatePoints( EDIT_POINTS& aPoints ) override;
215
216 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
217 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
218
220 EDIT_POINTS& aPoints ) const override;
221
222protected:
224 {
227
229 };
230
231private:
233};
234
235
240{
241public:
243 {
244 wxASSERT( aCircle.GetShape() == SHAPE_T::CIRCLE );
245 }
246
247 void MakePoints( EDIT_POINTS& aPoints ) override;
248
249 void UpdatePoints( EDIT_POINTS& aPoints ) override;
250
251 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
252 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
253
255 EDIT_POINTS& aPoints ) const override;
256
257protected:
259 {
262
264 };
265
266private:
268};
269
270
275{
276public:
278 {
279 wxASSERT( aBezier.GetShape() == SHAPE_T::BEZIER );
280 }
281
282 void MakePoints( EDIT_POINTS& aPoints ) override;
283
284 void UpdatePoints( EDIT_POINTS& aPoints ) override;
285
286 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
287 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
288
289protected:
291 {
296
298 };
299
300private:
302};
303
304
313{
314public:
316 {
317 // While PCB_TEXTBOXES are not always RECTANGLEs, they are when they
318 // are TABLECELLs.
319 wxASSERT( aCell.GetShape() == SHAPE_T::RECTANGLE );
320 }
321
322 void MakePoints( EDIT_POINTS& aPoints ) override;
323
324 void UpdatePoints( EDIT_POINTS& aPoints ) override;
325
326protected:
328 {
331
333 };
334
335private:
337};
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.
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_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:168
void SetHatchingDirty()
Definition: eda_shape.h:147
"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