diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp index 7e3076e9d1..09bfb78fa7 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -96,7 +97,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::Load( ::BOARD* aBoard ) loadTemplates(); loadCoppers(); loadNets(); - + loadTextVariables(); if( Layout.Trunks.size() > 0 ) { @@ -109,8 +110,8 @@ void CADSTAR_PCB_ARCHIVE_LOADER::Load( ::BOARD* aBoard ) { wxLogWarning( wxString::Format( _( "The CADSTAR design contains variants which has no KiCad equivalent. Only " - "the master variant ('%s') was loaded." ), - Layout.VariantHierarchy.Variants.at( "V0" ).Name ) ); + "the variant '%s' was loaded." ), + Layout.VariantHierarchy.Variants.begin()->second.Name ) ); } if( Layout.ReuseBlocks.size() > 0 ) @@ -1648,6 +1649,69 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadNets() } +void CADSTAR_PCB_ARCHIVE_LOADER::loadTextVariables() +{ + auto findAndReplaceTextField = + [&]( TEXT_FIELD_NAME aField, wxString aValue ) + { + if( mContext.TextFieldToValuesMap.find( aField ) != + mContext.TextFieldToValuesMap.end() ) + { + if( mContext.TextFieldToValuesMap.at( aField ) != aValue ) + { + mContext.TextFieldToValuesMap.at( aField ) = aValue; + mContext.InconsistentTextFields.insert( aField ); + return false; + } + } + else + { + mContext.TextFieldToValuesMap.insert( { aField, aValue } ); + } + + return true; + }; + + PROJECT* pj = mBoard->GetProject(); + + if( pj ) + { + std::map& txtVars = pj->GetTextVars(); + + // Most of the design text fields can be derived from other elements + if( Layout.VariantHierarchy.Variants.size() > 0 ) + { + VARIANT loadedVar = Layout.VariantHierarchy.Variants.begin()->second; + + findAndReplaceTextField( TEXT_FIELD_NAME::VARIANT_NAME, loadedVar.Name ); + findAndReplaceTextField( TEXT_FIELD_NAME::VARIANT_DESCRIPTION, loadedVar.Description ); + } + + findAndReplaceTextField( TEXT_FIELD_NAME::DESIGN_TITLE, Header.JobTitle ); + + for( std::pair txtvalue : mContext.TextFieldToValuesMap ) + { + wxString varName = CadstarToKicadFieldsMap.at( txtvalue.first ); + wxString varValue = txtvalue.second; + + txtVars.insert( { varName, varValue } ); + } + + for( std::pair txtvalue : mContext.FilenamesToTextMap ) + { + wxString varName = txtvalue.first; + wxString varValue = txtvalue.second; + + txtVars.insert( { varName, varValue } ); + } + } + else + { + wxLogError( _( "Text Variables could not be set as there is no project attached." ) ); + } +} + + void CADSTAR_PCB_ARCHIVE_LOADER::loadComponentAttributes( const COMPONENT& aComponent, FOOTPRINT* aFootprint ) { diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.h b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.h index 6c0fdad2f5..3f84032d13 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.h +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.h @@ -127,6 +127,7 @@ private: void loadTemplates(); void loadCoppers(); void loadNets(); + void loadTextVariables(); // Helper functions for element loading: void logBoardStackupWarning( const wxString& aCadstarLayerName,