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, see <https://www.gnu.org/licenses/>.
18 */
19
20
21#pragma once
22
23#include <wx/debug.h>
24
25#include <base_units.h>
27#include <eda_shape.h>
28#include <tool/edit_points.h>
29#include <view/view_controls.h>
30
31class COMMIT;
32class REFERENCE_IMAGE;
33class SHAPE_POLY_SET;
34
43{
44public:
45 virtual ~POINT_EDIT_BEHAVIOR() = default;
46
53 virtual void MakePoints( EDIT_POINTS& aPoints ) = 0;
54
69 virtual bool UpdatePoints( EDIT_POINTS& aPoints ) = 0;
70
80 virtual void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) {};
81
97 virtual void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
98 std::vector<EDA_ITEM*>& aUpdatedItems ) = 0;
99
106 virtual bool UpdateItemAppliesAllPoints() const { return false; }
107
115 virtual OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint,
116 EDIT_POINTS& aPoints ) const
117 {
118 // By default, no constrainer is defined and the caller must decide
119 return std::nullopt;
120 }
121
122protected:
126 static bool isModified( const EDIT_POINT& aEditedPoint, const EDIT_POINT& aPoint )
127 {
128 return &aEditedPoint == &aPoint;
129 }
130};
131
132// Helper macros to check the number of points in the edit points object
133// Still a bug, but at least it won't segfault if the number of points is wrong
134#define CHECK_POINT_COUNT( aPoints, aExpected ) \
135 wxCHECK( aPoints.PointsSize() == aExpected, /* void */ )
136#define CHECK_POINT_COUNT_GE( aPoints, aExpected ) \
137 wxCHECK( aPoints.PointsSize() >= aExpected, /* void */ )
138
139
148{
149public:
151 m_polygon( aPolygon )
152 {}
153
157 static void BuildForPolyOutline( EDIT_POINTS& aPoints, const SHAPE_POLY_SET& aOutline );
158
164 static void UpdatePointsFromOutline( const SHAPE_POLY_SET& aOutline, EDIT_POINTS& aPoints );
165
169 static void UpdateOutlineFromPoints( SHAPE_POLY_SET& aOutline, const EDIT_POINT& aEditedPoint,
170 EDIT_POINTS& aPoints );
171
177
178 void MakePoints( EDIT_POINTS& aPoints ) override
179 {
180 BuildForPolyOutline( aPoints, m_polygon );
181 }
182
183 bool UpdatePoints( EDIT_POINTS& aPoints ) override
184 {
186 return true;
187 }
188
189 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
190 std::vector<EDA_ITEM*>& aUpdatedItems ) override
191 {
192 UpdateOutlineFromPoints( m_polygon, aEditedPoint, aPoints );
193 }
194
195 bool UpdateItemAppliesAllPoints() const override { return true; }
196
197 void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) override;
198
199private:
201};
202
203
212{
213public:
215 m_shape( aPolygon )
216 {
217 wxASSERT( aPolygon.GetShape() == SHAPE_T::POLY );
218 }
219
220 void MakePoints( EDIT_POINTS& aPoints ) override
221 {
223 }
224
225 bool UpdatePoints( EDIT_POINTS& aPoints ) override
226 {
227 // Normalize can fold the polygon into a rectangle, which needs a different editor
228 if( m_shape.GetShape() != SHAPE_T::POLY )
229 return false;
230
232 return true;
233 }
234
235 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
236 std::vector<EDA_ITEM*>& aUpdatedItems ) override
237 {
239 m_shape.GetPolyShape(), aEditedPoint, aPoints );
240 }
241
242 bool UpdateItemAppliesAllPoints() const override { return true; }
243
244 void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) override
245 {
247 }
248
249private:
251};
252
253
258{
259public:
261 m_segment( aSegment )
262 {
263 wxASSERT( aSegment.GetShape() == SHAPE_T::SEGMENT );
264 }
265
266 void MakePoints( EDIT_POINTS& aPoints ) override;
267
268 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
269
270 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
271 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
272
274 EDIT_POINTS& aPoints ) const override;
275
276protected:
284
285private:
287};
288
289
294{
295public:
297 m_circle( aCircle )
298 {
299 wxASSERT( aCircle.GetShape() == SHAPE_T::CIRCLE );
300 }
301
302 void MakePoints( EDIT_POINTS& aPoints ) override;
303
304 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
305
306 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
307 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
308
310 EDIT_POINTS& aPoints ) const override;
311
312protected:
320
321private:
323};
324
325
330{
331public:
332 EDA_BEZIER_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aBezier, int aMaxError ) :
333 m_bezier( aBezier ),
334 m_maxError( aMaxError )
335 {
336 wxASSERT( aBezier.GetShape() == SHAPE_T::BEZIER );
337 }
338
339 void MakePoints( EDIT_POINTS& aPoints ) override;
340
341 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
342
343 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
344 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
345
346protected:
356
357private:
360};
361
362
376{
377public:
379 m_ellipse( aEllipse )
380 {
381 wxASSERT( aEllipse.GetShape() == SHAPE_T::ELLIPSE || aEllipse.GetShape() == SHAPE_T::ELLIPSE_ARC );
382 }
383
384 void MakePoints( EDIT_POINTS& aPoints ) override;
385
386 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
387
388 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
389 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
390
391protected:
403
404private:
406
408 VECTOR2I evaluateAt( const EDA_ANGLE& aTheta ) const;
409
411 EDA_ANGLE parametricAngleOf( const VECTOR2I& aWorldPt ) const;
412};
413
414
429{
441
442public:
448 m_image( aImage ),
449 m_minSize( aMinSize )
450 {
451 }
452
453 void MakePoints( EDIT_POINTS& aPoints ) override;
454
455 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
456
457 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
458 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
459
460private:
463};
464
465
474{
475public:
477 m_cell( aCell )
478 {
479 // Point editor only supports cardinally-rotated table cells.
480 wxASSERT( aCell.GetShape() == SHAPE_T::RECTANGLE );
481 }
482
483 void MakePoints( EDIT_POINTS& aPoints ) override;
484
485 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
486
487protected:
495
496private:
498};
499
500
505{
506public:
507 EDA_ARC_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aArc, const ARC_EDIT_MODE& aArcEditMode,
508 KIGFX::VIEW_CONTROLS& aViewContols,
509 const EDA_IU_SCALE& aIuScale );
510
511 void MakePoints( EDIT_POINTS& aPoints ) override;
512
513 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
514
515 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
516 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
517
518 OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints ) const override;
519
520private:
528
530 // The arc edit mode, which is injected from the editor
533 // IU scale of the owning editor, used to derive the minimum arc radius
535};
536
537
539
540
541namespace KI_ARC_EDIT
542{
549void EditArcEndpointKeepCenter( EDA_SHAPE& aArc, const VECTOR2I& aCenter, const VECTOR2I& aStart,
550 const VECTOR2I& aMid, const VECTOR2I& aEnd, const VECTOR2I& aCursor,
551 const EDA_IU_SCALE& aIuScale );
552
557void EditArcMidKeepCenter( EDA_SHAPE& aArc, const VECTOR2I& aCenter, const VECTOR2I& aStart,
558 const VECTOR2I& aMid, const VECTOR2I& aEnd, const VECTOR2I& aCursor,
559 const EDA_IU_SCALE& aIuScale );
560} // namespace KI_ARC_EDIT
ARC_EDIT_MODE
Settings for arc editing.
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition commit.h:68
EDA_ARC_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aArc, const ARC_EDIT_MODE &aArcEditMode, KIGFX::VIEW_CONTROLS &aViewContols, const EDA_IU_SCALE &aIuScale)
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
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.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
EDA_ANGLE parametricAngleOf(const VECTOR2I &aWorldPt) const
Inverse: the parametric angle of a world-space point relative to this ellipse.
EDA_ELLIPSE_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aEllipse)
VECTOR2I evaluateAt(const EDA_ANGLE &aTheta) const
World-space point on the ellipse at the given parametric angle.
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.
bool UpdateItemAppliesAllPoints() const override
Whether UpdateItem() writes every point back, so one call applies all of them.
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:178
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:44
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 bool UpdateItemAppliesAllPoints() const
Whether UpdateItem() writes every point back, so one call applies all of them.
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.
bool UpdateItemAppliesAllPoints() const override
Whether UpdateItem() writes every point back, so one call applies all of them.
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.
static void RemoveNullSegmentsIfPolygonSurvives(SHAPE_POLY_SET &aOutline)
Remove the zero length segments left by an edit, unless that would strip the outline down to somethin...
REFERENCE_IMAGE_POINT_EDIT_BEHAVIOR(REFERENCE_IMAGE &aImage, int aMinSize)
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.
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.
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
Represent a set of closed polygons.
@ ELLIPSE
Definition eda_shape.h:63
@ SEGMENT
Definition eda_shape.h:57
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
@ ELLIPSE_ARC
Definition eda_shape.h:64
void EditArcEndpointKeepCenter(EDA_SHAPE &aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor, const EDA_IU_SCALE &aIuScale)
Move an arc endpoint around the existing center, pulling the opposite endpoint along to keep the radi...
void EditArcMidKeepCenter(EDA_SHAPE &aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor, const EDA_IU_SCALE &aIuScale)
Move the mid point of an arc while keeping the center, rotating the endpoints onto the new radius.
ARC_EDIT_MODE IncrementArcEditMode(ARC_EDIT_MODE aMode)
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:35
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708