diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index d8ef448b4f..e1148068c2 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -85,6 +85,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( ::SCHEMATIC* aSchematic, ::SCH_SHEET* aRo loadBusses(); loadNets(); loadFigures(); + loadTexts(); // TODO Load other elements! // For all sheets, centre all elements and re calculate the page size: @@ -639,23 +640,19 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadFigures() { FIGURE fig = figPair.second; - if( fig.LayerID == "ALL_SHEETS" ) - { - for( std::pair sheetPair : Sheets.SheetNames ) - { - LAYER_ID sheetID = sheetPair.first; + loadFigure( fig, fig.LayerID, LAYER_NOTES ); + } +} - 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::loadTexts() +{ + for( std::pair textPair : Schematic.Texts ) + { + TEXT txt = textPair.second; + + SCH_TEXT* kiTxt = getKiCadSchText( txt ); + loadItemOntoKiCadSheet( txt.LayerID, kiTxt ); } } @@ -1100,15 +1097,21 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector& a prev = cur; - if( mSheetMap.find( aCadstarSheetID ) != mSheetMap.end() ) - { - mSheetMap.at( aCadstarSheetID )->GetScreen()->Append( segment ); - } - else - { - delete segment; - wxASSERT_MSG( false, "Unknown Sheet ID." ); - } + loadItemOntoKiCadSheet( aCadstarSheetID, segment ); + } +} + + +void CADSTAR_SCH_ARCHIVE_LOADER::loadFigure( const FIGURE& aCadstarFigure, + const LAYER_ID& aCadstarSheetIDOverride, SCH_LAYER_ID aKiCadSchLayerID ) +{ + loadShapeVertices( aCadstarFigure.Shape.Vertices, aCadstarFigure.LineCodeID, + aCadstarFigure.LayerID, aKiCadSchLayerID ); + + for( CUTOUT cutout : aCadstarFigure.Shape.Cutouts ) + { + loadShapeVertices( cutout.Vertices, aCadstarFigure.LineCodeID, aCadstarFigure.LayerID, + aKiCadSchLayerID ); } } @@ -1248,6 +1251,45 @@ int CADSTAR_SCH_ARCHIVE_LOADER::getSheetNumber( LAYER_ID aCadstarSheetID ) } +void CADSTAR_SCH_ARCHIVE_LOADER::loadItemOntoKiCadSheet( LAYER_ID aCadstarSheetID, SCH_ITEM* aItem ) +{ + wxCHECK_MSG( aItem, /*void*/, "aItem is null" ); + + if( aCadstarSheetID == "ALL_SHEETS" ) + { + SCH_ITEM* duplicateItem; + + for( std::pair sheetPair : Sheets.SheetNames ) + { + LAYER_ID sheetID = sheetPair.first; + duplicateItem = aItem->Duplicate(); + mSheetMap.at( sheetID )->GetScreen()->Append( aItem->Duplicate() ); + } + + //Get rid of the extra copy: + delete aItem; + aItem = duplicateItem; + } + else if( aCadstarSheetID == "NO_SHEET" ) + { + wxASSERT_MSG( + false, "Trying to add an item to NO_SHEET? This might be a documentation symbol." ); + } + else + { + if( mSheetMap.find( aCadstarSheetID ) != mSheetMap.end() ) + { + mSheetMap.at( aCadstarSheetID )->GetScreen()->Append( aItem ); + } + else + { + delete aItem; + wxASSERT_MSG( false, "Unknown Sheet ID." ); + } + } +} + + CADSTAR_SCH_ARCHIVE_LOADER::SYMDEF_ID CADSTAR_SCH_ARCHIVE_LOADER::getSymDefFromName( const wxString& aSymdefName, const wxString& aSymDefAlternate ) { @@ -1484,6 +1526,20 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( const TEXTCODE_ID& aCadstarT } } +SCH_TEXT* CADSTAR_SCH_ARCHIVE_LOADER::getKiCadSchText( const TEXT& aCadstarTextElement ) +{ + SCH_TEXT* kiTxt = new SCH_TEXT(); + + kiTxt->SetPosition( getKiCadPoint( aCadstarTextElement.Position ) ); + kiTxt->SetText( aCadstarTextElement.Text ); + applyTextSettings( aCadstarTextElement.TextCodeID, aCadstarTextElement.Alignment, + aCadstarTextElement.Justification, kiTxt ); + kiTxt->SetTextAngle( getAngleTenthDegree( aCadstarTextElement.OrientAngle ) ); + kiTxt->SetMirrored( aCadstarTextElement.Mirror ); + + return kiTxt; +} + std::pair CADSTAR_SCH_ARCHIVE_LOADER::getFigureExtentsKiCad( const FIGURE& aCadstarFigure ) diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h index 3ced72b373..14c53e8215 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h @@ -37,10 +37,12 @@ class LABEL_SPIN_STYLE; class LIB_FIELD; class LIB_PART; class SCH_COMPONENT; +class SCH_ITEM; class SCH_FIELD; class SCH_GLOBALLABEL; class SCH_HIERLABEL; class SCH_SHEET; +class SCH_TEXT; class SCHEMATIC; class CADSTAR_SCH_ARCHIVE_LOADER : public CADSTAR_SCH_ARCHIVE_PARSER @@ -100,6 +102,7 @@ private: void loadBusses(); void loadNets(); void loadFigures(); + void loadTexts(); //Helper Functions for loading sheets void loadSheetAndChildSheets( LAYER_ID aCadstarSheetID, wxPoint aPosition, wxSize aSheetSize, @@ -107,6 +110,7 @@ private: void loadChildSheets( LAYER_ID aCadstarSheetID ); std::vector findOrphanSheets(); int getSheetNumber( LAYER_ID aCadstarSheetID ); + void loadItemOntoKiCadSheet( LAYER_ID aCadstarSheetID, SCH_ITEM* aItem ); //Helper Functions for loading library items void loadSymDefIntoLibrary( const SYMDEF_ID& aSymdefID, const PART* aCadstarPart, @@ -132,6 +136,8 @@ private: void loadShapeVertices( const std::vector& aCadstarVertices, LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID ); + void loadFigure( const FIGURE& aCadstarFigure, const LAYER_ID& aCadstarSheetIDOverride, + SCH_LAYER_ID aKiCadSchLayerID ); //Helper Functions for obtaining CADSTAR elements from the parsed structures SYMDEF_ID getSymDefFromName( const wxString& aSymdefName, const wxString& aSymDefAlternate ); @@ -155,6 +161,8 @@ private: void applyTextSettings( const TEXTCODE_ID& aCadstarTextCodeID, const ALIGNMENT& aCadstarAlignment, const JUSTIFICATION& aCadstarJustification, EDA_TEXT* aKiCadTextItem ); + SCH_TEXT* getKiCadSchText( const TEXT& aCadstarTextElement ); + std::pair getFigureExtentsKiCad( const FIGURE& aCadstarFigure );