Some more reformatting and adding copyright notices.

This commit is contained in:
Maciej Suminski 2013-08-07 11:20:12 +02:00
parent 62ea71fcae
commit ee80c7f674
9 changed files with 444 additions and 342 deletions

View File

@ -1,3 +1,27 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Tomasz Wlostowski <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>
@ -41,12 +65,14 @@ CONTEXT_MENU::CONTEXT_MENU ( )
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 )
@ -60,11 +86,13 @@ void CONTEXT_MENU::SetTitle( const wxString& aTitle )
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;

View File

@ -1,3 +1,27 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Tomasz Wlostowski <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>
@ -6,16 +30,19 @@ 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();

View File

@ -1,3 +1,27 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Tomasz Wlostowski <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,11 +34,13 @@
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;
@ -24,6 +50,7 @@ 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;
@ -90,6 +117,7 @@ const std::string TOOL_EVENT::Format() const
return ev; return ev;
} }
const std::string TOOL_EVENT_LIST::Format() const const std::string TOOL_EVENT_LIST::Format() const
{ {
string s; string s;

View File

@ -1,3 +1,27 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Tomasz Wlostowski <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>
@ -9,6 +33,7 @@ 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_INTERACTIVE::TOOL_INTERACTIVE( const std::string& aName ) :
TOOL_BASE( TOOL_Interactive, TOOL_MANAGER::MakeToolId( aName ), aName ) TOOL_BASE( TOOL_Interactive, TOOL_MANAGER::MakeToolId( aName ), aName )
{}; {};
@ -16,24 +41,26 @@ TOOL_INTERACTIVE::TOOL_INTERACTIVE( const std::string& 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 );

View File

@ -58,7 +58,6 @@ public:
} }
private: private:
class CMEventHandler; class CMEventHandler;
friend class TOOL_INTERACTIVE; friend class TOOL_INTERACTIVE;

View File

@ -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,13 +34,14 @@
class EDA_ITEM; class EDA_ITEM;
class TOOL_MANAGER; class TOOL_MANAGER;
namespace KiGfx { namespace KiGfx
{
class VIEW; class VIEW;
class VIEW_CONTROLS; class VIEW_CONTROLS;
}; };
enum TOOL_Type
enum TOOL_Type { {
TOOL_Interactive = 0x1, TOOL_Interactive = 0x1,
TOOL_Batch = 0x2 TOOL_Batch = 0x2
}; };
@ -88,7 +87,6 @@ public:
} }
protected: protected:
friend class TOOL_MANAGER; friend class TOOL_MANAGER;
/** /**
@ -128,20 +126,16 @@ protected:
} }
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

View File

@ -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 {
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 {
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 {
// 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
@ -106,13 +110,12 @@ 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 ),
@ -122,7 +125,7 @@ class TOOL_EVENT
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 ),
@ -166,7 +169,8 @@ class TOOL_EVENT
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
@ -194,7 +198,6 @@ class TOOL_EVENT
return ( m_mouseButtons & aMask ); return ( m_mouseButtons & aMask );
} }
void Ignore(); void Ignore();
void SetMouseDragOrigin( const VECTOR2D &aP ) void SetMouseDragOrigin( const VECTOR2D &aP )
@ -236,9 +239,7 @@ class TOOL_EVENT
return m_commandId; return m_commandId;
} }
private: private:
friend class TOOL_MANAGER; friend class TOOL_MANAGER;
TOOL_EventCategory m_category; TOOL_EventCategory m_category;
@ -251,9 +252,6 @@ class TOOL_EVENT
int m_mouseButtons; int m_mouseButtons;
boost::optional<int> m_commandId; boost::optional<int> m_commandId;
boost::optional<std::string> m_commandStr; boost::optional<std::string> m_commandStr;
}; };
typedef boost::optional<TOOL_EVENT> OPT_TOOL_EVENT; typedef boost::optional<TOOL_EVENT> OPT_TOOL_EVENT;
@ -265,7 +263,6 @@ 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;
@ -325,8 +322,13 @@ class TOOL_EVENT_LIST {
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();
i != b.m_events.end(); ++i )
{
m_events.push_back(*i); m_events.push_back(*i);
}
return *this; return *this;
} }
@ -345,7 +347,6 @@ class TOOL_EVENT_LIST {
TOOL_EVENT_LIST& operator||( const TOOL_EVENT_LIST& b ) TOOL_EVENT_LIST& operator||( const TOOL_EVENT_LIST& b )
{ {
return *this; return *this;
} }

View File

@ -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,7 +87,6 @@ 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 = "" );
@ -100,7 +99,6 @@ protected:
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 );
}; };