diff --git a/common/jobs/job_fp_upgrade.cpp b/common/jobs/job_fp_upgrade.cpp index 10cfbc4ee0..e9c810a01b 100644 --- a/common/jobs/job_fp_upgrade.cpp +++ b/common/jobs/job_fp_upgrade.cpp @@ -25,6 +25,7 @@ JOB_FP_UPGRADE::JOB_FP_UPGRADE( bool aIsCli ) : JOB( "fpupgrade", aIsCli ), m_libraryPath(), m_outputLibraryPath(), - m_force( false ) + m_force( false ), + m_no_uuid_gen( false ) { } \ No newline at end of file diff --git a/common/jobs/job_fp_upgrade.h b/common/jobs/job_fp_upgrade.h index 0e96de0db9..7ee9a19b8b 100644 --- a/common/jobs/job_fp_upgrade.h +++ b/common/jobs/job_fp_upgrade.h @@ -34,6 +34,7 @@ public: wxString m_outputLibraryPath; bool m_force; + bool m_no_uuid_gen; }; #endif \ No newline at end of file diff --git a/kicad/cli/command_fp_upgrade.cpp b/kicad/cli/command_fp_upgrade.cpp index c97473d224..16fb68b119 100644 --- a/kicad/cli/command_fp_upgrade.cpp +++ b/kicad/cli/command_fp_upgrade.cpp @@ -29,6 +29,7 @@ #include #define ARG_FORCE "--force" +#define ARG_NO_UUID_GEN "--no-uuid-gen" CLI::FP_UPGRADE_COMMAND::FP_UPGRADE_COMMAND() : PCB_EXPORT_BASE_COMMAND( "upgrade", true, true ) { @@ -39,6 +40,11 @@ CLI::FP_UPGRADE_COMMAND::FP_UPGRADE_COMMAND() : PCB_EXPORT_BASE_COMMAND( "upgrad .help( UTF8STDSTR( _( "Forces the footprint library to be resaved regardless of versioning" ) ) ) .flag(); + + m_argParser.add_argument( ARG_NO_UUID_GEN ) + .help( UTF8STDSTR( + _( "Do not automatically generate UUIDs if they are not present" ) ) ) + .flag(); } @@ -49,6 +55,7 @@ int CLI::FP_UPGRADE_COMMAND::doPerform( KIWAY& aKiway ) fpJob->m_libraryPath = m_argInput; fpJob->m_outputLibraryPath = m_argOutput; fpJob->m_force = m_argParser.get( ARG_FORCE ); + fpJob->m_no_uuid_gen = m_argParser.get( ARG_NO_UUID_GEN ); int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, fpJob.get() ); diff --git a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.cpp b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.cpp index d198b48a00..3b4a5bded7 100644 --- a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.cpp +++ b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.cpp @@ -887,7 +887,9 @@ void PCB_IO_KICAD_SEXPR::format( const PCB_DIMENSION_BASE* aDimension, int aNest formatLayer( aDimension->GetLayer() ); - KICAD_FORMAT::FormatUuid( m_out, aDimension->m_Uuid ); + if(!this->m_no_generate_uuid) { + KICAD_FORMAT::FormatUuid( m_out, aDimension->m_Uuid ); + } m_out->Print( aNestLevel+1, "(pts (xy %s %s) (xy %s %s))\n", formatInternalUnits( aDimension->GetStart().x ).c_str(), @@ -1047,7 +1049,9 @@ void PCB_IO_KICAD_SEXPR::format( const PCB_SHAPE* aShape, int aNestLevel ) const if( aShape->GetNetCode() > 0 ) m_out->Print( 0, " (net %d)", m_mapping->Translate( aShape->GetNetCode() ) ); - KICAD_FORMAT::FormatUuid( m_out, aShape->m_Uuid, 0 ); + if(!this->m_no_generate_uuid) { + KICAD_FORMAT::FormatUuid( m_out, aShape->m_Uuid, 0 ); + } m_out->Print( 0, ")\n" ); } @@ -1093,7 +1097,9 @@ void PCB_IO_KICAD_SEXPR::format( const PCB_REFERENCE_IMAGE* aBitmap, int aNestLe m_out->Print( 0, "\n" ); m_out->Print( aNestLevel + 1, ")\n" ); // Closes data token. - KICAD_FORMAT::FormatUuid( m_out, aBitmap->m_Uuid, 0 ); + if(!this->m_no_generate_uuid) { + KICAD_FORMAT::FormatUuid( m_out, aBitmap->m_Uuid, 0 ); + } m_out->Print( aNestLevel, ")\n" ); // Closes image token. } @@ -1111,7 +1117,9 @@ void PCB_IO_KICAD_SEXPR::format( const PCB_TARGET* aTarget, int aNestLevel ) con formatLayer( aTarget->GetLayer() ); - KICAD_FORMAT::FormatUuid( m_out, aTarget->m_Uuid, 0 ); + if(!this->m_no_generate_uuid) { + KICAD_FORMAT::FormatUuid( m_out, aTarget->m_Uuid, 0 ); + } m_out->Print( 0, ")\n" ); } @@ -1161,7 +1169,7 @@ void PCB_IO_KICAD_SEXPR::format( const FOOTPRINT* aFootprint, int aNestLevel ) c m_out->Print( 0, "\n" ); - if( !( m_ctl & CTL_OMIT_UUIDS ) ) + if( !( m_ctl & CTL_OMIT_UUIDS ) && !this->m_no_generate_uuid ) KICAD_FORMAT::FormatUuid( m_out, aFootprint->m_Uuid ); if( !( m_ctl & CTL_OMIT_AT ) ) @@ -1840,7 +1848,9 @@ void PCB_IO_KICAD_SEXPR::format( const PAD* aPad, int aNestLevel ) const } m_out->Print( 0, "\n" ); - KICAD_FORMAT::FormatUuid( m_out, aPad->m_Uuid ); + if(!this->m_no_generate_uuid) { + KICAD_FORMAT::FormatUuid( m_out, aPad->m_Uuid ); + } m_out->Print( aNestLevel, ")\n" ); } @@ -1895,7 +1905,9 @@ void PCB_IO_KICAD_SEXPR::format( const PCB_TEXT* aText, int aNestLevel ) const if( parentFP && !aText->IsVisible() ) KICAD_FORMAT::FormatBool( m_out, 0, "hide", !aText->IsVisible() ); - KICAD_FORMAT::FormatUuid( m_out, aText->m_Uuid ); + if(!this->m_no_generate_uuid) { + KICAD_FORMAT::FormatUuid( m_out, aText->m_Uuid ); + } aText->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE ); @@ -1961,7 +1973,9 @@ void PCB_IO_KICAD_SEXPR::format( const PCB_TEXTBOX* aTextBox, int aNestLevel ) c formatLayer( aTextBox->GetLayer() ); m_out->Print( 0, "\n" ); - KICAD_FORMAT::FormatUuid( m_out, aTextBox->m_Uuid ); + if(!this->m_no_generate_uuid) { + KICAD_FORMAT::FormatUuid( m_out, aTextBox->m_Uuid ); + } // PCB_TEXTBOXes are never hidden, so always omit "hide" attribute aTextBox->EDA_TEXT::Format( m_out, aNestLevel, m_ctl | CTL_OMIT_HIDE ); @@ -2061,7 +2075,9 @@ void PCB_IO_KICAD_SEXPR::format( const PCB_GROUP* aGroup, int aNestLevel ) const m_out->Print( aNestLevel, "(group %s\n", m_out->Quotew( aGroup->GetName() ).c_str() ); - KICAD_FORMAT::FormatUuid( m_out, aGroup->m_Uuid ); + if(!this->m_no_generate_uuid) { + KICAD_FORMAT::FormatUuid( m_out, aGroup->m_Uuid ); + } if( aGroup->IsLocked() ) KICAD_FORMAT::FormatBool( m_out, aNestLevel + 1, "locked", aGroup->IsLocked() ); @@ -2087,7 +2103,9 @@ void PCB_IO_KICAD_SEXPR::format( const PCB_GENERATOR* aGenerator, int aNestLevel { m_out->Print( aNestLevel, "(generated\n" ); - KICAD_FORMAT::FormatUuid( m_out, aGenerator->m_Uuid ); + if(!this->m_no_generate_uuid) { + KICAD_FORMAT::FormatUuid( m_out, aGenerator->m_Uuid ); + } m_out->Print( aNestLevel + 1, "(type %s) (name %s)\n", TO_UTF8( aGenerator->GetGeneratorType() ), @@ -2323,7 +2341,9 @@ void PCB_IO_KICAD_SEXPR::format( const PCB_TRACK* aTrack, int aNestLevel ) const m_out->Print( 0, " (net %d)", m_mapping->Translate( aTrack->GetNetCode() ) ); - KICAD_FORMAT::FormatUuid( m_out, aTrack->m_Uuid ); + if(!this->m_no_generate_uuid) { + KICAD_FORMAT::FormatUuid( m_out, aTrack->m_Uuid ); + } m_out->Print( 0, ")\n" ); } @@ -2359,7 +2379,9 @@ void PCB_IO_KICAD_SEXPR::format( const ZONE* aZone, int aNestLevel ) const formatLayer( aZone->GetFirstLayer() ); } - KICAD_FORMAT::FormatUuid( m_out, aZone->m_Uuid ); + if(!this->m_no_generate_uuid) { + KICAD_FORMAT::FormatUuid( m_out, aZone->m_Uuid ); + } if( !aZone->GetZoneName().empty() ) m_out->Print( 0, " (name %s)", m_out->Quotew( aZone->GetZoneName() ).c_str() ); diff --git a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h index 560eb6c7e9..e8e79db714 100644 --- a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h +++ b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h @@ -378,6 +378,8 @@ public: return ret; } + inline void SetUUIDDisabled( bool aDisabled ) { m_no_generate_uuid = aDisabled; } + void SetOutputFormatter( OUTPUTFORMATTER* aFormatter ) { m_out = aFormatter; } BOARD_ITEM* Parse( const wxString& aClipboardSourceInput ); @@ -463,6 +465,8 @@ protected: NETINFO_MAPPING* m_mapping; ///< mapping for net codes, so only not empty net codes ///< are stored with consecutive integers as net codes + bool m_no_generate_uuid; ///< Flag: Do not generate UUIDs for footprints + std::function m_queryUserCallback; }; diff --git a/pcbnew/pcb_io/pcb_io_mgr.cpp b/pcbnew/pcb_io/pcb_io_mgr.cpp index a91be37e1d..e2b991ebce 100644 --- a/pcbnew/pcb_io/pcb_io_mgr.cpp +++ b/pcbnew/pcb_io/pcb_io_mgr.cpp @@ -29,6 +29,8 @@ #include #include +#include + #include #include @@ -217,6 +219,15 @@ bool PCB_IO_MGR::ConvertLibrary( STRING_UTF8_MAP* aOldFileProps, const wxString& for ( const wxString& fpName : fpNames ) { std::unique_ptr fp( oldFilePI->GetEnumeratedFootprint( aOldFilePath, fpName, aOldFileProps ) ); + // Set options + PCB_IO_KICAD_SEXPR* kicad_sexpr_parser = dynamic_cast( kicadPI.get() ); + if(kicad_sexpr_parser != nullptr) { + UTF8 value; + bool exists = aOldFileProps->Value( "no_uuid_gen", &value ); + kicad_sexpr_parser->SetUUIDDisabled( + exists && value == "true" + ); + } kicadPI->FootprintSave( aNewFilePath, fp.get() ); } diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index d12115703c..b491546a1e 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -1137,7 +1137,9 @@ int PCBNEW_JOBS_HANDLER::JobExportFpUpgrade( JOB* aJob ) } else { - if( !PCB_IO_MGR::ConvertLibrary( nullptr, upgradeJob->m_libraryPath, upgradeJob->m_outputLibraryPath ) ) + STRING_UTF8_MAP properties; + properties.emplace("no_uuid_gen", upgradeJob->m_no_uuid_gen ? UTF8("true") : UTF8("false")); + if( !PCB_IO_MGR::ConvertLibrary( &properties, upgradeJob->m_libraryPath, upgradeJob->m_outputLibraryPath ) ) { m_reporter->Report( ( "Unable to convert library\n" ), RPT_SEVERITY_ERROR ); return CLI::EXIT_CODES::ERR_UNKNOWN;