Minor code cleaning.

This commit is contained in:
Maciej Suminski 2015-07-15 14:08:52 +02:00
parent 36d1818b54
commit 59af7a96f8
6 changed files with 42 additions and 37 deletions

View File

@ -172,7 +172,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti
down = true; down = true;
} }
int mods = decodeModifiers<wxMouseEvent>( static_cast<wxMouseEvent*>( &aEvent ) ); int mods = decodeModifiers( static_cast<wxMouseEvent*>( &aEvent ) );
int args = st->button | mods; int args = st->button | mods;
if( down ) // Handle mouse button press 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 ) if( t - st->downTimestamp > DragTimeThreshold || st->dragMaxDelta > DragDistanceThreshold )
{ {
evt = TOOL_EVENT( TC_MOUSE, TA_MOUSE_DRAG, args ); evt = TOOL_EVENT( TC_MOUSE, TA_MOUSE_DRAG, args );
evt->SetMouseDragOrigin( st->dragOrigin ); evt->setMouseDragOrigin( st->dragOrigin );
evt->SetMouseDelta( m_lastMousePos - 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 ) type == KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE )
{ {
wxMouseEvent* me = static_cast<wxMouseEvent*>( &aEvent ); wxMouseEvent* me = static_cast<wxMouseEvent*>( &aEvent );
int mods = decodeModifiers<wxMouseEvent>( me ); int mods = decodeModifiers( me );
VECTOR2D screenPos = m_toolMgr->GetViewControls()->GetMousePosition(); VECTOR2D screenPos = m_toolMgr->GetViewControls()->GetMousePosition();
VECTOR2D pos = getView()->ToWorld( screenPos ); VECTOR2D pos = getView()->ToWorld( screenPos );
@ -295,7 +295,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
{ {
wxKeyEvent* ke = static_cast<wxKeyEvent*>( &aEvent ); wxKeyEvent* ke = static_cast<wxKeyEvent*>( &aEvent );
int key = ke->GetKeyCode(); int key = ke->GetKeyCode();
int mods = decodeModifiers<wxKeyEvent>( ke ); int mods = decodeModifiers( ke );
if( mods & MD_CTRL ) if( mods & MD_CTRL )
{ {

View File

@ -494,7 +494,7 @@ void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
if( st->waitEvents.Matches( aEvent ) ) if( st->waitEvents.Matches( aEvent ) )
{ {
// By default, only messages are passed further // 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 // got matching event? clear wait list and wake up the coroutine
st->wakeupEvent = aEvent; st->wakeupEvent = aEvent;
@ -563,7 +563,7 @@ bool TOOL_MANAGER::dispatchActivation( const TOOL_EVENT& aEvent )
{ {
if( aEvent.IsActivate() ) if( aEvent.IsActivate() )
{ {
std::map<std::string, TOOL_STATE*>::iterator tool = m_toolNameIndex.find( *aEvent.m_commandStr ); std::map<std::string, TOOL_STATE*>::iterator tool = m_toolNameIndex.find( *aEvent.GetCommandStr() );
if( tool != m_toolNameIndex.end() ) if( tool != m_toolNameIndex.end() )
{ {

View File

@ -97,8 +97,7 @@ private:
bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion ); bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );
///> Saves the state of key modifiers (Alt, Ctrl and so on). ///> Saves the state of key modifiers (Alt, Ctrl and so on).
template <class EventType> static int decodeModifiers( const wxKeyboardState* aState )
static int decodeModifiers( const EventType* aState )
{ {
int mods = 0; int mods = 0;

View File

@ -185,7 +185,7 @@ public:
{ {
if( aCategory == TC_MOUSE ) if( aCategory == TC_MOUSE )
{ {
m_mouseButtons = aExtraParam & BUT_BUTTON_MASK; setMouseButtons( aExtraParam & BUT_BUTTON_MASK );
} }
else if( aCategory == TC_KEYBOARD ) else if( aCategory == TC_KEYBOARD )
{ {
@ -311,21 +311,6 @@ public:
return m_actions == TA_KEY_PRESSED; 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() * Function Matches()
* Tests whether two events match in terms of category & action or command. * Tests whether two events match in terms of category & action or command.
@ -400,8 +385,35 @@ public:
return m_commandStr; return m_commandStr;
} }
void SetMousePosition( const VECTOR2D& aP )
{
m_mousePos = aP;
}
private: 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_EVENT_CATEGORY m_category;
TOOL_ACTIONS m_actions; TOOL_ACTIONS m_actions;

View File

@ -1029,7 +1029,7 @@ bool EDIT_TOOL::hoverSelection( const SELECTION& aSelection, bool aSanitize )
if( aSanitize ) if( aSanitize )
m_selectionTool->SanitizeSelection(); m_selectionTool->SanitizeSelection();
if( aSelection.Empty() ) if( aSelection.Empty() ) // TODO is it necessary?
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
return !aSelection.Empty(); return !aSelection.Empty();

View File

@ -226,7 +226,6 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
else if( evt->IsAction( &COMMON_ACTIONS::selectionCursor ) ) else if( evt->IsAction( &COMMON_ACTIONS::selectionCursor ) )
{ {
// GetMousePosition() is used, as it is independent of snapping settings
selectCursor( true ); selectCursor( true );
} }
@ -1166,8 +1165,6 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c
if( item->Type() == PCB_MODULE_T && areaRatio < textToFootprintMinRatio ) if( item->Type() == PCB_MODULE_T && areaRatio < textToFootprintMinRatio )
{ {
//printf("rejectModuleN\n");
rejected.insert( item ); rejected.insert( item );
} }
@ -1180,7 +1177,6 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c
case PCB_MODULE_T: case PCB_MODULE_T:
if( areaRatio > textToFeatureMinRatio ) if( areaRatio > textToFeatureMinRatio )
{ {
//printf("t after moduleRejected\n");
rejected.insert( txt ); rejected.insert( txt );
} }
break; break;
@ -1199,21 +1195,21 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c
if( calcRatio( minArea, maxArea ) <= footprintAreaRatio ) if( calcRatio( minArea, maxArea ) <= footprintAreaRatio )
{ {
for( int i = 0; i < aCollector.GetCount(); ++i ) for( int i = 0; i < aCollector.GetCount(); ++i )
{
if( MODULE* mod = dyn_cast<MODULE*>( aCollector[i] ) ) if( MODULE* mod = dyn_cast<MODULE*>( aCollector[i] ) )
{ {
double normalizedArea = calcRatio( calcArea(mod), maxArea ); double normalizedArea = calcRatio( calcArea(mod), maxArea );
if( normalizedArea > footprintAreaRatio ) if( normalizedArea > footprintAreaRatio )
{ {
//printf("rejectModule1\n");
rejected.insert( mod ); 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 ) for( int i = 0; i < aCollector.GetCount(); ++i )
{ {
@ -1314,8 +1310,6 @@ void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) c
{ {
aCollector.Remove( item ); aCollector.Remove( item );
} }
//printf("Post-selection: %d\n", aCollector.GetCount() );
} }
@ -1331,7 +1325,7 @@ bool SELECTION_TOOL::SanitizeSelection()
if( item->Type() == PCB_PAD_T ) if( item->Type() == PCB_PAD_T )
{ {
MODULE* mod = static_cast <MODULE*>( item->GetParent() ); MODULE* mod = static_cast<MODULE*>( item->GetParent() );
// case 1: module (or its pads) are locked // case 1: module (or its pads) are locked
if( mod && ( mod->PadsLocked() || mod->IsLocked() ) ) if( mod && ( mod->PadsLocked() || mod->IsLocked() ) )