GenCAD export: added a switch to generate unique pin names

This commit is contained in:
Maciej Suminski 2017-10-04 13:57:40 +02:00
parent c3c5205393
commit 6ba33c8489
3 changed files with 26 additions and 2 deletions

View File

@ -127,7 +127,8 @@ void DIALOG_GENCAD_EXPORT_OPTIONS::createOptCheckboxes()
{
std::map<GENCAD_EXPORT_OPT, wxString> 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 )

View File

@ -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
};

View File

@ -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<wxString> 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 );