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
88 virtual void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
89 std::vector<EDA_ITEM*>& aUpdatedItems ) = 0;
90
98 virtual OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint,
99 EDIT_POINTS& aPoints ) const
100 {
101 // By default, no constrainer is defined and the caller must decide
102 return std::nullopt;
103 }
104
105protected:
109 static bool isModified( const EDIT_POINT& aEditedPoint, const EDIT_POINT& aPoint )
110 {
111 return &aEditedPoint == &aPoint;
112 }
113};
114
115// Helper macros to check the number of points in the edit points object
116// Still a bug, but at least it won't segfault if the number of points is wrong
117#define CHECK_POINT_COUNT( aPoints, aExpected ) \
118 wxCHECK( aPoints.PointsSize() == aExpected, /* void */ )
119#define CHECK_POINT_COUNT_GE( aPoints, aExpected ) \
120 wxCHECK( aPoints.PointsSize() >= aExpected, /* void */ )
121
122
131{
132public:
134 m_polygon( aPolygon )
135 {}
136
140 static void BuildForPolyOutline( EDIT_POINTS& aPoints, const SHAPE_POLY_SET& aOutline );
141
147 static void UpdatePointsFromOutline( const SHAPE_POLY_SET& aOutline, EDIT_POINTS& aPoints );
148
152 static void UpdateOutlineFromPoints( SHAPE_POLY_SET& aOutline, const EDIT_POINT& aEditedPoint,
153 EDIT_POINTS& aPoints );
154
155 void MakePoints( EDIT_POINTS& aPoints ) override
156 {
157 BuildForPolyOutline( aPoints, m_polygon );
158 }
159
160 void UpdatePoints( EDIT_POINTS& aPoints ) override
161 {
163 }
164
165 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
166 std::vector<EDA_ITEM*>& aUpdatedItems ) override
167 {
168 UpdateOutlineFromPoints( m_polygon, aEditedPoint, aPoints );
169 }
170
171private:
173};
174
175
183{
184public:
185 // Editing the underlying polygon shape in-place is enough
187 POLYGON_POINT_EDIT_BEHAVIOR( aPolygon.GetPolyShape() )
188 {
189 wxASSERT( aPolygon.GetShape() == SHAPE_T::POLY );
190 }
191
192 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
193 std::vector<EDA_ITEM*>& aUpdatedItems ) override
194 {
195 POLYGON_POINT_EDIT_BEHAVIOR::UpdateItem( aEditedPoint, aPoints, aCommit, aUpdatedItems );
196 }
197};
198
199
204{
205public:
207 m_segment( aSegment )
208 {
209 wxASSERT( aSegment.GetShape() == SHAPE_T::SEGMENT );
210 }
211
212 void MakePoints( EDIT_POINTS& aPoints ) override;
213
214 void UpdatePoints( EDIT_POINTS& aPoints ) override;
215
216 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
217 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
218
220 EDIT_POINTS& aPoints ) const override;
221
222protected:
224 {
227
229 };
230
231private:
233};
234
235
240{
241public:
243 m_circle( aCircle )
244 {
245 wxASSERT( aCircle.GetShape() == SHAPE_T::CIRCLE );
246 }
247
248 void MakePoints( EDIT_POINTS& aPoints ) override;
249
250 void UpdatePoints( EDIT_POINTS& aPoints ) override;
251
252 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
253 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
254
256 EDIT_POINTS& aPoints ) const override;
257
258protected:
260 {
263
265 };
266
267private:
269};
270
271
276{
277public:
278 EDA_BEZIER_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aBezier, int aMaxError ) :
279 m_bezier( aBezier ),
280 m_maxError( aMaxError )
281 {
282 wxASSERT( aBezier.GetShape() == SHAPE_T::BEZIER );
283 }
284
285 void MakePoints( EDIT_POINTS& aPoints ) override;
286
287 void UpdatePoints( EDIT_POINTS& aPoints ) override;
288
289 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
290 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
291
292protected:
294 {
299
301 };
302
303private:
306};
307
308
317{
318public:
320 m_cell( aCell )
321 {
322 // Point editor only supports cardinally-rotated table cells.
323 wxASSERT( aCell.GetShape() == SHAPE_T::RECTANGLE );
324 }
325
326 void MakePoints( EDIT_POINTS& aPoints ) override;
327
328 void UpdatePoints( EDIT_POINTS& aPoints ) override;
329
330protected:
332 {
335
337 };
338
339private:
341};
342
343
348{
349public:
350 EDA_ARC_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aArc, const ARC_EDIT_MODE& aArcEditMode,
351 KIGFX::VIEW_CONTROLS& aViewContols );
352
353 void MakePoints( EDIT_POINTS& aPoints ) override;
354
355 void UpdatePoints( EDIT_POINTS& aPoints ) override;
356
357 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
358 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
359
360 OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints ) const override;
361
362private:
364 {
369 };
370
372 // The arc edit mode, which is injected from the editor
375};
376
377
ARC_EDIT_MODE
Settings for arc editing.
Definition: app_settings.h:52
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition: commit.h:73
"Standard" arc editing behavior.
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
void UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
"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.
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)
"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.
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)
"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:168
"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
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 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.
ARC_EDIT_MODE IncrementArcEditMode(ARC_EDIT_MODE aMode)
std::optional< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:39