From 2286652abe87c16e8843f086b2972a51637b998c Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 2 Feb 2020 23:46:26 +0000 Subject: [PATCH] Handle duplication of footprint ref and value. Fixes https://gitlab.com/kicad/code/kicad/issues/3828 --- pcbnew/class_module.cpp | 45 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 6a69f76567..0dd5f1d9e8 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1295,23 +1295,24 @@ void MODULE::SetOrientation( double newangle ) CalculateBoundingBox(); } -BOARD_ITEM* MODULE::Duplicate( const BOARD_ITEM* aItem, - bool aIncrementPadNumbers, +BOARD_ITEM* MODULE::Duplicate( const BOARD_ITEM* aItem, bool aIncrementPadNumbers, bool aAddToModule ) { BOARD_ITEM* new_item = NULL; - D_PAD* new_pad = NULL; MODULE_ZONE_CONTAINER* new_zone = NULL; switch( aItem->Type() ) { case PCB_PAD_T: { - new_pad = new D_PAD( *static_cast( aItem ) ); + D_PAD* new_pad = new D_PAD( *static_cast( aItem ) ); if( aAddToModule ) m_pads.push_back( new_pad ); + if( aIncrementPadNumbers && !new_pad->IsAperturePad() ) + new_pad->IncrementPadName( true, true ); + new_item = new_pad; break; } @@ -1329,26 +1330,30 @@ BOARD_ITEM* MODULE::Duplicate( const BOARD_ITEM* aItem, case PCB_MODULE_TEXT_T: { - const TEXTE_MODULE* old_text = static_cast( aItem ); + TEXTE_MODULE* new_text = new TEXTE_MODULE( *static_cast( aItem ) ); - // do not duplicate value or reference fields - // (there can only be one of each) - if( old_text->GetType() == TEXTE_MODULE::TEXT_is_DIVERS ) + if( new_text->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE ) { - TEXTE_MODULE* new_text = new TEXTE_MODULE( *old_text ); - - if( aAddToModule ) - Add( new_text ); - - new_item = new_text; + new_text->SetText( wxT( "%R" ) ); + new_text->SetType( TEXTE_MODULE::TEXT_is_DIVERS ); } + else if( new_text->GetType() == TEXTE_MODULE::TEXT_is_VALUE ) + { + new_text->SetText( wxT( "%V" ) ); + new_text->SetType( TEXTE_MODULE::TEXT_is_DIVERS ); + } + + if( aAddToModule ) + Add( new_text ); + + new_item = new_text; + break; } case PCB_MODULE_EDGE_T: { - EDGE_MODULE* new_edge = new EDGE_MODULE( - *static_cast(aItem) ); + EDGE_MODULE* new_edge = new EDGE_MODULE( *static_cast(aItem) ); if( aAddToModule ) Add( new_edge ); @@ -1363,16 +1368,10 @@ BOARD_ITEM* MODULE::Duplicate( const BOARD_ITEM* aItem, default: // Un-handled item for duplication - wxASSERT_MSG( false, "Duplication not supported for items of class " - + aItem->GetClass() ); + wxFAIL_MSG( "Duplication not supported for items of class " + aItem->GetClass() ); break; } - if( aIncrementPadNumbers && new_pad && !new_pad->IsAperturePad() ) - { - new_pad->IncrementPadName( true, true ); - } - return new_item; }