From 49a2926a34345d034dc8211cac3a1fbdee4e52e5 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Sat, 21 Nov 2020 22:56:56 +0000 Subject: [PATCH] CADSTAR Schematic Archive Importer: Fix loading of graphical arc segments Load the arc segments as piece-wise straight segments --- .../cadstar/cadstar_sch_archive_loader.cpp | 93 ++++++++++++++++--- .../cadstar/cadstar_sch_archive_loader.h | 6 ++ 2 files changed, 84 insertions(+), 15 deletions(-) diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 5329861000..097862bde2 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -1162,6 +1162,31 @@ wxString CADSTAR_SCH_ARCHIVE_LOADER::getNetName( const NET_SCH& aNet ) } +void CADSTAR_SCH_ARCHIVE_LOADER::loadGraphicStaightSegment( const wxPoint& aStartPoint, + const wxPoint& aEndPoint, const LINECODE_ID& aCadstarLineCodeID, + const LAYER_ID& aCadstarSheetID, const SCH_LAYER_ID& aKiCadSchLayerID, + const wxPoint& aMoveVector, const double& aRotationAngleDeciDeg, + const double& aScalingFactor, const wxPoint& aTransformCentre, const bool& aMirrorInvert ) +{ + SCH_LINE* segment = new SCH_LINE(); + + segment->SetLayer( aKiCadSchLayerID ); + segment->SetLineWidth( KiROUND( getLineThickness( aCadstarLineCodeID ) * aScalingFactor ) ); + segment->SetLineStyle( getLineStyle( aCadstarLineCodeID ) ); + + //Apply transforms + wxPoint startPoint = applyTransform( aStartPoint, aMoveVector, aRotationAngleDeciDeg, aScalingFactor, + aTransformCentre, aMirrorInvert ); + wxPoint endPoint = applyTransform( aEndPoint, aMoveVector, aRotationAngleDeciDeg, aScalingFactor, + aTransformCentre, aMirrorInvert ); + + segment->SetStartPoint( startPoint ); + segment->SetEndPoint( endPoint ); + + loadItemOntoKiCadSheet( aCadstarSheetID, segment ); +} + + void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector& aCadstarVertices, LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID, const wxPoint& aMoveVector, const double& aRotationAngleDeciDeg, @@ -1177,26 +1202,64 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector& a { cur = &aCadstarVertices.at( i ); - SCH_LINE* segment = new SCH_LINE(); - wxPoint startPoint = getKiCadPoint( prev->End ); - wxPoint endPoint = getKiCadPoint( cur->End ); + wxPoint startPoint = getKiCadPoint( prev->End ); + wxPoint endPoint = getKiCadPoint( cur->End ); + wxPoint centerPoint = getKiCadPoint( cur->Center ); + bool cw = false; - segment->SetLayer( aKiCadSchLayerID ); - segment->SetLineWidth( KiROUND( getLineThickness( aCadstarLineCodeID ) * aScalingFactor ) ); - segment->SetLineStyle( getLineStyle( aCadstarLineCodeID ) ); + if( cur->Type == VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE + || cur->Type == VERTEX_TYPE::CLOCKWISE_SEMICIRCLE ) + { + centerPoint = ( startPoint + endPoint ) / 2; + } - //Apply transforms - startPoint = applyTransform( startPoint, aMoveVector, aRotationAngleDeciDeg, aScalingFactor, - aTransformCentre, aMirrorInvert ); - endPoint = applyTransform( endPoint, aMoveVector, aRotationAngleDeciDeg, aScalingFactor, - aTransformCentre, aMirrorInvert ); + switch( cur->Type ) + { + case VERTEX_TYPE::CLOCKWISE_SEMICIRCLE: + case VERTEX_TYPE::CLOCKWISE_ARC: + cw = true; + KI_FALLTHROUGH; + case VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE: + case VERTEX_TYPE::ANTICLOCKWISE_ARC: + { + double arcStartAngle = getPolarAngle( startPoint - centerPoint ); + double arcEndAngle = getPolarAngle( endPoint - centerPoint ); + double arcAngleDeciDeg = arcEndAngle - arcStartAngle; + + if( cw ) + arcAngleDeciDeg = NormalizeAnglePos( arcAngleDeciDeg ); + else + arcAngleDeciDeg = NormalizeAngleNeg( arcAngleDeciDeg ); + + SHAPE_ARC tempArc( VECTOR2I(centerPoint), VECTOR2I(startPoint), arcAngleDeciDeg / 10.0 ); + SHAPE_LINE_CHAIN arcSegments = tempArc.ConvertToPolyline( Millimeter2iu( 0.1 ) ); + + // Load the arc as a series of piece-wise segments + + for( int i = 0; i < arcSegments.SegmentCount(); i++ ) + { + wxPoint segStart = (wxPoint) arcSegments.Segment( i ).A; + wxPoint segEnd = (wxPoint) arcSegments.Segment( i ).B; + + loadGraphicStaightSegment( segStart, segEnd, aCadstarLineCodeID, + aCadstarSheetID, aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg, + aScalingFactor, aTransformCentre, aMirrorInvert ); + } + } + break; + + case VERTEX_TYPE::POINT: + loadGraphicStaightSegment( startPoint, endPoint, aCadstarLineCodeID, aCadstarSheetID, + aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg, aScalingFactor, + aTransformCentre, aMirrorInvert ); + break; + + default: + wxFAIL_MSG( "Unknown CADSTAR Vertex type" ); + } - segment->SetStartPoint( startPoint ); - segment->SetEndPoint( endPoint ); prev = cur; - - loadItemOntoKiCadSheet( aCadstarSheetID, segment ); } } diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h index 4af878f51b..042d015da4 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h @@ -144,6 +144,12 @@ private: wxString getNetName( const NET_SCH& aNet ); //Helper functions for loading figures / graphical items + void loadGraphicStaightSegment( const wxPoint& aStartPoint, const wxPoint& aEndPoint, + const LINECODE_ID& aCadstarLineCodeID, const LAYER_ID& aCadstarSheetID, + const SCH_LAYER_ID& aKiCadSchLayerID, const wxPoint& aMoveVector = { 0, 0 }, + const double& aRotationAngleDeciDeg = 0.0, const double& aScalingFactor = 1.0, + const wxPoint& aTransformCentre = { 0, 0 }, const bool& aMirrorInvert = false ); + void loadShapeVertices( const std::vector& aCadstarVertices, LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID, const wxPoint& aMoveVector = { 0, 0 }, const double& aRotationAngleDeciDeg = 0.0,