From 4671b9b34e05f7268022d24fc33b3bfc68fd182b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 14 Dec 2017 17:10:06 +0100 Subject: [PATCH] Fixed module removal when rotating/flipping a placed module Module placer did not mark the newly placed modules as selected, but all edit functions (rotate/place/etc.) rely on getting a selected item. When a rotation/flip command was issued, the newly placed module was dropped and the one underneath the cursor has been rotated. To fix this the newly placed modules are marked as selected. It also simplifies the placer code a bit. Fixes: lp:1738148 * https://bugs.launchpad.net/kicad/+bug/1738148 --- pcbnew/tools/pcb_editor_control.cpp | 66 +++++++---------------------- 1 file changed, 15 insertions(+), 51 deletions(-) diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index dbcd72c75d..96ca451e5c 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -381,13 +381,10 @@ int PCB_EDITOR_CONTROL::ViaSizeDec( const TOOL_EVENT& aEvent ) int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) { MODULE* module = aEvent.Parameter(); - KIGFX::VIEW* view = getView(); KIGFX::VIEW_CONTROLS* controls = getViewControls(); - BOARD* board = getModel(); - - // Add a VIEW_GROUP that serves as a preview for the new item - KIGFX::VIEW_GROUP preview( view ); - view->Add( &preview ); + SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + SELECTION& selection = selTool->GetSelection(); + BOARD_COMMIT commit( m_frame ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); controls->ShowCursor( true ); @@ -398,12 +395,11 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) // Add all the drawable parts to preview VECTOR2I cursorPos = controls->GetCursorPosition(); + if( module ) { module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); - preview.Add( module ); - module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) ); - view->Update( &preview ); + m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module ); } // Main loop: keep receiving events @@ -415,35 +411,17 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) { if( module ) { - delete module; + m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); + commit.Revert(); module = NULL; - - preview.Clear(); - controls->ShowCursor( true ); } - else + else // let's have another chance placing a module break; if( evt->IsActivate() ) // now finish unconditionally break; } - else if( module && evt->Category() == TC_COMMAND ) - { - if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) ) - { - const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( - *m_frame, *evt ); - module->Rotate( module->GetPosition(), rotationAngle ); - view->Update( &preview ); - } - else if( evt->IsAction( &PCB_ACTIONS::flip ) ) - { - module->Flip( module->GetPosition() ); - view->Update( &preview ); - } - } - else if( evt->IsClick( BUT_LEFT ) ) { if( !module ) @@ -456,24 +434,16 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) if( module == NULL ) continue; - // Module has been added in LoadModuleFromLibrary(), - // so we have to remove it before committing the change @todo LEGACY - board->Remove( module ); + // NOTE: Module has been already added in LoadModuleFromLibrary(), + commit.Added( module ); module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); - - // Add all the drawable parts to preview - preview.Add( module ); - module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) ); + m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module ); + controls->SetCursorPosition( cursorPos, false ); } else { - BOARD_COMMIT commit( m_frame ); - commit.Add( module ); + m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); commit.Push( _( "Place a module" ) ); - - // Remove from preview - preview.Remove( module ); - module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Remove, &preview, _1 ) ); module = NULL; // to indicate that there is no module that we currently modify } @@ -481,22 +451,16 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) controls->SetAutoPan( placing ); controls->CaptureCursor( placing ); - controls->ShowCursor( !placing ); } else if( module && evt->IsMotion() ) { module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); - view->Update( &preview ); + selection.SetReferencePoint( cursorPos ); + getView()->Update( &selection ); } } - controls->ShowCursor( false ); - controls->SetSnapping( false ); - controls->SetAutoPan( false ); - controls->CaptureCursor( false ); - - view->Remove( &preview ); m_frame->SetNoToolSelected(); return 0;