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 SHAPE_POLY_SET;
35
45{
46public:
47 virtual ~POINT_EDIT_BEHAVIOR() = default;
48
55 virtual void MakePoints( EDIT_POINTS& aPoints ) = 0;
56
70 virtual void UpdatePoints( EDIT_POINTS& aPoints ) = 0;
71
81 virtual void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) {};
82
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 void UpdatePoints( EDIT_POINTS& aPoints ) override
172 {
174 }
175
176 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
177 std::vector<EDA_ITEM*>& aUpdatedItems ) override
178 {
179 UpdateOutlineFromPoints( m_polygon, aEditedPoint, aPoints );
180 }
181
182 void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) override;
183
184private:
186};
187
188
196{
197public:
198 // Editing the underlying polygon shape in-place is enough
200 POLYGON_POINT_EDIT_BEHAVIOR( aPolygon.GetPolyShape() )
201 {
202 wxASSERT( aPolygon.GetShape() == SHAPE_T::POLY );
203 }
204
205 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
206 std::vector<EDA_ITEM*>& aUpdatedItems ) override
207 {
208 POLYGON_POINT_EDIT_BEHAVIOR::UpdateItem( aEditedPoint, aPoints, aCommit, aUpdatedItems );
209 }
210};
211
212
217{
218public:
220 m_segment( aSegment )
221 {
222 wxASSERT( aSegment.GetShape() == SHAPE_T::SEGMENT );
223 }
224
225 void MakePoints( EDIT_POINTS& aPoints ) override;
226
227 void UpdatePoints( EDIT_POINTS& aPoints ) override;
228
229 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
230 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
231
233 EDIT_POINTS& aPoints ) const override;
234
235protected:
243
244private:
246};
247
248
253{
254public:
256 m_circle( aCircle )
257 {
258 wxASSERT( aCircle.GetShape() == SHAPE_T::CIRCLE );
259 }
260
261 void MakePoints( EDIT_POINTS& aPoints ) override;
262
263 void UpdatePoints( EDIT_POINTS& aPoints ) override;
264
265 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
266 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
267
269 EDIT_POINTS& aPoints ) const override;
270
271protected:
279
280private:
282};
283
284
289{
290public:
291 EDA_BEZIER_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aBezier, int aMaxError ) :
292 m_bezier( aBezier ),
293 m_maxError( aMaxError )
294 {
295 wxASSERT( aBezier.GetShape() == SHAPE_T::BEZIER );
296 }
297
298 void MakePoints( EDIT_POINTS& aPoints ) override;
299
300 void UpdatePoints( EDIT_POINTS& aPoints ) override;
301
302 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
303 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
304
305protected:
315
316private:
319};
320
321
330{
331public:
333 m_cell( aCell )
334 {
335 // Point editor only supports cardinally-rotated table cells.
336 wxASSERT( aCell.GetShape() == SHAPE_T::RECTANGLE );
337 }
338
339 void MakePoints( EDIT_POINTS& aPoints ) override;
340
341 void UpdatePoints( EDIT_POINTS& aPoints ) override;
342
343protected:
351
352private:
354};
355
356
361{
362public:
363 EDA_ARC_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aArc, const ARC_EDIT_MODE& aArcEditMode,
364 KIGFX::VIEW_CONTROLS& aViewContols );
365
366 void MakePoints( EDIT_POINTS& aPoints ) override;
367
368 void UpdatePoints( EDIT_POINTS& aPoints ) override;
369
370 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
371 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
372
373 OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints ) const override;
374
375private:
383
385 // The arc edit mode, which is injected from the editor
388};
389
390
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)
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.
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.
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.
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.
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)
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 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.
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 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.
virtual void UpdatePoints(EDIT_POINTS &aPoints)=0
Update the list of the edit points for the item.
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.
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 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.
@ SEGMENT
Definition eda_shape.h:45
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:46
ARC_EDIT_MODE IncrementArcEditMode(ARC_EDIT_MODE aMode)
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:39