KiCad PCB EDA Suite
Loading...
Searching...
No Matches
point_editor_behavior.cpp
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 (C) 2024 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
25
27
28
30 const SHAPE_POLY_SET& aOutline )
31{
32 const int cornersCount = aOutline.TotalVertices();
33
34 for( auto iterator = aOutline.CIterateWithHoles(); iterator; iterator++ )
35 {
36 aPoints.AddPoint( *iterator );
37
38 if( iterator.IsEndContour() )
39 aPoints.AddBreak();
40 }
41
42 // Lines have to be added after creating edit points, as they use EDIT_POINT references
43 for( int i = 0; i < cornersCount - 1; ++i )
44 {
45 if( aPoints.IsContourEnd( i ) )
46 aPoints.AddLine( aPoints.Point( i ), aPoints.Point( aPoints.GetContourStartIdx( i ) ) );
47 else
48 aPoints.AddLine( aPoints.Point( i ), aPoints.Point( i + 1 ) );
49
50 aPoints.Line( i ).SetConstraint( new EC_PERPLINE( aPoints.Line( i ) ) );
51 }
52
53 // The last missing line, connecting the last and the first polygon point
54 aPoints.AddLine( aPoints.Point( cornersCount - 1 ),
55 aPoints.Point( aPoints.GetContourStartIdx( cornersCount - 1 ) ) );
56
57 aPoints.Line( aPoints.LinesSize() - 1 )
58 .SetConstraint( new EC_PERPLINE( aPoints.Line( aPoints.LinesSize() - 1 ) ) );
59}
60
61
63 EDIT_POINTS& aPoints )
64{
65 // No size check here, as we can and will rebuild if that fails
66
67 if( aPoints.PointsSize() != (unsigned) aOutline.TotalVertices() )
68 {
69 // Rebuild the points list
70 aPoints.Clear();
71 BuildForPolyOutline( aPoints, aOutline );
72 }
73 else
74 {
75 for( int i = 0; i < aOutline.TotalVertices(); ++i )
76 {
77 aPoints.Point( i ).SetPosition( aOutline.CVertex( i ) );
78 }
79 }
80}
81
82
84 const EDIT_POINT& aEditedPoint,
85 EDIT_POINTS& aPoints )
86{
87 CHECK_POINT_COUNT_GE( aPoints, (unsigned) aOutline.TotalVertices() );
88
89 for( int i = 0; i < aOutline.TotalVertices(); ++i )
90 {
91 aOutline.SetVertex( i, aPoints.Point( i ).GetPosition() );
92 }
93
94 for( unsigned i = 0; i < aPoints.LinesSize(); ++i )
95 {
96 if( !isModified( aEditedPoint, aPoints.Line( i ) ) )
97 {
98 aPoints.Line( i ).SetConstraint( new EC_PERPLINE( aPoints.Line( i ) ) );
99 }
100 }
101}
102
103
105{
106 aPoints.AddPoint( m_segment.GetStart() );
107 aPoints.AddPoint( m_segment.GetEnd() );
108}
109
111{
113
114 aPoints.Point( SEGMENT_START ) = m_segment.GetStart();
115 aPoints.Point( SEGMENT_END ) = m_segment.GetEnd();
116}
117
119 EDIT_POINTS& aPoints, COMMIT& aCommit,
120 std::vector<EDA_ITEM*>& aUpdatedItems )
121{
123
124 if( isModified( aEditedPoint, aPoints.Point( SEGMENT_START ) ) )
126
127 else if( isModified( aEditedPoint, aPoints.Point( SEGMENT_END ) ) )
129}
130
133 EDIT_POINTS& aPoints ) const
134{
135 // Select the other end of line
136 return aPoints.Next( aEditedPoint )->GetPosition();
137}
138
139
141{
142 aPoints.AddPoint( m_circle.getCenter() );
143 aPoints.AddPoint( m_circle.GetEnd() );
144}
145
146
148{
150
152 aPoints.Point( CIRC_END ).SetPosition( m_circle.GetEnd() );
153}
154
155
157 EDIT_POINTS& aPoints, COMMIT& aCommit,
158 std::vector<EDA_ITEM*>& aUpdatedItems )
159{
161
162 const VECTOR2I& center = aPoints.Point( CIRC_CENTER ).GetPosition();
163 const VECTOR2I& end = aPoints.Point( CIRC_END ).GetPosition();
164
165 if( isModified( aEditedPoint, aPoints.Point( CIRC_CENTER ) ) )
166 {
167 m_circle.SetCenter( center );
168 }
169 else
170 {
171 m_circle.SetEnd( VECTOR2I( end.x, end.y ) );
172 }
173}
174
175
178 EDIT_POINTS& aPoints ) const
179{
180 return aPoints.Point( CIRC_CENTER ).GetPosition();
181}
182
183
185{
186 aPoints.AddPoint( m_bezier.GetStart() );
187 aPoints.AddPoint( m_bezier.GetBezierC1() );
188 aPoints.AddPoint( m_bezier.GetBezierC2() );
189 aPoints.AddPoint( m_bezier.GetEnd() );
190
191 aPoints.AddIndicatorLine( aPoints.Point( BEZIER_START ), aPoints.Point( BEZIER_CTRL_PT1 ) );
192 aPoints.AddIndicatorLine( aPoints.Point( BEZIER_CTRL_PT2 ), aPoints.Point( BEZIER_END ) );
193}
194
196{
198
203}
204
206 EDIT_POINTS& aPoints, COMMIT& aCommit,
207 std::vector<EDA_ITEM*>& aUpdatedItems )
208{
210
211 if( isModified( aEditedPoint, aPoints.Point( BEZIER_START ) ) )
212 {
214 }
215 else if( isModified( aEditedPoint, aPoints.Point( BEZIER_CTRL_PT1 ) ) )
216 {
218 }
219 else if( isModified( aEditedPoint, aPoints.Point( BEZIER_CTRL_PT2 ) ) )
220 {
222 }
223 else if( isModified( aEditedPoint, aPoints.Point( BEZIER_END ) ) )
224 {
226 }
227
229}
230
231
233{
234 aPoints.AddPoint( m_cell.GetEnd() - VECTOR2I( 0, m_cell.GetRectangleHeight() / 2 ) );
235 aPoints.AddPoint( m_cell.GetEnd() - VECTOR2I( m_cell.GetRectangleWidth() / 2, 0 ) );
236}
237
238
240{
241 aPoints.Point( COL_WIDTH )
243 aPoints.Point( ROW_HEIGHT )
245}
constexpr int ARC_HIGH_DEF
Definition: base_units.h:120
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition: commit.h:74
EDIT_CONSTRAINT for a EDIT_LINE, that constrains the line to move perpendicular to the line itself.
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.
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.
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.
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.
const VECTOR2I & GetBezierC2() const
Definition: eda_shape.h:213
void SetBezierC2(const VECTOR2I &aPt)
Definition: eda_shape.h:212
void SetCenter(const VECTOR2I &aCenter)
Definition: eda_shape.cpp:778
VECTOR2I getCenter() const
Definition: eda_shape.cpp:752
int GetRectangleWidth() const
Definition: eda_shape.cpp:417
void RebuildBezierToSegmentsPointsList(int aMaxError)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
Definition: eda_shape.cpp:725
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:174
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:141
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:137
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:178
void SetBezierC1(const VECTOR2I &aPt)
Definition: eda_shape.h:209
const VECTOR2I & GetBezierC1() const
Definition: eda_shape.h:210
int GetRectangleHeight() const
Definition: eda_shape.cpp:404
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 SetConstraint(EDIT_CONSTRAINT< EDIT_LINE > *aConstraint)
Set a constraint for and EDIT_POINT.
Definition: edit_points.h:267
EDIT_POINTS is a VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
Definition: edit_points.h:353
unsigned int PointsSize() const
Return number of stored EDIT_POINTs.
Definition: edit_points.h:534
void AddPoint(const EDIT_POINT &aPoint)
Add an EDIT_POINT.
Definition: edit_points.h:390
void Clear()
Clear all stored EDIT_POINTs and EDIT_LINEs.
Definition: edit_points.h:378
EDIT_POINT * Next(const EDIT_POINT &aPoint, bool aTraverseContours=true)
Return the point that is before the given point in the list.
EDIT_LINE & Line(unsigned int aIndex)
Definition: edit_points.h:521
bool IsContourEnd(int aPointIdx) const
Check is a point with given index is a contour finish.
void AddIndicatorLine(EDIT_POINT &aOrigin, EDIT_POINT &aEnd)
Adds an EDIT_LINE that is shown as an indicator, rather than an editable line (no center point drag,...
Definition: edit_points.h:434
void AddBreak()
Adds a break, indicating the end of a contour.
Definition: edit_points.h:445
int GetContourStartIdx(int aPointIdx) const
Return index of the contour origin for a point with given index.
Definition: edit_points.cpp:77
unsigned int LinesSize() const
Return number of stored EDIT_LINEs.
Definition: edit_points.h:542
EDIT_POINT & Point(unsigned int aIndex)
Definition: edit_points.h:511
void AddLine(const EDIT_LINE &aLine)
Adds an EDIT_LINE.
Definition: edit_points.h:410
Represent a single point that can be used for modifying items.
Definition: edit_points.h:48
virtual void SetPosition(const VECTOR2I &aPosition)
Set new coordinates for an EDIT_POINT.
Definition: edit_points.h:107
virtual VECTOR2I GetPosition() const
Return coordinates of an EDIT_POINT.
Definition: edit_points.h:71
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.
static void UpdatePointsFromOutline(const SHAPE_POLY_SET &aOutline, EDIT_POINTS &aPoints)
Update the edit points with the current polygon outline.
static void BuildForPolyOutline(EDIT_POINTS &aPoints, const SHAPE_POLY_SET &aOutline)
Build the edit points for the given polygon outline.
Represent a set of closed polygons.
void SetVertex(const VERTEX_INDEX &aIndex, const VECTOR2I &aPos)
Accessor function to set the position of a specific point.
int TotalVertices() const
Return total number of vertices stored in the set.
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the index-th vertex in a given hole outline within a given outline.
CONST_ITERATOR CIterateWithHoles(int aOutline) const
#define CHECK_POINT_COUNT(aPoints, aExpected)
#define CHECK_POINT_COUNT_GE(aPoints, aExpected)
std::optional< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:39
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691