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
138 static void BuildForPolyOutline( EDIT_POINTS& aPoints, const SHAPE_POLY_SET& aOutline );
139
145 static void UpdatePointsFromOutline( const SHAPE_POLY_SET& aOutline, EDIT_POINTS& aPoints );
146
150 static void UpdateOutlineFromPoints( SHAPE_POLY_SET& aOutline, const EDIT_POINT& aEditedPoint,
151 EDIT_POINTS& aPoints );
152
153 void MakePoints( EDIT_POINTS& aPoints ) override
154 {
155 BuildForPolyOutline( aPoints, m_polygon );
156 }
157
158 void UpdatePoints( EDIT_POINTS& aPoints ) override
159 {
161 }
162
163 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
164 std::vector<EDA_ITEM*>& aUpdatedItems ) override
165 {
166 UpdateOutlineFromPoints( m_polygon, aEditedPoint, aPoints );
167 }
168
169private:
171};
172
173
181{
182public:
183 // Editing the underlying polygon shape in-place is enough
185 POLYGON_POINT_EDIT_BEHAVIOR( aPolygon.GetPolyShape() )
186 {
187 wxASSERT( aPolygon.GetShape() == SHAPE_T::POLY );
188 }
189
190 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
191 std::vector<EDA_ITEM*>& aUpdatedItems ) override
192 {
193 POLYGON_POINT_EDIT_BEHAVIOR::UpdateItem( aEditedPoint, aPoints, aCommit, aUpdatedItems );
194 }
195};
196
197
202{
203public:
205 {
206 wxASSERT( aSegment.GetShape() == SHAPE_T::SEGMENT );
207 }
208
209 void MakePoints( EDIT_POINTS& aPoints ) override;
210
211 void UpdatePoints( EDIT_POINTS& aPoints ) override;
212
213 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
214 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
215
217 EDIT_POINTS& aPoints ) const override;
218
219protected:
221 {
224
226 };
227
228private:
230};
231
232
237{
238public:
240 {
241 wxASSERT( aCircle.GetShape() == SHAPE_T::CIRCLE );
242 }
243
244 void MakePoints( EDIT_POINTS& aPoints ) override;
245
246 void UpdatePoints( EDIT_POINTS& aPoints ) override;
247
248 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
249 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
250
252 EDIT_POINTS& aPoints ) const override;
253
254protected:
256 {
259
261 };
262
263private:
265};
266
267
272{
273public:
275 {
276 wxASSERT( aBezier.GetShape() == SHAPE_T::BEZIER );
277 }
278
279 void MakePoints( EDIT_POINTS& aPoints ) override;
280
281 void UpdatePoints( EDIT_POINTS& aPoints ) override;
282
283 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
284 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
285
286protected:
288 {
293
295 };
296
297private:
299};
300
301
310{
311public:
313 {
314 // While PCB_TEXTBOXES are not always RECTANGLEs, they are when they
315 // are TABLECELLs.
316 wxASSERT( aCell.GetShape() == SHAPE_T::RECTANGLE );
317 }
318
319 void MakePoints( EDIT_POINTS& aPoints ) override;
320
321 void UpdatePoints( EDIT_POINTS& aPoints ) override;
322
323protected:
325 {
328
330 };
331
332private:
334};
335
336
341{
342public:
343 EDA_ARC_POINT_EDIT_BEHAVIOR( EDA_SHAPE& aArc, const ARC_EDIT_MODE& aArcEditMode,
344 KIGFX::VIEW_CONTROLS& aViewContols );
345
346 void MakePoints( EDIT_POINTS& aPoints ) override;
347
348 void UpdatePoints( EDIT_POINTS& aPoints ) override;
349
350 void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints, COMMIT& aCommit,
351 std::vector<EDA_ITEM*>& aUpdatedItems ) override;
352
353 OPT_VECTOR2I Get45DegreeConstrainer( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints ) const override;
354
355private:
357 {
362 };
363
365 // The arc edit mode, which is injected from the editor
368};
369
370
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:74
"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.
EDA_BEZIER_POINT_EDIT_BEHAVIOR(EDA_SHAPE &aBezier)
void UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
"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