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