From d452a5a30cd16d93e934eab05fa462882edb1aa5 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 20 Apr 2017 14:43:42 +0200 Subject: [PATCH] Moved ratsnest update from EDIT_TOOL to PCB_EDITOR_CONTROL --- pcbnew/tools/edit_tool.cpp | 26 -------------------------- pcbnew/tools/edit_tool.h | 5 ----- pcbnew/tools/pcb_editor_control.cpp | 20 ++++++++++++++++++++ pcbnew/tools/pcb_editor_control.h | 3 +++ 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 58d1f9a2cb..bb82a32ced 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -295,8 +295,6 @@ 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 { @@ -406,7 +404,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; getView()->Update( &selection ); - updateRatsnest( true ); } } @@ -511,8 +508,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 ); @@ -619,8 +614,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 ); @@ -651,8 +644,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 ); @@ -1050,23 +1041,6 @@ void EDIT_TOOL::SetTransitions() } -void EDIT_TOOL::updateRatsnest( bool aRedraw ) -{ - const SELECTION& selection = m_selectionTool->GetSelection(); - RN_DATA* ratsnest = getModel()->GetRatsnest(); - - ratsnest->ClearSimple(); - - for( auto item : selection ) - { - ratsnest->Update( static_cast( item ) ); - - if( aRedraw ) - ratsnest->AddSimple( static_cast( item ) ); - } -} - - 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 afd2f12094..d578d668d3 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -144,11 +144,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 118364e1ba..cdaf05681d 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -1056,6 +1056,25 @@ int PCB_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent ) } +int PCB_EDITOR_CONTROL::UpdateSelectionRatsnest( const TOOL_EVENT& aEvent ) +{ + SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + const SELECTION& selection = selTool->GetSelection(); + RN_DATA* ratsnest = getModel()->GetRatsnest(); + + // Update "simple" ratsnest, computed for currently modified items + ratsnest->ClearSimple(); + + for( auto item : selection ) + { + ratsnest->Update( static_cast( item ) ); + ratsnest->AddSimple( static_cast( item ) ); + } + + return 0; +} + + void PCB_EDITOR_CONTROL::SetTransitions() { // Track & via size control @@ -1085,6 +1104,7 @@ void PCB_EDITOR_CONTROL::SetTransitions() Go( &PCB_EDITOR_CONTROL::DrillOrigin, PCB_ACTIONS::drillOrigin.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::HighlightNet, PCB_ACTIONS::highlightNet.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::HighlightNetCursor, PCB_ACTIONS::highlightNetCursor.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::UpdateSelectionRatsnest, PCB_ACTIONS::selectionModified.MakeEvent() ); } diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index 24bcd1f7b5..4e330b2689 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -102,6 +102,9 @@ public: ///> Launches a tool to pick the item whose net is going to be highlighted. int HighlightNetCursor( const TOOL_EVENT& aEvent ); + ///> Updates ratsnest for selected items. + int UpdateSelectionRatsnest( const TOOL_EVENT& aEvent ); + ///> Sets up handlers for various events. void SetTransitions() override;