From e1bfcb1816b0508ed9b725239cf83d3ad4c58f5e Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 3 Dec 2013 16:09:03 +0100 Subject: [PATCH] Renamed MOVE_TOOL to EDIT_TOOL. --- pcbnew/CMakeLists.txt | 2 +- pcbnew/tools/common_actions.cpp | 10 +- pcbnew/tools/common_actions.h | 2 +- pcbnew/tools/move_tool.cpp | 239 -------------------------------- pcbnew/tools/move_tool.h | 102 -------------- pcbnew/tools/pcb_tools.cpp | 6 +- pcbnew/tools/selection_tool.cpp | 4 +- pcbnew/tools/selection_tool.h | 2 +- 8 files changed, 13 insertions(+), 354 deletions(-) delete mode 100644 pcbnew/tools/move_tool.cpp delete mode 100644 pcbnew/tools/move_tool.h diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 360f98a5c3..770554f2c0 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -241,7 +241,7 @@ set( PCBNEW_CLASS_SRCS tools/selection_tool.cpp tools/selection_area.cpp tools/bright_box.cpp - tools/move_tool.cpp + tools/edit_tool.cpp tools/pcb_tools.cpp tools/common_actions.cpp ) diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index e1b95141c6..12aa52cb8f 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -30,19 +30,19 @@ 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", +// Edit tool actions +TOOL_ACTION COMMON_ACTIONS::editActivate( "pcbnew.InteractiveEdit", AS_GLOBAL, 'M', "Move", "Moves the selected item(s)" ); -TOOL_ACTION COMMON_ACTIONS::rotate( "pcbnew.InteractiveMove.rotate", +TOOL_ACTION COMMON_ACTIONS::rotate( "pcbnew.InteractiveEdit.rotate", AS_CONTEXT, 'R', "Rotate", "Rotates selected item(s)" ); -TOOL_ACTION COMMON_ACTIONS::flip( "pcbnew.InteractiveMove.flip", +TOOL_ACTION COMMON_ACTIONS::flip( "pcbnew.InteractiveEdit.flip", AS_CONTEXT, 'F', "Flip", "Flips selected item(s)" ); -TOOL_ACTION COMMON_ACTIONS::properties( "pcbnew.InteractiveMove.properties", +TOOL_ACTION COMMON_ACTIONS::properties( "pcbnew.InteractiveEdit.properties", AS_GLOBAL, 'E', "Properties...", "Displays properties window" ); diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index c93dd29220..5e8bbd7efc 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -36,7 +36,7 @@ class COMMON_ACTIONS { public: /// Activation of the move tool - static TOOL_ACTION moveActivate; + static TOOL_ACTION editActivate; /// Activation of the selection tool static TOOL_ACTION selectionActivate; diff --git a/pcbnew/tools/move_tool.cpp b/pcbnew/tools/move_tool.cpp deleted file mode 100644 index ccafa2c835..0000000000 --- a/pcbnew/tools/move_tool.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2013 CERN - * @author Maciej Suminski - * - * 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 -#include -#include -#include -#include -#include - -#include "common_actions.h" -#include "selection_tool.h" -#include "move_tool.h" - -using namespace KIGFX; -using boost::optional; - -MOVE_TOOL::MOVE_TOOL() : - TOOL_INTERACTIVE( "pcbnew.InteractiveMove" ), m_selectionTool( NULL ) -{ -} - - -bool MOVE_TOOL::Init() -{ - // Find the selection tool, so they can cooperate - TOOL_BASE* selectionTool = m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ); - - m_selectionTool = static_cast( selectionTool ); - if( !selectionTool ) - { - DisplayError( NULL, wxT( "pcbnew.InteractiveSelection tool is not available" ) ); - return false; - } - - // Add context menu entries that are displayed when selection tool is active - m_selectionTool->AddMenuItem( COMMON_ACTIONS::moveActivate ); - m_selectionTool->AddMenuItem( COMMON_ACTIONS::rotate ); - m_selectionTool->AddMenuItem( COMMON_ACTIONS::flip ); - m_selectionTool->AddMenuItem( COMMON_ACTIONS::properties ); - - setTransitions(); - - return true; -} - - -int MOVE_TOOL::Main( TOOL_EVENT& aEvent ) -{ - const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); - - if( selection.Empty() ) - return 0; // there are no items to operate on - - VECTOR2D dragPosition; - m_dragging = false; - bool restore = false; // Should items' state be restored when finishing the tool? - - VIEW_CONTROLS* controls = getViewControls(); - controls->ShowCursor( true ); - controls->SetSnapping( true ); - controls->SetAutoPan( true ); - - // Main loop: keep receiving events - while( OPT_TOOL_EVENT evt = Wait() ) - { - if( evt->IsCancel() ) - { - restore = true; // Cancelling the tool means that items have to be restored - break; // Finish - } - - // Dispatch TOOL_ACTIONs - else if( evt->Category() == TC_COMMAND ) - { - if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) - Rotate( aEvent ); - else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) - Flip( aEvent ); - } - - else if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) - { - if( m_dragging ) - { - // Drag items to the current cursor position - VECTOR2D movement = ( evt->Position() - dragPosition ); - m_state.Move( movement ); - } - else - { - // Prepare to drag - std::set::iterator it; - - for( it = selection.items.begin(); it != selection.items.end(); ++it ) - { - // Save the state of the selected items, in case it has to be restored - m_state.Save( *it ); - } - - m_dragging = true; - } - - selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); - dragPosition = evt->Position(); - } - - else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) - break; // Finish - } - - m_dragging = false; - - if( restore ) - { - // Modifications has to be rollbacked, so restore the previous state of items - selection.group->ItemsViewUpdate( VIEW_ITEM::APPEARANCE ); - m_state.RestoreAll(); - } - else - { - // Changes are applied, so update the items - selection.group->ItemsViewUpdate( m_state.GetUpdateFlag() ); - m_state.Apply(); - } - - controls->ShowCursor( false ); - controls->SetSnapping( false ); - controls->SetAutoPan( false ); - - setTransitions(); - - return 0; -} - - -int MOVE_TOOL::Properties( TOOL_EVENT& aEvent ) -{ - const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); - - // Properties are displayed when there is only one item selected - if( selection.items.size() == 1 ) - { - // Display properties dialog - PCB_EDIT_FRAME* editFrame = static_cast( m_toolMgr->GetEditFrame() ); - BOARD_ITEM* item = *selection.items.begin(); - editFrame->OnEditItemRequest( NULL, item ); - - item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - } - - setTransitions(); - - return 0; -} - - -int MOVE_TOOL::Rotate( TOOL_EVENT& aEvent ) -{ - const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); - VECTOR2D cursorPos = getView()->ToWorld( getViewControls()->GetCursorPosition() ); - - if( m_dragging ) - { - m_state.Rotate( cursorPos, 900.0 ); - selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); - } - else - { - std::set::iterator it; - - for( it = selection.items.begin(); it != selection.items.end(); ++it ) - { - (*it)->Rotate( wxPoint( cursorPos.x, cursorPos.y ), 900.0 ); - (*it)->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - } - - setTransitions(); - } - - return 0; -} - - -int MOVE_TOOL::Flip( TOOL_EVENT& aEvent ) -{ - const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); - VECTOR2D cursorPos = getView()->ToWorld( getViewControls()->GetCursorPosition() ); - - if( m_dragging ) - { - m_state.Flip( cursorPos ); - selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); - } - else - { - std::set::iterator it; - - for( it = selection.items.begin(); it != selection.items.end(); ++it ) - { - (*it)->Flip( wxPoint( cursorPos.x, cursorPos.y ) ); - (*it)->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); - } - - setTransitions(); - } - - return 0; -} - - -void MOVE_TOOL::setTransitions() -{ - Go( &MOVE_TOOL::Main, COMMON_ACTIONS::moveActivate.MakeEvent() ); - Go( &MOVE_TOOL::Rotate, COMMON_ACTIONS::rotate.MakeEvent() ); - Go( &MOVE_TOOL::Flip, COMMON_ACTIONS::flip.MakeEvent() ); - Go( &MOVE_TOOL::Properties, COMMON_ACTIONS::properties.MakeEvent() ); -} diff --git a/pcbnew/tools/move_tool.h b/pcbnew/tools/move_tool.h deleted file mode 100644 index 9b7a88012d..0000000000 --- a/pcbnew/tools/move_tool.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2013 CERN - * @author Maciej Suminski - * - * 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 - */ - -#ifndef __MOVE_TOOL_H -#define __MOVE_TOOL_H - -#include -#include -#include -#include "item_state.h" - -class BOARD_ITEM; -class SELECTION_TOOL; - -namespace KIGFX -{ -class VIEW_GROUP; -} - -/** - * Class MOVE_TOOL - * - * Our sample move tool. Allows to move, rotate and flip items selected by - * pcbnew.InteractiveSelection tool. - */ - -class MOVE_TOOL : public TOOL_INTERACTIVE -{ -public: - MOVE_TOOL(); - - /// @copydoc TOOL_INTERACTIVE::Reset() - void Reset() {}; - - /// @copydoc TOOL_INTERACTIVE::Init() - bool Init(); - - /** - * Function Main() - * - * Main loop in which events are handled. - * @param aEvent is the handled event. - */ - int Main( TOOL_EVENT& aEvent ); - - /** - * Function Edit() - * - * Displays properties window for the selected object. - */ - int Properties( TOOL_EVENT& aEvent ); - - /** - * Function Rotate() - * - * Rotates currently selected items. - */ - int Rotate( TOOL_EVENT& aEvent ); - - /** - * Function Flip() - * - * Rotates currently selected items. The rotation point is the current cursor position. - */ - int Flip( TOOL_EVENT& aEvent ); - -private: - ///> Saves the state of items and allows to restore them - ITEM_STATE m_state; - - ///> Selection tool used for obtaining selected items - SELECTION_TOOL* m_selectionTool; - - ///> Flag determining if anything is being dragged right now - bool m_dragging; - - ///> Sets up handlers for various events - void setTransitions(); -}; - -#endif diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index aaccb18978..f6903f6420 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -35,7 +35,7 @@ #include #include "selection_tool.h" -#include "move_tool.h" +#include "edit_tool.h" #include "common_actions.h" #include @@ -47,7 +47,7 @@ void PCB_EDIT_FRAME::setupTools() m_galCanvas->SetEventDispatcher( m_toolDispatcher ); // Register tool actions - m_toolManager->RegisterAction( &COMMON_ACTIONS::moveActivate ); + m_toolManager->RegisterAction( &COMMON_ACTIONS::editActivate ); m_toolManager->RegisterAction( &COMMON_ACTIONS::selectionActivate ); m_toolManager->RegisterAction( &COMMON_ACTIONS::rotate ); m_toolManager->RegisterAction( &COMMON_ACTIONS::flip ); @@ -56,7 +56,7 @@ void PCB_EDIT_FRAME::setupTools() // Register tools m_toolManager->RegisterTool( new SELECTION_TOOL ); m_toolManager->RegisterTool( new ROUTER_TOOL ); - m_toolManager->RegisterTool( new MOVE_TOOL ); + m_toolManager->RegisterTool( new EDIT_TOOL ); } diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index e7d56cd291..23033b02f4 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -116,7 +116,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) selectSingle( evt->Position() ); // Display properties window - m_toolMgr->RunAction( "pcbnew.InteractiveMove.properties" ); + m_toolMgr->RunAction( "pcbnew.InteractiveEdit.properties" ); } // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them @@ -134,7 +134,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) if( containsSelected( evt->Position() ) ) { // Yes -> run the move tool and wait till it finishes - m_toolMgr->InvokeTool( "pcbnew.InteractiveMove" ); + m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" ); } else { diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index faf48ef8db..6b3d62ba28 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -50,7 +50,7 @@ class VIEW_GROUP; * - draw selection box (drag LMB) * - handles MODULEs properly (ie. selects either MODULE or its PADs, TEXTs, etc.) * - takes into account high-contrast & layer visibility settings - * - invokes InteractiveMove tool when user starts to drag selected items + * - invokes InteractiveEdit tool when user starts to drag selected items */ class SELECTION_TOOL : public TOOL_INTERACTIVE