Loading pcbnew/tools/common_actions.cpp +5 −1 Original line number Diff line number Diff line Loading @@ -36,9 +36,13 @@ TOOL_ACTION COMMON_ACTIONS::moveActivate( "pcbnew.InteractiveMove", "Move", "Moves the selected item(s)" ); TOOL_ACTION COMMON_ACTIONS::rotate( "pcbnew.InteractiveMove.rotate", AS_CONTEXT, ' ', AS_CONTEXT, 'R', "Rotate", "Rotates selected item(s)" ); TOOL_ACTION COMMON_ACTIONS::flip( "pcbnew.InteractiveMove.flip", AS_CONTEXT, 'F', "Flip", "Flips selected item(s)" ); TOOL_ACTION COMMON_ACTIONS::properties( "pcbnew.InteractiveMove.properties", AS_GLOBAL, 'E', "Properties...", "Displays properties window" ); pcbnew/tools/common_actions.h +4 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ #include <tool/tool_action.h> class ACTION_MANAGER; //class ACTION_MANAGER; /** * Class COMMON_ACTIONS Loading @@ -46,4 +46,7 @@ public: /// Flipping of selected objects static TOOL_ACTION flip; /// Activation of the edit tool static TOOL_ACTION properties; }; pcbnew/tools/move_tool.cpp +107 −37 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include <class_board.h> #include <class_module.h> #include <wxPcbStruct.h> #include <tool/tool_manager.h> #include <view/view_controls.h> #include <confirm.h> Loading @@ -41,37 +42,25 @@ MOVE_TOOL::MOVE_TOOL() : } MOVE_TOOL::~MOVE_TOOL() { } void MOVE_TOOL::Reset() { // The tool launches upon reception of action event ("pcbnew.InteractiveMove") Go( &MOVE_TOOL::Main, COMMON_ACTIONS::moveActivate.MakeEvent() ); } bool MOVE_TOOL::Init() { // Find the selection tool, so they can cooperate TOOL_BASE* selectionTool = m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ); if( selectionTool ) { m_selectionTool = static_cast<SELECTION_TOOL*>( 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 ); } else { DisplayError( NULL, wxT( "pcbnew.InteractiveSelection tool is not available" ) ); return false; } m_selectionTool->AddMenuItem( COMMON_ACTIONS::properties ); setTransitions(); return true; } Loading @@ -85,7 +74,7 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent ) return 0; // there are no items to operate on VECTOR2D dragPosition; bool dragging = false; m_dragging = false; bool restore = false; // Should items' state be restored when finishing the tool? VIEW_CONTROLS* controls = getViewControls(); Loading @@ -105,23 +94,15 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent ) // Dispatch TOOL_ACTIONs else if( evt->Category() == TC_COMMAND ) { VECTOR2D cursorPos = getView()->ToWorld( getViewControls()->GetCursorPosition() ); if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) // got rotation event? { m_state.Rotate( cursorPos, 900.0 ); selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) // got flip event? { m_state.Flip( cursorPos ); selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); } 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( dragging ) if( m_dragging ) { // Drag items to the current cursor position VECTOR2D movement = ( evt->Position() - dragPosition ); Loading @@ -138,16 +119,19 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent ) m_state.Save( *it ); } dragging = true; 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 Loading @@ -165,5 +149,91 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent ) 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<PCB_EDIT_FRAME*>( 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<BOARD_ITEM*>::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<BOARD_ITEM*>::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() ); } pcbnew/tools/move_tool.h +31 −4 Original line number Diff line number Diff line Loading @@ -49,10 +49,9 @@ class MOVE_TOOL : public TOOL_INTERACTIVE { public: MOVE_TOOL(); ~MOVE_TOOL(); /// @copydoc TOOL_INTERACTIVE::Reset() void Reset(); void Reset() {}; /// @copydoc TOOL_INTERACTIVE::Init() bool Init(); Loading @@ -61,15 +60,43 @@ public: * 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 ///> Saves the state of items and allows to restore them ITEM_STATE m_state; /// Selection tool used for obtaining selected items ///> 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 pcbnew/tools/pcb_tools.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ void PCB_EDIT_FRAME::setupTools() m_toolManager->RegisterAction( &COMMON_ACTIONS::selectionActivate ); m_toolManager->RegisterAction( &COMMON_ACTIONS::rotate ); m_toolManager->RegisterAction( &COMMON_ACTIONS::flip ); m_toolManager->RegisterAction( &COMMON_ACTIONS::properties ); // Register tools m_toolManager->RegisterTool( new SELECTION_TOOL ); Loading Loading
pcbnew/tools/common_actions.cpp +5 −1 Original line number Diff line number Diff line Loading @@ -36,9 +36,13 @@ TOOL_ACTION COMMON_ACTIONS::moveActivate( "pcbnew.InteractiveMove", "Move", "Moves the selected item(s)" ); TOOL_ACTION COMMON_ACTIONS::rotate( "pcbnew.InteractiveMove.rotate", AS_CONTEXT, ' ', AS_CONTEXT, 'R', "Rotate", "Rotates selected item(s)" ); TOOL_ACTION COMMON_ACTIONS::flip( "pcbnew.InteractiveMove.flip", AS_CONTEXT, 'F', "Flip", "Flips selected item(s)" ); TOOL_ACTION COMMON_ACTIONS::properties( "pcbnew.InteractiveMove.properties", AS_GLOBAL, 'E', "Properties...", "Displays properties window" );
pcbnew/tools/common_actions.h +4 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ #include <tool/tool_action.h> class ACTION_MANAGER; //class ACTION_MANAGER; /** * Class COMMON_ACTIONS Loading @@ -46,4 +46,7 @@ public: /// Flipping of selected objects static TOOL_ACTION flip; /// Activation of the edit tool static TOOL_ACTION properties; };
pcbnew/tools/move_tool.cpp +107 −37 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include <class_board.h> #include <class_module.h> #include <wxPcbStruct.h> #include <tool/tool_manager.h> #include <view/view_controls.h> #include <confirm.h> Loading @@ -41,37 +42,25 @@ MOVE_TOOL::MOVE_TOOL() : } MOVE_TOOL::~MOVE_TOOL() { } void MOVE_TOOL::Reset() { // The tool launches upon reception of action event ("pcbnew.InteractiveMove") Go( &MOVE_TOOL::Main, COMMON_ACTIONS::moveActivate.MakeEvent() ); } bool MOVE_TOOL::Init() { // Find the selection tool, so they can cooperate TOOL_BASE* selectionTool = m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ); if( selectionTool ) { m_selectionTool = static_cast<SELECTION_TOOL*>( 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 ); } else { DisplayError( NULL, wxT( "pcbnew.InteractiveSelection tool is not available" ) ); return false; } m_selectionTool->AddMenuItem( COMMON_ACTIONS::properties ); setTransitions(); return true; } Loading @@ -85,7 +74,7 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent ) return 0; // there are no items to operate on VECTOR2D dragPosition; bool dragging = false; m_dragging = false; bool restore = false; // Should items' state be restored when finishing the tool? VIEW_CONTROLS* controls = getViewControls(); Loading @@ -105,23 +94,15 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent ) // Dispatch TOOL_ACTIONs else if( evt->Category() == TC_COMMAND ) { VECTOR2D cursorPos = getView()->ToWorld( getViewControls()->GetCursorPosition() ); if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) // got rotation event? { m_state.Rotate( cursorPos, 900.0 ); selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) // got flip event? { m_state.Flip( cursorPos ); selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); } 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( dragging ) if( m_dragging ) { // Drag items to the current cursor position VECTOR2D movement = ( evt->Position() - dragPosition ); Loading @@ -138,16 +119,19 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent ) m_state.Save( *it ); } dragging = true; 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 Loading @@ -165,5 +149,91 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent ) 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<PCB_EDIT_FRAME*>( 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<BOARD_ITEM*>::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<BOARD_ITEM*>::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() ); }
pcbnew/tools/move_tool.h +31 −4 Original line number Diff line number Diff line Loading @@ -49,10 +49,9 @@ class MOVE_TOOL : public TOOL_INTERACTIVE { public: MOVE_TOOL(); ~MOVE_TOOL(); /// @copydoc TOOL_INTERACTIVE::Reset() void Reset(); void Reset() {}; /// @copydoc TOOL_INTERACTIVE::Init() bool Init(); Loading @@ -61,15 +60,43 @@ public: * 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 ///> Saves the state of items and allows to restore them ITEM_STATE m_state; /// Selection tool used for obtaining selected items ///> 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
pcbnew/tools/pcb_tools.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ void PCB_EDIT_FRAME::setupTools() m_toolManager->RegisterAction( &COMMON_ACTIONS::selectionActivate ); m_toolManager->RegisterAction( &COMMON_ACTIONS::rotate ); m_toolManager->RegisterAction( &COMMON_ACTIONS::flip ); m_toolManager->RegisterAction( &COMMON_ACTIONS::properties ); // Register tools m_toolManager->RegisterTool( new SELECTION_TOOL ); Loading