diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index b30ca4beff..2f238dab42 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -372,11 +372,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) // Drag items to the current cursor position for( auto item : selection ) - { static_cast( item )->Move( movement + m_offset ); - } - - updateRatsnest( true ); } else if( !m_dragging ) // Prepare to start dragging { @@ -481,7 +477,6 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) { // Update dragging offset (distance between cursor and the first dragged item) m_offset = static_cast( selection.Front() )->GetPosition() - modPoint; - updateRatsnest( true ); } } @@ -494,8 +489,6 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) } } while( ( evt = Wait() ) ); //Should be assignment not equality test - getModel()->GetConnectivity()->ClearDynamicRatsnest(); - controls->ForceCursorPosition( false ); controls->ShowCursor( false ); controls->SetSnapping( false ); @@ -590,8 +583,6 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) if( !m_dragging ) m_commit->Push( _( "Rotate" ) ); - else - updateRatsnest( true ); if( selection.IsHover() ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); @@ -699,8 +690,6 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) if( !m_dragging ) m_commit->Push( _( "Mirror" ) ); - else - updateRatsnest( true ); if( selection.IsHover() ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); @@ -734,8 +723,6 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) if( !m_dragging ) m_commit->Push( _( "Flip" ) ); - else - updateRatsnest( true ); if( selection.IsHover() ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); @@ -1144,19 +1131,6 @@ void EDIT_TOOL::setTransitions() } -void EDIT_TOOL::updateRatsnest( bool aRedraw ) -{ - auto& selection = m_selectionTool->GetSelection(); - auto connectivity = getModel()->GetConnectivity(); - std::vector items; - - for ( auto item : selection ) - items.push_back ( static_cast( item ) ); - - connectivity->ComputeDynamicRatsnest( items ); -} - - wxPoint EDIT_TOOL::getModificationPoint( const SELECTION& aSelection ) { if( aSelection.Size() == 1 ) diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index 6ce3307826..a9ac7c55ab 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -145,11 +145,6 @@ private: ///> of edit reference point). VECTOR2I m_cursor; - ///> Updates ratsnest for selected items. - ///> @param aRedraw says if selected items should be drawn using the simple mode (e.g. one line - ///> per item). - void updateRatsnest( bool aRedraw ); - ///> Returns the right modification point (e.g. for rotation), depending on the number of ///> selected items. wxPoint getModificationPoint( const SELECTION& aSelection ); diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index e128a1f263..26074d94b9 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -1136,6 +1136,33 @@ int PCB_EDITOR_CONTROL::ShowLocalRatsnest( const TOOL_EVENT& aEvent ) int PCB_EDITOR_CONTROL::UpdateSelectionRatsnest( const TOOL_EVENT& aEvent ) { + auto selectionTool = m_toolMgr->GetTool(); + auto& selection = selectionTool->GetSelection(); + + if( selection.Empty() ) + { + getModel()->GetConnectivity()->ClearDynamicRatsnest(); + } + else + { + auto connectivity = getModel()->GetConnectivity(); + std::vector items; + items.reserve( selection.Size() ); + + for( auto item : selection ) + items.push_back( static_cast( item ) ); + + connectivity->ComputeDynamicRatsnest( items ); + } + + return 0; +} + + +int PCB_EDITOR_CONTROL::HideSelectionRatsnest( const TOOL_EVENT& aEvent ) +{ + getModel()->GetConnectivity()->ClearDynamicRatsnest(); + return 0; } @@ -1171,6 +1198,7 @@ void PCB_EDITOR_CONTROL::setTransitions() Go( &PCB_EDITOR_CONTROL::HighlightNetCursor, PCB_ACTIONS::highlightNetCursor.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::ShowLocalRatsnest, PCB_ACTIONS::showLocalRatsnest.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::UpdateSelectionRatsnest, PCB_ACTIONS::selectionModified.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::HideSelectionRatsnest, SELECTION_TOOL::ClearedEvent ); } diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index 35e193d6b6..1daa86c4bb 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -105,6 +105,9 @@ public: ///> Updates ratsnest for selected items. int UpdateSelectionRatsnest( const TOOL_EVENT& aEvent ); + ///> Hides ratsnest for selected items. Called when there are no items selected. + int HideSelectionRatsnest( const TOOL_EVENT& aEvent ); + ///> Shows local ratsnest of a component int ShowLocalRatsnest( const TOOL_EVENT& aEvent );