CADSTAR PCB: Fix loading of arc tracks following recent PCB_ARC changes

We no longer have any knowledge of the original start/end of the arc,
since SetArcAngleAndEnd swaps the start and end to ensure the arc is
always clockwise at the end.

Adds a method EDA_SHAPE::EndsSwapped() to notify whether the start/end
point of the shape were swapped.
This commit is contained in:
Roberto Fernandez Bautista 2021-10-17 15:22:07 +01:00
parent d6d800ccbb
commit 99442350a4
3 changed files with 59 additions and 12 deletions

View File

@ -36,6 +36,7 @@
#include <plotters/plotter.h> #include <plotters/plotter.h>
EDA_SHAPE::EDA_SHAPE( SHAPE_T aType, int aLineWidth, FILL_T aFill ) : EDA_SHAPE::EDA_SHAPE( SHAPE_T aType, int aLineWidth, FILL_T aFill ) :
m_endsSwapped( false ),
m_shape( aType ), m_shape( aType ),
m_width( aLineWidth ), m_width( aLineWidth ),
m_fill( aFill ), m_fill( aFill ),
@ -487,6 +488,7 @@ void EDA_SHAPE::SetArcGeometry( const wxPoint& aStart, const wxPoint& aMid, cons
m_start = aStart; m_start = aStart;
m_end = aEnd; m_end = aEnd;
m_arcCenter = CalcArcCenter( aStart, aMid, aEnd ); m_arcCenter = CalcArcCenter( aStart, aMid, aEnd );
m_endsSwapped = false;
} }
@ -510,7 +512,10 @@ void EDA_SHAPE::SetArcAngleAndEnd( double aAngle, bool aCheckNegativeAngle )
RotatePoint( &m_end, m_arcCenter, -NormalizeAngle360Max( aAngle ) ); RotatePoint( &m_end, m_arcCenter, -NormalizeAngle360Max( aAngle ) );
if( aCheckNegativeAngle && aAngle < 0 ) if( aCheckNegativeAngle && aAngle < 0 )
{
std::swap( m_start, m_end ); std::swap( m_start, m_end );
m_endsSwapped = true;
}
} }

View File

@ -96,9 +96,24 @@ public:
const wxPoint& GetStart() const { return m_start; } const wxPoint& GetStart() const { return m_start; }
int GetStartY() { return m_start.y; } int GetStartY() { return m_start.y; }
int GetStartX() { return m_start.x; } int GetStartX() { return m_start.x; }
void SetStart( const wxPoint& aStart ) { m_start = aStart; }
void SetStartY( int y ) { m_start.y = y; } void SetStart( const wxPoint& aStart )
void SetStartX( int x ) { m_start.x = x; } {
m_start = aStart;
m_endsSwapped = false;
}
void SetStartY( int y )
{
m_start.y = y;
m_endsSwapped = false;
}
void SetStartX( int x )
{
m_start.x = x;
m_endsSwapped = false;
}
/** /**
* Return the ending point of the graphic. * Return the ending point of the graphic.
@ -106,9 +121,24 @@ public:
const wxPoint& GetEnd() const { return m_end; } const wxPoint& GetEnd() const { return m_end; }
int GetEndY() { return m_end.y; } int GetEndY() { return m_end.y; }
int GetEndX() { return m_end.x; } int GetEndX() { return m_end.x; }
void SetEnd( const wxPoint& aEnd ) { m_end = aEnd; }
void SetEndY( int y ) { m_end.y = y; } void SetEnd( const wxPoint& aEnd )
void SetEndX( int x ) { m_end.x = x; } {
m_end = aEnd;
m_endsSwapped = false;
}
void SetEndY( int y )
{
m_end.y = y;
m_endsSwapped = false;
}
void SetEndX( int x )
{
m_end.x = x;
m_endsSwapped = false;
}
void SetBezierC1( const wxPoint& aPt ) { m_bezierC1 = aPt; } void SetBezierC1( const wxPoint& aPt ) { m_bezierC1 = aPt; }
const wxPoint& GetBezierC1() const { return m_bezierC1; } const wxPoint& GetBezierC1() const { return m_bezierC1; }
@ -128,6 +158,12 @@ public:
double GetArcAngle() const; double GetArcAngle() const;
/**
* Have the start and end points been swapped since they were set?
* @return true if they have
*/
bool EndsSwapped() const { return m_endsSwapped; }
// Some attributes are read only, since they are derived from m_Start, m_End, and m_Angle. // Some attributes are read only, since they are derived from m_Start, m_End, and m_Angle.
// No Set...() function for these attributes. // No Set...() function for these attributes.
@ -255,6 +291,7 @@ protected:
void setEditState( int aState ) { m_editState = aState; } void setEditState( int aState ) { m_editState = aState; }
protected: protected:
bool m_endsSwapped; // true if start/end were swapped e.g. SetArcAngleAndEnd
SHAPE_T m_shape; // Shape: line, Circle, Arc SHAPE_T m_shape; // Shape: line, Circle, Arc
int m_width; // thickness of lines ... int m_width; // thickness of lines ...
FILL_T m_fill; FILL_T m_fill;

View File

@ -2845,7 +2845,7 @@ PCB_SHAPE* CADSTAR_PCB_ARCHIVE_LOADER::getShapeFromVertex( const POINT& aCadstar
if( cw ) if( cw )
shape->SetArcAngleAndEnd( NormalizeAnglePos( arcAngle ) ); shape->SetArcAngleAndEnd( NormalizeAnglePos( arcAngle ) );
else else
shape->SetArcAngleAndEnd( NormalizeAngleNeg( arcAngle ) ); shape->SetArcAngleAndEnd( NormalizeAngleNeg( arcAngle ), true );
break; break;
} }
@ -3056,13 +3056,20 @@ std::vector<PCB_TRACK*> CADSTAR_PCB_ARCHIVE_LOADER::makeTracksFromShapes(
if( shape->GetClass() == wxT( "MGRAPHIC" ) ) if( shape->GetClass() == wxT( "MGRAPHIC" ) )
{ {
FP_SHAPE* fp_shape = (FP_SHAPE*) shape; FP_SHAPE* fp_shape = (FP_SHAPE*) shape;
SHAPE_ARC arc( fp_shape->GetCenter0(), fp_shape->GetStart0(), SHAPE_ARC arc( fp_shape->GetStart0(), fp_shape->GetArcMid0(), fp_shape->GetEnd0(), 0 );
fp_shape->GetArcAngle() / 10.0 );
if( fp_shape->EndsSwapped() )
arc.Reverse();
track = new PCB_ARC( aParentContainer, &arc ); track = new PCB_ARC( aParentContainer, &arc );
} }
else else
{ {
SHAPE_ARC arc( shape->GetCenter(), shape->GetStart(), shape->GetArcAngle() / 10.0 ); SHAPE_ARC arc( shape->GetStart(), shape->GetArcMid(), shape->GetEnd(), 0 );
if( shape->EndsSwapped() )
arc.Reverse();
track = new PCB_ARC( aParentContainer, &arc ); track = new PCB_ARC( aParentContainer, &arc );
} }
break; break;
@ -3107,8 +3114,6 @@ std::vector<PCB_TRACK*> CADSTAR_PCB_ARCHIVE_LOADER::makeTracksFromShapes(
// Apply route offsetting, mimmicking the behaviour of the CADSTAR post processor // Apply route offsetting, mimmicking the behaviour of the CADSTAR post processor
if( prevTrack != nullptr ) if( prevTrack != nullptr )
{ {
track->SetStart( prevTrack->GetEnd() ); // remove discontinuities if possible
int offsetAmount = ( track->GetWidth() / 2 ) - ( prevTrack->GetWidth() / 2 ); int offsetAmount = ( track->GetWidth() / 2 ) - ( prevTrack->GetWidth() / 2 );
if( offsetAmount > 0 ) if( offsetAmount > 0 )