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
This commit is contained in:
parent
9c2d1cf890
commit
4671b9b34e
|
@ -381,13 +381,10 @@ int PCB_EDITOR_CONTROL::ViaSizeDec( const TOOL_EVENT& aEvent )
|
||||||
int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
|
int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
MODULE* module = aEvent.Parameter<MODULE*>();
|
MODULE* module = aEvent.Parameter<MODULE*>();
|
||||||
KIGFX::VIEW* view = getView();
|
|
||||||
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
||||||
BOARD* board = getModel<BOARD>();
|
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
||||||
|
SELECTION& selection = selTool->GetSelection();
|
||||||
// Add a VIEW_GROUP that serves as a preview for the new item
|
BOARD_COMMIT commit( m_frame );
|
||||||
KIGFX::VIEW_GROUP preview( view );
|
|
||||||
view->Add( &preview );
|
|
||||||
|
|
||||||
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
||||||
controls->ShowCursor( true );
|
controls->ShowCursor( true );
|
||||||
|
@ -398,12 +395,11 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
// Add all the drawable parts to preview
|
// Add all the drawable parts to preview
|
||||||
VECTOR2I cursorPos = controls->GetCursorPosition();
|
VECTOR2I cursorPos = controls->GetCursorPosition();
|
||||||
|
|
||||||
if( module )
|
if( module )
|
||||||
{
|
{
|
||||||
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
||||||
preview.Add( module );
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
|
||||||
module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
|
|
||||||
view->Update( &preview );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main loop: keep receiving events
|
// Main loop: keep receiving events
|
||||||
|
@ -415,35 +411,17 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
if( module )
|
if( module )
|
||||||
{
|
{
|
||||||
delete module;
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
||||||
|
commit.Revert();
|
||||||
module = NULL;
|
module = NULL;
|
||||||
|
|
||||||
preview.Clear();
|
|
||||||
controls->ShowCursor( true );
|
|
||||||
}
|
}
|
||||||
else
|
else // let's have another chance placing a module
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if( evt->IsActivate() ) // now finish unconditionally
|
if( evt->IsActivate() ) // now finish unconditionally
|
||||||
break;
|
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 ) )
|
else if( evt->IsClick( BUT_LEFT ) )
|
||||||
{
|
{
|
||||||
if( !module )
|
if( !module )
|
||||||
|
@ -456,24 +434,16 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
|
||||||
if( module == NULL )
|
if( module == NULL )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Module has been added in LoadModuleFromLibrary(),
|
// NOTE: Module has been already added in LoadModuleFromLibrary(),
|
||||||
// so we have to remove it before committing the change @todo LEGACY
|
commit.Added( module );
|
||||||
board->Remove( module );
|
|
||||||
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
||||||
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
|
||||||
// Add all the drawable parts to preview
|
controls->SetCursorPosition( cursorPos, false );
|
||||||
preview.Add( module );
|
|
||||||
module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BOARD_COMMIT commit( m_frame );
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
||||||
commit.Add( module );
|
|
||||||
commit.Push( _( "Place a module" ) );
|
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
|
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->SetAutoPan( placing );
|
||||||
controls->CaptureCursor( placing );
|
controls->CaptureCursor( placing );
|
||||||
controls->ShowCursor( !placing );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if( module && evt->IsMotion() )
|
else if( module && evt->IsMotion() )
|
||||||
{
|
{
|
||||||
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
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();
|
m_frame->SetNoToolSelected();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue