Commit 7d5a4563 authored by Maciej Suminski's avatar Maciej Suminski

Code reformatting.

parent f193e389
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* 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 <wx/wx.h>
#include <wx/event.h>
......@@ -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));
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<wxMouseEvent*> (&aEvent);
wxMouseEvent* me = static_cast<wxMouseEvent*>( &aEvent );
int mods = 0;
if(me->ControlDown())
if( me->ControlDown() )
mods |= MB_ModCtrl;
if(me->AltDown())
if( me->AltDown() )
mods |= MB_ModAlt;
if(me->ShiftDown())
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<TOOL_EVENT> 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<wxMouseEvent*> (&aEvent);
pos = getView()->ToWorld ( VECTOR2D( me->GetX(), me->GetY() ));
if(pos != m_lastMousePos)
wxMouseEvent *me = static_cast<wxMouseEvent*>(&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 );
}
}
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* 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 <map>
#include <deque>
#include <boost/foreach.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptor/map.hpp>
......@@ -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<int, TOOL_EVENT&> *cofunc;
COROUTINE<int, TOOL_EVENT&>* cofunc;
TOOL_EVENT wakeupEvent;
TOOL_EVENT_LIST waitEvents;
std::vector<Transition> 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<TOOL_INTERACTIVE*>(aTool)->Reset();
if( aTool->GetType() == TOOL_Interactive )
static_cast<TOOL_INTERACTIVE*>( 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_EVENT> TOOL_MANAGER::ScheduleWait( TOOL_BASE *aTool, const TOOL_EVENT_LIST & aConditions )
optional<TOOL_EVENT> 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_EVENT> 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)
{
printf("process: %s\n", aEvent.Format().c_str());
dispatchInternal(aEvent);
bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent )
{
printf( "process: %s\n", aEvent.Format().c_str() );
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<PCB_EDIT_FRAME*>(GetEditFrame());
PCB_EDIT_FRAME* f = static_cast<PCB_EDIT_FRAME*>( 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;
......
......@@ -29,6 +29,7 @@
#include <deque>
#include <stack>
#include <limits>
#include <wx/event.h>
......@@ -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<double>::epsilon();
}
/**
......
......@@ -50,22 +50,21 @@ namespace KiGfx {
class TOOL_DISPATCHER
{
public:
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();
TOOL_DISPATCHER( TOOL_MANAGER* aToolMgr, PCB_BASE_FRAME* aEditFrame );
virtual ~TOOL_DISPATCHER();
virtual void ResetState ();
virtual void DispatchWxEvent(wxEvent &aEvent);
virtual void DispatchWxCommand(wxCommandEvent &aEvent);
private:
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;
......@@ -76,12 +75,12 @@ class TOOL_DISPATCHER
int decodeModifiers( wxEvent& aEvent );
KiGfx::VIEW *getView();
KiGfx::VIEW* getView();
struct ButtonState;
TOOL_MANAGER *m_toolMgr;
PCB_BASE_FRAME *m_editFrame;
TOOL_MANAGER* m_toolMgr;
PCB_BASE_FRAME* m_editFrame;
VECTOR2D m_lastMousePos;
std::vector<ButtonState*> m_buttons;
......
......@@ -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 <class Parameters>
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<TOOL_EVENT> ScheduleWait( TOOL_BASE *aTool, const TOOL_EVENT_LIST & aConditions );
boost::optional<TOOL_EVENT> 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<std::string, ToolState*> m_toolNameIndex;
std::map<TOOL_ID, ToolState*> 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
......@@ -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 );
}
......@@ -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.
{
}
......@@ -41,7 +41,7 @@
*/
class SELECTION_AREA : public EDA_ITEM
{
public:
public:
static const int SelectionLayer = 126; // fixme: define globally
SELECTION_AREA();
......@@ -64,12 +64,9 @@ class SELECTION_AREA : public EDA_ITEM
void Show(int x, std::ostream& st) const
{
}
private:
private:
VECTOR2I m_origin, m_end;
};
......
......@@ -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<BOARD>( PCB_T );
BOARD_ITEM *item;
BOARD* pcb = getModel<BOARD>( PCB_T );
BOARD_ITEM* item;
GENERAL_COLLECTORS_GUIDE guide = getEditFrame<PCB_EDIT_FRAME>()->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;
......
......@@ -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<BOARD_ITEM*> m_selectedItems;
SELECTION_AREA* m_selArea;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment