From 99442350a47901803a5a4b70cf000608617f1db2 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Sun, 17 Oct 2021 15:22:07 +0100 Subject: [PATCH] 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. --- common/eda_shape.cpp | 5 ++ include/eda_shape.h | 49 ++++++++++++++++--- .../cadstar/cadstar_pcb_archive_loader.cpp | 17 ++++--- 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/common/eda_shape.cpp b/common/eda_shape.cpp index c28a1b03a8..7010cc58ab 100644 --- a/common/eda_shape.cpp +++ b/common/eda_shape.cpp @@ -36,6 +36,7 @@ #include EDA_SHAPE::EDA_SHAPE( SHAPE_T aType, int aLineWidth, FILL_T aFill ) : + m_endsSwapped( false ), m_shape( aType ), m_width( aLineWidth ), m_fill( aFill ), @@ -487,6 +488,7 @@ void EDA_SHAPE::SetArcGeometry( const wxPoint& aStart, const wxPoint& aMid, cons m_start = aStart; m_end = 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 ) ); if( aCheckNegativeAngle && aAngle < 0 ) + { std::swap( m_start, m_end ); + m_endsSwapped = true; + } } diff --git a/include/eda_shape.h b/include/eda_shape.h index 673002bfbf..409a5d6b52 100644 --- a/include/eda_shape.h +++ b/include/eda_shape.h @@ -96,9 +96,24 @@ public: const wxPoint& GetStart() const { return m_start; } int GetStartY() { return m_start.y; } int GetStartX() { return m_start.x; } - void SetStart( const wxPoint& aStart ) { m_start = aStart; } - void SetStartY( int y ) { m_start.y = y; } - void SetStartX( int x ) { m_start.x = x; } + + void SetStart( const wxPoint& aStart ) + { + 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. @@ -106,9 +121,24 @@ public: const wxPoint& GetEnd() const { return m_end; } int GetEndY() { return m_end.y; } int GetEndX() { return m_end.x; } - void SetEnd( const wxPoint& aEnd ) { m_end = aEnd; } - void SetEndY( int y ) { m_end.y = y; } - void SetEndX( int x ) { m_end.x = x; } + + void SetEnd( const wxPoint& aEnd ) + { + 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; } const wxPoint& GetBezierC1() const { return m_bezierC1; } @@ -128,6 +158,12 @@ public: 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. // No Set...() function for these attributes. @@ -255,6 +291,7 @@ protected: void setEditState( int aState ) { m_editState = aState; } protected: + bool m_endsSwapped; // true if start/end were swapped e.g. SetArcAngleAndEnd SHAPE_T m_shape; // Shape: line, Circle, Arc int m_width; // thickness of lines ... FILL_T m_fill; diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp index abddc5c360..86cd4aa453 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp @@ -2845,7 +2845,7 @@ PCB_SHAPE* CADSTAR_PCB_ARCHIVE_LOADER::getShapeFromVertex( const POINT& aCadstar if( cw ) shape->SetArcAngleAndEnd( NormalizeAnglePos( arcAngle ) ); else - shape->SetArcAngleAndEnd( NormalizeAngleNeg( arcAngle ) ); + shape->SetArcAngleAndEnd( NormalizeAngleNeg( arcAngle ), true ); break; } @@ -3056,13 +3056,20 @@ std::vector CADSTAR_PCB_ARCHIVE_LOADER::makeTracksFromShapes( if( shape->GetClass() == wxT( "MGRAPHIC" ) ) { FP_SHAPE* fp_shape = (FP_SHAPE*) shape; - SHAPE_ARC arc( fp_shape->GetCenter0(), fp_shape->GetStart0(), - fp_shape->GetArcAngle() / 10.0 ); + SHAPE_ARC arc( fp_shape->GetStart0(), fp_shape->GetArcMid0(), fp_shape->GetEnd0(), 0 ); + + if( fp_shape->EndsSwapped() ) + arc.Reverse(); + track = new PCB_ARC( aParentContainer, &arc ); } 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 ); } break; @@ -3107,8 +3114,6 @@ std::vector CADSTAR_PCB_ARCHIVE_LOADER::makeTracksFromShapes( // Apply route offsetting, mimmicking the behaviour of the CADSTAR post processor if( prevTrack != nullptr ) { - track->SetStart( prevTrack->GetEnd() ); // remove discontinuities if possible - int offsetAmount = ( track->GetWidth() / 2 ) - ( prevTrack->GetWidth() / 2 ); if( offsetAmount > 0 )