diff --git a/common/jobs/job_fp_upgrade.h b/common/jobs/job_fp_upgrade.h index fb0f1c6923..48f8c7a91b 100644 --- a/common/jobs/job_fp_upgrade.h +++ b/common/jobs/job_fp_upgrade.h @@ -30,11 +30,13 @@ public: JOB_FP_UPGRADE( bool aIsCli ) : JOB( "fpupgrade", aIsCli ), m_libraryPath(), + m_outputLibraryPath(), m_force( false ) { } wxString m_libraryPath; + wxString m_outputLibraryPath; bool m_force; }; diff --git a/common/jobs/job_sym_upgrade.h b/common/jobs/job_sym_upgrade.h index 77900396eb..44884a3069 100644 --- a/common/jobs/job_sym_upgrade.h +++ b/common/jobs/job_sym_upgrade.h @@ -30,11 +30,13 @@ public: JOB_SYM_UPGRADE( bool aIsCli ) : JOB( "symupgrade", aIsCli ), m_libraryPath(), + m_outputLibraryPath(), m_force( false ) { } wxString m_libraryPath; + wxString m_outputLibraryPath; bool m_force; }; diff --git a/common/wx_filename.cpp b/common/wx_filename.cpp index 3ed6d18fbf..bb9c841d77 100644 --- a/common/wx_filename.cpp +++ b/common/wx_filename.cpp @@ -37,6 +37,13 @@ void WX_FILENAME::SetFullName( const wxString& aFileNameAndExtension ) } +void WX_FILENAME::SetPath( const wxString& aPath ) +{ + m_fn.SetPath( aPath ); + m_path = aPath; +} + + wxString WX_FILENAME::GetName() const { size_t dot = m_fullName.find_last_of( wxT( '.' ) ); diff --git a/eeschema/eeschema_jobs_handler.cpp b/eeschema/eeschema_jobs_handler.cpp index 15a1830c4e..47389d9cf6 100644 --- a/eeschema/eeschema_jobs_handler.cpp +++ b/eeschema/eeschema_jobs_handler.cpp @@ -338,6 +338,15 @@ int EESCHEMA_JOBS_HANDLER::JobExportSymLibUpgrade( JOB* aJob ) return CLI::EXIT_CODES::ERR_UNKNOWN; } + if( !upgradeJob->m_outputLibraryPath.IsEmpty() ) + { + if( wxFile::Exists( upgradeJob->m_outputLibraryPath ) ) + { + wxFprintf( stderr, _( "Output path must not conflict with existing path\n" ) ); + return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT; + } + } + bool shouldSave = upgradeJob->m_force || schLibrary.GetFileFormatVersionAtLoad() < SEXPR_SYMBOL_LIB_FILE_VERSION; @@ -347,6 +356,11 @@ int EESCHEMA_JOBS_HANDLER::JobExportSymLibUpgrade( JOB* aJob ) try { + if( !upgradeJob->m_outputLibraryPath.IsEmpty() ) + { + schLibrary.SetFileName( upgradeJob->m_outputLibraryPath ); + } + schLibrary.SetModified(); schLibrary.Save(); } diff --git a/include/wx_filename.h b/include/wx_filename.h index a66f60cd91..201d8375d6 100644 --- a/include/wx_filename.h +++ b/include/wx_filename.h @@ -51,6 +51,7 @@ public: WX_FILENAME( const wxString& aPath, const wxString& aFilename ); void SetFullName( const wxString& aFileNameAndExtension ); + void SetPath( const wxString& aPath ); wxString GetName() const; wxString GetFullName() const; diff --git a/kicad/cli/command_fp_upgrade.cpp b/kicad/cli/command_fp_upgrade.cpp index b20a1ef671..83537f25d8 100644 --- a/kicad/cli/command_fp_upgrade.cpp +++ b/kicad/cli/command_fp_upgrade.cpp @@ -45,6 +45,8 @@ int CLI::FP_UPGRADE_COMMAND::Perform( KIWAY& aKiway ) std::unique_ptr fpJob = std::make_unique( true ); fpJob->m_libraryPath = FROM_UTF8( m_argParser.get( ARG_INPUT ).c_str() ); + fpJob->m_outputLibraryPath = FROM_UTF8( m_argParser.get( ARG_OUTPUT ).c_str() ); + fpJob->m_force = m_argParser.get( ARG_FORCE ); if( !wxDir::Exists( fpJob->m_libraryPath ) ) { diff --git a/kicad/cli/command_sym_upgrade.cpp b/kicad/cli/command_sym_upgrade.cpp index ba3b90c539..661b7dd8c0 100644 --- a/kicad/cli/command_sym_upgrade.cpp +++ b/kicad/cli/command_sym_upgrade.cpp @@ -45,6 +45,8 @@ int CLI::SYM_UPGRADE_COMMAND::Perform( KIWAY& aKiway ) std::unique_ptr symJob = std::make_unique( true ); symJob->m_libraryPath = FROM_UTF8( m_argParser.get( ARG_INPUT ).c_str() ); + symJob->m_outputLibraryPath = FROM_UTF8( m_argParser.get( ARG_OUTPUT ).c_str() ); + symJob->m_force = m_argParser.get( ARG_FORCE ); if( !wxFile::Exists( symJob->m_libraryPath ) ) { diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index 61d3df77f2..4b2c7593e3 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -480,6 +481,16 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob ) if( aJob->IsCli() ) wxPrintf( _( "Loading board\n" ) ); + if( !upgradeJob->m_outputLibraryPath.IsEmpty() ) + { + if( wxFile::Exists( upgradeJob->m_outputLibraryPath ) || + wxDir::Exists( upgradeJob->m_outputLibraryPath) ) + { + wxFprintf( stderr, _( "Output path must not conflict with existing path\n" ) ); + return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT; + } + } + PCB_PLUGIN pcb_io( CTL_FOR_LIBRARY ); FP_CACHE fpLib( &pcb_io, upgradeJob->m_libraryPath ); @@ -509,6 +520,11 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob ) try { + if( !upgradeJob->m_outputLibraryPath.IsEmpty() ) + { + fpLib.SetPath( upgradeJob->m_outputLibraryPath ); + } + fpLib.Save(); } catch( ... ) diff --git a/pcbnew/plugins/kicad/pcb_plugin.cpp b/pcbnew/plugins/kicad/pcb_plugin.cpp index f30f8da710..f08476a6f5 100644 --- a/pcbnew/plugins/kicad/pcb_plugin.cpp +++ b/pcbnew/plugins/kicad/pcb_plugin.cpp @@ -232,6 +232,19 @@ bool FP_CACHE::IsPath( const wxString& aPath ) const } +void FP_CACHE::SetPath( const wxString& aPath ) +{ + m_lib_raw_path = aPath; + m_lib_path.SetPath( aPath ); + + + for( auto& footprint : GetFootprints() ) + { + footprint.second->SetFilePath( aPath ); + } +} + + bool FP_CACHE::IsModified() { m_cache_dirty = m_cache_dirty || GetTimestamp( m_lib_path.GetFullPath() ) != m_cache_timestamp; diff --git a/pcbnew/plugins/kicad/pcb_plugin.h b/pcbnew/plugins/kicad/pcb_plugin.h index c7988abe1f..4b2df16634 100644 --- a/pcbnew/plugins/kicad/pcb_plugin.h +++ b/pcbnew/plugins/kicad/pcb_plugin.h @@ -179,6 +179,7 @@ public: FP_CACHE_ITEM( FOOTPRINT* aFootprint, const WX_FILENAME& aFileName ); const WX_FILENAME& GetFileName() const { return m_filename; } + void SetFilePath( const wxString& aFilePath ) { m_filename.SetPath( aFilePath ); } const FOOTPRINT* GetFootprint() const { return m_footprint.get(); } }; @@ -246,6 +247,8 @@ public: * @return true if \a aPath is the same as the cache path. */ bool IsPath( const wxString& aPath ) const; + + void SetPath( const wxString& aPath ); };