From 6be3401b92363e483c585c9259c711811d66031d Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sun, 5 Jan 2025 21:59:01 +0000 Subject: [PATCH] Add more global extensions and switch archiver to use them --- common/design_block_lib_table.cpp | 7 ++----- common/fp_lib_table.cpp | 7 ++----- common/project.cpp | 6 +++--- common/project/project_archiver.cpp | 24 ++++++++++++------------ common/settings/settings_manager.cpp | 4 ++-- common/wildcards_and_files_ext.cpp | 8 ++++++++ eeschema/eeschema.cpp | 2 +- eeschema/sim/sim_library.cpp | 3 ++- eeschema/symbol_lib_table.cpp | 12 ++++-------- eeschema/symbol_lib_table.h | 2 +- include/wildcards_and_files_ext.h | 8 ++++++++ kicad/tools/kicad_manager_control.cpp | 4 ++-- pcbnew/pcbnew.cpp | 2 +- 13 files changed, 48 insertions(+), 41 deletions(-) diff --git a/common/design_block_lib_table.cpp b/common/design_block_lib_table.cpp index 3623c8300a..71524f721e 100644 --- a/common/design_block_lib_table.cpp +++ b/common/design_block_lib_table.cpp @@ -56,9 +56,6 @@ DESIGN_BLOCK_LIST_IMPL GDesignBlockList; using namespace LIB_TABLE_T; -static const wxChar global_tbl_name[] = wxT( "design-block-lib-table" ); - - bool DESIGN_BLOCK_LIB_TABLE_ROW::operator==( const DESIGN_BLOCK_LIB_TABLE_ROW& aRow ) const { return LIB_TABLE_ROW::operator==( aRow ) && type == aRow.type; @@ -612,7 +609,7 @@ bool DESIGN_BLOCK_LIB_TABLE::LoadGlobalTable( DESIGN_BLOCK_LIB_TABLE& aTable ) if( v && !v->IsEmpty() ) ss.AddPaths( *v, 0 ); - wxString fileName = ss.FindValidPath( global_tbl_name ); + wxString fileName = ss.FindValidPath( FILEEXT::DesignBlockLibraryTableFileName ); // The fallback is to create an empty global design block table for the user to populate. if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) ) @@ -691,7 +688,7 @@ wxString DESIGN_BLOCK_LIB_TABLE::GetGlobalTableFileName() wxFileName fn; fn.SetPath( PATHS::GetUserSettingsPath() ); - fn.SetName( global_tbl_name ); + fn.SetName( FILEEXT::DesignBlockLibraryTableFileName ); return fn.GetFullPath(); } diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index f3f97c4106..dc70b0f476 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -46,9 +46,6 @@ using namespace LIB_TABLE_T; -static const wxChar global_tbl_name[] = wxT( "fp-lib-table" ); - - bool FP_LIB_TABLE_ROW::operator==( const FP_LIB_TABLE_ROW& aRow ) const { return LIB_TABLE_ROW::operator == ( aRow ) && type == aRow.type; @@ -608,7 +605,7 @@ bool FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) if( v && !v->IsEmpty() ) ss.AddPaths( *v, 0 ); - wxString fileName = ss.FindValidPath( global_tbl_name ); + wxString fileName = ss.FindValidPath( FILEEXT::FootprintLibraryTableFileName ); // The fallback is to create an empty global footprint table for the user to populate. if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) ) @@ -673,7 +670,7 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName() wxFileName fn; fn.SetPath( PATHS::GetUserSettingsPath() ); - fn.SetName( global_tbl_name ); + fn.SetName( FILEEXT::FootprintLibraryTableFileName ); return fn.GetFullPath(); } diff --git a/common/project.cpp b/common/project.cpp index 8ccdef89e6..3cbe0ef677 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -158,19 +158,19 @@ bool PROJECT::IsNullProject() const const wxString PROJECT::SymbolLibTableName() const { - return libTableName( wxS( "sym-lib-table" ) ); + return libTableName( FILEEXT::SymbolLibraryTableFileName ); } const wxString PROJECT::FootprintLibTblName() const { - return libTableName( wxS( "fp-lib-table" ) ); + return libTableName( FILEEXT::FootprintLibraryTableFileName ); } const wxString PROJECT::DesignBlockLibTblName() const { - return libTableName( wxS( "design-block-lib-table" ) ); + return libTableName( FILEEXT::DesignBlockLibraryTableFileName ); } diff --git a/common/project/project_archiver.cpp b/common/project/project_archiver.cpp index c8011f03a3..e584d16629 100644 --- a/common/project/project_archiver.cpp +++ b/common/project/project_archiver.cpp @@ -174,8 +174,8 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi { #define EXT( ext ) "\\." + ext + "|" -#define NAME( name ) name "|" -#define EXT_NO_PIPE( ext ) "\\." ext +#define NAME( name ) name + "|" +#define EXT_NO_PIPE( ext ) "\\." + ext #define NAME_NO_PIPE( name ) name // List of file extensions that are always archived @@ -190,10 +190,10 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi EXT( FILEEXT::DrawingSheetFileExtension ) EXT( FILEEXT::KiCadJobSetFileExtension ) EXT( FILEEXT::JsonFileExtension ) // for design blocks - EXT( FILEEXT::WorkbookFileExtension ) - NAME( "fp-lib-table" ) - NAME( "sym-lib-table" ) - NAME_NO_PIPE( "design-block-lib-table" ); + EXT( FILEEXT::WorkbookFileExtension ) + + NAME( FILEEXT::FootprintLibraryTableFileName ) + + NAME( FILEEXT::SymbolLibraryTableFileName ) + + NAME_NO_PIPE( FILEEXT::DesignBlockLibraryTableFileName ); // List of additional file extensions that are only archived when aIncludeExtraFiles is true if( aIncludeExtraFiles ) @@ -217,14 +217,14 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi EXT( "xnc" ) // Fab drill files EXT( FILEEXT::IpcD356FileExtension ) EXT( FILEEXT::ReportFileExtension ) - EXT( "net" ) - EXT( "py" ) + EXT( FILEEXT::NetlistFileExtension ) + EXT( FILEEXT::PythonFileExtension ) EXT( FILEEXT::PdfFileExtension ) EXT( FILEEXT::TextFileExtension ) EXT( FILEEXT::SpiceFileExtension ) // SPICE files - EXT( "sub" ) // SPICE files - EXT( "model" ) // SPICE files - EXT_NO_PIPE( "ibs" ); + EXT( FILEEXT::SpiceSubcircuitFileExtension ) // SPICE files + EXT( FILEEXT::SpiceModelFileExtension ) // SPICE files + EXT_NO_PIPE( FILEEXT::IbisFileExtension ); } fileExtensionRegex += ")"; @@ -276,7 +276,7 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi for( unsigned ii = 0; ii < files.GetCount(); ++ii ) { - if( files[ii].EndsWith( wxS( ".ibs" ) ) ) + if( files[ii].EndsWith( FILEEXT::IbisFileExtension ) ) { wxFileName package( files[ ii ] ); package.MakeRelativeTo( aSrcDir ); diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index c7e676ba76..109aad6849 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -484,8 +484,8 @@ public: { wxFileName file( aSrcFilePath ); - if( !m_migrateTables && ( file.GetName() == wxT( "sym-lib-table" ) || - file.GetName() == wxT( "fp-lib-table" ) ) ) + if( !m_migrateTables && ( file.GetName() == FILEEXT::SymbolLibraryTableFileName || + file.GetName() == FILEEXT::FootprintLibraryTableFileName ) ) { return wxDIR_CONTINUE; } diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp index e48965802b..0e6c5a7ba9 100644 --- a/common/wildcards_and_files_ext.cpp +++ b/common/wildcards_and_files_ext.cpp @@ -142,6 +142,9 @@ const std::string FILEEXT::CadstarSchematicFileExtension( "csa" ); const std::string FILEEXT::CadstarPartsLibraryFileExtension( "lib" ); const std::string FILEEXT::KiCadSchematicFileExtension( "kicad_sch" ); const std::string FILEEXT::SpiceFileExtension( "cir" ); +const std::string FILEEXT::SpiceModelFileExtension( "model" ); +const std::string FILEEXT::SpiceSubcircuitFileExtension( "sub" ); +const std::string FILEEXT::IbisFileExtension( "ibs" ); const std::string FILEEXT::CadstarNetlistFileExtension( "frp" ); const std::string FILEEXT::OrCadPcb2NetlistFileExtension( "net" ); const std::string FILEEXT::NetlistFileExtension( "net" ); @@ -197,6 +200,7 @@ const std::string FILEEXT::MarkdownFileExtension( "md" ); const std::string FILEEXT::CsvFileExtension( "csv" ); const std::string FILEEXT::XmlFileExtension( "xml" ); const std::string FILEEXT::JsonFileExtension( "json" ); +const std::string FILEEXT::PythonFileExtension( "py" ); const std::string FILEEXT::StepFileExtension( "step" ); const std::string FILEEXT::StepFileAbrvExtension( "stp" ); @@ -208,6 +212,10 @@ const std::string FILEEXT::StlFileExtension( "stl" ); const wxString FILEEXT::GerberFileExtensionsRegex( "(gbr|gko|pho|(g[tb][alops])|(gm?\\d\\d*)|(gp[tb]))" ); +const std::string FILEEXT::FootprintLibraryTableFileName( "fp-lib-table" ); +const std::string FILEEXT::SymbolLibraryTableFileName( "sym-lib-table" ); +const std::string FILEEXT::DesignBlockLibraryTableFileName( "design-block-lib-table" ); + const std::string FILEEXT::KiCadUriPrefix( "kicad-embed" ); diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 03029ca5fd..2f8e933b6c 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -643,7 +643,7 @@ void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aProje aErrors += msg; } } - else if( destFile.GetName() == wxS( "sym-lib-table" ) ) + else if( destFile.GetName() == FILEEXT::SymbolLibraryTableFileName ) { SYMBOL_LIB_TABLE symbolLibTable; symbolLibTable.Load( aSrcFilePath ); diff --git a/eeschema/sim/sim_library.cpp b/eeschema/sim/sim_library.cpp index 0163b83c47..2567c26c7f 100644 --- a/eeschema/sim/sim_library.cpp +++ b/eeschema/sim/sim_library.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -35,7 +36,7 @@ SIM_LIBRARY::Create( const wxString& aFilePath, bool aForceFullParse, REPORTER& { std::unique_ptr library; - if( aFilePath.EndsWith( ".ibs" ) ) + if( aFilePath.EndsWith( FILEEXT::IbisFileExtension ) ) library = std::make_unique(); else library = std::make_unique( aForceFullParse ); diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index b39f11b31e..62554ce950 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -45,10 +45,6 @@ using namespace LIB_TABLE_T; - -static const wxString global_tbl_name( "sym-lib-table" ); - - const char* SYMBOL_LIB_TABLE::PropPowerSymsOnly = "pwr_sym_only"; const char* SYMBOL_LIB_TABLE::PropNonPowerSymsOnly = "non_pwr_sym_only"; int SYMBOL_LIB_TABLE::m_modifyHash = 1; // starts at 1 and goes up @@ -651,7 +647,7 @@ bool SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE& aTable ) if( v && !v->IsEmpty() ) ss.AddPaths( *v, 0 ); - wxString fileName = ss.FindValidPath( global_tbl_name ); + wxString fileName = ss.FindValidPath( FILEEXT::SymbolLibraryTableFileName ); // The fallback is to create an empty global symbol table for the user to populate. if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) ) @@ -743,13 +739,13 @@ wxString SYMBOL_LIB_TABLE::GetGlobalTableFileName() wxFileName fn; fn.SetPath( PATHS::GetUserSettingsPath() ); - fn.SetName( global_tbl_name ); + fn.SetName( FILEEXT::SymbolLibraryTableFileName ); return fn.GetFullPath(); } -const wxString& SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() +const wxString SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() { - return global_tbl_name; + return FILEEXT::SymbolLibraryTableFileName; } diff --git a/eeschema/symbol_lib_table.h b/eeschema/symbol_lib_table.h index c7f0247d86..cdfbff340d 100644 --- a/eeschema/symbol_lib_table.h +++ b/eeschema/symbol_lib_table.h @@ -319,7 +319,7 @@ public: static SYMBOL_LIB_TABLE& GetGlobalLibTable(); - static const wxString& GetSymbolLibTableFileName(); + static const wxString GetSymbolLibTableFileName(); /** * Compares this table against another. diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index dcb726113b..a798c81046 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -131,7 +131,10 @@ public: static const std::string CadstarSchematicFileExtension; static const std::string CadstarPartsLibraryFileExtension; static const std::string KiCadSchematicFileExtension; + static const std::string IbisFileExtension; static const std::string SpiceFileExtension; + static const std::string SpiceModelFileExtension; + static const std::string SpiceSubcircuitFileExtension; static const std::string CadstarNetlistFileExtension; static const std::string OrCadPcb2NetlistFileExtension; static const std::string NetlistFileExtension; @@ -186,6 +189,7 @@ public: static const std::string CsvFileExtension; static const std::string XmlFileExtension; static const std::string JsonFileExtension; + static const std::string PythonFileExtension; static const std::string StepFileExtension; static const std::string StepFileAbrvExtension; @@ -199,6 +203,10 @@ public: static const wxString GerberFileExtensionsRegex; + static const std::string FootprintLibraryTableFileName; + static const std::string SymbolLibraryTableFileName; + static const std::string DesignBlockLibraryTableFileName; + static const std::string KiCadUriPrefix; /** diff --git a/kicad/tools/kicad_manager_control.cpp b/kicad/tools/kicad_manager_control.cpp index f3a31dd974..fc81872ea7 100644 --- a/kicad/tools/kicad_manager_control.cpp +++ b/kicad/tools/kicad_manager_control.cpp @@ -533,7 +533,7 @@ public: || ext == FILEEXT::LegacySymbolDocumentFileExtension || ext == FILEEXT::KiCadSymbolLibFileExtension || ext == FILEEXT::NetlistFileExtension - || destFile.GetName() == "sym-lib-table" ) + || destFile.GetName() == FILEEXT::SymbolLibraryTableFileName ) { KIFACE* eeschema = m_frame->Kiway().KiFACE( KIWAY::FACE_SCH ); eeschema->SaveFileAs( m_projectDirPath, m_projectName, m_newProjectDirPath, @@ -545,7 +545,7 @@ public: || ext == FILEEXT::KiCadFootprintFileExtension || ext == FILEEXT::LegacyFootprintLibPathExtension || ext == FILEEXT::FootprintAssignmentFileExtension - || destFile.GetName() == "fp-lib-table" ) + || destFile.GetName() == FILEEXT::FootprintLibraryTableFileName ) { KIFACE* pcbnew = m_frame->Kiway().KiFACE( KIWAY::FACE_PCB ); pcbnew->SaveFileAs( m_projectDirPath, m_projectName, m_newProjectDirPath, diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 6261356284..3c696eb4e9 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -547,7 +547,7 @@ void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aSrcPr // name. KiCopyFile( aSrcFilePath, destFile.GetFullPath(), aErrors ); } - else if( destFile.GetName() == wxT( "fp-lib-table" ) ) + else if( destFile.GetName() == FILEEXT::FootprintLibraryTableFileName ) { try {