45 m_overrideTextEnabled( false ),
50 m_suppressZeroes( false ),
52 m_arrowLength( Mils2iu( 50 ) ),
53 m_extensionOffset( 0 ),
55 m_keepTextAligned( true ),
98 template<
typename ShapeType>
101 m_shapes.push_back( std::make_shared<ShapeType>( aShape ) );
107 struct lconv* lc = localeconv();
108 wxChar sep = lc->decimal_point[0];
118 while(
text.Last() ==
'0' )
122 if(
text.Last() ==
'.' ||
text.Last() == sep )
236 if( newAngle >= 3600 )
262 int axis = aMirrorLeftRight ? axis_pos.x : axis_pos.y;
265 #define INVERT( pos ) ( ( pos ) = axis - ( ( pos ) - axis ) ) 266 if( aMirrorLeftRight )
276 if( aMirrorLeftRight )
294 std::vector<MSG_PANEL_ITEM>& aList )
299 wxCHECK_RET(
m_parent !=
nullptr, wxT(
"PCB_TEXT::GetMsgPanelInfo() m_Parent is NULL." ) );
303 aList.emplace_back(
_(
"Prefix" ),
GetPrefix() );
317 aList.emplace_back(
_(
"Suffix" ),
GetSuffix() );
334 aList.emplace_back( start, wxEmptyString );
347 aList.emplace_back( start, end );
351 aList.emplace_back(
_(
"Status" ),
_(
"Locked" ) );
359 std::shared_ptr<SHAPE_COMPOUND> effectiveShape = std::make_shared<SHAPE_COMPOUND>();
361 effectiveShape->AddShape(
Text().GetEffectiveTextShape()->
Clone() );
363 for(
const std::shared_ptr<SHAPE>& shape :
GetShapes() )
364 effectiveShape->AddShape( shape->Clone() );
366 return effectiveShape;
379 for(
const std::shared_ptr<SHAPE>& shape :
GetShapes() )
381 if( shape->Collide( aPosition, dist_max ) )
409 int xmin, xmax, ymin, ymax;
417 for(
const std::shared_ptr<SHAPE>& shape :
GetShapes() )
419 BOX2I shapeBox = shape->BBox();
422 xmin = std::min( xmin, shapeBox.
GetOrigin().
x );
423 xmax = std::max( xmax, shapeBox.
GetEnd().
x );
424 ymin = std::min( ymin, shapeBox.
GetOrigin().
y );
425 ymax = std::max( ymax, shapeBox.
GetEnd().
y );
460 VECTOR2I endpoint( aStart ? aSeg.
B : aSeg.
A );
467 if(
OPT_VECTOR2I intersection = ( *seg ).Intersect( aSeg ) )
469 if( ( *intersection - start ).SquaredEuclideanNorm() <
470 ( endpoint - start ).SquaredEuclideanNorm() )
471 endpoint = *intersection;
475 if( start == endpoint )
485 VECTOR2I endpoint( aStart ? aSeg.
B : aSeg.
A );
490 std::vector<VECTOR2I> intersections = aCircle.
Intersect( aSeg );
494 if( ( intersection - start ).SquaredEuclideanNorm() <
495 ( endpoint - start ).SquaredEuclideanNorm() )
496 endpoint = intersection;
499 if( start == endpoint )
509 bool aIgnoreLineWidth )
const 511 wxASSERT_MSG( !aIgnoreLineWidth, wxT(
"IgnoreLineWidth has no meaning for dimensions." ) );
513 for(
const std::shared_ptr<SHAPE>& shape :
m_shapes )
515 const SHAPE_CIRCLE* circle = dynamic_cast<const SHAPE_CIRCLE*>( shape.get() );
516 const SHAPE_SEGMENT* seg = dynamic_cast<const SHAPE_SEGMENT*>( shape.get() );
532 wxFAIL_MSG( wxT(
"PCB_DIMENSION_BASE::TransformShapeWithClearanceToPolygon unexpected " 559 static_cast<PCB_DIM_ALIGNED*>( aImage )->m_shapes.clear();
561 std::swap( *static_cast<PCB_DIM_ALIGNED*>(
this ), *static_cast<PCB_DIM_ALIGNED*>( aImage ) );
576 VECTOR2D crossBar( aCrossbarEnd - aCrossbarStart );
578 if( height.
Cross( crossBar ) > 0 )
598 extension =
VECTOR2I( -dimension.
y, dimension.
x );
600 extension =
VECTOR2I( dimension.
y, -dimension.
x );
639 bool containsA = polyBox.
Contains( crossbar.
A );
640 bool containsB = polyBox.
Contains( crossbar.
B );
651 if( !containsA && !containsB && !endpointA && !endpointB )
683 if( crossbarCenter.
x == 0 )
686 rotation = -std::copysign(
DEG2RAD( 90 ), crossbarCenter.
x );
689 textOffset += crossbarCenter;
704 if( textAngle > 900 && textAngle <= 2700 )
742 static_cast<PCB_DIM_ORTHOGONAL*>( aImage )->m_shapes.clear();
744 std::swap( *static_cast<PCB_DIM_ORTHOGONAL*>(
this ),
745 *static_cast<PCB_DIM_ORTHOGONAL*>( aImage ) );
821 bool containsA = polyBox.
Contains( crossbar.
A );
822 bool containsB = polyBox.
Contains( crossbar.
B );
833 if( !containsA && !containsB && !endpointA && !endpointB )
868 textOffset.
y = -textOffsetDistance;
870 textOffset.
x = -textOffsetDistance;
872 textOffset += crossbarCenter;
885 if( abs( crossbarCenter.
x ) > abs( crossbarCenter.
y ) )
904 else if( aAngle <= -1800 )
914 if( aAngle > 450 && aAngle <= 1350 )
927 else if( aAngle < -450 && aAngle >= -1350 )
940 else if( aAngle > 1350 || aAngle < -1350 )
971 std::swap( *static_cast<PCB_DIM_LEADER*>(
this ), *static_cast<PCB_DIM_LEADER*>( aImage ) );
1011 double radius = ( textBox.
GetWidth() / 2.0 ) - penWidth;
1024 arrowSegEnd =
m_end;
1035 start + wxPoint( arrowEnd.
Rotate( arrowRotPos ) ) ) );
1037 start + wxPoint( arrowEnd.
Rotate( arrowRotNeg ) ) ) );
1055 double radius = ( textBox.
GetWidth() / 2.0 ) - penWidth;
1066 if( textSegEnd && *arrowSegEnd ==
m_end )
1085 aList.emplace_back( start, wxEmptyString );
1109 std::swap( *static_cast<PCB_DIM_CENTER*>(
this ), *static_cast<PCB_DIM_CENTER*>( aImage ) );
void SetMirrored(bool isMirrored)
wxString m_prefix
String prepended to the value.
extended_type Cross(const VECTOR2< T > &aVector) const
Compute cross product of self with aVector.
static OPT_VECTOR2I segCircleIntersection(CIRCLE &aCircle, SEG &aSeg, bool aStart=true)
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer, FLASHING aFlash=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
void Offset(const wxPoint &aOffset)
void SetUnits(EDA_UNITS aUnits)
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.
DIM_TEXT_POSITION
Where to place the text on a dimension.
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
static PROPERTY_MANAGER & Instance()
bool TextHitTest(const wxPoint &aPoint, int aAccuracy=0) const override
Test if aPoint is within the bounds of this object.
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
class PCB_DIM_LEADER, a leader dimension (graphic item)
wxString GetValueText() const
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
DIR m_orientation
What axis to lock the dimension line to.
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.
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
std::vector< std::shared_ptr< SHAPE > > m_shapes
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void updateText() override
Update the text field value from the current geometry (called by updateGeometry normally).
int m_precision
Number of digits to display after decimal.
void SetTextAngle(double aAngle) override
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void Mirror(const wxPoint &axis_pos, bool aMirrorLeftRight=false)
Mirror the dimension relative to a given horizontal axis.
class PCB_DIM_CENTER, a center point marking (graphic item)
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
EDA_RECT GetTextBox(int aLine=-1, bool aInvertY=false) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
const wxString GetText() const
Retrieve the value text or override text, not including prefix or suffix.
bool m_autoUnits
If true, follow the currently selected UI units.
void SetTextPos(const wxPoint &aPoint)
void SetText(const wxString &aNewText)
Set the override text - has no effect if m_overrideValue == false.
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
double GetTextAngle() const
double RAD2DECIDEG(double rad)
const std::vector< std::shared_ptr< SHAPE > > & GetShapes() const
virtual ORIGIN_TRANSFORMS & GetOriginTransforms()
Return a reference to the default ORIGIN_TRANSFORMS object.
Base class for iterating over all segments in a given SHAPE_POLY_SET.
Text appears outside the dimension line (default)
bool GetOverrideTextEnabled() const
void Rotate(double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
wxString GetAbbreviatedUnitsLabel(EDA_UNITS aUnit, EDA_DATA_TYPE aType)
Get the units string for a given units type.
const VECTOR2I GetCenter() const
wxPoint m_crossBarEnd
Crossbar end control point.
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, int aAccuracy=0, bool aUseBBoxCaches=false) const
Return true if a given subpolygon contains the point aP.
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.
PCB_DIM_LEADER(BOARD_ITEM *aParent)
void RotatePoint(int *pX, int *pY, double angle)
void NORMALIZE_ANGLE_POS(T &Angle)
wxPoint m_end
Internal cache of drawn shapes.
The base class for create windows for drawing purpose.
void updateText() override
Update the text field value from the current geometry (called by updateGeometry normally).
virtual bool IsLocked() const
wxString m_suffix
String appended to the value.
PCB_TEXT m_text
The actual text object.
bool Contains(const wxPoint &aPoint) const
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
virtual void SetParent(EDA_ITEM *aParent)
wxPoint m_crossBarStart
Crossbar start control point.
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
int GetTextHeight() const
DIM_UNITS_MODE GetUnitsMode() const
For better understanding of the points that make a dimension:
void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
Text appears in line with the dimension line.
EDA_UNITS m_units
0 = inches, 1 = mm
wxString GetPrefix() const
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
const wxPoint GetEnd() const
virtual const wxPoint & GetStart() const
The dimension's origin is the first feature point for the dimension.
PCB_DIMENSION_BASE(BOARD_ITEM *aParent, KICAD_T aType=PCB_DIMENSION_T)
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
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.
DIM_UNITS_MODE
Used for storing the units selection in the file because EDA_UNITS alone doesn't cut it.
void updateGeometry() override
Update the cached geometry of the dimension after changing any of its properties.
virtual void SetText(const wxString &aText)
virtual wxPoint GetPosition() const override
OPT< VECTOR2I > OPT_VECTOR2I
wxString GetSuffix() const
void updateGeometry() override
Update the cached geometry of the dimension after changing any of its properties.
Represent a set of closed polygons.
void updateGeometry() override
Update the cached geometry of the dimension after changing any of its properties.
const wxPoint GetOrigin() const
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
DIM_UNITS_FORMAT
How to display the units in a dimension's text.
wxPoint GetPosition() const override
void SetParent(EDA_ITEM *aParent) override
void SetPrefix(const wxString &aPrefix)
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aCornerBuffer, const wxPoint &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void Move(const wxPoint &offset) override
Move this object.
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
int m_extensionHeight
Length of extension lines past the crossbar.
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate this object.
bool m_keepTextAligned
Calculate text orientation to match dimension.
void SetSuffix(const wxString &aSuffix)
Represent basic circle geometry with utility geometry functions.
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.
static struct DIMENSION_DESC _DIMENSION_DESC
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
double Angle() const
Compute the angle of the vector.
int GetMeasuredValue() const
int NewOutline()
Creates a new hole in a given outline.
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
bool m_suppressZeroes
Suppress trailing zeroes.
PCB_DIM_ORTHOGONAL(BOARD_ITEM *aParent)
Some functions to handle hotkeys in KiCad.
static constexpr float s_arrowAngle
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
double GetTextAngleRadians() const
void Normalize()
Ensures that the height ant width are positive.
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth) const override
Convert the item shape to a closed polygon.
void UpdateHeight(const wxPoint &aCrossbarStart, const wxPoint &aCrossbarEnd)
Update the stored height basing on points coordinates.
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
double To_User_Unit(EDA_UNITS aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
DIM_UNITS_FORMAT m_unitsFormat
How to render the units suffix.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
BITMAPS
A list of all bitmap identifiers.
double DEG2RAD(double deg)
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
bool m_overrideTextEnabled
Manually specify the displayed measurement value.
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate this object.
std::vector< VECTOR2I > Intersect(const CIRCLE &aCircle) const
Compute the intersection points between this circle and aCircle.
PCB_LAYER_ID
A quick note on layer IDs:
wxString m_valueString
Displayed value when m_overrideValue = true.
bool Contains(const VECTOR2I &aP) const
Return true if aP is on the circumference of this circle.
void GetUnits(EDA_UNITS &aUnits) const
void addShape(const ShapeType &aShape)
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Handle the component boundary box.
void TransformOvalToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aStart, const wxPoint &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
PCB_DIM_CENTER(BOARD_ITEM *aParent)
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 m_lineThickness
Thickness used for all graphics in the dimension.
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
DIM_TEXT_FRAME m_textFrame
const wxPoint & GetTextPos() const
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Provide class metadata.Helper macro to map type hashes to names.
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
virtual const wxPoint & GetEnd() const
static OPT_VECTOR2I segPolyIntersection(const SHAPE_POLY_SET &aPoly, const SEG &aSeg, bool aStart=true)
Find the intersection between a given segment and polygon outline.
#define PCB_EDIT_FRAME_NAME
int m_extensionOffset
Distance from feature points to extension line start.
CONST_SEGMENT_ITERATOR CIterateSegments(int aFirst, int aLast, bool aIterateHoles=false) const
Return an iterator object, for iterating aPolygonIdx-th polygon edges.
const Vec & GetOrigin() const
int m_height
Perpendicular distance from features to crossbar.
const wxPoint GetCenter() const
PCB_DIM_ALIGNED(BOARD_ITEM *aParent, KICAD_T aType=PCB_DIM_ALIGNED_T)
void SetUnitsMode(DIM_UNITS_MODE aMode)
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
static constexpr int Millimeter2iu(double mm)
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
virtual const wxString & GetText() const
Return the string associated with the text object.
wxString GetOverrideText() const
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
int m_measuredValue
value of PCB dimensions
DIM_TEXT_POSITION m_textPosition
How to position the text.
DIM_TEXT_FRAME
Frame to show around dimension text.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
SEGMENT_ITERATOR IterateSegments(int aFirst, int aLast, bool aIterateHoles=false)
Return an iterator object, for iterating between aFirst and aLast outline, with or without holes (def...
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Test if aPosition is inside or on the boundary of this item.
virtual void updateText()
Update the text field value from the current geometry (called by updateGeometry normally).
KICAD_T Type() const
Returns the type of object.
void updateGeometry() override
Update the cached geometry of the dimension after changing any of its properties.
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...
int m_arrowLength
Length of arrow shapes.
void Update()
Update the dimension's cached text and geometry.