45#include <api/common/types/base_types.pb.h>
49 m_endsSwapped( false ),
54 m_hatchingDirty( true ),
55 m_rectangleHeight( 0 ),
56 m_rectangleWidth( 0 ),
70 m_endsSwapped( false ),
73 m_hatchingDirty( true ),
74 m_rectangleHeight( 0 ),
75 m_rectangleWidth( 0 ),
80 switch( aShape.
Type() )
84 auto rect =
static_cast<const SHAPE_RECT&
>( aShape );
87 SetEnd( rect.GetPosition() + rect.GetSize() );
122 auto arc =
static_cast<const SHAPE_ARC&
>( aShape );
152 types::GraphicShape shape;
154 types::StrokeAttributes* stroke = shape.mutable_attributes()->mutable_stroke();
155 types::GraphicFillAttributes* fill = shape.mutable_attributes()->mutable_fill();
157 stroke->mutable_width()->set_value_nm(
GetWidth() );
161 case LINE_STYLE::DEFAULT: stroke->set_style( types::SLS_DEFAULT );
break;
162 case LINE_STYLE::SOLID: stroke->set_style( types::SLS_SOLID );
break;
163 case LINE_STYLE::DASH: stroke->set_style( types::SLS_DASH );
break;
164 case LINE_STYLE::DOT: stroke->set_style( types::SLS_DOT );
break;
165 case LINE_STYLE::DASHDOT: stroke->set_style( types::SLS_DASHDOT );
break;
166 case LINE_STYLE::DASHDOTDOT: stroke->set_style( types::SLS_DASHDOTDOT );
break;
172 case FILL_T::FILLED_SHAPE: fill->set_fill_type( types::GFT_FILLED );
break;
173 default: fill->set_fill_type( types::GFT_UNFILLED );
break;
178 case SHAPE_T::SEGMENT:
180 types::GraphicSegmentAttributes* segment = shape.mutable_segment();
181 PackVector2( *segment->mutable_start(),
GetStart() );
182 PackVector2( *segment->mutable_end(),
GetEnd() );
186 case SHAPE_T::RECTANGLE:
188 types::GraphicRectangleAttributes* rectangle = shape.mutable_rectangle();
189 PackVector2( *rectangle->mutable_top_left(),
GetStart() );
190 PackVector2( *rectangle->mutable_bottom_right(),
GetEnd() );
196 types::GraphicArcAttributes* arc = shape.mutable_arc();
197 PackVector2( *arc->mutable_start(),
GetStart() );
198 PackVector2( *arc->mutable_mid(),
GetArcMid() );
199 PackVector2( *arc->mutable_end(),
GetEnd() );
203 case SHAPE_T::CIRCLE:
205 types::GraphicCircleAttributes*
circle = shape.mutable_circle();
207 PackVector2( *
circle->mutable_radius_point(),
GetEnd() );
213 PackPolySet( *shape.mutable_polygon(),
GetPolyShape() );
217 case SHAPE_T::BEZIER:
219 types::GraphicBezierAttributes* bezier = shape.mutable_bezier();
220 PackVector2( *bezier->mutable_start(),
GetStart() );
221 PackVector2( *bezier->mutable_control1(),
GetBezierC1() );
222 PackVector2( *bezier->mutable_control2(),
GetBezierC2() );
223 PackVector2( *bezier->mutable_end(),
GetEnd() );
228 wxASSERT_MSG(
false,
"Unhandled shape in PCB_SHAPE::Serialize" );
233 aContainer.PackFrom( shape );
241 types::GraphicShape shape;
243 if( !aContainer.UnpackTo( &shape ) )
258 SetFilled( shape.attributes().fill().fill_type() == types::GFT_FILLED );
259 SetWidth( shape.attributes().stroke().width().value_nm() );
261 switch( shape.attributes().stroke().style() )
263 case types::SLS_DEFAULT:
SetLineStyle( LINE_STYLE::DEFAULT );
break;
264 case types::SLS_SOLID:
SetLineStyle( LINE_STYLE::SOLID );
break;
265 case types::SLS_DASH:
SetLineStyle( LINE_STYLE::DASH );
break;
266 case types::SLS_DOT:
SetLineStyle( LINE_STYLE::DOT );
break;
267 case types::SLS_DASHDOT:
SetLineStyle( LINE_STYLE::DASHDOT );
break;
268 case types::SLS_DASHDOTDOT:
SetLineStyle( LINE_STYLE::DASHDOTDOT );
break;
272 if( shape.has_segment() )
275 SetStart( UnpackVector2( shape.segment().start() ) );
276 SetEnd( UnpackVector2( shape.segment().end() ) );
278 else if( shape.has_rectangle() )
281 SetStart( UnpackVector2( shape.rectangle().top_left() ) );
282 SetEnd( UnpackVector2( shape.rectangle().bottom_right() ) );
284 else if( shape.has_arc() )
288 UnpackVector2( shape.arc().mid() ),
289 UnpackVector2( shape.arc().end() ) );
291 else if( shape.has_circle() )
294 SetStart( UnpackVector2( shape.circle().center() ) );
295 SetEnd( UnpackVector2( shape.circle().radius_point() ) );
297 else if( shape.has_polygon() )
302 else if( shape.has_bezier() )
305 SetStart( UnpackVector2( shape.bezier().start() ) );
306 SetBezierC1( UnpackVector2( shape.bezier().control1() ) );
307 SetBezierC2( UnpackVector2( shape.bezier().control2() ) );
308 SetEnd( UnpackVector2( shape.bezier().end() ) );
322 case SHAPE_T::SEGMENT:
return _(
"Thermal Spoke" );
323 case SHAPE_T::RECTANGLE:
return _(
"Number Box" );
324 default:
return wxT(
"??" );
331 case SHAPE_T::SEGMENT:
return _(
"Line" );
332 case SHAPE_T::RECTANGLE:
return _(
"Rect" );
333 case SHAPE_T::ARC:
return _(
"Arc" );
334 case SHAPE_T::CIRCLE:
return _(
"Circle" );
335 case SHAPE_T::BEZIER:
return _(
"Bezier Curve" );
336 case SHAPE_T::POLY:
return _(
"Polygon" );
337 default:
return wxT(
"??" );
347 case SHAPE_T::SEGMENT:
return wxS(
"S_SEGMENT" );
348 case SHAPE_T::RECTANGLE:
return wxS(
"S_RECT" );
349 case SHAPE_T::ARC:
return wxS(
"S_ARC" );
350 case SHAPE_T::CIRCLE:
return wxS(
"S_CIRCLE" );
351 case SHAPE_T::POLY:
return wxS(
"S_POLYGON" );
352 case SHAPE_T::BEZIER:
return wxS(
"S_CURVE" );
353 case SHAPE_T::UNDEFINED:
return wxS(
"UNDEFINED" );
356 return wxEmptyString;
370 else if(
m_shape == SHAPE_T::POLY )
383 case SHAPE_T::BEZIER:
389 case SHAPE_T::SEGMENT:
412 case SHAPE_T::RECTANGLE:
426 case SHAPE_T::RECTANGLE:
440 case SHAPE_T::SEGMENT:
454 case SHAPE_T::RECTANGLE:
469 case SHAPE_T::RECTANGLE:
484 case SHAPE_T::RECTANGLE:
499 case SHAPE_T::SEGMENT:
513 case SHAPE_T::CIRCLE:
514 case SHAPE_T::RECTANGLE:
518 case SHAPE_T::SEGMENT:
527 case SHAPE_T::BEZIER:
551 case UI_FILL_MODE::NONE:
SetFillMode( FILL_T::NO_FILL );
break;
552 case UI_FILL_MODE::HATCH:
SetFillMode( FILL_T::HATCH );
break;
553 case UI_FILL_MODE::REVERSE_HATCH:
SetFillMode( FILL_T::REVERSE_HATCH );
break;
554 case UI_FILL_MODE::CROSS_HATCH:
SetFillMode( FILL_T::CROSS_HATCH );
break;
564 case FILL_T::NO_FILL:
return UI_FILL_MODE::NONE;
565 case FILL_T::HATCH:
return UI_FILL_MODE::HATCH;
566 case FILL_T::REVERSE_HATCH:
return UI_FILL_MODE::REVERSE_HATCH;
567 case FILL_T::CROSS_HATCH:
return UI_FILL_MODE::CROSS_HATCH;
568 default:
return UI_FILL_MODE::SOLID;
580 std::vector<double> slopes;
588 slopes = { 1.0, -1.0 };
602 case SHAPE_T::SEGMENT:
603 case SHAPE_T::BEZIER:
606 case SHAPE_T::RECTANGLE:
614 case SHAPE_T::CIRCLE:
635 int maxError = lineWidth;
656 hole_base.
Append( corner );
657 corner.
x += hole_size;
658 hole_base.
Append( corner );
659 corner.
y += hole_size;
660 hole_base.
Append( corner );
662 hole_base.
Append( corner );
669 int x_offset = bbox.
GetX() - ( bbox.
GetX() ) % gridsize - gridsize;
670 int y_offset = bbox.
GetY() - ( bbox.
GetY() ) % gridsize - gridsize;
672 for(
int xx = x_offset; xx <= bbox.
GetRight(); xx += gridsize )
674 for(
int yy = y_offset; yy <= bbox.
GetBottom(); yy += gridsize )
704 case SHAPE_T::SEGMENT:
705 case SHAPE_T::RECTANGLE:
706 case SHAPE_T::CIRCLE:
708 m_end += aMoveVector;
715 case SHAPE_T::BEZIER:
717 m_end += aMoveVector;
739 pt.x =
KiROUND( pt.x * aScale );
740 pt.y =
KiROUND( pt.y * aScale );
749 case SHAPE_T::SEGMENT:
750 case SHAPE_T::RECTANGLE:
755 case SHAPE_T::CIRCLE:
763 std::vector<VECTOR2I> pts;
769 pts.emplace_back( pt );
770 scalePt( pts.back() );
778 case SHAPE_T::BEZIER:
799 case SHAPE_T::SEGMENT:
800 case SHAPE_T::CIRCLE:
815 case SHAPE_T::RECTANGLE:
838 case SHAPE_T::BEZIER:
862 case SHAPE_T::SEGMENT:
863 case SHAPE_T::RECTANGLE:
868 case SHAPE_T::CIRCLE:
885 case SHAPE_T::BEZIER:
906 if(
m_shape != SHAPE_T::BEZIER )
919 std::vector<VECTOR2I> bezierPoints;
924 converter.
GetPoly( bezierPoints, aMaxError );
937 case SHAPE_T::CIRCLE:
940 case SHAPE_T::SEGMENT:
945 case SHAPE_T::RECTANGLE:
946 case SHAPE_T::BEZIER:
964 case SHAPE_T::CIRCLE:
997 if( aEndAngle == aStartAngle )
1000 while( aEndAngle < aStartAngle )
1015 case SHAPE_T::CIRCLE:
1024 if(
radius > (
double) INT_MAX / 2.0 )
1025 radius = (double) INT_MAX / 2.0;
1087 return endAngle - startAngle;
1115 if( aCheckNegativeAngle && aAngle <
ANGLE_0 )
1129 case SHAPE_T::RECTANGLE:
return _(
"Pad Number Box" );
1130 case SHAPE_T::SEGMENT:
return _(
"Thermal Spoke Template" );
1131 default:
return _(
"Unrecognized" );
1138 case SHAPE_T::CIRCLE:
return _(
"Circle" );
1139 case SHAPE_T::ARC:
return _(
"Arc" );
1140 case SHAPE_T::BEZIER:
return _(
"Curve" );
1141 case SHAPE_T::POLY:
return _(
"Polygon" );
1142 case SHAPE_T::RECTANGLE:
return _(
"Rectangle" );
1143 case SHAPE_T::SEGMENT:
return _(
"Segment" );
1144 default:
return _(
"Unrecognized" );
1154 wxString shape =
_(
"Shape" );
1159 case SHAPE_T::CIRCLE:
1167 aList.emplace_back(
_(
"Angle" ), msg );
1172 case SHAPE_T::BEZIER:
1177 msg.Printf( wxS(
"%d" ),
GetPolyShape().Outline(0).PointCount() );
1178 aList.emplace_back(
_(
"Points" ), msg );
1181 case SHAPE_T::RECTANGLE:
1182 aList.emplace_back(
_(
"Width" ),
1185 aList.emplace_back(
_(
"Height" ),
1189 case SHAPE_T::SEGMENT:
1191 aList.emplace_back(
_(
"Length" ),
1215 case SHAPE_T::RECTANGLE:
1221 case SHAPE_T::SEGMENT:
1226 case SHAPE_T::CIRCLE:
1240 bbox.
Merge( *iter );
1244 case SHAPE_T::BEZIER:
1265 double maxdist = aAccuracy;
1272 case SHAPE_T::CIRCLE:
1278 return dist <=
radius + maxdist;
1279 else if( abs(
radius - dist ) <= maxdist )
1303 if( dist >
radius + maxdist )
1309 if( abs(
radius - dist ) > maxdist )
1324 if( endAngle > startAngle )
1325 return relPosAngle >= startAngle && relPosAngle <= endAngle;
1327 return relPosAngle >= startAngle || relPosAngle <= endAngle;
1330 case SHAPE_T::BEZIER:
1333 std::vector<VECTOR2I> updatedBezierPoints;
1338 converter.
GetPoly( updatedBezierPoints, aAccuracy / 2 );
1339 pts = &updatedBezierPoints;
1342 for(
unsigned int i = 1; i < pts->size(); i++ )
1344 if(
TestSegmentHit( aPosition, ( *pts )[i - 1], ( *pts )[i], maxdist ) )
1350 case SHAPE_T::SEGMENT:
1353 case SHAPE_T::RECTANGLE:
1362 return poly.
Collide( aPosition, maxdist );
1389 copy.SetClosed(
true );
1390 return copy.Collide( aPosition, maxdist );
1417 BOX2I arect = aRect;
1425 case SHAPE_T::CIRCLE:
1464 case SHAPE_T::RECTANGLE:
1481 case SHAPE_T::SEGMENT:
1513 for(
int jj = 0; jj < count; jj++ )
1521 if( jj + 1 < count )
1543 case SHAPE_T::BEZIER:
1558 std::vector<VECTOR2I> updatedBezierPoints;
1563 converter.
GetPoly( updatedBezierPoints, aAccuracy / 2 );
1564 pts = &updatedBezierPoints;
1567 for(
unsigned ii = 1; ii < pts->size(); ii++ )
1569 VECTOR2I vertex = ( *pts )[ii - 1];
1570 VECTOR2I vertexNext = ( *pts )[ii];
1601 std::vector<VECTOR2I> pts;
1605 pts.emplace_back( topLeft );
1606 pts.emplace_back( botRight.
x, topLeft.
y );
1607 pts.emplace_back( botRight );
1608 pts.emplace_back( topLeft.
x, botRight.
y );
1616 std::vector<VECTOR2I> pts;
1665 std::vector<VECTOR2I> corners;
1670 corners.emplace_back( pt );
1673 while( corners.size() < 4 )
1674 corners.emplace_back( corners.back() +
VECTOR2I( 10, 10 ) );
1681 for(
const VECTOR2I& corner : corners )
1683 if( corner.x < minX.
x )
1686 if( corner.x > maxX.
x )
1689 if( corner.y < minY.
y )
1692 if( corner.y > maxY.
y )
1698 pts.emplace_back( minX );
1699 pts.emplace_back( minY );
1700 pts.emplace_back( maxX );
1701 pts.emplace_back( maxY );
1705 pts.emplace_back( maxY );
1706 pts.emplace_back( minX );
1707 pts.emplace_back( minY );
1708 pts.emplace_back( maxX );
1712 pts.emplace_back( maxX );
1713 pts.emplace_back( maxY );
1714 pts.emplace_back( minX );
1715 pts.emplace_back( minY );
1719 pts.emplace_back( minY );
1720 pts.emplace_back( maxX );
1721 pts.emplace_back( maxY );
1722 pts.emplace_back( minX );
1751 if( t1 < ANGLE_0 && t2 >
ANGLE_0 )
1754 if( t1 < ANGLE_90 && t2 >
ANGLE_90 )
1765 if( t1 < ANGLE_0 || t2 >
ANGLE_0 )
1768 if( t1 < ANGLE_90 || t2 >
ANGLE_90 )
1792 std::vector<SHAPE*> effectiveShapes;
1802 case SHAPE_T::SEGMENT:
1806 case SHAPE_T::RECTANGLE:
1811 effectiveShapes.emplace_back(
new SHAPE_SIMPLE( pts ) );
1813 if( width > 0 || !solidFill )
1815 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( pts[0], pts[1], width ) );
1816 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( pts[1], pts[2], width ) );
1817 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( pts[2], pts[3], width ) );
1818 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( pts[3], pts[0], width ) );
1823 case SHAPE_T::CIRCLE:
1828 if( width > 0 || !solidFill )
1834 case SHAPE_T::BEZIER:
1837 VECTOR2I start_pt = bezierPoints[0];
1839 for(
unsigned int jj = 1; jj < bezierPoints.size(); jj++ )
1841 VECTOR2I end_pt = bezierPoints[jj];
1842 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( start_pt, end_pt, width ) );
1865 if( aLineChainOnly && l.
IsClosed() )
1868 for(
int jj = 0; jj < segCount; jj++ )
1880 return effectiveShapes;
1892 aBuffer.reserve( pointCount );
1895 aBuffer.emplace_back( iter->x, iter->y );
1920 case SHAPE_T::SEGMENT:
1921 case SHAPE_T::CIRCLE:
1922 case SHAPE_T::RECTANGLE:
1932 case SHAPE_T::BEZIER:
1962 case SHAPE_T::SEGMENT:
1963 case SHAPE_T::CIRCLE:
1964 case SHAPE_T::RECTANGLE:
1967 case SHAPE_T::BEZIER:
1980 poly.
Append( aPosition,
true );
1993#define sq( x ) pow( x, 2 )
1997 case SHAPE_T::SEGMENT:
1998 case SHAPE_T::CIRCLE:
1999 case SHAPE_T::RECTANGLE:
2003 case SHAPE_T::BEZIER:
2064 if( chordBefore > 0 )
2065 ratio = chordAfter / chordBefore;
2068 radius = std::max( sqrt(
sq(
radius ) * ratio ), sqrt( chordAfter ) / 2 );
2076 radius = ( radialA + radialB ) / 2.0;
2090 double sqRadDiff = (
radius *
radius ) - ( l * l ) / 4.0;
2095 if( l > 0 && sqRadDiff >= 0 )
2150 case SHAPE_T::SEGMENT:
2151 case SHAPE_T::CIRCLE:
2152 case SHAPE_T::RECTANGLE:
2153 case SHAPE_T::BEZIER:
2187 #define SWAPITEM( x ) std::swap( x, image->x )
2211#define TEST( a, b ) { if( a != b ) return a - b; }
2212#define TEST_E( a, b ) { if( abs( a - b ) > EPSILON ) return a - b; }
2213#define TEST_PT( a, b ) { TEST_E( a.x, b.x ); TEST_E( a.y, b.y ); }
2224 else if(
m_shape == SHAPE_T::BEZIER )
2229 else if(
m_shape == SHAPE_T::POLY )
2249 ERROR_LOC aErrorLoc,
bool ignoreLineWidth,
2250 bool includeFill )
const
2253 int width = ignoreLineWidth ? 0 :
GetWidth();
2255 width += 2 * aClearance;
2259 case SHAPE_T::CIRCLE:
2271 case SHAPE_T::RECTANGLE:
2283 if( width > 0 || !solidFill )
2299 case SHAPE_T::SEGMENT:
2321 int inflate = width / 2;
2326 tmp.
Inflate( inflate, CORNER_STRATEGY::ROUND_ALL_CORNERS, aError );
2338 for(
int jj = 0; jj < (int) poly.
SegmentCount(); ++jj )
2349 case SHAPE_T::BEZIER:
2353 std::vector<VECTOR2I> poly;
2354 converter.
GetPoly( poly, aError );
2356 for(
unsigned ii = 1; ii < poly.size(); ii++ )
2393 return LINE_STYLE::SOLID;
2447 double similarity = 1.0;
2482 similarity *= std::pow( 0.9, m + n - 2 * longest );
2488 std::vector<VECTOR2I> poly;
2489 std::vector<VECTOR2I> otherPoly;
2497 for(
int ii = 0; ii < m; ++ii )
2505 for(
int ii = 0; ii < n; ++ii )
2507 otherPoly.emplace_back( lastPt - aOther.
m_poly.
CVertex( ii ) );
2513 similarity *= std::pow( 0.9, m + n - 2 * longest );
2539 if( lineStyleEnum.
Choices().GetCount() == 0 )
2550 if( hatchModeEnum.
Choices().GetCount() == 0 )
2562 auto isNotPolygonOrCircle =
2592 const wxString shapeProps =
_HKI(
"Shape Properties" );
2667 angle->SetAvailableFunc(
2677 auto fillAvailable =
2690 switch( edaShape->GetShape() )
2709 .SetAvailableFunc( fillAvailable );
2714 .SetAvailableFunc( fillAvailable )
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Bezier curves to polygon converter.
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMaxError=10)
Convert a Bezier curve to a polygon.
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr void SetOrigin(const Vec &pos)
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
constexpr coord_type GetY() const
constexpr Vec Centre() const
constexpr coord_type GetX() const
bool IntersectsCircleEdge(const Vec &aCenter, const int aRadius, const int aWidth) const
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr coord_type GetLeft() const
constexpr bool Contains(const Vec &aPoint) const
constexpr coord_type GetRight() const
constexpr void SetEnd(coord_type x, coord_type y)
constexpr coord_type GetTop() const
constexpr bool Intersects(const BOX2< Vec > &aRect) const
constexpr coord_type GetBottom() const
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
UI_FILL_MODE GetFillModeProp() const
virtual int GetHatchLineSpacing() const
EDA_ANGLE GetArcAngle() const
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false, bool includeFill=false) const
Convert the shape to a closed polygon.
const VECTOR2I & GetBezierC2() const
void SetBezierC2(const VECTOR2I &aPt)
void move(const VECTOR2I &aMoveVector)
void SetCenter(const VECTOR2I &aCenter)
VECTOR2I getCenter() const
void SetFillModeProp(UI_FILL_MODE)
void SetLength(const double &aLength)
virtual int getMaxError() const
void rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
const std::vector< VECTOR2I > buildBezierToSegmentsPointsList(int aMaxError) const
const SHAPE_POLY_SET & GetHatching() const
FILL_T GetFillMode() const
long long int m_rectangleHeight
virtual int GetEffectiveWidth() const
COLOR4D GetLineColor() const
SHAPE_POLY_SET m_hatching
int GetRectangleWidth() const
void SetLineStyle(const LINE_STYLE aStyle)
void calcEdit(const VECTOR2I &aPosition)
virtual std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
SHAPE_POLY_SET & GetPolyShape()
void CalcArcAngles(EDA_ANGLE &aStartAngle, EDA_ANGLE &aEndAngle) const
Calc arc start and end angles such that aStartAngle < aEndAngle.
std::vector< VECTOR2I > GetCornersInSequence(EDA_ANGLE angle) const
void ShapeGetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
virtual bool isMoving() const
bool operator==(const EDA_SHAPE &aOther) const
void SetPolyShape(const SHAPE_POLY_SET &aShape)
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void SetRectangleHeight(const int &aHeight)
bool IsHatchedFill() const
virtual void SetFilled(bool aFlag)
virtual bool IsFilledForHitTesting() const
bool continueEdit(const VECTOR2I &aPosition)
wxString ShowShape() const
void SetFillColor(const COLOR4D &aColor)
std::vector< SHAPE * > makeEffectiveShapes(bool aEdgeOnly, bool aLineChainOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
bool hitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
void SetCachedArcData(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCenter)
Set the data used for mid point caching.
void RebuildBezierToSegmentsPointsList(int aMaxError)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
virtual int GetHatchLineWidth() const
void flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
EDA_SHAPE(SHAPE_T aType, int aLineWidth, FILL_T aFill)
void beginEdit(const VECTOR2I &aStartPoint)
int GetPointCount() const
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
void SetStart(const VECTOR2I &aStart)
void DupPolyPointsList(std::vector< VECTOR2I > &aBuffer) const
Duplicate the list of corners in a std::vector<VECTOR2I>.
LINE_STYLE GetLineStyle() const
void endEdit(bool aClosed=true)
Finish editing the shape.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
void SetLineColor(const COLOR4D &aColor)
COLOR4D GetFillColor() const
void SetRectangle(const long long int &aHeight, const long long int &aWidth)
void SetShape(SHAPE_T aShape)
void SwapShape(EDA_SHAPE *aImage)
std::vector< VECTOR2I > GetRectCorners() const
void SetSegmentAngle(const EDA_ANGLE &aAngle)
std::vector< VECTOR2I > m_bezierPoints
void setPosition(const VECTOR2I &aPos)
virtual bool IsProxyItem() const
void computeArcBBox(BOX2I &aBBox) const
virtual void UpdateHatching() const
void SetEnd(const VECTOR2I &aEnd)
void SetRectangleWidth(const int &aWidth)
void SetBezierC1(const VECTOR2I &aPt)
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
wxString SHAPE_T_asString() const
void scale(double aScale)
double Similarity(const EDA_SHAPE &aOther) const
const VECTOR2I & GetBezierC1() const
const BOX2I getBoundingBox() const
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
int GetRectangleHeight() const
virtual int GetWidth() const
VECTOR2I getPosition() const
bool IsClockwiseArc() const
void SetPolyPoints(const std::vector< VECTOR2I > &aPoints)
wxString getFriendlyName() const
void SetWidth(int aWidth)
EDA_ANGLE GetSegmentAngle() const
void SetFillMode(FILL_T aFill)
long long int m_rectangleWidth
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
bool IsPolyShapeValid() const
int Compare(const EDA_SHAPE *aOther) const
VECTOR2I GetArcMid() const
ENUM_MAP & Map(T aValue, const wxString &aName)
static ENUM_MAP< T > & Instance()
Class that other classes need to inherit from, in order to be inspectable.
A color representation with 4 components: red, green, blue, alpha.
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Provide class metadata.Helper macro to map type hashes to names.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
int Length() const
Return the length (this).
SHAPE_TYPE Type() const
Return the type of the shape.
const VECTOR2I GetCenter() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Move(const VECTOR2I &aVector) override
bool IsClosed() const override
virtual const VECTOR2I GetPoint(int aIndex) const override
void SetPoint(int aIndex, const VECTOR2I &aPos)
Move a point to a specific location.
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
virtual size_t GetPointCount() const override
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
virtual const SEG GetSegment(int aIndex) const override
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const VECTOR2I & CLastPoint() const
Return the last point in the line chain.
void Remove(int aStartIndex, int aEndIndex)
Remove the range of points [start_index, end_index] from the line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
const std::vector< VECTOR2I > & CPoints() const
Represent a set of closed polygons.
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
void RemoveAllContours()
Remove all outlines & holes (clears) the polygon set.
bool CollideEdge(const VECTOR2I &aPoint, VERTEX_INDEX *aClosestVertex=nullptr, int aClearance=0) const
Check whether aPoint collides with any edge of any of the contours of the polygon.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
int VertexCount(int aOutline=-1, int aHole=-1) const
Return the number of vertices in a given outline/hole.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
void Fracture()
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
int TotalVertices() const
Return total number of vertices stored in the set.
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
const std::vector< SEG > GenerateHatchLines(const std::vector< double > &aSlopes, int aSpacing, int aLineLength) const
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void Mirror(const VECTOR2I &aRef, FLIP_DIRECTION aFlipDirection)
Mirror the line points about y or x (or both)
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the index-th vertex in a given hole outline within a given outline.
int OutlineCount() const
Return the number of outlines in the set.
void Move(const VECTOR2I &aVector) override
SHAPE_POLY_SET CloneDropTriangulation() const
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
An abstract shape on 2D plane.
void SetLineStyle(LINE_STYLE aLineStyle)
void SetWidth(int aWidth)
void GetMsgPanelInfo(UNITS_PROVIDER *aUnitsProvider, std::vector< MSG_PANEL_ITEM > &aList, bool aIncludeStyle=true, bool aIncludeWidth=true)
LINE_STYLE GetLineStyle() const
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
constexpr extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
void TransformRingToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aCentre, int aRadius, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arcs to multiple straight segments.
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
void TransformArcToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arc to multiple straight segments.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_45
static constexpr EDA_ANGLE ANGLE_270
static constexpr EDA_ANGLE ANGLE_360
static constexpr EDA_ANGLE ANGLE_180
static struct EDA_SHAPE_DESC _EDA_SHAPE_DESC
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
a few functions useful in geometry calculations.
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
#define UNIMPLEMENTED_FOR(type)
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
KICOMMON_API wxString MessageTextFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A helper to convert the double length aValue to a string in inches, millimeters, or unscaled units.
bool ShapeHitTest(const SHAPE_LINE_CHAIN &aHitter, const SHAPE &aHittee, bool aHitteeContained)
Perform a shape-to-shape hit test.
size_t longest_common_subset(const _Container &__c1, const _Container &__c2)
Returns the length of the longest common subset of values between two containers.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
#define IMPLEMENT_ENUM_TO_WXANY(type)
#define NO_SETTER(owner, type)
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
@ PT_DECIDEGREE
Angle expressed in decidegrees.
@ PT_SIZE
Size expressed in distance units (mm/inch)
@ SH_POLY_SET
set of polygons (with holes, etc.)
@ SH_RECT
axis-aligned rectangle
@ SH_SIMPLE
simple polygon
@ SH_NULL
empty shape (no shape...),
@ SH_POLY_SET_TRIANGLE
a single triangle belonging to a POLY_SET triangulation
@ SH_LINE_CHAIN
line chain (polyline)
@ SH_COMPOUND
compound shape, consisting of multiple simple shapes
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
LINE_STYLE
Dashed line types.
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
bool TestSegmentHit(const VECTOR2I &aRefPoint, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
const VECTOR2I CalcArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc or circle given three points on its circumference.
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D