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
30#include <eda_shape.h>
31#include <tool/edit_points.h>
32#include <view/view_controls.h>
33
34class COMMIT;
35class SHAPE_POLY_SET;
36
45{
46public:
47 virtual ~POINT_EDIT_BEHAVIOR() = default;
48
55 virtual void MakePoints( EDIT_POINTS& aPoints ) = 0;
56
71 virtual bool UpdatePoints( EDIT_POINTS& aPoints ) = 0;
72
82 virtual void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) {};
83
99 virtual void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
100 std::vector<EDA_ITEM*>& aUpdatedItems ) = 0;
101
109 virtual OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint,
110 EDIT_POINTS& aPoints ) const
111 {
112 // By default, no constrainer is defined and the caller must decide
113 return std::nullopt;
114 }
115
116protected:
120 static bool isModified( const EDIT_POINT& aEditedPoint, const EDIT_POINT& aPoint )
121 {
122 return &aEditedPoint == &aPoint;
123 }
124};
125
126// Helper macros to check the number of points in the edit points object
127// Still a bug, but at least it won't segfault if the number of points is wrong
128#define CHECK_POINT_COUNT( aPoints, aExpected ) \
129 wxCHECK( aPoints.PointsSize() == aExpected, /* void */ )
130#define CHECK_POINT_COUNT_GE( aPoints, aExpected ) \
131 wxCHECK( aPoints.PointsSize() >= aExpected, /* void */ )
132
133
142{
143public:
145 m_polygon( aPolygon )
146 {}
147
151 static void BuildForPolyOutline( EDIT_POINTS& aPoints, const SHAPE_POLY_SET& aOutline );
152
158 static void UpdatePointsFromOutline( const SHAPE_POLY_SET& aOutline, EDIT_POINTS& aPoints );
159
163 static void UpdateOutlineFromPoints( SHAPE_POLY_SET& aOutline, const EDIT_POINT& aEditedPoint,
164 EDIT_POINTS& aPoints );
165
166 void MakePoints( EDIT_POINTS& aPoints ) override
167 {
168 BuildForPolyOutline( aPoints, m_polygon );
169 }
170
171 bool UpdatePoints( EDIT_POINTS& aPoints ) override
172 {
174 return true;
175 }
176
177 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
178 std::vector<EDA_ITEM*>& aUpdatedItems ) override
179 {
180 UpdateOutlineFromPoints( m_polygon, aEditedPoint, aPoints );
181 }
182
183 void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) override;
184
185private:
187};
188
189
198{
199public:
201 m_shape( aPolygon )
202 {
203 wxASSERT( aPolygon.GetShape() == SHAPE_T::POLY );
204 }
205
206 void MakePoints( EDIT_POINTS& aPoints ) override
207 {
209 }
210
211 bool UpdatePoints( EDIT_POINTS& aPoints ) override
212 {
214 return true;
215 }
216
217 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
218 std::vector<EDA_ITEM*>& aUpdatedItems ) override
219 {
221 m_shape.GetPolyShape(), aEditedPoint, aPoints );
222 }
223
224 void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) override
225 {
226 m_shape.GetPolyShape().RemoveNullSegments();
227 }
228
229private:
231};
232
233
238{
239public:
241 m_segment( aSegment )
242 {
243 wxASSERT( aSegment.GetShape() == SHAPE_T::SEGMENT );
244 }
245
246 void MakePoints( EDIT_POINTS& aPoints ) override;
247
248 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
249
250 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
251 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
252
254 EDIT_POINTS& aPoints ) const override;
255
256protected:
264
265private:
267};
268
269
274{
275public:
277 m_circle( aCircle )
278 {
279 wxASSERT( aCircle.GetShape() == SHAPE_T::CIRCLE );
280 }
281
282 void MakePoints( EDIT_POINTS& aPoints ) override;
283
284 bool 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
290 EDIT_POINTS& aPoints ) const override;
291
292protected:
300
301private:
303};
304
305
310{
311public:
312 EDA_BEZIER_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aBezier, int aMaxError ) :
313 m_bezier( aBezier ),
314 m_maxError( aMaxError )
315 {
316 wxASSERT( aBezier.GetShape() == SHAPE_T::BEZIER );
317 }
318
319 void MakePoints( EDIT_POINTS& aPoints ) override;
320
321 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
322
323 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
324 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
325
326protected:
336
337private:
340};
341
342
351{
352public:
354 m_cell( aCell )
355 {
356 // Point editor only supports cardinally-rotated table cells.
357 wxASSERT( aCell.GetShape() == SHAPE_T::RECTANGLE );
358 }
359
360 void MakePoints( EDIT_POINTS& aPoints ) override;
361
362 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
363
364protected:
372
373private:
375};
376
377
382{
383public:
384 EDA_ARC_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aArc, const ARC_EDIT_MODE& aArcEditMode,
385 KIGFX::VIEW_CONTROLS& aViewContols );
386
387 void MakePoints( EDIT_POINTS& aPoints ) override;
388
389 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
390
391 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
392 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
393
394 OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints ) const override;
395
396private:
404
406 // The arc edit mode, which is injected from the editor
409};
410
411
ARC_EDIT_MODE
Settings for arc editing.
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition commit.h:72
const ARC_EDIT_MODE & m_arcEditMode
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.
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.
KIGFX::VIEW_CONTROLS & m_viewControls
EDA_ARC_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aArc, const ARC_EDIT_MODE &aArcEditMode, KIGFX::VIEW_CONTROLS &aViewContols)
bool 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.
bool 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.
EDA_BEZIER_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aBezier, int aMaxError)
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.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
EDA_CIRCLE_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aCircle)
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.
void FinalizeItem(EDIT_POINTS &aPoints, COMMIT &aCommit) override
Finalize the edit operation.
EDA_POLYGON_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aPolygon)
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
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 MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
bool 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.
EDA_SEGMENT_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aSegment)
SHAPE_T GetShape() const
Definition eda_shape.h:181
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
bool 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.
Represent a single point that can be used for modifying items.
Definition edit_points.h:48
An interface for classes handling user events controlling the view behavior such as zooming,...
A helper class interface to manage the edit points for a single item.
virtual bool UpdatePoints(EDIT_POINTS &aPoints)=0
Update the list of the edit points for the 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 FinalizeItem(EDIT_POINTS &aPoints, COMMIT &aCommit)
Finalize the edit operation.
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.
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.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
static void UpdatePointsFromOutline(const SHAPE_POLY_SET &aOutline, EDIT_POINTS &aPoints)
Update the edit points with the current polygon outline.
void FinalizeItem(EDIT_POINTS &aPoints, COMMIT &aCommit) override
Finalize the edit operation.
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 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.
@ SEGMENT
Definition eda_shape.h:47
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:48
ARC_EDIT_MODE IncrementArcEditMode(ARC_EDIT_MODE aMode)
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:39