From 6ba33c848959f77db42f24dc8292ec7e844893ff Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 4 Oct 2017 13:57:40 +0200 Subject: [PATCH] GenCAD export: added a switch to generate unique pin names --- .../dialogs/dialog_gencad_export_options.cpp | 3 ++- pcbnew/dialogs/dialog_gencad_export_options.h | 3 ++- pcbnew/exporters/export_gencad.cpp | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pcbnew/dialogs/dialog_gencad_export_options.cpp b/pcbnew/dialogs/dialog_gencad_export_options.cpp index 7aa2f9ac7a..2e74b9d818 100644 --- a/pcbnew/dialogs/dialog_gencad_export_options.cpp +++ b/pcbnew/dialogs/dialog_gencad_export_options.cpp @@ -127,7 +127,8 @@ void DIALOG_GENCAD_EXPORT_OPTIONS::createOptCheckboxes() { std::map opts = { - { FLIP_BOTTOM_LAYERS, _( "Flip layer stack for bottom components" ) } + { FLIP_BOTTOM_LAYERS, _( "Flip layer stack for bottom components" ) }, + { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) } }; for( const auto& option : opts ) diff --git a/pcbnew/dialogs/dialog_gencad_export_options.h b/pcbnew/dialogs/dialog_gencad_export_options.h index 391091b097..43369d368f 100644 --- a/pcbnew/dialogs/dialog_gencad_export_options.h +++ b/pcbnew/dialogs/dialog_gencad_export_options.h @@ -33,7 +33,8 @@ class wxTextCtrl; ///> Settings for GenCAD exporter enum GENCAD_EXPORT_OPT { - FLIP_BOTTOM_LAYERS // invert layer stack for bottom components + FLIP_BOTTOM_LAYERS, // invert layer stack for bottom components + UNIQUE_PIN_NAMES // generate unique pin names }; diff --git a/pcbnew/exporters/export_gencad.cpp b/pcbnew/exporters/export_gencad.cpp index fb8f505bcf..a9a9ff97cc 100644 --- a/pcbnew/exporters/export_gencad.cpp +++ b/pcbnew/exporters/export_gencad.cpp @@ -226,6 +226,7 @@ const static double SCALE_FACTOR = 1000.0 * IU_PER_MILS; // Export options bool flipBottomLayers; +bool uniquePins; /* Two helper functions to calculate coordinates of modules in gencad values * (GenCAD Y axis from bottom to top) @@ -261,6 +262,7 @@ void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent ) // Get options flipBottomLayers = optionsDialog.GetOption( FLIP_BOTTOM_LAYERS ); + uniquePins = optionsDialog.GetOption( UNIQUE_PIN_NAMES ); // Switch the locale to standard C (needed to print floating point numbers) LOCALE_IO toggle; @@ -637,6 +639,9 @@ static void CreateShapesSection( FILE* aFile, BOARD* aPcb ) for( module = aPcb->m_Modules; module; module = module->Next() ) { + // already emitted pins to check for duplicates + std::set pins; + FootprintWriteShape( aFile, module ); for( pad = module->PadsList(); pad; pad = pad->Next() ) @@ -662,6 +667,23 @@ static void CreateShapesSection( FILE* aFile, BOARD* aPcb ) if( pinname.IsEmpty() ) pinname = wxT( "none" ); + if( uniquePins ) + { + int suffix = 0; + wxString origPinname( pinname ); + + auto it = pins.find( pinname ); + + while( it != pins.end() ) + { + pinname = wxString::Format( "%s_%d", origPinname, suffix ); + ++suffix; + it = pins.find( pinname ); + } + + pins.insert( pinname ); + } + double orient = pad->GetOrientation() - module->GetOrientation(); NORMALIZE_ANGLE_POS( orient );