KiCad PCB EDA Suite
CADSTAR_ARCHIVE_PARSER::VERTEX Struct Reference

Represents a vertex in a shape. More...

#include <cadstar_archive_parser.h>

Inheritance diagram for CADSTAR_ARCHIVE_PARSER::VERTEX:
CADSTAR_ARCHIVE_PARSER::PARSER

Public Member Functions

 VERTEX (VERTEX_TYPE aType=VERTEX_TYPE::POINT, POINT aEnd=POINT(), POINT aCenter=POINT())
 
void Parse (XNODE *aNode, PARSER_CONTEXT *aContext) override
 
void AppendToChain (SHAPE_LINE_CHAIN *aChainToAppendTo, const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, double aAccuracy) const
 

Static Public Member Functions

static bool IsVertex (XNODE *aNode)
 

Public Attributes

VERTEX_TYPE Type
 
POINT End
 
POINT Center
 

Detailed Description

Represents a vertex in a shape.

E.g. A circle is made by two semicircles with the same center point.

Definition at line 438 of file cadstar_archive_parser.h.

Constructor & Destructor Documentation

◆ VERTEX()

CADSTAR_ARCHIVE_PARSER::VERTEX::VERTEX ( VERTEX_TYPE  aType = VERTEX_TYPE::POINT,
POINT  aEnd = POINT(),
POINT  aCenter = POINT() 
)
inline

Definition at line 440 of file cadstar_archive_parser.h.

Member Function Documentation

◆ AppendToChain()

void CADSTAR_ARCHIVE_PARSER::VERTEX::AppendToChain ( SHAPE_LINE_CHAIN aChainToAppendTo,
const std::function< VECTOR2I(const VECTOR2I &)>  aCadstarToKicadPointCallback,
double  aAccuracy 
) const

Definition at line 485 of file cadstar_archive_parser.cpp.

488{
489 VECTOR2I endPoint = aCadstarToKicadPointCallback( End );
490
491 if( Type == VERTEX_TYPE::POINT )
492 {
493 aChainToAppendTo->Append( endPoint );
494 return;
495 }
496
497 wxCHECK_MSG( aChainToAppendTo->PointCount() > 0, /*void*/,
498 "Can't append an arc to vertex to an empty chain" );
499
500 VECTOR2I startPoint = aChainToAppendTo->GetPoint( -1 );
501 VECTOR2I centerPoint;
502
504 centerPoint = ( startPoint / 2 ) + ( endPoint / 2 );
505 else
506 centerPoint = aCadstarToKicadPointCallback( Center );
507
508 bool clockwise = Type == VERTEX_TYPE::CLOCKWISE_ARC
510
511 // A bit of a hack to figure out if we need to invert clockwise due to the transform
512 VECTOR2I transform = aCadstarToKicadPointCallback( { 500, 500 } )
513 - aCadstarToKicadPointCallback( { 0, 0 } );
514
515 if( ( transform.x > 0 && transform.y < 0 ) || ( transform.x < 0 && transform.y > 0 ) )
516 clockwise = !clockwise;
517
518 SHAPE_ARC arc;
519 arc.ConstructFromStartEndCenter( startPoint, endPoint, centerPoint, clockwise );
520
521 aChainToAppendTo->Append( arc, aAccuracy );
522}
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
Definition: shape_arc.cpp:209
virtual const VECTOR2I GetPoint(int aIndex) const override
int PointCount() const
Return the number of points (vertices) in this line chain.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.

References CADSTAR_ARCHIVE_PARSER::ANTICLOCKWISE_SEMICIRCLE, SHAPE_LINE_CHAIN::Append(), PCAD2KICAD::Center, CADSTAR_ARCHIVE_PARSER::CLOCKWISE_ARC, CADSTAR_ARCHIVE_PARSER::CLOCKWISE_SEMICIRCLE, SHAPE_ARC::ConstructFromStartEndCenter(), SHAPE_LINE_CHAIN::GetPoint(), CADSTAR_ARCHIVE_PARSER::POINT, SHAPE_LINE_CHAIN::PointCount(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ IsVertex()

bool CADSTAR_ARCHIVE_PARSER::VERTEX::IsVertex ( XNODE aNode)
static

Definition at line 423 of file cadstar_archive_parser.cpp.

424{
425 wxString aNodeName = aNode->GetName();
426
427 if( aNodeName == wxT( "PT" ) || aNodeName == wxT( "ACWARC" ) || aNodeName == wxT( "CWARC" )
428 || aNodeName == wxT( "CWSEMI" ) || aNodeName == wxT( "ACWSEMI" ) )
429 {
430 return true;
431 }
432 else
433 {
434 return false;
435 }
436}

Referenced by CADSTAR_PCB_ARCHIVE_PARSER::NET_PCB::ROUTE_VERTEX::Parse(), and CADSTAR_ARCHIVE_PARSER::ParseAllChildVertices().

◆ Parse()

void CADSTAR_ARCHIVE_PARSER::VERTEX::Parse ( XNODE aNode,
PARSER_CONTEXT aContext 
)
overridevirtual

Implements CADSTAR_ARCHIVE_PARSER::PARSER.

Definition at line 439 of file cadstar_archive_parser.cpp.

440{
441 wxASSERT( IsVertex( aNode ) );
442
443 wxString aNodeName = aNode->GetName();
444
445 if( aNodeName == wxT( "PT" ) )
446 {
450 End.Parse( aNode, aContext );
451 }
452 else if( aNodeName == wxT( "ACWARC" ) || aNodeName == wxT( "CWARC" ) )
453 {
454 if( aNodeName == wxT( "ACWARC" ) )
456 else
458
459 std::vector<POINT> pts = ParseAllChildPoints( aNode, aContext, true, 2 );
460
461 Center = pts[0];
462 End = pts[1];
463 }
464 else if( aNodeName == wxT( "ACWSEMI" ) || aNodeName == wxT( "CWSEMI" ) )
465 {
466 if( aNodeName == wxT( "ACWSEMI" ) )
468 else
470
473
474 std::vector<POINT> pts = ParseAllChildPoints( aNode, aContext, true, 1 );
475
476 End = pts[0];
477 }
478 else
479 {
480 wxASSERT_MSG( true, wxT( "Unknown VERTEX type" ) );
481 }
482}
static const long UNDEFINED_VALUE
static std::vector< POINT > ParseAllChildPoints(XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false, int aExpectedNumPoints=UNDEFINED_VALUE)
if no children are present, it just returns an empty vector (without throwing an exception)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override

References CADSTAR_ARCHIVE_PARSER::ANTICLOCKWISE_ARC, CADSTAR_ARCHIVE_PARSER::ANTICLOCKWISE_SEMICIRCLE, PCAD2KICAD::Center, CADSTAR_ARCHIVE_PARSER::CLOCKWISE_ARC, CADSTAR_ARCHIVE_PARSER::CLOCKWISE_SEMICIRCLE, CADSTAR_ARCHIVE_PARSER::ParseAllChildPoints(), CADSTAR_ARCHIVE_PARSER::POINT, and CADSTAR_ARCHIVE_PARSER::UNDEFINED_VALUE.

Referenced by CADSTAR_ARCHIVE_PARSER::ParseAllChildVertices().

Member Data Documentation

◆ Center

◆ End

◆ Type


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