diff --git a/pcbnew/array_creator.cpp b/pcbnew/array_creator.cpp index 4567579751..6114e0f927 100644 --- a/pcbnew/array_creator.cpp +++ b/pcbnew/array_creator.cpp @@ -81,13 +81,12 @@ void ARRAY_CREATOR::Invoke() { // increment pad numbers if do any renumbering // (we will number again later according to the numbering scheme if set) - new_item = module->DuplicateAndAddItem( - item, array_opts->ShouldNumberItems() ); + new_item = module->Duplicate( item, array_opts->ShouldNumberItems(), true ); } else { // PCB items keep the same numbering - new_item = getBoard()->DuplicateAndAddItem( item ); + new_item = getBoard()->Duplicate( item, true ); // @TODO: we should merge zones. This is a bit tricky, because // the undo command needs saving old area, if it is merged. diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index aac91c9ca9..bfdebdc0d0 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -2770,7 +2770,8 @@ void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets, } -BOARD_ITEM* BOARD::DuplicateAndAddItem( const BOARD_ITEM* aItem ) +BOARD_ITEM* BOARD::Duplicate( const BOARD_ITEM* aItem, + bool aAddToBoard ) { BOARD_ITEM* new_item = NULL; @@ -2799,7 +2800,10 @@ BOARD_ITEM* BOARD::DuplicateAndAddItem( const BOARD_ITEM* aItem ) } if( new_item ) - Add( new_item ); + { + if( aAddToBoard ) + Add( new_item ); + } return new_item; } diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index dd4476c267..2d256bb5a1 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -277,13 +277,7 @@ public: ///> @copydoc BOARD_ITEM_CONTAINER::Remove() void Remove( BOARD_ITEM* aBoardItem ) override; - /** - * Function DuplicateAndAddItem - * duplicates an item, and add it to the board list. - * @param aItem The item to duplicate. - * @return BOARD_ITEM* \a the new item which was added. - */ - BOARD_ITEM* DuplicateAndAddItem( const BOARD_ITEM* aItem ); + BOARD_ITEM* Duplicate( const BOARD_ITEM* aItem, bool aAddToBoard = false ); /** * Function GetRatsnest() diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 7ec0d6170d..726cd48cac 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1110,8 +1110,9 @@ void MODULE::SetOrientation( double newangle ) CalculateBoundingBox(); } -BOARD_ITEM* MODULE::DuplicateAndAddItem( 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; @@ -1122,7 +1123,9 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem, { new_pad = new D_PAD( *static_cast( aItem ) ); - Pads().PushBack( new_pad ); + if( aAddToModule ) + Pads().PushBack( new_pad ); + new_item = new_pad; break; } @@ -1137,7 +1140,9 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem, { TEXTE_MODULE* new_text = new TEXTE_MODULE( *old_text ); - GraphicalItems().PushBack( new_text ); + if( aAddToModule ) + GraphicalItems().PushBack( new_text ); + new_item = new_text; } break; @@ -1148,7 +1153,9 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem, EDGE_MODULE* new_edge = new EDGE_MODULE( *static_cast(aItem) ); - GraphicalItems().PushBack( new_edge ); + if( aAddToModule ) + GraphicalItems().PushBack( new_edge ); + new_item = new_edge; break; } diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 9221d0a22f..715a8f6c85 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -520,12 +520,13 @@ public: void SetPlacementCost90( int aCost ) { m_CntRot90 = aCost; } /** - * Function DuplicateAndAddItem - * Duplicate a given item within the module + * Function Duplicate + * Duplicate a given item within the module, without adding to the board * @return the new item, or NULL if the item could not be duplicated */ - BOARD_ITEM* DuplicateAndAddItem( const BOARD_ITEM* item, - bool aIncrementPadNumbers ); + BOARD_ITEM* Duplicate( const BOARD_ITEM* aItem, + bool aIncrementPadNumbers, + bool aAddToModule = false ); /** * Function Add3DModel diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 8d83cdbd1e..d92e300ad5 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -714,7 +714,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // TODO move DuplicateAndAddItem() to BOARD_ITEM_CONTAINER? dunno.. if( m_editModules ) - new_item = editFrame->GetBoard()->m_Modules->DuplicateAndAddItem( item, increment ); + new_item = editFrame->GetBoard()->m_Modules->Duplicate( item, increment, true ); else { #if 0 @@ -723,7 +723,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // so zones are not duplicated if( item->Type() != PCB_ZONE_AREA_T ) #endif - new_item = editFrame->GetBoard()->DuplicateAndAddItem( item ); + new_item = editFrame->GetBoard()->Duplicate( item, true ); } if( new_item )