diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 4e114a58c1..91df534df7 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -1,3 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Tomasz Wlostowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + #include #include @@ -19,12 +43,12 @@ using boost::optional; struct TOOL_DISPATCHER::ButtonState { - - ButtonState (TOOL_MouseButtons aButton, const wxEventType& aDownEvent, const wxEventType & aUpEvent, bool aTriggerMenu = false) : - button(aButton), - downEvent(aDownEvent), - upEvent(aUpEvent), - triggerContextMenu(aTriggerMenu) + ButtonState( TOOL_MouseButtons aButton, const wxEventType& aDownEvent, + const wxEventType & aUpEvent, bool aTriggerMenu = false) : + button( aButton ), + downEvent( aDownEvent ), + upEvent( aUpEvent ), + triggerContextMenu( aTriggerMenu ) {}; bool dragging; @@ -47,119 +71,123 @@ struct TOOL_DISPATCHER::ButtonState } }; -TOOL_DISPATCHER::TOOL_DISPATCHER( TOOL_MANAGER *aToolMgr, PCB_BASE_FRAME *aEditFrame ): - m_toolMgr(aToolMgr), - m_editFrame(aEditFrame) - { - - m_buttons.push_back(new ButtonState(MB_Left, wxEVT_LEFT_DOWN, wxEVT_LEFT_UP)); - m_buttons.push_back(new ButtonState(MB_Right, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_UP, true)); - m_buttons.push_back(new ButtonState(MB_Middle, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_UP)); - - ResetState(); - }; - + +TOOL_DISPATCHER::TOOL_DISPATCHER( TOOL_MANAGER *aToolMgr, PCB_BASE_FRAME *aEditFrame ) : + m_toolMgr(aToolMgr), m_editFrame(aEditFrame) +{ + m_buttons.push_back( new ButtonState( MB_Left, wxEVT_LEFT_DOWN, wxEVT_LEFT_UP ) ); + m_buttons.push_back( new ButtonState( MB_Right, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_UP, true ) ); + m_buttons.push_back( new ButtonState( MB_Middle, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_UP ) ); + + ResetState(); +} + + TOOL_DISPATCHER::~TOOL_DISPATCHER() { - BOOST_FOREACH(ButtonState *st, m_buttons) + BOOST_FOREACH( ButtonState* st, m_buttons ) delete st; } + void TOOL_DISPATCHER::ResetState() { - BOOST_FOREACH(ButtonState *st, m_buttons) + BOOST_FOREACH( ButtonState* st, m_buttons ) st->Reset(); } - KiGfx::VIEW* TOOL_DISPATCHER::getView() { return m_editFrame->GetGalCanvas()->GetView(); } + int TOOL_DISPATCHER::decodeModifiers( wxEvent& aEvent ) { - wxMouseEvent *me = static_cast (&aEvent); - int mods = 0; + wxMouseEvent* me = static_cast( &aEvent ); + int mods = 0; - if(me->ControlDown()) - mods |= MB_ModCtrl; - if(me->AltDown()) - mods |= MB_ModAlt; - if(me->ShiftDown()) - mods |= MB_ModShift; + if( me->ControlDown() ) + mods |= MB_ModCtrl; + if( me->AltDown() ) + mods |= MB_ModAlt; + if( me->ShiftDown() ) + mods |= MB_ModShift; return mods; } + bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMotion ) { - ButtonState *st = m_buttons[aIndex]; + ButtonState* st = m_buttons[aIndex]; wxEventType type = aEvent.GetEventType(); optional evt; bool up = type == st->upEvent; bool down = type == st->downEvent; - int mods = decodeModifiers(aEvent); + int mods = decodeModifiers( aEvent ); int args = st->button | mods; - if(down) + if( down ) { st->downTimestamp = wxGetLocalTimeMillis(); st->dragOrigin = m_lastMousePos; st->dragMaxDelta = 0; st->pressed = true; - evt = TOOL_EVENT (TC_Mouse, TA_MouseDown, args ); - } else if (up) + evt = TOOL_EVENT( TC_Mouse, TA_MouseDown, args ); + } + else if ( up ) { bool isClick = false; st->pressed = false; - if(st->dragging) + if( st->dragging ) { wxLongLong t = wxGetLocalTimeMillis(); if( t - st->downTimestamp < DragTimeThreshold && st->dragMaxDelta < DragDistanceThreshold ) isClick = true; else - evt = TOOL_EVENT (TC_Mouse, TA_MouseUp, args ); - } else + evt = TOOL_EVENT( TC_Mouse, TA_MouseUp, args ); + } + else isClick = true; - if(isClick) + if( isClick ) { - if(st -> triggerContextMenu && !mods) + if( st -> triggerContextMenu && !mods ) {} - // evt = TOOL_EVENT (TC_Command, TA_ContextMenu ); + // evt = TOOL_EVENT( TC_Command, TA_ContextMenu ); else - evt = TOOL_EVENT (TC_Mouse, TA_MouseClick, args ); + evt = TOOL_EVENT( TC_Mouse, TA_MouseClick, args ); } st->dragging = false; } - if(st->pressed && aMotion) + if( st->pressed && aMotion ) { st->dragging = true; - double dragPixelDistance = getView()->ToScreen(m_lastMousePos - st->dragOrigin, false).EuclideanNorm(); - st->dragMaxDelta = std::max(st->dragMaxDelta, dragPixelDistance); + double dragPixelDistance = getView()->ToScreen( m_lastMousePos - st->dragOrigin, false ).EuclideanNorm(); + st->dragMaxDelta = std::max( st->dragMaxDelta, dragPixelDistance ); wxLongLong t = wxGetLocalTimeMillis(); if( t - st->downTimestamp > DragTimeThreshold || st->dragMaxDelta > DragDistanceThreshold ) { - evt = TOOL_EVENT (TC_Mouse, TA_MouseDrag, args ); - evt->SetMouseDragOrigin(st->dragOrigin); - evt->SetMouseDelta(m_lastMousePos - st->dragOrigin); + evt = TOOL_EVENT( TC_Mouse, TA_MouseDrag, args ); + evt->SetMouseDragOrigin( st->dragOrigin ); + evt->SetMouseDelta( m_lastMousePos - st->dragOrigin ); } } - if(evt) + if( evt ) { - evt->SetMousePosition(m_lastMousePos); + evt->SetMousePosition( m_lastMousePos ); m_toolMgr->ProcessEvent( *evt ); return true; @@ -168,7 +196,8 @@ bool TOOL_DISPATCHER::handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMot return false; } -void TOOL_DISPATCHER::DispatchWxEvent(wxEvent &aEvent) + +void TOOL_DISPATCHER::DispatchWxEvent( wxEvent &aEvent ) { bool motion = false, buttonEvents = false; VECTOR2D pos; @@ -178,37 +207,38 @@ void TOOL_DISPATCHER::DispatchWxEvent(wxEvent &aEvent) if( type == wxEVT_MOTION ) { - wxMouseEvent *me = static_cast (&aEvent); - pos = getView()->ToWorld ( VECTOR2D( me->GetX(), me->GetY() )); - if(pos != m_lastMousePos) + wxMouseEvent *me = static_cast(&aEvent ); + pos = getView()->ToWorld( VECTOR2D( me->GetX(), me->GetY() ) ); + if( pos != m_lastMousePos ) { motion = true; m_lastMousePos = pos; } } - for(unsigned int i = 0; i < m_buttons.size(); i++) - buttonEvents |= handleMouseButton(aEvent, i, motion); + for( unsigned int i = 0; i < m_buttons.size(); i++ ) + buttonEvents |= handleMouseButton( aEvent, i, motion ); - if(!buttonEvents && motion) + if( !buttonEvents && motion ) { evt = TOOL_EVENT (TC_Mouse, TA_MouseMotion ); - evt->SetMousePosition(pos); + evt->SetMousePosition( pos ); } - if(evt) + if( evt ) m_toolMgr->ProcessEvent( *evt ); aEvent.Skip(); } -void TOOL_DISPATCHER::DispatchWxCommand(wxCommandEvent &aEvent) + +void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent &aEvent ) { bool activateTool = false; std::string toolName; - switch (aEvent.GetId()) + switch ( aEvent.GetId() ) { case ID_SELECTION_TOOL: toolName = "pcbnew.InteractiveSelection"; @@ -216,9 +246,9 @@ void TOOL_DISPATCHER::DispatchWxCommand(wxCommandEvent &aEvent) break; } - if(activateTool) + if( activateTool ) { TOOL_EVENT evt ( TC_Command, TA_ActivateTool, toolName ); - m_toolMgr->ProcessEvent(evt); + m_toolMgr->ProcessEvent( evt ); } -} \ No newline at end of file +} diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 2fa4e702e5..f1855907ee 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -1,7 +1,30 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Tomasz Wlostowski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + #include #include - #include #include #include @@ -24,33 +47,30 @@ using namespace std; struct TOOL_MANAGER::ToolState { - TOOL_BASE *theTool; + TOOL_BASE* theTool; bool idle; bool pendingWait; bool pendingContextMenu; - CONTEXT_MENU *contextMenu; + CONTEXT_MENU* contextMenu; TOOL_ContextMenuTrigger contextMenuTrigger; - COROUTINE *cofunc; + COROUTINE* cofunc; TOOL_EVENT wakeupEvent; TOOL_EVENT_LIST waitEvents; std::vector transitions; - - }; TOOL_MANAGER::TOOL_MANAGER() { - } void TOOL_MANAGER::RegisterTool ( TOOL_BASE *aTool ) { - ToolState *st = new ToolState; + ToolState* st = new ToolState; st->theTool = aTool; st->idle = true; @@ -59,25 +79,29 @@ void TOOL_MANAGER::RegisterTool ( TOOL_BASE *aTool ) st->cofunc = NULL; st->contextMenuTrigger = CMENU_OFF; - m_toolState[ aTool ] = st; - m_toolNameIndex [ aTool->GetName() ] = st; - m_toolIdIndex [ aTool->GetId() ] = st; + m_toolState[aTool] = st; + m_toolNameIndex[aTool->GetName()] = st; + m_toolIdIndex[aTool->GetId()] = st; aTool->m_toolMgr = this; - if(aTool->GetType() == TOOL_Interactive) - static_cast(aTool)->Reset(); + if( aTool->GetType() == TOOL_Interactive ) + static_cast( aTool )->Reset(); } -void TOOL_MANAGER::ScheduleNextState( TOOL_BASE *aTool, TOOL_STATE_FUNC& aHandler, const TOOL_EVENT_LIST & aConditions ) + +void TOOL_MANAGER::ScheduleNextState( TOOL_BASE *aTool, TOOL_STATE_FUNC& aHandler, + const TOOL_EVENT_LIST& aConditions ) { - ToolState *st = m_toolState [aTool]; - st->transitions.push_back ( Transition (aConditions, aHandler )); + ToolState* st = m_toolState[aTool]; + st->transitions.push_back( Transition( aConditions, aHandler ) ); } -optional TOOL_MANAGER::ScheduleWait( TOOL_BASE *aTool, const TOOL_EVENT_LIST & aConditions ) + +optional TOOL_MANAGER::ScheduleWait( TOOL_BASE *aTool, + const TOOL_EVENT_LIST& aConditions ) { - ToolState *st = m_toolState [aTool]; + ToolState *st = m_toolState[aTool]; st->pendingWait = true; st->waitEvents = aConditions; @@ -86,34 +110,36 @@ optional TOOL_MANAGER::ScheduleWait( TOOL_BASE *aTool, const TOOL_EV return st->wakeupEvent; } -void TOOL_MANAGER::dispatchInternal ( TOOL_EVENT& aEvent ) + +void TOOL_MANAGER::dispatchInternal( TOOL_EVENT& aEvent ) { // iterate over all registered tools - BOOST_FOREACH(ToolState *st, m_toolState | boost::adaptors::map_values) + BOOST_FOREACH( ToolState* st, m_toolState | boost::adaptors::map_values ) { // the tool state handler is waiting for events (i.e. called Wait() method) - if(st->pendingWait) + if( st->pendingWait ) { - - if( st->waitEvents.Matches(aEvent) ) + if( st->waitEvents.Matches( aEvent ) ) { // got matching event? clear wait list and wake up the coroutine st->wakeupEvent = aEvent; st->pendingWait = false; st->waitEvents.clear(); st->cofunc->Resume(); - if(!st->cofunc->Running()) + if( !st->cofunc->Running() ) delete st->cofunc; - } - } else { + } + else + { // no state handler in progress - check if there are any transitions (defined by // Go() method that match the event. - if(st->transitions.size()) { - BOOST_FOREACH(Transition tr, st->transitions) + if( st->transitions.size() ) + { + BOOST_FOREACH( Transition tr, st->transitions ) { - if(tr.first.Matches(aEvent)) + if( tr.first.Matches( aEvent ) ) { st->transitions.clear(); @@ -123,9 +149,9 @@ void TOOL_MANAGER::dispatchInternal ( TOOL_EVENT& aEvent ) st->cofunc->SetEntry( tr.second ); // got match? Run the handler. - st->cofunc->Call(aEvent); + st->cofunc->Call( aEvent ); - if(!st->cofunc->Running()) + if( !st->cofunc->Running() ) delete st->cofunc; } } @@ -134,16 +160,16 @@ void TOOL_MANAGER::dispatchInternal ( TOOL_EVENT& aEvent ) } } -bool TOOL_MANAGER::ProcessEvent (TOOL_EVENT& aEvent) + +bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent ) { - printf("process: %s\n", aEvent.Format().c_str()); + printf( "process: %s\n", aEvent.Format().c_str() ); - dispatchInternal(aEvent); + dispatchInternal( aEvent ); - - BOOST_FOREACH(ToolState *st, m_toolState | boost::adaptors::map_values) + BOOST_FOREACH( ToolState* st, m_toolState | boost::adaptors::map_values ) { - if(st->contextMenuTrigger == CMENU_NOW) + if( st->contextMenuTrigger == CMENU_NOW ) { st->pendingWait = true; st->waitEvents = TOOL_EVENT ( TC_Any, TA_Any ); @@ -157,33 +183,37 @@ bool TOOL_MANAGER::ProcessEvent (TOOL_EVENT& aEvent) } } - if(m_view->IsDirty()) + if( m_view->IsDirty() ) { - PCB_EDIT_FRAME *f = static_cast(GetEditFrame()); + PCB_EDIT_FRAME* f = static_cast( GetEditFrame() ); f->GetGalCanvas()->Refresh(); // fixme: ugly hack, provide a method in TOOL_DISPATCHER. } return false; } -void TOOL_MANAGER::ScheduleContextMenu( TOOL_BASE *aTool, CONTEXT_MENU *aMenu, TOOL_ContextMenuTrigger aTrigger ) + +void TOOL_MANAGER::ScheduleContextMenu( TOOL_BASE* aTool, CONTEXT_MENU* aMenu, + TOOL_ContextMenuTrigger aTrigger ) { - ToolState *st = m_toolState [aTool]; + ToolState* st = m_toolState[aTool]; st->contextMenu = aMenu; st->contextMenuTrigger = aTrigger; - if(aTrigger == CMENU_NOW) + if( aTrigger == CMENU_NOW ) st->cofunc->Yield(); } -TOOL_ID TOOL_MANAGER::MakeToolId( const std::string &aToolName ) + +TOOL_ID TOOL_MANAGER::MakeToolId( const std::string& aToolName ) { static int currentId; return currentId++; } -void TOOL_MANAGER::SetEnvironment( EDA_ITEM *aModel, KiGfx::VIEW* aView, KiGfx::VIEW_CONTROLS *aViewControls, wxWindow *aFrame ) +void TOOL_MANAGER::SetEnvironment( EDA_ITEM* aModel, KiGfx::VIEW* aView, + KiGfx::VIEW_CONTROLS* aViewControls, wxWindow* aFrame ) { m_model = aModel; m_view = aView; diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index bc81a32f6c..3aaf93ecad 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -29,6 +29,7 @@ #include #include +#include #include @@ -717,9 +718,13 @@ public: */ virtual void DrawCursor( VECTOR2D aCursorPosition ) = 0; + /** + * @brief Changes the current depth to deeper, so it is possible to draw objects right beneath + * other. + */ inline void AdvanceDepth() { - layerDepth -= 0.1; // fixme: there should be a minimum step + layerDepth -= std::numeric_limits::epsilon(); } /** diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index 572d4bc60e..2060b0d544 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -50,40 +50,39 @@ namespace KiGfx { class TOOL_DISPATCHER { - public: - /** - * Constructor - * - * @param aToolMgr: tool manager instance the events will be sent to - * @param aEditFrame: the frame wx events come from - */ - TOOL_DISPATCHER( TOOL_MANAGER *aToolMgr, PCB_BASE_FRAME *aEditFrame ); - ~TOOL_DISPATCHER(); - - virtual void ResetState (); - virtual void DispatchWxEvent(wxEvent &aEvent); - virtual void DispatchWxCommand(wxCommandEvent &aEvent); - - private: - - static const int MouseButtonCount = 3; - static const int DragTimeThreshold = 300; - static const int DragDistanceThreshold = 8; +public: + /** + * Constructor + * + * @param aToolMgr: tool manager instance the events will be sent to + * @param aEditFrame: the frame wx events come from + */ + TOOL_DISPATCHER( TOOL_MANAGER* aToolMgr, PCB_BASE_FRAME* aEditFrame ); + virtual ~TOOL_DISPATCHER(); - bool handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMotion ); - bool handleKeys ( wxEvent& aEvent ); - bool handlePopupMenu ( wxEvent& aEvent ); + virtual void ResetState(); + virtual void DispatchWxEvent( wxEvent& aEvent ); + virtual void DispatchWxCommand( wxCommandEvent& aEvent ); - int decodeModifiers( wxEvent& aEvent ); +private: + static const int MouseButtonCount = 3; + static const int DragTimeThreshold = 300; + static const int DragDistanceThreshold = 8; - KiGfx::VIEW *getView(); + bool handleMouseButton ( wxEvent& aEvent, int aIndex, bool aMotion ); + bool handleKeys ( wxEvent& aEvent ); + bool handlePopupMenu ( wxEvent& aEvent ); - struct ButtonState; - - TOOL_MANAGER *m_toolMgr; - PCB_BASE_FRAME *m_editFrame; - VECTOR2D m_lastMousePos; - std::vector m_buttons; + int decodeModifiers( wxEvent& aEvent ); + + KiGfx::VIEW* getView(); + + struct ButtonState; + + TOOL_MANAGER* m_toolMgr; + PCB_BASE_FRAME* m_editFrame; + VECTOR2D m_lastMousePos; + std::vector m_buttons; }; diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index 4a70d5048a..a41200b6e7 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -58,7 +58,7 @@ class TOOL_MANAGER /** * Generates an unique ID from for a tool with given name. */ - static TOOL_ID MakeToolId( const std::string &aToolName ); + static TOOL_ID MakeToolId( const std::string& aToolName ); /** * Function RegisterTool() @@ -66,46 +66,46 @@ class TOOL_MANAGER * each tool during application initialization. * @param aTool: tool to be added. Ownership is transferred. */ - void RegisterTool(TOOL_BASE *aTool); + void RegisterTool( TOOL_BASE* aTool ); /** * Function InvokeTool() * Calls a tool by sending a tool activation event to tool of given ID or name. * An user-defined parameter object can be also passed */ - void InvokeTool(TOOL_ID aToolId); - void InvokeTool(const std::string& name); + void InvokeTool( TOOL_ID aToolId ); + void InvokeTool( const std::string& name ); template - void InvokeTool( const std::string& name, const Parameters& aToolParams); + void InvokeTool( const std::string& name, const Parameters& aToolParams ); /** * Function FindTool() * Searches for a tool with given name or ID */ - TOOL_BASE *FindTool(int aId); - TOOL_BASE *FindTool(const std::string& aName); + TOOL_BASE *FindTool( int aId ); + TOOL_BASE *FindTool( const std::string& aName ); /** * Resets the state of a given tool by clearing its wait and * transition lists and calling tool's internal Reset() method. */ - void ResetTool( TOOL_BASE *aTool ); /** * Takes an event from the TOOL_DISPATCHER and propagates it to * tools that requested events of matching type(s) */ - bool ProcessEvent (TOOL_EVENT& aEvent); + bool ProcessEvent( TOOL_EVENT& aEvent ); /** * Sets the work environment (model, view, view controls and the parent window). * These are made available to the tool. Called by the parent frame (PCB_EDIT_FRAME) * when the board is set up */ - void SetEnvironment( EDA_ITEM *aModel, KiGfx::VIEW* aView, KiGfx::VIEW_CONTROLS *aViewControls, wxWindow *aFrame ); + void SetEnvironment( EDA_ITEM* aModel, KiGfx::VIEW* aView, + KiGfx::VIEW_CONTROLS* aViewControls, wxWindow* aFrame ); /* Accessors for the environment objects (view, model, etc.) */ KiGfx::VIEW* GetView() @@ -132,13 +132,16 @@ class TOOL_MANAGER * Defines a state transition - the events that cause a given handler method in the tool * to be called. Called by TOOL_INTERACTIVE::Go(). May be called from a coroutine context. */ - void ScheduleNextState( TOOL_BASE *aTool, TOOL_STATE_FUNC& aHandler, const TOOL_EVENT_LIST & aConditions ); + void ScheduleNextState( TOOL_BASE* aTool, TOOL_STATE_FUNC& aHandler, + const TOOL_EVENT_LIST& aConditions ); /** - * Pauses execution of a given tool until one or more events matching aConditions arrives. The pause/resume - * operation is done through COROUTINE object. Called only from coroutines. + * Pauses execution of a given tool until one or more events matching aConditions arrives. + * The pause/resume operation is done through COROUTINE object. + * Called only from coroutines. */ - boost::optional ScheduleWait( TOOL_BASE *aTool, const TOOL_EVENT_LIST & aConditions ); + boost::optional ScheduleWait( TOOL_BASE* aTool, + const TOOL_EVENT_LIST& aConditions ); /** * Sets behaviour of the tool's context popup menu. @@ -149,10 +152,10 @@ class TOOL_MANAGER * CMENU_OFF: menu is disabled. * May be called from a coroutine context. */ - void ScheduleContextMenu( TOOL_BASE *aTool, CONTEXT_MENU *aMenu, TOOL_ContextMenuTrigger aTrigger ); + void ScheduleContextMenu( TOOL_BASE* aTool, CONTEXT_MENU* aMenu, + TOOL_ContextMenuTrigger aTrigger ); private: - void dispatchInternal ( TOOL_EVENT& aEvent ); struct ToolState; @@ -162,13 +165,12 @@ class TOOL_MANAGER std::map m_toolNameIndex; std::map m_toolIdIndex; - EDA_ITEM *m_model; - KiGfx::VIEW *m_view; - KiGfx::VIEW_CONTROLS *m_viewControls; - wxWindow *m_editFrame; + EDA_ITEM* m_model; + KiGfx::VIEW* m_view; + KiGfx::VIEW_CONTROLS* m_viewControls; + wxWindow* m_editFrame; - ToolState *m_currentTool; + ToolState* m_currentTool; }; - -#endif \ No newline at end of file +#endif diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index d2c60a5498..4ee70cde94 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -41,15 +41,15 @@ void PCB_EDIT_FRAME::setupTools() // create the manager and dispatcher. Route draw panel events to the dispatcher. m_toolManager = new TOOL_MANAGER; m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, this ); - m_galCanvas->SetEventDispatcher (m_toolDispatcher); + m_galCanvas->SetEventDispatcher( m_toolDispatcher ); // register our selection tool. - m_toolManager->RegisterTool(new SELECTION_TOOL); - + m_toolManager->RegisterTool( new SELECTION_TOOL ); } -void PCB_EDIT_FRAME::onGenericCommand(wxCommandEvent &aEvent) + +void PCB_EDIT_FRAME::onGenericCommand( wxCommandEvent &aEvent ) { - m_toolDispatcher->DispatchWxCommand(aEvent); + m_toolDispatcher->DispatchWxCommand( aEvent ); } diff --git a/pcbnew/tools/selection_area.cpp b/pcbnew/tools/selection_area.cpp index 717a09bfc6..3b8c52d0e6 100644 --- a/pcbnew/tools/selection_area.cpp +++ b/pcbnew/tools/selection_area.cpp @@ -39,15 +39,17 @@ const BOX2I SELECTION_AREA::ViewBBox() const return tmp; } + void SELECTION_AREA::ViewGetLayers( int aLayers[], int& aCount ) const { aLayers[0] = SelectionLayer; aCount = 1; } + void SELECTION_AREA::ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const { - VECTOR2D width = m_view->ToWorld( VECTOR2D(1.0, 1.0), false ); // fixme: pixel-sized stroke width setting? + VECTOR2D width = m_view->ToWorld( VECTOR2D( 1.0, 1.0 ), false ); // fixme: pixel-sized stroke width setting? aGal->SetLineWidth( width.x ); aGal->SetStrokeColor(COLOR4D(1.0, 1.0, 0.4, 1.0)); aGal->SetFillColor(COLOR4D(0.3, 0.3, 0.5, 0.3)); @@ -57,6 +59,8 @@ void SELECTION_AREA::ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea aGal->DrawRectangle(m_origin, m_end); } -SELECTION_AREA::SELECTION_AREA(): - EDA_ITEM(NOT_USED) // this item is never added to a BOARD so it needs no type. - {} \ No newline at end of file + +SELECTION_AREA::SELECTION_AREA() : + EDA_ITEM( NOT_USED ) // this item is never added to a BOARD so it needs no type. +{ +} diff --git a/pcbnew/tools/selection_area.h b/pcbnew/tools/selection_area.h index f4677f40a7..e004339d9b 100644 --- a/pcbnew/tools/selection_area.h +++ b/pcbnew/tools/selection_area.h @@ -41,36 +41,33 @@ */ class SELECTION_AREA : public EDA_ITEM { - public: - static const int SelectionLayer = 126; // fixme: define globally +public: + static const int SelectionLayer = 126; // fixme: define globally - SELECTION_AREA(); - ~SELECTION_AREA() {}; + SELECTION_AREA(); + ~SELECTION_AREA() {}; - virtual const BOX2I ViewBBox() const; + virtual const BOX2I ViewBBox() const; - void ViewDraw( int aLayer, KiGfx::GAL* aGal, const BOX2I& aVisibleArea ) const; - void ViewGetLayers( int aLayers[], int& aCount ) const; + void ViewDraw( int aLayer, KiGfx::GAL* aGal, const BOX2I& aVisibleArea ) const; + void ViewGetLayers( int aLayers[], int& aCount ) const; - void SetOrigin ( VECTOR2I aOrigin ) - { - m_origin = aOrigin; - } + void SetOrigin ( VECTOR2I aOrigin ) + { + m_origin = aOrigin; + } - void SetEnd ( VECTOR2I aEnd ) - { - m_end = aEnd; - } + void SetEnd ( VECTOR2I aEnd ) + { + m_end = aEnd; + } - void Show(int x, std::ostream& st) const - { + void Show(int x, std::ostream& st) const + { + } - } - - private: - - - VECTOR2I m_origin, m_end; +private: + VECTOR2I m_origin, m_end; }; #endif diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index c2cbc2978f..acd33326d6 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -64,11 +64,9 @@ void SELECTION_TOOL::Reset() int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) { - // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { - if( evt->IsCancel() ) return 0; @@ -87,7 +85,6 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem, bool aAdditive ) { - if( m_selectedItems.find( aItem ) != m_selectedItems.end() ) { aItem->ClearSelected(); @@ -104,7 +101,7 @@ void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem, bool aAdditive ) void SELECTION_TOOL::clearSelection() { - BOOST_FOREACH(BOARD_ITEM* item, m_selectedItems) + BOOST_FOREACH( BOARD_ITEM* item, m_selectedItems ) { item->ClearSelected(); } @@ -113,17 +110,17 @@ void SELECTION_TOOL::clearSelection() } -void SELECTION_TOOL::selectSingle( const VECTOR2I &aWhere, bool aAdditive ) +void SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere, bool aAdditive ) { - BOARD *pcb = getModel( PCB_T ); - BOARD_ITEM *item; + BOARD* pcb = getModel( PCB_T ); + BOARD_ITEM* item; GENERAL_COLLECTORS_GUIDE guide = getEditFrame()->GetCollectorsGuide(); GENERAL_COLLECTOR collector; collector.Collect( pcb, GENERAL_COLLECTOR::AllBoardItems, wxPoint( aWhere.x, aWhere.y ), guide ); - switch (collector.GetCount()) + switch( collector.GetCount() ) { case 0: if( !aAdditive ) @@ -161,7 +158,7 @@ BOARD_ITEM* SELECTION_TOOL::pickSmallestComponent( GENERAL_COLLECTOR* aCollector for( int i = 0; i < count; ++i ) { - MODULE* module = (MODULE*) ( *aCollector )[i]; + MODULE* module = (MODULE*)( *aCollector )[i]; int lx = module->GetBoundingBox().GetWidth(); int ly = module->GetBoundingBox().GetHeight(); @@ -175,7 +172,7 @@ BOARD_ITEM* SELECTION_TOOL::pickSmallestComponent( GENERAL_COLLECTOR* aCollector } } - return ( *aCollector )[minNdx]; + return (*aCollector)[minNdx]; } @@ -219,7 +216,7 @@ void SELECTION_TOOL::selectMultiple() } -BOARD_ITEM *SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR *aCollector ) +BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR *aCollector ) { CONTEXT_MENU cmenu; OPT_TOOL_EVENT evt; diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index e3020d3758..8db55dd306 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -56,13 +56,13 @@ public: int Main(TOOL_EVENT& aEvent); private: - void selectSingle( const VECTOR2I &aWhere, bool aAdditive ); - void selectMultiple (); + void selectSingle( const VECTOR2I& aWhere, bool aAdditive ); + void selectMultiple(); void handleHighlight( const VECTOR2D& aP ); - BOARD_ITEM* disambiguationMenu ( GENERAL_COLLECTOR* aItems ); + BOARD_ITEM* disambiguationMenu( GENERAL_COLLECTOR* aItems ); BOARD_ITEM* pickSmallestComponent( GENERAL_COLLECTOR* aCollector ); - void toggleSelection ( BOARD_ITEM * aItem, bool aAdditive ); - void clearSelection (); + void toggleSelection( BOARD_ITEM* aItem, bool aAdditive ); + void clearSelection(); std::set m_selectedItems; SELECTION_AREA* m_selArea;