41 m_endsSwapped( false ),
47 m_annotationProxy( false )
60 return _(
"Number Box" );
70 default:
return wxT(
"??" );
182 m_end += aMoveVector;
192 m_end += aMoveVector;
212 pt.x =
KiROUND( pt.x * aScale );
213 pt.y =
KiROUND( pt.y * aScale );
234 std::vector<VECTOR2I> pts;
240 pts.emplace_back( pt );
241 scalePt( pts.back() );
371 m_poly.
Mirror( aFlipLeftRight, !aFlipLeftRight, aCentre );
433 std::vector<VECTOR2I> bezierPoints;
438 converter.
GetPoly( bezierPoints, aMinSegLen );
510 if( aEndAngle == aStartAngle )
513 if( aStartAngle > aEndAngle )
542 return std::max( 1,
KiROUND( radius ) );
592 return endAngle - startAngle;
603 if( aCheckNegativeAngle && aAngle <
ANGLE_0 )
621 default:
return _(
"Unrecognized" );
631 wxString shape =
_(
"Shape" );
642 aList.emplace_back(
_(
"Angle" ), msg );
652 msg.Printf( wxS(
"%d" ),
GetPolyShape().Outline(0).PointCount() );
653 aList.emplace_back(
_(
"Points" ), msg );
657 aList.emplace_back(
_(
"Width" ),
660 aList.emplace_back(
_(
"Height" ),
666 aList.emplace_back(
_(
"Length" ),
747 int maxdist = aAccuracy;
762 return dist <= radius + maxdist;
764 return abs( radius - dist ) <= maxdist;
779 KiROUND<double, VECTOR2I::extended_type>(
EuclideanNorm( relPos ) );
784 if( dist > radius + maxdist )
790 if(
abs( radius - dist ) > maxdist )
805 if( endAngle > startAngle )
806 return relPosAngle >= startAngle && relPosAngle <= endAngle;
808 return relPosAngle >= startAngle || relPosAngle <= endAngle;
834 return poly.
Collide( aPosition, maxdist );
965 for(
int jj = 0; jj < count; jj++ )
1011 for(
unsigned ii = 1; ii < count; ii++ )
1037 std::vector<VECTOR2I> pts;
1052 pts.emplace_back( topLeft );
1053 pts.emplace_back( botRight.
x, topLeft.
y );
1054 pts.emplace_back( botRight );
1055 pts.emplace_back( topLeft.
x, botRight.
y );
1092 if( t1 < ANGLE_0 && t2 >
ANGLE_0 )
1095 if( t1 < ANGLE_90 && t2 >
ANGLE_90 )
1106 if( t1 < ANGLE_0 || t2 >
ANGLE_0 )
1109 if( t1 < ANGLE_90 || t2 >
ANGLE_90 )
1133 std::vector<SHAPE*> effectiveShapes;
1151 effectiveShapes.emplace_back(
new SHAPE_SIMPLE( pts ) );
1153 if( width > 0 || !
IsFilled() || aEdgeOnly )
1155 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( pts[0], pts[1], width ) );
1156 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( pts[1], pts[2], width ) );
1157 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( pts[2], pts[3], width ) );
1158 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( pts[3], pts[0], width ) );
1168 if( width > 0 || !
IsFilled() || aEdgeOnly )
1177 VECTOR2I start_pt = bezierPoints[0];
1179 for(
unsigned int jj = 1; jj < bezierPoints.size(); jj++ )
1181 VECTOR2I end_pt = bezierPoints[jj];
1182 effectiveShapes.emplace_back(
new SHAPE_SEGMENT( start_pt, end_pt, width ) );
1198 if( aLineChainOnly )
1207 if( width > 0 || !
IsFilled() || aEdgeOnly )
1221 return effectiveShapes;
1233 aBuffer.reserve( pointCount );
1236 aBuffer.emplace_back( iter->x, iter->y );
1312 poly.
Append( aPosition,
true );
1325#define sq( x ) pow( x, 2 )
1361 double chordBefore =
sq( v.
x ) +
sq( v.
y );
1369 double chordAfter =
sq( v.
x ) +
sq( v.
y );
1370 double ratio = chordAfter / chordBefore;
1374 radius = std::max(
int( sqrt(
sq( radius ) * ratio ) ) + 1,
1375 int( sqrt( chordAfter ) / 2 ) + 1 );
1384 radius = int( ( radialA + radialB ) / 2.0 ) + 1;
1490 #define SWAPITEM( x ) std::swap( x, image->x )
1512#define TEST( a, b ) { if( a != b ) return a - b; }
1513#define TEST_E( a, b ) { if( abs( a - b ) > EPSILON ) return a - b; }
1514#define TEST_PT( a, b ) { TEST_E( a.x, b.x ); TEST_E( a.y, b.y ); }
1550 ERROR_LOC aErrorLoc,
bool ignoreLineWidth )
const
1552 int width = ignoreLineWidth ? 0 :
GetWidth();
1554 width += 2 * aClearance;
1612 std::vector<VECTOR2I> poly;
1625 for(
const VECTOR2I& point : poly )
1626 aBuffer.
Append( point.x, point.y );
1631 VECTOR2I pt1( poly[poly.size() - 1] );
1649 std::vector<VECTOR2I> poly;
1652 for(
unsigned ii = 1; ii < poly.size(); ii++ )
1712 angle->SetAvailableFunc(
1721 filled->SetAvailableFunc(
Bezier curves to polygon converter.
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMinSegLen=0, int aMaxSegCount=32)
Convert a Bezier curve to a polygon.
void SetOrigin(const Vec &pos)
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
bool Intersects(const BOX2< Vec > &aRect) const
bool IntersectsCircleEdge(const Vec &aCenter, const int aRadius, const int aWidth) const
bool Contains(const Vec &aPoint) const
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
void SetEnd(coord_type x, coord_type y)
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
ORIGIN_TRANSFORMS & GetOriginTransforms() override
Return a reference to the default ORIGIN_TRANSFORMS object.
The base class for create windows for drawing purpose.
EDA_ANGLE GetArcAngle() const
virtual VECTOR2I getParentPosition() const =0
wxString GetFriendlyName() const
const VECTOR2I & GetBezierC2() const
virtual EDA_ANGLE getParentOrientation() const =0
void move(const VECTOR2I &aMoveVector)
void SetCenter(const VECTOR2I &aCenter)
VECTOR2I getCenter() const
void rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
void flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
virtual int GetEffectiveWidth() const
const std::vector< VECTOR2I > buildBezierToSegmentsPointsList(int aMinSegLen) const
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 continueEdit(const VECTOR2I &aPosition)
wxString ShowShape() const
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.
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>
void endEdit(bool aClosed=true)
Finishes editing the shape.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
void SwapShape(EDA_SHAPE *aImage)
std::vector< VECTOR2I > GetRectCorners() const
std::vector< VECTOR2I > m_bezierPoints
void setPosition(const VECTOR2I &aPos)
void computeArcBBox(BOX2I &aBBox) const
void SetEnd(const VECTOR2I &aEnd)
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
double GetLength() const
Return the length of the track using the hypotenuse calculation.
wxString SHAPE_T_asString() const
void scale(double aScale)
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.
VECTOR2I getPosition() const
bool IsAnnotationProxy() 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.
void SetWidth(int aWidth)
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.
wxAny Get(PROPERTY_BASE *aProperty) const
A color representation with 4 components: red, green, blue, alpha.
Provide class metadata.Helper macro to map type hashes to names.
static PROPERTY_MANAGER & Instance()
void AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
int Length() const
Return the length (this).
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.
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
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
SEG Segment(int aIndex)
Return a copy of the aIndex-th segment in the line chain.
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.
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 VertexCount(int aOutline=-1, int aHole=-1) const
Return the number of points in the shape poly set.
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
Delete aIdx-th polygon from the set.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aRef={ 0, 0 })
Mirror the line points about y or x (or both)
SHAPE_LINE_CHAIN & Outline(int aIndex)
int NewOutline()
Creates a new hole in a given outline.
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the aGlobalIndex-th vertex in the poly set.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
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.
void GetMsgPanelInfo(UNITS_PROVIDER *aUnitsProvider, std::vector< MSG_PANEL_ITEM > &aList, bool aIncludeStyle=true, bool aIncludeWidth=true)
PLOT_DASH_TYPE GetPlotStyle() const
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A lower-precision version of StringFromValue().
extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
VECTOR2_TRAITS< int >::extended_type extended_type
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_180
static constexpr EDA_ANGLE & ANGLE_360
static constexpr EDA_ANGLE & ANGLE_90
static constexpr EDA_ANGLE & ANGLE_0
static constexpr EDA_ANGLE & ANGLE_270
static struct EDA_SHAPE_DESC _EDA_SHAPE_DESC
@ LAST
marker for list end
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
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)
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.
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
#define NO_SETTER(owner, type)
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
@ PT_DECIDEGREE
Angle expressed in decidegrees.
@ PT_SIZE
Size expressed in distance units (mm/inch)
PLOT_DASH_TYPE
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)
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.
double GetLineLength(const VECTOR2I &aPointA, const VECTOR2I &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
double EuclideanNorm(const VECTOR2I &vector)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".