103 wxASSERT_MSG(
false,
"PCB_SHAPE::GetLength not implemented for shape" 119 m_end += aMoveVector;
149 auto scalePt = [&]( wxPoint& pt )
151 pt.x =
KiROUND( pt.x * aScale );
152 pt.y =
KiROUND( pt.y * aScale );
179 std::vector<wxPoint> pts;
183 pts.emplace_back( pt );
184 scalePt( pts.back() );
211 if(
KiROUND( aAngle ) % 900 == 0 )
245 wxFAIL_MSG(
"PCB_SHAPE::Rotate not implemented for " 257 m_end.x = aCentre.x - (
m_end.x - aCentre.x );
262 m_end.y = aCentre.y - (
m_end.y - aCentre.y );
306 wxFAIL_MSG(
"PCB_SHAPE::Flip not implemented for " 330 std::vector<wxPoint> bezierPoints;
335 converter.
GetPoly( bezierPoints, aMinSegLen );
364 wxFAIL_MSG(
"PCB_SHAPE::GetCentre not implemented for " 375 wxPoint endPoint(
m_end );
393 wxPoint endPoint(
m_end );
450 VECTOR2D startLine = aStart - center;
455 if( clockwise &&
angle < 0.0 )
457 else if( !clockwise &&
angle > 0.0 )
493 aList.emplace_back(
_(
"Type" ),
_(
"Drawing" ) );
496 aList.emplace_back(
_(
"Status" ),
_(
"locked" ) );
498 wxString shape =
_(
"Shape" );
503 aList.emplace_back( shape,
_(
"Circle" ) );
506 aList.emplace_back(
_(
"Radius" ), msg );
510 aList.emplace_back( shape,
_(
"Arc" ) );
512 msg.Printf( wxT(
"%.1f" ),
m_angle / 10.0 );
513 aList.emplace_back(
_(
"Angle" ), msg );
516 aList.emplace_back(
_(
"Radius" ), msg );
520 aList.emplace_back( shape,
_(
"Curve" ) );
523 aList.emplace_back(
_(
"Length" ), msg );
527 aList.emplace_back( shape,
_(
"Polygon" ) );
529 msg.Printf(
"%d",
GetPolyShape().Outline(0).PointCount() );
530 aList.emplace_back(
_(
"Points" ), msg );
534 aList.emplace_back( shape,
_(
"Rectangle" ) );
537 aList.emplace_back(
_(
"Width" ), msg );
540 aList.emplace_back(
_(
"Height" ), msg );
545 aList.emplace_back( shape,
_(
"Segment" ) );
548 aList.emplace_back(
_(
"Length" ), msg );
558 aList.emplace_back( shape,
_(
"Unrecognized" ) );
582 for( wxPoint& pt : pts )
609 wxPoint pt( iter->x, iter->y );
611 if( parentFootprint )
629 wxFAIL_MSG(
"PCB_SHAPE::GetBoundingBox not implemented for " 643 int maxdist = aAccuracy + (
m_width / 2 );
654 if( dist <= radius + maxdist )
659 if( abs( radius - dist ) <= maxdist )
667 wxPoint relPos = aPosition -
GetCenter();
671 if( abs( radius - dist ) <= maxdist )
681 double arc_hittest =
ArcTangente( relPos.y, relPos.x );
684 arc_hittest -= arc_angle_start;
698 if( arc_hittest >= ( 3600.0 +
GetAngle() ) )
706 const_cast<PCB_SHAPE*>(
this )->RebuildBezierToSegmentsPointsList(
m_width );
731 for(
const wxPoint& pt : pts )
764 wxFAIL_MSG(
"PCB_SHAPE::HitTest (point) not implemented for " 811 arcRect = bb.
Common( arect );
871 for(
int ii = 0; ii < count; ii++ )
877 if( arect.
Contains( ( wxPoint ) vertex ) )
881 if( arect.
Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
903 for(
unsigned ii = 1; ii < count; ii++ )
909 if( arect.
Contains( ( wxPoint ) vertex ) )
921 wxFAIL_MSG(
"PCB_SHAPE::HitTest (rect) not implemented for " 972 std::vector<wxPoint> pts;
975 wxPoint botRight =
GetEnd();
988 pts.emplace_back( topLeft );
989 pts.emplace_back( botRight.x, topLeft.y );
990 pts.emplace_back( botRight );
991 pts.emplace_back( topLeft.x, botRight.y );
996 for( wxPoint& pt : pts )
1013 wxPoint end =
m_end;
1022 unsigned int quarter = 0;
1041 bool directionCW = (
m_angle > 0 );
1047 quarter = ( quarter + 3 ) % 4;
1050 while(
angle > 900 )
1080 for (
const wxPoint& p : aPoints )
1087 std::vector<SHAPE*> effectiveShapes;
1115 effectiveShapes.emplace_back(
new SHAPE_SIMPLE( pts ) );
1154 wxPoint start_pt = bezierPoints[0];
1156 for(
unsigned int jj = 1; jj < bezierPoints.size(); jj++ )
1158 wxPoint end_pt = bezierPoints[jj];
1171 if( parentFootprint )
1191 wxFAIL_MSG(
"PCB_SHAPE::MakeEffectiveShapes unsupported PCB_SHAPE shape: " 1196 return effectiveShapes;
1208 std::vector<wxPoint> rv;
1215 rv.emplace_back( iter->x, iter->y );
1248 PCB_SHAPE* image = dynamic_cast<PCB_SHAPE*>( aImage );
1271 if( aFirst->
Type() != aSecond->
Type() )
1272 return aFirst->
Type() < aSecond->
Type();
1279 const PCB_SHAPE* dwgA = static_cast<const PCB_SHAPE*>( aFirst );
1280 const PCB_SHAPE* dwgB = static_cast<const PCB_SHAPE*>( aSecond );
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
int Length() const
Return the length (this).
int TotalVertices() const
Delete aIdx-th polygon from the set.
wxPoint GetArcEnd() const
bool IsPolyShapeValid() const
EDA_ITEM * m_parent
Linked list: Link (parent struct)
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
static PROPERTY_MANAGER & Instance()
int OutlineCount() const
Return the number of vertices in a given outline/hole.
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
void Merge(const EDA_RECT &aRect)
Modify the position and size of the rectangle in order to contain aRect.
PNG memory record (file in memory).
static struct DRAWSEGMENT_DESC _DRAWSEGMENT_DESC
const BITMAP_OPAQUE add_dashed_line_xpm[1]
T NormalizeAngle360Max(T Angle)
Normalize angle to be >=-360.0 and <= 360.0 Angle can be equal to -360 or +360.
SHAPE_POLY_SET & GetPolyShape()
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Implementation of conversion functions that require both schematic and board internal units.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
void Scale(double aScale)
void GetPoly(std::vector< wxPoint > &aOutput, int aMinSegLen=0)
Convert a Bezier curve to a polygon.
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the aGlobalIndex-th vertex in the poly set.
int GetRadius() const
Function GetRadius returns the radius of this item Has meaning only for arc and circle.
void Move(const VECTOR2I &aVector) override
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
std::vector< wxPoint > GetRectCorners() const
double RAD2DEG(double rad)
double GetArcAngleStart() const
function GetArcAngleStart()
int VertexCount(int aOutline=-1, int aHole=-1) const
Returns the number of holes in a given outline.
bool operator()(const BOARD_ITEM *aFirst, const BOARD_ITEM *aSecond) const
void computeArcBBox(EDA_RECT &aBBox) const
polygon (not yet used for tracks, but could be in microwave apps)
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
#define DEFAULT_LINE_WIDTH
double RAD2DECIDEG(double rad)
Structure to hold the necessary information in order to index a vertex on a SHAPE_POLY_SET object: th...
static wxString ShowShape(PCB_SHAPE_TYPE_T aShape)
Convert the enum PCB_SHAPE_TYPE_T integer value to a wxString.
void SetOrigin(const wxPoint &pos)
usual segment : line with rounded ends
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
virtual ORIGIN_TRANSFORMS & GetOriginTransforms()
Return a reference to the default ORIGIN_TRANSFORMS object.
bool IntersectsCircleEdge(const wxPoint &aCenter, const int aRadius, const int aWidth) const
Test for intersection between this rect and the edge (radius) of a circle.
EDA_RECT Common(const EDA_RECT &aRect) const
Return the area that is common with another rectangle.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
void Rotate(double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
void RotatePoint(int *pX, int *pY, double angle)
void NORMALIZE_ANGLE_POS(T &Angle)
segment with non rounded ends
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
The base class for create windows for drawing purpose.
virtual void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate this object.
int PointCount() const
Function PointCount()
bool Contains(const wxPoint &aPoint) const
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aRef={ 0, 0 })
Mirror the line points about y or x (or both)
wxPoint GetArcStart() const
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is contained within or on the bounding box of an item.
void SetArcGeometry(const wxPoint &aStart, const wxPoint &aMid, const wxPoint &aEnd)
Set the three controlling points for an arc.
virtual void Move(const wxPoint &aMoveVector) override
Move this object.
const std::vector< wxPoint > BuildPolyPointsList() const
Build and return the list of corners in a std::vector<wxPoint> It must be used only to convert the SH...
PCB_LAYER_ID
A quick note on layer IDs:
Display value expressed in distance units (mm/inch)
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=0.005 *PCB_IU_PER_MM) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
void Move(const VECTOR2I &aVector) override
const std::vector< VECTOR2I > & CPoints() const
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
const wxPoint GetOrigin() const
void SetEnd(int x, int y)
static wxString PCB_SHAPE_TYPE_T_asString(PCB_SHAPE_TYPE_T a)
wxPoint GetCenter() const override
This defaults to the center of the bounding box if not overridden.
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void SetPosition(const wxPoint &aPos) override
double GetArcAngleEnd() const
function GetArcAngleEnd()
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
double Angle() const
Compute the angle of the vector.
int NewOutline()
Creates a new hole in a given outline.
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
int SegmentCount() const
Function SegmentCount()
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
class FOOTPRINT, a footprint
Some functions to handle hotkeys in KiCad.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
void Rotate(double aAngle, const VECTOR2I &aCenter=VECTOR2I(0, 0)) override
Function Rotate rotates all vertices by a given angle.
void Normalize()
Ensures that the height ant width are positive.
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,...
wxPoint GetPosition() const override
bool CollideEdge(const VECTOR2I &aPoint, VERTEX_INDEX &aClosestVertex, int aClearance=0) const
Check whether aPoint collides with any edge of any of the contours of the polygon.
std::vector< SHAPE * > MakeEffectiveShapes() const
Makes a set of SHAPE objects representing the PCB_SHAPE.
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Bezier curves to polygon converter.
SEG Segment(int aIndex)
Function Segment()
virtual bool IsLocked() const
virtual BITMAP_DEF GetMenuImage() const override
Return a pointer to an image to be used in menus.
const SEG CSegment(int aIndex) const
Function CSegment()
FOOTPRINT * GetParentFootprint() const
Function GetParentFootprint returns a pointer to the parent footprint, or NULL if PCB_SHAPE does not ...
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void AddProperty(PROPERTY_BASE *aProperty)
Register a property.
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Handle the component boundary box.
double DECIDEG2RAD(double deg)
void SetWidth(int aWidth)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
A base class for most all the KiCad significant classes used in schematics and boards.
int GetPointCount() const
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_BezierPoints vertex list that approximate the Bezier curve by a list of segments Has me...
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
void SetArcEnd(const wxPoint &aArcEndPoint)
Initialize the end arc point.
Provide class metadata.Helper macro to map type hashes to names.
virtual void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
wxPoint GetArcMid() const
PCB_SHAPE_TYPE_T GetShape() const
double ArcTangente(int dy, int dx)
const VECTOR2I GetArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc or circle given three points on its circumference.
std::vector< wxPoint > m_bezierPoints
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
virtual void SetAngle(double aAngle, bool aUpdateEnd=true)
Sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
class PCB_SHAPE, a segment not on copper layers
static constexpr int Millimeter2iu(double mm)
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
PCB_SHAPE(BOARD_ITEM *aParent=NULL, KICAD_T idtype=PCB_SHAPE_T)
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
const std::vector< wxPoint > buildBezierToSegmentsPointsList(int aMinSegLen) const
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
void SetArcStart(const wxPoint &aArcStartPoint)
Initialize the start arc point.
const wxSize GetSize() const
KICAD_T Type() const
Returns the type of object.
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...
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.