Commit ee80c7f6 authored by Maciej Suminski's avatar Maciej Suminski

Some more reformatting and adding copyright notices.

parent 62ea71fc
/*
* 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/menu.h>
......@@ -10,7 +34,7 @@
class CONTEXT_MENU::CMEventHandler : public wxEvtHandler
{
public:
CMEventHandler( CONTEXT_MENU *aMenu ):
CMEventHandler( CONTEXT_MENU* aMenu ):
m_menu(aMenu) {};
void onEvent( wxEvent & aEvent )
......@@ -18,53 +42,57 @@ public:
TOOL_EVENT evt;
wxEventType type = aEvent.GetEventType();
if(type == wxEVT_MENU_HIGHLIGHT)
evt = TOOL_EVENT (TC_Command, TA_ContextMenuUpdate, aEvent.GetId() );
else if (type == wxEVT_COMMAND_MENU_SELECTED)
evt = TOOL_EVENT (TC_Command, TA_ContextMenuChoice, aEvent.GetId() );
if( type == wxEVT_MENU_HIGHLIGHT )
evt = TOOL_EVENT( TC_Command, TA_ContextMenuUpdate, aEvent.GetId() );
else if ( type == wxEVT_COMMAND_MENU_SELECTED )
evt = TOOL_EVENT( TC_Command, TA_ContextMenuChoice, aEvent.GetId() );
m_menu->m_tool->GetManager()->ProcessEvent(evt);
m_menu->m_tool->GetManager()->ProcessEvent( evt );
}
private:
CONTEXT_MENU *m_menu;
CONTEXT_MENU* m_menu;
};
CONTEXT_MENU::CONTEXT_MENU ( )
CONTEXT_MENU::CONTEXT_MENU()
{
m_tool = NULL;
m_menu = new wxMenu();
m_handler = new CMEventHandler(this);
m_menu->Connect (wxEVT_MENU_HIGHLIGHT, wxEventHandler( CMEventHandler::onEvent ), NULL, m_handler );
m_menu->Connect (wxEVT_COMMAND_MENU_SELECTED, wxEventHandler( CMEventHandler::onEvent ), NULL, m_handler );
m_handler = new CMEventHandler( this );
m_menu->Connect( wxEVT_MENU_HIGHLIGHT, wxEventHandler( CMEventHandler::onEvent ), NULL, m_handler );
m_menu->Connect( wxEVT_COMMAND_MENU_SELECTED, wxEventHandler( CMEventHandler::onEvent ), NULL, m_handler );
m_titleSet = false;
}
CONTEXT_MENU::~CONTEXT_MENU ( )
CONTEXT_MENU::~CONTEXT_MENU()
{
delete m_menu;
delete m_handler;
}
void CONTEXT_MENU::SetTitle( const wxString& aTitle )
{
if(m_titleSet)
if( m_titleSet )
{
m_menu->Delete(m_menu->FindItemByPosition(0)); // fixme: this is LAME!
m_menu->Delete(m_menu->FindItemByPosition(0));
m_menu->Delete( m_menu->FindItemByPosition( 0 ) ); // fixme: this is LAME!
m_menu->Delete( m_menu->FindItemByPosition( 0 ) );
}
m_menu->InsertSeparator(0);
m_menu->Insert(0, new wxMenuItem( m_menu, -1, aTitle, wxEmptyString, wxITEM_NORMAL ) );
m_menu->InsertSeparator( 0 );
m_menu->Insert( 0, new wxMenuItem( m_menu, -1, aTitle, wxEmptyString, wxITEM_NORMAL ) );
m_titleSet = true;
}
void CONTEXT_MENU::Add ( const wxString& aItem, int aId )
{
m_menu->Append( new wxMenuItem( m_menu, aId, aItem, wxEmptyString, wxITEM_NORMAL ) );
}
void CONTEXT_MENU::Clear()
{
m_titleSet = false;
......
/*
* 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 <tool/tool_event.h>
#include <tool/tool_manager.h>
KiGfx::VIEW *TOOL_BASE::getView()
KiGfx::VIEW* TOOL_BASE::getView()
{
return m_toolMgr->GetView();
}
KiGfx::VIEW_CONTROLS *TOOL_BASE::getViewControls()
KiGfx::VIEW_CONTROLS* TOOL_BASE::getViewControls()
{
return m_toolMgr->GetViewControls();
}
wxWindow * TOOL_BASE::getEditFrameInt()
wxWindow* TOOL_BASE::getEditFrameInt()
{
return m_toolMgr->GetEditFrame();
}
EDA_ITEM * TOOL_BASE::getModelInt()
EDA_ITEM* TOOL_BASE::getModelInt()
{
return m_toolMgr->GetModel();
}
/*
* 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 <cstring>
#include <string>
......@@ -10,12 +34,14 @@
using namespace std;
struct FlagString {
struct FlagString
{
int flag;
std::string str;
};
static const std::string flag2string(int flag, const FlagString *exps)
static const std::string flag2string( int flag, const FlagString* exps )
{
std::string rv;
for(int i = 0; exps[i].str.length(); i++)
......@@ -24,78 +50,80 @@ static const std::string flag2string(int flag, const FlagString *exps)
return rv;
}
const std::string TOOL_EVENT::Format() const
{
std::string ev;
const FlagString categories[] = {
{TC_Mouse, "mouse"},
{TC_Command, "command"},
{TC_Message, "message"},
{TC_View, "view"},
{0, ""}
{ TC_Mouse, "mouse" },
{ TC_Command, "command" },
{ TC_Message, "message" },
{ TC_View, "view" },
{ 0, "" }
};
const FlagString actions[] = {
{TA_MouseClick, "click"},
{TA_MouseUp, "button-up"},
{TA_MouseDown, "button-down"},
{TA_MouseDrag, "drag"},
{TA_MouseMotion, "motion"},
{TA_MouseWheel, "wheel"},
{TA_ViewRefresh, "view-refresh"},
{TA_ViewZoom, "view-zoom"},
{TA_ViewPan, "view-pan"},
{TA_ViewDirty, "view-dirty"},
{TA_ChangeLayer, "change-layer"},
{TA_CancelTool, "cancel-tool"},
{TA_ActivateTool, "activate-tool"},
{TA_ContextMenuUpdate, "context-menu-update"},
{TA_ContextMenuChoice, "context-menu-choice"},
{0, ""}
{ TA_MouseClick, "click" },
{ TA_MouseUp, "button-up" },
{ TA_MouseDown, "button-down" },
{ TA_MouseDrag, "drag" },
{ TA_MouseMotion, "motion" },
{ TA_MouseWheel, "wheel" },
{ TA_ViewRefresh, "view-refresh" },
{ TA_ViewZoom, "view-zoom" },
{ TA_ViewPan, "view-pan" },
{ TA_ViewDirty, "view-dirty" },
{ TA_ChangeLayer, "change-layer" },
{ TA_CancelTool, "cancel-tool" },
{ TA_ActivateTool, "activate-tool" },
{ TA_ContextMenuUpdate, "context-menu-update" },
{ TA_ContextMenuChoice, "context-menu-choice" },
{ 0, "" }
};
const FlagString buttons[] = {
{MB_None, "none"},
{MB_Left, "left"},
{MB_Right, "right"},
{MB_Middle, "middle"},
{MB_ModShift, "shift"},
{MB_ModCtrl, "ctrl"},
{MB_ModAlt, "alt"},
{0, ""}
{ MB_None, "none" },
{ MB_Left, "left" },
{ MB_Right, "right" },
{ MB_Middle, "middle" },
{ MB_ModShift, "shift" },
{ MB_ModCtrl, "ctrl" },
{ MB_ModAlt, "alt" },
{ 0, "" }
};
ev = "category: ";
ev += flag2string(m_category, categories);
ev += flag2string( m_category, categories );
ev +=" action: ";
ev += flag2string(m_actions, actions);
ev += flag2string( m_actions, actions );
if(m_actions & TA_Mouse)
if( m_actions & TA_Mouse )
{
ev +=" btns: ";
ev += flag2string(m_mouseButtons, buttons);
ev += flag2string( m_mouseButtons, buttons );
};
if(m_commandId)
if( m_commandId )
{
char tmp[128];
sprintf(tmp,"cmd-id: %d", *m_commandId);
sprintf( tmp, "cmd-id: %d", *m_commandId );
ev += tmp;
}
if(m_commandStr)
ev += "cmd-str: " + (*m_commandStr);
if( m_commandStr )
ev += "cmd-str: " + ( *m_commandStr );
return ev;
}
const std::string TOOL_EVENT_LIST::Format() const
{
string s;
BOOST_FOREACH(TOOL_EVENT e, m_events)
s+=e.Format()+" ";
BOOST_FOREACH( TOOL_EVENT e, m_events )
s += e.Format() + " ";
return s;
}
/*
* 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 <string>
#include <tool/tool_event.h>
......@@ -5,37 +29,40 @@
#include <tool/tool_interactive.h>
#include <tool/context_menu.h>
TOOL_INTERACTIVE::TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName ):
TOOL_BASE(TOOL_Interactive, aId, aName)
TOOL_INTERACTIVE::TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName ) :
TOOL_BASE( TOOL_Interactive, aId, aName )
{};
TOOL_INTERACTIVE::TOOL_INTERACTIVE( const std::string& aName ):
TOOL_BASE(TOOL_Interactive, TOOL_MANAGER::MakeToolId(aName), aName)
TOOL_INTERACTIVE::TOOL_INTERACTIVE( const std::string& aName ) :
TOOL_BASE( TOOL_Interactive, TOOL_MANAGER::MakeToolId( aName ), aName )
{};
TOOL_INTERACTIVE::~TOOL_INTERACTIVE()
{
}
OPT_TOOL_EVENT TOOL_INTERACTIVE::Wait ( const TOOL_EVENT_LIST & aEventList )
{
return m_toolMgr->ScheduleWait(this, aEventList);
return m_toolMgr->ScheduleWait( this, aEventList );
}
void TOOL_INTERACTIVE::goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions )
{
m_toolMgr->ScheduleNextState(this, aState, aConditions);
m_toolMgr->ScheduleNextState( this, aState, aConditions );
}
void TOOL_INTERACTIVE::Reset()
{
}
void TOOL_INTERACTIVE::SetContextMenu( CONTEXT_MENU *aMenu, TOOL_ContextMenuTrigger aTrigger )
{
aMenu->setTool(this);
m_toolMgr->ScheduleContextMenu(this, aMenu, aTrigger);
aMenu->setTool( this );
m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger );
}
......@@ -41,8 +41,8 @@ class CONTEXT_MENU
public:
CONTEXT_MENU ( );
~CONTEXT_MENU ( );
CONTEXT_MENU();
~CONTEXT_MENU();
void SetTitle( const wxString& aTitle );
void Add ( const wxString& aItem, int aId );
......@@ -52,27 +52,26 @@ public:
void Clear();
wxMenu *GetMenu() const
wxMenu* GetMenu() const
{
return m_menu;
}
private:
class CMEventHandler;
friend class TOOL_INTERACTIVE;
void setTool ( TOOL_INTERACTIVE *aTool )
void setTool ( TOOL_INTERACTIVE* aTool )
{
m_tool = aTool;
}
bool m_titleSet;
wxMenu *m_menu;
CMEventHandler *m_handler;
TOOL_INTERACTIVE *m_tool;
wxMenu* m_menu;
CMEventHandler* m_handler;
TOOL_INTERACTIVE* m_tool;
};
#endif
......@@ -26,9 +26,7 @@
#define __TOOL_BASE_H
#include <cassert>
// for KICAD_T.
#include <base_struct.h>
#include <base_struct.h> // for KICAD_T
#include <tool/tool_event.h>
#include <tool/delegate.h>
......@@ -36,13 +34,14 @@
class EDA_ITEM;
class TOOL_MANAGER;
namespace KiGfx {
class VIEW;
class VIEW_CONTROLS;
namespace KiGfx
{
class VIEW;
class VIEW_CONTROLS;
};
enum TOOL_Type {
enum TOOL_Type
{
TOOL_Interactive = 0x1,
TOOL_Batch = 0x2
};
......@@ -60,10 +59,10 @@ class TOOL_BASE
{
public:
TOOL_BASE(TOOL_Type aType, TOOL_ID aId, const std::string& aName = std::string("")) :
m_type(aType),
m_toolId(aId),
m_toolName(aName) {};
TOOL_BASE( TOOL_Type aType, TOOL_ID aId, const std::string& aName = std::string( "" ) ) :
m_type( aType ),
m_toolId( aId ),
m_toolName( aName ) {};
virtual ~TOOL_BASE() {};
......@@ -82,13 +81,12 @@ public:
return m_toolName;
}
TOOL_MANAGER *GetManager()
TOOL_MANAGER* GetManager()
{
return m_toolMgr;
}
protected:
friend class TOOL_MANAGER;
/**
......@@ -99,8 +97,8 @@ protected:
*/
void attachManager( TOOL_MANAGER *aManager );
KiGfx::VIEW *getView();
KiGfx::VIEW_CONTROLS *getViewControls();
KiGfx::VIEW* getView();
KiGfx::VIEW_CONTROLS* getViewControls();
/**
* Function getEditFrame()
......@@ -111,7 +109,7 @@ protected:
template<typename T>
T *getEditFrame()
{
return static_cast<T*> (getEditFrameInt());
return static_cast<T*>( getEditFrameInt() );
}
/**
......@@ -124,24 +122,20 @@ protected:
{
EDA_ITEM *m = getModelInt();
// assert(modelType == m->Type());
return static_cast<T*> (m);
return static_cast<T*>( m );
}
protected:
TOOL_Type m_type;
TOOL_ID m_toolId;
std::string m_toolName;
TOOL_MANAGER *m_toolMgr;
TOOL_MANAGER* m_toolMgr;
private:
// hide the implementation to avoid spreading half of
// kicad and wxWidgets headers to the tools that may not need them at all!
EDA_ITEM *getModelInt();
wxWindow *getEditFrameInt();
EDA_ITEM* getModelInt();
wxWindow* getEditFrameInt();
};
#endif
......@@ -38,7 +38,8 @@ class TOOL_MANAGER;
* Internal (GUI-independent) event definitions.
* Enums are mostly self-explanatory.
*/
enum TOOL_EventCategory {
enum TOOL_EventCategory
{
TC_None = 0x0,
TC_Mouse = 0x1,
TC_Command = 0x2,
......@@ -47,7 +48,8 @@ enum TOOL_EventCategory {
TC_Any = 0xffffffff
};
enum TOOL_Actions {
enum TOOL_Actions
{
TA_None = 0x0,
TA_MouseClick = 0x1,
TA_MouseUp = 0x2,
......@@ -77,7 +79,8 @@ enum TOOL_Actions {
TA_Any = 0xffffffff
};
enum TOOL_MouseButtons {
enum TOOL_MouseButtons
{
MB_None = 0x0,
MB_Left = 0x1,
MB_Right = 0x2,
......@@ -92,7 +95,8 @@ enum TOOL_MouseButtons {
// Defines when a context menu is opened.
enum TOOL_ContextMenuTrigger {
enum TOOL_ContextMenuTrigger
{
CMENU_BUTTON = 0, // On the right button
CMENU_NOW, // Right now (after TOOL_INTERACTIVE::SetContxtMenu)
CMENU_OFF // Never
......@@ -105,41 +109,40 @@ enum TOOL_ContextMenuTrigger {
*/
class TOOL_EVENT
{
public:
const std::string Format ( ) const;
public:
const std::string Format() const;
TOOL_EVENT(TOOL_EventCategory aCategory = TC_None, TOOL_Actions aAction = TA_None ):
m_category (aCategory),
m_actions (aAction),
m_mouseButtons(0) {};
TOOL_EVENT( TOOL_EventCategory aCategory = TC_None, TOOL_Actions aAction = TA_None ):
m_category( aCategory ),
m_actions( aAction ),
m_mouseButtons( 0 ) {}
TOOL_EVENT(TOOL_EventCategory aCategory, TOOL_Actions aAction, int aExtraParam ):
m_category (aCategory),
m_actions (aAction)
TOOL_EVENT( TOOL_EventCategory aCategory, TOOL_Actions aAction, int aExtraParam ):
m_category( aCategory ),
m_actions( aAction )
{
if(aCategory == TC_Mouse)
if( aCategory == TC_Mouse )
m_mouseButtons = aExtraParam;
else if (aCategory == TC_Command)
else if ( aCategory == TC_Command )
m_commandId = aExtraParam;
};
}
TOOL_EVENT(TOOL_EventCategory aCategory, TOOL_Actions aAction, const std::string& aExtraParam ):
m_category (aCategory),
m_actions (aAction),
m_mouseButtons(0)
TOOL_EVENT( TOOL_EventCategory aCategory, TOOL_Actions aAction, const std::string& aExtraParam ):
m_category( aCategory ),
m_actions( aAction ),
m_mouseButtons( 0 )
{
if(aCategory == TC_Command)
if( aCategory == TC_Command )
m_commandStr = aExtraParam;
}
TOOL_EventCategory Category ( ) const
TOOL_EventCategory Category() const
{
return m_category;
}
TOOL_Actions Action ( ) const
TOOL_Actions Action() const
{
return m_actions;
}
......@@ -164,37 +167,37 @@ class TOOL_EVENT
return m_mouseButtons;
}
bool IsClick ( int aButtonMask = MB_Any ) const
bool IsClick( int aButtonMask = MB_Any ) const
{
return (m_actions == TA_MouseClick) && ((m_mouseButtons & aButtonMask) == aButtonMask);
return ( m_actions == TA_MouseClick )
&& ( ( m_mouseButtons & aButtonMask ) == aButtonMask );
}
bool IsDrag ( int aButtonMask = MB_Any ) const
bool IsDrag( int aButtonMask = MB_Any ) const
{
return (m_actions == TA_MouseDrag) && ((m_mouseButtons & aButtonMask) == aButtonMask);
return ( m_actions == TA_MouseDrag ) && ( ( m_mouseButtons & aButtonMask ) == aButtonMask );
}
bool IsMouseUp ( int aButtonMask = MB_Any ) const
bool IsMouseUp( int aButtonMask = MB_Any ) const
{
return (m_actions == TA_MouseUp) && ((m_mouseButtons & aButtonMask) == aButtonMask);
return ( m_actions == TA_MouseUp ) && ( ( m_mouseButtons & aButtonMask ) == aButtonMask );
}
bool IsMotion ( ) const
bool IsMotion() const
{
return (m_actions == TA_MouseMotion);
return ( m_actions == TA_MouseMotion );
}
bool IsCancel ( ) const
bool IsCancel() const
{
return m_actions == TA_CancelTool;
}
bool Modifier ( int aMask = MB_ModifierMask ) const
bool Modifier( int aMask = MB_ModifierMask ) const
{
return (m_mouseButtons & aMask);
return ( m_mouseButtons & aMask );
}
void Ignore();
void SetMouseDragOrigin( const VECTOR2D &aP )
......@@ -212,20 +215,20 @@ class TOOL_EVENT
m_mouseDelta = aP;
}
bool Matches ( const TOOL_EVENT& aEvent ) const
bool Matches( const TOOL_EVENT& aEvent ) const
{
if (! (m_category & aEvent.m_category))
if( ! ( m_category & aEvent.m_category ) )
return false;
if (! (m_actions & aEvent.m_actions))
if( ! ( m_actions & aEvent.m_actions ) )
return false;
if( m_category == TC_Command)
if( m_category == TC_Command )
{
if(m_commandStr && aEvent.m_commandStr)
return (*m_commandStr == *aEvent.m_commandStr);
if(m_commandId && aEvent.m_commandId)
return (*m_commandId == *aEvent.m_commandId);
if( m_commandStr && aEvent.m_commandStr )
return ( *m_commandStr == *aEvent.m_commandStr );
if( m_commandId && aEvent.m_commandId )
return ( *m_commandId == *aEvent.m_commandId );
}
return true;
......@@ -236,9 +239,7 @@ class TOOL_EVENT
return m_commandId;
}
private:
private:
friend class TOOL_MANAGER;
TOOL_EventCategory m_category;
......@@ -251,9 +252,6 @@ class TOOL_EVENT
int m_mouseButtons;
boost::optional<int> m_commandId;
boost::optional<std::string> m_commandStr;
};
typedef boost::optional<TOOL_EVENT> OPT_TOOL_EVENT;
......@@ -265,8 +263,7 @@ typedef boost::optional<TOOL_EVENT> OPT_TOOL_EVENT;
* concatenating TOOL_EVENTs with little code.
*/
class TOOL_EVENT_LIST {
public:
public:
typedef TOOL_EVENT value_type;
typedef std::deque<TOOL_EVENT>::iterator iterator;
typedef std::deque<TOOL_EVENT>::const_iterator const_iterator;
......@@ -277,19 +274,19 @@ class TOOL_EVENT_LIST {
m_events.push_back(aSingleEvent);
}
const std::string Format ( ) const;
const std::string Format() const;
boost::optional<const TOOL_EVENT&> Matches( const TOOL_EVENT &b ) const
{
for(const_iterator i = m_events.begin(); i != m_events.end(); ++i)
if (i->Matches(b))
for( const_iterator i = m_events.begin(); i != m_events.end(); ++i )
if ( i->Matches( b ) )
return *i;
return boost::optional<const TOOL_EVENT&> ();
return boost::optional<const TOOL_EVENT&>();
}
void Add ( const TOOL_EVENT& aEvent )
void Add( const TOOL_EVENT& aEvent )
{
m_events.push_back(aEvent);
m_events.push_back( aEvent );
}
iterator begin()
......@@ -322,52 +319,56 @@ class TOOL_EVENT_LIST {
m_events.clear();
}
TOOL_EVENT_LIST& operator=(const TOOL_EVENT_LIST& b)
TOOL_EVENT_LIST& operator=( const TOOL_EVENT_LIST& b )
{
m_events.clear();
for(std::deque<TOOL_EVENT>::const_iterator i = b.m_events.begin(); i != b.m_events.end(); ++i)
for( std::deque<TOOL_EVENT>::const_iterator i = b.m_events.begin();
i != b.m_events.end(); ++i )
{
m_events.push_back(*i);
}
return *this;
}
TOOL_EVENT_LIST& operator=(const TOOL_EVENT& b)
TOOL_EVENT_LIST& operator=( const TOOL_EVENT& b )
{
m_events.clear();
m_events.push_back(b);
m_events.push_back( b );
return *this;
}
TOOL_EVENT_LIST& operator||(const TOOL_EVENT& b)
TOOL_EVENT_LIST& operator||( const TOOL_EVENT& b )
{
Add(b);
Add( b );
return *this;
}
TOOL_EVENT_LIST& operator||(const TOOL_EVENT_LIST& b)
TOOL_EVENT_LIST& operator||( const TOOL_EVENT_LIST& b )
{
return *this;
}
private:
private:
std::deque<TOOL_EVENT> m_events;
};
inline const TOOL_EVENT_LIST operator || (const TOOL_EVENT& a, const TOOL_EVENT &b )
inline const TOOL_EVENT_LIST operator||( const TOOL_EVENT& a, const TOOL_EVENT &b )
{
TOOL_EVENT_LIST l;
l.Add(a);
l.Add(b);
l.Add( a );
l.Add( b );
return l;
}
inline const TOOL_EVENT_LIST operator || (const TOOL_EVENT & a, const TOOL_EVENT_LIST &b )
inline const TOOL_EVENT_LIST operator||( const TOOL_EVENT & a, const TOOL_EVENT_LIST &b )
{
TOOL_EVENT_LIST l(b);
TOOL_EVENT_LIST l( b );
l.Add(a);
l.Add( a );
return l;
}
......
......@@ -32,9 +32,9 @@
class CONTEXT_MENU;
class TOOL_INTERACTIVE : public TOOL_BASE {
class TOOL_INTERACTIVE : public TOOL_BASE
{
public:
TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName );
/**
......@@ -87,20 +87,18 @@ public:
void Yield ( const T& returnValue );
protected:
/* helper functions for constructing events for Wait() and Go() with
less typing */
const TOOL_EVENT evActivate( std::string aToolName = "" );
const TOOL_EVENT evCommand( int aCommandId = -1 );
const TOOL_EVENT evCommand( std::string aCommandStr = "");
const TOOL_EVENT evMotion();
const TOOL_EVENT evClick(int aButton = MB_Any );
const TOOL_EVENT evDrag(int aButton = MB_Any );
const TOOL_EVENT evClick( int aButton = MB_Any );
const TOOL_EVENT evDrag( int aButton = MB_Any );
const TOOL_EVENT evButtonUp( int aButton = MB_Any );
const TOOL_EVENT evButtonDown(int aButton = MB_Any );
private:
void goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions );
};
......@@ -108,7 +106,7 @@ private:
template<class T>
void TOOL_INTERACTIVE::Go( int (T::*aStateFunc)( TOOL_EVENT& ), const TOOL_EVENT_LIST& aConditions )
{
TOOL_STATE_FUNC sptr (static_cast<T*>(this), aStateFunc);
TOOL_STATE_FUNC sptr (static_cast<T*>( this ), aStateFunc);
goInternal( sptr, aConditions );
}
......
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