diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index 3522e6a69b..ce32fc9b55 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -139,7 +139,7 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame // units display, Inches is bigger than mm GetTextSize( _( "Inches" ), stsbar ).x + 10, - // Size for the "Current Tool" panel; longest string from SetToolID() + // Size for the "Current Tool" panel; longest string from SetTool() GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x + 10, }; @@ -480,31 +480,12 @@ void EDA_DRAW_FRAME::ClearToolStack() } -void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg ) +bool EDA_DRAW_FRAME::IsCurrentTool( const TOOL_ACTION& aAction ) { - // Keep default cursor in toolbars - SetCursor( wxNullCursor ); - - // Change GAL canvas cursor if requested. - if( aCursor >= 0 ) - GetCanvas()->SetCurrentCursor( aCursor ); - - DisplayToolMsg( aToolMsg ); - - if( aId < 0 ) - return; - - wxCHECK2_MSG( aId >= ID_NO_TOOL_SELECTED, aId = ID_NO_TOOL_SELECTED, - wxString::Format( wxT( "Current tool ID cannot be set to %d." ), aId ) ); - - m_toolId = aId; -} - - -void EDA_DRAW_FRAME::SetNoToolSelected() -{ - // Select the ID_NO_TOOL_SELECTED id tool (Idle tool) - SetToolID( ID_NO_TOOL_SELECTED, GetCanvas()->GetDefaultCursor(), wxEmptyString ); + if( m_toolStack.empty() ) + return &aAction == &ACTIONS::selectionTool; + else + return m_toolStack.back() == aAction.GetName(); } @@ -628,9 +609,6 @@ void EDA_DRAW_FRAME::ActivateGalCanvas() { GetCanvas()->SetEvtHandlerEnabled( true ); GetCanvas()->StartDrawing(); - - // Reset current tool on switch(); - SetNoToolSelected(); } diff --git a/common/tool/zoom_tool.cpp b/common/tool/zoom_tool.cpp index bb1d64e2c1..2d7737864a 100644 --- a/common/tool/zoom_tool.cpp +++ b/common/tool/zoom_tool.cpp @@ -46,12 +46,17 @@ void ZOOM_TOOL::Reset( RESET_REASON aReason ) int ZOOM_TOOL::Main( const TOOL_EVENT& aEvent ) { - m_frame->SetToolID( ID_ZOOM_SELECTION, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) ); + m_frame->PushTool( aEvent.GetCommandStr().get() ); while( auto evt = Wait() ) { - if( evt->IsCancel() || evt->IsActivate() ) + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) + { + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + m_frame->ClearToolStack(); + break; + } else if( evt->IsDrag( BUT_LEFT ) || evt->IsDrag( BUT_RIGHT ) ) { @@ -64,7 +69,7 @@ int ZOOM_TOOL::Main( const TOOL_EVENT& aEvent ) } // Exit zoom tool - m_frame->SetNoToolSelected(); + m_frame->PopTool(); return 0; } diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt index c57fa81400..be34e411ef 100644 --- a/cvpcb/CMakeLists.txt +++ b/cvpcb/CMakeLists.txt @@ -33,6 +33,7 @@ set( CVPCB_SRCS ../pcbnew/board_items_to_polygon_shape_transform.cpp ../pcbnew/pcb_general_settings.cpp ../pcbnew/drc_item.cpp + ../pcbnew/tools/pcb_actions.cpp ../pcbnew/tools/grid_helper.cpp auto_associate.cpp cfg.cpp diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 759b86fbf9..23621269bc 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -445,11 +445,11 @@ void DISPLAY_FOOTPRINTS_FRAME::UpdateMsgPanel() void DISPLAY_FOOTPRINTS_FRAME::SyncToolbars() { - m_mainToolBar->Toggle( ACTIONS::zoomTool, GetToolId() == ID_ZOOM_SELECTION ); + m_mainToolBar->Toggle( ACTIONS::zoomTool, IsCurrentTool( ACTIONS::zoomTool ) ); m_mainToolBar->Refresh(); - m_optionsToolBar->Toggle( ACTIONS::selectionTool, GetToolId() == ID_NO_TOOL_SELECTED ); - m_optionsToolBar->Toggle( ACTIONS::measureTool, GetToolId() == ID_TB_MEASUREMENT_TOOL ); + m_optionsToolBar->Toggle( ACTIONS::selectionTool, IsCurrentTool( ACTIONS::selectionTool ) ); + m_optionsToolBar->Toggle( ACTIONS::measureTool, IsCurrentTool( ACTIONS::measureTool ) ); m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != INCHES ); m_optionsToolBar->Toggle( ACTIONS::imperialUnits, GetUserUnits() == INCHES ); m_optionsToolBar->Refresh(); diff --git a/cvpcb/tools/cvpcb_selection_tool.cpp b/cvpcb/tools/cvpcb_selection_tool.cpp index bd6d9b2a62..f97380a3e7 100644 --- a/cvpcb/tools/cvpcb_selection_tool.cpp +++ b/cvpcb/tools/cvpcb_selection_tool.cpp @@ -60,7 +60,7 @@ int CVPCB_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) // There doesn't seem to be any other good way to tell when another tool // is canceled and control returns to the selection tool, except by the // fact that the selection tool starts to get events again. - if( m_frame->GetToolId() == ID_NO_TOOL_SELECTED) + if( m_frame->IsCurrentTool( ACTIONS::selectionTool ) ) { getViewControls()->SetAdditionalPanButtons( false, true ); } @@ -105,8 +105,8 @@ int CVPCB_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) auto& controls = *getViewControls(); auto previous_settings = controls.GetSettings(); + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); - m_frame->SetToolID( ID_TB_MEASUREMENT_TOOL, wxCURSOR_PENCIL, _( "Measure distance" ) ); KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr; KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, m_frame->GetUserUnits() ); @@ -126,12 +126,25 @@ int CVPCB_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) if( evt->IsCancel() || evt->IsActivate() ) { - break; + if( originSet ) + { + view.SetVisible( &ruler, false ); + controls.SetAutoPan( false ); + controls.CaptureCursor( false ); + originSet = false; + } + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + { + m_frame->ClearToolStack(); + break; + } + + if( evt->IsActivate() ) + break; } // click or drag starts - else if( !originSet && - ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) ) + else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) ) { if( !evt->IsDrag( BUT_LEFT ) ) { @@ -154,8 +167,7 @@ int CVPCB_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) } // second click or mouse up after drag ends - else if( originSet && - ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) ) + else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) ) { originSet = false; @@ -166,8 +178,7 @@ int CVPCB_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) } // move or drag when origin set updates rules - else if( originSet && - ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) ) + else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) ) { twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) ); twoPtMgr.SetEnd( cursorPos ); @@ -187,8 +198,6 @@ int CVPCB_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) controls.ApplySettings( previous_settings ); - m_frame->SetNoToolSelected(); - return 0; } diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index 7c8bfdaaae..8d3eece4f5 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -77,7 +77,7 @@ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) if( strcmp( idcmd, "$NET:" ) == 0 ) { - if( GetCurrentToolName() == EE_ACTIONS::highlightNetCursor.GetName() ) + if( IsCurrentTool( EE_ACTIONS::highlightNetCursor ) ) { m_SelectedNetName = FROM_UTF8( text ); diff --git a/eeschema/libedit/toolbars_libedit.cpp b/eeschema/libedit/toolbars_libedit.cpp index bf6428dd74..76864ba204 100644 --- a/eeschema/libedit/toolbars_libedit.cpp +++ b/eeschema/libedit/toolbars_libedit.cpp @@ -50,7 +50,7 @@ void LIB_EDIT_FRAME::ReCreateVToolbar() KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL ); // Set up toolbar - m_drawToolBar->Add( EE_ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); + m_drawToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); KiScaledSeparator( m_drawToolBar, this ); m_drawToolBar->Add( EE_ACTIONS::placeSymbolPin, ACTION_TOOLBAR::TOGGLE ); @@ -164,7 +164,7 @@ void LIB_EDIT_FRAME::SyncToolbars() m_mainToolBar->Toggle( ACTIONS::saveAll, modified ); m_mainToolBar->Toggle( ACTIONS::undo, GetScreen() && GetScreen()->GetUndoCommandCount() > 0 ); m_mainToolBar->Toggle( ACTIONS::redo, GetScreen() && GetScreen()->GetRedoCommandCount() > 0 ); - m_mainToolBar->Toggle( ACTIONS::zoomTool, GetToolId() == ID_ZOOM_SELECTION ); + m_mainToolBar->Toggle( ACTIONS::zoomTool, IsCurrentTool( ACTIONS::zoomTool ) ); m_mainToolBar->Toggle( EE_ACTIONS::showDatasheet, GetCurPart() != nullptr ); m_mainToolBar->Toggle( EE_ACTIONS::showDeMorganStandard, GetShowDeMorgan(), @@ -185,15 +185,15 @@ void LIB_EDIT_FRAME::SyncToolbars() m_optionsToolBar->Toggle( EE_ACTIONS::showComponentTree, IsSearchTreeShown() ); m_optionsToolBar->Refresh(); -#define TOGGLE_TOOL( tool ) m_drawToolBar->Toggle( tool, GetCurrentToolName() == tool.GetName() ) +#define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) ) - TOGGLE_TOOL( EE_ACTIONS::selectionTool ); - TOGGLE_TOOL( EE_ACTIONS::placeSymbolPin ); - TOGGLE_TOOL( EE_ACTIONS::placeSymbolText ); - TOGGLE_TOOL( EE_ACTIONS::drawSymbolRectangle ); - TOGGLE_TOOL( EE_ACTIONS::drawSymbolCircle ); - TOGGLE_TOOL( EE_ACTIONS::drawSymbolArc ); - TOGGLE_TOOL( EE_ACTIONS::drawSymbolLines ); - TOGGLE_TOOL( EE_ACTIONS::deleteItemCursor ); + TOGGLE_TOOL( m_drawToolBar, ACTIONS::selectionTool ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeSymbolPin ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeSymbolText ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::drawSymbolRectangle ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::drawSymbolCircle ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::drawSymbolArc ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::drawSymbolLines ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::deleteItemCursor ); m_drawToolBar->Refresh(); } diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index fc4bda0153..2d92ab31ef 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -441,12 +441,3 @@ void SCH_BASE_FRAME::SyncView() } -std::string SCH_BASE_FRAME::GetCurrentToolName() -{ - if( m_toolStack.empty() ) - return EE_ACTIONS::selectionTool.GetName(); - else - return m_toolStack.back(); -} - - diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index fbd2e1fbd7..550f004f68 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -302,8 +302,6 @@ public: void HardRedraw() override; - std::string GetCurrentToolName(); - /** * Add an item to the screen (and view) * aScreen is the screen the item is located on, if not the current screen diff --git a/eeschema/toolbars_sch_editor.cpp b/eeschema/toolbars_sch_editor.cpp index 112aacfe0a..9e05249450 100644 --- a/eeschema/toolbars_sch_editor.cpp +++ b/eeschema/toolbars_sch_editor.cpp @@ -113,7 +113,7 @@ void SCH_EDIT_FRAME::ReCreateVToolbar() KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL ); // Set up toolbar - m_drawToolBar->Add( EE_ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); + m_drawToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); m_drawToolBar->Add( EE_ACTIONS::highlightNetCursor, ACTION_TOOLBAR::TOGGLE ); KiScaledSeparator( m_drawToolBar, this ); @@ -166,13 +166,15 @@ void SCH_EDIT_FRAME::ReCreateOptToolbar() void SCH_EDIT_FRAME::SyncToolbars() { +#define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) ) + KIGFX::GAL_DISPLAY_OPTIONS& galOpts = GetGalDisplayOptions(); SCH_SHEET_LIST sheetList( g_RootSheet ); m_mainToolBar->Toggle( ACTIONS::saveAll, sheetList.IsModified() ); m_mainToolBar->Toggle( ACTIONS::undo, GetScreen() && GetScreen()->GetUndoCommandCount() > 0 ); m_mainToolBar->Toggle( ACTIONS::redo, GetScreen() && GetScreen()->GetRedoCommandCount() > 0 ); - m_mainToolBar->Toggle( ACTIONS::zoomTool, GetToolId() == ID_ZOOM_SELECTION ); + TOGGLE_TOOL( m_mainToolBar, ACTIONS::zoomTool ); m_mainToolBar->Refresh(); m_optionsToolBar->Toggle( ACTIONS::toggleGrid, IsGridVisible() ); @@ -183,27 +185,25 @@ void SCH_EDIT_FRAME::SyncToolbars() m_optionsToolBar->Toggle( EE_ACTIONS::toggleForceHV, GetForceHVLines() ); m_optionsToolBar->Refresh(); -#define TOGGLE_TOOL( tool ) m_drawToolBar->Toggle( tool, GetCurrentToolName() == tool.GetName() ) - - TOGGLE_TOOL( ACTIONS::selectionTool ); - TOGGLE_TOOL( EE_ACTIONS::highlightNetCursor ); - TOGGLE_TOOL( EE_ACTIONS::placeSymbol ); - TOGGLE_TOOL( EE_ACTIONS::placePower ); - TOGGLE_TOOL( EE_ACTIONS::drawWire ); - TOGGLE_TOOL( EE_ACTIONS::drawBus ); - TOGGLE_TOOL( EE_ACTIONS::placeBusWireEntry ); - TOGGLE_TOOL( EE_ACTIONS::placeBusBusEntry ); - TOGGLE_TOOL( EE_ACTIONS::placeNoConnect ); - TOGGLE_TOOL( EE_ACTIONS::placeJunction ); - TOGGLE_TOOL( EE_ACTIONS::placeLabel ); - TOGGLE_TOOL( EE_ACTIONS::placeGlobalLabel ); - TOGGLE_TOOL( EE_ACTIONS::placeHierLabel ); - TOGGLE_TOOL( EE_ACTIONS::drawSheet ); - TOGGLE_TOOL( EE_ACTIONS::importSheetPin ); - TOGGLE_TOOL( EE_ACTIONS::placeSheetPin ); - TOGGLE_TOOL( EE_ACTIONS::drawLines ); - TOGGLE_TOOL( EE_ACTIONS::placeSchematicText ); - TOGGLE_TOOL( EE_ACTIONS::placeImage ); - TOGGLE_TOOL( EE_ACTIONS::deleteItemCursor ); + TOGGLE_TOOL( m_drawToolBar, ACTIONS::selectionTool ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::highlightNetCursor ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeSymbol ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placePower ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::drawWire ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::drawBus ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeBusWireEntry ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeBusBusEntry ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeNoConnect ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeJunction ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeLabel ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeGlobalLabel ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeHierLabel ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::drawSheet ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::importSheetPin ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeSheetPin ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::drawLines ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeSchematicText ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::placeImage ); + TOGGLE_TOOL( m_drawToolBar, EE_ACTIONS::deleteItemCursor ); m_drawToolBar->Refresh(); } diff --git a/eeschema/tools/lib_edit_tool.cpp b/eeschema/tools/lib_edit_tool.cpp index 3079f29b6c..0a62e5bd83 100644 --- a/eeschema/tools/lib_edit_tool.cpp +++ b/eeschema/tools/lib_edit_tool.cpp @@ -291,19 +291,62 @@ static bool deleteItem( SCH_BASE_FRAME* aFrame, const VECTOR2D& aPosition ) } +#define HITTEST_THRESHOLD_PIXELS 5 + + int LIB_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { - m_frame->PushTool( aEvent.GetCommandStr().get() ); + m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); + + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); EE_PICKER_TOOL* picker = m_toolMgr->GetTool(); - wxCHECK( picker, 0 ); + m_pickerItem = nullptr; + + picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool + { + if( m_pickerItem ) + { + EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + selectionTool->AddItemToSel( m_pickerItem, true ); + m_toolMgr->RunAction( EE_ACTIONS::doDelete, true ); + m_pickerItem = nullptr; + } + + return true; + } ); + + picker->SetMotionHandler( [this] ( const VECTOR2D& aPos ) + { + EE_COLLECTOR collector; + collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); + collector.Collect( m_frame->GetCurPart(), nonFields, (wxPoint) aPos ); + EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr; + + if( m_pickerItem != item ) + { + EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + + if( m_pickerItem ) + selectionTool->UnbrightenItem( m_pickerItem ); + + m_pickerItem = item; + + if( m_pickerItem ) + selectionTool->BrightenItem( m_pickerItem ); + } + } ); + + picker->SetFinalizeHandler( [&]( const int& aFinalState ) + { + if( aFinalState == EE_PICKER_TOOL::EVT_CANCEL ) + m_frame->ClearToolStack(); + } ); - picker->SetClickHandler( std::bind( deleteItem, m_frame, std::placeholders::_1 ) ); picker->Activate(); Wait(); - m_frame->PopTool(); return 0; } diff --git a/eeschema/tools/lib_edit_tool.h b/eeschema/tools/lib_edit_tool.h index 6d1442bcdc..da12028c60 100644 --- a/eeschema/tools/lib_edit_tool.h +++ b/eeschema/tools/lib_edit_tool.h @@ -71,6 +71,9 @@ private: ///> Sets up handlers for various events. void setTransitions() override; + +private: + EDA_ITEM* m_pickerItem; }; #endif //KICAD_LIB_EDIT_TOOL_H diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index a62450f1fc..8b3a335027 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -99,8 +99,7 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent ) m_selectionTool->AddItemToSel( component ); } - m_frame->PushTool( aEvent.GetCommandStr().get() ); - + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); // Prime the pump @@ -460,7 +459,6 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) getViewControls()->ShowCursor( true ); m_frame->SetTool( aEvent.GetCommandStr().get() ); - Activate(); // Prime the pump diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index c2f998998c..b7ef1cbb0c 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -136,14 +136,14 @@ bool SCH_EDIT_TOOL::Init() wxASSERT_MSG( drawingTools, "eeshema.InteractiveDrawing tool is not available" ); auto sheetTool = [ this ] ( const SELECTION& aSel ) { - return ( m_frame->GetCurrentToolName() == EE_ACTIONS::drawSheet.GetName() ); + return ( m_frame->IsCurrentTool( EE_ACTIONS::drawSheet ) ); }; auto anyTextTool = [ this ] ( const SELECTION& aSel ) { - return ( m_frame->GetCurrentToolName() == EE_ACTIONS::placeLabel.GetName() - || m_frame->GetCurrentToolName() == EE_ACTIONS::placeGlobalLabel.GetName() - || m_frame->GetCurrentToolName() == EE_ACTIONS::placeHierLabel.GetName() - || m_frame->GetCurrentToolName() == EE_ACTIONS::placeSchematicText.GetName() ); + return ( m_frame->IsCurrentTool( EE_ACTIONS::placeLabel ) + || m_frame->IsCurrentTool( EE_ACTIONS::placeGlobalLabel ) + || m_frame->IsCurrentTool( EE_ACTIONS::placeHierLabel ) + || m_frame->IsCurrentTool( EE_ACTIONS::placeSchematicText ) ); }; auto duplicateCondition = [] ( const SELECTION& aSel ) { @@ -947,51 +947,58 @@ int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) Activate(); EE_PICKER_TOOL* picker = m_toolMgr->GetTool(); - wxCHECK( picker, 0 ); m_pickerItem = nullptr; - picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool { - if( m_pickerItem ) + picker->SetClickHandler( [this] ( const VECTOR2D& aPosition ) -> bool { - SCH_ITEM* sch_item = dynamic_cast( m_pickerItem ); - - if( sch_item && sch_item->IsLocked() ) + if( m_pickerItem ) { - STATUS_TEXT_POPUP statusPopup( m_frame ); - statusPopup.SetText( _( "Item locked." ) ); - statusPopup.PopupFor( 2000 ); - statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); - return true; + SCH_ITEM* sch_item = dynamic_cast( m_pickerItem ); + + if( sch_item && sch_item->IsLocked() ) + { + STATUS_TEXT_POPUP statusPopup( m_frame ); + statusPopup.SetText( _( "Item locked." ) ); + statusPopup.PopupFor( 2000 ); + statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); + return true; + } + + EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + selectionTool->AddItemToSel( m_pickerItem, true ); + m_toolMgr->RunAction( EE_ACTIONS::doDelete, true ); + m_pickerItem = nullptr; } - EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); - selectionTool->AddItemToSel( m_pickerItem, true ); - m_toolMgr->RunAction( EE_ACTIONS::doDelete, true ); - m_pickerItem = nullptr; - } + return true; + } ); - return true; - } ); - - picker->SetMotionHandler( [this] ( const VECTOR2D& aPos ) { - EE_COLLECTOR collector; - collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); - collector.Collect( m_frame->GetScreen()->GetDrawItems(), deletableItems, (wxPoint) aPos ); - EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr; - - if( m_pickerItem != item ) + picker->SetMotionHandler( [this] ( const VECTOR2D& aPos ) { - EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); + EE_COLLECTOR collector; + collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); + collector.Collect( m_frame->GetScreen()->GetDrawItems(), deletableItems, (wxPoint) aPos ); + EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr; - if( m_pickerItem ) - selectionTool->UnbrightenItem( m_pickerItem ); + if( m_pickerItem != item ) + { + EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); - m_pickerItem = item; + if( m_pickerItem ) + selectionTool->UnbrightenItem( m_pickerItem ); - if( m_pickerItem ) - selectionTool->BrightenItem( m_pickerItem ); - } - } ); + m_pickerItem = item; + + if( m_pickerItem ) + selectionTool->BrightenItem( m_pickerItem ); + } + } ); + + picker->SetFinalizeHandler( [&]( const int& aFinalState ) + { + if( aFinalState == EE_PICKER_TOOL::EVT_CANCEL ) + m_frame->ClearToolStack(); + } ); picker->Activate(); Wait(); diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index b8be49984a..848eaac073 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -149,26 +149,25 @@ SCH_LINE_WIRE_BUS_TOOL::~SCH_LINE_WIRE_BUS_TOOL() } -using E_C = EE_CONDITIONS; - bool SCH_LINE_WIRE_BUS_TOOL::Init() { EE_TOOL_BASE::Init(); auto wireOrBusTool = [ this ] ( const SELECTION& aSel ) { - return ( m_frame->GetCurrentToolName() == EE_ACTIONS::drawWire.GetName() - || m_frame->GetCurrentToolName() == EE_ACTIONS::drawBus.GetName() ); + return ( m_frame->IsCurrentTool( EE_ACTIONS::drawWire ) + || m_frame->IsCurrentTool( EE_ACTIONS::drawBus ) ); }; auto lineTool = [ this ] ( const SELECTION& aSel ) { - return ( m_frame->GetCurrentToolName() == EE_ACTIONS::drawLines.GetName() ); + return ( m_frame->IsCurrentTool( EE_ACTIONS::drawLines ) ); }; auto belowRootSheetCondition = [] ( const SELECTION& aSel ) { return g_CurrentSheet->Last() != g_RootSheet; }; - auto busSelection = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_LINE_LOCATE_BUS_T ); + auto busSelection = EE_CONDITIONS::MoreThan( 0 ) + && EE_CONDITIONS::OnlyType( SCH_LINE_LOCATE_BUS_T ); auto& ctxMenu = m_menu.GetMenu(); @@ -177,9 +176,9 @@ bool SCH_LINE_WIRE_BUS_TOOL::Init() ctxMenu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 2 ); ctxMenu.AddSeparator( 10 ); - ctxMenu.AddItem( EE_ACTIONS::drawWire, wireOrBusTool && E_C::Idle, 10 ); - ctxMenu.AddItem( EE_ACTIONS::drawBus, wireOrBusTool && E_C::Idle, 10 ); - ctxMenu.AddItem( EE_ACTIONS::drawLines, lineTool && E_C::Idle, 10 ); + ctxMenu.AddItem( EE_ACTIONS::drawWire, wireOrBusTool && EE_CONDITIONS::Idle, 10 ); + ctxMenu.AddItem( EE_ACTIONS::drawBus, wireOrBusTool && EE_CONDITIONS::Idle, 10 ); + ctxMenu.AddItem( EE_ACTIONS::drawLines, lineTool && EE_CONDITIONS::Idle, 10 ); ctxMenu.AddItem( EE_ACTIONS::finishWire, IsDrawingWire, 10 ); ctxMenu.AddItem( EE_ACTIONS::finishBus, IsDrawingBus, 10 ); ctxMenu.AddItem( EE_ACTIONS::finishLine, IsDrawingLine, 10 ); @@ -190,16 +189,16 @@ bool SCH_LINE_WIRE_BUS_TOOL::Init() ctxMenu.AddMenu( busUnfoldMenu.get(), EE_CONDITIONS::Idle, 10 ); ctxMenu.AddSeparator( 100 ); - ctxMenu.AddItem( EE_ACTIONS::placeJunction, wireOrBusTool && E_C::Idle, 100 ); - ctxMenu.AddItem( EE_ACTIONS::placeLabel, wireOrBusTool && E_C::Idle, 100 ); - ctxMenu.AddItem( EE_ACTIONS::placeGlobalLabel, wireOrBusTool && E_C::Idle, 100 ); - ctxMenu.AddItem( EE_ACTIONS::placeHierLabel, wireOrBusTool && E_C::Idle, 100 ); - ctxMenu.AddItem( EE_ACTIONS::breakWire, wireOrBusTool && E_C::Idle, 100 ); - ctxMenu.AddItem( EE_ACTIONS::breakBus, wireOrBusTool && E_C::Idle, 100 ); + ctxMenu.AddItem( EE_ACTIONS::placeJunction, wireOrBusTool && EE_CONDITIONS::Idle, 100 ); + ctxMenu.AddItem( EE_ACTIONS::placeLabel, wireOrBusTool && EE_CONDITIONS::Idle, 100 ); + ctxMenu.AddItem( EE_ACTIONS::placeGlobalLabel, wireOrBusTool && EE_CONDITIONS::Idle, 100 ); + ctxMenu.AddItem( EE_ACTIONS::placeHierLabel, wireOrBusTool && EE_CONDITIONS::Idle, 100 ); + ctxMenu.AddItem( EE_ACTIONS::breakWire, wireOrBusTool && EE_CONDITIONS::Idle, 100 ); + ctxMenu.AddItem( EE_ACTIONS::breakBus, wireOrBusTool && EE_CONDITIONS::Idle, 100 ); ctxMenu.AddSeparator( 200 ); - ctxMenu.AddItem( EE_ACTIONS::selectNode, wireOrBusTool && E_C::Idle, 200 ); - ctxMenu.AddItem( EE_ACTIONS::selectConnection, wireOrBusTool && E_C::Idle, 200 ); + ctxMenu.AddItem( EE_ACTIONS::selectNode, wireOrBusTool && EE_CONDITIONS::Idle, 200 ); + ctxMenu.AddItem( EE_ACTIONS::selectConnection, wireOrBusTool && EE_CONDITIONS::Idle, 200 ); // Add bus unfolding to the selection tool // @@ -208,7 +207,7 @@ bool SCH_LINE_WIRE_BUS_TOOL::Init() std::shared_ptr selBusUnfoldMenu = std::make_shared(); selBusUnfoldMenu->SetTool( m_selectionTool ); m_selectionTool->GetToolMenu().AddSubMenu( selBusUnfoldMenu ); - selToolMenu.AddMenu( selBusUnfoldMenu.get(), busSelection && E_C::Idle, 100 ); + selToolMenu.AddMenu( selBusUnfoldMenu.get(), busSelection && EE_CONDITIONS::Idle, 100 ); return true; } @@ -476,13 +475,10 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( int aType, SCH_LINE* aSegment ) m_view->ClearPreview(); m_view->ShowPreview( false ); } - else + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { - if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) - { - m_frame->ClearToolStack(); - break; - } + m_frame->ClearToolStack(); + break; } if( evt->IsActivate() ) diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 081daba231..9ac511438f 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -1260,3 +1260,4 @@ void GERBVIEW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged ) Layout(); SendSizeEvent(); } + diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 51ccf85eed..7219cb2ca8 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -586,8 +586,8 @@ public: // currently: do nothing in GerbView. } - ///> @copydoc EDA_DRAW_FRAME::UseGalCanvas - virtual void ActivateGalCanvas() override; + ///> @copydoc EDA_DRAW_FRAME::ActivateGalCanvas + void ActivateGalCanvas() override; /** * Allows Gerbview to install its preferences panels into the preferences dialog. diff --git a/gerbview/toolbars_gerber.cpp b/gerbview/toolbars_gerber.cpp index 636f7f6201..e6d8cca675 100644 --- a/gerbview/toolbars_gerber.cpp +++ b/gerbview/toolbars_gerber.cpp @@ -202,7 +202,7 @@ void GERBVIEW_FRAME::ReCreateVToolbar() m_drawToolBar = new ACTION_TOOLBAR( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize, KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL ); - m_optionsToolBar->Add( GERBVIEW_ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); m_drawToolBar->AddSeparator(); m_drawToolBar->Realize(); @@ -467,10 +467,12 @@ void GERBVIEW_FRAME::SyncToolbars() { KIGFX::GAL_DISPLAY_OPTIONS& galOpts = GetGalDisplayOptions(); - m_mainToolBar->Toggle( ACTIONS::zoomTool, GetToolId() == ID_ZOOM_SELECTION ); +#define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) ) + + TOGGLE_TOOL( m_mainToolBar, ACTIONS::zoomTool ); m_mainToolBar->Refresh(); - m_optionsToolBar->Toggle( GERBVIEW_ACTIONS::selectionTool, GetToolId() == ID_NO_TOOL_SELECTED ); + TOGGLE_TOOL( m_optionsToolBar, ACTIONS::selectionTool ); m_optionsToolBar->Toggle( ACTIONS::toggleGrid, IsGridVisible() ); m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != INCHES ); m_optionsToolBar->Toggle( ACTIONS::imperialUnits, GetUserUnits() == INCHES ); diff --git a/gerbview/tools/gerbview_selection_tool.cpp b/gerbview/tools/gerbview_selection_tool.cpp index 24ff8b9492..b8c126df7a 100644 --- a/gerbview/tools/gerbview_selection_tool.cpp +++ b/gerbview/tools/gerbview_selection_tool.cpp @@ -187,7 +187,7 @@ int GERBVIEW_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) // There doesn't seem to be any other good way to tell when another tool // is canceled and control returns to the selection tool, except by the // fact that the selection tool starts to get events again. - if( m_frame->GetToolId() == ID_NO_TOOL_SELECTED) + if( m_frame->IsCurrentTool( ACTIONS::selectionTool ) ) { getViewControls()->SetAdditionalPanButtons( false, true ); } @@ -747,8 +747,8 @@ int GERBVIEW_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) auto& controls = *getViewControls(); auto previous_settings = controls.GetSettings(); + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); - m_frame->SetToolID( ID_TB_MEASUREMENT_TOOL, wxCURSOR_PENCIL, _( "Measure distance" ) ); KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr; KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, m_frame->GetUserUnits() ); @@ -768,12 +768,25 @@ int GERBVIEW_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) if( evt->IsCancel() || evt->IsActivate() ) { - break; + if( originSet ) + { + view.SetVisible( &ruler, false ); + controls.SetAutoPan( false ); + controls.CaptureCursor( false ); + originSet = false; + } + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + { + m_frame->ClearToolStack(); + break; + } + + if( evt->IsActivate() ) + break; } // click or drag starts - else if( !originSet && - ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) ) + else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) ) { if( !evt->IsDrag( BUT_LEFT ) ) { @@ -796,8 +809,7 @@ int GERBVIEW_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) } // second click or mouse up after drag ends - else if( originSet && - ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) ) + else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) ) { originSet = false; @@ -808,8 +820,7 @@ int GERBVIEW_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) } // move or drag when origin set updates rules - else if( originSet && - ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) ) + else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) ) { twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) ); twoPtMgr.SetEnd( cursorPos ); @@ -829,8 +840,6 @@ int GERBVIEW_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) controls.ApplySettings( previous_settings ); - m_frame->SetNoToolSelected(); - return 0; } diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h index f0cd30ccb3..7b7bfc0d63 100644 --- a/include/eda_draw_frame.h +++ b/include/eda_draw_frame.h @@ -310,32 +310,16 @@ public: virtual void SetTool( const std::string& actionName ); virtual void PushTool( const std::string& actionName ); virtual void PopTool(); - /** * The selection tool runs underneath the tool stack, so clearing the stack is equivalent * to selecting the selection tool. */ virtual void ClearToolStack(); - /** - * Set the tool command ID to \a aId and sets the cursor to \a aCursor. - * - * The command ID must be greater or equal ::ID_NO_TOOL_SELECTED. If the command - * ID is less than ::ID_NO_TOOL_SELECTED, the tool command ID is set to - * ::ID_NO_TOOL_SELECTED. On debug builds, an assertion will be raised when - * \a aId is invalid. - * - * @param aId New tool command ID if greater than or equal to ::ID_NO_TOOL_SELECTED. - If less than zero, the current tool command ID is retained. - * @param aCursor Sets the cursor shape if greater than or equal to zero. - * @param aToolMsg The tool message to set in the status bar. - */ - virtual void SetToolID( int aId, int aCursor, const wxString& aToolMsg ); + bool ToolStackIsEmpty() { return m_toolStack.empty(); } + + bool IsCurrentTool( const TOOL_ACTION& aAction ); - /** - * Select the ID_NO_TOOL_SELECTED id tool (Idle tool) - */ - virtual void SetNoToolSelected(); /** * @return the current tool ID diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index ba6a927afe..1605cc0790 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -200,7 +200,6 @@ public: virtual void ReCreateOptToolbar() { } virtual void ShowChangedLanguage() override; virtual void ReCreateMenuBar() override; - virtual void SetToolID( int aId, int aCursor, const wxString& aToolMsg ) override; virtual void UpdateStatusBar() override; PCB_SCREEN* GetScreen() const override { return (PCB_SCREEN*) EDA_DRAW_FRAME::GetScreen(); } diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index 010ab94588..126010f376 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -737,3 +737,4 @@ const wxString PL_EDITOR_FRAME::GetZoomLevelIndicator() const { return EDA_DRAW_FRAME::GetZoomLevelIndicator(); } + diff --git a/pagelayout_editor/pl_editor_id.h b/pagelayout_editor/pl_editor_id.h index 1a20bc2ac4..7c6da07e8f 100644 --- a/pagelayout_editor/pl_editor_id.h +++ b/pagelayout_editor/pl_editor_id.h @@ -42,13 +42,6 @@ enum pl_editor_ids ID_APPEND_DESCR_FILE, - ID_PL_MOVE_TOOL, - ID_PL_LINE_TOOL, - ID_PL_RECTANGLE_TOOL, - ID_PL_TEXT_TOOL, - ID_PL_IMAGE_TOOL, - ID_PL_DELETE_TOOL, - ID_PLEDITOR_END_LIST }; diff --git a/pagelayout_editor/toolbars_pl_editor.cpp b/pagelayout_editor/toolbars_pl_editor.cpp index a0a472ae26..a3d2d50f58 100644 --- a/pagelayout_editor/toolbars_pl_editor.cpp +++ b/pagelayout_editor/toolbars_pl_editor.cpp @@ -125,7 +125,7 @@ void PL_EDITOR_FRAME::ReCreateVToolbar() m_drawToolBar = new ACTION_TOOLBAR( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize, KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL ); - m_drawToolBar->Add( PL_ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); + m_drawToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); KiScaledSeparator( m_drawToolBar, this ); m_drawToolBar->Add( PL_ACTIONS::drawLine, ACTION_TOOLBAR::TOGGLE ); @@ -148,18 +148,20 @@ void PL_EDITOR_FRAME::ReCreateOptToolbar() void PL_EDITOR_FRAME::SyncToolbars() { +#define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) ) + m_mainToolBar->Toggle( ACTIONS::save, GetScreen() && GetScreen()->IsModify() ); m_mainToolBar->Toggle( ACTIONS::undo, GetScreen() && GetScreen()->GetUndoCommandCount() > 0 ); m_mainToolBar->Toggle( ACTIONS::redo, GetScreen() && GetScreen()->GetRedoCommandCount() > 0 ); - m_mainToolBar->Toggle( ACTIONS::zoomTool, GetToolId() == ID_ZOOM_SELECTION ); + TOGGLE_TOOL( m_mainToolBar, ACTIONS::zoomTool ); m_mainToolBar->Refresh(); - m_drawToolBar->Toggle( PL_ACTIONS::selectionTool, GetToolId() == ID_NO_TOOL_SELECTED ); - m_drawToolBar->Toggle( PL_ACTIONS::drawLine, GetToolId() == ID_PL_LINE_TOOL ); - m_drawToolBar->Toggle( PL_ACTIONS::drawRectangle, GetToolId() == ID_PL_RECTANGLE_TOOL ); - m_drawToolBar->Toggle( PL_ACTIONS::placeText, GetToolId() == ID_PL_TEXT_TOOL ); - m_drawToolBar->Toggle( PL_ACTIONS::placeImage, GetToolId() == ID_PL_IMAGE_TOOL ); - m_drawToolBar->Toggle( PL_ACTIONS::deleteItemCursor, GetToolId() == ID_PL_DELETE_TOOL ); + TOGGLE_TOOL( m_drawToolBar, ACTIONS::selectionTool ); + TOGGLE_TOOL( m_drawToolBar, PL_ACTIONS::drawLine ); + TOGGLE_TOOL( m_drawToolBar, PL_ACTIONS::drawRectangle ); + TOGGLE_TOOL( m_drawToolBar, PL_ACTIONS::placeText ); + TOGGLE_TOOL( m_drawToolBar, PL_ACTIONS::placeImage ); + TOGGLE_TOOL( m_drawToolBar, PL_ACTIONS::deleteItemCursor ); m_drawToolBar->Toggle( PL_ACTIONS::appendImportedWorksheet, false ); // Not really a tool m_drawToolBar->Refresh(); diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp index 9ce29382ff..3ac01f9fa3 100644 --- a/pagelayout_editor/tools/pl_edit_tool.cpp +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -293,8 +293,7 @@ int PL_EDIT_TOOL::ImportWorksheetContent( const TOOL_EVENT& aEvent ) wxCommandEvent evt( wxEVT_NULL, ID_APPEND_DESCR_FILE ); m_frame->Files_io( evt ); - m_frame->SetNoToolSelected(); - + m_frame->ClearToolStack(); return 0; } @@ -352,13 +351,20 @@ static bool deleteItem( PL_EDITOR_FRAME* aFrame, const VECTOR2D& aPosition ) int PL_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); PL_PICKER_TOOL* picker = m_toolMgr->GetTool(); wxCHECK( picker, 0 ); - m_frame->SetToolID( ID_PL_DELETE_TOOL, wxCURSOR_BULLSEYE, _( "Delete item" ) ); picker->SetClickHandler( std::bind( deleteItem, m_frame, std::placeholders::_1 ) ); + + picker->SetFinalizeHandler( [&]( const int& aFinalState ) + { + if( aFinalState == PL_PICKER_TOOL::EVT_CANCEL ) + m_frame->ClearToolStack(); + } ); + picker->Activate(); Wait(); diff --git a/pagelayout_editor/tools/pl_picker_tool.cpp b/pagelayout_editor/tools/pl_picker_tool.cpp index 91eec9dc67..c0c9d94c0a 100644 --- a/pagelayout_editor/tools/pl_picker_tool.cpp +++ b/pagelayout_editor/tools/pl_picker_tool.cpp @@ -147,8 +147,6 @@ int PL_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) resetPicker(); controls->ForceCursorPosition( false ); - getEditFrame()->SetNoToolSelected(); - return 0; } diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp index d3da330a9b..d4163b108a 100644 --- a/pcbnew/cross-probing.cpp +++ b/pcbnew/cross-probing.cpp @@ -89,7 +89,7 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) if( strcmp( idcmd, "$NET:" ) == 0 ) { - if( GetToolId() == ID_PCB_HIGHLIGHT_BUTT ) + if( IsCurrentTool( PCB_ACTIONS::highlightNetTool ) ) { wxString net_name = FROM_UTF8( text ); NETINFO_ITEM* netinfo = pcb->FindNet( net_name ); diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 699725a24f..c1074fbf49 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -64,22 +64,6 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) int id = event.GetId(); auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions(); - switch( id ) // Some (not all ) edit commands must be finished or aborted - { - case ID_TOOLBARH_PCB_SELECT_LAYER: - break; - - default: // Finish (abort) the command - if( GetToolId() != id ) - { - if( m_lastDrawToolId != GetToolId() ) - m_lastDrawToolId = GetToolId(); - - SetNoToolSelected(); - } - break; - } - switch( id ) // Execute command { case 0: diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index 0e77c05ae9..957205313b 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -144,16 +144,6 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) wxGetMousePosition( &pos.x, &pos.y ); pos.y += 20; - switch( id ) - { - case ID_TOOLBARH_PCB_SELECT_LAYER: - break; - - default: - SetNoToolSelected(); - break; - } - switch( id ) { case ID_MODEDIT_NEW_MODULE: diff --git a/pcbnew/menubar_footprint_editor.cpp b/pcbnew/menubar_footprint_editor.cpp index a3e4ac1e6b..947151588c 100644 --- a/pcbnew/menubar_footprint_editor.cpp +++ b/pcbnew/menubar_footprint_editor.cpp @@ -120,7 +120,7 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar() return GetScreen() && GetScreen()->GetRedoCommandCount() > 0; }; auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) { - return GetToolId() == ID_NO_TOOL_SELECTED; + return ToolStackIsEmpty(); }; editMenu->AddItem( ACTIONS::undo, enableUndoCondition ); diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index 7ceef6914c..6f0d49d46e 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -218,7 +218,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() return GetScreen() && GetScreen()->GetRedoCommandCount() > 0; }; auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) { - return GetToolId() == ID_NO_TOOL_SELECTED; + return ToolStackIsEmpty(); }; editMenu->AddItem( ACTIONS::undo, enableUndoCondition ); @@ -417,8 +417,8 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() routeMenu->AddItem( PCB_ACTIONS::selectLayerPair, SELECTION_CONDITIONS::ShowAlways ); routeMenu->AddSeparator(); - routeMenu->AddItem( PCB_ACTIONS::routerActivateSingle, SELECTION_CONDITIONS::ShowAlways ); - routeMenu->AddItem( PCB_ACTIONS::routerActivateDiffPair, SELECTION_CONDITIONS::ShowAlways ); + routeMenu->AddItem( PCB_ACTIONS::routeSingleTrack, SELECTION_CONDITIONS::ShowAlways ); + routeMenu->AddItem( PCB_ACTIONS::routeDiffPair, SELECTION_CONDITIONS::ShowAlways ); routeMenu->AddSeparator(); routeMenu->AddItem( PCB_ACTIONS::routerTuneSingleTrace, SELECTION_CONDITIONS::ShowAlways ); diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 63da2d392e..88ee2488d4 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -564,31 +564,6 @@ GENERAL_COLLECTORS_GUIDE PCB_BASE_FRAME::GetCollectorsGuide() return guide; } -void PCB_BASE_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg ) -{ - bool redraw = false; - - EDA_DRAW_FRAME::SetToolID( aId, aCursor, aToolMsg ); - - if( aId < 0 ) - return; - - auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions(); - - // handle color changes for transitions in and out of ID_TRACK_BUTT - if( ( GetToolId() == ID_TRACK_BUTT && aId != ID_TRACK_BUTT ) - || ( GetToolId() != ID_TRACK_BUTT && aId == ID_TRACK_BUTT ) ) - { - if( displ_opts->m_ContrastModeDisplay ) - redraw = true; - } - - // must do this after the tool has been set, otherwise pad::Draw() does - // not show proper color when GetDisplayOptions().ContrastModeDisplay is true. - if( redraw ) - GetCanvas()->Refresh(); -} - /* * Display the grid status. diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 8dbdb304f4..d04dc1ce07 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -173,8 +173,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) PCB_EDIT_FRAME::OnUpdateSelectTrackWidth ) EVT_UPDATE_UI_RANGE( ID_POPUP_PCB_SELECT_VIASIZE1, ID_POPUP_PCB_SELECT_VIASIZE8, PCB_EDIT_FRAME::OnUpdateSelectViaSize ) - EVT_UPDATE_UI_RANGE( ID_PCB_MUWAVE_START_CMD, ID_PCB_MUWAVE_END_CMD, - PCB_EDIT_FRAME::OnUpdateMuWaveToolbar ) EVT_COMMAND( wxID_ANY, LAYER_WIDGET::EVT_LAYER_COLOR_CHANGE, PCB_EDIT_FRAME::OnLayerColorChange ) END_EVENT_TABLE() diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 9c0d567583..8b280a38db 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -87,7 +87,7 @@ class PCB_EDIT_FRAME : public PCB_BASE_EDIT_FRAME friend class PCB_LAYER_WIDGET; /// The auxiliary right vertical tool bar used to access the microwave tools. - wxAuiToolBar* m_microWaveToolBar; + ACTION_TOOLBAR* m_microWaveToolBar; protected: PCB_LAYER_WIDGET* m_Layers; @@ -302,7 +302,6 @@ public: bool MicrowaveToolbarShown(); void OnUpdateSelectViaSize( wxUpdateUIEvent& aEvent ); void OnUpdateSelectTrackWidth( wxUpdateUIEvent& aEvent ); - void OnUpdateMuWaveToolbar( wxUpdateUIEvent& aEvent ); void OnLayerColorChange( wxCommandEvent& aEvent ); void OnRunEeschema( wxCommandEvent& event ); diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index 27fb71c874..01c01e13c1 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -119,28 +119,8 @@ enum pcbnew_ids ID_PCB_GEN_BOM_FILE_FROM_BOARD, ID_PCB_3DSHAPELIB_WIZARD, - ID_PCB_MUWAVE_START_CMD, - ID_PCB_MUWAVE_TOOL_SELF_CMD, - ID_PCB_MUWAVE_TOOL_GAP_CMD, - ID_PCB_MUWAVE_TOOL_STUB_CMD, - ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD, - ID_PCB_MUWAVE_TOOL_FUNCTION_SHAPE_CMD, - ID_PCB_MUWAVE_END_CMD, - ID_TOOLBARH_PCB_SELECT_LAYER, - // Module editor right vertical tool bar commands. - ID_MODEDIT_PAD_TOOL, - ID_MODEDIT_LINE_TOOL, - ID_MODEDIT_CIRCLE_TOOL, - ID_MODEDIT_ARC_TOOL, - ID_MODEDIT_POLYGON_TOOL, - ID_MODEDIT_TEXT_TOOL, - ID_MODEDIT_ANCHOR_TOOL, - ID_MODEDIT_DELETE_TOOL, - ID_MODEDIT_PLACE_GRID_COORD, - ID_MODEDIT_MEASUREMENT_TOOL, - // ID used in module editor: ID_MODEDIT_CHECK, ID_MODEDIT_SAVE, diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp index 93b86f59af..b4ee520f80 100644 --- a/pcbnew/router/length_tuner_tool.cpp +++ b/pcbnew/router/length_tuner_tool.cpp @@ -247,43 +247,23 @@ void LENGTH_TUNER_TOOL::performTuning() } -int LENGTH_TUNER_TOOL::TuneSingleTrace( const TOOL_EVENT& aEvent ) -{ - frame()->SetToolID( ID_TRACK_BUTT, wxCURSOR_PENCIL, _( "Tune Trace Length" ) ); - return mainLoop( PNS::PNS_MODE_TUNE_SINGLE ); -} - - -int LENGTH_TUNER_TOOL::TuneDiffPair( const TOOL_EVENT& aEvent ) -{ - frame()->SetToolID( ID_TRACK_BUTT, wxCURSOR_PENCIL, _( "Tune Diff Pair Length" ) ); - return mainLoop( PNS::PNS_MODE_TUNE_DIFF_PAIR ); -} - - -int LENGTH_TUNER_TOOL::TuneDiffPairSkew( const TOOL_EVENT& aEvent ) -{ - frame()->SetToolID( ID_TRACK_BUTT, wxCURSOR_PENCIL, _( "Tune Diff Pair Skew" ) ); - return mainLoop( PNS::PNS_MODE_TUNE_DIFF_PAIR_SKEW ); -} - - void LENGTH_TUNER_TOOL::setTransitions() { - Go( &LENGTH_TUNER_TOOL::TuneSingleTrace, PCB_ACTIONS::routerTuneSingleTrace.MakeEvent() ); - Go( &LENGTH_TUNER_TOOL::TuneDiffPair, PCB_ACTIONS::routerTuneDiffPair.MakeEvent() ); - Go( &LENGTH_TUNER_TOOL::TuneDiffPairSkew, PCB_ACTIONS::routerTuneDiffPairSkew.MakeEvent() ); + Go( &LENGTH_TUNER_TOOL::MainLoop, PCB_ACTIONS::routerTuneSingleTrace.MakeEvent() ); + Go( &LENGTH_TUNER_TOOL::MainLoop, PCB_ACTIONS::routerTuneDiffPair.MakeEvent() ); + Go( &LENGTH_TUNER_TOOL::MainLoop, PCB_ACTIONS::routerTuneDiffPairSkew.MakeEvent() ); } -int LENGTH_TUNER_TOOL::mainLoop( PNS::ROUTER_MODE aMode ) +int LENGTH_TUNER_TOOL::MainLoop( const TOOL_EVENT& aEvent ) { // Deselect all items m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); + frame()->SetTool( aEvent.GetCommandStr().get() ); Activate(); - m_router->SetMode( aMode ); + m_router->SetMode( aEvent.Parameter() ); controls()->SetSnapping( true ); controls()->ShowCursor( true ); @@ -315,7 +295,6 @@ int LENGTH_TUNER_TOOL::mainLoop( PNS::ROUTER_MODE aMode ) } } - frame()->SetNoToolSelected(); frame()->UndoRedoBlock( false ); // Store routing settings till the next invocation diff --git a/pcbnew/router/length_tuner_tool.h b/pcbnew/router/length_tuner_tool.h index 787d5b0262..db2f6da118 100644 --- a/pcbnew/router/length_tuner_tool.h +++ b/pcbnew/router/length_tuner_tool.h @@ -36,15 +36,12 @@ public: void Reset( RESET_REASON aReason ) override; - int TuneSingleTrace( const TOOL_EVENT& aEvent ); - int TuneDiffPair( const TOOL_EVENT& aEvent ); - int TuneDiffPairSkew( const TOOL_EVENT& aEvent ); + int MainLoop( const TOOL_EVENT& aEvent ); void setTransitions() override; private: void performTuning(); - int mainLoop( PNS::ROUTER_MODE aMode ); void updateStatusPopup( PNS_TUNE_STATUS_POPUP& aPopup ); int routerOptionsDialog( const TOOL_EVENT& aEvent ); diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index c39c9ad054..869c394472 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -83,22 +83,16 @@ enum VIA_ACTION_FLAGS #undef _ #define _(s) s -static const TOOL_ACTION ACT_NewTrack( "pcbnew.InteractiveRouter.NewTrack", - AS_CONTEXT, - 'X', LEGACY_HK_NAME( "Add New Track" ), - _( "New Track" ), _( "Starts laying a new track." ), - add_tracks_xpm ); - -static const TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", +static const TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", AS_CONTEXT, WXK_END, "", - _( "End Track" ), _( "Stops laying the current track." ), + _( "Finish Track" ), _( "Stops laying the current track." ), checked_ok_xpm ); static const TOOL_ACTION ACT_AutoEndRoute( "pcbnew.InteractiveRouter.AutoEndRoute", AS_CONTEXT, 'F', "", - _( "Auto-end Track" ), _( "Automagically finishes currently routed track." ) ); + _( "Auto-finish Track" ), _( "Automagically finishes laying the current track." ) ); static const TOOL_ACTION ACT_PlaceThroughVia( "pcbnew.InteractiveRouter.PlaceVia", AS_CONTEXT, @@ -394,7 +388,8 @@ public: AppendSeparator(); - Add( ACT_NewTrack ); + Add( PCB_ACTIONS::routeSingleTrack ); + Add( PCB_ACTIONS::routeDiffPair ); Add( ACT_EndTrack ); Add( PCB_ACTIONS::breakTrack ); @@ -770,7 +765,7 @@ void ROUTER_TOOL::performRouting() updateEndItem( *evt ); m_router->Move( m_endSnapPoint, m_endItem ); } - else if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &ACT_NewTrack ) ) + else if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &PCB_ACTIONS::routeSingleTrack ) ) { updateEndItem( *evt ); bool needLayerSwitch = m_router->IsPlacingVia(); @@ -849,42 +844,6 @@ int ROUTER_TOOL::SettingsDialog( const TOOL_EVENT& aEvent ) } -void ROUTER_TOOL::setTransitions() -{ - Go( &ROUTER_TOOL::SelectCopperLayerPair, PCB_ACTIONS::selectLayerPair.MakeEvent() ); - - Go( &ROUTER_TOOL::RouteSingleTrace, PCB_ACTIONS::routerActivateSingle.MakeEvent() ); - Go( &ROUTER_TOOL::RouteDiffPair, PCB_ACTIONS::routerActivateDiffPair.MakeEvent() ); - Go( &ROUTER_TOOL::DpDimensionsDialog, PCB_ACTIONS::routerDiffPairDialog.MakeEvent() ); - Go( &ROUTER_TOOL::SettingsDialog, PCB_ACTIONS::routerSettingsDialog.MakeEvent() ); - Go( &ROUTER_TOOL::InlineDrag, PCB_ACTIONS::routerInlineDrag.MakeEvent() ); - Go( &ROUTER_TOOL::InlineBreakTrack, PCB_ACTIONS::inlineBreakTrack.MakeEvent() ); - - Go( &ROUTER_TOOL::onViaCommand, ACT_PlaceThroughVia.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, ACT_PlaceBlindVia.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, ACT_PlaceMicroVia.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, ACT_SelLayerAndPlaceThroughVia.MakeEvent() ); - Go( &ROUTER_TOOL::onViaCommand, ACT_SelLayerAndPlaceBlindVia.MakeEvent() ); - - Go( &ROUTER_TOOL::CustomTrackWidthDialog, ACT_CustomTrackWidth.MakeEvent() ); - Go( &ROUTER_TOOL::onTrackViaSizeChanged, PCB_ACTIONS::trackViaSizeChanged.MakeEvent() ); -} - - -int ROUTER_TOOL::RouteSingleTrace( const TOOL_EVENT& aEvent ) -{ - frame()->SetToolID( ID_TRACK_BUTT, wxCURSOR_PENCIL, _( "Route Track" ) ); - return mainLoop( PNS::PNS_MODE_ROUTE_SINGLE ); -} - - -int ROUTER_TOOL::RouteDiffPair( const TOOL_EVENT& aEvent ) -{ - frame()->SetToolID( ID_TRACK_BUTT, wxCURSOR_PENCIL, _( "Router Differential Pair" ) ); - return mainLoop( PNS::PNS_MODE_ROUTE_DIFF_PAIR ); -} - - void ROUTER_TOOL::breakTrack() { if( m_startItem && m_startItem->OfKind( PNS::ITEM::SEGMENT_T ) ) @@ -894,30 +853,39 @@ void ROUTER_TOOL::breakTrack() } -int ROUTER_TOOL::mainLoop( PNS::ROUTER_MODE aMode ) +int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent ) { - PCB_EDIT_FRAME* frame = getEditFrame(); + PNS::ROUTER_MODE mode = aEvent.Parameter(); + PCB_EDIT_FRAME* frame = getEditFrame(); // Deselect all items m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); + frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); - m_router->SetMode( aMode ); + m_router->SetMode( mode ); VIEW_CONTROLS* ctls = getViewControls(); ctls->ShowCursor( true ); ctls->ForceCursorPosition( false ); m_startSnapPoint = ctls->GetCursorPosition(); - std::unique_ptr ctxMenu( new ROUTER_TOOL_MENU( *frame, aMode ) ); + std::unique_ptr ctxMenu( new ROUTER_TOOL_MENU( *frame, mode ) ); SetContextMenu( ctxMenu.get() ); + // Prime the pump + if( aEvent.HasPosition() ) + m_toolMgr->RunAction( ACTIONS::cursorClick ); + // Main loop: keep receiving events while( TOOL_EVENT* evt = Wait() ) { if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) { + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + frame->ClearToolStack(); + break; // Finish } else if( evt->Action() == TA_UNDO_REDO_PRE ) @@ -947,8 +915,16 @@ int ROUTER_TOOL::mainLoop( PNS::ROUTER_MODE aMode ) updateStartItem( *evt, true ); breakTrack( ); } - else if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &ACT_NewTrack ) ) + else if( evt->IsClick( BUT_LEFT ) + || evt->IsAction( &PCB_ACTIONS::routeSingleTrack ) + || evt->IsAction( &PCB_ACTIONS::routeDiffPair ) ) { + if( evt->IsAction( &PCB_ACTIONS::routeSingleTrack ) + || evt->IsAction( &PCB_ACTIONS::routeDiffPair ) ) + { + mode = evt->Parameter(); + } + updateStartItem( *evt ); if( evt->Modifier( MD_CTRL ) ) @@ -962,7 +938,6 @@ int ROUTER_TOOL::mainLoop( PNS::ROUTER_MODE aMode ) } } - frame->SetNoToolSelected(); SetContextMenu( nullptr ); // Store routing settings till the next invocation @@ -1256,3 +1231,27 @@ int ROUTER_TOOL::onTrackViaSizeChanged( const TOOL_EVENT& aEvent ) return 0; } + + +void ROUTER_TOOL::setTransitions() +{ + Go( &ROUTER_TOOL::SelectCopperLayerPair, PCB_ACTIONS::selectLayerPair.MakeEvent() ); + + Go( &ROUTER_TOOL::MainLoop, PCB_ACTIONS::routeSingleTrack.MakeEvent() ); + Go( &ROUTER_TOOL::MainLoop, PCB_ACTIONS::routeDiffPair.MakeEvent() ); + Go( &ROUTER_TOOL::DpDimensionsDialog, PCB_ACTIONS::routerDiffPairDialog.MakeEvent() ); + Go( &ROUTER_TOOL::SettingsDialog, PCB_ACTIONS::routerSettingsDialog.MakeEvent() ); + Go( &ROUTER_TOOL::InlineDrag, PCB_ACTIONS::routerInlineDrag.MakeEvent() ); + Go( &ROUTER_TOOL::InlineBreakTrack, PCB_ACTIONS::inlineBreakTrack.MakeEvent() ); + + Go( &ROUTER_TOOL::onViaCommand, ACT_PlaceThroughVia.MakeEvent() ); + Go( &ROUTER_TOOL::onViaCommand, ACT_PlaceBlindVia.MakeEvent() ); + Go( &ROUTER_TOOL::onViaCommand, ACT_PlaceMicroVia.MakeEvent() ); + Go( &ROUTER_TOOL::onViaCommand, ACT_SelLayerAndPlaceThroughVia.MakeEvent() ); + Go( &ROUTER_TOOL::onViaCommand, ACT_SelLayerAndPlaceBlindVia.MakeEvent() ); + + Go( &ROUTER_TOOL::CustomTrackWidthDialog, ACT_CustomTrackWidth.MakeEvent() ); + Go( &ROUTER_TOOL::onTrackViaSizeChanged, PCB_ACTIONS::trackViaSizeChanged.MakeEvent() ); +} + + diff --git a/pcbnew/router/router_tool.h b/pcbnew/router/router_tool.h index eba2942dbc..78f09da471 100644 --- a/pcbnew/router/router_tool.h +++ b/pcbnew/router/router_tool.h @@ -34,8 +34,8 @@ public: bool Init() override; void Reset( RESET_REASON aReason ) override; - int RouteSingleTrace( const TOOL_EVENT& aEvent ); - int RouteDiffPair( const TOOL_EVENT& aEvent ); + int MainLoop( const TOOL_EVENT& aEvent ); + int InlineBreakTrack( const TOOL_EVENT& aEvent ); bool CanInlineDrag(); int InlineDrag( const TOOL_EVENT& aEvent ); @@ -53,8 +53,6 @@ public: static void NeighboringSegmentFilter( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ); private: - int mainLoop( PNS::ROUTER_MODE aMode ); - void performRouting(); void performDragging( int aMode = PNS::DM_ANY ); void breakTrack(); diff --git a/pcbnew/toolbars_footprint_editor.cpp b/pcbnew/toolbars_footprint_editor.cpp index 171c9fc5dc..fee3daf493 100644 --- a/pcbnew/toolbars_footprint_editor.cpp +++ b/pcbnew/toolbars_footprint_editor.cpp @@ -126,7 +126,7 @@ void FOOTPRINT_EDIT_FRAME::ReCreateVToolbar() m_drawToolBar = new ACTION_TOOLBAR( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize, KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL ); - m_drawToolBar->Add( PCB_ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); + m_drawToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); KiScaledSeparator( m_drawToolBar, this ); m_drawToolBar->Add( PCB_ACTIONS::placePad, ACTION_TOOLBAR::TOGGLE ); @@ -174,6 +174,8 @@ void FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar() void FOOTPRINT_EDIT_FRAME::SyncToolbars() { +#define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) ) + PCB_DISPLAY_OPTIONS* opts = (PCB_DISPLAY_OPTIONS*) GetDisplayOptions(); if( IsCurrentFPFromBoard() ) @@ -183,7 +185,7 @@ void FOOTPRINT_EDIT_FRAME::SyncToolbars() m_mainToolBar->Toggle( ACTIONS::undo, GetScreen() && GetScreen()->GetUndoCommandCount() > 0 ); m_mainToolBar->Toggle( ACTIONS::redo, GetScreen() && GetScreen()->GetRedoCommandCount() > 0 ); - m_mainToolBar->Toggle( ACTIONS::zoomTool, GetToolId() == ID_ZOOM_SELECTION ); + TOGGLE_TOOL( m_mainToolBar, ACTIONS::zoomTool ); m_mainToolBar->Toggle( PCB_ACTIONS::footprintProperties, GetBoard()->GetFirstModule() ); m_mainToolBar->Refresh(); @@ -197,16 +199,16 @@ void FOOTPRINT_EDIT_FRAME::SyncToolbars() m_optionsToolBar->Toggle( PCB_ACTIONS::toggleFootprintTree, IsSearchTreeShown() ); m_optionsToolBar->Refresh(); - m_drawToolBar->Toggle( ACTIONS::selectionTool, GetToolId() == ID_NO_TOOL_SELECTED ); - m_drawToolBar->Toggle( PCB_ACTIONS::placePad, GetToolId() == ID_MODEDIT_PAD_TOOL ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawLine, GetToolId() == ID_MODEDIT_LINE_TOOL ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawCircle, GetToolId() == ID_MODEDIT_CIRCLE_TOOL ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawArc, GetToolId() == ID_MODEDIT_ARC_TOOL ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawPolygon, GetToolId() == ID_MODEDIT_POLYGON_TOOL ); - m_drawToolBar->Toggle( PCB_ACTIONS::placeText, GetToolId() == ID_MODEDIT_TEXT_TOOL ); - m_drawToolBar->Toggle( PCB_ACTIONS::deleteTool, GetToolId() == ID_MODEDIT_DELETE_TOOL ); - m_drawToolBar->Toggle( PCB_ACTIONS::setAnchor, GetToolId() == ID_MODEDIT_ANCHOR_TOOL ); - m_drawToolBar->Toggle( PCB_ACTIONS::gridSetOrigin, GetToolId() == ID_MODEDIT_PLACE_GRID_COORD ); - m_drawToolBar->Toggle( ACTIONS::measureTool, GetToolId() == ID_MODEDIT_MEASUREMENT_TOOL ); + TOGGLE_TOOL( m_drawToolBar, ACTIONS::selectionTool ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placePad ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawLine ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawCircle ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawArc ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawPolygon ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placeText ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::deleteTool ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::setAnchor ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::gridSetOrigin ); + TOGGLE_TOOL( m_drawToolBar, ACTIONS::measureTool ); m_drawToolBar->Refresh(); } diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index 66b93d39ec..2c2ed50393 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -367,13 +367,13 @@ void PCB_EDIT_FRAME::ReCreateVToolbar() m_drawToolBar = new ACTION_TOOLBAR( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize, KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL ); - m_drawToolBar->Add( PCB_ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); + m_drawToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); m_drawToolBar->Add( PCB_ACTIONS::highlightNetTool, ACTION_TOOLBAR::TOGGLE ); m_drawToolBar->Add( PCB_ACTIONS::localRatsnestTool, ACTION_TOOLBAR::TOGGLE ); KiScaledSeparator( m_drawToolBar, this ); m_drawToolBar->Add( PCB_ACTIONS::placeModule, ACTION_TOOLBAR::TOGGLE ); - m_drawToolBar->Add( PCB_ACTIONS::routerActivateSingle, ACTION_TOOLBAR::TOGGLE ); + m_drawToolBar->Add( PCB_ACTIONS::routeSingleTrack, ACTION_TOOLBAR::TOGGLE ); m_drawToolBar->Add( PCB_ACTIONS::drawVia, ACTION_TOOLBAR::TOGGLE ); m_drawToolBar->Add( PCB_ACTIONS::drawZone, ACTION_TOOLBAR::TOGGLE ); m_drawToolBar->Add( PCB_ACTIONS::drawZoneKeepout, ACTION_TOOLBAR::TOGGLE ); @@ -406,37 +406,18 @@ void PCB_EDIT_FRAME::ReCreateMicrowaveVToolbar() if( m_microWaveToolBar ) m_microWaveToolBar->Clear(); else - m_microWaveToolBar = new wxAuiToolBar( this, ID_MICROWAVE_V_TOOLBAR, wxDefaultPosition, - wxDefaultSize, - KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL ); + m_microWaveToolBar = new ACTION_TOOLBAR( this, ID_MICROWAVE_V_TOOLBAR, wxDefaultPosition, + wxDefaultSize, + KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL ); // Set up toolbar - m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_SELF_CMD, wxEmptyString, - KiScaledBitmap( mw_add_line_xpm, this ), - _( "Create line of specified length for microwave applications" ), - wxITEM_CHECK ); - - m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_GAP_CMD, wxEmptyString, - KiScaledBitmap( mw_add_gap_xpm, this ), - _( "Create gap of specified length for microwave applications" ), - wxITEM_CHECK ); + m_microWaveToolBar->Add( PCB_ACTIONS::microwaveCreateLine, ACTION_TOOLBAR::TOGGLE ); + m_microWaveToolBar->Add( PCB_ACTIONS::microwaveCreateGap, ACTION_TOOLBAR::TOGGLE ); KiScaledSeparator( m_microWaveToolBar, this ); - - m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_STUB_CMD, wxEmptyString, - KiScaledBitmap( mw_add_stub_xpm, this ), - _( "Create stub of specified length for microwave applications" ), - wxITEM_CHECK ); - - m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD, wxEmptyString, - KiScaledBitmap( mw_add_stub_arc_xpm, this ), - _( "Create stub (arc) of specified length for microwave applications" ), - wxITEM_CHECK ); - - m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_FUNCTION_SHAPE_CMD, wxEmptyString, - KiScaledBitmap( mw_add_shape_xpm, this ), - _( "Create a polynomial shape for microwave applications" ), - wxITEM_CHECK ); + m_microWaveToolBar->Add( PCB_ACTIONS::microwaveCreateStub, ACTION_TOOLBAR::TOGGLE ); + m_microWaveToolBar->Add( PCB_ACTIONS::microwaveCreateStubArc, ACTION_TOOLBAR::TOGGLE ); + m_microWaveToolBar->Add( PCB_ACTIONS::microwaveCreateFunctionShape, ACTION_TOOLBAR::TOGGLE ); m_microWaveToolBar->Realize(); } @@ -684,15 +665,10 @@ bool PCB_EDIT_FRAME::MicrowaveToolbarShown() } -void PCB_EDIT_FRAME::OnUpdateMuWaveToolbar( wxUpdateUIEvent& aEvent ) -{ - if( aEvent.GetEventObject() == m_microWaveToolBar ) - aEvent.Check( GetToolId() == aEvent.GetId() ); -} - - void PCB_EDIT_FRAME::SyncToolbars() { +#define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) ) + PCB_DISPLAY_OPTIONS* opts = (PCB_DISPLAY_OPTIONS*) GetDisplayOptions(); KIGFX::GAL_DISPLAY_OPTIONS& galOpts = GetGalDisplayOptions(); int zoneMode = opts->m_DisplayZonesMode; @@ -700,7 +676,7 @@ void PCB_EDIT_FRAME::SyncToolbars() m_mainToolBar->Toggle( ACTIONS::save, GetScreen() && GetScreen()->IsModify() ); m_mainToolBar->Toggle( ACTIONS::undo, GetScreen() && GetScreen()->GetUndoCommandCount() > 0 ); m_mainToolBar->Toggle( ACTIONS::redo, GetScreen() && GetScreen()->GetRedoCommandCount() > 0 ); - m_mainToolBar->Toggle( ACTIONS::zoomTool, GetToolId() == ID_ZOOM_SELECTION ); + TOGGLE_TOOL( m_mainToolBar, ACTIONS::zoomTool ); #if defined(KICAD_SCRIPTING_WXPYTHON) if( IsWxPythonLoaded() ) { @@ -731,24 +707,31 @@ void PCB_EDIT_FRAME::SyncToolbars() m_optionsToolBar->Toggle( ACTIONS::highContrastMode, opts->m_ContrastModeDisplay ); m_optionsToolBar->Refresh(); - m_drawToolBar->Toggle( PCB_ACTIONS::selectionTool, GetToolId() == ID_NO_TOOL_SELECTED ); - m_drawToolBar->Toggle( PCB_ACTIONS::highlightNetTool, GetToolId() == ID_PCB_HIGHLIGHT_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::localRatsnestTool,GetToolId() == ID_LOCAL_RATSNEST_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::placeModule, GetToolId() == ID_PCB_MODULE_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::routerActivateSingle, GetToolId() == ID_TRACK_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawVia, GetToolId() == ID_PCB_DRAW_VIA_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawZone, GetToolId() == ID_PCB_ZONES_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawZoneKeepout, GetToolId() == ID_PCB_KEEPOUT_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawLine, GetToolId() == ID_PCB_ADD_LINE_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawCircle, GetToolId() == ID_PCB_CIRCLE_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawArc, GetToolId() == ID_PCB_ARC_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawPolygon, GetToolId() == ID_PCB_ADD_POLYGON_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::placeText, GetToolId() == ID_PCB_ADD_TEXT_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::drawDimension, GetToolId() == ID_PCB_DIMENSION_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::placeTarget, GetToolId() == ID_PCB_TARGET_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::deleteTool, GetToolId() == ID_PCB_DELETE_ITEM_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::drillOrigin, GetToolId() == ID_PCB_PLACE_OFFSET_COORD_BUTT ); - m_drawToolBar->Toggle( PCB_ACTIONS::gridSetOrigin, GetToolId() == ID_PCB_PLACE_GRID_COORD_BUTT ); - m_drawToolBar->Toggle( ACTIONS::measureTool, GetToolId() == ID_PCB_MEASUREMENT_TOOL ); + TOGGLE_TOOL( m_drawToolBar, ACTIONS::selectionTool ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::highlightNetTool ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::localRatsnestTool ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placeModule ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::routeSingleTrack ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawVia ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawZone ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawZoneKeepout ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawLine ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawCircle ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawArc ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawPolygon ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placeText ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawDimension ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placeTarget ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::deleteTool ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drillOrigin ); + TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::gridSetOrigin ); + TOGGLE_TOOL( m_drawToolBar, ACTIONS::measureTool ); m_drawToolBar->Refresh(); + + TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateLine ); + TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateGap ); + TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateStub ); + TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateStubArc ); + TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateFunctionShape ); + m_microWaveToolBar->Refresh(); } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index c2097371fa..2c5223eefd 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -137,18 +137,18 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent ) if( m_editModules && !m_frame->GetModel() ) return 0; - BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); - DRAWSEGMENT* line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; + MODULE* module = dynamic_cast( m_frame->GetModel() ); + DRAWSEGMENT* line = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT; + BOARD_COMMIT commit( m_frame ); + SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE ); + OPT startingPoint = NULLOPT; + line->SetFlags( IS_NEW ); - auto startingPoint = boost::make_optional( false, VECTOR2D( 0, 0 ) ); - BOARD_COMMIT commit( m_frame ); - - SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::LINE ); - - m_frame->SetToolID( m_editModules ? ID_MODEDIT_LINE_TOOL : ID_PCB_ADD_LINE_BUTT, - wxCURSOR_PENCIL, _( "Add graphic line" ) ); + if( aEvent.HasPosition() ) + startingPoint = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) ); + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); while( drawSegment( S_SEGMENT, line, startingPoint ) ) @@ -170,12 +170,10 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent ) startingPoint = NULLOPT; } - line = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; + line = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT; line->SetFlags( IS_NEW ); } - m_frame->SetNoToolSelected(); - return 0; } @@ -185,20 +183,21 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent ) if( m_editModules && !m_frame->GetModel() ) return 0; - BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); - DRAWSEGMENT* circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; - BOARD_COMMIT commit( m_frame ); + MODULE* module = dynamic_cast( m_frame->GetModel() ); + DRAWSEGMENT* circle = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT; + BOARD_COMMIT commit( m_frame ); + SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE ); + OPT startingPoint = NULLOPT; circle->SetFlags( IS_NEW ); - SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::CIRCLE ); - - m_frame->SetToolID( m_editModules ? ID_MODEDIT_CIRCLE_TOOL : ID_PCB_CIRCLE_BUTT, - wxCURSOR_PENCIL, _( "Add graphic circle" ) ); + if( aEvent.HasPosition() ) + startingPoint = getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) ); + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); - while( drawSegment( S_CIRCLE, circle ) ) + while( drawSegment( S_CIRCLE, circle, startingPoint ) ) { // This can be reset by some actions (e.g. Save Board), so ensure it stays set. m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); @@ -212,12 +211,11 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent ) commit.Push( _( "Draw a circle" ) ); } - circle = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; + circle = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT; circle->SetFlags( IS_NEW ); + startingPoint = NULLOPT; } - m_frame->SetNoToolSelected(); - return 0; } @@ -227,18 +225,18 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent ) if( m_editModules && !m_frame->GetModel() ) return 0; - BOARD_ITEM_CONTAINER* parent = m_frame->GetModel(); - DRAWSEGMENT* arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; - BOARD_COMMIT commit( m_frame ); - + MODULE* module = dynamic_cast( m_frame->GetModel() ); + DRAWSEGMENT* arc = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT; + BOARD_COMMIT commit( m_frame ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ARC ); + bool immediateMode = aEvent.HasPosition(); arc->SetFlags( IS_NEW ); - m_frame->SetToolID( m_editModules ? ID_MODEDIT_ARC_TOOL : ID_PCB_ARC_BUTT, - wxCURSOR_PENCIL, _( "Add graphic arc" ) ); + m_frame->SetTool( aEvent.GetCommandStr().get() ); + Activate(); - while( drawArc( arc ) ) + while( drawArc( arc, immediateMode ) ) { // This can be reset by some actions (e.g. Save Board), so ensure it stays set. m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); @@ -252,12 +250,11 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent ) commit.Push( _( "Draw an arc" ) ); } - arc = m_editModules ? new EDGE_MODULE( (MODULE*) parent ) : new DRAWSEGMENT; + arc = m_editModules ? new EDGE_MODULE( module ) : new DRAWSEGMENT; arc->SetFlags( IS_NEW ); + immediateMode = false; } - m_frame->SetNoToolSelected(); - return 0; } @@ -278,12 +275,15 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT ); + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); - m_frame->SetToolID( m_editModules ? ID_MODEDIT_TEXT_TOOL : ID_PCB_ADD_TEXT_BUTT, - wxCURSOR_PENCIL, _( "Add text" ) ); bool reselect = false; + // Prime the pump + if( aEvent.HasPosition() ) + m_toolMgr->RunAction( ACTIONS::cursorClick ); + // Main loop: keep receiving events while( TOOL_EVENT* evt = Wait() ) { @@ -309,9 +309,15 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) m_controls->ShowCursor( true ); } else - break; + { + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + { + m_frame->ClearToolStack(); + break; + } + } - if( evt->IsActivate() ) // now finish unconditionally + if( evt->IsActivate() ) break; } else if( evt->IsClick( BUT_RIGHT ) ) @@ -432,8 +438,6 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) } frame()->SetMsgPanel( board() ); - frame()->SetNoToolSelected(); - return 0; } @@ -467,8 +471,8 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION ); + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); - m_frame->SetToolID( ID_PCB_DIMENSION_BUTT, wxCURSOR_PENCIL, _( "Add dimension" ) ); enum DIMENSION_STEPS { @@ -479,6 +483,10 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) }; int step = SET_ORIGIN; + // Prime the pump + if( aEvent.HasPosition() ) + m_toolMgr->RunAction( ACTIONS::cursorClick ); + // Main loop: keep receiving events while( TOOL_EVENT* evt = Wait() ) { @@ -502,9 +510,15 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) step = SET_ORIGIN; } else - break; + { + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + { + m_frame->ClearToolStack(); + break; + } + } - if( evt->IsActivate() ) // now finish unconditionally + if( evt->IsActivate() ) break; } else if( evt->IsAction( &PCB_ACTIONS::incWidth ) && step != SET_ORIGIN ) @@ -636,66 +650,10 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) m_view->Remove( &preview ); frame()->SetMsgPanel( board() ); - m_frame->SetNoToolSelected(); - return 0; } -int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent ) -{ - SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE ); - - m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add zones" ) ); - - return drawZone( false, ZONE_MODE::ADD ); -} - - -int DRAWING_TOOL::DrawZoneKeepout( const TOOL_EVENT& aEvent ) -{ - SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::KEEPOUT ); - - m_frame->SetToolID( ID_PCB_KEEPOUT_BUTT, wxCURSOR_PENCIL, _( "Add keepout" ) ); - - return drawZone( true, ZONE_MODE::ADD ); -} - - -int DRAWING_TOOL::DrawZoneCutout( const TOOL_EVENT& aEvent ) -{ - SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE ); - - m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add zone cutout" ) ); - - return drawZone( false, ZONE_MODE::CUTOUT ); -} - - -int DRAWING_TOOL::DrawGraphicPolygon( const TOOL_EVENT& aEvent ) -{ - if( m_editModules && !m_frame->GetModel() ) - return 0; - - SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::GRAPHIC_POLYGON ); - - m_frame->SetToolID( m_editModules ? ID_MODEDIT_POLYGON_TOOL : ID_PCB_ADD_POLYGON_BUTT, - wxCURSOR_PENCIL, _( "Add graphic polygon" ) ); - - return drawZone( false, ZONE_MODE::GRAPHIC_POLYGON ); -} - - -int DRAWING_TOOL::DrawSimilarZone( const TOOL_EVENT& aEvent ) -{ - SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ZONE ); - - m_frame->SetToolID( ID_PCB_ZONES_BUTT, wxCURSOR_PENCIL, _( "Add similar zone" ) ); - - return drawZone( false, ZONE_MODE::SIMILAR ); -} - - int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent ) { if( !m_frame->GetModel() ) @@ -718,7 +676,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent ) return 0; } - m_frame->SetNoToolSelected(); + m_frame->ClearToolStack(); // Add a VIEW_GROUP that serves as a preview for the new item PCBNEW_SELECTION preview; @@ -767,6 +725,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent ) m_view->Update( &preview ); + m_frame->PushTool( aEvent.GetCommandStr().get() ); Activate(); // Main loop: keep receiving events @@ -826,7 +785,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent ) preview.Clear(); m_view->Remove( &preview ); - + m_frame->PopTool(); return 0; } @@ -840,8 +799,8 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR ); + m_frame->PushTool( aEvent.GetCommandStr().get() ); Activate(); - m_frame->SetToolID( ID_MODEDIT_ANCHOR_TOOL, wxCURSOR_PENCIL, _( "Place the footprint anchor" ) ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); @@ -878,8 +837,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) break; } - m_frame->SetNoToolSelected(); - + m_frame->PopTool(); return 0; } @@ -905,27 +863,9 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, OPTGetScreen()->m_LocalOrigin != VECTOR2D( 0, 0 ) ); VECTOR2I cursorPos = m_controls->GetMousePosition(); + // Prime the pump if( aStartingPoint ) - { - // Init the new item attributes - aGraphic->SetShape( (STROKE_T) aShape ); - aGraphic->SetWidth( m_lineWidth ); - aGraphic->SetLayer( getDrawingLayer() ); - aGraphic->SetStart( (wxPoint) aStartingPoint.get() ); - - cursorPos = grid.BestSnapAnchor( cursorPos, aGraphic ); - m_controls->ForceCursorPosition( true, cursorPos ); - aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); - - preview.Add( aGraphic ); - m_controls->SetAutoPan( true ); - m_controls->CaptureCursor( true ); - - if( !isLocalOriginSet ) - m_frame->GetScreen()->m_LocalOrigin = aStartingPoint.get(); - - started = true; - } + m_toolMgr->RunAction( ACTIONS::cursorClick ); // Main loop: keep receiving events while( TOOL_EVENT* evt = Wait() ) @@ -963,13 +903,20 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, OPTIsActivate() ) { - preview.Clear(); - m_view->Update( &preview ); - delete aGraphic; - aGraphic = nullptr; + if( started ) + { + preview.Clear(); + m_view->Update( &preview ); + delete aGraphic; + aGraphic = nullptr; - if( !isLocalOriginSet ) - m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 ); + if( !isLocalOriginSet ) + m_frame->GetScreen()->m_LocalOrigin = VECTOR2D( 0, 0 ); + } + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + { + m_frame->ClearToolStack(); + } break; } @@ -989,6 +936,12 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, OPTRunAction( PCB_ACTIONS::selectionClear, true ); @@ -1137,10 +1090,12 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic ) m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); - Activate(); - bool firstPoint = false; + // Prime the pump + if( aImmediateMode ) + m_toolMgr->RunAction( ACTIONS::cursorClick ); + // Main loop: keep receiving events while( TOOL_EVENT* evt = Wait() ) { @@ -1187,9 +1142,17 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic ) } else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) { - preview.Clear(); - delete aGraphic; - aGraphic = nullptr; + if( firstPoint ) + { + preview.Clear(); + delete aGraphic; + aGraphic = nullptr; + } + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + { + m_frame->ClearToolStack(); + } + break; } else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) ) @@ -1233,7 +1196,7 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic ) m_view->Update( &preview ); m_view->Update( &arcAsst ); - if(firstPoint) + if( firstPoint ) frame()->SetMsgPanel( aGraphic ); else frame()->SetMsgPanel( board() ); @@ -1286,28 +1249,39 @@ bool DRAWING_TOOL::getSourceZoneForAction( ZONE_MODE aMode, ZONE_CONTAINER*& aZo return true; } -int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode ) +int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent ) { + ZONE_MODE zoneMode = aEvent.Parameter(); + MODE drawMode = MODE::ZONE; + + if( aEvent.IsAction( &PCB_ACTIONS::drawZoneKeepout ) ) + drawMode = MODE::KEEPOUT; + + if( aEvent.IsAction( &PCB_ACTIONS::drawPolygon ) ) + drawMode = MODE::GRAPHIC_POLYGON; + + SCOPED_DRAW_MODE scopedDrawMode( m_mode, drawMode ); + // get a source zone, if we need one. We need it for: // ZONE_MODE::CUTOUT (adding a hole to the source zone) // ZONE_MODE::SIMILAR (creating a new zone using settings of source zone ZONE_CONTAINER* sourceZone = nullptr; - if( !getSourceZoneForAction( aMode, sourceZone ) ) + if( !getSourceZoneForAction( zoneMode, sourceZone ) ) { - m_frame->SetNoToolSelected(); + m_frame->ClearToolStack(); return 0; } ZONE_CREATE_HELPER::PARAMS params; - params.m_keepout = aKeepout; - params.m_mode = aMode; + params.m_keepout = drawMode == MODE::KEEPOUT; + params.m_mode = zoneMode; params.m_sourceZone = sourceZone; - if( aMode == ZONE_MODE::GRAPHIC_POLYGON ) + if( zoneMode == ZONE_MODE::GRAPHIC_POLYGON ) params.m_layer = getDrawingLayer(); - else if( aMode == ZONE_MODE::SIMILAR ) + else if( zoneMode == ZONE_MODE::SIMILAR ) params.m_layer = sourceZone->GetLayer(); else params.m_layer = m_frame->GetActiveLayer(); @@ -1318,6 +1292,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode ) // hands the calculated points over to the zone creator tool POLYGON_GEOM_MANAGER polyGeomMgr( zoneTool ); + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); // register for events m_controls->ShowCursor( true ); @@ -1329,6 +1304,11 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode ) status.SetTextColor( wxColour( 255, 0, 0 ) ); status.SetText( _( "Self-intersecting polygons are not allowed" ) ); + // Prime the pump + if( aEvent.HasPosition() ) + m_toolMgr->RunAction( ACTIONS::cursorClick ); + + // Main loop: keep receiving events while( TOOL_EVENT* evt = Wait() ) { // This can be reset by some actions (e.g. Save Board), so ensure it stays set. @@ -1342,25 +1322,30 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode ) if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) { - // pre-empted by another tool, give up - // cancelled without an inprogress polygon, give up - if( !polyGeomMgr.IsPolygonInProgress() || evt->IsActivate() ) + if( polyGeomMgr.IsPolygonInProgress() ) { + polyGeomMgr.Reset(); + // start again + started = false; + + m_controls->SetAutoPan( false ); + m_controls->CaptureCursor( false ); + } + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + { + m_frame->ClearToolStack(); break; } - polyGeomMgr.Reset(); - // start again - started = false; - - m_controls->SetAutoPan( false ); - m_controls->CaptureCursor( false ); + // pre-empted by another tool, give up + if( evt->IsActivate() ) + break; } else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) ) { - if( aMode == ZONE_MODE::GRAPHIC_POLYGON ) + if( zoneMode == ZONE_MODE::GRAPHIC_POLYGON ) params.m_layer = getDrawingLayer(); - else if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::CUTOUT ) + else if( zoneMode == ZONE_MODE::ADD || zoneMode == ZONE_MODE::CUTOUT ) params.m_layer = frame()->GetActiveLayer(); } else if( evt->IsClick( BUT_RIGHT ) ) @@ -1435,9 +1420,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode ) } // end while m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - m_frame->SetNoToolSelected(); m_controls->ForceCursorPosition( false ); - return 0; } @@ -1719,36 +1702,15 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) VIA_PLACER placer( frame() ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::VIA ); - - frame()->SetToolID( ID_PCB_DRAW_VIA_BUTT, wxCURSOR_PENCIL, _( "Add vias" ) ); + frame()->SetTool( aEvent.GetCommandStr().get() ); doInteractiveItemPlacement( &placer, _( "Place via" ), - IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP ); - - frame()->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); + IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP ); return 0; } -void DRAWING_TOOL::setTransitions() -{ - Go( &DRAWING_TOOL::DrawLine, PCB_ACTIONS::drawLine.MakeEvent() ); - Go( &DRAWING_TOOL::DrawGraphicPolygon, PCB_ACTIONS::drawPolygon.MakeEvent() ); - Go( &DRAWING_TOOL::DrawCircle, PCB_ACTIONS::drawCircle.MakeEvent() ); - Go( &DRAWING_TOOL::DrawArc, PCB_ACTIONS::drawArc.MakeEvent() ); - Go( &DRAWING_TOOL::DrawDimension, PCB_ACTIONS::drawDimension.MakeEvent() ); - Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawZone.MakeEvent() ); - Go( &DRAWING_TOOL::DrawZoneKeepout, PCB_ACTIONS::drawZoneKeepout.MakeEvent() ); - Go( &DRAWING_TOOL::DrawZoneCutout, PCB_ACTIONS::drawZoneCutout.MakeEvent() ); - Go( &DRAWING_TOOL::DrawSimilarZone, PCB_ACTIONS::drawSimilarZone.MakeEvent() ); - Go( &DRAWING_TOOL::DrawVia, PCB_ACTIONS::drawVia.MakeEvent() ); - Go( &DRAWING_TOOL::PlaceText, PCB_ACTIONS::placeText.MakeEvent() ); - Go( &DRAWING_TOOL::PlaceImportedGraphics, PCB_ACTIONS::placeImportedGraphics.MakeEvent() ); - Go( &DRAWING_TOOL::SetAnchor, PCB_ACTIONS::setAnchor.MakeEvent() ); -} - - int DRAWING_TOOL::getSegmentWidth( PCB_LAYER_ID aLayer ) const { assert( m_board ); @@ -1778,3 +1740,21 @@ PCB_LAYER_ID DRAWING_TOOL::getDrawingLayer() const const unsigned int DRAWING_TOOL::WIDTH_STEP = Millimeter2iu( 0.1 ); + + +void DRAWING_TOOL::setTransitions() +{ + Go( &DRAWING_TOOL::DrawLine, PCB_ACTIONS::drawLine.MakeEvent() ); + Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawPolygon.MakeEvent() ); + Go( &DRAWING_TOOL::DrawCircle, PCB_ACTIONS::drawCircle.MakeEvent() ); + Go( &DRAWING_TOOL::DrawArc, PCB_ACTIONS::drawArc.MakeEvent() ); + Go( &DRAWING_TOOL::DrawDimension, PCB_ACTIONS::drawDimension.MakeEvent() ); + Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawZone.MakeEvent() ); + Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawZoneKeepout.MakeEvent() ); + Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawZoneCutout.MakeEvent() ); + Go( &DRAWING_TOOL::DrawZone, PCB_ACTIONS::drawSimilarZone.MakeEvent() ); + Go( &DRAWING_TOOL::DrawVia, PCB_ACTIONS::drawVia.MakeEvent() ); + Go( &DRAWING_TOOL::PlaceText, PCB_ACTIONS::placeText.MakeEvent() ); + Go( &DRAWING_TOOL::PlaceImportedGraphics, PCB_ACTIONS::placeImportedGraphics.MakeEvent() ); + Go( &DRAWING_TOOL::SetAnchor, PCB_ACTIONS::setAnchor.MakeEvent() ); +} diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 3c8222b37b..a8a2e97874 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -25,10 +25,10 @@ #ifndef __DRAWING_TOOL_H #define __DRAWING_TOOL_H -#include #include - #include +#include +#include namespace KIGFX { @@ -128,39 +128,16 @@ public: * is displayed. After confirmation it allows the user to set points that are going to be used * as a boundary polygon of the zone. Double click or clicking on the origin of the boundary * polyline finishes the drawing. + * + * The event parameter indicates which type of zone to draw: + * ADD add a new zone/keepout with fresh settings + * CUTOUT add a cutout to an existing zone + * SIMILAR add a new zone with the same settings as an existing one */ - int DrawZone( const TOOL_EVENT& aEvent ); - int DrawGraphicPolygon( const TOOL_EVENT& aEvent ); + int DrawZone( const TOOL_EVENT& aEvent ); int DrawVia( const TOOL_EVENT& aEvent ); - /** - * Function DrawZoneKeepout() - * Starts interactively drawing a keepout area. After invoking the function an area settings - * dialog is displayed. After confirmation it allows the user to set points that are going to - * be used as a boundary polygon of the area. Double click or clicking on the origin of the - * boundary polyline finishes the drawing. - */ - int DrawZoneKeepout( const TOOL_EVENT& aEvent ); - - /** - * Function DrawZoneCutout() - * Starts interactively drawing a zone cutout area of an existing zone. - * The normal zone interactive tool is used, but the zone settings - * dialog is not shown (since the cutout affects only shape of an - * existing zone). - */ - int DrawZoneCutout( const TOOL_EVENT& aEvent ); - - /** - * Function DrawSimilarZone() - * Starts interactively drawing a zone with same settings as - * an existing zone. - * The normal zone interactive tool is used, but the zone settings - * dialog is not shown at the start. - */ - int DrawSimilarZone( const TOOL_EVENT& aEvent ); - /** * Function PlaceImportedGraphics() * Places a drawing imported from a DXF or SVG file in module editor. @@ -178,14 +155,6 @@ public: private: - enum class ZONE_MODE - { - ADD, ///< Add a new zone/keepout with fresh settings - CUTOUT, ///< Make a cutout to an existing zone - SIMILAR, ///< Add a new zone with the same settings as an existing one - GRAPHIC_POLYGON - }; - ///> Starts drawing a selected shape (i.e. DRAWSEGMENT). ///> @param aShape is the type of created shape (@see STROKE_T). ///> @param aGraphic is an object that is going to be used by the tool for drawing. It has to @@ -195,15 +164,14 @@ private: ///> and its settings (width, layer) set to the current default values. ///> @return False if the tool was cancelled before the origin was set or origin and end are ///> the same point. - bool drawSegment( int aShape, DRAWSEGMENT*& aGraphic, - OPT aStartingPoint = NULLOPT ); + bool drawSegment( int aShape, DRAWSEGMENT*& aGraphic, OPT aStartingPoint ); ///> Starts drawing an arc. ///> @param aGraphic is an object that is going to be used by the tool for drawing. It has to ///> be already created. The tool deletes the object if it is not added to a BOARD. ///> @return False if the tool was cancelled before the origin was set or origin and end are ///> the same point. - bool drawArc( DRAWSEGMENT*& aGraphic ); + bool drawArc( DRAWSEGMENT*& aGraphic, bool aImmediateMode ); /** * Draws a polygon, that is added as a zone or a keepout area. @@ -215,7 +183,6 @@ private: * CUTOUT add a cutout to an existing zone * SIMILAR add a new zone with the same settings as an existing one */ - int drawZone( bool aKeepout, ZONE_MODE aMode ); /** * Function getSourceZoneForAction() diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 27a2c44ae0..64e1315a2f 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2013-2017 CERN * @author Maciej Suminski * @author Tomasz Wlostowski - * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2019 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -137,7 +137,7 @@ bool EDIT_TOOL::Init() && SELECTION_CONDITIONS::Count( 1 ); auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) { - return ( frame()->GetToolId() == ID_NO_TOOL_SELECTED ); + return frame()->ToolStackIsEmpty(); }; // Add context menu entries that are displayed when selection tool is active @@ -183,7 +183,7 @@ bool EDIT_TOOL::Init() // Populate the context menu displayed during the edit tool (primarily the measure tool) auto activeToolCondition = [ this ] ( const SELECTION& aSel ) { - return ( frame()->GetToolId() != ID_NO_TOOL_SELECTED ); + return frame()->ToolStackIsEmpty(); }; auto frame = getEditFrame(); @@ -1104,10 +1104,9 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) auto& view = *getView(); auto& controls = *getViewControls(); - int toolID = EditingModules() ? ID_MODEDIT_MEASUREMENT_TOOL : ID_PCB_MEASUREMENT_TOOL; + frame()->SetTool( aEvent.GetCommandStr().get() ); Activate(); - frame()->SetToolID( toolID, wxCURSOR_PENCIL, _( "Measure distance" ) ); EDA_UNITS_T units = frame()->GetUserUnits(); KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr; @@ -1136,7 +1135,21 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) { - break; + if( originSet ) + { + view.SetVisible( &ruler, false ); + controls.SetAutoPan( false ); + controls.CaptureCursor( false ); + originSet = false; + } + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + { + frame()->ClearToolStack(); + break; + } + + if( evt->IsActivate() ) + break; } // click or drag starts @@ -1190,8 +1203,6 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) view.SetVisible( &ruler, false ); view.Remove( &ruler ); - frame()->SetNoToolSelected(); - return 0; } diff --git a/pcbnew/tools/footprint_editor_tools.cpp b/pcbnew/tools/footprint_editor_tools.cpp index a67a256f9d..6308022512 100644 --- a/pcbnew/tools/footprint_editor_tools.cpp +++ b/pcbnew/tools/footprint_editor_tools.cpp @@ -313,13 +313,10 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent ) PAD_PLACER placer; - m_frame->SetToolID( ID_MODEDIT_PAD_TOOL, wxCURSOR_PENCIL, _( "Add pads" ) ); + frame()->SetTool( aEvent.GetCommandStr().get() ); - wxASSERT( board()->GetFirstModule() ); - - doInteractiveItemPlacement( &placer, _( "Place pad" ), IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP ); - - m_frame->SetNoToolSelected(); + doInteractiveItemPlacement( &placer, _( "Place pad" ), + IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP ); return 0; } diff --git a/pcbnew/tools/microwave_tool.cpp b/pcbnew/tools/microwave_tool.cpp index 1a139304c2..ea5e809ba6 100644 --- a/pcbnew/tools/microwave_tool.cpp +++ b/pcbnew/tools/microwave_tool.cpp @@ -56,93 +56,52 @@ void MICROWAVE_TOOL::Reset( RESET_REASON aReason ) } -struct MICROWAVE_TOOL_INFO +int MICROWAVE_TOOL::addMicrowaveFootprint( const TOOL_EVENT& aEvent ) { - using MOD_CREATOR = std::function()>; + auto& frame = *getEditFrame(); - wxString name; - int toolId; - MOD_CREATOR creatorFunc; -}; + std::function()> creator; - -MICROWAVE_TOOL_INFO getMicrowaveItemCreator( PCB_EDIT_FRAME& frame, int aParam ) -{ - MICROWAVE_TOOL_INFO info; - - switch( aParam ) + switch( aEvent.Parameter() ) { case MWAVE_TOOL_SIMPLE_ID::GAP: - info.name = _( "Add Gap" ); - info.toolId = ID_PCB_MUWAVE_TOOL_GAP_CMD; - info.creatorFunc = [&frame] () { + creator = [&frame] () { return std::unique_ptr( frame.Create_MuWaveComponent( 0 ) ); }; break; case MWAVE_TOOL_SIMPLE_ID::STUB: - info.name = _( "Add Stub" ); - info.toolId = ID_PCB_MUWAVE_TOOL_STUB_CMD; - info.creatorFunc = [&frame] () { + creator = [&frame] () { return std::unique_ptr( frame.Create_MuWaveComponent( 1 ) ); }; break; case MWAVE_TOOL_SIMPLE_ID::STUB_ARC: - info.name = _( "Add Stub (Arc)" ); - info.toolId = ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD; - info.creatorFunc = [&frame] () { + creator = [&frame] () { return std::unique_ptr( frame.Create_MuWaveComponent( 2 ) ); }; break; case MWAVE_TOOL_SIMPLE_ID::FUNCTION_SHAPE: - info.name = _( "Add Polynomial Shape" ); - info.toolId = ID_PCB_MUWAVE_TOOL_FUNCTION_SHAPE_CMD; - info.creatorFunc = [&frame] () { + creator = [&frame] () { return std::unique_ptr( frame.Create_MuWavePolygonShape() ); }; break; default: - // Avoid uninitilized value: - info.toolId = 0; - // info.name is already set to empty string break; }; - return info; -} - - -int MICROWAVE_TOOL::addMicrowaveFootprint( const TOOL_EVENT& aEvent ) -{ - auto& frame = *getEditFrame(); - - const int param = aEvent.Parameter(); - - MICROWAVE_TOOL_INFO info = getMicrowaveItemCreator( frame, param ); - - // failed to find suitable item info - shouldn't be possible - // if all the id's are handled - if( !info.name ) - { - wxASSERT_MSG( 0, "Failed to find suitable microwave tool info" ); - return 0; - } - - frame.SetToolID( info.toolId, wxCURSOR_PENCIL, info.name ); - struct MICROWAVE_PLACER : public INTERACTIVE_PLACER_BASE { - MICROWAVE_TOOL_INFO& m_info; + const std::function()>& m_creator; - MICROWAVE_PLACER( MICROWAVE_TOOL_INFO& aInfo ) : - m_info( aInfo ) {}; + MICROWAVE_PLACER( const std::function()>& aCreator ) : + m_creator( aCreator ) {}; std::unique_ptr CreateItem() override { - auto module = m_info.creatorFunc(); + auto module = m_creator(); // Module has been added in the legacy backend, // so we have to remove it before committing the change @@ -156,13 +115,13 @@ int MICROWAVE_TOOL::addMicrowaveFootprint( const TOOL_EVENT& aEvent ) } }; - MICROWAVE_PLACER placer ( info ); + MICROWAVE_PLACER placer( creator ); + + frame.SetTool( aEvent.GetCommandStr().get() ); doInteractiveItemPlacement( &placer, _( "Place microwave feature" ), IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP | IPO_PROPERTIES ); - frame.SetNoToolSelected(); - return 0; } @@ -196,9 +155,7 @@ void MICROWAVE_TOOL::createInductorBetween( const VECTOR2I& aStart, const VECTOR if ( !inductorModule || !errorMessage.IsEmpty() ) { if ( !errorMessage.IsEmpty() ) - { DisplayError( &frame, errorMessage ); - } } else { @@ -229,8 +186,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent ) KIGFX::VIEW_CONTROLS& controls = *getViewControls(); auto& frame = *getEditFrame(); - frame.SetToolID( ID_PCB_MUWAVE_TOOL_SELF_CMD, wxCURSOR_PENCIL, _( "Add Microwave Inductor" ) ); - + frame.SetTool( aEvent.GetCommandStr().get() ); Activate(); TWO_POINT_GEOMETRY_MANAGER tpGeomMgr; @@ -256,21 +212,25 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent ) if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) { - // overriding action, or we're cancelling without - // an in-progress preview area - if ( evt->IsActivate() || !originSet ) + if( originSet ) { + // had an in-progress area, so start again but don't + // cancel the tool + originSet = false; + controls.CaptureCursor( false ); + controls.SetAutoPan( false ); + + view.SetVisible( &previewRect, false ); + view.Update( &previewRect, KIGFX::GEOMETRY ); + } + else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + { + frame.ClearToolStack(); break; } - // had an in-progress area, so start again but don't - // cancel the tool - originSet = false; - controls.CaptureCursor( false ); - controls.SetAutoPan( false ); - - view.SetVisible( &previewRect, false ); - view.Update( &previewRect, KIGFX::GEOMETRY ); + if( evt->IsActivate() ) + break; } // A click or drag starts @@ -287,8 +247,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent ) // another click after origin set is the end // left up is also the end, as you'll only get that after a drag - else if( originSet && - ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) ) + else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) ) { // second click, we're done: // delegate to the point-to-point inductor creator function @@ -305,8 +264,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent ) // any move or drag once the origin was set updates // the end point - else if( originSet && - ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) ) + else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) ) { tpGeomMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) ); tpGeomMgr.SetEnd( cursorPos ); @@ -325,8 +283,6 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent ) controls.SetAutoPan( false ); view.Remove( &previewRect ); - frame.SetNoToolSelected(); - return 0; } diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index e3f622c7ed..71700bee3d 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -149,9 +149,9 @@ bool PAD_TOOL::haveFootprints() bool PAD_TOOL::Init() { - auto contextMenu = std::make_shared( EditingModules(), - [this]() { return m_padCopied; } ); - contextMenu->SetTool( this ); + auto ctxMenu = std::make_shared( EditingModules(), + [this]() { return m_padCopied; } ); + ctxMenu->SetTool( this ); SELECTION_TOOL* selTool = m_toolMgr->GetTool(); @@ -160,21 +160,18 @@ bool PAD_TOOL::Init() auto& toolMenu = selTool->GetToolMenu(); auto& menu = toolMenu.GetMenu(); - toolMenu.AddSubMenu( contextMenu ); + toolMenu.AddSubMenu( ctxMenu ); - auto canShowMenuCond = [this, contextMenu] ( const SELECTION& aSel ) { - contextMenu->UpdateAll(); - return frame()->GetToolId() == ID_NO_TOOL_SELECTED - && haveFootprints() - && contextMenu->HasEnabledItems(); + auto canShowMenuCond = [this, ctxMenu] ( const SELECTION& aSel ) { + ctxMenu->UpdateAll(); + return frame()->ToolStackIsEmpty() && haveFootprints() && ctxMenu->HasEnabledItems(); }; // show menu when there is a footprint, and the menu has any items auto showCond = canShowMenuCond && - ( SELECTION_CONDITIONS::HasType( PCB_PAD_T ) - || SELECTION_CONDITIONS::Count( 0 ) ); + ( SELECTION_CONDITIONS::HasType( PCB_PAD_T ) || SELECTION_CONDITIONS::Count( 0 ) ); - menu.AddMenu( contextMenu.get(), showCond, 1000 ); + menu.AddMenu( ctxMenu.get(), showCond, 1000 ); // we need a separator only when the selection is empty auto separatorCond = canShowMenuCond && SELECTION_CONDITIONS::Count( 0 ); @@ -331,6 +328,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) if( settingsDlg.ShowModal() != wxID_OK ) return 0; + frame()->PushTool( aEvent.GetCommandStr().get() ); Activate(); GENERAL_COLLECTOR collector; @@ -347,9 +345,6 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) wxString padPrefix = settingsDlg.GetPrefix(); std::deque storedPadNumbers; - frame()->SetToolID( ID_MODEDIT_PAD_TOOL, wxCURSOR_HAND, - _( "Click on successive pads to renumber them" ) ); - m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); getViewControls()->ShowCursor( true ); @@ -435,9 +430,11 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) else newval = seqPadNum; - statusPopup.SetText( wxString::Format( - _( "Click on pad %s%d\nPress Escape to cancel or double-click to commit" ), - padPrefix.c_str(), newval ) ); + statusPopup.SetText( wxString::Format( _( "Click on pad %s%d\n" + "Press Escape to cancel or " + "double-click to commit" ), + padPrefix.c_str(), + newval ) ); } // ..or restore the old name if it was enumerated and clicked again @@ -452,9 +449,11 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) pad->SetName( it->second.second ); oldNames.erase( it ); - statusPopup.SetText( wxString::Format( - _( "Click on pad %s%d\nPress Escape to cancel or double-click to commit" ), - padPrefix.c_str(), storedPadNumbers.front() ) ); + statusPopup.SetText( wxString::Format( _( "Click on pad %s%d\n" + "Press Escape to cancel or " + "double-click to commit" ), + padPrefix.c_str(), + storedPadNumbers.front() ) ); } pad->ClearSelected(); @@ -470,8 +469,8 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) break; } - // This is a cancel-current-action (ie: ). - // Note that this must go before IsCancelInteractive() as it also checks IsCancel(). + // This is a cancel-current-action (ie: ). + // Note that this must go before IsCancelInteractive() as it also checks IsCancel(). else if( evt->IsCancel() ) { // Clear current selection list to avoid selection of deleted items @@ -481,7 +480,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) break; } - // Now that cancel-current-action has been handled, check for cancel-tool. + // Now that cancel-current-action has been handled, check for cancel-tool. else if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) { commit.Push( _( "Renumber pads" ) ); @@ -506,9 +505,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) } statusPopup.Hide(); - frame()->SetNoToolSelected(); - frame()->GetCanvas()->SetCursor( wxCURSOR_ARROW ); - + frame()->PopTool(); return 0; } diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index c552884a76..0b14cf44c1 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -29,7 +29,7 @@ #include #include #include - +#include OPT PCB_ACTIONS::TranslateLegacyId( int aId ) { @@ -37,24 +37,6 @@ OPT PCB_ACTIONS::TranslateLegacyId( int aId ) { case ID_GEN_IMPORT_GRAPHICS_FILE: return PCB_ACTIONS::placeImportedGraphics.MakeEvent(); - - case ID_NO_TOOL_SELECTED: - return PCB_ACTIONS::selectionTool.MakeEvent(); - - case ID_PCB_MUWAVE_TOOL_GAP_CMD: - return PCB_ACTIONS::microwaveCreateGap.MakeEvent(); - - case ID_PCB_MUWAVE_TOOL_STUB_CMD: - return PCB_ACTIONS::microwaveCreateStub.MakeEvent(); - - case ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD: - return PCB_ACTIONS::microwaveCreateStubArc.MakeEvent(); - - case ID_PCB_MUWAVE_TOOL_FUNCTION_SHAPE_CMD: - return PCB_ACTIONS::microwaveCreateFunctionShape.MakeEvent(); - - case ID_PCB_MUWAVE_TOOL_SELF_CMD: - return PCB_ACTIONS::microwaveCreateLine.MakeEvent(); } return OPT(); @@ -81,7 +63,7 @@ TOOL_ACTION PCB_ACTIONS::drawPolygon( "pcbnew.InteractiveDrawing.graphicPolygon" AS_GLOBAL, MD_SHIFT + MD_CTRL + 'P', LEGACY_HK_NAME( "Draw Graphic Polygon" ), _( "Draw Graphic Polygon" ), _( "Draw a graphic polygon" ), - add_graphical_polygon_xpm, AF_ACTIVATE ); + add_graphical_polygon_xpm, AF_ACTIVATE, (void*) ZONE_MODE::GRAPHIC_POLYGON ); TOOL_ACTION PCB_ACTIONS::drawCircle( "pcbnew.InteractiveDrawing.circle", AS_GLOBAL, @@ -116,7 +98,7 @@ TOOL_ACTION PCB_ACTIONS::drawZone( "pcbnew.InteractiveDrawing.zone", #endif LEGACY_HK_NAME( "Add Filled Zone" ), _( "Add Filled Zone" ), _( "Add a filled zone" ), - add_zone_xpm, AF_ACTIVATE ); + add_zone_xpm, AF_ACTIVATE, (void*) ZONE_MODE::ADD ); TOOL_ACTION PCB_ACTIONS::drawVia( "pcbnew.InteractiveDrawing.via", AS_GLOBAL, @@ -128,19 +110,19 @@ TOOL_ACTION PCB_ACTIONS::drawZoneKeepout( "pcbnew.InteractiveDrawing.keepout", AS_GLOBAL, MD_SHIFT + MD_CTRL + 'K', LEGACY_HK_NAME( "Add Keepout Area" ), _( "Add Keepout Area" ), _( "Add a keepout area" ), - add_keepout_area_xpm, AF_ACTIVATE ); + add_keepout_area_xpm, AF_ACTIVATE, (void*) ZONE_MODE::ADD ); TOOL_ACTION PCB_ACTIONS::drawZoneCutout( "pcbnew.InteractiveDrawing.zoneCutout", AS_GLOBAL, MD_SHIFT + 'C', LEGACY_HK_NAME( "Add a Zone Cutout" ), _( "Add a Zone Cutout" ), _( "Add a cutout area of an existing zone" ), - add_zone_cutout_xpm, AF_ACTIVATE ); + add_zone_cutout_xpm, AF_ACTIVATE, (void*) ZONE_MODE::CUTOUT ); TOOL_ACTION PCB_ACTIONS::drawSimilarZone( "pcbnew.InteractiveDrawing.similarZone", AS_GLOBAL, MD_SHIFT + MD_CTRL + '.', LEGACY_HK_NAME( "Add a Similar Zone" ), _( "Add a Similar Zone" ), _( "Add a zone with the same settings as an existing zone" ), - add_zone_xpm, AF_ACTIVATE ); + add_zone_xpm, AF_ACTIVATE, (void*) ZONE_MODE::SIMILAR ); TOOL_ACTION PCB_ACTIONS::placeImportedGraphics( "pcbnew.InteractiveDrawing.placeImportedGraphics", AS_GLOBAL, @@ -924,11 +906,6 @@ TOOL_ACTION PCB_ACTIONS::layerChanged( "pcbnew.Control.layerChanged", nullptr, AF_NOTIFY ); // Miscellaneous -TOOL_ACTION PCB_ACTIONS::selectionTool( "pcbnew.Control.selectionTool", - AS_GLOBAL, 0, "", - _( "Select item(s)" ), "", - cursor_xpm, AF_ACTIVATE ); - TOOL_ACTION PCB_ACTIONS::deleteTool( "pcbnew.Control.deleteTool", AS_GLOBAL, 0, "", _( "Delete Items Tool" ), _( "Click on items to delete them" ), @@ -1127,17 +1104,17 @@ TOOL_ACTION PCB_ACTIONS::autoplaceOffboardComponents( "pcbnew.Autoplacer.autopla // ROUTER_TOOL // -TOOL_ACTION PCB_ACTIONS::routerActivateSingle( "pcbnew.InteractiveRouter.SingleTrack", +TOOL_ACTION PCB_ACTIONS::routeSingleTrack( "pcbnew.InteractiveRouter.SingleTrack", AS_GLOBAL, 'X', LEGACY_HK_NAME( "Add New Track" ), - _( "Interactive Router (Single Tracks)" ), _( "Run push & shove router (single tracks)" ), - add_tracks_xpm, AF_ACTIVATE ); + _( "Route Single Track" ), _( "Run push & shove router (single tracks)" ), + add_tracks_xpm, AF_ACTIVATE, (void*) PNS::PNS_MODE_ROUTE_SINGLE ); -TOOL_ACTION PCB_ACTIONS::routerActivateDiffPair( "pcbnew.InteractiveRouter.DiffPair", +TOOL_ACTION PCB_ACTIONS::routeDiffPair( "pcbnew.InteractiveRouter.DiffPair", AS_GLOBAL, '6', LEGACY_HK_NAME( "Route Differential Pair (Modern Toolset only)" ), - _( "Interactive Router (Differential Pairs)" ), _( "Run push & shove router (differential pairs)" ), - ps_diff_pair_xpm, AF_ACTIVATE ); + _( "Route Differential Pair" ), _( "Run push & shove router (differential pairs)" ), + ps_diff_pair_xpm, AF_ACTIVATE, (void*) PNS::PNS_MODE_ROUTE_DIFF_PAIR ); TOOL_ACTION PCB_ACTIONS::routerSettingsDialog( "pcbnew.InteractiveRouter.SettingsDialog", AS_GLOBAL, @@ -1157,21 +1134,21 @@ TOOL_ACTION PCB_ACTIONS::selectLayerPair( "pcbnew.InteractiveRouter.SelectLayerP TOOL_ACTION PCB_ACTIONS::routerTuneSingleTrace( "pcbnew.LengthTuner.TuneSingleTrack", AS_GLOBAL, - '7', LEGACY_HK_NAME( "Tune Single Track (Modern Toolset only)" ), + '7', LEGACY_HK_NAME( "Tune Single Track" ), _( "Tune length of a single track" ), "", - ps_tune_length_xpm, AF_ACTIVATE ); + ps_tune_length_xpm, AF_ACTIVATE, (void*) PNS::PNS_MODE_TUNE_SINGLE ); TOOL_ACTION PCB_ACTIONS::routerTuneDiffPair( "pcbnew.LengthTuner.TuneDiffPair", AS_GLOBAL, - '8', LEGACY_HK_NAME( "Tune Differential Pair Length (Modern Toolset only)" ), + '8', LEGACY_HK_NAME( "Tune Differential Pair Length" ), _( "Tune length of a differential pair" ), "", - nullptr, AF_ACTIVATE ); + nullptr, AF_ACTIVATE, (void*) PNS::PNS_MODE_TUNE_DIFF_PAIR ); TOOL_ACTION PCB_ACTIONS::routerTuneDiffPairSkew( "pcbnew.LengthTuner.TuneDiffPairSkew", AS_GLOBAL, - '9', LEGACY_HK_NAME( "Tune Differential Pair Skew (Modern Toolset only)" ), + '9', LEGACY_HK_NAME( "Tune Differential Pair Skew" ), _( "Tune skew of a differential pair" ), "", - nullptr, AF_ACTIVATE ); + nullptr, AF_ACTIVATE, (void*) PNS::PNS_MODE_TUNE_DIFF_PAIR_SKEW ); TOOL_ACTION PCB_ACTIONS::routerInlineDrag( "pcbnew.InteractiveRouter.InlineDrag", AS_CONTEXT, 0, "", diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index 83f980f57c..795a0bc61c 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -43,6 +43,16 @@ enum MWAVE_TOOL_SIMPLE_ID FUNCTION_SHAPE, }; + +enum class ZONE_MODE +{ + ADD, ///< Add a new zone/keepout with fresh settings + CUTOUT, ///< Make a cutout to an existing zone + SIMILAR, ///< Add a new zone with the same settings as an existing one + GRAPHIC_POLYGON +}; + + /** * Class PCB_ACTIONS * @@ -170,10 +180,10 @@ public: // Push and Shove Router Tool /// Activation of the Push and Shove router - static TOOL_ACTION routerActivateSingle; + static TOOL_ACTION routeSingleTrack; /// Activation of the Push and Shove router (differential pair mode) - static TOOL_ACTION routerActivateDiffPair; + static TOOL_ACTION routeDiffPair; /// Activation of the Push and Shove router (tune single line mode) static TOOL_ACTION routerTuneSingleTrace; diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 2b9580307e..b295a75a29 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -181,15 +181,15 @@ void PCB_EDITOR_CONTROL::Reset( RESET_REASON aReason ) bool PCB_EDITOR_CONTROL::Init() { auto activeToolCondition = [ this ] ( const SELECTION& aSel ) { - return ( m_frame->GetToolId() != ID_NO_TOOL_SELECTED ); + return ( !m_frame->ToolStackIsEmpty() ); }; auto inactiveStateCondition = [ this ] ( const SELECTION& aSel ) { - return ( m_frame->GetToolId() == ID_NO_TOOL_SELECTED && aSel.Size() == 0 ); + return ( m_frame->ToolStackIsEmpty() && aSel.Size() == 0 ); }; auto placeModuleCondition = [ this ] ( const SELECTION& aSel ) { - return ( m_frame->GetToolId() == ID_PCB_MODULE_BUTT && aSel.GetSize() == 0 ); + return ( m_frame->IsCurrentTool( PCB_ACTIONS::placeModule ) && aSel.GetSize() == 0 ); }; auto& ctxMenu = m_menu.GetMenu(); @@ -518,19 +518,20 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) controls->ShowCursor( true ); controls->SetSnapping( true ); + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); - m_frame->SetToolID( ID_PCB_MODULE_BUTT, wxCURSOR_PENCIL, _( "Add footprint" ) ); - // Add all the drawable parts to preview VECTOR2I cursorPos = controls->GetCursorPosition(); + bool reselect = false; + // Prime the pump if( module ) { module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module ); } - - bool reselect = false; + else if( aEvent.HasPosition() ) + m_toolMgr->RunAction( PCB_ACTIONS::cursorClick ); // Main loop: keep receiving events while( TOOL_EVENT* evt = Wait() ) @@ -550,8 +551,14 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) commit.Revert(); module = NULL; } - else // let's have another chance placing a module - break; + else + { + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + { + m_frame->ClearToolStack(); + break; + } + } if( evt->IsActivate() ) // now finish unconditionally break; @@ -618,7 +625,7 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) controls->CaptureCursor( !!module ); } - m_frame->SetNoToolSelected(); + m_frame->PopTool(); return 0; } @@ -709,8 +716,8 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); controls->SetSnapping( true ); + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); - m_frame->SetToolID( ID_PCB_TARGET_BUTT, wxCURSOR_PENCIL, _( "Add layer alignment target" ) ); // Main loop: keep receiving events while( TOOL_EVENT* evt = Wait() ) @@ -720,7 +727,12 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) cursorPos = controls->GetCursorPosition( !evt->Modifier( MD_ALT ) ); if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) + { + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + m_frame->ClearToolStack(); + break; + } else if( evt->IsAction( &PCB_ACTIONS::incWidth ) ) { @@ -771,9 +783,6 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) controls->SetSnapping( false ); view->Remove( &preview ); - - m_frame->SetNoToolSelected(); - return 0; } @@ -956,7 +965,7 @@ int PCB_EDITOR_CONTROL::CrossProbeSchToPcb( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); // If it is a pad and the net highlighting tool is enabled, highlight the net - if( item->Type() == PCB_PAD_T && m_frame->GetToolId() == ID_PCB_HIGHLIGHT_BUTT ) + if( item->Type() == PCB_PAD_T && m_frame->IsCurrentTool( PCB_ACTIONS::highlightNetTool ) ) { int net = static_cast( item )->GetNetCode(); m_toolMgr->RunAction( PCB_ACTIONS::highlightNet, false, net ); @@ -986,28 +995,25 @@ void PCB_EDITOR_CONTROL::DoSetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* a } -bool PCB_EDITOR_CONTROL::SetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, - BOARD_ITEM* originViewItem, const VECTOR2D& aPosition ) -{ - aFrame->SaveCopyInUndoList( originViewItem, UR_DRILLORIGIN ); - DoSetDrillOrigin( aView, aFrame, originViewItem, aPosition ); - return false; // drill origin is a one-shot; don't continue with tool -} - - int PCB_EDITOR_CONTROL::DrillOrigin( const TOOL_EVENT& aEvent ) { + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); assert( picker ); - m_frame->SetToolID( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxCURSOR_HAND, _( "Adjust zero" ) ); - picker->SetClickHandler( std::bind( SetDrillOrigin, getView(), m_frame, - m_placeOrigin.get(), _1 ) ); + picker->SetClickHandler( [this] ( const VECTOR2D& pt ) -> bool + { + m_frame->SaveCopyInUndoList( m_placeOrigin.get(), UR_DRILLORIGIN ); + DoSetDrillOrigin( getView(), m_frame, m_placeOrigin.get(), pt ); + return false; // drill origin is a one-shot; don't continue with tool + } ); + picker->Activate(); Wait(); + m_frame->ClearToolStack(); return 0; } @@ -1174,19 +1180,27 @@ int PCB_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent ) // there is no selection, then behave like a ctrl-left-click. if( aEvent.IsAction( &PCB_ACTIONS::highlightNetSelection ) ) { - bool use_selection = ( m_frame->GetToolId() != ID_PCB_HIGHLIGHT_BUTT ); + bool use_selection = m_frame->IsCurrentTool( PCB_ACTIONS::highlightNetTool ); highlightNet( getViewControls()->GetMousePosition(), use_selection ); } + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); - assert( picker ); - m_frame->SetToolID( ID_PCB_HIGHLIGHT_BUTT, wxCURSOR_HAND, _( "Highlight net" ) ); - picker->SetClickHandler( [this] ( const VECTOR2D& pt ) -> bool { - return highlightNet( pt, false ); - } ); + picker->SetClickHandler( [this] ( const VECTOR2D& pt ) -> bool + { + highlightNet( pt, false ); + return true; + } ); + + picker->SetFinalizeHandler( [&]( const int& aFinalState ) + { + if( aFinalState == PCBNEW_PICKER_TOOL::EVT_CANCEL ) + m_frame->ClearToolStack(); + } ); + picker->SetLayerSet( LSET::AllCuMask() ); picker->Activate(); Wait(); @@ -1231,9 +1245,7 @@ static bool showLocalRatsnest( TOOL_MANAGER* aToolMgr, BOARD* aBoard, bool aShow bool enable = !( *( mod->Pads().begin() ) )->GetLocalRatsnestVisible(); for( auto modpad : mod->Pads() ) - { modpad->SetLocalRatsnestVisible( enable ); - } } } } @@ -1246,6 +1258,7 @@ static bool showLocalRatsnest( TOOL_MANAGER* aToolMgr, BOARD* aBoard, bool aShow int PCB_EDITOR_CONTROL::LocalRatsnestTool( const TOOL_EVENT& aEvent ) { + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); auto picker = m_toolMgr->GetTool(); @@ -1254,17 +1267,22 @@ int PCB_EDITOR_CONTROL::LocalRatsnestTool( const TOOL_EVENT& aEvent ) wxASSERT( picker ); wxASSERT( board ); - m_frame->SetToolID( ID_LOCAL_RATSNEST_BUTT, wxCURSOR_PENCIL, - _( "Pick Components for Local Ratsnest" ) ); - picker->SetClickHandler( std::bind( - showLocalRatsnest, m_toolMgr, board, opt->m_ShowGlobalRatsnest, _1 ) ); - picker->SetFinalizeHandler( [ board, opt ]( int aCondition ){ - if( aCondition != PCBNEW_PICKER_TOOL::END_ACTIVATE ) + picker->SetClickHandler( std::bind( showLocalRatsnest, m_toolMgr, board, + opt->m_ShowGlobalRatsnest, _1 ) ); + + picker->SetFinalizeHandler( [ this, board, opt ]( int aCondition ) { - for( auto mod : board->Modules() ) - for( auto pad : mod->Pads() ) - pad->SetLocalRatsnestVisible( opt->m_ShowGlobalRatsnest ); - } + if( aCondition != PCBNEW_PICKER_TOOL::END_ACTIVATE ) + { + for( auto mod : board->Modules() ) + { + for( auto pad : mod->Pads() ) + pad->SetLocalRatsnestVisible( opt->m_ShowGlobalRatsnest ); + } + } + + if( aCondition == PCBNEW_PICKER_TOOL::EVT_CANCEL ) + m_frame->ClearToolStack(); } ); picker->Activate(); diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index 3d896dee86..e8cf533849 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -114,10 +114,6 @@ public: ///> Runs the drill origin tool for setting the origin for drill and pick-and-place files. int DrillOrigin( const TOOL_EVENT& aEvent ); - ///> UI-level access (including undo) to setting the drill origin - static bool SetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, - BOARD_ITEM* aItem, const VECTOR2D& aPoint ); - ///> Low-level access (below undo) to setting the drill origin static void DoSetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, BOARD_ITEM* aItem, const VECTOR2D& aPoint ); diff --git a/pcbnew/tools/pcb_tool_base.cpp b/pcbnew/tools/pcb_tool_base.cpp index 5f3cb30983..dce2938924 100644 --- a/pcbnew/tools/pcb_tool_base.cpp +++ b/pcbnew/tools/pcb_tool_base.cpp @@ -86,7 +86,10 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer preview.Clear(); if( aOptions & IPO_SINGLE_CLICK ) + { + frame()->ClearToolStack(); break; + } controls()->SetAutoPan( false ); controls()->CaptureCursor( false ); @@ -94,6 +97,9 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer } else { + if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) + frame()->ClearToolStack(); + break; } diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 7ff1ba71b7..0f5dc4d6b1 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -443,15 +443,6 @@ void PCBNEW_CONTROL::DoSetGridOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame } -bool PCBNEW_CONTROL::SetGridOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, - BOARD_ITEM* originViewItem, const VECTOR2D& aPoint ) -{ - aFrame->SaveCopyInUndoList( originViewItem, UR_GRIDORIGIN ); - DoSetGridOrigin( aView, aFrame, originViewItem, aPoint ); - return false; // Set grid origin is a one-shot; don't keep tool active -} - - int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) { VECTOR2D* origin = aEvent.Parameter(); @@ -465,16 +456,22 @@ int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) } else { + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); - wxCHECK( picker, 0 ); - // 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" ) ); - picker->SetClickHandler( std::bind( SetGridOrigin, getView(), m_frame, m_gridOrigin.get(), _1 ) ); + picker->SetClickHandler( [this] ( const VECTOR2D& pt ) -> bool + { + m_frame->SaveCopyInUndoList( m_gridOrigin.get(), UR_GRIDORIGIN ); + DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), pt ); + return false; // drill origin is a one-shot; don't continue with tool + } ); + picker->Activate(); Wait(); + + m_frame->ClearToolStack(); } return 0; @@ -483,8 +480,8 @@ int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::GridResetOrigin( const TOOL_EVENT& aEvent ) { - SetGridOrigin( getView(), m_frame, m_gridOrigin.get(), VECTOR2D( 0, 0 ) ); - + m_frame->SaveCopyInUndoList( m_gridOrigin.get(), UR_GRIDORIGIN ); + DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), VECTOR2D( 0, 0 ) ); return 0; } @@ -512,14 +509,20 @@ static bool deleteItem( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition ) int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { + m_frame->SetTool( aEvent.GetCommandStr().get() ); Activate(); PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); wxCHECK( picker, 0 ); - m_frame->SetToolID( m_editModules ? ID_MODEDIT_DELETE_TOOL : ID_PCB_DELETE_ITEM_BUTT, - wxCURSOR_BULLSEYE, _( "Delete item" ) ); picker->SetClickHandler( std::bind( deleteItem, m_toolMgr, _1 ) ); + + picker->SetFinalizeHandler( [&]( const int& aFinalState ) + { + if( aFinalState == PCBNEW_PICKER_TOOL::EVT_CANCEL ) + m_frame->ClearToolStack(); + } ); + picker->Activate(); Wait(); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 998ea1e277..b2c9a132b3 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -78,10 +78,6 @@ public: int GridSetOrigin( const TOOL_EVENT& aEvent ); int GridResetOrigin( const TOOL_EVENT& aEvent ); - // UI-level access (including undo) to setting the grid origin - static bool SetGridOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, - BOARD_ITEM* originViewItem, const VECTOR2D& aPoint ); - // Low-level access (below undo) to setting the grid origin static void DoSetGridOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, BOARD_ITEM* originViewItem, const VECTOR2D& aPoint ); diff --git a/pcbnew/tools/pcbnew_picker_tool.cpp b/pcbnew/tools/pcbnew_picker_tool.cpp index be7f329f92..84bcf7e708 100644 --- a/pcbnew/tools/pcbnew_picker_tool.cpp +++ b/pcbnew/tools/pcbnew_picker_tool.cpp @@ -130,8 +130,6 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) reset(); controls->ForceCursorPosition( false ); - getEditFrame()->SetNoToolSelected(); - return 0; } diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 978cdd0773..f6c959ec7d 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -185,6 +185,15 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason ) } +int SELECTION_TOOL::SelectionTool( const TOOL_EVENT& aEvent ) +{ + // Since the selection tool is always running underneath the toolStack, all we need to + // do is clear the stack. + m_frame->ClearToolStack(); + return 0; +} + + int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { // Main loop: keep receiving events @@ -2195,6 +2204,7 @@ void SELECTION_TOOL::setTransitions() Go( &SELECTION_TOOL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() ); Go( &SELECTION_TOOL::Main, PCB_ACTIONS::selectionActivate.MakeEvent() ); + Go( &SELECTION_TOOL::SelectionTool, ACTIONS::selectionTool.MakeEvent() ); Go( &SELECTION_TOOL::CursorSelection, PCB_ACTIONS::selectionCursor.MakeEvent() ); Go( &SELECTION_TOOL::ClearSelection, PCB_ACTIONS::selectionClear.MakeEvent() ); diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 486151f2f5..edd1b4038b 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -79,6 +79,8 @@ public: */ int Main( const TOOL_EVENT& aEvent ); + int SelectionTool( const TOOL_EVENT& aEvent ); + /** * Function GetSelection() * diff --git a/pcbnew/tools/zone_create_helper.cpp b/pcbnew/tools/zone_create_helper.cpp index 189f7bd953..e9b5afc0cc 100644 --- a/pcbnew/tools/zone_create_helper.cpp +++ b/pcbnew/tools/zone_create_helper.cpp @@ -66,7 +66,7 @@ std::unique_ptr ZONE_CREATE_HELPER::createNewZone( bool aKeepout zoneInfo.m_NetcodeSelection = board.GetHighLightNetCode(); zoneInfo.SetIsKeepout( m_params.m_keepout ); - if( m_params.m_mode != DRAWING_TOOL::ZONE_MODE::GRAPHIC_POLYGON ) + if( m_params.m_mode != ZONE_MODE::GRAPHIC_POLYGON ) { // Get the current default settings for zones @@ -165,13 +165,13 @@ void ZONE_CREATE_HELPER::commitZone( std::unique_ptr aZone ) switch ( m_params.m_mode ) { - case DRAWING_TOOL::ZONE_MODE::CUTOUT: + case ZONE_MODE::CUTOUT: // For cutouts, subtract from the source performZoneCutout( *m_params.m_sourceZone, *aZone ); break; - case DRAWING_TOOL::ZONE_MODE::ADD: - case DRAWING_TOOL::ZONE_MODE::SIMILAR: + case ZONE_MODE::ADD: + case ZONE_MODE::SIMILAR: { BOARD_COMMIT bCommit( &m_tool ); @@ -188,7 +188,7 @@ void ZONE_CREATE_HELPER::commitZone( std::unique_ptr aZone ) break; } - case DRAWING_TOOL::ZONE_MODE::GRAPHIC_POLYGON: + case ZONE_MODE::GRAPHIC_POLYGON: { BOARD_COMMIT bCommit( &m_tool ); BOARD_ITEM_CONTAINER* parent = frame.GetModel(); diff --git a/pcbnew/tools/zone_create_helper.h b/pcbnew/tools/zone_create_helper.h index 3b56abecb0..95adbde4c5 100644 --- a/pcbnew/tools/zone_create_helper.h +++ b/pcbnew/tools/zone_create_helper.h @@ -56,7 +56,7 @@ public: PCB_LAYER_ID m_layer; ///> The zone mode to operate in - DRAWING_TOOL::ZONE_MODE m_mode; + ZONE_MODE m_mode; ///> Zone settings source (for similar and cutout zones) ZONE_CONTAINER* m_sourceZone;