44#include <api/common/types/base_types.pb.h>
48 m_endsSwapped( false ),
53 m_rectangleHeight( 0 ),
54 m_rectangleWidth( 0 ),
68 m_endsSwapped( false ),
71 m_rectangleHeight( 0 ),
72 m_rectangleWidth( 0 ),
77 switch( aShape.
Type() )
81 auto rect =
static_cast<const SHAPE_RECT&
>( aShape );
84 SetEnd( rect.GetPosition() + rect.GetSize() );
110 auto circle =
static_cast<const SHAPE_CIRCLE&
>( aShape );
113 SetEnd( circle.GetCenter() + circle.GetRadius() );
119 auto arc =
static_cast<const SHAPE_ARC&
>( aShape );
149 types::GraphicShape shape;
151 types::StrokeAttributes* stroke = shape.mutable_attributes()->mutable_stroke();
152 types::GraphicFillAttributes* fill = shape.mutable_attributes()->mutable_fill();
154 stroke->mutable_width()->set_value_nm(
GetWidth() );
158 case LINE_STYLE::DEFAULT: stroke->set_style( types::SLS_DEFAULT );
break;
159 case LINE_STYLE::SOLID: stroke->set_style( types::SLS_SOLID );
break;
160 case LINE_STYLE::DASH: stroke->set_style( types::SLS_DASH );
break;
161 case LINE_STYLE::DOT: stroke->set_style( types::SLS_DOT );
break;
162 case LINE_STYLE::DASHDOT: stroke->set_style( types::SLS_DASHDOT );
break;
163 case LINE_STYLE::DASHDOTDOT: stroke->set_style( types::SLS_DASHDOTDOT );
break;
169 case FILL_T::FILLED_SHAPE: fill->set_fill_type( types::GFT_FILLED );
break;
170 default: fill->set_fill_type( types::GFT_UNFILLED );
break;
175 case SHAPE_T::SEGMENT:
177 types::GraphicSegmentAttributes* segment = shape.mutable_segment();
178 PackVector2( *segment->mutable_start(),
GetStart() );
179 PackVector2( *segment->mutable_end(),
GetEnd() );
183 case SHAPE_T::RECTANGLE:
185 types::GraphicRectangleAttributes* rectangle = shape.mutable_rectangle();
186 PackVector2( *rectangle->mutable_top_left(),
GetStart() );
187 PackVector2( *rectangle->mutable_bottom_right(),
GetEnd() );
193 types::GraphicArcAttributes* arc = shape.mutable_arc();
194 PackVector2( *arc->mutable_start(),
GetStart() );
195 PackVector2( *arc->mutable_mid(),
GetArcMid() );
196 PackVector2( *arc->mutable_end(),
GetEnd() );
200 case SHAPE_T::CIRCLE:
202 types::GraphicCircleAttributes* circle = shape.mutable_circle();
203 PackVector2( *circle->mutable_center(),
GetStart() );
204 PackVector2( *circle->mutable_radius_point(),
GetEnd() );
210 PackPolySet( *shape.mutable_polygon(),
GetPolyShape() );
214 case SHAPE_T::BEZIER:
216 types::GraphicBezierAttributes* bezier = shape.mutable_bezier();
217 PackVector2( *bezier->mutable_start(),
GetStart() );
218 PackVector2( *bezier->mutable_control1(),
GetBezierC1() );
219 PackVector2( *bezier->mutable_control2(),
GetBezierC2() );
220 PackVector2( *bezier->mutable_end(),
GetEnd() );
225 wxASSERT_MSG(
false,
"Unhandled shape in PCB_SHAPE::Serialize" );
230 aContainer.PackFrom( shape );
238 types::GraphicShape shape;
240 if( !aContainer.UnpackTo( &shape ) )
255 SetFilled( shape.attributes().fill().fill_type() == types::GFT_FILLED );
256 SetWidth( shape.attributes().stroke().width().value_nm() );
258 switch( shape.attributes().stroke().style() )
260 case types::SLS_DEFAULT:
SetLineStyle( LINE_STYLE::DEFAULT );
break;
261 case types::SLS_SOLID:
SetLineStyle( LINE_STYLE::SOLID );
break;
262 case types::SLS_DASH:
SetLineStyle( LINE_STYLE::DASH );
break;
263 case types::SLS_DOT:
SetLineStyle( LINE_STYLE::DOT );
break;
264 case types::SLS_DASHDOT:
SetLineStyle( LINE_STYLE::DASHDOT );
break;
265 case types::SLS_DASHDOTDOT:
SetLineStyle( LINE_STYLE::DASHDOTDOT );
break;
269 if( shape.has_segment() )
272 SetStart( UnpackVector2( shape.segment().start() ) );
273 SetEnd( UnpackVector2( shape.segment().end() ) );
275 else if( shape.has_rectangle() )
278 SetStart( UnpackVector2( shape.rectangle().top_left() ) );
279 SetEnd( UnpackVector2( shape.rectangle().bottom_right() ) );
281 else if( shape.has_arc() )
285 UnpackVector2( shape.arc().mid() ),
286 UnpackVector2( shape.arc().end() ) );
288 else if( shape.has_circle() )
291 SetStart( UnpackVector2( shape.circle().center() ) );
292 SetEnd( UnpackVector2( shape.circle().radius_point() ) );
294 else if( shape.has_polygon() )
299 else if( shape.has_bezier() )
302 SetStart( UnpackVector2( shape.bezier().start() ) );
303 SetBezierC1( UnpackVector2( shape.bezier().control1() ) );
304 SetBezierC2( UnpackVector2( shape.bezier().control2() ) );
305 SetEnd( UnpackVector2( shape.bezier().end() ) );
319 case SHAPE_T::SEGMENT:
return _(
"Thermal Spoke" );
320 case SHAPE_T::RECTANGLE:
return _(
"Number Box" );
321 default:
return wxT(
"??" );
328 case SHAPE_T::SEGMENT:
return _(
"Line" );
329 case SHAPE_T::RECTANGLE:
return _(
"Rect" );
330 case SHAPE_T::ARC:
return _(
"Arc" );
331 case SHAPE_T::CIRCLE:
return _(
"Circle" );
332 case SHAPE_T::BEZIER:
return _(
"Bezier Curve" );
333 case SHAPE_T::POLY:
return _(
"Polygon" );
334 default:
return wxT(
"??" );
344 case SHAPE_T::SEGMENT:
return wxS(
"S_SEGMENT" );
345 case SHAPE_T::RECTANGLE:
return wxS(
"S_RECT" );
346 case SHAPE_T::ARC:
return wxS(
"S_ARC" );
347 case SHAPE_T::CIRCLE:
return wxS(
"S_CIRCLE" );
348 case SHAPE_T::POLY:
return wxS(
"S_POLYGON" );
349 case SHAPE_T::BEZIER:
return wxS(
"S_CURVE" );
350 case SHAPE_T::UNDEFINED:
return wxS(
"UNDEFINED" );
353 return wxEmptyString;
367 else if(
m_shape == SHAPE_T::POLY )
380 case SHAPE_T::BEZIER:
386 case SHAPE_T::SEGMENT:
408 case SHAPE_T::RECTANGLE:
421 case SHAPE_T::RECTANGLE:
434 case SHAPE_T::SEGMENT:
446 case SHAPE_T::RECTANGLE:
460 case SHAPE_T::RECTANGLE:
474 case SHAPE_T::RECTANGLE:
489 case SHAPE_T::SEGMENT:
502 case SHAPE_T::CIRCLE:
503 case SHAPE_T::RECTANGLE:
507 case SHAPE_T::SEGMENT:
516 case SHAPE_T::BEZIER:
538 case SHAPE_T::SEGMENT:
539 case SHAPE_T::RECTANGLE:
540 case SHAPE_T::CIRCLE:
542 m_end += aMoveVector;
549 case SHAPE_T::BEZIER:
551 m_end += aMoveVector;
571 pt.x =
KiROUND( pt.x * aScale );
572 pt.y =
KiROUND( pt.y * aScale );
581 case SHAPE_T::SEGMENT:
582 case SHAPE_T::RECTANGLE:
587 case SHAPE_T::CIRCLE:
595 std::vector<VECTOR2I> pts;
601 pts.emplace_back( pt );
602 scalePt( pts.back() );
610 case SHAPE_T::BEZIER:
629 case SHAPE_T::SEGMENT:
630 case SHAPE_T::CIRCLE:
641 case SHAPE_T::RECTANGLE:
664 case SHAPE_T::BEZIER:
686 case SHAPE_T::SEGMENT:
687 case SHAPE_T::RECTANGLE:
692 case SHAPE_T::CIRCLE:
709 case SHAPE_T::BEZIER:
728 if(
m_shape != SHAPE_T::BEZIER )
741 std::vector<VECTOR2I> bezierPoints;
746 converter.
GetPoly( bezierPoints, aMaxError );
759 case SHAPE_T::CIRCLE:
762 case SHAPE_T::SEGMENT:
767 case SHAPE_T::RECTANGLE:
768 case SHAPE_T::BEZIER:
786 case SHAPE_T::CIRCLE:
818 if( aEndAngle == aStartAngle )
821 while( aEndAngle < aStartAngle )
836 case SHAPE_T::CIRCLE:
845 return std::max( 1,
KiROUND( radius ) );
903 return endAngle - startAngle;
931 if( aCheckNegativeAngle && aAngle <
ANGLE_0 )
945 case SHAPE_T::RECTANGLE:
return _(
"Pad Number Box" );
946 case SHAPE_T::SEGMENT:
return _(
"Thermal Spoke Template" );
947 default:
return _(
"Unrecognized" );
954 case SHAPE_T::CIRCLE:
return _(
"Circle" );
955 case SHAPE_T::ARC:
return _(
"Arc" );
956 case SHAPE_T::BEZIER:
return _(
"Curve" );
957 case SHAPE_T::POLY:
return _(
"Polygon" );
958 case SHAPE_T::RECTANGLE:
return _(
"Rectangle" );
959 case SHAPE_T::SEGMENT:
return _(
"Segment" );
960 default:
return _(
"Unrecognized" );
970 wxString shape =
_(
"Shape" );
975 case SHAPE_T::CIRCLE:
981 aList.emplace_back(
_(
"Angle" ), msg );
986 case SHAPE_T::BEZIER:
991 msg.Printf( wxS(
"%d" ),
GetPolyShape().Outline(0).PointCount() );
992 aList.emplace_back(
_(
"Points" ), msg );
995 case SHAPE_T::RECTANGLE:
996 aList.emplace_back(
_(
"Width" ),
999 aList.emplace_back(
_(
"Height" ),
1003 case SHAPE_T::SEGMENT:
1005 aList.emplace_back(
_(
"Length" ),
1029 case SHAPE_T::RECTANGLE:
1035 case SHAPE_T::SEGMENT:
1040 case SHAPE_T::CIRCLE:
1054 bbox.
Merge( *iter );
1058 case SHAPE_T::BEZIER:
1079 double maxdist = aAccuracy;
1086 case SHAPE_T::CIRCLE:
1092 return dist <= radius + maxdist;
1094 return abs( radius - dist ) <= maxdist;
1112 if( dist > radius + maxdist )
1118 if( abs( radius - dist ) > maxdist )
1133 if( endAngle > startAngle )
1134 return relPosAngle >= startAngle && relPosAngle <= endAngle;
1136 return relPosAngle >= startAngle || relPosAngle <= endAngle;
1139 case SHAPE_T::BEZIER:
1142 std::vector<VECTOR2I> updatedBezierPoints;
1147 converter.
GetPoly( updatedBezierPoints, aAccuracy / 2 );
1148 pts = &updatedBezierPoints;
1151 for(
unsigned int i = 1; i < pts->size(); i++ )
1153 if(
TestSegmentHit( aPosition, ( *pts )[i - 1], ( *pts )[i], maxdist ) )
1159 case SHAPE_T::SEGMENT:
1162 case SHAPE_T::RECTANGLE:
1171 return poly.
Collide( aPosition, maxdist );
1190 copy.SetClosed(
true );
1191 return copy.Collide( aPosition, maxdist );
1212 BOX2I arect = aRect;
1220 case SHAPE_T::CIRCLE:
1259 case SHAPE_T::RECTANGLE:
1276 case SHAPE_T::SEGMENT:
1308 for(
int jj = 0; jj < count; jj++ )
1316 if( jj + 1 < count )
1338 case SHAPE_T::BEZIER:
1353 std::vector<VECTOR2I> updatedBezierPoints;
1358 converter.
GetPoly( updatedBezierPoints, aAccuracy / 2 );
1359 pts = &updatedBezierPoints;
1362 for(
unsigned ii = 1; ii < pts->size(); ii++ )
1364 VECTOR2I vertex = ( *pts )[ii - 1];
1365 VECTOR2I vertexNext = ( *pts )[ii];
1388 std::vector<VECTOR2I> pts;
1392 pts.emplace_back( topLeft );
1393 pts.emplace_back( botRight.
x, topLeft.
y );
1394 pts.emplace_back( botRight );
1395 pts.emplace_back( topLeft.
x, botRight.
y );
1422 if( t1 < ANGLE_0 && t2 >
ANGLE_0 )
1425 if( t1 < ANGLE_90 && t2 >
ANGLE_90 )
1436 if( t1 < ANGLE_0 || t2 >
ANGLE_0 )
1439 if( t1 < ANGLE_90 || t2 >
ANGLE_90 )
1463 std::vector<SHAPE*> effectiveShapes;
1472 case SHAPE_T::SEGMENT:
1476 case SHAPE_T::RECTANGLE:
1481 effectiveShapes.emplace_back(
new SHAPE_SIMPLE( pts ) );
1483 if( width > 0 || !
IsFilled() || aEdgeOnly )
1485 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( pts[0], pts[1], width ) );
1486 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( pts[1], pts[2], width ) );
1487 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( pts[2], pts[3], width ) );
1488 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( pts[3], pts[0], width ) );
1493 case SHAPE_T::CIRCLE:
1498 if( width > 0 || !
IsFilled() || aEdgeOnly )
1504 case SHAPE_T::BEZIER:
1507 VECTOR2I start_pt = bezierPoints[0];
1509 for(
unsigned int jj = 1; jj < bezierPoints.size(); jj++ )
1511 VECTOR2I end_pt = bezierPoints[jj];
1512 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( start_pt, end_pt, width ) );
1531 if( width > 0 || !
IsFilled() || aEdgeOnly )
1535 if( aLineChainOnly && l.
IsClosed() )
1538 for(
int jj = 0; jj < segCount; jj++ )
1550 return effectiveShapes;
1562 aBuffer.reserve( pointCount );
1565 aBuffer.emplace_back( iter->x, iter->y );
1590 case SHAPE_T::SEGMENT:
1591 case SHAPE_T::CIRCLE:
1592 case SHAPE_T::RECTANGLE:
1602 case SHAPE_T::BEZIER:
1632 case SHAPE_T::SEGMENT:
1633 case SHAPE_T::CIRCLE:
1634 case SHAPE_T::RECTANGLE:
1637 case SHAPE_T::BEZIER:
1650 poly.
Append( aPosition,
true );
1663#define sq( x ) pow( x, 2 )
1667 case SHAPE_T::SEGMENT:
1668 case SHAPE_T::CIRCLE:
1669 case SHAPE_T::RECTANGLE:
1673 case SHAPE_T::BEZIER:
1734 if( chordBefore > 0 )
1735 ratio = chordAfter / chordBefore;
1738 radius = std::max( sqrt(
sq( radius ) * ratio ), sqrt( chordAfter ) / 2 );
1746 radius = ( radialA + radialB ) / 2.0;
1760 double sqRadDiff = ( radius * radius ) - ( l * l ) / 4.0;
1765 if( l > 0 && sqRadDiff >= 0 )
1820 case SHAPE_T::SEGMENT:
1821 case SHAPE_T::CIRCLE:
1822 case SHAPE_T::RECTANGLE:
1823 case SHAPE_T::BEZIER:
1857 #define SWAPITEM( x ) std::swap( x, image->x )
1879#define TEST( a, b ) { if( a != b ) return a - b; }
1880#define TEST_E( a, b ) { if( abs( a - b ) > EPSILON ) return a - b; }
1881#define TEST_PT( a, b ) { TEST_E( a.x, b.x ); TEST_E( a.y, b.y ); }
1892 else if(
m_shape == SHAPE_T::BEZIER )
1897 else if(
m_shape == SHAPE_T::POLY )
1917 ERROR_LOC aErrorLoc,
bool ignoreLineWidth )
const
1919 int width = ignoreLineWidth ? 0 :
GetWidth();
1921 width += 2 * aClearance;
1925 case SHAPE_T::CIRCLE:
1937 case SHAPE_T::RECTANGLE:
1965 case SHAPE_T::SEGMENT:
1987 int inflate = width / 2;
1992 tmp.
Inflate( inflate, CORNER_STRATEGY::ROUND_ALL_CORNERS, aError );
2004 for(
int jj = 0; jj < (int) poly.
SegmentCount(); ++jj )
2015 case SHAPE_T::BEZIER:
2019 std::vector<VECTOR2I> poly;
2020 converter.
GetPoly( poly, aError );
2022 for(
unsigned ii = 1; ii < poly.size(); ii++ )
2046 return LINE_STYLE::SOLID;
2100 double similarity = 1.0;
2135 similarity *= std::pow( 0.9, m + n - 2 * longest );
2141 std::vector<VECTOR2I> poly;
2142 std::vector<VECTOR2I> otherPoly;
2150 for(
int ii = 0; ii < m; ++ii )
2158 for(
int ii = 0; ii < n; ++ii )
2160 otherPoly.emplace_back( lastPt - aOther.
m_poly.
CVertex( ii ) );
2166 similarity *= std::pow( 0.9, m + n - 2 * longest );
2191 if( plotDashTypeEnum.Choices().GetCount() == 0 )
2204 auto isNotPolygonOrCircle = [](
INSPECTABLE* aItem ) ->
bool
2222 auto isRectangle = [](
INSPECTABLE* aItem ) ->
bool
2231 const wxString shapeProps =
_HKI(
"Shape Properties" );
2306 angle->SetAvailableFunc(
2316 auto fillAvailable =
2329 switch( edaShape->GetShape() )
2348 .SetAvailableFunc( fillAvailable );
2352 fillColor->SetWriteableFunc(
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
constexpr int ARC_HIGH_DEF
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 Vec Centre() 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 bool Contains(const Vec &aPoint) const
constexpr void SetEnd(coord_type x, coord_type y)
constexpr bool Intersects(const BOX2< Vec > &aRect) 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.
EDA_ANGLE GetArcAngle() const
const VECTOR2I & GetBezierC2() const
void SetBezierC2(const VECTOR2I &aPt)
void move(const VECTOR2I &aMoveVector)
void SetCenter(const VECTOR2I &aCenter)
VECTOR2I getCenter() const
void SetLength(const double &aLength)
void rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
const std::vector< VECTOR2I > buildBezierToSegmentsPointsList(int aMaxError) const
FILL_T GetFillMode() const
long long int m_rectangleHeight
virtual int GetEffectiveWidth() const
COLOR4D GetLineColor() const
int GetRectangleWidth() const
void SetLineStyle(const LINE_STYLE aStyle)
void calcEdit(const VECTOR2I &aPosition)
SHAPE_POLY_SET & GetPolyShape()
void CalcArcAngles(EDA_ANGLE &aStartAngle, EDA_ANGLE &aEndAngle) const
Calc arc start and end angles such that aStartAngle < aEndAngle.
void ShapeGetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
void SetFilled(bool aFlag)
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)
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.
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)
Finishes 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
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)
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the shape to a closed polygon.
wxString getFriendlyName() const
void SetWidth(int aWidth)
EDA_ANGLE GetSegmentAngle() const
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
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.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
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
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)
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
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
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 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_270
static constexpr EDA_ANGLE ANGLE_360
static constexpr EDA_ANGLE ANGLE_180
static struct EDA_SHAPE_DESC _EDA_SHAPE_DESC
@ ARC
use RECTANGLE instead of RECT to avoid collision in a Windows header
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.
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
LINE_STYLE
Dashed line types.
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