Moved ratsnest update from EDIT_TOOL to PCB_EDITOR_CONTROL

This commit is contained in:
Maciej Suminski 2017-04-20 14:43:42 +02:00
parent bc8668b039
commit d452a5a30c
4 changed files with 23 additions and 31 deletions

View File

@ -295,8 +295,6 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
// Drag items to the current cursor position // Drag items to the current cursor position
for( auto item : selection ) for( auto item : selection )
static_cast<BOARD_ITEM*>( item )->Move( movement + m_offset ); static_cast<BOARD_ITEM*>( item )->Move( movement + m_offset );
updateRatsnest( true );
} }
else if( !m_dragging ) // Prepare to start dragging 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) // Update dragging offset (distance between cursor and the first dragged item)
m_offset = static_cast<BOARD_ITEM*>( selection.Front() )->GetPosition() - modPoint; m_offset = static_cast<BOARD_ITEM*>( selection.Front() )->GetPosition() - modPoint;
getView()->Update( &selection ); getView()->Update( &selection );
updateRatsnest( true );
} }
} }
@ -511,8 +508,6 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
if( !m_dragging ) if( !m_dragging )
m_commit->Push( _( "Rotate" ) ); m_commit->Push( _( "Rotate" ) );
else
updateRatsnest( true );
if( selection.IsHover() ) if( selection.IsHover() )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
@ -619,8 +614,6 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
if( !m_dragging ) if( !m_dragging )
m_commit->Push( _( "Mirror" ) ); m_commit->Push( _( "Mirror" ) );
else
updateRatsnest( true );
if( selection.IsHover() ) if( selection.IsHover() )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
@ -651,8 +644,6 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
if( !m_dragging ) if( !m_dragging )
m_commit->Push( _( "Flip" ) ); m_commit->Push( _( "Flip" ) );
else
updateRatsnest( true );
if( selection.IsHover() ) if( selection.IsHover() )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); 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<BOARD>()->GetRatsnest();
ratsnest->ClearSimple();
for( auto item : selection )
{
ratsnest->Update( static_cast<BOARD_ITEM*>( item ) );
if( aRedraw )
ratsnest->AddSimple( static_cast<BOARD_ITEM*>( item ) );
}
}
wxPoint EDIT_TOOL::getModificationPoint( const SELECTION& aSelection ) wxPoint EDIT_TOOL::getModificationPoint( const SELECTION& aSelection )
{ {
if( aSelection.Size() == 1 ) if( aSelection.Size() == 1 )

View File

@ -144,11 +144,6 @@ private:
///> of edit reference point). ///> of edit reference point).
VECTOR2I m_cursor; 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 ///> Returns the right modification point (e.g. for rotation), depending on the number of
///> selected items. ///> selected items.
wxPoint getModificationPoint( const SELECTION& aSelection ); wxPoint getModificationPoint( const SELECTION& aSelection );

View File

@ -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<SELECTION_TOOL>();
const SELECTION& selection = selTool->GetSelection();
RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest();
// Update "simple" ratsnest, computed for currently modified items
ratsnest->ClearSimple();
for( auto item : selection )
{
ratsnest->Update( static_cast<BOARD_ITEM*>( item ) );
ratsnest->AddSimple( static_cast<BOARD_ITEM*>( item ) );
}
return 0;
}
void PCB_EDITOR_CONTROL::SetTransitions() void PCB_EDITOR_CONTROL::SetTransitions()
{ {
// Track & via size control // 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::DrillOrigin, PCB_ACTIONS::drillOrigin.MakeEvent() );
Go( &PCB_EDITOR_CONTROL::HighlightNet, PCB_ACTIONS::highlightNet.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::HighlightNet, PCB_ACTIONS::highlightNet.MakeEvent() );
Go( &PCB_EDITOR_CONTROL::HighlightNetCursor, PCB_ACTIONS::highlightNetCursor.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::HighlightNetCursor, PCB_ACTIONS::highlightNetCursor.MakeEvent() );
Go( &PCB_EDITOR_CONTROL::UpdateSelectionRatsnest, PCB_ACTIONS::selectionModified.MakeEvent() );
} }

View File

@ -102,6 +102,9 @@ public:
///> Launches a tool to pick the item whose net is going to be highlighted. ///> Launches a tool to pick the item whose net is going to be highlighted.
int HighlightNetCursor( const TOOL_EVENT& aEvent ); int HighlightNetCursor( const TOOL_EVENT& aEvent );
///> Updates ratsnest for selected items.
int UpdateSelectionRatsnest( const TOOL_EVENT& aEvent );
///> Sets up handlers for various events. ///> Sets up handlers for various events.
void SetTransitions() override; void SetTransitions() override;