KiCad PCB EDA Suite
EDA_SHAPE Class Referenceabstract

#include <eda_shape.h>

Inheritance diagram for EDA_SHAPE:
LIB_SHAPE PCB_SHAPE FP_SHAPE

Public Member Functions

 EDA_SHAPE (SHAPE_T aType, int aLineWidth, FILL_T aFill, bool eeWinding)
 
 ~EDA_SHAPE ()
 
void SwapShape (EDA_SHAPE *aImage)
 
wxString ShowShape () const
 
wxString SHAPE_T_asString () const
 
void SetFillMode (FILL_T aFill)
 
FILL_T GetFillType () const
 
bool IsFilled () const
 
void SetFilled (bool aFlag)
 
void SetWidth (int aWidth)
 
int GetWidth () const
 
void SetShape (SHAPE_T aShape)
 
SHAPE_T GetShape () const
 
const wxPoint & GetStart () const
 Return the starting point of the graphic. More...
 
int GetStartY ()
 
int GetStartX ()
 
void SetStart (const wxPoint &aStart)
 
void SetStartY (int y)
 
void SetStartX (int x)
 
const wxPoint & GetEnd () const
 Return the ending point of the graphic. More...
 
int GetEndY ()
 
int GetEndX ()
 
void SetEnd (const wxPoint &aEnd)
 
void SetEndY (int y)
 
void SetEndX (int x)
 
void SetBezierC1 (const wxPoint &aPt)
 
const wxPoint & GetBezierC1 () const
 
void SetBezierC2 (const wxPoint &aPt)
 
const wxPoint & GetBezierC2 () const
 
wxPoint getCenter () const
 
void SetCenter (const wxPoint &aCenter)
 
void SetArcAngleAndEnd (double aAngle, bool aCheckNegativeAngle=false)
 Set the end point from the angle center and start. More...
 
double GetArcAngle () const
 
bool EndsSwapped () const
 Have the start and end points been swapped since they were set? More...
 
wxPoint GetArcMid () const
 
std::vector< wxPoint > GetRectCorners () const
 
void CalcArcAngles (double &aStartAngle, double &aEndAngle) const
 Calc arc start and end angles such that aStartAngle < aEndAngle. More...
 
int GetRadius () const
 
void SetArcGeometry (const wxPoint &aStart, const wxPoint &aMid, const wxPoint &aEnd)
 Set the three controlling points for an arc. More...
 
const std::vector< wxPoint > & GetBezierPoints () const
 
void DupPolyPointsList (std::vector< wxPoint > &aBuffer) const
 Duplicate the list of corners in a std::vector<wxPoint> More...
 
int GetPointCount () const
 
SHAPE_POLY_SETGetPolyShape ()
 
const SHAPE_POLY_SETGetPolyShape () const
 
bool IsPolyShapeValid () const
 
void SetPolyShape (const SHAPE_POLY_SET &aShape)
 
void SetBezierPoints (const std::vector< wxPoint > &aPoints)
 
void RebuildBezierToSegmentsPointsList (int aMinSegLen)
 Rebuild the m_BezierPoints vertex list that approximate the Bezier curve by a list of segments. More...
 
void SetPolyPoints (const std::vector< wxPoint > &aPoints)
 
std::vector< SHAPE * > MakeEffectiveShapes () const
 Make a set of SHAPE objects representing the EDA_SHAPE. More...
 
void ShapeGetMsgPanelInfo (EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
 
double GetLength () const
 Return the length of the track using the hypotenuse calculation. More...
 
void TransformShapeWithClearanceToPolygon (SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth) const
 Convert the shape to a closed polygon. More...
 
int Compare (const EDA_SHAPE *aOther) const
 

Protected Member Functions

void setPosition (const wxPoint &aPos)
 
wxPoint getPosition () const
 
void move (const wxPoint &aMoveVector)
 
void rotate (const wxPoint &aRotCentre, double aAngle)
 
void flip (const wxPoint &aCentre, bool aFlipLeftRight)
 
void scale (double aScale)
 
virtual double getParentOrientation () const =0
 
virtual wxPoint getParentPosition () const =0
 
const EDA_RECT getBoundingBox () const
 
void computeArcBBox (EDA_RECT &aBBox) const
 
bool hitTest (const wxPoint &aPosition, int aAccuracy=0) const
 
bool hitTest (const EDA_RECT &aRect, bool aContained, int aAccuracy=0) const
 
const std::vector< wxPoint > buildBezierToSegmentsPointsList (int aMinSegLen) const
 
void beginEdit (const wxPoint &aStartPoint)
 
bool continueEdit (const wxPoint &aPosition)
 
void calcEdit (const wxPoint &aPosition)
 
void endEdit ()
 
void setEditState (int aState)
 

Protected Attributes

bool m_endsSwapped
 
SHAPE_T m_shape
 
int m_width
 
FILL_T m_fill
 
wxPoint m_start
 
wxPoint m_end
 
wxPoint m_arcCenter
 
wxPoint m_bezierC1
 
wxPoint m_bezierC2
 
std::vector< wxPoint > m_bezierPoints
 
SHAPE_POLY_SET m_poly
 
int m_editState
 
bool m_eeWinding
 

Detailed Description

Definition at line 62 of file eda_shape.h.

Constructor & Destructor Documentation

◆ EDA_SHAPE()

EDA_SHAPE::EDA_SHAPE ( SHAPE_T  aType,
int  aLineWidth,
FILL_T  aFill,
bool  eeWinding 
)

Definition at line 40 of file eda_shape.cpp.

40  :
41  m_endsSwapped( false ),
42  m_shape( aType ),
43  m_width( aLineWidth ),
44  m_fill( aFill ),
45  m_editState( 0 ),
46  m_eeWinding( eeWinding )
47 {
48 }
SHAPE_T m_shape
Definition: eda_shape.h:296
bool m_endsSwapped
Definition: eda_shape.h:295
int m_editState
Definition: eda_shape.h:310
FILL_T m_fill
Definition: eda_shape.h:298
bool m_eeWinding
Definition: eda_shape.h:311
int m_width
Definition: eda_shape.h:297

◆ ~EDA_SHAPE()

EDA_SHAPE::~EDA_SHAPE ( )

Definition at line 51 of file eda_shape.cpp.

52 {
53 }

Member Function Documentation

◆ beginEdit()

void EDA_SHAPE::beginEdit ( const wxPoint &  aStartPoint)
protected

Definition at line 1192 of file eda_shape.cpp.

1193 {
1194  switch( GetShape() )
1195  {
1196  case SHAPE_T::SEGMENT:
1197  case SHAPE_T::CIRCLE:
1198  case SHAPE_T::RECT:
1199  SetStart( aPosition );
1200  SetEnd( aPosition );
1201  break;
1202 
1203  case SHAPE_T::ARC:
1204  SetArcGeometry( aPosition, aPosition, aPosition );
1205  m_editState = 1;
1206  break;
1207 
1208  case SHAPE_T::POLY:
1209  m_poly.NewOutline();
1210  m_poly.Outline( 0 ).SetClosed( false );
1211 
1212  // Start and end of the first segment (co-located for now)
1213  m_poly.Outline( 0 ).Append( aPosition );
1214  m_poly.Outline( 0 ).Append( aPosition, true );
1215  break;
1216 
1217  default:
1219  }
1220 }
void SetEnd(const wxPoint &aEnd)
Definition: eda_shape.h:126
void SetArcGeometry(const wxPoint &aStart, const wxPoint &aMid, const wxPoint &aEnd)
Set the three controlling points for an arc.
Definition: eda_shape.cpp:489
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
void SetStart(const wxPoint &aStart)
Definition: eda_shape.h:101
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
SHAPE_LINE_CHAIN & Outline(int aIndex)
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
int m_editState
Definition: eda_shape.h:310
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
int NewOutline()
Creates a new hole in a given outline.
SHAPE_T GetShape() const
Definition: eda_shape.h:92

References SHAPE_LINE_CHAIN::Append(), ARC, CIRCLE, GetShape(), m_editState, m_poly, SHAPE_POLY_SET::NewOutline(), SHAPE_POLY_SET::Outline(), POLY, RECT, SEGMENT, SetArcGeometry(), SHAPE_LINE_CHAIN::SetClosed(), SetEnd(), SetStart(), SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by LIB_SHAPE::BeginEdit().

◆ buildBezierToSegmentsPointsList()

const std::vector< wxPoint > EDA_SHAPE::buildBezierToSegmentsPointsList ( int  aMinSegLen) const
protected

Definition at line 380 of file eda_shape.cpp.

381 {
382  std::vector<wxPoint> bezierPoints;
383 
384  // Rebuild the m_BezierPoints vertex list that approximate the Bezier curve
385  std::vector<wxPoint> ctrlPoints = { m_start, m_bezierC1, m_bezierC2, m_end };
386  BEZIER_POLY converter( ctrlPoints );
387  converter.GetPoly( bezierPoints, aMinSegLen );
388 
389  return bezierPoints;
390 }
wxPoint m_bezierC1
Definition: eda_shape.h:304
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_bezierC2
Definition: eda_shape.h:305
wxPoint m_start
Definition: eda_shape.h:299
Bezier curves to polygon converter.
Definition: bezier_curves.h:36

References BEZIER_POLY::GetPoly(), m_bezierC1, m_bezierC2, m_end, and m_start.

Referenced by MakeEffectiveShapes(), and RebuildBezierToSegmentsPointsList().

◆ CalcArcAngles()

void EDA_SHAPE::CalcArcAngles ( double &  aStartAngle,
double &  aEndAngle 
) const

Calc arc start and end angles such that aStartAngle < aEndAngle.

Each may be between -360.0 and 360.0.

Definition at line 445 of file eda_shape.cpp.

446 {
447  VECTOR2D startRadial( GetStart() - getCenter() );
448  VECTOR2D endRadial( GetEnd() - getCenter() );
449 
450  aStartAngle = 180.0 / M_PI * atan2( startRadial.y, startRadial.x );
451  aEndAngle = 180.0 / M_PI * atan2( endRadial.y, endRadial.x );
452 
453  if( aEndAngle == aStartAngle )
454  aEndAngle = aStartAngle + 360.0; // ring, not null
455 
456  if( aStartAngle > aEndAngle )
457  {
458  if( aEndAngle < 0 )
459  aEndAngle = NormalizeAngleDegrees( aEndAngle, 0.0, 360.0 );
460  else
461  aStartAngle = NormalizeAngleDegrees( aStartAngle, -360.0, 0.0 );
462  }
463 }
wxPoint getCenter() const
Definition: eda_shape.cpp:393
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:97
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
double NormalizeAngleDegrees(double Angle, double aMin, double aMax)
Normalize angle to be aMin < angle <= aMax angle is in degrees.
Definition: trigo.h:327

References getCenter(), GetEnd(), GetStart(), NormalizeAngleDegrees(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by computeArcBBox(), KIGFX::PCB_PAINTER::draw(), GetArcAngle(), and hitTest().

◆ calcEdit()

void EDA_SHAPE::calcEdit ( const wxPoint &  aPosition)
protected

Definition at line 1250 of file eda_shape.cpp.

1251 {
1252 #define sq( x ) pow( x, 2 )
1253 
1254  switch( GetShape() )
1255  {
1256  case SHAPE_T::SEGMENT:
1257  case SHAPE_T::CIRCLE:
1258  case SHAPE_T::RECT:
1259  SetEnd( aPosition );
1260  break;
1261 
1262  case SHAPE_T::ARC:
1263  {
1264  int radius = GetRadius();
1265 
1266  // Edit state 0: drawing: place start
1267  // Edit state 1: drawing: place end (center calculated for 90-degree subtended angle)
1268  // Edit state 2: point edit: move start (center calculated for invariant subtended angle)
1269  // Edit state 3: point edit: move end (center calculated for invariant subtended angle)
1270  // Edit state 4: point edit: move center
1271  // Edit state 5: point edit: move arc-mid-point
1272 
1273  switch( m_editState )
1274  {
1275  case 0:
1276  SetArcGeometry( aPosition, aPosition, aPosition );
1277  return;
1278 
1279  case 1:
1280  m_end = aPosition;
1281  radius = KiROUND( sqrt( sq( GetLineLength( m_start, m_end ) ) / 2.0 ) );
1282  break;
1283 
1284  case 2:
1285  case 3:
1286  {
1287  wxPoint v = m_start - m_end;
1288  double chordBefore = sq( v.x ) + sq( v.y );
1289 
1290  if( m_editState == 2 )
1291  m_start = aPosition;
1292  else
1293  m_end = aPosition;
1294 
1295  v = m_start - m_end;
1296  double chordAfter = sq( v.x ) + sq( v.y );
1297  double ratio = chordAfter / chordBefore;
1298 
1299  if( ratio != 0 )
1300  {
1301  radius = std::max( int( sqrt( sq( radius ) * ratio ) ) + 1,
1302  int( sqrt( chordAfter ) / 2 ) + 1 );
1303  }
1304  }
1305  break;
1306 
1307  case 4:
1308  {
1309  double chordA = GetLineLength( m_start, aPosition );
1310  double chordB = GetLineLength( m_end, aPosition );
1311  radius = int( ( chordA + chordB ) / 2.0 ) + 1;
1312  }
1313  break;
1314 
1315  case 5:
1316  SetArcGeometry( GetStart(), aPosition, GetEnd() );
1317  return;
1318  }
1319 
1320  // Calculate center based on start, end, and radius
1321  //
1322  // Let 'l' be the length of the chord and 'm' the middle point of the chord
1323  double l = GetLineLength( m_start, m_end );
1324  wxPoint m = ( m_start + m_end ) / 2;
1325 
1326  // Calculate 'd', the vector from the chord midpoint to the center
1327  wxPoint d;
1328  d.x = KiROUND( sqrt( sq( radius ) - sq( l/2 ) ) * ( m_start.y - m_end.y ) / l );
1329  d.y = KiROUND( sqrt( sq( radius ) - sq( l/2 ) ) * ( m_end.x - m_start.x ) / l );
1330 
1331  wxPoint c1 = m + d;
1332  wxPoint c2 = m - d;
1333 
1334  // Solution gives us 2 centers; we need to pick one:
1335  switch( m_editState )
1336  {
1337  case 1:
1338  {
1339  // Keep center clockwise from chord while drawing
1340  wxPoint chordVector = m_end - m_start;
1341  double chordAngle = ArcTangente( chordVector.y, chordVector.x );
1342  NORMALIZE_ANGLE_POS( chordAngle );
1343 
1344  wxPoint c1Test = c1;
1345  RotatePoint( &c1Test, m_start, -chordAngle );
1346 
1347  m_arcCenter = c1Test.x > 0 ? c2 : c1;
1348  }
1349  break;
1350 
1351  case 2:
1352  case 3:
1353  // Pick the one closer to the old center
1354  m_arcCenter = GetLineLength( c1, m_arcCenter ) < GetLineLength( c2, m_arcCenter ) ? c1 : c2;
1355  break;
1356 
1357  case 4:
1358  // Pick the one closer to the mouse position
1359  m_arcCenter = GetLineLength( c1, aPosition ) < GetLineLength( c2, aPosition ) ? c1 : c2;
1360  break;
1361  }
1362  }
1363  break;
1364 
1365  case SHAPE_T::POLY:
1366  m_poly.Outline( 0 ).SetPoint( m_poly.Outline( 0 ).GetPointCount() - 1, aPosition );
1367  break;
1368 
1369  default:
1371  }
1372 }
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:222
virtual size_t GetPointCount() const override
#define sq(x)
void SetEnd(const wxPoint &aEnd)
Definition: eda_shape.h:126
void SetArcGeometry(const wxPoint &aStart, const wxPoint &aMid, const wxPoint &aEnd)
Set the three controlling points for an arc.
Definition: eda_shape.cpp:489
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:97
void SetPoint(int aIndex, const VECTOR2I &aPos)
Move a point to a specific location.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:290
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
SHAPE_LINE_CHAIN & Outline(int aIndex)
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
int m_editState
Definition: eda_shape.h:310
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
wxPoint m_start
Definition: eda_shape.h:299
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
SHAPE_T GetShape() const
Definition: eda_shape.h:92
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:183
int GetRadius() const
Definition: eda_shape.cpp:466

References ARC, ArcTangente(), CIRCLE, GetEnd(), GetLineLength(), SHAPE_LINE_CHAIN::GetPointCount(), GetRadius(), GetShape(), GetStart(), KiROUND(), m_arcCenter, m_editState, m_end, m_poly, m_start, NORMALIZE_ANGLE_POS(), SHAPE_POLY_SET::Outline(), POLY, RECT, RotatePoint(), SEGMENT, SetArcGeometry(), SetEnd(), SHAPE_LINE_CHAIN::SetPoint(), SHAPE_T_asString(), sq, and UNIMPLEMENTED_FOR.

Referenced by LIB_SHAPE::CalcEdit().

◆ Compare()

int EDA_SHAPE::Compare ( const EDA_SHAPE aOther) const

Definition at line 1424 of file eda_shape.cpp.

1425 {
1426 #define EPSILON 2 // Should be enough for rounding errors on calculated items
1427 
1428 #define TEST( a, b ) { if( a != b ) return a - b; }
1429 #define TEST_E( a, b ) { if( abs( a - b ) > EPSILON ) return a - b; }
1430 #define TEST_PT( a, b ) { TEST_E( a.x, b.x ); TEST_E( a.y, b.y ); }
1431 
1432  TEST_PT( m_start, aOther->m_start );
1433  TEST_PT( m_end, aOther->m_end );
1434 
1435  TEST( (int) m_shape, (int) aOther->m_shape );
1436 
1437  if( m_shape == SHAPE_T::ARC )
1438  {
1439  TEST_PT( m_arcCenter, aOther->m_arcCenter );
1440  }
1441  else if( m_shape == SHAPE_T::BEZIER )
1442  {
1443  TEST_PT( m_bezierC1, aOther->m_bezierC1 );
1444  TEST_PT( m_bezierC2, aOther->m_bezierC2 );
1445  }
1446  else if( m_shape == SHAPE_T::POLY )
1447  {
1448  TEST( m_poly.TotalVertices(), aOther->m_poly.TotalVertices() );
1449 
1450  for( int ii = 0; ii < m_poly.TotalVertices(); ++ii )
1451  TEST_PT( m_poly.CVertex( ii ), aOther->m_poly.CVertex( ii ) );
1452  }
1453 
1454  TEST_E( m_width, aOther->m_width );
1455  TEST( (int) m_fill, (int) aOther->m_fill );
1456 
1457  return 0;
1458 }
int TotalVertices() const
Delete aIdx-th polygon from the set.
SHAPE_T m_shape
Definition: eda_shape.h:296
wxPoint m_bezierC1
Definition: eda_shape.h:304
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the aGlobalIndex-th vertex in the poly set.
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
wxPoint m_bezierC2
Definition: eda_shape.h:305
#define TEST(a, b)
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
#define TEST_E(a, b)
FILL_T m_fill
Definition: eda_shape.h:298
wxPoint m_start
Definition: eda_shape.h:299
#define TEST_PT(a, b)
int m_width
Definition: eda_shape.h:297

References ARC, BEZIER, SHAPE_POLY_SET::CVertex(), m_arcCenter, m_bezierC1, m_bezierC2, m_end, m_fill, m_poly, m_shape, m_start, m_width, POLY, TEST, TEST_E, TEST_PT, and SHAPE_POLY_SET::TotalVertices().

Referenced by LIB_SHAPE::compare(), and BOARD::cmp_drawings::operator()().

◆ computeArcBBox()

void EDA_SHAPE::computeArcBBox ( EDA_RECT aBBox) const
protected

Definition at line 979 of file eda_shape.cpp.

980 {
981  wxPoint start = m_start;
982  wxPoint end = m_end;
983  double t1, t2;
984 
985  CalcArcAngles( t1, t2 );
986 
987  if( m_eeWinding && NormalizeAngleDegrees( t1 - t2, -180.0, 180.0 ) > 0 )
988  std::swap( start, end );
989 
990  // Do not include the center, which is not necessarily inside the BB of an arc with a small
991  // included angle
992  aBBox.SetOrigin( start );
993  aBBox.Merge( end );
994 
995  // Determine the starting quarter
996  // 0 right-bottom
997  // 1 left-bottom
998  // 2 left-top
999  // 3 right-top
1000  unsigned int quarter;
1001 
1002  if( start.x < m_arcCenter.x )
1003  {
1004  if( start.y <= m_arcCenter.y )
1005  quarter = 2;
1006  else
1007  quarter = 1;
1008  }
1009  else if( start.x == m_arcCenter.x )
1010  {
1011  if( start.y < m_arcCenter.y )
1012  quarter = 3;
1013  else
1014  quarter = 1;
1015  }
1016  else
1017  {
1018  if( start.y < m_arcCenter.y )
1019  quarter = 3;
1020  else
1021  quarter = 0;
1022  }
1023 
1024  int radius = GetRadius();
1025  VECTOR2I startRadial = start - m_arcCenter;
1026  VECTOR2I endRadial = end - m_arcCenter;
1027  double angleStart = ArcTangente( startRadial.y, startRadial.x );
1028  double arcAngle = RAD2DECIDEG( endRadial.Angle() - startRadial.Angle() );
1029  int angle = (int) NormalizeAnglePos( angleStart ) % 900 + NormalizeAnglePos( arcAngle );
1030 
1031  while( angle > 900 )
1032  {
1033  switch( quarter )
1034  {
1035  case 0: aBBox.Merge( wxPoint( m_arcCenter.x, m_arcCenter.y + radius ) ); break; // down
1036  case 1: aBBox.Merge( wxPoint( m_arcCenter.x - radius, m_arcCenter.y ) ); break; // left
1037  case 2: aBBox.Merge( wxPoint( m_arcCenter.x, m_arcCenter.y - radius ) ); break; // up
1038  case 3: aBBox.Merge( wxPoint( m_arcCenter.x + radius, m_arcCenter.y ) ); break; // right
1039  }
1040 
1041  ++quarter %= 4;
1042  angle -= 900;
1043  }
1044 }
void Merge(const EDA_RECT &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: eda_rect.cpp:432
double RAD2DECIDEG(double rad)
Definition: trigo.h:234
void CalcArcAngles(double &aStartAngle, double &aEndAngle) const
Calc arc start and end angles such that aStartAngle < aEndAngle.
Definition: eda_shape.cpp:445
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:121
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
double Angle() const
Compute the angle of the vector.
Definition: vector2d.h:307
wxPoint m_start
Definition: eda_shape.h:299
bool m_eeWinding
Definition: eda_shape.h:311
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .. 360.0 range: angle is in 1/10 degrees.
Definition: trigo.h:281
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
double NormalizeAngleDegrees(double Angle, double aMin, double aMax)
Normalize angle to be aMin < angle <= aMax angle is in degrees.
Definition: trigo.h:327
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:183
int GetRadius() const
Definition: eda_shape.cpp:466

References PNS::angle(), VECTOR2< T >::Angle(), ArcTangente(), CalcArcAngles(), GetRadius(), m_arcCenter, m_eeWinding, m_end, m_start, EDA_RECT::Merge(), NormalizeAngleDegrees(), NormalizeAnglePos(), RAD2DECIDEG(), EDA_RECT::SetOrigin(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by getBoundingBox().

◆ continueEdit()

bool EDA_SHAPE::continueEdit ( const wxPoint &  aPosition)
protected

Definition at line 1223 of file eda_shape.cpp.

1224 {
1225  switch( GetShape() )
1226  {
1227  case SHAPE_T::ARC:
1228  case SHAPE_T::SEGMENT:
1229  case SHAPE_T::CIRCLE:
1230  case SHAPE_T::RECT:
1231  return false;
1232 
1233  case SHAPE_T::POLY:
1234  {
1235  SHAPE_LINE_CHAIN& poly = m_poly.Outline( 0 );
1236 
1237  // do not add zero-length segments
1238  if( poly.CPoint( poly.GetPointCount() - 2 ) != poly.CLastPoint() )
1239  poly.Append( aPosition, true );
1240  }
1241  return true;
1242 
1243  default:
1245  return false;
1246  }
1247 }
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.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
SHAPE_LINE_CHAIN & Outline(int aIndex)
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const VECTOR2I & CLastPoint() const
Return the last point in the line chain.
SHAPE_T GetShape() const
Definition: eda_shape.h:92

References SHAPE_LINE_CHAIN::Append(), ARC, CIRCLE, SHAPE_LINE_CHAIN::CLastPoint(), SHAPE_LINE_CHAIN::CPoint(), SHAPE_LINE_CHAIN::GetPointCount(), GetShape(), m_poly, SHAPE_POLY_SET::Outline(), POLY, RECT, SEGMENT, SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by LIB_SHAPE::ContinueEdit().

◆ DupPolyPointsList()

void EDA_SHAPE::DupPolyPointsList ( std::vector< wxPoint > &  aBuffer) const

Duplicate the list of corners in a std::vector<wxPoint>

It must be used only to convert the SHAPE_POLY_SET internal corner buffer to a list of wxPoints, and nothing else, because it duplicates the buffer, that is inefficient to know for instance the corner count

Definition at line 1152 of file eda_shape.cpp.

1153 {
1154  if( m_poly.OutlineCount() )
1155  {
1156  int pointCount = m_poly.COutline( 0 ).PointCount();
1157 
1158  if( pointCount )
1159  {
1160  aBuffer.reserve( pointCount );
1161 
1162  for ( auto iter = m_poly.CIterate(); iter; iter++ )
1163  aBuffer.emplace_back( iter->x, iter->y );
1164  }
1165  }
1166 }
int OutlineCount() const
Return the number of vertices in a given outline/hole.
int PointCount() const
Return the number of points (vertices) in this line chain.
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
const SHAPE_LINE_CHAIN & COutline(int aIndex) const

References SHAPE_POLY_SET::CIterate(), SHAPE_POLY_SET::COutline(), m_poly, SHAPE_POLY_SET::OutlineCount(), and SHAPE_LINE_CHAIN::PointCount().

Referenced by PCB_GRID_HELPER::computeAnchors(), BRDITEMS_PLOTTER::PlotFootprintGraphicItem(), TransformShapeWithClearanceToPolygon(), and PCB_POINT_EDITOR::updatePoints().

◆ endEdit()

void EDA_SHAPE::endEdit ( )
protected

Definition at line 1375 of file eda_shape.cpp.

1376 {
1377  switch( GetShape() )
1378  {
1379  case SHAPE_T::ARC:
1380  case SHAPE_T::SEGMENT:
1381  case SHAPE_T::CIRCLE:
1382  case SHAPE_T::RECT:
1383  break;
1384 
1385  case SHAPE_T::POLY:
1386  {
1387  SHAPE_LINE_CHAIN& poly = m_poly.Outline( 0 );
1388 
1389  // do not include last point twice
1390  if( poly.GetPointCount() > 2 )
1391  {
1392  if( poly.CPoint( poly.GetPointCount() - 2 ) == poly.CLastPoint() )
1393  {
1394  poly.SetClosed( true );
1395  poly.Remove( poly.GetPointCount() - 1 );
1396  }
1397  }
1398  }
1399  break;
1400 
1401  default:
1403  }
1404 }
virtual size_t GetPointCount() const override
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
SHAPE_LINE_CHAIN & Outline(int aIndex)
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
void Remove(int aStartIndex, int aEndIndex)
Remove the range of points [start_index, end_index] from the line chain.
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const VECTOR2I & CLastPoint() const
Return the last point in the line chain.
SHAPE_T GetShape() const
Definition: eda_shape.h:92

References ARC, CIRCLE, SHAPE_LINE_CHAIN::CLastPoint(), SHAPE_LINE_CHAIN::CPoint(), SHAPE_LINE_CHAIN::GetPointCount(), GetShape(), m_poly, SHAPE_POLY_SET::Outline(), POLY, RECT, SHAPE_LINE_CHAIN::Remove(), SEGMENT, SHAPE_LINE_CHAIN::SetClosed(), SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by LIB_SHAPE::EndEdit().

◆ EndsSwapped()

bool EDA_SHAPE::EndsSwapped ( ) const
inline

Have the start and end points been swapped since they were set?

Returns
true if they have

Definition at line 166 of file eda_shape.h.

166 { return m_endsSwapped; }
bool m_endsSwapped
Definition: eda_shape.h:295

References m_endsSwapped.

Referenced by CADSTAR_PCB_ARCHIVE_LOADER::makeTracksFromShapes().

◆ flip()

void EDA_SHAPE::flip ( const wxPoint &  aCentre,
bool  aFlipLeftRight 
)
protected

Definition at line 281 of file eda_shape.cpp.

282 {
283  switch ( m_shape )
284  {
285  case SHAPE_T::SEGMENT:
286  case SHAPE_T::RECT:
287  if( aFlipLeftRight )
288  {
289  m_start.x = aCentre.x - ( m_start.x - aCentre.x );
290  m_end.x = aCentre.x - ( m_end.x - aCentre.x );
291  }
292  else
293  {
294  m_start.y = aCentre.y - ( m_start.y - aCentre.y );
295  m_end.y = aCentre.y - ( m_end.y - aCentre.y );
296  }
297 
298  std::swap( m_start, m_end );
299  break;
300 
301  case SHAPE_T::CIRCLE:
302  if( aFlipLeftRight )
303  {
304  m_start.x = aCentre.x - ( m_start.x - aCentre.x );
305  m_end.x = aCentre.x - ( m_end.x - aCentre.x );
306  }
307  else
308  {
309  m_start.y = aCentre.y - ( m_start.y - aCentre.y );
310  m_end.y = aCentre.y - ( m_end.y - aCentre.y );
311  }
312  break;
313 
314  case SHAPE_T::ARC:
315  if( aFlipLeftRight )
316  {
317  m_start.x = aCentre.x - ( m_start.x - aCentre.x );
318  m_end.x = aCentre.x - ( m_end.x - aCentre.x );
319  m_arcCenter.x = aCentre.x - ( m_arcCenter.x - aCentre.x );
320  }
321  else
322  {
323  m_start.y = aCentre.y - ( m_start.y - aCentre.y );
324  m_end.y = aCentre.y - ( m_end.y - aCentre.y );
325  m_arcCenter.y = aCentre.y - ( m_arcCenter.y - aCentre.y );
326  }
327 
328  std::swap( m_start, m_end );
329  break;
330 
331  case SHAPE_T::POLY:
332  m_poly.Mirror( aFlipLeftRight, !aFlipLeftRight, VECTOR2I( aCentre ) );
333  break;
334 
335  case SHAPE_T::BEZIER:
336  if( aFlipLeftRight )
337  {
338  m_start.x = aCentre.x - ( m_start.x - aCentre.x );
339  m_end.x = aCentre.x - ( m_end.x - aCentre.x );
340  m_bezierC1.x = aCentre.x - ( m_bezierC1.x - aCentre.x );
341  m_bezierC2.x = aCentre.x - ( m_bezierC2.x - aCentre.x );
342  }
343  else
344  {
345  m_start.y = aCentre.y - ( m_start.y - aCentre.y );
346  m_end.y = aCentre.y - ( m_end.y - aCentre.y );
347  m_bezierC1.y = aCentre.y - ( m_bezierC1.y - aCentre.y );
348  m_bezierC2.y = aCentre.y - ( m_bezierC2.y - aCentre.y );
349  }
350 
351  // Rebuild the poly points shape
352  {
353  std::vector<wxPoint> ctrlPoints = { m_start, m_bezierC1, m_bezierC2, m_end };
354  BEZIER_POLY converter( ctrlPoints );
355  converter.GetPoly( m_bezierPoints, m_width );
356  }
357  break;
358 
359  default:
361  break;
362  }
363 }
SHAPE_T m_shape
Definition: eda_shape.h:296
wxPoint m_bezierC1
Definition: eda_shape.h:304
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aRef={ 0, 0 })
Mirror the line points about y or x (or both)
wxPoint m_bezierC2
Definition: eda_shape.h:305
std::vector< wxPoint > m_bezierPoints
Definition: eda_shape.h:307
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
wxPoint m_start
Definition: eda_shape.h:299
Bezier curves to polygon converter.
Definition: bezier_curves.h:36
int m_width
Definition: eda_shape.h:297

References ARC, BEZIER, CIRCLE, BEZIER_POLY::GetPoly(), m_arcCenter, m_bezierC1, m_bezierC2, m_bezierPoints, m_end, m_poly, m_shape, m_start, m_width, SHAPE_POLY_SET::Mirror(), POLY, RECT, SEGMENT, SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by PCB_SHAPE::Flip(), LIB_SHAPE::MirrorHorizontal(), and LIB_SHAPE::MirrorVertical().

◆ GetArcAngle()

double EDA_SHAPE::GetArcAngle ( ) const

◆ GetArcMid()

wxPoint EDA_SHAPE::GetArcMid ( ) const

◆ GetBezierC1()

◆ GetBezierC2()

◆ GetBezierPoints()

const std::vector<wxPoint>& EDA_SHAPE::GetBezierPoints ( ) const
inline

◆ getBoundingBox()

const EDA_RECT EDA_SHAPE::getBoundingBox ( ) const
protected

Definition at line 596 of file eda_shape.cpp.

597 {
598  EDA_RECT bbox;
599 
600  switch( m_shape )
601  {
602  case SHAPE_T::RECT:
603  for( wxPoint& pt : GetRectCorners() )
604  bbox.Merge( pt );
605 
606  break;
607 
608  case SHAPE_T::SEGMENT:
609  bbox.SetOrigin( GetStart() );
610  bbox.SetEnd( GetEnd() );
611  break;
612 
613  case SHAPE_T::CIRCLE:
614  bbox.SetOrigin( GetStart() );
615  bbox.Inflate( GetRadius() );
616  break;
617 
618  case SHAPE_T::ARC:
619  computeArcBBox( bbox );
620  break;
621 
622  case SHAPE_T::POLY:
623  if( m_poly.IsEmpty() )
624  break;
625 
626  for( auto iter = m_poly.CIterate(); iter; iter++ )
627  {
628  wxPoint pt( iter->x, iter->y );
629 
631  pt += getParentPosition();
632 
633  bbox.Merge( pt );
634  }
635 
636  break;
637 
638  case SHAPE_T::BEZIER:
639  bbox.SetOrigin( GetStart() );
640  bbox.Merge( GetBezierC1() );
641  bbox.Merge( GetBezierC2() );
642  bbox.Merge( GetEnd() );
643  break;
644 
645  default:
647  break;
648  }
649 
650  bbox.Inflate( std::max( 0, m_width / 2 ) );
651  bbox.Normalize();
652 
653  return bbox;
654 }
SHAPE_T m_shape
Definition: eda_shape.h:296
void Merge(const EDA_RECT &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: eda_rect.cpp:432
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:97
bool IsEmpty() const
void computeArcBBox(EDA_RECT &aBBox) const
Definition: eda_shape.cpp:979
virtual wxPoint getParentPosition() const =0
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:121
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
const wxPoint & GetBezierC1() const
Definition: eda_shape.h:145
std::vector< wxPoint > GetRectCorners() const
Definition: eda_shape.cpp:943
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
void SetEnd(int x, int y)
Definition: eda_rect.h:182
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
const wxPoint & GetBezierC2() const
Definition: eda_shape.h:148
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
virtual double getParentOrientation() const =0
Handle the component boundary box.
Definition: eda_rect.h:42
int m_width
Definition: eda_shape.h:297
int GetRadius() const
Definition: eda_shape.cpp:466
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364

References ARC, BEZIER, CIRCLE, SHAPE_POLY_SET::CIterate(), computeArcBBox(), GetBezierC1(), GetBezierC2(), GetEnd(), getParentOrientation(), getParentPosition(), GetRadius(), GetRectCorners(), GetStart(), EDA_RECT::Inflate(), SHAPE_POLY_SET::IsEmpty(), m_poly, m_shape, m_width, EDA_RECT::Merge(), EDA_RECT::Normalize(), POLY, RECT, RotatePoint(), SEGMENT, EDA_RECT::SetEnd(), EDA_RECT::SetOrigin(), SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by LIB_SHAPE::GetBoundingBox(), PCB_SHAPE::GetBoundingBox(), getCenter(), and hitTest().

◆ getCenter()

wxPoint EDA_SHAPE::getCenter ( ) const

Definition at line 393 of file eda_shape.cpp.

394 {
395  switch( m_shape )
396  {
397  case SHAPE_T::ARC:
398  return m_arcCenter;
399 
400  case SHAPE_T::CIRCLE:
401  return m_start;
402 
403  case SHAPE_T::SEGMENT:
404  // Midpoint of the line
405  return ( m_start + m_end ) / 2;
406 
407  case SHAPE_T::POLY:
408  case SHAPE_T::RECT:
409  case SHAPE_T::BEZIER:
410  return getBoundingBox().Centre();
411 
412  default:
414  return wxPoint();
415  }
416 }
SHAPE_T m_shape
Definition: eda_shape.h:296
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
wxPoint m_start
Definition: eda_shape.h:299
const EDA_RECT getBoundingBox() const
Definition: eda_shape.cpp:596
wxPoint Centre() const
Definition: eda_rect.h:55

References ARC, BEZIER, EDA_RECT::Centre(), CIRCLE, getBoundingBox(), m_arcCenter, m_end, m_shape, m_start, POLY, RECT, SEGMENT, SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by CalcArcAngles(), PCB_SHAPE::GetCenter(), LIB_SHAPE::GetCenter(), getPosition(), hitTest(), MakeEffectiveShapes(), LIB_SHAPE::Plot(), LIB_SHAPE::print(), and TransformShapeWithClearanceToPolygon().

◆ GetEnd()

const wxPoint& EDA_SHAPE::GetEnd ( ) const
inline

Return the ending point of the graphic.

Definition at line 122 of file eda_shape.h.

122 { return m_end; }
wxPoint m_end
Definition: eda_shape.h:300

References m_end.

Referenced by PCB_POINT_EDITOR::addCorner(), BOARD_ADAPTER::addShapeWithClearance(), GRAPHICS_CLEANER::areEquivalent(), LIB_SHAPE::CalcArcAngles(), CalcArcAngles(), calcEdit(), PCB_GRID_HELPER::computeAnchors(), ConvertOutlineToPolygon(), CreateBoardSection(), CONVERT_TOOL::CreateLines(), MICROWAVE_TOOL::createMicrowaveInductor(), KIGFX::SCH_PAINTER::draw(), KIGFX::PCB_PAINTER::draw(), PCB_POINT_EDITOR::editArcEndpointKeepTangent(), PCB_PLUGIN::format(), formatArc(), formatBezier(), formatRect(), getBoundingBox(), GetLength(), GetRectCorners(), CADSTAR_SCH_ARCHIVE_LOADER::getScaledLibPart(), CONVERT_TOOL::getStartEndPoints(), hash_fp_item(), hitTest(), idf_export_outline(), GRAPHICS_CLEANER::isNullShape(), SCH_LEGACY_PLUGIN_CACHE::loadArc(), EDIT_POINTS_FACTORY::Make(), MakeEffectiveShapes(), DSN::SPECCTRA_DB::makeIMAGE(), PCB_POINT_EDITOR::makePoints(), CONVERT_TOOL::makePolysFromRects(), CONVERT_TOOL::makePolysFromSegs(), GRAPHICS_CLEANER::mergeRects(), PCB_PARSER::parsePAD(), BRDITEMS_PLOTTER::PlotFootprintGraphicItem(), BRDITEMS_PLOTTER::PlotPcbShape(), SCH_LEGACY_PLUGIN_CACHE::saveArc(), SCH_LEGACY_PLUGIN_CACHE::saveRectangle(), ShapeGetMsgPanelInfo(), AR_MATRIX::TraceSegmentPcb(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow(), TransformShapeWithClearanceToPolygon(), EE_POINT_EDITOR::updatePoints(), and PCB_POINT_EDITOR::updatePoints().

◆ GetEndX()

int EDA_SHAPE::GetEndX ( )
inline

Definition at line 124 of file eda_shape.h.

124 { return m_end.x; }
wxPoint m_end
Definition: eda_shape.h:300

References m_end.

Referenced by EDA_SHAPE_DESC::EDA_SHAPE_DESC(), PCB_SHAPE_DESC::PCB_SHAPE_DESC(), and DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run().

◆ GetEndY()

int EDA_SHAPE::GetEndY ( )
inline

Definition at line 123 of file eda_shape.h.

123 { return m_end.y; }
wxPoint m_end
Definition: eda_shape.h:300

References m_end.

Referenced by EDA_SHAPE_DESC::EDA_SHAPE_DESC(), PCB_SHAPE_DESC::PCB_SHAPE_DESC(), and DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run().

◆ GetFillType()

◆ GetLength()

double EDA_SHAPE::GetLength ( ) const

Return the length of the track using the hypotenuse calculation.

Returns
the length of the track

Definition at line 106 of file eda_shape.cpp.

107 {
108  double length = 0.0;
109 
110  switch( m_shape )
111  {
112  case SHAPE_T::BEZIER:
113  for( size_t ii = 1; ii < m_bezierPoints.size(); ++ii )
114  length += GetLineLength( m_bezierPoints[ ii - 1], m_bezierPoints[ii] );
115 
116  return length;
117 
118  case SHAPE_T::SEGMENT:
119  return GetLineLength( GetStart(), GetEnd() );
120 
121  case SHAPE_T::POLY:
122  for( int ii = 0; ii < m_poly.COutline( 0 ).SegmentCount(); ii++ )
123  length += m_poly.COutline( 0 ).CSegment( ii ).Length();
124 
125  return length;
126 
127  case SHAPE_T::ARC:
128  return 2 * M_PI * GetRadius() * ( GetArcAngle() / 3600.0 );
129 
130  default:
132  return 0.0;
133  }
134 }
int Length() const
Return the length (this).
Definition: seg.h:350
SHAPE_T m_shape
Definition: eda_shape.h:296
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:222
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:97
double GetArcAngle() const
Definition: eda_shape.cpp:498
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
std::vector< wxPoint > m_bezierPoints
Definition: eda_shape.h:307
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
int GetRadius() const
Definition: eda_shape.cpp:466

References ARC, BEZIER, SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CSegment(), GetArcAngle(), GetEnd(), GetLineLength(), GetRadius(), GetStart(), SEG::Length(), m_bezierPoints, m_poly, m_shape, POLY, SEGMENT, SHAPE_LINE_CHAIN::SegmentCount(), SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by ShapeGetMsgPanelInfo().

◆ getParentOrientation()

virtual double EDA_SHAPE::getParentOrientation ( ) const
protectedpure virtual

◆ getParentPosition()

virtual wxPoint EDA_SHAPE::getParentPosition ( ) const
protectedpure virtual

◆ GetPointCount()

int EDA_SHAPE::GetPointCount ( ) const
Returns
the number of corners of the polygonal shape

Definition at line 1181 of file eda_shape.cpp.

1182 {
1183  // return the number of corners of the polygonal shape
1184  // this shape is expected to be only one polygon without hole
1185  if( GetPolyShape().OutlineCount() )
1186  return GetPolyShape().VertexCount( 0 );
1187 
1188  return 0;
1189 }
int VertexCount(int aOutline=-1, int aHole=-1) const
Return the number of points in the shape poly set.
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:207

References GetPolyShape(), and SHAPE_POLY_SET::VertexCount().

Referenced by GRAPHICS_CLEANER::isNullShape(), and EE_POINT_EDITOR::updatePoints().

◆ GetPolyShape() [1/2]

◆ GetPolyShape() [2/2]

const SHAPE_POLY_SET& EDA_SHAPE::GetPolyShape ( ) const
inline

Definition at line 208 of file eda_shape.h.

208 { return m_poly; }
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308

References m_poly.

◆ getPosition()

wxPoint EDA_SHAPE::getPosition ( ) const
protected

Definition at line 95 of file eda_shape.cpp.

96 {
97  if( m_shape == SHAPE_T::ARC )
98  return getCenter();
99  else if( m_shape == SHAPE_T::POLY )
100  return (wxPoint) m_poly.CVertex( 0 );
101  else
102  return m_start;
103 }
SHAPE_T m_shape
Definition: eda_shape.h:296
wxPoint getCenter() const
Definition: eda_shape.cpp:393
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the aGlobalIndex-th vertex in the poly set.
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
wxPoint m_start
Definition: eda_shape.h:299

References ARC, SHAPE_POLY_SET::CVertex(), getCenter(), m_poly, m_shape, m_start, and POLY.

Referenced by PCB_SHAPE::GetPosition(), LIB_SHAPE::GetPosition(), and setPosition().

◆ GetRadius()

int EDA_SHAPE::GetRadius ( ) const

Definition at line 466 of file eda_shape.cpp.

467 {
468  double radius = 0.0;
469 
470  switch( m_shape )
471  {
472  case SHAPE_T::ARC:
473  radius = GetLineLength( m_arcCenter, m_start );
474  break;
475 
476  case SHAPE_T::CIRCLE:
477  radius = GetLineLength( m_start, m_end );
478  break;
479 
480  default:
482  }
483 
484  // don't allow degenerate circles/arcs
485  return std::max( 1, KiROUND( radius ) );
486 }
SHAPE_T m_shape
Definition: eda_shape.h:296
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:222
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
wxPoint m_start
Definition: eda_shape.h:299
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73

References ARC, CIRCLE, GetLineLength(), KiROUND(), m_arcCenter, m_end, m_shape, m_start, SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by BOARD_ADAPTER::addShapeWithClearance(), calcEdit(), computeArcBBox(), ConvertOutlineToPolygon(), KIGFX::SCH_PAINTER::draw(), KIGFX::PCB_PAINTER::draw(), formatCircle(), getBoundingBox(), PCB_SHAPE::GetFocusPosition(), GetLength(), LIB_SHAPE::GetSelectMenuText(), hash_fp_item(), hitTest(), idf_export_outline(), GRAPHICS_CLEANER::isNullShape(), MakeEffectiveShapes(), DSN::SPECCTRA_DB::makeIMAGE(), CONVERT_TOOL::makePolysFromCircles(), ALTIUM_PCB::Parse(), PCB_PARSER::parsePAD(), LIB_SHAPE::Plot(), BRDITEMS_PLOTTER::PlotPcbShape(), LIB_SHAPE::print(), SCH_LEGACY_PLUGIN_CACHE::saveArc(), SCH_LEGACY_PLUGIN_CACHE::saveCircle(), scale(), ShapeGetMsgPanelInfo(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow(), and TransformShapeWithClearanceToPolygon().

◆ GetRectCorners()

std::vector< wxPoint > EDA_SHAPE::GetRectCorners ( ) const

Definition at line 943 of file eda_shape.cpp.

944 {
945  std::vector<wxPoint> pts;
946  wxPoint topLeft = GetStart();
947  wxPoint botRight = GetEnd();
948 
949  // Un-rotate rect topLeft and botRight
950  if( KiROUND( getParentOrientation() ) % 900 != 0 )
951  {
952  topLeft -= getParentPosition();
953  RotatePoint( &topLeft, -getParentOrientation() );
954 
955  botRight -= getParentPosition();
956  RotatePoint( &botRight, -getParentOrientation() );
957  }
958 
959  // Set up the un-rotated 4 corners
960  pts.emplace_back( topLeft );
961  pts.emplace_back( botRight.x, topLeft.y );
962  pts.emplace_back( botRight );
963  pts.emplace_back( topLeft.x, botRight.y );
964 
965  // Now re-rotate the 4 corners to get a diamond
966  if( KiROUND( getParentOrientation() ) % 900 != 0 )
967  {
968  for( wxPoint& pt : pts )
969  {
971  pt += getParentPosition();
972  }
973  }
974 
975  return pts;
976 }
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:97
virtual wxPoint getParentPosition() const =0
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
virtual double getParentOrientation() const =0
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73

References GetEnd(), getParentOrientation(), getParentPosition(), GetStart(), KiROUND(), and RotatePoint().

Referenced by BOARD_ADAPTER::addShapeWithClearance(), ConvertOutlineToPolygon(), KIGFX::PCB_PAINTER::draw(), getBoundingBox(), hitTest(), MakeEffectiveShapes(), BRDITEMS_PLOTTER::PlotFootprintGraphicItem(), BRDITEMS_PLOTTER::PlotPcbShape(), and TransformShapeWithClearanceToPolygon().

◆ GetShape()

SHAPE_T EDA_SHAPE::GetShape ( ) const
inline

Definition at line 92 of file eda_shape.h.

92 { return m_shape; }
SHAPE_T m_shape
Definition: eda_shape.h:296

References m_shape.

Referenced by PCB_POINT_EDITOR::addCorner(), EE_POINT_EDITOR::addCornerCondition(), LIB_SHAPE::AddPoint(), BOARD_ADAPTER::addShapeWithClearance(), GRAPHICS_CLEANER::areEquivalent(), beginEdit(), calcEdit(), PCB_POINT_EDITOR::canAddCorner(), GRAPHICS_CLEANER::cleanupSegments(), PCB_GRID_HELPER::computeAnchors(), continueEdit(), ConvertOutlineToPolygon(), CONVERT_TOOL::CreateLines(), KIGFX::SCH_PAINTER::draw(), KIGFX::PCB_PAINTER::draw(), EDA_SHAPE_DESC::EDA_SHAPE_DESC(), endEdit(), PAD_TOOL::explodePad(), CADSTAR_SCH_ARCHIVE_LOADER::fixUpLibraryPins(), FP_SHAPE::Flip(), FootprintWriteShape(), PCB_PLUGIN::format(), FOOTPRINT::GetCoverageArea(), LIB_SHAPE::GetMenuImage(), CADSTAR_SCH_ARCHIVE_LOADER::getScaledLibPart(), LIB_SHAPE::GetSelectMenuText(), EE_SELECTION_TOOL::GuessSelectionCandidates(), hash_fp_item(), idf_export_outline(), GRAPHICS_CLEANER::isNullShape(), EE_POINT_EDITOR::Main(), EDIT_POINTS_FACTORY::Make(), DSN::SPECCTRA_DB::makeIMAGE(), PCB_POINT_EDITOR::makePoints(), CONVERT_TOOL::makePolysFromCircles(), CONVERT_TOOL::makePolysFromRects(), GRAPHICS_CLEANER::mergeRects(), FP_SHAPE::Mirror(), FP_SHAPE::Move(), PCB_SHAPE::cmp_drawings::operator()(), FOOTPRINT::cmp_drawings::operator()(), ALTIUM_PCB::Parse(), LIB_SHAPE::Plot(), BRDITEMS_PLOTTER::PlotFootprintGraphicItem(), BRDITEMS_PLOTTER::PlotPcbShape(), LIB_SHAPE::print(), PAD_TOOL::recombinePad(), PCB_POINT_EDITOR::removeCorner(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), SCH_LEGACY_PLUGIN_CACHE::saveArc(), SCH_LEGACY_PLUGIN_CACHE::saveBezier(), SCH_LEGACY_PLUGIN_CACHE::saveCircle(), SCH_LEGACY_PLUGIN_CACHE::savePolyLine(), SCH_LEGACY_PLUGIN_CACHE::saveRectangle(), SCH_LEGACY_PLUGIN_CACHE::SaveSymbol(), SCH_SEXPR_PLUGIN_CACHE::saveSymbolDrawItem(), PNS_KICAD_IFACE_BASE::syncGraphicalItem(), AR_MATRIX::TraceSegmentPcb(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow(), PCB_POINT_EDITOR::updateItem(), EE_POINT_EDITOR::updateParentItem(), EE_POINT_EDITOR::updatePoints(), PCB_POINT_EDITOR::updatePoints(), and DIALOG_GRAPHIC_ITEM_PROPERTIES::Validate().

◆ GetStart()

const wxPoint& EDA_SHAPE::GetStart ( ) const
inline

Return the starting point of the graphic.

Definition at line 97 of file eda_shape.h.

97 { return m_start; }
wxPoint m_start
Definition: eda_shape.h:299

References m_start.

Referenced by PCB_POINT_EDITOR::addCorner(), BOARD_ADAPTER::addShapeWithClearance(), GRAPHICS_CLEANER::areEquivalent(), LIB_SHAPE::CalcArcAngles(), CalcArcAngles(), calcEdit(), PCB_GRID_HELPER::computeAnchors(), ConvertOutlineToPolygon(), CreateBoardSection(), CONVERT_TOOL::CreateLines(), MICROWAVE_TOOL::createMicrowaveInductor(), KIGFX::PCB_PAINTER::draw(), PCB_POINT_EDITOR::editArcEndpointKeepCenter(), PCB_POINT_EDITOR::editArcEndpointKeepTangent(), PCB_PLUGIN::format(), formatArc(), formatBezier(), formatCircle(), formatRect(), getBoundingBox(), PCB_SHAPE::GetFocusPosition(), GetLength(), GetRectCorners(), CADSTAR_SCH_ARCHIVE_LOADER::getScaledLibPart(), CONVERT_TOOL::getStartEndPoints(), hash_fp_item(), hitTest(), idf_export_outline(), GRAPHICS_CLEANER::isNullShape(), SCH_LEGACY_PLUGIN_CACHE::loadArc(), EDIT_POINTS_FACTORY::Make(), DSN::SPECCTRA_DB::makeIMAGE(), PCB_POINT_EDITOR::makePoints(), CONVERT_TOOL::makePolysFromRects(), CONVERT_TOOL::makePolysFromSegs(), GRAPHICS_CLEANER::mergeRects(), PCB_PARSER::parsePAD(), BRDITEMS_PLOTTER::PlotFootprintGraphicItem(), BRDITEMS_PLOTTER::PlotPcbShape(), BRDITEMS_PLOTTER::PlotPcbTarget(), SCH_LEGACY_PLUGIN_CACHE::saveArc(), ShapeGetMsgPanelInfo(), AR_MATRIX::TraceSegmentPcb(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataToWindow(), TransformShapeWithClearanceToPolygon(), EE_POINT_EDITOR::updatePoints(), and PCB_POINT_EDITOR::updatePoints().

◆ GetStartX()

int EDA_SHAPE::GetStartX ( )
inline

Definition at line 99 of file eda_shape.h.

99 { return m_start.x; }
wxPoint m_start
Definition: eda_shape.h:299

References m_start.

Referenced by EDA_SHAPE_DESC::EDA_SHAPE_DESC(), and DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run().

◆ GetStartY()

int EDA_SHAPE::GetStartY ( )
inline

Definition at line 98 of file eda_shape.h.

98 { return m_start.y; }
wxPoint m_start
Definition: eda_shape.h:299

References m_start.

Referenced by EDA_SHAPE_DESC::EDA_SHAPE_DESC(), and DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run().

◆ GetWidth()

int EDA_SHAPE::GetWidth ( ) const
inline

◆ hitTest() [1/2]

bool EDA_SHAPE::hitTest ( const wxPoint &  aPosition,
int  aAccuracy = 0 
) const
protected

Definition at line 657 of file eda_shape.cpp.

658 {
659  int maxdist = aAccuracy;
660 
661  if( m_width > 0 )
662  maxdist += m_width / 2;
663 
664  switch( m_shape )
665  {
666  case SHAPE_T::CIRCLE:
667  {
668  int radius = GetRadius();
669  int dist = KiROUND( EuclideanNorm( aPosition - getCenter() ) );
670 
671  if( IsFilled() )
672  return dist <= radius + maxdist; // Filled circle hit-test
673  else
674  return abs( radius - dist ) <= maxdist; // Ring hit-test
675  }
676 
677  case SHAPE_T::ARC:
678  {
679  if( EuclideanNorm( aPosition - m_start ) <= maxdist )
680  return true;
681 
682  if( EuclideanNorm( aPosition - m_end ) <= maxdist )
683  return true;
684 
685  wxPoint relPos = aPosition - getCenter();
686  int radius = GetRadius();
687  int dist = KiROUND( EuclideanNorm( relPos ) );
688 
689  if( abs( radius - dist ) <= maxdist )
690  {
691  double startAngle;
692  double endAngle;
693  CalcArcAngles( startAngle, endAngle );
694 
695  if( m_eeWinding && NormalizeAngleDegrees( startAngle - endAngle, -180.0, 180.0 ) > 0 )
696  std::swap( startAngle, endAngle );
697 
698  double relPosAngle = 180.0 / M_PI * atan2( relPos.y, relPos.x );
699 
700  startAngle = NormalizeAngleDegrees( startAngle, 0.0, 360.0 );
701  endAngle = NormalizeAngleDegrees( endAngle, 0.0, 360.0 );
702  relPosAngle = NormalizeAngleDegrees( relPosAngle, 0.0, 360.0 );
703 
704  if( endAngle > startAngle )
705  return relPosAngle >= startAngle && relPosAngle <= endAngle;
706  else
707  return relPosAngle >= startAngle || relPosAngle <= endAngle;
708  }
709 
710  return false;
711  }
712 
713  case SHAPE_T::BEZIER:
714  const_cast<EDA_SHAPE*>( this )->RebuildBezierToSegmentsPointsList( m_width );
715 
716  for( unsigned int i= 1; i < m_bezierPoints.size(); i++)
717  {
718  if( TestSegmentHit( aPosition, m_bezierPoints[ i - 1], m_bezierPoints[i], maxdist ) )
719  return true;
720  }
721 
722  return false;
723 
724  case SHAPE_T::SEGMENT:
725  return TestSegmentHit( aPosition, GetStart(), GetEnd(), maxdist );
726 
727  case SHAPE_T::RECT:
728  if( IsFilled() ) // Filled rect hit-test
729  {
730  SHAPE_POLY_SET poly;
731  poly.NewOutline();
732 
733  for( const wxPoint& pt : GetRectCorners() )
734  poly.Append( pt );
735 
736  return poly.Collide( VECTOR2I( aPosition ), maxdist );
737  }
738  else // Open rect hit-test
739  {
740  std::vector<wxPoint> pts = GetRectCorners();
741 
742  return TestSegmentHit( aPosition, pts[0], pts[1], maxdist )
743  || TestSegmentHit( aPosition, pts[1], pts[2], maxdist )
744  || TestSegmentHit( aPosition, pts[2], pts[3], maxdist )
745  || TestSegmentHit( aPosition, pts[3], pts[0], maxdist );
746  }
747 
748  case SHAPE_T::POLY:
749  if( IsFilled() )
750  {
751  return m_poly.Collide( VECTOR2I( aPosition ), maxdist );
752  }
753  else
754  {
756  return m_poly.CollideEdge( VECTOR2I( aPosition ), dummy, maxdist );
757  }
758 
759  default:
761  return false;
762  }
763 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:146
SHAPE_T m_shape
Definition: eda_shape.h:296
wxPoint getCenter() const
Definition: eda_shape.cpp:393
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:97
void CalcArcAngles(double &aStartAngle, double &aEndAngle) const
Calc arc start and end angles such that aStartAngle < aEndAngle.
Definition: eda_shape.cpp:445
Structure to hold the necessary information in order to index a vertex on a SHAPE_POLY_SET object: th...
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
wxPoint m_end
Definition: eda_shape.h:300
bool IsFilled() const
Definition: eda_shape.h:81
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
std::vector< wxPoint > GetRectCorners() const
Definition: eda_shape.cpp:943
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
Represent a set of closed polygons.
std::vector< wxPoint > m_bezierPoints
Definition: eda_shape.h:307
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
bool TestSegmentHit(const wxPoint &aRefPoint, const wxPoint &aStart, const wxPoint &aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition: trigo.cpp:129
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
int NewOutline()
Creates a new hole in a given outline.
wxPoint m_start
Definition: eda_shape.h:299
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,...
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.
bool m_eeWinding
Definition: eda_shape.h:311
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
double NormalizeAngleDegrees(double Angle, double aMin, double aMax)
Normalize angle to be aMin < angle <= aMax angle is in degrees.
Definition: trigo.h:327
int m_width
Definition: eda_shape.h:297
int GetRadius() const
Definition: eda_shape.cpp:466
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...

References SHAPE_POLY_SET::Append(), ARC, BEZIER, CalcArcAngles(), CIRCLE, SHAPE_POLY_SET::Collide(), SHAPE_POLY_SET::CollideEdge(), dummy(), EuclideanNorm(), getCenter(), GetEnd(), GetRadius(), GetRectCorners(), GetStart(), IsFilled(), KiROUND(), m_bezierPoints, m_eeWinding, m_end, m_poly, m_shape, m_start, m_width, SHAPE_POLY_SET::NewOutline(), NormalizeAngleDegrees(), POLY, RECT, SEGMENT, SHAPE_T_asString(), TestSegmentHit(), and UNIMPLEMENTED_FOR.

Referenced by LIB_SHAPE::HitTest(), and PCB_SHAPE::HitTest().

◆ hitTest() [2/2]

bool EDA_SHAPE::hitTest ( const EDA_RECT aRect,
bool  aContained,
int  aAccuracy = 0 
) const
protected

Definition at line 766 of file eda_shape.cpp.

767 {
768  EDA_RECT arect = aRect;
769  arect.Normalize();
770  arect.Inflate( aAccuracy );
771 
772  EDA_RECT arcRect;
773  EDA_RECT bb = getBoundingBox();
774 
775  switch( m_shape )
776  {
777  case SHAPE_T::CIRCLE:
778  // Test if area intersects or contains the circle:
779  if( aContained )
780  {
781  return arect.Contains( bb );
782  }
783  else
784  {
785  // If the rectangle does not intersect the bounding box, this is a much quicker test
786  if( !aRect.Intersects( bb ) )
787  {
788  return false;
789  }
790  else
791  {
792  return arect.IntersectsCircleEdge( getCenter(), GetRadius(), GetWidth() );
793  }
794  }
795 
796  case SHAPE_T::ARC:
797  // Test for full containment of this arc in the rect
798  if( aContained )
799  {
800  return arect.Contains( bb );
801  }
802  // Test if the rect crosses the arc
803  else
804  {
805  arcRect = bb.Common( arect );
806 
807  /* All following tests must pass:
808  * 1. Rectangle must intersect arc BoundingBox
809  * 2. Rectangle must cross the outside of the arc
810  */
811  return arcRect.Intersects( arect ) &&
813  }
814 
815  case SHAPE_T::RECT:
816  if( aContained )
817  {
818  return arect.Contains( bb );
819  }
820  else
821  {
822  std::vector<wxPoint> pts = GetRectCorners();
823 
824  // Account for the width of the lines
825  arect.Inflate( GetWidth() / 2 );
826  return ( arect.Intersects( pts[0], pts[1] )
827  || arect.Intersects( pts[1], pts[2] )
828  || arect.Intersects( pts[2], pts[3] )
829  || arect.Intersects( pts[3], pts[0] ) );
830  }
831 
832  case SHAPE_T::SEGMENT:
833  if( aContained )
834  {
835  return arect.Contains( GetStart() ) && aRect.Contains( GetEnd() );
836  }
837  else
838  {
839  // Account for the width of the line
840  arect.Inflate( GetWidth() / 2 );
841  return arect.Intersects( GetStart(), GetEnd() );
842  }
843 
844  case SHAPE_T::POLY:
845  if( aContained )
846  {
847  return arect.Contains( bb );
848  }
849  else
850  {
851  // Fast test: if aRect is outside the polygon bounding box,
852  // rectangles cannot intersect
853  if( !arect.Intersects( bb ) )
854  return false;
855 
856  // Account for the width of the line
857  arect.Inflate( GetWidth() / 2 );
858 
859  // Polygons in footprints use coordinates relative to the footprint.
860  // Therefore, instead of using m_poly, we make a copy which is translated
861  // to the actual location in the board.
862  double orientation = 0.0;
863  wxPoint offset = getParentPosition();
864 
865  if( getParentOrientation() )
866  orientation = -DECIDEG2RAD( getParentOrientation() );
867 
868  SHAPE_LINE_CHAIN poly = m_poly.Outline( 0 );
869  poly.Rotate( orientation );
870  poly.Move( offset );
871 
872  int count = poly.GetPointCount();
873 
874  for( int ii = 0; ii < count; ii++ )
875  {
876  VECTOR2I vertex = poly.GetPoint( ii );
877 
878  // Test if the point is within aRect
879  if( arect.Contains( ( wxPoint ) vertex ) )
880  return true;
881 
882  if( ii + 1 < count )
883  {
884  VECTOR2I vertexNext = poly.GetPoint( ii + 1 );
885 
886  // Test if this edge intersects aRect
887  if( arect.Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
888  return true;
889  }
890  else if( poly.IsClosed() )
891  {
892  VECTOR2I vertexNext = poly.GetPoint( 0 );
893 
894  // Test if this edge intersects aRect
895  if( arect.Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
896  return true;
897  }
898  }
899 
900  return false;
901  }
902 
903  case SHAPE_T::BEZIER:
904  if( aContained )
905  {
906  return arect.Contains( bb );
907  }
908  else
909  {
910  // Fast test: if aRect is outside the polygon bounding box,
911  // rectangles cannot intersect
912  if( !arect.Intersects( bb ) )
913  return false;
914 
915  // Account for the width of the line
916  arect.Inflate( GetWidth() / 2 );
917  unsigned count = m_bezierPoints.size();
918 
919  for( unsigned ii = 1; ii < count; ii++ )
920  {
921  wxPoint vertex = m_bezierPoints[ ii - 1];
922  wxPoint vertexNext = m_bezierPoints[ii];
923 
924  // Test if the point is within aRect
925  if( arect.Contains( ( wxPoint ) vertex ) )
926  return true;
927 
928  // Test if this edge intersects aRect
929  if( arect.Intersects( vertex, vertexNext ) )
930  return true;
931  }
932 
933  return false;
934  }
935 
936  default:
938  return false;
939  }
940 }
SHAPE_T m_shape
Definition: eda_shape.h:296
int GetWidth() const
Definition: eda_shape.h:89
virtual size_t GetPointCount() const override
wxPoint getCenter() const
Definition: eda_shape.cpp:393
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:97
void Move(const VECTOR2I &aVector) override
virtual wxPoint getParentPosition() const =0
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.
Definition: eda_rect.cpp:331
EDA_RECT Common(const EDA_RECT &aRect) const
Return the area that is common with another rectangle.
Definition: eda_rect.cpp:489
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
std::vector< wxPoint > GetRectCorners() const
Definition: eda_shape.cpp:943
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
bool IsClosed() const override
SHAPE_LINE_CHAIN & Outline(int aIndex)
std::vector< wxPoint > m_bezierPoints
Definition: eda_shape.h:307
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
virtual const VECTOR2I GetPoint(int aIndex) const override
void Rotate(double aAngle, const VECTOR2I &aCenter=VECTOR2I(0, 0)) override
Rotate all vertices by a given angle.
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
const EDA_RECT getBoundingBox() const
Definition: eda_shape.cpp:596
virtual double getParentOrientation() const =0
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Handle the component boundary box.
Definition: eda_rect.h:42
double DECIDEG2RAD(double deg)
Definition: trigo.h:233
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
Definition: eda_rect.cpp:150
int GetRadius() const
Definition: eda_shape.cpp:466
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364

References ARC, BEZIER, CIRCLE, EDA_RECT::Common(), EDA_RECT::Contains(), DECIDEG2RAD(), getBoundingBox(), getCenter(), GetEnd(), getParentOrientation(), getParentPosition(), SHAPE_LINE_CHAIN::GetPoint(), SHAPE_LINE_CHAIN::GetPointCount(), GetRadius(), GetRectCorners(), GetStart(), GetWidth(), EDA_RECT::Inflate(), EDA_RECT::Intersects(), EDA_RECT::IntersectsCircleEdge(), SHAPE_LINE_CHAIN::IsClosed(), m_bezierPoints, m_poly, m_shape, SHAPE_LINE_CHAIN::Move(), EDA_RECT::Normalize(), SHAPE_POLY_SET::Outline(), POLY, RECT, SHAPE_LINE_CHAIN::Rotate(), SEGMENT, SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

◆ IsFilled()

◆ IsPolyShapeValid()

bool EDA_SHAPE::IsPolyShapeValid ( ) const
Returns
true if the polygonal shape is valid (has more than 2 points)

Definition at line 1169 of file eda_shape.cpp.

1170 {
1171  // return true if the polygonal shape is valid (has more than 2 points)
1172  if( GetPolyShape().OutlineCount() == 0 )
1173  return false;
1174 
1175  const SHAPE_LINE_CHAIN& outline = ( (SHAPE_POLY_SET&)GetPolyShape() ).Outline( 0 );
1176 
1177  return outline.PointCount() > 2;
1178 }
int PointCount() const
Return the number of points (vertices) in this line chain.
Represent a set of closed polygons.
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:207
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...

References GetPolyShape(), and SHAPE_LINE_CHAIN::PointCount().

Referenced by PCB_PLUGIN::format(), BRDITEMS_PLOTTER::PlotFootprintGraphicItem(), BRDITEMS_PLOTTER::PlotPcbShape(), and TransformShapeWithClearanceToPolygon().

◆ MakeEffectiveShapes()

std::vector< SHAPE * > EDA_SHAPE::MakeEffectiveShapes ( ) const

Make a set of SHAPE objects representing the EDA_SHAPE.

Caller owns the objects.

Definition at line 1057 of file eda_shape.cpp.

1058 {
1059  std::vector<SHAPE*> effectiveShapes;
1060 
1061  switch( m_shape )
1062  {
1063  case SHAPE_T::ARC:
1064  effectiveShapes.emplace_back( new SHAPE_ARC( m_arcCenter, m_start, GetArcAngle() / 10.0,
1065  m_width ) );
1066  break;
1067 
1068  case SHAPE_T::SEGMENT:
1069  effectiveShapes.emplace_back( new SHAPE_SEGMENT( m_start, m_end, m_width ) );
1070  break;
1071 
1072  case SHAPE_T::RECT:
1073  {
1074  std::vector<wxPoint> pts = GetRectCorners();
1075 
1076  if( IsFilled() )
1077  effectiveShapes.emplace_back( new SHAPE_SIMPLE( pts ) );
1078 
1079  if( m_width > 0 || !IsFilled() )
1080  {
1081  effectiveShapes.emplace_back( new SHAPE_SEGMENT( pts[0], pts[1], m_width ) );
1082  effectiveShapes.emplace_back( new SHAPE_SEGMENT( pts[1], pts[2], m_width ) );
1083  effectiveShapes.emplace_back( new SHAPE_SEGMENT( pts[2], pts[3], m_width ) );
1084  effectiveShapes.emplace_back( new SHAPE_SEGMENT( pts[3], pts[0], m_width ) );
1085  }
1086  }
1087  break;
1088 
1089  case SHAPE_T::CIRCLE:
1090  {
1091  if( IsFilled() )
1092  effectiveShapes.emplace_back( new SHAPE_CIRCLE( getCenter(), GetRadius() ) );
1093 
1094  if( m_width > 0 || !IsFilled() )
1095  {
1096  // SHAPE_CIRCLE has no ConvertToPolyline() method, so use a 360.0 SHAPE_ARC
1097  SHAPE_ARC circle( getCenter(), GetEnd(), 360.0 );
1098  SHAPE_LINE_CHAIN l = circle.ConvertToPolyline();
1099 
1100  for( int i = 0; i < l.SegmentCount(); i++ )
1101  {
1102  effectiveShapes.emplace_back( new SHAPE_SEGMENT( l.Segment( i ).A, l.Segment( i ).B,
1103  m_width ) );
1104  }
1105  }
1106 
1107  break;
1108  }
1109 
1110  case SHAPE_T::BEZIER:
1111  {
1112  auto bezierPoints = buildBezierToSegmentsPointsList( GetWidth() );
1113  wxPoint start_pt = bezierPoints[0];
1114 
1115  for( unsigned int jj = 1; jj < bezierPoints.size(); jj++ )
1116  {
1117  wxPoint end_pt = bezierPoints[jj];
1118  effectiveShapes.emplace_back( new SHAPE_SEGMENT( start_pt, end_pt, m_width ) );
1119  start_pt = end_pt;
1120  }
1121 
1122  break;
1123  }
1124 
1125  case SHAPE_T::POLY:
1126  {
1128 
1130  l.Move( getParentPosition() );
1131 
1132  if( IsFilled() )
1133  effectiveShapes.emplace_back( new SHAPE_SIMPLE( l ) );
1134 
1135  if( m_width > 0 || !IsFilled() )
1136  {
1137  for( int i = 0; i < l.SegmentCount(); i++ )
1138  effectiveShapes.emplace_back( new SHAPE_SEGMENT( l.Segment( i ), m_width ) );
1139  }
1140  }
1141  break;
1142 
1143  default:
1145  break;
1146  }
1147 
1148  return effectiveShapes;
1149 }
SHAPE_T m_shape
Definition: eda_shape.h:296
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
Definition: shape_simple.h:41
int GetWidth() const
Definition: eda_shape.h:89
wxPoint getCenter() const
Definition: eda_shape.cpp:393
void Move(const VECTOR2I &aVector) override
double GetArcAngle() const
Definition: eda_shape.cpp:498
virtual wxPoint getParentPosition() const =0
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
bool IsFilled() const
Definition: eda_shape.h:81
std::vector< wxPoint > GetRectCorners() const
Definition: eda_shape.cpp:943
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
const std::vector< wxPoint > buildBezierToSegmentsPointsList(int aMinSegLen) const
Definition: eda_shape.cpp:380
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
int SegmentCount() const
Return the number of segments in this line chain.
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:207
wxPoint m_start
Definition: eda_shape.h:299
void Rotate(double aAngle, const VECTOR2I &aCenter=VECTOR2I(0, 0)) override
Rotate all vertices by a given angle.
SEG Segment(int aIndex)
Return a copy of the aIndex-th segment in the line chain.
virtual double getParentOrientation() const =0
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
VECTOR2I A
Definition: seg.h:48
double DECIDEG2RAD(double deg)
Definition: trigo.h:233
int m_width
Definition: eda_shape.h:297
int GetRadius() const
Definition: eda_shape.cpp:466
VECTOR2I B
Definition: seg.h:49

References SEG::A, ARC, SEG::B, BEZIER, buildBezierToSegmentsPointsList(), CIRCLE, SHAPE_ARC::ConvertToPolyline(), SHAPE_POLY_SET::COutline(), DECIDEG2RAD(), GetArcAngle(), getCenter(), GetEnd(), getParentOrientation(), getParentPosition(), GetPolyShape(), GetRadius(), GetRectCorners(), GetWidth(), IsFilled(), m_arcCenter, m_end, m_shape, m_start, m_width, SHAPE_LINE_CHAIN::Move(), POLY, RECT, SHAPE_LINE_CHAIN::Rotate(), SEGMENT, SHAPE_LINE_CHAIN::Segment(), SHAPE_LINE_CHAIN::SegmentCount(), SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by PCB_SHAPE::GetEffectiveShape(), and PNS_KICAD_IFACE_BASE::syncGraphicalItem().

◆ move()

void EDA_SHAPE::move ( const wxPoint &  aMoveVector)
protected

Definition at line 137 of file eda_shape.cpp.

138 {
139  switch ( m_shape )
140  {
141  case SHAPE_T::ARC:
142  case SHAPE_T::SEGMENT:
143  case SHAPE_T::RECT:
144  case SHAPE_T::CIRCLE:
145  m_start += aMoveVector;
146  m_end += aMoveVector;
147  m_arcCenter += aMoveVector;
148  break;
149 
150  case SHAPE_T::POLY:
151  m_poly.Move( VECTOR2I( aMoveVector ) );
152  break;
153 
154  case SHAPE_T::BEZIER:
155  m_start += aMoveVector;
156  m_end += aMoveVector;
157  m_bezierC1 += aMoveVector;
158  m_bezierC2 += aMoveVector;
159 
160  for( wxPoint& pt : m_bezierPoints)
161  pt += aMoveVector;
162 
163  break;
164 
165  default:
167  break;
168  }
169 }
SHAPE_T m_shape
Definition: eda_shape.h:296
wxPoint m_bezierC1
Definition: eda_shape.h:304
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
wxPoint m_bezierC2
Definition: eda_shape.h:305
void Move(const VECTOR2I &aVector) override
std::vector< wxPoint > m_bezierPoints
Definition: eda_shape.h:307
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
wxPoint m_start
Definition: eda_shape.h:299

References ARC, BEZIER, CIRCLE, m_arcCenter, m_bezierC1, m_bezierC2, m_bezierPoints, m_end, m_poly, m_shape, m_start, SHAPE_POLY_SET::Move(), POLY, RECT, SEGMENT, SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by PCB_SHAPE::Move(), LIB_SHAPE::Offset(), and setPosition().

◆ RebuildBezierToSegmentsPointsList()

void EDA_SHAPE::RebuildBezierToSegmentsPointsList ( int  aMinSegLen)

Rebuild the m_BezierPoints vertex list that approximate the Bezier curve by a list of segments.

Has meaning only for BEZIER shape.

Parameters
aMinSegLenis the min length of segments approximating the bezier. The shape's last segment can be shorter. This parameter avoids having too many very short segment in list. Good values are between m_width/2 and m_width.

Definition at line 366 of file eda_shape.cpp.

367 {
368  // Has meaning only for S_CURVE DRAW_SEGMENT shape
369  if( m_shape != SHAPE_T::BEZIER )
370  {
371  m_bezierPoints.clear();
372  return;
373  }
374 
375  // Rebuild the m_BezierPoints vertex list that approximate the Bezier curve
377 }
SHAPE_T m_shape
Definition: eda_shape.h:296
std::vector< wxPoint > m_bezierPoints
Definition: eda_shape.h:307
const std::vector< wxPoint > buildBezierToSegmentsPointsList(int aMinSegLen) const
Definition: eda_shape.cpp:380

References BEZIER, buildBezierToSegmentsPointsList(), m_bezierPoints, and m_shape.

Referenced by ConvertOutlineToPolygon(), FP_SHAPE::Flip(), GRAPHICS_CLEANER::isNullShape(), SCH_LEGACY_PLUGIN_CACHE::loadBezier(), FP_SHAPE::Mirror(), FP_SHAPE::SetDrawCoord(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), and PCB_POINT_EDITOR::updateItem().

◆ rotate()

void EDA_SHAPE::rotate ( const wxPoint &  aRotCentre,
double  aAngle 
)
protected

Definition at line 224 of file eda_shape.cpp.

225 {
226  switch( m_shape )
227  {
228  case SHAPE_T::SEGMENT:
229  case SHAPE_T::CIRCLE:
230  RotatePoint( &m_start, aRotCentre, aAngle );
231  RotatePoint( &m_end, aRotCentre, aAngle );
232  break;
233 
234  case SHAPE_T::ARC:
235  RotatePoint( &m_start, aRotCentre, aAngle );
236  RotatePoint( &m_end, aRotCentre, aAngle );
237  RotatePoint( &m_arcCenter, aRotCentre, aAngle );
238  break;
239 
240  case SHAPE_T::RECT:
241  if( KiROUND( aAngle ) % 900 == 0 )
242  {
243  RotatePoint( &m_start, aRotCentre, aAngle );
244  RotatePoint( &m_end, aRotCentre, aAngle );
245  break;
246  }
247 
248  // Convert non-cartesian-rotated rect to a diamond
251  m_poly.NewOutline();
252  m_poly.Append( m_start );
253  m_poly.Append( m_end.x, m_start.y );
254  m_poly.Append( m_end );
255  m_poly.Append( m_start.x, m_end.y );
256 
258 
259  case SHAPE_T::POLY:
260  m_poly.Rotate( -DECIDEG2RAD( aAngle ), VECTOR2I( aRotCentre ) );
261  break;
262 
263  case SHAPE_T::BEZIER:
264  RotatePoint( &m_start, aRotCentre, aAngle);
265  RotatePoint( &m_end, aRotCentre, aAngle);
266  RotatePoint( &m_bezierC1, aRotCentre, aAngle);
267  RotatePoint( &m_bezierC2, aRotCentre, aAngle);
268 
269  for( wxPoint& pt : m_bezierPoints )
270  RotatePoint( &pt, aRotCentre, aAngle);
271 
272  break;
273 
274  default:
276  break;
277  }
278 }
SHAPE_T m_shape
Definition: eda_shape.h:296
wxPoint m_bezierC1
Definition: eda_shape.h:304
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
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)
Definition: trigo.cpp:229
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
wxPoint m_bezierC2
Definition: eda_shape.h:305
std::vector< wxPoint > m_bezierPoints
Definition: eda_shape.h:307
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
int NewOutline()
Creates a new hole in a given outline.
wxPoint m_start
Definition: eda_shape.h:299
double DECIDEG2RAD(double deg)
Definition: trigo.h:233
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
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...

References SHAPE_POLY_SET::Append(), ARC, BEZIER, CIRCLE, DECIDEG2RAD(), KI_FALLTHROUGH, KiROUND(), m_arcCenter, m_bezierC1, m_bezierC2, m_bezierPoints, m_end, m_poly, m_shape, m_start, SHAPE_POLY_SET::NewOutline(), POLY, RECT, SHAPE_POLY_SET::RemoveAllContours(), SHAPE_POLY_SET::Rotate(), RotatePoint(), SEGMENT, SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by LIB_SHAPE::Rotate(), and PCB_SHAPE::Rotate().

◆ scale()

void EDA_SHAPE::scale ( double  aScale)
protected

Definition at line 172 of file eda_shape.cpp.

173 {
174  auto scalePt = [&]( wxPoint& pt )
175  {
176  pt.x = KiROUND( pt.x * aScale );
177  pt.y = KiROUND( pt.y * aScale );
178  };
179 
180  switch( m_shape )
181  {
182  case SHAPE_T::ARC:
183  case SHAPE_T::SEGMENT:
184  case SHAPE_T::RECT:
185  scalePt( m_start );
186  scalePt( m_end );
187  scalePt( m_arcCenter );
188  break;
189 
190  case SHAPE_T::CIRCLE: // ring or circle
191  scalePt( m_start );
192  m_end.x = m_start.x + KiROUND( GetRadius() * aScale );
193  m_end.y = m_start.y;
194  break;
195 
196  case SHAPE_T::POLY: // polygon
197  {
198  std::vector<wxPoint> pts;
199 
200  for( const VECTOR2I& pt : m_poly.Outline( 0 ).CPoints() )
201  {
202  pts.emplace_back( pt );
203  scalePt( pts.back() );
204  }
205 
206  SetPolyPoints( pts );
207  }
208  break;
209 
210  case SHAPE_T::BEZIER:
211  scalePt( m_start );
212  scalePt( m_end );
213  scalePt( m_bezierC1 );
214  scalePt( m_bezierC2 );
215  break;
216 
217  default:
219  break;
220  }
221 }
SHAPE_T m_shape
Definition: eda_shape.h:296
wxPoint m_bezierC1
Definition: eda_shape.h:304
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
wxPoint m_bezierC2
Definition: eda_shape.h:305
const std::vector< VECTOR2I > & CPoints() const
SHAPE_LINE_CHAIN & Outline(int aIndex)
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
wxPoint m_start
Definition: eda_shape.h:299
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
Definition: eda_shape.cpp:1047
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
int GetRadius() const
Definition: eda_shape.cpp:466

References ARC, BEZIER, CIRCLE, SHAPE_LINE_CHAIN::CPoints(), GetRadius(), KiROUND(), m_arcCenter, m_bezierC1, m_bezierC2, m_end, m_poly, m_shape, m_start, SHAPE_POLY_SET::Outline(), POLY, RECT, SEGMENT, SetPolyPoints(), SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by PCB_SHAPE::Scale().

◆ SetArcAngleAndEnd()

void EDA_SHAPE::SetArcAngleAndEnd ( double  aAngle,
bool  aCheckNegativeAngle = false 
)

Set the end point from the angle center and start.

Parameters
aAngleis tenths of degrees.

Definition at line 509 of file eda_shape.cpp.

510 {
511  m_end = m_start;
513 
514  if( aCheckNegativeAngle && aAngle < 0 )
515  {
516  std::swap( m_start, m_end );
517  m_endsSwapped = true;
518  }
519 }
T NormalizeAngle360Max(T Angle)
Normalize angle to be >=-360.0 and <= 360.0 Angle can be equal to -360 or +360.
Definition: trigo.h:241
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
bool m_endsSwapped
Definition: eda_shape.h:295
wxPoint m_start
Definition: eda_shape.h:299

References m_arcCenter, m_end, m_endsSwapped, m_start, NormalizeAngle360Max(), and RotatePoint().

Referenced by PAD::AddPrimitiveArc(), PCAD2KICAD::PCB_ARC::AddToBoard(), DRAWING_TOOL::drawArc(), CADSTAR_PCB_ARCHIVE_LOADER::getShapeFromVertex(), ALTIUM_PCB::HelperCreateBoardOutline(), EAGLE_PLUGIN::loadPlain(), ALTIUM_PCB::ParseArcs6Data(), and DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataFromWindow().

◆ SetArcGeometry()

void EDA_SHAPE::SetArcGeometry ( const wxPoint &  aStart,
const wxPoint &  aMid,
const wxPoint &  aEnd 
)

Set the three controlling points for an arc.

NB: these are NOT what's currently stored, so we have to do some calculations behind the scenes. However, they are what SHOULD be stored.

Definition at line 489 of file eda_shape.cpp.

490 {
491  m_start = aStart;
492  m_end = aEnd;
493  m_arcCenter = CalcArcCenter( aStart, aMid, aEnd );
494  m_endsSwapped = false;
495 }
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
bool m_endsSwapped
Definition: eda_shape.h:295
wxPoint m_start
Definition: eda_shape.h:299
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.
Definition: trigo.cpp:454

References CalcArcCenter(), m_arcCenter, m_end, m_endsSwapped, and m_start.

Referenced by beginEdit(), calcEdit(), PCB_POINT_EDITOR::editArcMidKeepEndpoints(), and SCH_EAGLE_PLUGIN::loadSymbolWire().

◆ SetBezierC1()

◆ SetBezierC2()

◆ SetBezierPoints()

void EDA_SHAPE::SetBezierPoints ( const std::vector< wxPoint > &  aPoints)
inline

Definition at line 217 of file eda_shape.h.

217 { m_bezierPoints = aPoints; }
std::vector< wxPoint > m_bezierPoints
Definition: eda_shape.h:307

References m_bezierPoints.

◆ SetCenter()

◆ setEditState()

void EDA_SHAPE::setEditState ( int  aState)
inlineprotected

Definition at line 292 of file eda_shape.h.

292 { m_editState = aState; }
int m_editState
Definition: eda_shape.h:310

References m_editState.

Referenced by LIB_SHAPE::SetEditState().

◆ SetEnd()

void EDA_SHAPE::SetEnd ( const wxPoint &  aEnd)
inline

Definition at line 126 of file eda_shape.h.

127  {
128  m_end = aEnd;
129  m_endsSwapped = false;
130  }
wxPoint m_end
Definition: eda_shape.h:300
bool m_endsSwapped
Definition: eda_shape.h:295

References m_end, and m_endsSwapped.

Referenced by PCB_POINT_EDITOR::addCorner(), PAD::AddPrimitiveCircle(), PAD::AddPrimitiveCurve(), PAD::AddPrimitiveRect(), PAD::AddPrimitiveSegment(), PCAD2KICAD::PCB_LINE::AddToBoard(), beginEdit(), calcEdit(), CONVERT_TOOL::CreateLines(), MICROWAVE_TOOL::createMicrowaveInductor(), PCB_POINT_EDITOR::editArcEndpointKeepCenter(), PCB_POINT_EDITOR::editArcEndpointKeepTangent(), PCB_POINT_EDITOR::editArcMidKeepCenter(), PAD_TOOL::explodePad(), CADSTAR_SCH_ARCHIVE_LOADER::getScaledLibPart(), CADSTAR_PCB_ARCHIVE_LOADER::getShapeFromVertex(), ALTIUM_PCB::HelperCreateBoardOutline(), HelperGeneratePowerPortGraphics(), ALTIUM_PCB::HelperParseDimensions6Leader(), ALTIUM_PCB::HelperParsePad6NonCopper(), SCH_LEGACY_PLUGIN_CACHE::loadArc(), SCH_LEGACY_PLUGIN_CACHE::loadBezier(), SCH_LEGACY_PLUGIN_CACHE::loadCircle(), CADSTAR_SCH_ARCHIVE_LOADER::loadLibrarySymbolShapeVertices(), EAGLE_PLUGIN::loadPlain(), SCH_LEGACY_PLUGIN_CACHE::loadRect(), SCH_EAGLE_PLUGIN::loadSymbolCircle(), SCH_EAGLE_PLUGIN::loadSymbolRectangle(), GRAPHICS_CLEANER::mergeRects(), SCH_ALTIUM_PLUGIN::ParseArc(), ALTIUM_PCB::ParseArcs6Data(), SCH_ALTIUM_PLUGIN::ParseBezier(), SCH_ALTIUM_PLUGIN::ParseRectangle(), SCH_ALTIUM_PLUGIN::ParseRoundRectangle(), ALTIUM_PCB::ParseTracks6Data(), BRDITEMS_PLOTTER::PlotDimension(), BRDITEMS_PLOTTER::PlotPcbTarget(), PAD_TOOL::recombinePad(), CONVERT_TOOL::SegmentToArc(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataFromWindow(), updateArcFromConstructionMgr(), PCB_POINT_EDITOR::updateItem(), EE_POINT_EDITOR::updateParentItem(), and updateSegmentFromGeometryMgr().

◆ SetEndX()

◆ SetEndY()

◆ SetFilled()

◆ SetFillMode()

◆ SetPolyPoints()

void EDA_SHAPE::SetPolyPoints ( const std::vector< wxPoint > &  aPoints)

Definition at line 1047 of file eda_shape.cpp.

1048 {
1050  m_poly.NewOutline();
1051 
1052  for ( const wxPoint& p : aPoints )
1053  m_poly.Append( p.x, p.y );
1054 }
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
int NewOutline()
Creates a new hole in a given outline.
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...

References SHAPE_POLY_SET::Append(), m_poly, SHAPE_POLY_SET::NewOutline(), and SHAPE_POLY_SET::RemoveAllContours().

Referenced by PAD::AddPrimitivePoly(), PCAD2KICAD::PCB_POLYGON::AddToFootprint(), MICROWAVE_TOOL::createPolygonShape(), ALTIUM_PCB::HelperParsePad6NonCopper(), EAGLE_PLUGIN::packagePolygon(), EAGLE_PLUGIN::packageRectangle(), ALTIUM_PCB::ParseFills6Data(), scale(), and DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataFromWindow().

◆ SetPolyShape()

◆ setPosition()

void EDA_SHAPE::setPosition ( const wxPoint &  aPos)
protected

Definition at line 89 of file eda_shape.cpp.

90 {
91  move( aPos - getPosition() );
92 }
void move(const wxPoint &aMoveVector)
Definition: eda_shape.cpp:137
wxPoint getPosition() const
Definition: eda_shape.cpp:95

References getPosition(), and move().

Referenced by LIB_SHAPE::MoveTo(), PCB_SHAPE::SetPosition(), and LIB_SHAPE::SetPosition().

◆ SetShape()

◆ SetStart()

void EDA_SHAPE::SetStart ( const wxPoint &  aStart)
inline

Definition at line 101 of file eda_shape.h.

102  {
103  m_start = aStart;
104  m_endsSwapped = false;
105  }
bool m_endsSwapped
Definition: eda_shape.h:295
wxPoint m_start
Definition: eda_shape.h:299

References m_endsSwapped, and m_start.

Referenced by PCB_POINT_EDITOR::addCorner(), PAD::AddPrimitiveArc(), PAD::AddPrimitiveCircle(), PAD::AddPrimitiveCurve(), PAD::AddPrimitiveRect(), PAD::AddPrimitiveSegment(), PCAD2KICAD::PCB_ARC::AddToBoard(), PCAD2KICAD::PCB_LINE::AddToBoard(), beginEdit(), CONVERT_TOOL::CreateLines(), MICROWAVE_TOOL::createMicrowaveInductor(), PCB_POINT_EDITOR::editArcEndpointKeepCenter(), PCB_POINT_EDITOR::editArcEndpointKeepTangent(), PCB_POINT_EDITOR::editArcMidKeepCenter(), PAD_TOOL::explodePad(), CADSTAR_SCH_ARCHIVE_LOADER::getScaledLibPart(), CADSTAR_PCB_ARCHIVE_LOADER::getShapeFromVertex(), ALTIUM_PCB::HelperCreateBoardOutline(), ALTIUM_PCB::HelperParseDimensions6Datum(), ALTIUM_PCB::HelperParseDimensions6Leader(), ALTIUM_PCB::HelperParsePad6NonCopper(), SCH_LEGACY_PLUGIN_CACHE::loadArc(), SCH_LEGACY_PLUGIN_CACHE::loadBezier(), SCH_LEGACY_PLUGIN_CACHE::loadCircle(), CADSTAR_SCH_ARCHIVE_LOADER::loadLibrarySymbolShapeVertices(), EAGLE_PLUGIN::loadPlain(), GRAPHICS_CLEANER::mergeRects(), SCH_ALTIUM_PLUGIN::ParseArc(), ALTIUM_PCB::ParseArcs6Data(), SCH_ALTIUM_PLUGIN::ParseBezier(), ALTIUM_PCB::ParseTracks6Data(), BRDITEMS_PLOTTER::PlotDimension(), BRDITEMS_PLOTTER::PlotPcbTarget(), PAD_TOOL::recombinePad(), CONVERT_TOOL::SegmentToArc(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataFromWindow(), updateArcFromConstructionMgr(), PCB_POINT_EDITOR::updateItem(), and updateSegmentFromGeometryMgr().

◆ SetStartX()

void EDA_SHAPE::SetStartX ( int  x)
inline

◆ SetStartY()

void EDA_SHAPE::SetStartY ( int  y)
inline

◆ SetWidth()

void EDA_SHAPE::SetWidth ( int  aWidth)
inline

Definition at line 88 of file eda_shape.h.

88 { m_width = aWidth; }
int m_width
Definition: eda_shape.h:297

References m_width.

Referenced by PAD::AddPrimitiveArc(), PAD::AddPrimitiveCircle(), PAD::AddPrimitiveCurve(), PAD::AddPrimitivePoly(), PAD::AddPrimitiveRect(), PAD::AddPrimitiveSegment(), PCAD2KICAD::PCB_ARC::AddToBoard(), PCAD2KICAD::PCB_LINE::AddToBoard(), PCAD2KICAD::PCB_ARC::AddToFootprint(), PCAD2KICAD::PCB_LINE::AddToFootprint(), PCAD2KICAD::PCB_POLYGON::AddToFootprint(), ZONE_CREATE_HELPER::commitZone(), MICROWAVE_TOOL::createMicrowaveInductor(), MICROWAVE_TOOL::createPolygonShape(), CONVERT_TOOL::CreatePolys(), PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems(), DRAWING_TOOL::drawArc(), CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarShape(), EDA_SHAPE_DESC::EDA_SHAPE_DESC(), PAD_TOOL::explodePad(), CADSTAR_PCB_ARCHIVE_LOADER::getKiCadPad(), ALTIUM_PCB::HelperCreateBoardOutline(), HelperGeneratePowerPortGraphics(), ALTIUM_PCB::HelperParseDimensions6Datum(), ALTIUM_PCB::HelperParseDimensions6Leader(), ALTIUM_PCB::HelperParsePad6NonCopper(), SCH_LEGACY_PLUGIN_CACHE::loadArc(), SCH_LEGACY_PLUGIN_CACHE::loadBezier(), SCH_LEGACY_PLUGIN_CACHE::loadCircle(), FABMASTER::loadGraphics(), CADSTAR_SCH_ARCHIVE_LOADER::loadLibrarySymbolShapeVertices(), CADSTAR_PCB_ARCHIVE_LOADER::loadNetTracks(), EAGLE_PLUGIN::loadPlain(), FABMASTER::loadPolygon(), SCH_LEGACY_PLUGIN_CACHE::loadPolyLine(), SCH_LEGACY_PLUGIN_CACHE::loadRect(), SCH_EAGLE_PLUGIN::loadSymbolCircle(), SCH_EAGLE_PLUGIN::loadSymbolWire(), GRAPHICS_CLEANER::mergeRects(), DIALOG_PAD_PROPERTIES::onAddPrimitive(), EAGLE_PLUGIN::packageCircle(), EAGLE_PLUGIN::packagePolygon(), EAGLE_PLUGIN::packageRectangle(), EAGLE_PLUGIN::packageWire(), SCH_ALTIUM_PLUGIN::ParseArc(), ALTIUM_PCB::ParseArcs6Data(), SCH_ALTIUM_PLUGIN::ParseBezier(), ALTIUM_PCB::ParseFills6Data(), GPCB_FPL_CACHE::parseFOOTPRINT(), SCH_ALTIUM_PLUGIN::ParseLine(), SCH_ALTIUM_PLUGIN::ParsePolygon(), SCH_ALTIUM_PLUGIN::ParsePolyline(), SCH_ALTIUM_PLUGIN::ParseRectangle(), SCH_ALTIUM_PLUGIN::ParseRoundRectangle(), ALTIUM_PCB::ParseShapeBasedRegions6Data(), ALTIUM_PCB::ParseTracks6Data(), PCB_SHAPE_DESC::PCB_SHAPE_DESC(), BRDITEMS_PLOTTER::PlotDimension(), BRDITEMS_PLOTTER::PlotPcbTarget(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), PAD_TOOL::recombinePad(), CONVERT_TOOL::SegmentToArc(), DIALOG_LIB_SHAPE_PROPERTIES::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), DIALOG_PAD_PRIMITIVES_PROPERTIES::TransferDataFromWindow(), and DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataFromWindow().

◆ SHAPE_T_asString()

wxString EDA_SHAPE::SHAPE_T_asString ( ) const

Definition at line 71 of file eda_shape.cpp.

72 {
73  switch( m_shape )
74  {
75  case SHAPE_T::SEGMENT: return "S_SEGMENT";
76  case SHAPE_T::RECT: return "S_RECT";
77  case SHAPE_T::ARC: return "S_ARC";
78  case SHAPE_T::CIRCLE: return "S_CIRCLE";
79  case SHAPE_T::POLY: return "S_POLYGON";
80  case SHAPE_T::BEZIER: return "S_CURVE";
81  case SHAPE_T::LAST: return "!S_LAST!"; // Synthetic value, but if we come across it then
82  // we're going to want to know.
83  }
84 
85  return wxEmptyString; // Just to quiet GCC.
86 }
SHAPE_T m_shape
Definition: eda_shape.h:296
marker for list end

References ARC, BEZIER, CIRCLE, LAST, m_shape, POLY, RECT, and SEGMENT.

Referenced by LIB_SHAPE::AddPoint(), BOARD_ADAPTER::addShapeWithClearance(), GRAPHICS_CLEANER::areEquivalent(), beginEdit(), calcEdit(), continueEdit(), ConvertOutlineToPolygon(), KIGFX::SCH_PAINTER::draw(), endEdit(), PAD_TOOL::explodePad(), FP_SHAPE::Flip(), flip(), PCB_PLUGIN::format(), getBoundingBox(), getCenter(), FP_SHAPE::GetCenter0(), GetLength(), LIB_SHAPE::GetMenuImage(), GetRadius(), LIB_SHAPE::GetSelectMenuText(), hitTest(), GRAPHICS_CLEANER::isNullShape(), EDIT_POINTS_FACTORY::Make(), MakeEffectiveShapes(), FP_SHAPE::Mirror(), FP_SHAPE::Move(), move(), LIB_SHAPE::Plot(), BRDITEMS_PLOTTER::PlotPcbShape(), LIB_SHAPE::print(), PAD_TOOL::recombinePad(), rotate(), SCH_SEXPR_PLUGIN_CACHE::saveSymbolDrawItem(), scale(), SetCenter(), FP_SHAPE::SetCenter0(), TransformShapeWithClearanceToPolygon(), EE_POINT_EDITOR::updateParentItem(), EE_POINT_EDITOR::updatePoints(), and DIALOG_GRAPHIC_ITEM_PROPERTIES::Validate().

◆ ShapeGetMsgPanelInfo()

void EDA_SHAPE::ShapeGetMsgPanelInfo ( EDA_DRAW_FRAME aFrame,
std::vector< MSG_PANEL_ITEM > &  aList 
)

Definition at line 522 of file eda_shape.cpp.

523 {
524  EDA_UNITS units = aFrame->GetUserUnits();
525  ORIGIN_TRANSFORMS originTransforms = aFrame->GetOriginTransforms();
526  wxString msg;
527 
528  wxString shape = _( "Shape" );
529 
530  switch( m_shape )
531  {
532  case SHAPE_T::CIRCLE:
533  aList.emplace_back( shape, _( "Circle" ) );
534 
535  msg = MessageTextFromValue( units, GetRadius() );
536  aList.emplace_back( _( "Radius" ), msg );
537  break;
538 
539  case SHAPE_T::ARC:
540  aList.emplace_back( shape, _( "Arc" ) );
541 
542  msg.Printf( wxT( "%.1f" ), GetArcAngle() / 10.0 );
543  aList.emplace_back( _( "Angle" ), msg );
544 
545  msg = MessageTextFromValue( units, GetRadius() );
546  aList.emplace_back( _( "Radius" ), msg );
547  break;
548 
549  case SHAPE_T::BEZIER:
550  aList.emplace_back( shape, _( "Curve" ) );
551 
552  msg = MessageTextFromValue( units, GetLength() );
553  aList.emplace_back( _( "Length" ), msg );
554  break;
555 
556  case SHAPE_T::POLY:
557  aList.emplace_back( shape, _( "Polygon" ) );
558 
559  msg.Printf( "%d", GetPolyShape().Outline(0).PointCount() );
560  aList.emplace_back( _( "Points" ), msg );
561  break;
562 
563  case SHAPE_T::RECT:
564  aList.emplace_back( shape, _( "Rectangle" ) );
565 
566  msg = MessageTextFromValue( units, std::abs( GetEnd().x - GetStart().x ) );
567  aList.emplace_back( _( "Width" ), msg );
568 
569  msg = MessageTextFromValue( units, std::abs( GetEnd().y - GetStart().y ) );
570  aList.emplace_back( _( "Height" ), msg );
571  break;
572 
573  case SHAPE_T::SEGMENT:
574  {
575  aList.emplace_back( shape, _( "Segment" ) );
576 
577  msg = MessageTextFromValue( units, GetLineLength( GetStart(), GetEnd() ) );
578  aList.emplace_back( _( "Length" ), msg );
579 
580  // angle counter-clockwise from 3'o-clock
581  const double deg = RAD2DEG( atan2( (double)( GetStart().y - GetEnd().y ),
582  (double)( GetEnd().x - GetStart().x ) ) );
583  aList.emplace_back( _( "Angle" ), wxString::Format( "%.1f", deg ) );
584  }
585  break;
586 
587  default:
588  aList.emplace_back( shape, _( "Unrecognized" ) );
589  break;
590  }
591 
592  aList.emplace_back( _( "Line width" ), MessageTextFromValue( units, m_width ) );
593 }
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:104
SHAPE_T m_shape
Definition: eda_shape.h:296
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:222
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:97
double RAD2DEG(double rad)
Definition: trigo.h:230
double GetArcAngle() const
Definition: eda_shape.cpp:498
virtual ORIGIN_TRANSFORMS & GetOriginTransforms()
Return a reference to the default ORIGIN_TRANSFORMS object.
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
double GetLength() const
Return the length of the track using the hypotenuse calculation.
Definition: eda_shape.cpp:106
#define _(s)
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:207
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
EDA_UNITS
Definition: eda_units.h:38
A class to perform either relative or absolute display origin transforms for a single axis of a point...
int m_width
Definition: eda_shape.h:297
int GetRadius() const
Definition: eda_shape.cpp:466
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References _, ARC, BEZIER, CIRCLE, Format(), GetArcAngle(), GetEnd(), GetLength(), GetLineLength(), EDA_DRAW_FRAME::GetOriginTransforms(), GetPolyShape(), GetRadius(), GetStart(), EDA_BASE_FRAME::GetUserUnits(), m_shape, m_width, MessageTextFromValue(), POLY, RAD2DEG(), RECT, and SEGMENT.

Referenced by LIB_SHAPE::GetMsgPanelInfo(), and PCB_SHAPE::GetMsgPanelInfo().

◆ ShowShape()

wxString EDA_SHAPE::ShowShape ( ) const

Definition at line 56 of file eda_shape.cpp.

57 {
58  switch( m_shape )
59  {
60  case SHAPE_T::SEGMENT: return _( "Line" );
61  case SHAPE_T::RECT: return _( "Rect" );
62  case SHAPE_T::ARC: return _( "Arc" );
63  case SHAPE_T::CIRCLE: return _( "Circle" );
64  case SHAPE_T::BEZIER: return _( "Bezier Curve" );
65  case SHAPE_T::POLY: return _( "Polygon" );
66  default: return wxT( "??" );
67  }
68 }
SHAPE_T m_shape
Definition: eda_shape.h:296
#define _(s)

References _, ARC, BEZIER, CIRCLE, m_shape, POLY, RECT, and SEGMENT.

Referenced by PCB_SHAPE::GetSelectMenuText(), FP_SHAPE::GetSelectMenuText(), and LIB_SHAPE::GetTypeName().

◆ SwapShape()

void EDA_SHAPE::SwapShape ( EDA_SHAPE aImage)

Definition at line 1407 of file eda_shape.cpp.

1408 {
1409  EDA_SHAPE* image = dynamic_cast<EDA_SHAPE*>( aImage );
1410  assert( image );
1411 
1412  std::swap( m_width, image->m_width );
1413  std::swap( m_start, image->m_start );
1414  std::swap( m_end, image->m_end );
1415  std::swap( m_arcCenter, image->m_arcCenter );
1416  std::swap( m_shape, image->m_shape );
1417  std::swap( m_bezierC1, image->m_bezierC1 );
1418  std::swap( m_bezierC2, image->m_bezierC2 );
1419  std::swap( m_bezierPoints, image->m_bezierPoints );
1420  std::swap( m_poly, image->m_poly );
1421 }
SHAPE_T m_shape
Definition: eda_shape.h:296
wxPoint m_bezierC1
Definition: eda_shape.h:304
wxPoint m_end
Definition: eda_shape.h:300
wxPoint m_arcCenter
Definition: eda_shape.h:302
wxPoint m_bezierC2
Definition: eda_shape.h:305
std::vector< wxPoint > m_bezierPoints
Definition: eda_shape.h:307
SHAPE_POLY_SET m_poly
Definition: eda_shape.h:308
wxPoint m_start
Definition: eda_shape.h:299
int m_width
Definition: eda_shape.h:297

References image, m_arcCenter, m_bezierC1, m_bezierC2, m_bezierPoints, m_end, m_poly, m_shape, m_start, and m_width.

Referenced by PCB_SHAPE::SwapData().

◆ TransformShapeWithClearanceToPolygon()

void EDA_SHAPE::TransformShapeWithClearanceToPolygon ( SHAPE_POLY_SET aCornerBuffer,
int  aClearanceValue,
int  aError,
ERROR_LOC  aErrorLoc,
bool  ignoreLineWidth 
) const

Convert the shape to a closed polygon.

Used in filling zones calculations. Circles and arcs are approximated by segments.

Parameters
aCornerBufferis a buffer to store the polygon.
aClearanceValueis the clearance around the pad.
aErroris the maximum deviation from a true arc.
aErrorLocwhether any approximation error shoule be placed inside or outside
ignoreLineWidthis used for edge cut items where the line width is only for visualization

Definition at line 1461 of file eda_shape.cpp.

1465 {
1466  int width = ignoreLineWidth ? 0 : m_width;
1467 
1468  width += 2 * aClearanceValue;
1469 
1470  switch( m_shape )
1471  {
1472  case SHAPE_T::CIRCLE:
1473  if( IsFilled() )
1474  {
1475  TransformCircleToPolygon( aCornerBuffer, getCenter(), GetRadius() + width / 2, aError,
1476  aErrorLoc );
1477  }
1478  else
1479  {
1480  TransformRingToPolygon( aCornerBuffer, getCenter(), GetRadius(), width, aError,
1481  aErrorLoc );
1482  }
1483 
1484  break;
1485 
1486  case SHAPE_T::RECT:
1487  {
1488  std::vector<wxPoint> pts = GetRectCorners();
1489 
1490  if( IsFilled() )
1491  {
1492  aCornerBuffer.NewOutline();
1493 
1494  for( const wxPoint& pt : pts )
1495  aCornerBuffer.Append( pt );
1496  }
1497 
1498  if( width > 0 || !IsFilled() )
1499  {
1500  // Add in segments
1501  TransformOvalToPolygon( aCornerBuffer, pts[0], pts[1], width, aError, aErrorLoc );
1502  TransformOvalToPolygon( aCornerBuffer, pts[1], pts[2], width, aError, aErrorLoc );
1503  TransformOvalToPolygon( aCornerBuffer, pts[2], pts[3], width, aError, aErrorLoc );
1504  TransformOvalToPolygon( aCornerBuffer, pts[3], pts[0], width, aError, aErrorLoc );
1505  }
1506 
1507  break;
1508  }
1509 
1510  case SHAPE_T::ARC:
1511  TransformArcToPolygon( aCornerBuffer, GetStart(), GetArcMid(), GetEnd(), width, aError,
1512  aErrorLoc );
1513  break;
1514 
1515  case SHAPE_T::SEGMENT:
1516  TransformOvalToPolygon( aCornerBuffer, GetStart(), GetEnd(), width, aError, aErrorLoc );
1517  break;
1518 
1519  case SHAPE_T::POLY:
1520  {
1521  if( !IsPolyShapeValid() )
1522  break;
1523 
1524  // The polygon is expected to be a simple polygon; not self intersecting, no hole.
1525  double orientation = getParentOrientation();
1526  wxPoint offset = getParentPosition();
1527 
1528  // Build the polygon with the actual position and orientation:
1529  std::vector<wxPoint> poly;
1530  DupPolyPointsList( poly );
1531 
1532  for( wxPoint& point : poly )
1533  {
1534  RotatePoint( &point, orientation );
1535  point += offset;
1536  }
1537 
1538  if( IsFilled() )
1539  {
1540  aCornerBuffer.NewOutline();
1541 
1542  for( const wxPoint& point : poly )
1543  aCornerBuffer.Append( point.x, point.y );
1544  }
1545 
1546  if( width > 0 || !IsFilled() )
1547  {
1548  wxPoint pt1( poly[ poly.size() - 1] );
1549 
1550  for( const wxPoint& pt2 : poly )
1551  {
1552  if( pt2 != pt1 )
1553  TransformOvalToPolygon( aCornerBuffer, pt1, pt2, width, aError, aErrorLoc );
1554 
1555  pt1 = pt2;
1556  }
1557  }
1558 
1559  break;
1560  }
1561 
1562  case SHAPE_T::BEZIER:
1563  {
1564  std::vector<wxPoint> ctrlPts = { GetStart(), GetBezierC1(), GetBezierC2(), GetEnd() };
1565  BEZIER_POLY converter( ctrlPts );
1566  std::vector< wxPoint> poly;
1567  converter.GetPoly( poly, m_width );
1568 
1569  for( unsigned ii = 1; ii < poly.size(); ii++ )
1570  {
1571  TransformOvalToPolygon( aCornerBuffer, poly[ii - 1], poly[ii], width, aError,
1572  aErrorLoc );
1573  }
1574 
1575  break;
1576  }
1577 
1578  default:
1580  break;
1581  }
1582 }
SHAPE_T m_shape
Definition: eda_shape.h:296
wxPoint getCenter() const
Definition: eda_shape.cpp:393
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:97
void DupPolyPointsList(std::vector< wxPoint > &aBuffer) const
Duplicate the list of corners in a std::vector<wxPoint>
Definition: eda_shape.cpp:1152
virtual wxPoint getParentPosition() const =0
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
bool IsPolyShapeValid() const
Definition: eda_shape.cpp:1169
bool IsFilled() const
Definition: eda_shape.h:81
const wxPoint & GetBezierC1() const
Definition: eda_shape.h:145
std::vector< wxPoint > GetRectCorners() const
Definition: eda_shape.cpp:943
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
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.
const wxPoint & GetBezierC2() const
Definition: eda_shape.h:148
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:71
int NewOutline()
Creates a new hole in a given outline.
Bezier curves to polygon converter.
Definition: bezier_curves.h:36
virtual double getParentOrientation() const =0
wxPoint GetArcMid() const
Definition: eda_shape.cpp:437
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.
void TransformArcToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aStart, const wxPoint &aMid, const wxPoint &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arc to multiple straight segments.
int m_width
Definition: eda_shape.h:297
int GetRadius() const
Definition: eda_shape.cpp:466
void TransformRingToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aCentre, int aRadius, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arcs to multiple straight segments.
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...

References SHAPE_POLY_SET::Append(), ARC, BEZIER, CIRCLE, DupPolyPointsList(), GetArcMid(), GetBezierC1(), GetBezierC2(), getCenter(), GetEnd(), getParentOrientation(), getParentPosition(), BEZIER_POLY::GetPoly(), GetRadius(), GetRectCorners(), GetStart(), IsFilled(), IsPolyShapeValid(), m_shape, m_width, SHAPE_POLY_SET::NewOutline(), POLY, RECT, RotatePoint(), SEGMENT, SHAPE_T_asString(), TransformArcToPolygon(), TransformCircleToPolygon(), TransformOvalToPolygon(), TransformRingToPolygon(), and UNIMPLEMENTED_FOR.

Referenced by PCB_SHAPE::TransformShapeWithClearanceToPolygon().

Member Data Documentation

◆ m_arcCenter

◆ m_bezierC1

◆ m_bezierC2

◆ m_bezierPoints

◆ m_editState

int EDA_SHAPE::m_editState
protected

Definition at line 310 of file eda_shape.h.

Referenced by beginEdit(), calcEdit(), LIB_SHAPE::LIB_SHAPE(), and setEditState().

◆ m_eeWinding

bool EDA_SHAPE::m_eeWinding
protected

Definition at line 311 of file eda_shape.h.

Referenced by computeArcBBox(), and hitTest().

◆ m_end

◆ m_endsSwapped

bool EDA_SHAPE::m_endsSwapped
protected

◆ m_fill

FILL_T EDA_SHAPE::m_fill
protected

◆ m_poly

◆ m_shape

◆ m_start

◆ m_width


The documentation for this class was generated from the following files: