diff --git a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp index 2898064b87..1f1c4f5a35 100644 --- a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp @@ -56,6 +56,26 @@ const wxString PartVersionFieldName = "Part Version"; const wxString PartAcceptanceFieldName = "Part Acceptance"; +wxString CADSTAR_SCH_ARCHIVE_LOADER::CreateLibName( const wxFileName& aFileName, + const SCH_SHEET* aRootSheet ) +{ + wxString libName = aFileName.GetName(); + + if( libName.IsEmpty() && aRootSheet ) + { + wxFileName fn( aRootSheet->GetFileName() ); + libName = fn.GetName(); + } + + if( libName.IsEmpty() ) + libName = "noname"; + + libName = LIB_ID::FixIllegalChars( libName, true ).wx_str(); + + return libName; +} + + std::vector CADSTAR_SCH_ARCHIVE_LOADER::LoadPartsLib( const wxString& aFilename ) { if( m_progressReporter ) @@ -2067,8 +2087,11 @@ SCH_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbol( const SYMBOL& aCads const LIB_SYMBOL& aKiCadPart, EDA_ANGLE& aComponentOrientation ) { + wxString libName = CreateLibName( m_footprintLibName, m_rootSheet ); + LIB_ID libId; libId.SetLibItemName( aKiCadPart.GetName() ); + libId.SetLibNickname( libName ); int unit = getKiCadUnitNumberFromGate( aCadstarSymbol.GateID ); diff --git a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.h b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.h index 4ad4b3642a..9c719f5181 100644 --- a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.h +++ b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.h @@ -71,6 +71,7 @@ public: m_designCenter.y = 0; m_reporter = aReporter; m_progressReporter = aProgressReporter; + m_fileName = aFilename; // Assume that the PCB footprint library name will be the same as the schematic filename wxFileName schFilename( Filename ); @@ -96,6 +97,7 @@ public: */ void Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet ); + static wxString CreateLibName( const wxFileName& aFileName, const SCH_SHEET* aRootSheet ); private: typedef std::pair BLOCK_PIN_ID; @@ -112,6 +114,7 @@ private: REPORTER* m_reporter; SCHEMATIC* m_schematic; SCH_SHEET* m_rootSheet; + wxFileName m_fileName; wxString m_footprintLibName; ///< Name of the footprint library to prepend all footprints with /** diff --git a/eeschema/sch_io/cadstar/sch_io_cadstar_archive.cpp b/eeschema/sch_io/cadstar/sch_io_cadstar_archive.cpp index 34f24b10b1..d880943aee 100644 --- a/eeschema/sch_io/cadstar/sch_io_cadstar_archive.cpp +++ b/eeschema/sch_io/cadstar/sch_io_cadstar_archive.cpp @@ -98,19 +98,8 @@ SCH_SHEET* SCH_IO_CADSTAR_ARCHIVE::LoadSchematicFile( const wxString& aFi wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." ); - // Lets come up with a nice library name - wxString libName = aSchematic->Prj().GetProjectName(); - - if( libName.IsEmpty() ) - { - wxFileName fn( rootSheet->GetFileName() ); - libName = fn.GetName(); - } - - if( libName.IsEmpty() ) - libName = "noname"; - - libName = LIB_ID::FixIllegalChars( libName, true ).wx_str(); + wxFileName fn = aSchematic->Prj().GetProjectFullName(); + wxString libName = CADSTAR_SCH_ARCHIVE_LOADER::CreateLibName( fn, nullptr ); wxFileName libFileName( aSchematic->Prj().GetProjectPath(), libName, FILEEXT::KiCadSymbolLibFileExtension );