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 <stroke_params.h>
32
33class LINE_READER;
34class EDA_DRAW_FRAME;
35class FOOTPRINT;
36class MSG_PANEL_ITEM;
37
38using KIGFX::COLOR4D;
39
40enum class SHAPE_T : int
41{
42 SEGMENT = 0,
43 RECT,
44 ARC,
45 CIRCLE,
46 POLY,
47 BEZIER,
48 LAST
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 bool IsAnnotationProxy() const { return m_annotationProxy; }
88 void SetIsAnnotationProxy( bool aIsProxy = true ) { m_annotationProxy = aIsProxy; }
89
90 bool IsFilled() const
91 {
92 return GetFillMode() != FILL_T::NO_FILL;
93 }
94
95 void SetFilled( bool aFlag )
96 {
97 m_fill = aFlag ? FILL_T::FILLED_SHAPE : FILL_T::NO_FILL;
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 int GetWidth() const { return m_stroke.GetWidth(); }
110 virtual int GetEffectiveWidth() const { return GetWidth(); }
111
112 void SetShape( SHAPE_T aShape ) { m_shape = aShape; }
113 SHAPE_T GetShape() const { return m_shape; }
114
115 wxString GetFriendlyName() const;
116
120 const VECTOR2I& GetStart() const { return m_start; }
121 int GetStartY() const { return m_start.y; }
122 int GetStartX() const { return m_start.x; }
123
124 void SetStart( const VECTOR2I& aStart )
125 {
126 m_start = aStart;
127 m_endsSwapped = false;
128 }
129
130 void SetStartY( int y )
131 {
132 m_start.y = y;
133 m_endsSwapped = false;
134 }
135
136 void SetStartX( int x )
137 {
138 m_start.x = x;
139 m_endsSwapped = false;
140 }
141
145 const VECTOR2I& GetEnd() const { return m_end; }
146 int GetEndY() const { return m_end.y; }
147 int GetEndX() const { return m_end.x; }
148
149 void SetEnd( const VECTOR2I& aEnd )
150 {
151 m_end = aEnd;
152 m_endsSwapped = false;
153 }
154
155 void SetEndY( int y )
156 {
157 m_end.y = y;
158 m_endsSwapped = false;
159 }
160
161 void SetEndX( int x )
162 {
163 m_end.x = x;
164 m_endsSwapped = false;
165 }
166
167 virtual VECTOR2I GetTopLeft() const { return GetStart(); }
168 virtual VECTOR2I GetBotRight() const { return GetEnd(); }
169
170 virtual void SetTop( int val ) { SetStartY( val ); }
171 virtual void SetLeft( int val ) { SetStartX( val ); }
172 virtual void SetRight( int val ) { SetEndX( val ); }
173 virtual void SetBottom( int val ) { SetEndY( val ); }
174
175 void SetBezierC1( const VECTOR2I& aPt ) { m_bezierC1 = aPt; }
176 const VECTOR2I& GetBezierC1() const { return m_bezierC1; }
177
178 void SetBezierC2( const VECTOR2I& aPt ) { m_bezierC2 = aPt; }
179 const VECTOR2I& GetBezierC2() const { return m_bezierC2; }
180
181 VECTOR2I getCenter() const;
182 void SetCenter( const VECTOR2I& aCenter );
183
187 void SetArcAngleAndEnd( const EDA_ANGLE& aAngle, bool aCheckNegativeAngle = false );
188
189 EDA_ANGLE GetArcAngle() const;
190
195 bool EndsSwapped() const { return m_endsSwapped; }
196
197 // Some attributes are read only, since they are derived from m_Start, m_End, and m_Angle.
198 // No Set...() function for these attributes.
199
200 VECTOR2I GetArcMid() const;
201 std::vector<VECTOR2I> GetRectCorners() const;
202
207 void CalcArcAngles( EDA_ANGLE& aStartAngle, EDA_ANGLE& aEndAngle ) const;
208
209 int GetRadius() const;
210
217 void SetArcGeometry( const VECTOR2I& aStart, const VECTOR2I& aMid, const VECTOR2I& aEnd );
218
228 void SetCachedArcData( const VECTOR2I& aStart, const VECTOR2I& aMid, const VECTOR2I& aEnd, const VECTOR2I& aCenter );
229
230 const std::vector<VECTOR2I>& GetBezierPoints() const { return m_bezierPoints; }
231
239 void DupPolyPointsList( std::vector<VECTOR2I>& aBuffer ) const;
240
244 int GetPointCount() const;
245
246 // Accessors to the polygonal shape
248 const SHAPE_POLY_SET& GetPolyShape() const { return m_poly; }
249
253 bool IsPolyShapeValid() const;
254
255 void SetPolyShape( const SHAPE_POLY_SET& aShape )
256 {
257 m_poly = aShape;
258
259 for( int ii = 0; ii < m_poly.OutlineCount(); ++ii )
260 {
261 if( m_poly.HoleCount( ii ) )
262 {
264 break;
265 }
266 }
267 }
268
269 void SetPolyPoints( const std::vector<VECTOR2I>& aPoints );
270
281 void RebuildBezierToSegmentsPointsList( int aMinSegLen );
282
289 virtual std::vector<SHAPE*> MakeEffectiveShapes( bool aEdgeOnly = false ) const
290 {
291 return makeEffectiveShapes( aEdgeOnly );
292 }
293
294 void ShapeGetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList );
295
301 double GetLength() const;
302
313 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, int aClearance, int aError,
314 ERROR_LOC aErrorLoc, bool ignoreLineWidth = false ) const;
315
316 int Compare( const EDA_SHAPE* aOther ) const;
317
318protected:
319 void setPosition( const VECTOR2I& aPos );
320 VECTOR2I getPosition() const;
321
322 void move( const VECTOR2I& aMoveVector );
323 void rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
324 void flip( const VECTOR2I& aCentre, bool aFlipLeftRight );
325 void scale( double aScale );
326
327 const BOX2I getBoundingBox() const;
328
329 void computeArcBBox( BOX2I& aBBox ) const;
330
331 bool hitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const;
332 bool hitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const;
333
334 const std::vector<VECTOR2I> buildBezierToSegmentsPointsList( int aMinSegLen ) const;
335
336 void beginEdit( const VECTOR2I& aStartPoint );
337 bool continueEdit( const VECTOR2I& aPosition );
338 void calcEdit( const VECTOR2I& aPosition );
339
344 void endEdit( bool aClosed = true );
345 void setEditState( int aState ) { m_editState = aState; }
346
355 // fixme: move to shape_compound
356 std::vector<SHAPE*> makeEffectiveShapes( bool aEdgeOnly, bool aLineChainOnly = false ) const;
357
358protected:
359 bool m_endsSwapped; // true if start/end were swapped e.g. SetArcAngleAndEnd
360 SHAPE_T m_shape; // Shape: line, Circle, Arc
361 STROKE_PARAMS m_stroke; // Line style, width, etc.
364
365 VECTOR2I m_start; // Line start point or Circle center
366 VECTOR2I m_end; // Line end point or Circle 3 o'clock point
367
368 VECTOR2I m_arcCenter; // Used only for Arcs: arc end point
369 ARC_MID m_arcMidData; // Used to store originating data
370
371 VECTOR2I m_bezierC1; // Bezier Control Point 1
372 VECTOR2I m_bezierC2; // Bezier Control Point 2
373
374 std::vector<VECTOR2I> m_bezierPoints;
375 SHAPE_POLY_SET m_poly; // Stores the S_POLYGON shape
376
378 bool m_annotationProxy; // A shape storing the position of an annotation
379};
380
381#endif // EDA_SHAPE_H
The base class for create windows for drawing purpose.
EDA_ANGLE GetArcAngle() const
Definition: eda_shape.cpp:585
SHAPE_T m_shape
Definition: eda_shape.h:360
wxString GetFriendlyName() const
Definition: eda_shape.cpp:611
void SetStartX(int x)
Definition: eda_shape.h:136
bool m_endsSwapped
Definition: eda_shape.h:359
const VECTOR2I & GetBezierC2() const
Definition: eda_shape.h:179
void SetBezierC2(const VECTOR2I &aPt)
Definition: eda_shape.h:178
void SetCenter(const VECTOR2I &aCenter)
Definition: eda_shape.cpp:470
VECTOR2I getCenter() const
Definition: eda_shape.cpp:444
int GetStartY() const
Definition: eda_shape.h:121
int m_editState
Definition: eda_shape.h:377
virtual VECTOR2I GetTopLeft() const
Definition: eda_shape.h:167
void rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
Definition: eda_shape.cpp:263
void flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
Definition: eda_shape.cpp:320
FILL_T GetFillMode() const
Definition: eda_shape.h:101
virtual ~EDA_SHAPE()
Definition: eda_shape.cpp:52
void SetEndY(int y)
Definition: eda_shape.h:155
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
Definition: eda_shape.cpp:405
virtual int GetEffectiveWidth() const
Definition: eda_shape.h:110
int GetEndX() const
Definition: eda_shape.h:147
const std::vector< VECTOR2I > buildBezierToSegmentsPointsList(int aMinSegLen) const
Definition: eda_shape.cpp:431
void calcEdit(const VECTOR2I &aPosition)
Definition: eda_shape.cpp:1284
void SetStartY(int y)
Definition: eda_shape.h:130
virtual std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
Definition: eda_shape.h:289
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:247
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:502
void ShapeGetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Definition: eda_shape.cpp:626
void SetFilled(bool aFlag)
Definition: eda_shape.h:95
int GetRadius() const
Definition: eda_shape.cpp:523
SHAPE_T GetShape() const
Definition: eda_shape.h:113
void SetPolyShape(const SHAPE_POLY_SET &aShape)
Definition: eda_shape.h:255
virtual VECTOR2I GetBotRight() const
Definition: eda_shape.h:168
virtual void SetBottom(int val)
Definition: eda_shape.h:173
VECTOR2I m_arcCenter
Definition: eda_shape.h:368
virtual void SetTop(int val)
Definition: eda_shape.h:170
bool m_annotationProxy
Definition: eda_shape.h:378
bool continueEdit(const VECTOR2I &aPosition)
Definition: eda_shape.cpp:1257
wxString ShowShape() const
Definition: eda_shape.cpp:57
ARC_MID m_arcMidData
Definition: eda_shape.h:369
void SetFillColor(const COLOR4D &aColor)
Definition: eda_shape.h:106
int GetEndY() const
Definition: eda_shape.h:146
std::vector< SHAPE * > makeEffectiveShapes(bool aEdgeOnly, bool aLineChainOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
Definition: eda_shape.cpp:1095
bool hitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Definition: eda_shape.cpp:738
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:546
void beginEdit(const VECTOR2I &aStartPoint)
Definition: eda_shape.cpp:1226
void SetEndX(int x)
Definition: eda_shape.h:161
VECTOR2I m_start
Definition: eda_shape.h:365
int GetPointCount() const
Definition: eda_shape.cpp:1215
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:145
bool IsClosed() const
Definition: eda_shape.cpp:141
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:124
void DupPolyPointsList(std::vector< VECTOR2I > &aBuffer) const
Duplicate the list of corners in a std::vector<VECTOR2I>
Definition: eda_shape.cpp:1186
void endEdit(bool aClosed=true)
Finishes editing the shape.
Definition: eda_shape.cpp:1414
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:120
COLOR4D GetFillColor() const
Definition: eda_shape.h:105
void SetShape(SHAPE_T aShape)
Definition: eda_shape.h:112
void SwapShape(EDA_SHAPE *aImage)
Definition: eda_shape.cpp:1446
std::vector< VECTOR2I > GetRectCorners() const
Definition: eda_shape.cpp:1020
std::vector< VECTOR2I > m_bezierPoints
Definition: eda_shape.h:374
int GetWidth() const
Definition: eda_shape.h:109
void setPosition(const VECTOR2I &aPos)
Definition: eda_shape.cpp:93
const std::vector< VECTOR2I > & GetBezierPoints() const
Definition: eda_shape.h:230
void computeArcBBox(BOX2I &aBBox) const
Definition: eda_shape.cpp:1035
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:149
bool EndsSwapped() const
Have the start and end points been swapped since they were set?
Definition: eda_shape.h:195
const SHAPE_POLY_SET & GetPolyShape() const
Definition: eda_shape.h:248
void SetBezierC1(const VECTOR2I &aPt)
Definition: eda_shape.h:175
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
Definition: eda_shape.cpp:555
virtual void SetLeft(int val)
Definition: eda_shape.h:171
double GetLength() const
Return the length of the track using the hypotenuse calculation.
Definition: eda_shape.cpp:110
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:75
int GetStartX() const
Definition: eda_shape.h:122
const VECTOR2I & GetBezierC1() const
Definition: eda_shape.h:176
VECTOR2I m_end
Definition: eda_shape.h:366
const BOX2I getBoundingBox() const
Definition: eda_shape.cpp:684
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
Definition: eda_shape.cpp:596
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:375
VECTOR2I getPosition() const
Definition: eda_shape.cpp:99
STROKE_PARAMS m_stroke
Definition: eda_shape.h:361
void setEditState(int aState)
Definition: eda_shape.h:345
bool IsAnnotationProxy() const
Definition: eda_shape.h:87
void SetIsAnnotationProxy(bool aIsProxy=true)
Definition: eda_shape.h:88
void SetPolyPoints(const std::vector< VECTOR2I > &aPoints)
Definition: eda_shape.cpp:1085
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:1510
VECTOR2I m_bezierC1
Definition: eda_shape.h:371
FILL_T m_fill
Definition: eda_shape.h:362
COLOR4D m_fillColor
Definition: eda_shape.h:363
void SetWidth(int aWidth)
Definition: eda_shape.h:108
virtual void SetRight(int val)
Definition: eda_shape.h:172
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:100
VECTOR2I m_bezierC2
Definition: eda_shape.h:372
bool IsPolyShapeValid() const
Definition: eda_shape.cpp:1203
int Compare(const EDA_SHAPE *aOther) const
Definition: eda_shape.cpp:1469
VECTOR2I GetArcMid() const
Definition: eda_shape.cpp:488
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
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:88
int GetWidth() const
Definition: stroke_params.h:98
void SetWidth(int aWidth)
Definition: stroke_params.h:99
SHAPE_T
Definition: eda_shape.h:41
@ LAST
marker for list end
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...
const int scale
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