diff --git a/common/plugins/cadstar/cadstar_archive_parser.cpp b/common/plugins/cadstar/cadstar_archive_parser.cpp index a6a54f2075..8efa33d8fa 100644 --- a/common/plugins/cadstar/cadstar_archive_parser.cpp +++ b/common/plugins/cadstar/cadstar_archive_parser.cpp @@ -124,15 +124,21 @@ double CADSTAR_ARCHIVE_PARSER::EVALUE::GetDouble() void CADSTAR_ARCHIVE_PARSER::InsertAttributeAtEnd( XNODE* aNode, wxString aValue ) { - wxString result, paramName = "attr0"; - int i = 0; - - while( aNode->GetAttribute( paramName, &result ) ) + wxString result; + int numAttributes = 0; + + if( aNode->GetAttribute( wxT( "numAttributes" ), &result ) ) { - paramName = wxT( "attr" ); - paramName << i++; + numAttributes = wxAtoi( result ); + aNode->DeleteAttribute( wxT( "numAttributes" ) ); + ++numAttributes; } + aNode->AddAttribute( wxT( "numAttributes" ), wxString::Format( wxT( "%i" ), numAttributes ) ); + + wxString paramName = wxT( "attr" ); + paramName << numAttributes; + aNode->AddAttribute( paramName, aValue ); } @@ -226,6 +232,13 @@ XNODE* CADSTAR_ARCHIVE_PARSER::LoadArchiveFile( return NULL; } + +bool CADSTAR_ARCHIVE_PARSER::IsValidAttribute( wxXmlAttribute* aAttribute ) +{ + return aAttribute->GetName() != wxT( "numAttributes" ); +} + + wxString CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDString( XNODE* aNode, unsigned int aID ) { wxString attrName, retVal; diff --git a/common/plugins/cadstar/cadstar_archive_parser.h b/common/plugins/cadstar/cadstar_archive_parser.h index 8c6359ecc9..8e5a8cb1b4 100644 --- a/common/plugins/cadstar/cadstar_archive_parser.h +++ b/common/plugins/cadstar/cadstar_archive_parser.h @@ -163,6 +163,13 @@ public: */ static XNODE* LoadArchiveFile( const wxString& aFileName, const wxString& aFileTypeIdentifier ); + /** + * @brief + * @param aAttribute + * @return + */ + static bool IsValidAttribute( wxXmlAttribute* aAttribute ); + /** * @brief diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp index 54df29473e..182d4838f6 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp @@ -79,6 +79,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::Load( ::BOARD* aBoard ) loadComponentLibrary(); loadBoards(); loadFigures(); + loadTexts(); loadAreas(); loadComponents(); loadTemplates(); @@ -641,6 +642,106 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadFigures() } } +void CADSTAR_PCB_ARCHIVE_LOADER::loadTexts() +{ + for( std::pair txtPair : Layout.Texts ) + { + TEXT& csTxt = txtPair.second; + + TEXTE_PCB* txt = new TEXTE_PCB( mBoard ); + mBoard->Add( txt ); + txt->SetText( csTxt.Text ); + + /*wxPoint rotatedTextPos = getKiCadPoint( aCadstarAttrLoc.Position ) - aModule->GetPosition(); + RotatePoint( &rotatedTextPos, -aModule->GetOrientation() );*/ + + txt->SetTextPos( getKiCadPoint( csTxt.Position ) ); + txt->SetPosition( getKiCadPoint( csTxt.Position ) ); + + txt->SetMirrored( csTxt.Mirror ); + txt->SetTextAngle( getAngleTenthDegree( csTxt.OrientAngle ) ); + + TEXTCODE tc = getTextCode( csTxt.TextCodeID ); + + txt->SetTextThickness( getKiCadLength( tc.LineWidth ) ); + txt->SetTextSize( { getKiCadLength( tc.Width ), getKiCadLength( tc.Height ) } ); + + switch( csTxt.Alignment ) + { + case ALIGNMENT::NO_ALIGNMENT: // Default for Single line text is Bottom Left + case ALIGNMENT::BOTTOMLEFT: + txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); + txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); + break; + + case ALIGNMENT::BOTTOMCENTER: + txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); + txt->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); + break; + + case ALIGNMENT::BOTTOMRIGHT: + txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); + txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); + break; + + case ALIGNMENT::CENTERLEFT: + txt->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); + txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); + break; + + case ALIGNMENT::CENTERCENTER: + txt->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); + txt->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); + break; + + case ALIGNMENT::CENTERRIGHT: + txt->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); + txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); + break; + + case ALIGNMENT::TOPLEFT: + txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); + txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); + break; + + case ALIGNMENT::TOPCENTER: + txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); + txt->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); + break; + + case ALIGNMENT::TOPRIGHT: + txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); + txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); + break; + + default: + wxASSERT_MSG( true, "Unknown Aligment - needs review!" ); + } + + if( isLayerSet( csTxt.LayerID ) ) + { + //Make a copy on each layer + + LSEQ layers = getKiCadLayerSet( csTxt.LayerID ).Seq(); + TEXTE_PCB* newtxt; + + for( PCB_LAYER_ID layer : layers ) + { + txt->SetLayer( layer ); + newtxt = new TEXTE_PCB( *txt ); + mBoard->Add( newtxt, ADD_MODE::APPEND ); + } + + mBoard->Remove( txt ); + delete txt; + } + else + txt->SetLayer( getKiCadLayer( csTxt.LayerID ) ); + + //TODO Handle different font types when KiCad can support it. + } +} + void CADSTAR_PCB_ARCHIVE_LOADER::loadAreas() { @@ -1851,11 +1952,16 @@ NETINFO_ITEM* CADSTAR_PCB_ARCHIVE_LOADER::getKiCadNet( const NET_ID& aCadstarNet wxCHECK( Layout.Nets.find( aCadstarNetID ) != Layout.Nets.end(), nullptr ); NET csNet = Layout.Nets.at( aCadstarNetID ); + wxString newName = wxEmptyString; + + if( csNet.Name.IsEmpty() ) + newName = "CSNET" + ( csNet.SignalNum ); NETINFO_ITEM* netInfo = new NETINFO_ITEM( mBoard, csNet.Name, ++mNumNets ); mBoard->Add( netInfo, ADD_MODE::APPEND ); //todo also add the Netclass + mNetMap.insert( { aCadstarNetID, netInfo } ); return netInfo; } diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.h b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.h index 7f4af7255c..467230162a 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.h +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.h @@ -96,6 +96,7 @@ private: void loadComponentLibrary(); void loadBoards(); void loadFigures(); + void loadTexts(); void loadAreas(); void loadComponents(); void loadTemplates(); diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.cpp index 9a10330a3b..25eba11924 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_parser.cpp @@ -217,7 +217,10 @@ void CADSTAR_PCB_ARCHIVE_PARSER::LAYERDEFS::Parse( XNODE* aNode ) for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) { - LayerStack.push_back( (LAYER_ID) xmlAttribute->GetValue() ); + if( !IsValidAttribute( xmlAttribute ) ) + continue; + else + LayerStack.push_back( (LAYER_ID) xmlAttribute->GetValue() ); } CheckNoChildNodes( cNode ); @@ -1580,6 +1583,9 @@ void CADSTAR_PCB_ARCHIVE_PARSER::COMPONENT_COPPER::Parse( XNODE* aNode ) for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) { + if( !IsValidAttribute( xmlAttribute ) ) + continue; + long padId; if( !xmlAttribute->GetValue().ToLong( &padId ) ) @@ -1630,6 +1636,9 @@ void CADSTAR_PCB_ARCHIVE_PARSER::COMPONENT_AREA::Parse( XNODE* aNode ) for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) { + if( !IsValidAttribute( xmlAttribute ) ) + continue; + if( xmlAttribute->GetValue() == wxT( "NO_TRACKS" ) ) NoTracks = true; else if( xmlAttribute->GetValue() == wxT( "NO_VIAS" ) ) @@ -1654,6 +1663,9 @@ void CADSTAR_PCB_ARCHIVE_PARSER::PAD_EXITS::Parse( XNODE* aNode ) for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) { + if( !IsValidAttribute( xmlAttribute ) ) + continue; + if( xmlAttribute->GetValue() == wxT( "FREE" ) ) FreeAngle = true; else if( xmlAttribute->GetValue() == wxT( "N" ) ) @@ -2391,6 +2403,9 @@ void CADSTAR_PCB_ARCHIVE_PARSER::PART::DEFINITION::PIN_EQUIVALENCE::Parse( XNODE for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) { + if( !IsValidAttribute( xmlAttribute ) ) + continue; + long pinId; if( !xmlAttribute->GetValue().ToLong( &pinId ) ) @@ -2411,6 +2426,9 @@ void CADSTAR_PCB_ARCHIVE_PARSER::PART::DEFINITION::SWAP_GATE::Parse( XNODE* aNod for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) { + if( !IsValidAttribute( xmlAttribute ) ) + continue; + long pinId; if( !xmlAttribute->GetValue().ToLong( &pinId ) ) @@ -2636,6 +2654,9 @@ void CADSTAR_PCB_ARCHIVE_PARSER::AREA::Parse( XNODE* aNode ) for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) { + if( !IsValidAttribute( xmlAttribute ) ) + continue; + if( xmlAttribute->GetValue() == wxT( "PLACEMENT" ) ) Placement = true; else if( xmlAttribute->GetValue() == wxT( "ROUTING" ) )