diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 6b845bc27b..90ab2b0f80 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -421,11 +421,6 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) } } - m_controls->ShowCursor( false ); - m_controls->SetSnapping( false ); - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); - m_view->Remove( &preview ); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); @@ -603,12 +598,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) if( step != SET_ORIGIN ) delete dimension; - m_controls->ShowCursor( false ); - m_controls->SetSnapping( false ); - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); m_view->Remove( &preview ); - m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -826,11 +816,6 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) } preview.Clear(); - - m_controls->ShowCursor( false ); - m_controls->SetSnapping( false ); - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); m_view->Remove( &preview ); return 0; @@ -879,11 +864,6 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) break; } - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); - m_controls->SetSnapping( false ); - m_controls->ShowCursor( false ); - m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -1053,10 +1033,6 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, } } - m_controls->ShowCursor( false ); - m_controls->SetSnapping( false ); - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); m_view->Remove( &preview ); return started; @@ -1223,18 +1199,13 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic ) } } - m_controls->ShowCursor( false ); - m_controls->SetSnapping( false ); - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); m_view->Remove( &preview ); return ( step > SET_ORIGIN ); } -std::unique_ptr DRAWING_TOOL::createNewZone( - bool aKeepout ) +std::unique_ptr DRAWING_TOOL::createNewZone( bool aKeepout ) { const auto& board = *getModel(); @@ -1541,12 +1512,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode ) } } - m_controls->ShowCursor( false ); - m_controls->SetSnapping( false ); - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); m_view->Remove( &preview ); - m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 6d15113ce5..b26aa4b553 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -425,9 +425,6 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) else m_commit->Push( _( "Drag" ) ); - controls->ShowCursor( false ); - controls->SetAutoPan( false ); - return 0; } diff --git a/pcbnew/tools/module_editor_tools.cpp b/pcbnew/tools/module_editor_tools.cpp index 54a7d08d43..ffb39cfbe5 100644 --- a/pcbnew/tools/module_editor_tools.cpp +++ b/pcbnew/tools/module_editor_tools.cpp @@ -193,11 +193,7 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent ) } } - m_controls->ShowCursor( false ); - m_controls->SetSnapping( false ); - m_controls->SetAutoPan( false ); m_view->Remove( &preview ); - m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -341,7 +337,6 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent ) } m_frame->DisplayToolMsg( wxEmptyString ); - m_controls->ShowCursor( false ); return 0; } @@ -409,9 +404,6 @@ int MODULE_EDITOR_TOOLS::CopyItems( const TOOL_EVENT& aEvent ) } m_frame->DisplayToolMsg( wxString::Format( _( "Copied %d item(s)" ), selection.Size() ) ); - m_controls->SetSnapping( false ); - m_controls->ShowCursor( false ); - m_controls->SetAutoPan( false ); return 0; } @@ -528,9 +520,6 @@ int MODULE_EDITOR_TOOLS::PasteItems( const TOOL_EVENT& aEvent ) } delete pastedModule; - m_controls->ShowCursor( false ); - m_controls->SetSnapping( false ); - m_controls->SetAutoPan( false ); m_view->Remove( &preview ); return 0; diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 935bf55a03..462ee98ae8 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -481,12 +481,7 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) } } - controls->ShowCursor( false ); - controls->SetSnapping( false ); - controls->SetAutoPan( false ); - controls->CaptureCursor( false ); view->Remove( &preview ); - m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index b62e305281..f69c6051be 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -254,113 +254,109 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); - if( selection.Size() == 1 ) + if( selection.Size() != 1 ) + return 0; + + Activate(); + + KIGFX::VIEW_CONTROLS* controls = getViewControls(); + KIGFX::VIEW* view = getView(); + PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); + auto item = selection.Front(); + + m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() ); + + if( !m_editPoints ) + return 0; + + view->Add( m_editPoints.get() ); + m_editedPoint = NULL; + bool modified = false; + + BOARD_COMMIT commit( editFrame ); + + // Main loop: keep receiving events + while( OPT_TOOL_EVENT evt = Wait() ) { - Activate(); - - KIGFX::VIEW_CONTROLS* controls = getViewControls(); - KIGFX::VIEW* view = getView(); - PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); - auto item = selection.Front(); - - m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() ); - - if( !m_editPoints ) - return 0; - - view->Add( m_editPoints.get() ); - m_editedPoint = NULL; - bool modified = false; - - BOARD_COMMIT commit( editFrame ); - - // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) + if( !m_editPoints || + evt->Matches( m_selectionTool->ClearedEvent ) || + evt->Matches( m_selectionTool->UnselectedEvent ) || + evt->Matches( m_selectionTool->SelectedEvent ) ) { - if( !m_editPoints || - evt->Matches( m_selectionTool->ClearedEvent ) || - evt->Matches( m_selectionTool->UnselectedEvent ) || - evt->Matches( m_selectionTool->SelectedEvent ) ) + break; + } + + if ( !modified ) + updateEditedPoint( *evt ); + + if( evt->IsDrag( BUT_LEFT ) && m_editedPoint ) + { + if( !modified ) { - break; + commit.StageItems( selection, CHT_MODIFY ); + + controls->ForceCursorPosition( false ); + m_original = *m_editedPoint; // Save the original position + controls->SetAutoPan( true ); + modified = true; } - if ( !modified ) - updateEditedPoint( *evt ); + bool enableAltConstraint = !!evt->Modifier( MD_CTRL ); - if( evt->IsDrag( BUT_LEFT ) && m_editedPoint ) - { - if( !modified ) - { - commit.StageItems( selection, CHT_MODIFY ); + if( enableAltConstraint != (bool) m_altConstraint ) // alternative constraint + setAltConstraint( enableAltConstraint ); - controls->ForceCursorPosition( false ); - m_original = *m_editedPoint; // Save the original position - controls->SetAutoPan( true ); - modified = true; - } - - bool enableAltConstraint = !!evt->Modifier( MD_CTRL ); - - if( enableAltConstraint != (bool) m_altConstraint ) // alternative constraint - setAltConstraint( enableAltConstraint ); - - m_editedPoint->SetPosition( controls->GetCursorPosition() ); - - if( m_altConstraint ) - m_altConstraint->Apply(); - else - m_editedPoint->ApplyConstraint(); - - updateItem(); - updatePoints(); - } - - else if( evt->IsMouseUp( BUT_LEFT ) ) - { - controls->SetAutoPan( false ); - setAltConstraint( false ); - - if( modified ) - { - commit.Push( _( "Drag a line ending" ) ); - modified = false; - } - - m_toolMgr->PassEvent(); - } - - else if( evt->IsCancel() ) - { - if( modified ) // Restore the last change - { - commit.Revert(); - updatePoints(); - modified = false; - } - - // Let the selection tool receive the event too - m_toolMgr->PassEvent(); - - break; - } + m_editedPoint->SetPosition( controls->GetCursorPosition() ); + if( m_altConstraint ) + m_altConstraint->Apply(); else - { - m_toolMgr->PassEvent(); - } + m_editedPoint->ApplyConstraint(); + + updateItem(); + updatePoints(); } - if( m_editPoints ) + else if( evt->IsMouseUp( BUT_LEFT ) ) { - finishItem(); - view->Remove( m_editPoints.get() ); - m_editPoints.reset(); + controls->SetAutoPan( false ); + setAltConstraint( false ); + + if( modified ) + { + commit.Push( _( "Drag a line ending" ) ); + modified = false; + } + + m_toolMgr->PassEvent(); } - controls->ShowCursor( false ); - controls->SetAutoPan( false ); - controls->SetSnapping( false ); + else if( evt->IsCancel() ) + { + if( modified ) // Restore the last change + { + commit.Revert(); + updatePoints(); + modified = false; + } + + // Let the selection tool receive the event too + m_toolMgr->PassEvent(); + + break; + } + + else + { + m_toolMgr->PassEvent(); + } + } + + if( m_editPoints ) + { + finishItem(); + view->Remove( m_editPoints.get() ); + m_editPoints.reset(); } return 0;