KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eda_shape.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 (C) 2018 Jean-Pierre Charras jp.charras at wanadoo.fr
5 * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef EDA_SHAPE_H
26#define EDA_SHAPE_H
27
28#include <trigo.h>
31#include <properties/property.h>
32#include <stroke_params.h>
33
34class LINE_READER;
35class EDA_DRAW_FRAME;
36class FOOTPRINT;
37class MSG_PANEL_ITEM;
38
39using KIGFX::COLOR4D;
40
41enum class SHAPE_T : int
42{
43 SEGMENT = 0,
44 RECTANGLE,
45 ARC,
46 CIRCLE,
47 POLY,
48 BEZIER
49};
50
51
52// WARNING: Do not change these values without updating dialogs that depend on their position values
53enum class FILL_T : int
54{
55 NO_FILL = 1,
56 FILLED_SHAPE, // Fill with object color
57 FILLED_WITH_BG_BODYCOLOR, // Fill with background body color
58 FILLED_WITH_COLOR // Fill with a separate color
59};
60
61
62// Holding struct to keep originating midpoint
63struct ARC_MID
64{
69};
70
72{
73public:
74 EDA_SHAPE( SHAPE_T aType, int aLineWidth, FILL_T aFill );
75
76 // Do not create a copy constructor & operator=.
77 // The ones generated by the compiler are adequate.
78
79 virtual ~EDA_SHAPE();
80
81 void SwapShape( EDA_SHAPE* aImage );
82
83 wxString ShowShape() const;
84
85 wxString SHAPE_T_asString() const;
86
87 virtual bool IsProxyItem() const { return m_proxyItem; }
88 virtual void SetIsProxyItem( bool aIsProxy = true ) { m_proxyItem = aIsProxy; }
89
90 bool IsFilled() const
91 {
92 return GetFillMode() != FILL_T::NO_FILL;
93 }
94
95 void SetFilled( bool aFlag )
96 {
97 setFilled( aFlag );
98 }
99
100 void SetFillMode( FILL_T aFill ) { m_fill = aFill; }
101 FILL_T GetFillMode() const { return m_fill; }
102
103 bool IsClosed() const;
104
105 COLOR4D GetFillColor() const { return m_fillColor; }
106 void SetFillColor( const COLOR4D& aColor ) { m_fillColor = aColor; }
107
108 void SetWidth( int aWidth ) { m_stroke.SetWidth( aWidth ); }
109 virtual int GetWidth() const { return m_stroke.GetWidth(); }
110 virtual int GetEffectiveWidth() const { return GetWidth(); }
111
112 void SetLineStyle( const LINE_STYLE aStyle );
113 LINE_STYLE GetLineStyle() const;
114
115 void SetLineColor( const COLOR4D& aColor ) { m_stroke.SetColor( aColor ); }
116 COLOR4D GetLineColor() const { return m_stroke.GetColor(); }
117
118 void SetShape( SHAPE_T aShape ) { m_shape = aShape; }
119 SHAPE_T GetShape() const { return m_shape; }
120
121 wxString GetFriendlyName() const;
122
126 const VECTOR2I& GetStart() const { return m_start; }
127 int GetStartY() const { return m_start.y; }
128 int GetStartX() const { return m_start.x; }
129
130 void SetStart( const VECTOR2I& aStart )
131 {
132 m_start = aStart;
133 m_endsSwapped = false;
134 }
135
136 void SetStartY( int y )
137 {
138 m_start.y = y;
139 m_endsSwapped = false;
140 }
141
142 void SetStartX( int x )
143 {
144 m_start.x = x;
145 m_endsSwapped = false;
146 }
147
151 const VECTOR2I& GetEnd() const { return m_end; }
152 int GetEndY() const { return m_end.y; }
153 int GetEndX() const { return m_end.x; }
154
155 void SetEnd( const VECTOR2I& aEnd )
156 {
157 m_end = aEnd;
158 m_endsSwapped = false;
159 }
160
161 void SetEndY( int aY )
162 {
163 m_end.y = aY;
164 m_endsSwapped = false;
165 }
166
167 void SetEndX( int aX )
168 {
169 m_end.x = aX;
170 m_endsSwapped = false;
171 }
172
173 void SetRadius( int aX )
174 {
175 m_end = m_start + VECTOR2I( aX, 0 );
176 }
177
178 virtual VECTOR2I GetTopLeft() const { return GetStart(); }
179 virtual VECTOR2I GetBotRight() const { return GetEnd(); }
180
181 virtual void SetTop( int val ) { SetStartY( val ); }
182 virtual void SetLeft( int val ) { SetStartX( val ); }
183 virtual void SetRight( int val ) { SetEndX( val ); }
184 virtual void SetBottom( int val ) { SetEndY( val ); }
185
186 void SetBezierC1( const VECTOR2I& aPt ) { m_bezierC1 = aPt; }
187 const VECTOR2I& GetBezierC1() const { return m_bezierC1; }
188
189 void SetBezierC2( const VECTOR2I& aPt ) { m_bezierC2 = aPt; }
190 const VECTOR2I& GetBezierC2() const { return m_bezierC2; }
191
192 VECTOR2I getCenter() const;
193 void SetCenter( const VECTOR2I& aCenter );
194
201 void SetArcAngleAndEnd( const EDA_ANGLE& aAngle, bool aCheckNegativeAngle = false );
202
203 EDA_ANGLE GetArcAngle() const;
204
206
211 bool EndsSwapped() const { return m_endsSwapped; }
212
213 // Some attributes are read only, since they are derived from m_Start, m_End, and m_Angle.
214 // No Set...() function for these attributes.
215
216 VECTOR2I GetArcMid() const;
217 std::vector<VECTOR2I> GetRectCorners() const;
218
223 void CalcArcAngles( EDA_ANGLE& aStartAngle, EDA_ANGLE& aEndAngle ) const;
224
225 int GetRadius() const;
226
233 void SetArcGeometry( const VECTOR2I& aStart, const VECTOR2I& aMid, const VECTOR2I& aEnd );
234
244 void SetCachedArcData( const VECTOR2I& aStart, const VECTOR2I& aMid, const VECTOR2I& aEnd, const VECTOR2I& aCenter );
245
246 const std::vector<VECTOR2I>& GetBezierPoints() const { return m_bezierPoints; }
247
255 void DupPolyPointsList( std::vector<VECTOR2I>& aBuffer ) const;
256
260 int GetPointCount() const;
261
262 // Accessors to the polygonal shape
264 const SHAPE_POLY_SET& GetPolyShape() const { return m_poly; }
265
269 bool IsPolyShapeValid() const;
270
271 void SetPolyShape( const SHAPE_POLY_SET& aShape )
272 {
273 m_poly = aShape;
274
275 for( int ii = 0; ii < m_poly.OutlineCount(); ++ii )
276 {
277 if( m_poly.HoleCount( ii ) )
278 {
280 break;
281 }
282 }
283 }
284
285 void SetPolyPoints( const std::vector<VECTOR2I>& aPoints );
286
297 void RebuildBezierToSegmentsPointsList( int aMinSegLen );
298
305 virtual std::vector<SHAPE*> MakeEffectiveShapes( bool aEdgeOnly = false ) const
306 {
307 return makeEffectiveShapes( aEdgeOnly );
308 }
309
310 void ShapeGetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList );
311
312 void SetLength( const double& aLength );
313
314 void SetRectangle( const long long int& aHeight, const long long int& aWidth );
315
316 void SetSegmentAngle( const EDA_ANGLE& aAngle );
317
318 bool IsClockwiseArc() const;
319
323 double GetLength() const;
324
325 int GetRectangleHeight() const;
326 int GetRectangleWidth() const;
327
338 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, int aClearance, int aError,
339 ERROR_LOC aErrorLoc, bool ignoreLineWidth = false ) const;
340
341 int Compare( const EDA_SHAPE* aOther ) const;
342
343 double Similarity( const EDA_SHAPE& aOther ) const;
344
345 bool operator==( const EDA_SHAPE& aOther ) const;
346
347protected:
348 void setPosition( const VECTOR2I& aPos );
349 VECTOR2I getPosition() const;
350
351 virtual void setFilled( bool aFlag )
352 {
353 m_fill = aFlag ? FILL_T::FILLED_SHAPE : FILL_T::NO_FILL;
354 }
355
356 void move( const VECTOR2I& aMoveVector );
357 void rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
358 void flip( const VECTOR2I& aCentre, bool aFlipLeftRight );
359 void scale( double aScale );
360
361 const BOX2I getBoundingBox() const;
362
363 void computeArcBBox( BOX2I& aBBox ) const;
364
365 bool hitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const;
366 bool hitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const;
367
368 const std::vector<VECTOR2I> buildBezierToSegmentsPointsList( int aMinSegLen ) const;
369
370 void beginEdit( const VECTOR2I& aStartPoint );
371 bool continueEdit( const VECTOR2I& aPosition );
372 void calcEdit( const VECTOR2I& aPosition );
373
378 void endEdit( bool aClosed = true );
379 void setEditState( int aState ) { m_editState = aState; }
380
389 // fixme: move to shape_compound
390 std::vector<SHAPE*> makeEffectiveShapes( bool aEdgeOnly, bool aLineChainOnly = false ) const;
391
392protected:
393 bool m_endsSwapped; // true if start/end were swapped e.g. SetArcAngleAndEnd
394 SHAPE_T m_shape; // Shape: line, Circle, Arc
395 STROKE_PARAMS m_stroke; // Line style, width, etc.
398
399 long long int m_rectangleHeight;
400 long long int m_rectangleWidth;
401
404
405 VECTOR2I m_start; // Line start point or Circle center
406 VECTOR2I m_end; // Line end point or Circle 3 o'clock point
407
408 VECTOR2I m_arcCenter; // Used only for Arcs: arc end point
409 ARC_MID m_arcMidData; // Used to store originating data
410
411 VECTOR2I m_bezierC1; // Bezier Control Point 1
412 VECTOR2I m_bezierC2; // Bezier Control Point 2
413
414 std::vector<VECTOR2I> m_bezierPoints;
415 SHAPE_POLY_SET m_poly; // Stores the S_POLYGON shape
416
418 bool m_proxyItem; // A shape storing proxy information (ie: a pad
419 // number box, thermal spoke template, etc.)
420};
421
422#ifndef SWIG
425#endif
426
427#endif // EDA_SHAPE_H
Generic cubic Bezier representation.
Definition: bezier_curves.h:78
The base class for create windows for drawing purpose.
EDA_ANGLE GetArcAngle() const
Definition: eda_shape.cpp:656
SHAPE_T m_shape
Definition: eda_shape.h:394
wxString GetFriendlyName() const
Definition: eda_shape.cpp:699
void SetStartX(int x)
Definition: eda_shape.h:142
bool m_proxyItem
Definition: eda_shape.h:418
bool m_endsSwapped
Definition: eda_shape.h:393
const VECTOR2I & GetBezierC2() const
Definition: eda_shape.h:190
void SetBezierC2(const VECTOR2I &aPt)
Definition: eda_shape.h:189
void SetCenter(const VECTOR2I &aCenter)
Definition: eda_shape.cpp:538
VECTOR2I getCenter() const
Definition: eda_shape.cpp:512
int GetStartY() const
Definition: eda_shape.h:127
void SetLength(const double &aLength)
Definition: eda_shape.cpp:174
int m_editState
Definition: eda_shape.h:417
virtual VECTOR2I GetTopLeft() const
Definition: eda_shape.h:178
void rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
Definition: eda_shape.cpp:331
void flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
Definition: eda_shape.cpp:388
FILL_T GetFillMode() const
Definition: eda_shape.h:101
virtual ~EDA_SHAPE()
Definition: eda_shape.cpp:55
long long int m_rectangleHeight
Definition: eda_shape.h:399
void SetEndY(int aY)
Definition: eda_shape.h:161
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
Definition: eda_shape.cpp:473
virtual int GetEffectiveWidth() const
Definition: eda_shape.h:110
COLOR4D GetLineColor() const
Definition: eda_shape.h:116
int GetEndX() const
Definition: eda_shape.h:153
int GetRectangleWidth() const
Definition: eda_shape.cpp:162
void SetLineStyle(const LINE_STYLE aStyle)
Definition: eda_shape.cpp:1789
const std::vector< VECTOR2I > buildBezierToSegmentsPointsList(int aMinSegLen) const
Definition: eda_shape.cpp:499
void calcEdit(const VECTOR2I &aPosition)
Definition: eda_shape.cpp:1415
void SetStartY(int y)
Definition: eda_shape.h:136
virtual std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
Definition: eda_shape.h:305
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:263
bool IsFilled() const
Definition: eda_shape.h:90
void CalcArcAngles(EDA_ANGLE &aStartAngle, EDA_ANGLE &aEndAngle) const
Calc arc start and end angles such that aStartAngle < aEndAngle.
Definition: eda_shape.cpp:570
void ShapeGetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Definition: eda_shape.cpp:726
void SetFilled(bool aFlag)
Definition: eda_shape.h:95
bool operator==(const EDA_SHAPE &aOther) const
Definition: eda_shape.cpp:1804
int GetRadius() const
Definition: eda_shape.cpp:586
SHAPE_T GetShape() const
Definition: eda_shape.h:119
void SetPolyShape(const SHAPE_POLY_SET &aShape)
Definition: eda_shape.h:271
virtual VECTOR2I GetBotRight() const
Definition: eda_shape.h:179
virtual void SetBottom(int val)
Definition: eda_shape.h:184
VECTOR2I m_arcCenter
Definition: eda_shape.h:408
double m_segmentLength
Definition: eda_shape.h:402
virtual void SetTop(int val)
Definition: eda_shape.h:181
bool continueEdit(const VECTOR2I &aPosition)
Definition: eda_shape.cpp:1381
wxString ShowShape() const
Definition: eda_shape.cpp:60
ARC_MID m_arcMidData
Definition: eda_shape.h:409
void SetFillColor(const COLOR4D &aColor)
Definition: eda_shape.h:106
int GetEndY() const
Definition: eda_shape.h:152
std::vector< SHAPE * > makeEffectiveShapes(bool aEdgeOnly, bool aLineChainOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
Definition: eda_shape.cpp:1207
bool hitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Definition: eda_shape.cpp:837
void SetCachedArcData(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCenter)
Set the data used for mid point caching.
Definition: eda_shape.cpp:609
void SetEndX(int aX)
Definition: eda_shape.h:167
void beginEdit(const VECTOR2I &aStartPoint)
Definition: eda_shape.cpp:1340
VECTOR2I m_start
Definition: eda_shape.h:405
int GetPointCount() const
Definition: eda_shape.cpp:1329
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:151
bool IsClosed() const
Definition: eda_shape.cpp:209
void SetRadius(int aX)
Definition: eda_shape.h:173
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:130
void DupPolyPointsList(std::vector< VECTOR2I > &aBuffer) const
Duplicate the list of corners in a std::vector<VECTOR2I>
Definition: eda_shape.cpp:1300
LINE_STYLE GetLineStyle() const
Definition: eda_shape.cpp:1795
void endEdit(bool aClosed=true)
Finishes editing the shape.
Definition: eda_shape.cpp:1569
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:126
void SetLineColor(const COLOR4D &aColor)
Definition: eda_shape.h:115
COLOR4D GetFillColor() const
Definition: eda_shape.h:105
void SetRectangle(const long long int &aHeight, const long long int &aWidth)
Definition: eda_shape.cpp:185
void SetShape(SHAPE_T aShape)
Definition: eda_shape.h:118
void SwapShape(EDA_SHAPE *aImage)
Definition: eda_shape.cpp:1606
std::vector< VECTOR2I > GetRectCorners() const
Definition: eda_shape.cpp:1132
void SetSegmentAngle(const EDA_ANGLE &aAngle)
Definition: eda_shape.cpp:199
std::vector< VECTOR2I > m_bezierPoints
Definition: eda_shape.h:414
void setPosition(const VECTOR2I &aPos)
Definition: eda_shape.cpp:103
virtual void setFilled(bool aFlag)
Definition: eda_shape.h:351
const std::vector< VECTOR2I > & GetBezierPoints() const
Definition: eda_shape.h:246
virtual bool IsProxyItem() const
Definition: eda_shape.h:87
void computeArcBBox(BOX2I &aBBox) const
Definition: eda_shape.cpp:1147
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:155
bool EndsSwapped() const
Have the start and end points been swapped since they were set?
Definition: eda_shape.h:211
const SHAPE_POLY_SET & GetPolyShape() const
Definition: eda_shape.h:264
void SetBezierC1(const VECTOR2I &aPt)
Definition: eda_shape.h:186
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
Definition: eda_shape.cpp:618
virtual void SetLeft(int val)
Definition: eda_shape.h:182
double GetLength() const
Definition: eda_shape.cpp:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:87
int GetStartX() const
Definition: eda_shape.h:128
double Similarity(const EDA_SHAPE &aOther) const
Definition: eda_shape.cpp:1849
const VECTOR2I & GetBezierC1() const
Definition: eda_shape.h:187
VECTOR2I m_end
Definition: eda_shape.h:406
const BOX2I getBoundingBox() const
Definition: eda_shape.cpp:783
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
Definition: eda_shape.cpp:684
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:415
int GetRectangleHeight() const
Definition: eda_shape.cpp:150
virtual int GetWidth() const
Definition: eda_shape.h:109
VECTOR2I getPosition() const
Definition: eda_shape.cpp:109
bool IsClockwiseArc() const
Definition: eda_shape.cpp:667
STROKE_PARAMS m_stroke
Definition: eda_shape.h:395
EDA_ANGLE m_segmentAngle
Definition: eda_shape.h:403
void setEditState(int aState)
Definition: eda_shape.h:379
void SetPolyPoints(const std::vector< VECTOR2I > &aPoints)
Definition: eda_shape.cpp:1197
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the shape to a closed polygon.
Definition: eda_shape.cpp:1670
VECTOR2I m_bezierC1
Definition: eda_shape.h:411
FILL_T m_fill
Definition: eda_shape.h:396
COLOR4D m_fillColor
Definition: eda_shape.h:397
void SetWidth(int aWidth)
Definition: eda_shape.h:108
EDA_ANGLE GetSegmentAngle() const
Definition: eda_shape.cpp:647
virtual void SetRight(int val)
Definition: eda_shape.h:183
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:100
virtual void SetIsProxyItem(bool aIsProxy=true)
Definition: eda_shape.h:88
long long int m_rectangleWidth
Definition: eda_shape.h:400
VECTOR2I m_bezierC2
Definition: eda_shape.h:412
bool IsPolyShapeValid() const
Definition: eda_shape.cpp:1317
int Compare(const EDA_SHAPE *aOther) const
Definition: eda_shape.cpp:1629
VECTOR2I GetArcMid() const
Definition: eda_shape.cpp:556
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:54
Represent a set of closed polygons.
void Fracture(POLYGON_MODE aFastMode)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
int OutlineCount() const
Return the number of outlines in the set.
Simple container to manage line stroke parameters.
Definition: stroke_params.h:81
int GetWidth() const
Definition: stroke_params.h:91
void SetWidth(int aWidth)
Definition: stroke_params.h:92
void SetColor(const KIGFX::COLOR4D &aColor)
Definition: stroke_params.h:98
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:97
SHAPE_T
Definition: eda_shape.h:42
@ ARC
use RECTANGLE instead of RECT to avoid collision in a Windows header
FILL_T
Definition: eda_shape.h:54
@ FILLED_WITH_COLOR
@ FILLED_WITH_BG_BODYCOLOR
@ FILLED_SHAPE
a few functions useful in geometry calculations.
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
#define DECLARE_ENUM_TO_WXANY(type)
Definition: property.h:719
const int scale
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:48
VECTOR2I end
Definition: eda_shape.h:67
VECTOR2I center
Definition: eda_shape.h:68
VECTOR2I start
Definition: eda_shape.h:66
VECTOR2I mid
Definition: eda_shape.h:65
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588