diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 7038af3279..8cb571e3b4 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -91,6 +91,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( ::SCHEMATIC* aSchematic, ::SCH_SHEET* aRo loadFigures(); loadTexts(); loadDocumentationSymbols(); + loadTextVariables(); if( Schematic.VariantHierarchy.Variants.size() > 0 ) { @@ -911,6 +912,66 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadDocumentationSymbols() } +void CADSTAR_SCH_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 = &mSchematic->Prj(); + + if( pj ) + { + std::map& txtVars = pj->GetTextVars(); + + // Most of the design text fields can be derived from other elements + if( Schematic.VariantHierarchy.Variants.size() > 0 ) + { + VARIANT loadedVar = Schematic.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_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdefID, const PART* aCadstarPart, const GATE_ID& aGateID, LIB_PART* aPart ) { diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h index de3a08b93a..94e813824c 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h @@ -108,6 +108,7 @@ private: void loadFigures(); void loadTexts(); void loadDocumentationSymbols(); + void loadTextVariables(); //Helper Functions for loading sheets void loadSheetAndChildSheets( LAYER_ID aCadstarSheetID, wxPoint aPosition, wxSize aSheetSize,