From 99d02ac7c0e716319122d67c6666480fb59ea012 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Tue, 10 Jan 2023 22:25:28 +0100 Subject: [PATCH] CADSTAR SCH: Load symbol shapes with correct fill state Changes architecture of importer to use SHAPE_LINE_CHAIN. For now lets just load symbol shapes like this, but we could update code for all other loading operations (also in PCB). FIxes https://gitlab.com/kicad/code/kicad/-/issues/8060 --- .../cadstar/cadstar_archive_parser.cpp | 31 ++++++++++--- .../plugins/cadstar/cadstar_archive_parser.h | 9 ++-- .../cadstar/cadstar_sch_archive_loader.cpp | 45 ++++++++++++++----- .../cadstar/cadstar_sch_archive_loader.h | 3 +- 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/common/plugins/cadstar/cadstar_archive_parser.cpp b/common/plugins/cadstar/cadstar_archive_parser.cpp index 7666f30d26..62b3119449 100644 --- a/common/plugins/cadstar/cadstar_archive_parser.cpp +++ b/common/plugins/cadstar/cadstar_archive_parser.cpp @@ -483,7 +483,8 @@ void CADSTAR_ARCHIVE_PARSER::VERTEX::Parse( XNODE* aNode, PARSER_CONTEXT* aConte void CADSTAR_ARCHIVE_PARSER::VERTEX::AppendToChain( SHAPE_LINE_CHAIN* aChainToAppendTo, - const std::function aCadstarToKicadPointCallback ) const + const std::function aCadstarToKicadPointCallback, + double aAccuracy ) const { VECTOR2I endPoint = aCadstarToKicadPointCallback( End ); @@ -517,7 +518,7 @@ void CADSTAR_ARCHIVE_PARSER::VERTEX::AppendToChain( SHAPE_LINE_CHAIN* aChainToAp SHAPE_ARC arc; arc.ConstructFromStartEndCenter( startPoint, endPoint, centerPoint, clockwise ); - aChainToAppendTo->Append( arc ); + aChainToAppendTo->Append( arc, aAccuracy ); } @@ -586,38 +587,54 @@ void CADSTAR_ARCHIVE_PARSER::SHAPE::Parse( XNODE* aNode, PARSER_CONTEXT* aContex } SHAPE_LINE_CHAIN CADSTAR_ARCHIVE_PARSER::SHAPE::OutlineAsChain( - const std::function aCadstarToKicadPointCallback ) const + const std::function aCadstarToKicadPointCallback, + double aAccuracy ) const { SHAPE_LINE_CHAIN outline; + if( Vertices.size() == 0 ) + return outline; + for( const auto& vertex : Vertices ) - vertex.AppendToChain( &outline, aCadstarToKicadPointCallback ); + vertex.AppendToChain( &outline, aCadstarToKicadPointCallback, aAccuracy ); if( Type != SHAPE_TYPE::OPENSHAPE ) + { outline.SetClosed( true ); + // Append after closing, to ensre first and last point remain the same + Vertices.at( 0 ).AppendToChain( &outline, aCadstarToKicadPointCallback, aAccuracy ); + } + return outline; } SHAPE_POLY_SET CADSTAR_ARCHIVE_PARSER::SHAPE::ConvertToPolySet( - const std::function aCadstarToKicadPointCallback ) const + const std::function aCadstarToKicadPointCallback, + double aAccuracy ) const { SHAPE_POLY_SET polyset; wxCHECK( Type != SHAPE_TYPE::OPENSHAPE, polyset ); // We shouldn't convert openshapes to polyset! - polyset.AddOutline( OutlineAsChain( aCadstarToKicadPointCallback) ); + polyset.AddOutline( OutlineAsChain( aCadstarToKicadPointCallback, aAccuracy ) ); for( const auto& cutout : Cutouts ) { SHAPE_LINE_CHAIN hole; + if( cutout.Vertices.size() == 0 ) + continue; + for( const auto& cutoutVertex : cutout.Vertices ) - cutoutVertex.AppendToChain( &hole, aCadstarToKicadPointCallback ); + cutoutVertex.AppendToChain( &hole, aCadstarToKicadPointCallback, aAccuracy ); hole.SetClosed( true ); + // Append after closing, to ensre first and last point remain the same + cutout.Vertices.at( 0 ).AppendToChain( &hole, aCadstarToKicadPointCallback, aAccuracy ); + polyset.AddHole( hole ); } diff --git a/common/plugins/cadstar/cadstar_archive_parser.h b/common/plugins/cadstar/cadstar_archive_parser.h index cd2336cc89..a5330ba5fd 100644 --- a/common/plugins/cadstar/cadstar_archive_parser.h +++ b/common/plugins/cadstar/cadstar_archive_parser.h @@ -449,7 +449,8 @@ public: void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override; void AppendToChain( SHAPE_LINE_CHAIN* aChainToAppendTo, - const std::function aCadstarToKicadPointCallback ) const; + const std::function aCadstarToKicadPointCallback, + double aAccuracy ) const; }; /** @@ -483,10 +484,12 @@ public: void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override; SHAPE_LINE_CHAIN OutlineAsChain( const std::function - aCadstarToKicadPointCallback ) const; + aCadstarToKicadPointCallback, + double aAccuracy ) const; SHAPE_POLY_SET ConvertToPolySet( const std::function - aCadstarToKicadPointCallback ) const; + aCadstarToKicadPointCallback, + double aAccuracy ) const; }; diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 5849d19695..ca5c080756 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -1324,15 +1324,36 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef { FIGURE fig = figPair.second; int lineThickness = getLineThickness( fig.LineCodeID ); + PLOT_DASH_TYPE linestyle = getLineStyle( fig.LineCodeID ); - loadLibrarySymbolShapeVertices( fig.Shape.Vertices, symbol.Origin, aSymbol, gateNumber, - lineThickness ); - - for( CUTOUT c : fig.Shape.Cutouts ) + if( fig.Shape.Type == SHAPE_TYPE::OPENSHAPE ) { - loadLibrarySymbolShapeVertices( c.Vertices, symbol.Origin, aSymbol, gateNumber, + loadLibrarySymbolShapeVertices( fig.Shape.Vertices, symbol.Origin, aSymbol, gateNumber, lineThickness ); } + else + { + LIB_SHAPE* shape = new LIB_SHAPE( aSymbol, SHAPE_T::POLY ); + shape->SetPolyShape( fig.Shape.ConvertToPolySet( + [&]( const VECTOR2I& aPt ) + { + return getKiCadLibraryPoint( aPt, symbol.Origin ); + }, + ARC_ACCURACY ) ); + + shape->SetUnit( gateNumber ); + + shape->SetStroke( STROKE_PARAMS( lineThickness, linestyle ) ); + + if( fig.Shape.Type == SHAPE_TYPE::SOLID ) + shape->SetFillMode( FILL_T::FILLED_SHAPE ); + else if( fig.Shape.Type == SHAPE_TYPE::OUTLINE ) + shape->SetFillMode( FILL_T::NO_FILL ); + else if( fig.Shape.Type == SHAPE_TYPE::HATCHED ) // We don't have an equivalent + shape->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR ); + + aSymbol->AddDrawItem( shape ); + } } TERMINAL_TO_PINNUM_MAP pinNumMap; @@ -1647,9 +1668,9 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadLibrarySymbolShapeVertices( const std::vect LIB_SHAPE* shape = nullptr; bool cw = false; - wxPoint startPoint = getKiCadLibraryPoint( prev->End, aSymbolOrigin ); - wxPoint endPoint = getKiCadLibraryPoint( cur->End, aSymbolOrigin ); - wxPoint centerPoint; + VECTOR2I startPoint = getKiCadLibraryPoint( prev->End, aSymbolOrigin ); + VECTOR2I endPoint = getKiCadLibraryPoint( cur->End, aSymbolOrigin ); + VECTOR2I centerPoint; if( cur->Type == VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE || cur->Type == VERTEX_TYPE::CLOCKWISE_SEMICIRCLE ) @@ -2094,7 +2115,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector& a // TODO: Load as arc... SHAPE_ARC tempArc( centerPoint, startPoint, arcAngle ); - SHAPE_LINE_CHAIN arcSegments = tempArc.ConvertToPolyline( schIUScale.mmToIU( 0.1 ) ); + SHAPE_LINE_CHAIN arcSegments = tempArc.ConvertToPolyline( ARC_ACCURACY ); // Load the arc as a series of piece-wise segments @@ -3040,10 +3061,10 @@ VECTOR2I CADSTAR_SCH_ARCHIVE_LOADER::getKiCadPoint( const VECTOR2I& aCadstarPoin } -wxPoint CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLibraryPoint( const wxPoint& aCadstarPoint, - const wxPoint& aCadstarCentre ) +VECTOR2I CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLibraryPoint( const VECTOR2I& aCadstarPoint, + const VECTOR2I& aCadstarCentre ) { - wxPoint retval; + VECTOR2I retval; retval.x = getKiCadLength( aCadstarPoint.x - aCadstarCentre.x ); retval.y = getKiCadLength( aCadstarPoint.y - aCadstarCentre.y ); diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h index ab120fb38e..5b140be9a5 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h @@ -54,6 +54,7 @@ class CADSTAR_SCH_ARCHIVE_LOADER : public CADSTAR_SCH_ARCHIVE_PARSER public: // Size of tiny net labels when none present in original design const int SMALL_LABEL_SIZE = KiROUND( (double) SCH_IU_PER_MM * 0.4 ); + const double ARC_ACCURACY = SCH_IU_PER_MM * 0.01; // 0.01mm explicit CADSTAR_SCH_ARCHIVE_LOADER( wxString aFilename, REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter ) : @@ -234,7 +235,7 @@ private: VECTOR2I getKiCadPoint( const VECTOR2I& aCadstarPoint ); - wxPoint getKiCadLibraryPoint( const wxPoint& aCadstarPoint, const wxPoint& aCadstarCentre ); + VECTOR2I getKiCadLibraryPoint( const VECTOR2I& aCadstarPoint, const VECTOR2I& aCadstarCentre ); VECTOR2I applyTransform( const VECTOR2I& aPoint, const VECTOR2I& aMoveVector = { 0, 0 }, const EDA_ANGLE& aRotation = ANGLE_0,