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
107 virtual OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint,
108 EDIT_POINTS& aPoints ) const
109 {
110 // By default, no constrainer is defined and the caller must decide
111 return std::nullopt;
112 }
113
114protected:
118 static bool isModified( const EDIT_POINT& aEditedPoint, const EDIT_POINT& aPoint )
119 {
120 return &aEditedPoint == &aPoint;
121 }
122};
123
124// Helper macros to check the number of points in the edit points object
125// Still a bug, but at least it won't segfault if the number of points is wrong
126#define CHECK_POINT_COUNT( aPoints, aExpected ) \
127 wxCHECK( aPoints.PointsSize() == aExpected, /* void */ )
128#define CHECK_POINT_COUNT_GE( aPoints, aExpected ) \
129 wxCHECK( aPoints.PointsSize() >= aExpected, /* void */ )
130
131
140{
141public:
143 m_polygon( aPolygon )
144 {}
145
149 static void BuildForPolyOutline( EDIT_POINTS& aPoints, const SHAPE_POLY_SET& aOutline );
150
156 static void UpdatePointsFromOutline( const SHAPE_POLY_SET& aOutline, EDIT_POINTS& aPoints );
157
161 static void UpdateOutlineFromPoints( SHAPE_POLY_SET& aOutline, const EDIT_POINT& aEditedPoint,
162 EDIT_POINTS& aPoints );
163
169
170 void MakePoints( EDIT_POINTS& aPoints ) override
171 {
172 BuildForPolyOutline( aPoints, m_polygon );
173 }
174
175 bool UpdatePoints( EDIT_POINTS& aPoints ) override
176 {
178 return true;
179 }
180
181 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
182 std::vector<EDA_ITEM*>& aUpdatedItems ) override
183 {
184 UpdateOutlineFromPoints( m_polygon, aEditedPoint, aPoints );
185 }
186
187 void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) override;
188
189private:
191};
192
193
202{
203public:
205 m_shape( aPolygon )
206 {
207 wxASSERT( aPolygon.GetShape() == SHAPE_T::POLY );
208 }
209
210 void MakePoints( EDIT_POINTS& aPoints ) override
211 {
213 }
214
215 bool UpdatePoints( EDIT_POINTS& aPoints ) override
216 {
217 // Normalize can fold the polygon into a rectangle, which needs a different editor
218 if( m_shape.GetShape() != SHAPE_T::POLY )
219 return false;
220
222 return true;
223 }
224
225 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
226 std::vector<EDA_ITEM*>& aUpdatedItems ) override
227 {
229 m_shape.GetPolyShape(), aEditedPoint, aPoints );
230 }
231
232 void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) override
233 {
235 }
236
237private:
239};
240
241
246{
247public:
249 m_segment( aSegment )
250 {
251 wxASSERT( aSegment.GetShape() == SHAPE_T::SEGMENT );
252 }
253
254 void MakePoints( EDIT_POINTS& aPoints ) override;
255
256 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
257
258 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
259 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
260
262 EDIT_POINTS& aPoints ) const override;
263
264protected:
272
273private:
275};
276
277
282{
283public:
285 m_circle( aCircle )
286 {
287 wxASSERT( aCircle.GetShape() == SHAPE_T::CIRCLE );
288 }
289
290 void MakePoints( EDIT_POINTS& aPoints ) override;
291
292 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
293
294 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
295 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
296
298 EDIT_POINTS& aPoints ) const override;
299
300protected:
308
309private:
311};
312
313
318{
319public:
320 EDA_BEZIER_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aBezier, int aMaxError ) :
321 m_bezier( aBezier ),
322 m_maxError( aMaxError )
323 {
324 wxASSERT( aBezier.GetShape() == SHAPE_T::BEZIER );
325 }
326
327 void MakePoints( EDIT_POINTS& aPoints ) override;
328
329 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
330
331 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
332 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
333
334protected:
344
345private:
348};
349
350
364{
365public:
367 m_ellipse( aEllipse )
368 {
369 wxASSERT( aEllipse.GetShape() == SHAPE_T::ELLIPSE || aEllipse.GetShape() == SHAPE_T::ELLIPSE_ARC );
370 }
371
372 void MakePoints( EDIT_POINTS& aPoints ) override;
373
374 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
375
376 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
377 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
378
379protected:
391
392private:
394
396 VECTOR2I evaluateAt( const EDA_ANGLE& aTheta ) const;
397
399 EDA_ANGLE parametricAngleOf( const VECTOR2I& aWorldPt ) const;
400};
401
402
417{
429
430public:
436 m_image( aImage ),
437 m_minSize( aMinSize )
438 {
439 }
440
441 void MakePoints( EDIT_POINTS& aPoints ) override;
442
443 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
444
445 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
446 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
447
448private:
451};
452
453
462{
463public:
465 m_cell( aCell )
466 {
467 // Point editor only supports cardinally-rotated table cells.
468 wxASSERT( aCell.GetShape() == SHAPE_T::RECTANGLE );
469 }
470
471 void MakePoints( EDIT_POINTS& aPoints ) override;
472
473 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
474
475protected:
483
484private:
486};
487
488
493{
494public:
495 EDA_ARC_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aArc, const ARC_EDIT_MODE& aArcEditMode,
496 KIGFX::VIEW_CONTROLS& aViewContols,
497 const EDA_IU_SCALE& aIuScale );
498
499 void MakePoints( EDIT_POINTS& aPoints ) override;
500
501 bool UpdatePoints( EDIT_POINTS& aPoints ) override;
502
503 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
504 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
505
506 OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints ) const override;
507
508private:
516
518 // The arc edit mode, which is injected from the editor
521 // IU scale of the owning editor, used to derive the minimum arc radius
523};
524
525
527
528
529namespace KI_ARC_EDIT
530{
537void EditArcEndpointKeepCenter( EDA_SHAPE& aArc, const VECTOR2I& aCenter, const VECTOR2I& aStart,
538 const VECTOR2I& aMid, const VECTOR2I& aEnd, const VECTOR2I& aCursor,
539 const EDA_IU_SCALE& aIuScale );
540
545void EditArcMidKeepCenter( EDA_SHAPE& aArc, const VECTOR2I& aCenter, const VECTOR2I& aStart,
546 const VECTOR2I& aMid, const VECTOR2I& aEnd, const VECTOR2I& aCursor,
547 const EDA_IU_SCALE& aIuScale );
548} // 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.
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:177
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 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.
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:62
@ SEGMENT
Definition eda_shape.h:56
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:57
@ ELLIPSE_ARC
Definition eda_shape.h:63
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