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,54 +42,58 @@ 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;
}
\ 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_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();
}
\ 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 <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,15 +34,16 @@
class EDA_ITEM;
class TOOL_MANAGER;
namespace KiGfx {
class VIEW;
class VIEW_CONTROLS;
namespace KiGfx
{
class VIEW;
class VIEW_CONTROLS;
};
enum TOOL_Type {
TOOL_Interactive = 0x1,
TOOL_Batch = 0x2
enum TOOL_Type
{
TOOL_Interactive = 0x1,
TOOL_Batch = 0x2
};
typedef int TOOL_ID;
......@@ -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
This diff is collapsed.
......@@ -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 );
}
......
......@@ -281,7 +281,7 @@ public:
}
/**
* Function SetLayerOrder()
* Function SetLayerOrder()
* Sets rendering order of a particular layer.
* @param aLayer: the layer
* @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