Commit 35721397 authored by Maciej Suminski's avatar Maciej Suminski

Moved common actions to a separate file.

parent 6b74b577
......@@ -66,7 +66,7 @@ void ACTION_MANAGER::UnregisterAction( TOOL_ACTION* aAction )
int ACTION_MANAGER::MakeActionId( const std::string& aActionName )
{
static int currentActionId = 0;
static int currentActionId = 1;
return currentActionId++;
}
......
......@@ -228,6 +228,7 @@ set( PCBNEW_CLASS_SRCS
tools/bright_box.cpp
tools/move_tool.cpp
tools/pcb_tools.cpp
tools/common_actions.cpp
)
set( PCBNEW_SRCS ${PCBNEW_AUTOROUTER_SRCS} ${PCBNEW_CLASS_SRCS} ${PCBNEW_DIALOGS} )
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Maciej Suminski <maciej.suminski@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 "common_actions.h"
#include <tool/action_manager.h>
// Selection tool actions
TOOL_ACTION COMMON_ACTIONS::selectionActivate( "pcbnew.InteractiveSelection",
AS_GLOBAL, 'S',
"Selection tool", "Allows to select items" );
// Move tool actions
TOOL_ACTION COMMON_ACTIONS::moveActivate( "pcbnew.InteractiveMove",
AS_GLOBAL, 'M',
"Move", "Moves the selected item(s)" );
TOOL_ACTION COMMON_ACTIONS::rotate( "pcbnew.InteractiveMove.rotate",
AS_CONTEXT, ' ',
"Rotate", "Rotates selected item(s)" );
TOOL_ACTION COMMON_ACTIONS::flip( "pcbnew.InteractiveMove.flip",
AS_CONTEXT, 'F',
"Flip", "Flips selected item(s)" );
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Maciej Suminski <maciej.suminski@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_action.h>
class ACTION_MANAGER;
/**
* Class COMMON_ACTIONS
*
* Gathers all the actions that are shared by tools. The instance of COMMON_ACTIOSN is created
* inside of ACTION_MANAGER object and registers them.
*/
class COMMON_ACTIONS
{
public:
/// Activation of the move tool
static TOOL_ACTION moveActivate;
/// Activation of the selection tool
static TOOL_ACTION selectionActivate;
/// Rotation of selected objects
static TOOL_ACTION rotate;
/// Flipping of selected objects
static TOOL_ACTION flip;
};
......@@ -25,9 +25,9 @@
#include <class_board.h>
#include <class_module.h>
#include <tool/tool_manager.h>
#include <tool/tool_action.h>
#include <view/view_controls.h>
#include "common_actions.h"
#include "selection_tool.h"
#include "move_tool.h"
......@@ -35,12 +35,7 @@ using namespace KiGfx;
using boost::optional;
MOVE_TOOL::MOVE_TOOL() :
TOOL_INTERACTIVE( "pcbnew.InteractiveMove" ), m_selectionTool( NULL ),
// Available actions:
m_activate( m_toolName, AS_GLOBAL, 'M', "Move", "Moves the selected item(s)" ),
m_rotate( m_toolName + ".rotate", AS_CONTEXT, ' ', "Rotate", "Rotates selected item(s)" ),
m_flip( m_toolName + ".flip", AS_CONTEXT, 'F', "Flip", "Flips selected item(s)" )
TOOL_INTERACTIVE( "pcbnew.InteractiveMove" ), m_selectionTool( NULL )
{
}
......@@ -53,7 +48,7 @@ MOVE_TOOL::~MOVE_TOOL()
void MOVE_TOOL::Reset()
{
// The tool launches upon reception of action event ("pcbnew.InteractiveMove")
Go( &MOVE_TOOL::Main, m_activate.MakeEvent() );
Go( &MOVE_TOOL::Main, COMMON_ACTIONS::moveActivate.MakeEvent() );
}
......@@ -66,15 +61,10 @@ bool MOVE_TOOL::Init()
{
m_selectionTool = static_cast<SELECTION_TOOL*>( selectionTool );
// Activate hot keys
m_toolMgr->RegisterAction( &m_activate );
m_toolMgr->RegisterAction( &m_rotate );
m_toolMgr->RegisterAction( &m_flip );
// Add context menu entries that are displayed when selection tool is active
m_selectionTool->AddMenuItem( m_activate );
m_selectionTool->AddMenuItem( m_rotate );
m_selectionTool->AddMenuItem( m_flip );
m_selectionTool->AddMenuItem( COMMON_ACTIONS::moveActivate );
m_selectionTool->AddMenuItem( COMMON_ACTIONS::rotate );
m_selectionTool->AddMenuItem( COMMON_ACTIONS::flip );
}
else
{
......@@ -115,12 +105,12 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent )
{
VECTOR2D cursorPos = getView()->ToWorld( getViewControls()->GetCursorPosition() );
if( evt->IsAction( &m_rotate ) ) // got rotation event?
if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) // got rotation event?
{
m_state.Rotate( cursorPos, 900.0 );
m_items.ViewUpdate( VIEW_ITEM::GEOMETRY );
}
else if( evt->IsAction( &m_flip ) ) // got flip event?
else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) // got flip event?
{
m_state.Flip( cursorPos );
m_items.ViewUpdate( VIEW_ITEM::GEOMETRY );
......
......@@ -85,15 +85,6 @@ private:
/// VIEW_GROUP that helds currently moved items
KiGfx::VIEW_GROUP m_items;
/// Register hotkey for activation of the move tool
TOOL_ACTION m_activate;
/// Register hotkey for rotation of selected objects
TOOL_ACTION m_rotate;
/// Register hotkey for flipping of selected objects
TOOL_ACTION m_flip;
};
#endif
......@@ -36,6 +36,7 @@
#include "selection_tool.h"
#include "move_tool.h"
#include "common_actions.h"
#include <router/router_tool.h>
void PCB_EDIT_FRAME::setupTools()
......@@ -45,6 +46,12 @@ void PCB_EDIT_FRAME::setupTools()
m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, this );
m_galCanvas->SetEventDispatcher( m_toolDispatcher );
// Register tool actions
m_toolManager->RegisterAction( &COMMON_ACTIONS::moveActivate );
m_toolManager->RegisterAction( &COMMON_ACTIONS::selectionActivate );
m_toolManager->RegisterAction( &COMMON_ACTIONS::rotate );
m_toolManager->RegisterAction( &COMMON_ACTIONS::flip );
// Register tools
m_toolManager->RegisterTool( new SELECTION_TOOL );
m_toolManager->RegisterTool( new ROUTER_TOOL );
......@@ -54,6 +61,11 @@ void PCB_EDIT_FRAME::setupTools()
void PCB_EDIT_FRAME::destroyTools()
{
m_toolManager->UnregisterAction( &COMMON_ACTIONS::moveActivate );
m_toolManager->UnregisterAction( &COMMON_ACTIONS::selectionActivate );
m_toolManager->UnregisterAction( &COMMON_ACTIONS::rotate );
m_toolManager->UnregisterAction( &COMMON_ACTIONS::flip );
delete m_toolDispatcher;
delete m_toolManager;
}
......
......@@ -44,13 +44,13 @@
#include "selection_tool.h"
#include "selection_area.h"
#include "bright_box.h"
#include "common_actions.h"
using namespace KiGfx;
using boost::optional;
SELECTION_TOOL::SELECTION_TOOL() :
TOOL_INTERACTIVE( "pcbnew.InteractiveSelection" ), m_multiple( false ),
m_activate( m_toolName, AS_GLOBAL, 'S', "Selection tool", "Allows to select items" )
TOOL_INTERACTIVE( "pcbnew.InteractiveSelection" ), m_multiple( false )
{
m_selArea = new SELECTION_AREA;
}
......@@ -68,15 +68,7 @@ void SELECTION_TOOL::Reset()
m_selectedItems.clear();
// The tool launches upon reception of action event ("pcbnew.InteractiveSelection")
Go( &SELECTION_TOOL::Main, m_activate.MakeEvent() );
}
bool SELECTION_TOOL::Init()
{
m_toolMgr->RegisterAction( &m_activate );
return true;
Go( &SELECTION_TOOL::Main, COMMON_ACTIONS::selectionActivate.MakeEvent() );
}
......
......@@ -30,7 +30,6 @@
#include <math/vector2d.h>
#include <tool/tool_interactive.h>
#include <tool/tool_action.h>
#include <tool/context_menu.h>
class SELECTION_AREA;
......@@ -58,9 +57,6 @@ public:
/// @copydoc TOOL_INTERACTIVE::Reset()
void Reset();
/// @copydoc TOOL_INTERACTIVE::Init()
bool Init();
/**
* Function Main()
*
......@@ -194,9 +190,6 @@ private:
/// Flag saying if multiple selection mode is active
bool m_multiple;
/// Register hotkey fot activation of the selection tool
TOOL_ACTION m_activate;
/// Right click popup menu
CONTEXT_MENU m_menu;
};
......
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