From 35bc2efb61c9f8f6c869ca48c0389af6331b5661 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 4 Jun 2014 18:01:01 +0200 Subject: [PATCH] Minor code cleaning. --- pcbnew/router/router_tool.cpp | 4 ++-- pcbnew/tools/edit_tool.cpp | 23 ++++++++++------------- pcbnew/tools/selection_tool.cpp | 2 +- pcbnew/tools/selection_tool.h | 7 +++++++ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 177660798a..a81883d3ad 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -385,7 +385,7 @@ void ROUTER_TOOL::handleCommonEvents( TOOL_EVENT& aEvent ) #endif if( aEvent.IsAction( &ACT_RouterOptions ) ) { - DIALOG_PNS_SETTINGS settingsDlg( m_toolMgr->GetEditFrame(), m_router->Settings() ); + DIALOG_PNS_SETTINGS settingsDlg( getEditFrame(), m_router->Settings() ); if( settingsDlg.ShowModal() ) m_router->ApplySettings(); @@ -393,7 +393,7 @@ void ROUTER_TOOL::handleCommonEvents( TOOL_EVENT& aEvent ) else if( aEvent.IsAction( &ACT_CustomTrackWidth ) ) { - DIALOG_TRACK_VIA_SIZE sizeDlg( m_toolMgr->GetEditFrame(), m_router->Settings() ); + DIALOG_TRACK_VIA_SIZE sizeDlg( getEditFrame(), m_router->Settings() ); BOARD_DESIGN_SETTINGS& bds = getModel( PCB_T )->GetDesignSettings(); sizeDlg.ShowModal(); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 3badc60fb2..05f34d8608 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -93,7 +93,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) m_updateFlag = KIGFX::VIEW_ITEM::GEOMETRY; KIGFX::VIEW_CONTROLS* controls = getViewControls(); - PCB_EDIT_FRAME* editFrame = static_cast( m_toolMgr->GetEditFrame() ); + PCB_EDIT_FRAME* editFrame = getEditFrame(); controls->ShowCursor( true ); controls->SetSnapping( true ); controls->SetAutoPan( true ); @@ -208,7 +208,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) int EDIT_TOOL::Properties( TOOL_EVENT& aEvent ) { const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); - PCB_EDIT_FRAME* editFrame = static_cast( m_toolMgr->GetEditFrame() ); + PCB_EDIT_FRAME* editFrame = getEditFrame(); // Shall the selection be cleared at the end? bool unselect = selection.Empty(); @@ -224,7 +224,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent ) if( selection.Size() == 1 ) { // Display properties dialog - BOARD_ITEM* item = static_cast( selection.items.GetPickedItem( 0 ) ); + BOARD_ITEM* item = selection.Item( 0 ); // Check if user wants to edit pad or module properties if( item->Type() == PCB_MODULE_T ) @@ -280,7 +280,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent ) int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) { const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); - PCB_EDIT_FRAME* editFrame = static_cast( m_toolMgr->GetEditFrame() ); + PCB_EDIT_FRAME* editFrame = getEditFrame(); // Shall the selection be cleared at the end? bool unselect = selection.Empty(); @@ -302,7 +302,7 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) for( unsigned int i = 0; i < selection.items.GetCount(); ++i ) { - BOARD_ITEM* item = static_cast( selection.items.GetPickedItem( i ) ); + BOARD_ITEM* item = selection.Item( i ); item->Rotate( rotatePoint, editFrame->GetRotationAngle() ); @@ -334,7 +334,7 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) int EDIT_TOOL::Flip( TOOL_EVENT& aEvent ) { const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); - PCB_EDIT_FRAME* editFrame = static_cast( m_toolMgr->GetEditFrame() ); + PCB_EDIT_FRAME* editFrame = getEditFrame(); // Shall the selection be cleared at the end? bool unselect = selection.Empty(); @@ -356,7 +356,7 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent ) for( unsigned int i = 0; i < selection.items.GetCount(); ++i ) { - BOARD_ITEM* item = static_cast( selection.items.GetPickedItem( i ) ); + BOARD_ITEM* item = selection.Item( i ); item->Flip( flipPoint ); @@ -398,7 +398,7 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent ) // Get a copy of the selected items set PICKED_ITEMS_LIST selectedItems = selection.items; - PCB_EDIT_FRAME* editFrame = static_cast( m_toolMgr->GetEditFrame() ); + PCB_EDIT_FRAME* editFrame = getEditFrame(); // As we are about to remove items, they have to be removed from the selection first m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); @@ -412,10 +412,7 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent ) // And now remove for( unsigned int i = 0; i < selectedItems.GetCount(); ++i ) - { - BOARD_ITEM* item = static_cast( selectedItems.GetPickedItem( i ) ); - remove( item ); - } + remove( static_cast( selectedItems.GetPickedItem( i ) ) ); getModel( PCB_T )->GetRatsnest()->Recalculate(); @@ -491,7 +488,7 @@ void EDIT_TOOL::updateRatsnest( bool aRedraw ) ratsnest->ClearSimple(); for( unsigned int i = 0; i < selection.items.GetCount(); ++i ) { - BOARD_ITEM* item = static_cast( selection.items.GetPickedItem( i ) ); + BOARD_ITEM* item = selection.Item( i ); ratsnest->Update( item ); diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 48d1b36412..d32f532ef9 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -658,7 +658,7 @@ bool SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const // Check if the point is located within any of the currently selected items bounding boxes for( unsigned int i = 0; i < m_selection.items.GetCount(); ++i ) { - BOARD_ITEM* item = static_cast( m_selection.items.GetPickedItem( i ) ); + BOARD_ITEM* item = m_selection.Item( i ); BOX2I itemBox = item->ViewBBox(); itemBox.Inflate( margin.x, margin.y ); // Give some margin for gripping an item diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 0850286d24..9fe3d32b53 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -78,6 +78,13 @@ public: return items.GetCount(); } + /// Alias to make code shorter and clearer + template + T* Item( unsigned int aIndex ) const + { + return static_cast( items.GetPickedItem( aIndex ) ); + } + private: /// Clears both the VIEW_GROUP and set of selected items. Please note that it does not /// change properties of selected items (e.g. selection flag).