From f63170ca8458d54ae43cea525cc56c30ef94b41b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 18 Jun 2015 17:51:51 +0200 Subject: [PATCH] Tools available under toolbar buttons: delete items, highlight net, set drill/place origin (GAL). --- pcbnew/tools/common_actions.cpp | 29 +++++++--- pcbnew/tools/common_actions.h | 3 ++ pcbnew/tools/pcb_editor_control.cpp | 36 +++++++++++++ pcbnew/tools/pcb_editor_control.h | 6 +++ pcbnew/tools/pcbnew_control.cpp | 83 ++++++++++++++++++++--------- pcbnew/tools/pcbnew_control.h | 1 + 6 files changed, 127 insertions(+), 31 deletions(-) diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 4ecc7058fd..19046980dd 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -383,10 +383,18 @@ TOOL_ACTION COMMON_ACTIONS::placeModule( "pcbnew.EditorControl.placeModule", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_MODULE ), _( "Add modules" ), _( "Add modules" ), NULL, AF_ACTIVATE ); +TOOL_ACTION COMMON_ACTIONS::drillOrigin( "pcbnew.EditorControl.drillOrigin", + AS_GLOBAL, 0, + "", "" ); + TOOL_ACTION COMMON_ACTIONS::highlightNet( "pcbnew.EditorControl.highlightNet", AS_GLOBAL, 0, "", "" ); +TOOL_ACTION COMMON_ACTIONS::highlightNetCursor( "pcbnew.EditorControl.highlightNetCursor", + AS_GLOBAL, 0, + "", "" ); + // Module editor tools TOOL_ACTION COMMON_ACTIONS::placePad( "pcbnew.ModuleEditor.placePad", @@ -433,6 +441,10 @@ TOOL_ACTION COMMON_ACTIONS::switchUnits( "pcbnew.Control.switchUnits", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_SWITCH_UNITS ), "", "" ); +TOOL_ACTION COMMON_ACTIONS::deleteItemCursor( "pcbnew.Control.deleteItemCursor", + AS_GLOBAL, 0, + "", "" ); + TOOL_ACTION COMMON_ACTIONS::showHelp( "pcbnew.Control.showHelp", AS_GLOBAL, '?', "", "" ); @@ -637,14 +649,17 @@ boost::optional COMMON_ACTIONS::TranslateLegacyId( int aId ) return COMMON_ACTIONS::selectionTool.MakeEvent(); case ID_PCB_DELETE_ITEM_BUTT: - case ID_PCB_HIGHLIGHT_BUTT: - case ID_PCB_SHOW_1_RATSNEST_BUTT: - case ID_PCB_PLACE_OFFSET_COORD_BUTT: - case ID_TB_OPTIONS_SHOW_MODULE_RATSNEST: - case ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE: - case ID_MENU_PCB_SHOW_HIDE_MUWAVE_TOOLBAR: - case ID_MICROWAVE_V_TOOLBAR: case ID_MODEDIT_DELETE_TOOL: + return COMMON_ACTIONS::deleteItemCursor.MakeEvent(); + + case ID_PCB_PLACE_OFFSET_COORD_BUTT: + return COMMON_ACTIONS::drillOrigin.MakeEvent(); + + case ID_PCB_HIGHLIGHT_BUTT: + return COMMON_ACTIONS::highlightNetCursor.MakeEvent(); + + case ID_PCB_SHOW_1_RATSNEST_BUTT: + case ID_TB_OPTIONS_SHOW_MODULE_RATSNEST: return COMMON_ACTIONS::toBeDone.MakeEvent(); } diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index 8d58636832..0fbd338e27 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -271,7 +271,10 @@ public: static TOOL_ACTION resetCoords; static TOOL_ACTION switchCursor; static TOOL_ACTION switchUnits; + static TOOL_ACTION deleteItemCursor; static TOOL_ACTION highlightNet; + static TOOL_ACTION highlightNetCursor; + static TOOL_ACTION drillOrigin; static TOOL_ACTION showHelp; static TOOL_ACTION toBeDone; diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 970dc357f0..f537ac4558 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -29,6 +29,7 @@ #include #include "selection_tool.h" +#include "picker_tool.h" #include #include @@ -468,6 +469,26 @@ int PCB_EDITOR_CONTROL::SelectionCrossProbe( const TOOL_EVENT& aEvent ) } +static bool setDrillOrigin( PCB_BASE_FRAME* aFrame, const VECTOR2D& aPosition ) +{ + aFrame->SetAuxOrigin( wxPoint( aPosition.x, aPosition.y ) ); + + return true; +} + + +int PCB_EDITOR_CONTROL::DrillOrigin( const TOOL_EVENT& aEvent ) +{ + PICKER_TOOL* picker = m_toolMgr->GetTool(); + assert( picker ); + + m_frame->SetToolID( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust zero" ) ); + picker->SetClickHandler( boost::bind( setDrillOrigin, m_frame, _1 ) ); + picker->Activate(); + + return 0; +} + /** * Function highlightNet() * Looks for a BOARD_CONNECTED_ITEM in a given spot, and if one is found - it enables @@ -509,6 +530,19 @@ int PCB_EDITOR_CONTROL::HighlightNet( const TOOL_EVENT& aEvent ) } +int PCB_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent ) +{ + PICKER_TOOL* picker = m_toolMgr->GetTool(); + assert( picker ); + + m_frame->SetToolID( ID_PCB_HIGHLIGHT_BUTT, wxCURSOR_PENCIL, _( "Highlight net" ) ); + picker->SetClickHandler( boost::bind( highlightNet, m_toolMgr, _1 ) ); + picker->Activate(); + + return 0; +} + + void PCB_EDITOR_CONTROL::SetTransitions() { // Track & via size control @@ -529,7 +563,9 @@ void PCB_EDITOR_CONTROL::SetTransitions() // Other Go( &PCB_EDITOR_CONTROL::SelectionCrossProbe, SELECTION_TOOL::SelectedEvent ); + Go( &PCB_EDITOR_CONTROL::DrillOrigin, COMMON_ACTIONS::drillOrigin.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::HighlightNet, COMMON_ACTIONS::highlightNet.MakeEvent() ); + Go( &PCB_EDITOR_CONTROL::HighlightNetCursor, COMMON_ACTIONS::highlightNetCursor.MakeEvent() ); } diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index e13aefc526..b6fbe17f81 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -72,9 +72,15 @@ public: ///> Notifies eeschema about the selected item. int SelectionCrossProbe( const TOOL_EVENT& aEvent ); + ///> Places the origin point for drill and pick-and-place files. + int DrillOrigin( const TOOL_EVENT& aEvent ); + ///> Highlights net belonging to the item under the cursor. int HighlightNet( const TOOL_EVENT& aEvent ); + ///> Launches a tool to pick the item whose net is going to be highlighted. + int HighlightNetCursor( const TOOL_EVENT& aEvent ); + ///> Sets up handlers for various events. void SetTransitions(); diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index fc73206f6c..4fff0cb9d8 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -24,6 +24,8 @@ #include "pcbnew_control.h" #include "common_actions.h" +#include "selection_tool.h" +#include "picker_tool.h" #include #include @@ -34,11 +36,14 @@ #include #include #include +#include #include #include #include +#include + PCBNEW_CONTROL::PCBNEW_CONTROL() : TOOL_INTERACTIVE( "pcbnew.Control" ), m_frame( NULL ) @@ -437,32 +442,25 @@ int PCBNEW_CONTROL::GridPrev( const TOOL_EVENT& aEvent ) } +static bool setOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, const VECTOR2D& aPoint ) +{ + aFrame->SetGridOrigin( wxPoint( aPoint.x, aPoint.y ) ); + aView->GetGAL()->SetGridOrigin( aPoint ); + aView->MarkDirty(); + + return true; +} + + int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) { - Activate(); + PICKER_TOOL* picker = m_toolMgr->GetTool(); + assert( picker ); + + // TODO it will not check the toolbar button in module editor, as it uses a different ID.. m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust grid origin" ) ); - - KIGFX::VIEW_CONTROLS* controls = getViewControls(); - controls->ShowCursor( true ); - controls->SetSnapping( true ); - controls->SetAutoPan( true ); - - while( OPT_TOOL_EVENT evt = Wait() ) - { - if( evt->IsClick( BUT_LEFT ) ) - { - getView()->GetGAL()->SetGridOrigin( controls->GetCursorPosition() ); - getView()->MarkDirty(); - } - - else if( evt->IsCancel() || evt->IsActivate() ) - break; - } - - controls->SetAutoPan( false ); - controls->SetSnapping( false ); - controls->ShowCursor( false ); - m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); + picker->SetClickHandler( boost::bind( setOrigin, getView(), m_frame, _1 ) ); + picker->Activate(); return 0; } @@ -523,6 +521,42 @@ int PCBNEW_CONTROL::SwitchUnits( const TOOL_EVENT& aEvent ) } +static bool deleteItem( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition ) +{ + SELECTION_TOOL* selectionTool = aToolMgr->GetTool(); + assert( selectionTool ); + + aToolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); + aToolMgr->RunAction( COMMON_ACTIONS::selectionCursor, true ); + selectionTool->SanitizeSelection(); + + if( selectionTool->GetSelection().Empty() ) + return true; + + if( IsOK( aToolMgr->GetEditFrame(), _( "Are you sure you want to delete item?" ) ) ) + aToolMgr->RunAction( COMMON_ACTIONS::remove, true ); + + aToolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); + + return true; +} + + +int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent ) +{ + PICKER_TOOL* picker = m_toolMgr->GetTool(); + assert( picker ); + + // TODO it will not check the toolbar button in the module editor, as it uses a different ID.. + m_frame->SetToolID( ID_PCB_DELETE_ITEM_BUTT, wxCURSOR_PENCIL, _( "Delete item" ) ); + picker->SetSnapping( false ); + picker->SetClickHandler( boost::bind( deleteItem, m_toolMgr, _1 ) ); + picker->Activate(); + + return 0; +} + + int PCBNEW_CONTROL::ShowHelp( const TOOL_EVENT& aEvent ) { // TODO @@ -534,7 +568,7 @@ int PCBNEW_CONTROL::ShowHelp( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::ToBeDone( const TOOL_EVENT& aEvent ) { - DisplayInfoMessage( m_frame, _( "Not implemented yet." ) ); + DisplayInfoMessage( m_frame, _( "Not available in OpenGL/Cairo canvases." ) ); return 0; } @@ -589,6 +623,7 @@ void PCBNEW_CONTROL::SetTransitions() Go( &PCBNEW_CONTROL::ResetCoords, COMMON_ACTIONS::resetCoords.MakeEvent() ); Go( &PCBNEW_CONTROL::SwitchCursor, COMMON_ACTIONS::switchCursor.MakeEvent() ); Go( &PCBNEW_CONTROL::SwitchUnits, COMMON_ACTIONS::switchUnits.MakeEvent() ); + Go( &PCBNEW_CONTROL::DeleteItemCursor, COMMON_ACTIONS::deleteItemCursor.MakeEvent() ); Go( &PCBNEW_CONTROL::ShowHelp, COMMON_ACTIONS::showHelp.MakeEvent() ); Go( &PCBNEW_CONTROL::ToBeDone, COMMON_ACTIONS::toBeDone.MakeEvent() ); } diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 873d5b5292..e449eec0b2 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -79,6 +79,7 @@ public: int ResetCoords( const TOOL_EVENT& aEvent ); int SwitchCursor( const TOOL_EVENT& aEvent ); int SwitchUnits( const TOOL_EVENT& aEvent ); + int DeleteItemCursor( const TOOL_EVENT& aEvent ); int ShowHelp( const TOOL_EVENT& aEvent ); int ToBeDone( const TOOL_EVENT& aEvent );