From da791c5298fa6aa51e905a2551ae93a04db1ba11 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Sat, 26 Sep 2020 19:23:13 +0100 Subject: [PATCH] CADSTAR Schematic Archive Importer: Load Figures --- .../cadstar/cadstar_sch_archive_loader.cpp | 88 +++++++++++++++++++ .../cadstar/cadstar_sch_archive_loader.h | 21 +++-- .../cadstar/cadstar_sch_archive_parser.cpp | 2 +- 3 files changed, 104 insertions(+), 7 deletions(-) diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index ee54ec68d7..d8ef448b4f 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -84,6 +84,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( ::SCHEMATIC* aSchematic, ::SCH_SHEET* aRo loadSchematicSymbolInstances(); loadBusses(); loadNets(); + loadFigures(); // TODO Load other elements! // For all sheets, centre all elements and re calculate the page size: @@ -632,6 +633,33 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets() } +void CADSTAR_SCH_ARCHIVE_LOADER::loadFigures() +{ + for( std::pair figPair : Schematic.Figures ) + { + FIGURE fig = figPair.second; + + if( fig.LayerID == "ALL_SHEETS" ) + { + for( std::pair sheetPair : Sheets.SheetNames ) + { + LAYER_ID sheetID = sheetPair.first; + + loadShapeVertices( fig.Shape.Vertices, fig.LineCodeID, sheetID, LAYER_NOTES ); + } + } + else if( fig.LayerID == "NO_SHEET" ) + { + continue; + } + else + { + loadShapeVertices( fig.Shape.Vertices, fig.LineCodeID, fig.LayerID, LAYER_NOTES ); + } + } +} + + void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdefID, const PART* aCadstarPart, const GATE_ID& aGateID, LIB_PART* aPart ) { @@ -1047,6 +1075,44 @@ wxString CADSTAR_SCH_ARCHIVE_LOADER::getNetName( const NET_SCH& aNet ) } +void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector& aCadstarVertices, + LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID ) +{ + const VERTEX* prev = &aCadstarVertices.at( 0 ); + const VERTEX* cur; + + wxASSERT_MSG( + prev->Type == VERTEX_TYPE::POINT, "First vertex should always be a point vertex" ); + + for( size_t i = 1; i < aCadstarVertices.size(); i++ ) + { + cur = &aCadstarVertices.at( i ); + + SCH_LINE* segment = new SCH_LINE(); + wxPoint startPoint = getKiCadPoint( prev->End ); + wxPoint endPoint = getKiCadPoint( cur->End ); + + segment->SetStartPoint( startPoint ); + segment->SetEndPoint( endPoint ); + segment->SetLayer( aKiCadSchLayerID ); + segment->SetLineWidth( getLineThickness( aCadstarLineCodeID ) ); + segment->SetLineStyle( getLineStyle( aCadstarLineCodeID ) ); + + prev = cur; + + if( mSheetMap.find( aCadstarSheetID ) != mSheetMap.end() ) + { + mSheetMap.at( aCadstarSheetID )->GetScreen()->Append( segment ); + } + else + { + delete segment; + wxASSERT_MSG( false, "Unknown Sheet ID." ); + } + } +} + + void CADSTAR_SCH_ARCHIVE_LOADER::loadSheetAndChildSheets( LAYER_ID aCadstarSheetID, wxPoint aPosition, wxSize aSheetSize, SCH_SHEET* aParentSheet ) { @@ -1224,6 +1290,28 @@ int CADSTAR_SCH_ARCHIVE_LOADER::getLineThickness( const LINECODE_ID& aCadstarLin } +PLOT_DASH_TYPE CADSTAR_SCH_ARCHIVE_LOADER::getLineStyle( const LINECODE_ID& aCadstarLineCodeID ) +{ + wxCHECK( Assignments.Codedefs.LineCodes.find( aCadstarLineCodeID ) + != Assignments.Codedefs.LineCodes.end(), + PLOT_DASH_TYPE::SOLID ); + + // clang-format off + switch( Assignments.Codedefs.LineCodes.at( aCadstarLineCodeID ).Style ) + { + case LINESTYLE::DASH: return PLOT_DASH_TYPE::DASH; + case LINESTYLE::DASHDOT: return PLOT_DASH_TYPE::DASHDOT; + case LINESTYLE::DASHDOTDOT: return PLOT_DASH_TYPE::DASHDOT; //TODO: update in future + case LINESTYLE::DOT: return PLOT_DASH_TYPE::DOT; + case LINESTYLE::SOLID: return PLOT_DASH_TYPE::SOLID; + default: return PLOT_DASH_TYPE::DEFAULT; + } + // clang-format on + + return PLOT_DASH_TYPE(); +} + + CADSTAR_SCH_ARCHIVE_LOADER::TEXTCODE CADSTAR_SCH_ARCHIVE_LOADER::getTextCode( const TEXTCODE_ID& aCadstarTextCodeID ) { diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h index df83731354..3ced72b373 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h @@ -28,6 +28,8 @@ #include +#include // SCH_LAYER_ID +#include // PLOT_DASH_TYPE #include class EDA_TEXT; @@ -97,6 +99,7 @@ private: void loadSchematicSymbolInstances(); void loadBusses(); void loadNets(); + void loadFigures(); //Helper Functions for loading sheets void loadSheetAndChildSheets( LAYER_ID aCadstarSheetID, wxPoint aPosition, wxSize aSheetSize, @@ -125,16 +128,22 @@ private: POINT getLocationOfNetElement( const NET_SCH& aNet, const NETELEMENT_ID& aNetElementID ); wxString getNetName( const NET_SCH& aNet ); + //Helper functions for loading figures / graphical items + void loadShapeVertices( const std::vector& aCadstarVertices, + LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, + SCH_LAYER_ID aKiCadSchLayerID ); + //Helper Functions for obtaining CADSTAR elements from the parsed structures SYMDEF_ID getSymDefFromName( const wxString& aSymdefName, const wxString& aSymDefAlternate ); wxString generateSymDefName( const SYMDEF_ID& aSymdefID ); int getLineThickness( const LINECODE_ID& aCadstarLineCodeID ); - PART getPart( const PART_ID& aCadstarPartID ); - ROUTECODE getRouteCode( const ROUTECODE_ID& aCadstarRouteCodeID ); - TEXTCODE getTextCode( const TEXTCODE_ID& aCadstarTextCodeID ); - wxString getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID ); - wxString getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID, - const std::map& aCadstarAttributeMap ); + PLOT_DASH_TYPE getLineStyle( const LINECODE_ID& aCadstarLineCodeID ); + PART getPart( const PART_ID& aCadstarPartID ); + ROUTECODE getRouteCode( const ROUTECODE_ID& aCadstarRouteCodeID ); + TEXTCODE getTextCode( const TEXTCODE_ID& aCadstarTextCodeID ); + wxString getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID ); + wxString getAttributeValue( const ATTRIBUTE_ID& aCadstarAttributeID, + const std::map& aCadstarAttributeMap ); PART::DEFINITION::PIN getPartDefinitionPin( const PART& aCadstarPart, const GATE_ID& aGateID, const TERMINAL_ID& aTerminalID ); diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.cpp index 93d804c165..7b1ea15d5e 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_parser.cpp @@ -163,7 +163,7 @@ void CADSTAR_SCH_ARCHIVE_PARSER::TERMINAL_SHAPE::Parse( XNODE* aNode ) case TERMINAL_SHAPE_TYPE::DIAMOND: case TERMINAL_SHAPE_TYPE::OCTAGON: case TERMINAL_SHAPE_TYPE::SQUARE: - KI_FALLTHROUGH; //don't do anything + //don't do anything break; case TERMINAL_SHAPE_TYPE::UNDEFINED: