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 (C) 2024 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) wxCHECK( aPoints.PointsSize() == aExpected, /* void */ )
116#define CHECK_POINT_COUNT_GE(aPoints, aExpected) wxCHECK( aPoints.PointsSize() >= aExpected, /* void */ )
117
118
127{
128public:
130
134 static void BuildForPolyOutline( EDIT_POINTS& aPoints, const SHAPE_POLY_SET& aOutline );
135
141 static void UpdatePointsFromOutline( const SHAPE_POLY_SET& aOutline, EDIT_POINTS& aPoints );
142
146 static void UpdateOutlineFromPoints( SHAPE_POLY_SET& aOutline, const EDIT_POINT& aEditedPoint,
147 EDIT_POINTS& aPoints );
148
149 void MakePoints( EDIT_POINTS& aPoints ) override
150 {
151 BuildForPolyOutline( aPoints, m_polygon );
152 }
153
154 void UpdatePoints( EDIT_POINTS& aPoints ) override
155 {
157 }
158
159 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
160 std::vector<EDA_ITEM*>& aUpdatedItems ) override
161 {
162 UpdateOutlineFromPoints( m_polygon, aEditedPoint, aPoints );
163 }
164
165private:
167};
168
169
177{
178public:
179 // Editing the underlying polygon shape in-place is enough
181 POLYGON_POINT_EDIT_BEHAVIOR( aPolygon.GetPolyShape() )
182 {
183 wxASSERT( aPolygon.GetShape() == SHAPE_T::POLY );
184 }
185};
186
187
192{
193public:
195 {
196 wxASSERT( aSegment.GetShape() == SHAPE_T::SEGMENT );
197 }
198
199 void MakePoints( EDIT_POINTS& aPoints ) override;
200
201 void UpdatePoints( EDIT_POINTS& aPoints ) override;
202
203 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
204 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
205
207 EDIT_POINTS& aPoints ) const override;
208
209protected:
211 {
214
216 };
217
218private:
220};
221
222
227{
228public:
230 {
231 wxASSERT( aCircle.GetShape() == SHAPE_T::CIRCLE );
232 }
233
234 void MakePoints( EDIT_POINTS& aPoints ) override;
235
236 void UpdatePoints( EDIT_POINTS& aPoints ) override;
237
238 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
239 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
240
242 EDIT_POINTS& aPoints ) const override;
243
244protected:
246 {
249
251 };
252
253private:
255};
256
257
262{
263public:
265 {
266 wxASSERT( aBezier.GetShape() == SHAPE_T::BEZIER );
267 }
268
269 void MakePoints( EDIT_POINTS& aPoints ) override;
270
271 void UpdatePoints( EDIT_POINTS& aPoints ) override;
272
273 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
274 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
275
276protected:
278 {
283
285 };
286
287private:
289};
290
291
300{
301public:
303 {
304 // While PCB_TEXTBOXES are not always RECTANGLEs, they are when they
305 // are TABLECELLs.
306 wxASSERT( aCell.GetShape() == SHAPE_T::RECTANGLE );
307 }
308
309 void MakePoints( EDIT_POINTS& aPoints ) override;
310
311 void UpdatePoints( EDIT_POINTS& aPoints ) override;
312
313protected:
315 {
318
320 };
321
322private:
324};
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:125
"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