From 59af7a96f8bc5c1698dfd19f99d973f14d22cfe9 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 15 Jul 2015 14:08:52 +0200 Subject: [PATCH] Minor code cleaning. --- common/tool/tool_dispatcher.cpp | 10 +++---- common/tool/tool_manager.cpp | 4 +-- include/tool/tool_dispatcher.h | 3 +-- include/tool/tool_event.h | 46 +++++++++++++++++++++------------ pcbnew/tools/edit_tool.cpp | 2 +- pcbnew/tools/selection_tool.cpp | 14 +++------- 6 files changed, 42 insertions(+), 37 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 8a66147ceb..97127cef49 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -172,7 +172,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti down = true; } - int mods = decodeModifiers( static_cast( &aEvent ) ); + int mods = decodeModifiers( static_cast( &aEvent ) ); int args = st->button | mods; if( down ) // Handle mouse button press @@ -224,8 +224,8 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti if( t - st->downTimestamp > DragTimeThreshold || st->dragMaxDelta > DragDistanceThreshold ) { evt = TOOL_EVENT( TC_MOUSE, TA_MOUSE_DRAG, args ); - evt->SetMouseDragOrigin( st->dragOrigin ); - evt->SetMouseDelta( m_lastMousePos - st->dragOrigin ); + evt->setMouseDragOrigin( st->dragOrigin ); + evt->setMouseDelta( m_lastMousePos - st->dragOrigin ); } } @@ -262,7 +262,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) type == KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE ) { wxMouseEvent* me = static_cast( &aEvent ); - int mods = decodeModifiers( me ); + int mods = decodeModifiers( me ); VECTOR2D screenPos = m_toolMgr->GetViewControls()->GetMousePosition(); VECTOR2D pos = getView()->ToWorld( screenPos ); @@ -295,7 +295,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) { wxKeyEvent* ke = static_cast( &aEvent ); int key = ke->GetKeyCode(); - int mods = decodeModifiers( ke ); + int mods = decodeModifiers( ke ); if( mods & MD_CTRL ) { diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index f7e613fd6e..3da57c9961 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -494,7 +494,7 @@ void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) if( st->waitEvents.Matches( aEvent ) ) { // By default, only messages are passed further - m_passEvent = ( aEvent.m_category == TC_MESSAGE ); + m_passEvent = ( aEvent.Category() == TC_MESSAGE ); // got matching event? clear wait list and wake up the coroutine st->wakeupEvent = aEvent; @@ -563,7 +563,7 @@ bool TOOL_MANAGER::dispatchActivation( const TOOL_EVENT& aEvent ) { if( aEvent.IsActivate() ) { - std::map::iterator tool = m_toolNameIndex.find( *aEvent.m_commandStr ); + std::map::iterator tool = m_toolNameIndex.find( *aEvent.GetCommandStr() ); if( tool != m_toolNameIndex.end() ) { diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index 3cc9bacea4..cf6e852734 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -97,8 +97,7 @@ private: bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion ); ///> Saves the state of key modifiers (Alt, Ctrl and so on). - template - static int decodeModifiers( const EventType* aState ) + static int decodeModifiers( const wxKeyboardState* aState ) { int mods = 0; diff --git a/include/tool/tool_event.h b/include/tool/tool_event.h index fc97369cb4..4def191f8a 100644 --- a/include/tool/tool_event.h +++ b/include/tool/tool_event.h @@ -185,7 +185,7 @@ public: { if( aCategory == TC_MOUSE ) { - m_mouseButtons = aExtraParam & BUT_BUTTON_MASK; + setMouseButtons( aExtraParam & BUT_BUTTON_MASK ); } else if( aCategory == TC_KEYBOARD ) { @@ -311,21 +311,6 @@ public: return m_actions == TA_KEY_PRESSED; } - void SetMouseDragOrigin( const VECTOR2D& aP ) - { - m_mouseDragOrigin = aP; - } - - void SetMousePosition( const VECTOR2D& aP ) - { - m_mousePos = aP; - } - - void SetMouseDelta( const VECTOR2D& aP ) - { - m_mouseDelta = aP; - } - /** * Function Matches() * Tests whether two events match in terms of category & action or command. @@ -400,8 +385,35 @@ public: return m_commandStr; } + void SetMousePosition( const VECTOR2D& aP ) + { + m_mousePos = aP; + } + private: - friend class TOOL_MANAGER; + friend class TOOL_DISPATCHER; + + void setMouseDragOrigin( const VECTOR2D& aP ) + { + m_mouseDragOrigin = aP; + } + + void setMouseDelta( const VECTOR2D& aP ) + { + m_mouseDelta = aP; + } + + void setMouseButtons( int aButtons ) + { + assert( ( aButtons & ~BUT_BUTTON_MASK ) == 0 ); + m_mouseButtons = aButtons; + } + + void setModifiers( int aMods ) + { + assert( ( aMods & ~MD_MODIFIER_MASK ) == 0 ); + m_modifiers = aMods; + } TOOL_EVENT_CATEGORY m_category; TOOL_ACTIONS m_actions; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 7195d7ac5b..3976db89b4 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -1029,7 +1029,7 @@ bool EDIT_TOOL::hoverSelection( const SELECTION& aSelection, bool aSanitize ) if( aSanitize ) m_selectionTool->SanitizeSelection(); - if( aSelection.Empty() ) + if( aSelection.Empty() ) // TODO is it necessary? m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); return !aSelection.Empty(); diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 615c1af4e9..e8898366ba 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -226,7 +226,6 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) else if( evt->IsAction( &COMMON_ACTIONS::selectionCursor ) ) { - // GetMousePosition() is used, as it is independent of snapping settings selectCursor( true ); } @@ -1166,8 +1165,6 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c if( item->Type() == PCB_MODULE_T && areaRatio < textToFootprintMinRatio ) { - //printf("rejectModuleN\n"); - rejected.insert( item ); } @@ -1180,7 +1177,6 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c case PCB_MODULE_T: if( areaRatio > textToFeatureMinRatio ) { - //printf("t after moduleRejected\n"); rejected.insert( txt ); } break; @@ -1199,21 +1195,21 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c if( calcRatio( minArea, maxArea ) <= footprintAreaRatio ) { for( int i = 0; i < aCollector.GetCount(); ++i ) + { if( MODULE* mod = dyn_cast( aCollector[i] ) ) { double normalizedArea = calcRatio( calcArea(mod), maxArea ); if( normalizedArea > footprintAreaRatio ) { - //printf("rejectModule1\n"); - rejected.insert( mod ); } } + } } } - if( aCollector.CountType ( PCB_PAD_T ) > 0 ) + if( aCollector.CountType( PCB_PAD_T ) > 0 ) { for( int i = 0; i < aCollector.GetCount(); ++i ) { @@ -1314,8 +1310,6 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c { aCollector.Remove( item ); } - - //printf("Post-selection: %d\n", aCollector.GetCount() ); } @@ -1331,7 +1325,7 @@ bool SELECTION_TOOL::SanitizeSelection() if( item->Type() == PCB_PAD_T ) { - MODULE* mod = static_cast ( item->GetParent() ); + MODULE* mod = static_cast( item->GetParent() ); // case 1: module (or its pads) are locked if( mod && ( mod->PadsLocked() || mod->IsLocked() ) )