diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index cf4e0436ca..936863de18 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -2635,66 +2635,18 @@ BOARD_ITEM* BOARD::DuplicateAndAddItem( const BOARD_ITEM* aItem, new_module->IncrementReference( true ); } - m_Modules.PushBack( new_module ); new_item = new_module; break; } case PCB_TEXT_T: - { - const TEXTE_PCB* old_text = static_cast( aItem ); - - TEXTE_PCB* new_text = new TEXTE_PCB( *old_text ); - - m_Drawings.PushBack( new_text ); - new_item = new_text; - - break; - } case PCB_LINE_T: - { - DRAWSEGMENT* new_edge = new DRAWSEGMENT( - *static_cast(aItem) ); - - m_Drawings.PushBack( new_edge ); - new_item = new_edge; - break; - } case PCB_TRACE_T: - { - TRACK* new_track = new TRACK( - *static_cast(aItem) ); - - m_Track.PushBack( new_track ); - new_item = new_track; - break; - } case PCB_ZONE_AREA_T: - { - ZONE_CONTAINER* new_zone = new ZONE_CONTAINER( - *static_cast(aItem) ); - - m_ZoneDescriptorList.push_back( new_zone ); - new_item = new_zone; - break; - } case PCB_TARGET_T: - { - PCB_TARGET* new_target = new PCB_TARGET( - *static_cast(aItem) ); - - m_Drawings.PushBack( new_target ); - new_item = new_target; - break; - } case PCB_DIMENSION_T: - { - DIMENSION* new_dim = new DIMENSION( - *static_cast(aItem) ); - - m_Drawings.PushBack( new_dim ); - new_item = new_dim; + new_item = static_cast( aItem->Clone() ); break; - } + default: // Un-handled item for duplication wxASSERT_MSG( false, "Duplication not supported for items of class " @@ -2702,6 +2654,9 @@ BOARD_ITEM* BOARD::DuplicateAndAddItem( const BOARD_ITEM* aItem, break; } + if( new_item ) + Add( new_item ); + return new_item; } @@ -2723,7 +2678,7 @@ wxString BOARD::GetNextModuleReferenceWithPrefix( const wxString& aPrefix, continue; // the suffix must be a number - if ( !remainder.IsNumber() ) + if( !remainder.IsNumber() ) continue; long number; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 740faf3a04..e69dfb71cd 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -699,10 +699,10 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) BOARD_ITEM* new_item = NULL; - if ( PCB_EDIT_FRAME* frame = dynamic_cast( editFrame ) ) - new_item = frame->GetBoard()->DuplicateAndAddItem( item, increment ); - else if ( FOOTPRINT_EDIT_FRAME* frame = dynamic_cast( editFrame ) ) - new_item = frame->GetBoard()->m_Modules->DuplicateAndAddItem( item, increment ); + if( m_editModules ) + new_item = editFrame->GetBoard()->m_Modules->DuplicateAndAddItem( item, increment ); + else + new_item = editFrame->GetBoard()->DuplicateAndAddItem( item, increment ); if( new_item ) { @@ -759,9 +759,7 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) PCB_BASE_FRAME* editFrame = getEditFrame(); editFrame->OnModify(); - const bool editingModule = NULL != dynamic_cast( editFrame ); - - if( editingModule ) + if( m_editModules ) { // Module editors do their undo point upfront for the whole module editFrame->SaveCopyInUndoList( editFrame->GetBoard()->m_Modules, UR_MODEDIT ); @@ -819,10 +817,10 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) // if renumbering, no need to increment const bool increment = !array_opts->ShouldRenumberItems(); - if ( PCB_EDIT_FRAME* frame = dynamic_cast( editFrame ) ) - newItem = frame->GetBoard()->DuplicateAndAddItem( item, increment ); - else if ( FOOTPRINT_EDIT_FRAME* frame = dynamic_cast( editFrame ) ) - newItem = frame->GetBoard()->m_Modules->DuplicateAndAddItem( item, increment ); + if( m_editModules ) + newItem = editFrame->GetBoard()->m_Modules->DuplicateAndAddItem( item, increment ); + else + newItem = editFrame->GetBoard()->DuplicateAndAddItem( item, increment ); if( newItem ) { @@ -839,6 +837,7 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) } editFrame->GetGalCanvas()->GetView()->Add( newItem ); + getModel()->GetRatsnest()->Update( newItem ); } } @@ -881,7 +880,7 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) } } - if( !editingModule ) + if( !m_editModules ) { if( originalItemsModified ) { @@ -896,6 +895,7 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) } } + getModel()->GetRatsnest()->Recalculate(); setTransitions(); return 0;