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 LAST
50};
51
52
53// WARNING: Do not change these values without updating dialogs that depend on their position values
54enum class FILL_T : int
55{
56 NO_FILL = 1,
57 FILLED_SHAPE, // Fill with object color
58 FILLED_WITH_BG_BODYCOLOR, // Fill with background body color
59 FILLED_WITH_COLOR // Fill with a separate color
60};
61
62
63// Holding struct to keep originating midpoint
64struct ARC_MID
65{
70};
71
73{
74public:
75 EDA_SHAPE( SHAPE_T aType, int aLineWidth, FILL_T aFill );
76
77 // Do not create a copy constructor & operator=.
78 // The ones generated by the compiler are adequate.
79
80 virtual ~EDA_SHAPE();
81
82 void SwapShape( EDA_SHAPE* aImage );
83
84 wxString ShowShape() const;
85
86 wxString SHAPE_T_asString() const;
87
88 virtual bool IsProxyItem() const { return m_proxyItem; }
89 virtual void SetIsProxyItem( bool aIsProxy = true ) { m_proxyItem = aIsProxy; }
90
91 bool IsFilled() const
92 {
93 return GetFillMode() != FILL_T::NO_FILL;
94 }
95
96 void SetFilled( bool aFlag )
97 {
98 m_fill = aFlag ? FILL_T::FILLED_SHAPE : FILL_T::NO_FILL;
99 }
100
101 void SetFillMode( FILL_T aFill ) { m_fill = aFill; }
102 FILL_T GetFillMode() const { return m_fill; }
103
104 bool IsClosed() const;
105
106 COLOR4D GetFillColor() const { return m_fillColor; }
107 void SetFillColor( const COLOR4D& aColor ) { m_fillColor = aColor; }
108
109 void SetWidth( int aWidth ) { m_stroke.SetWidth( aWidth ); }
110 virtual int GetWidth() const { return m_stroke.GetWidth(); }
111 virtual int GetEffectiveWidth() const { return GetWidth(); }
112
113 void SetLineStyle( const PLOT_DASH_TYPE aStyle );
115
116 void SetShape( SHAPE_T aShape ) { m_shape = aShape; }
117 SHAPE_T GetShape() const { return m_shape; }
118
119 wxString GetFriendlyName() const;
120
124 const VECTOR2I& GetStart() const { return m_start; }
125 int GetStartY() const { return m_start.y; }
126 int GetStartX() const { return m_start.x; }
127
128 void SetStart( const VECTOR2I& aStart )
129 {
130 m_start = aStart;
131 m_endsSwapped = false;
132 }
133
134 void SetStartY( int y )
135 {
136 m_start.y = y;
137 m_endsSwapped = false;
138 }
139
140 void SetStartX( int x )
141 {
142 m_start.x = x;
143 m_endsSwapped = false;
144 }
145
149 const VECTOR2I& GetEnd() const { return m_end; }
150 int GetEndY() const { return m_end.y; }
151 int GetEndX() const { return m_end.x; }
152
153 void SetEnd( const VECTOR2I& aEnd )
154 {
155 m_end = aEnd;
156 m_endsSwapped = false;
157 }
158
159 void SetEndY( int y )
160 {
161 m_end.y = y;
162 m_endsSwapped = false;
163 }
164
165 void SetEndX( int x )
166 {
167 m_end.x = x;
168 m_endsSwapped = false;
169 }
170
171 virtual VECTOR2I GetTopLeft() const { return GetStart(); }
172 virtual VECTOR2I GetBotRight() const { return GetEnd(); }
173
174 virtual void SetTop( int val ) { SetStartY( val ); }
175 virtual void SetLeft( int val ) { SetStartX( val ); }
176 virtual void SetRight( int val ) { SetEndX( val ); }
177 virtual void SetBottom( int val ) { SetEndY( val ); }
178
179 void SetBezierC1( const VECTOR2I& aPt ) { m_bezierC1 = aPt; }
180 const VECTOR2I& GetBezierC1() const { return m_bezierC1; }
181
182 void SetBezierC2( const VECTOR2I& aPt ) { m_bezierC2 = aPt; }
183 const VECTOR2I& GetBezierC2() const { return m_bezierC2; }
184
185 VECTOR2I getCenter() const;
186 void SetCenter( const VECTOR2I& aCenter );
187
194 void SetArcAngleAndEnd( const EDA_ANGLE& aAngle, bool aCheckNegativeAngle = false );
195
196 EDA_ANGLE GetArcAngle() const;
197
199
204 bool EndsSwapped() const { return m_endsSwapped; }
205
206 // Some attributes are read only, since they are derived from m_Start, m_End, and m_Angle.
207 // No Set...() function for these attributes.
208
209 VECTOR2I GetArcMid() const;
210 std::vector<VECTOR2I> GetRectCorners() const;
211
216 void CalcArcAngles( EDA_ANGLE& aStartAngle, EDA_ANGLE& aEndAngle ) const;
217
218 int GetRadius() const;
219
226 void SetArcGeometry( const VECTOR2I& aStart, const VECTOR2I& aMid, const VECTOR2I& aEnd );
227
237 void SetCachedArcData( const VECTOR2I& aStart, const VECTOR2I& aMid, const VECTOR2I& aEnd, const VECTOR2I& aCenter );
238
239 const std::vector<VECTOR2I>& GetBezierPoints() const { return m_bezierPoints; }
240
248 void DupPolyPointsList( std::vector<VECTOR2I>& aBuffer ) const;
249
253 int GetPointCount() const;
254
255 // Accessors to the polygonal shape
257 const SHAPE_POLY_SET& GetPolyShape() const { return m_poly; }
258
262 bool IsPolyShapeValid() const;
263
264 void SetPolyShape( const SHAPE_POLY_SET& aShape )
265 {
266 m_poly = aShape;
267
268 for( int ii = 0; ii < m_poly.OutlineCount(); ++ii )
269 {
270 if( m_poly.HoleCount( ii ) )
271 {
273 break;
274 }
275 }
276 }
277
278 void SetPolyPoints( const std::vector<VECTOR2I>& aPoints );
279
290 void RebuildBezierToSegmentsPointsList( int aMinSegLen );
291
298 virtual std::vector<SHAPE*> MakeEffectiveShapes( bool aEdgeOnly = false ) const
299 {
300 return makeEffectiveShapes( aEdgeOnly );
301 }
302
303 void ShapeGetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList );
304
305 void SetLength( const double& aLength );
306
307 void SetRectangle( const long long int& aHeight, const long long int& aWidth );
308
309 void SetSegmentAngle( const EDA_ANGLE& aAngle );
310
314 double GetLength() const;
315
316 int GetRectangleHeight() const;
317 int GetRectangleWidth() const;
318
329 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, int aClearance, int aError,
330 ERROR_LOC aErrorLoc, bool ignoreLineWidth = false ) const;
331
332 int Compare( const EDA_SHAPE* aOther ) const;
333
334protected:
335 void setPosition( const VECTOR2I& aPos );
336 VECTOR2I getPosition() const;
337
338 void move( const VECTOR2I& aMoveVector );
339 void rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
340 void flip( const VECTOR2I& aCentre, bool aFlipLeftRight );
341 void scale( double aScale );
342
343 const BOX2I getBoundingBox() const;
344
345 void computeArcBBox( BOX2I& aBBox ) const;
346
347 bool hitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const;
348 bool hitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const;
349
350 const std::vector<VECTOR2I> buildBezierToSegmentsPointsList( int aMinSegLen ) const;
351
352 void beginEdit( const VECTOR2I& aStartPoint );
353 bool continueEdit( const VECTOR2I& aPosition );
354 void calcEdit( const VECTOR2I& aPosition );
355
360 void endEdit( bool aClosed = true );
361 void setEditState( int aState ) { m_editState = aState; }
362
371 // fixme: move to shape_compound
372 std::vector<SHAPE*> makeEffectiveShapes( bool aEdgeOnly, bool aLineChainOnly = false ) const;
373
374protected:
375 bool m_endsSwapped; // true if start/end were swapped e.g. SetArcAngleAndEnd
376 SHAPE_T m_shape; // Shape: line, Circle, Arc
377 STROKE_PARAMS m_stroke; // Line style, width, etc.
380
381 long long int m_rectangleHeight;
382 long long int m_rectangleWidth;
383
386
387 VECTOR2I m_start; // Line start point or Circle center
388 VECTOR2I m_end; // Line end point or Circle 3 o'clock point
389
390 VECTOR2I m_arcCenter; // Used only for Arcs: arc end point
391 ARC_MID m_arcMidData; // Used to store originating data
392
393 VECTOR2I m_bezierC1; // Bezier Control Point 1
394 VECTOR2I m_bezierC2; // Bezier Control Point 2
395
396 std::vector<VECTOR2I> m_bezierPoints;
397 SHAPE_POLY_SET m_poly; // Stores the S_POLYGON shape
398
400 bool m_proxyItem; // A shape storing proxy information (ie: a pad
401 // number box, thermal spoke template, etc.)
402};
403
404#ifndef SWIG
407#endif
408
409#endif // EDA_SHAPE_H
The base class for create windows for drawing purpose.
EDA_ANGLE GetArcAngle() const
Definition: eda_shape.cpp:658
SHAPE_T m_shape
Definition: eda_shape.h:376
wxString GetFriendlyName() const
Definition: eda_shape.cpp:684
void SetStartX(int x)
Definition: eda_shape.h:140
bool m_proxyItem
Definition: eda_shape.h:400
bool m_endsSwapped
Definition: eda_shape.h:375
const VECTOR2I & GetBezierC2() const
Definition: eda_shape.h:183
void SetBezierC2(const VECTOR2I &aPt)
Definition: eda_shape.h:182
void SetCenter(const VECTOR2I &aCenter)
Definition: eda_shape.cpp:540
VECTOR2I getCenter() const
Definition: eda_shape.cpp:514
int GetStartY() const
Definition: eda_shape.h:125
void SetLength(const double &aLength)
Definition: eda_shape.cpp:176
int m_editState
Definition: eda_shape.h:399
virtual VECTOR2I GetTopLeft() const
Definition: eda_shape.h:171
void rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
Definition: eda_shape.cpp:333
void flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
Definition: eda_shape.cpp:390
FILL_T GetFillMode() const
Definition: eda_shape.h:102
virtual ~EDA_SHAPE()
Definition: eda_shape.cpp:55
void SetEndY(int y)
Definition: eda_shape.h:159
long long int m_rectangleHeight
Definition: eda_shape.h:381
PLOT_DASH_TYPE GetLineStyle() const
Definition: eda_shape.cpp:1715
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
Definition: eda_shape.cpp:475
virtual int GetEffectiveWidth() const
Definition: eda_shape.h:111
int GetEndX() const
Definition: eda_shape.h:151
int GetRectangleWidth() const
Definition: eda_shape.cpp:164
const std::vector< VECTOR2I > buildBezierToSegmentsPointsList(int aMinSegLen) const
Definition: eda_shape.cpp:501
void calcEdit(const VECTOR2I &aPosition)
Definition: eda_shape.cpp:1371
void SetStartY(int y)
Definition: eda_shape.h:134
virtual std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
Definition: eda_shape.h:298
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:256
bool IsFilled() const
Definition: eda_shape.h:91
void CalcArcAngles(EDA_ANGLE &aStartAngle, EDA_ANGLE &aEndAngle) const
Calc arc start and end angles such that aStartAngle < aEndAngle.
Definition: eda_shape.cpp:572
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: eda_shape.cpp:1709
void ShapeGetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Definition: eda_shape.cpp:711
void SetFilled(bool aFlag)
Definition: eda_shape.h:96
int GetRadius() const
Definition: eda_shape.cpp:588
SHAPE_T GetShape() const
Definition: eda_shape.h:117
void SetPolyShape(const SHAPE_POLY_SET &aShape)
Definition: eda_shape.h:264
virtual VECTOR2I GetBotRight() const
Definition: eda_shape.h:172
virtual void SetBottom(int val)
Definition: eda_shape.h:177
VECTOR2I m_arcCenter
Definition: eda_shape.h:390
double m_segmentLength
Definition: eda_shape.h:384
virtual void SetTop(int val)
Definition: eda_shape.h:174
bool continueEdit(const VECTOR2I &aPosition)
Definition: eda_shape.cpp:1344
wxString ShowShape() const
Definition: eda_shape.cpp:60
ARC_MID m_arcMidData
Definition: eda_shape.h:391
void SetFillColor(const COLOR4D &aColor)
Definition: eda_shape.h:107
int GetEndY() const
Definition: eda_shape.h:150
std::vector< SHAPE * > makeEffectiveShapes(bool aEdgeOnly, bool aLineChainOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
Definition: eda_shape.cpp:1180
bool hitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Definition: eda_shape.cpp:823
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:611
void beginEdit(const VECTOR2I &aStartPoint)
Definition: eda_shape.cpp:1313
void SetEndX(int x)
Definition: eda_shape.h:165
VECTOR2I m_start
Definition: eda_shape.h:387
int GetPointCount() const
Definition: eda_shape.cpp:1302
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:149
bool IsClosed() const
Definition: eda_shape.cpp:211
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:128
void DupPolyPointsList(std::vector< VECTOR2I > &aBuffer) const
Duplicate the list of corners in a std::vector<VECTOR2I>
Definition: eda_shape.cpp:1273
void endEdit(bool aClosed=true)
Finishes editing the shape.
Definition: eda_shape.cpp:1497
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:124
COLOR4D GetFillColor() const
Definition: eda_shape.h:106
void SetRectangle(const long long int &aHeight, const long long int &aWidth)
Definition: eda_shape.cpp:187
void SetShape(SHAPE_T aShape)
Definition: eda_shape.h:116
void SwapShape(EDA_SHAPE *aImage)
Definition: eda_shape.cpp:1533
std::vector< VECTOR2I > GetRectCorners() const
Definition: eda_shape.cpp:1105
void SetSegmentAngle(const EDA_ANGLE &aAngle)
Definition: eda_shape.cpp:201
std::vector< VECTOR2I > m_bezierPoints
Definition: eda_shape.h:396
void setPosition(const VECTOR2I &aPos)
Definition: eda_shape.cpp:105
const std::vector< VECTOR2I > & GetBezierPoints() const
Definition: eda_shape.h:239
virtual bool IsProxyItem() const
Definition: eda_shape.h:88
void computeArcBBox(BOX2I &aBBox) const
Definition: eda_shape.cpp:1120
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:153
bool EndsSwapped() const
Have the start and end points been swapped since they were set?
Definition: eda_shape.h:204
const SHAPE_POLY_SET & GetPolyShape() const
Definition: eda_shape.h:257
void SetBezierC1(const VECTOR2I &aPt)
Definition: eda_shape.h:179
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
Definition: eda_shape.cpp:620
virtual void SetLeft(int val)
Definition: eda_shape.h:175
double GetLength() const
Definition: eda_shape.cpp:122
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:87
int GetStartX() const
Definition: eda_shape.h:126
const VECTOR2I & GetBezierC1() const
Definition: eda_shape.h:180
VECTOR2I m_end
Definition: eda_shape.h:388
const BOX2I getBoundingBox() const
Definition: eda_shape.cpp:769
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
Definition: eda_shape.cpp:669
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:397
int GetRectangleHeight() const
Definition: eda_shape.cpp:152
virtual int GetWidth() const
Definition: eda_shape.h:110
VECTOR2I getPosition() const
Definition: eda_shape.cpp:111
STROKE_PARAMS m_stroke
Definition: eda_shape.h:377
EDA_ANGLE m_segmentAngle
Definition: eda_shape.h:385
void setEditState(int aState)
Definition: eda_shape.h:361
void SetPolyPoints(const std::vector< VECTOR2I > &aPoints)
Definition: eda_shape.cpp:1170
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:1597
VECTOR2I m_bezierC1
Definition: eda_shape.h:393
FILL_T m_fill
Definition: eda_shape.h:378
COLOR4D m_fillColor
Definition: eda_shape.h:379
void SetWidth(int aWidth)
Definition: eda_shape.h:109
EDA_ANGLE GetSegmentAngle() const
Definition: eda_shape.cpp:649
virtual void SetRight(int val)
Definition: eda_shape.h:176
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:101
virtual void SetIsProxyItem(bool aIsProxy=true)
Definition: eda_shape.h:89
long long int m_rectangleWidth
Definition: eda_shape.h:382
VECTOR2I m_bezierC2
Definition: eda_shape.h:394
bool IsPolyShapeValid() const
Definition: eda_shape.cpp:1290
int Compare(const EDA_SHAPE *aOther) const
Definition: eda_shape.cpp:1556
VECTOR2I GetArcMid() const
Definition: eda_shape.cpp:558
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
SHAPE_T
Definition: eda_shape.h:42
@ ARC
use RECTANGLE instead of RECT to avoid collision in a Windows header
@ LAST
marker for list end
FILL_T
Definition: eda_shape.h:55
@ 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:706
const int scale
PLOT_DASH_TYPE
Dashed line types.
Definition: stroke_params.h:48
VECTOR2I end
Definition: eda_shape.h:68
VECTOR2I center
Definition: eda_shape.h:69
VECTOR2I start
Definition: eda_shape.h:67
VECTOR2I mid
Definition: eda_shape.h:66