diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp index 6e4b446d14..13519ea01b 100644 --- a/pcbnew/router/length_tuner_tool.cpp +++ b/pcbnew/router/length_tuner_tool.cpp @@ -43,6 +43,7 @@ #include "length_tuner_tool.h" #include +#include using namespace KIGFX; @@ -94,10 +95,9 @@ public: SetIcon( router_len_tuner_xpm ); DisplayTitle( true ); - //Add( ACT_StartTuning ); - //Add( ACT_EndTuning ); + Add( ACTIONS::cancelInteractive ); - //AppendSeparator(); + AppendSeparator(); Add( ACT_SpacingIncrease ); Add( ACT_SpacingDecrease ); @@ -172,7 +172,7 @@ void LENGTH_TUNER_TOOL::performTuning() while( OPT_TOOL_EVENT evt = Wait() ) { - if( evt->IsCancel() || evt->IsActivate() ) + if( evt->IsCancel() || evt->IsActivate() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) break; else if( evt->IsMotion() ) { @@ -278,7 +278,7 @@ int LENGTH_TUNER_TOOL::mainLoop( PNS::ROUTER_MODE aMode ) // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { - if( evt->IsCancel() || evt->IsActivate() ) + if( evt->IsCancel() || evt->IsActivate() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { break; // Finish } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index e30f85577d..bf352ccd07 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -152,8 +152,7 @@ DRAWING_TOOL::DRAWING_TOOL() : PCB_TOOL( "pcbnew.InteractiveDrawing" ), m_view( nullptr ), m_controls( nullptr ), m_board( nullptr ), m_frame( nullptr ), m_mode( MODE::NONE ), - m_lineWidth( 1 ), - m_menu( *this ) + m_lineWidth( 1 ) { } @@ -181,14 +180,15 @@ bool DRAWING_TOOL::Init() auto& ctxMenu = m_menu.GetMenu(); - // cancel current toool goes in main context menu at the top if present - ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1000 ); + // cancel current tool goes in main context menu at the top if present + ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 ); + ctxMenu.AddSeparator( activeToolFunctor, 1 ); // tool-specific actions - ctxMenu.AddItem( closeZoneOutline, zoneActiveFunctor, 1000 ); - ctxMenu.AddItem( deleteLastPoint, canUndoPoint, 1000 ); + ctxMenu.AddItem( closeZoneOutline, zoneActiveFunctor, 200 ); + ctxMenu.AddItem( deleteLastPoint, canUndoPoint, 200 ); - ctxMenu.AddSeparator( activeToolFunctor, 1000 ); + ctxMenu.AddSeparator( canUndoPoint, 500 ); // Type-specific sub-menus will be added for us by other tools // For example, zone fill/unfill is provided by the PCB control tool @@ -1688,6 +1688,8 @@ 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" ) ); doInteractiveItemPlacement( &placer, _( "Place via" ), diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 74d58ecda5..9193164843 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -77,7 +77,8 @@ public: DIMENSION, KEEPOUT, ZONE, - GRAPHIC_POLYGON + GRAPHIC_POLYGON, + VIA }; /** @@ -280,9 +281,6 @@ private: /// Stores the current line width for multisegment drawing. unsigned int m_lineWidth; - /// Menu model displayed by the tool. - TOOL_MENU m_menu; - // How does line width change after one -/+ key press. static const unsigned int WIDTH_STEP; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 819c73cd68..da2a463f22 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -237,8 +237,7 @@ void EnsureEditableFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector ) EDIT_TOOL::EDIT_TOOL() : PCB_TOOL( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ), - m_dragging( false ), - m_measureMenu( *this ) + m_dragging( false ) { } @@ -319,16 +318,6 @@ bool EDIT_TOOL::Init() menu.AddItem( PCB_ACTIONS::updateFootprints, singleModuleCondition ); menu.AddItem( PCB_ACTIONS::exchangeFootprints, singleModuleCondition ); - // Initialize menu for Measurement Tool - auto& ctxMenu = m_measureMenu.GetMenu(); - - // cancel current toool goes in main context menu at the top if present - ctxMenu.AddItem( ACTIONS::cancelInteractive, SELECTION_CONDITIONS::ShowAlways, 1000 ); - ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 ); - - // Finally, add the standard zoom/grid items - m_measureMenu.AddStandardSubMenus( *getEditFrame() ); - return true; } @@ -1304,7 +1293,7 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) else if( evt->IsClick( BUT_RIGHT ) ) { - m_measureMenu.ShowContextMenu(); + m_menu.ShowContextMenu(); } } diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index e081308206..2b620baae6 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -194,9 +194,6 @@ private: ///> of edit reference point). VECTOR2I m_cursor; - ///> A context menu for the Measurement Tool - TOOL_MENU m_measureMenu; - ///> Returns the right modification point (e.g. for rotation), depending on the number of ///> selected items. bool updateModificationPoint( SELECTION& aSelection ); diff --git a/pcbnew/tools/microwave_tool.cpp b/pcbnew/tools/microwave_tool.cpp index 30511da88a..644ed6ac92 100644 --- a/pcbnew/tools/microwave_tool.cpp +++ b/pcbnew/tools/microwave_tool.cpp @@ -91,8 +91,7 @@ TOOL_ACTION PCB_ACTIONS::microwaveCreateLine( MICROWAVE_TOOL::MICROWAVE_TOOL() : - PCB_TOOL( "pcbnew.MicrowaveTool" ), - m_menu( *this ) + PCB_TOOL( "pcbnew.MicrowaveTool" ) { } @@ -106,24 +105,6 @@ void MICROWAVE_TOOL::Reset( RESET_REASON aReason ) } -bool MICROWAVE_TOOL::Init() -{ - auto activeToolFunctor = [] ( const SELECTION& aSel ) { - return true; - }; - - auto& ctxMenu = m_menu.GetMenu(); - - // cancel current goes in main context menu at the top if present - ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1000 ); - ctxMenu.AddSeparator( activeToolFunctor, 1000 ); - - m_menu.AddStandardSubMenus( *getEditFrame() ); - - return true; -} - - struct MICROWAVE_TOOL_INFO { using MOD_CREATOR = std::function()>; @@ -226,7 +207,8 @@ int MICROWAVE_TOOL::addMicrowaveFootprint( const TOOL_EVENT& aEvent ) MICROWAVE_PLACER placer ( info ); - doInteractiveItemPlacement( &placer, _( "Place microwave feature" ) ); + doInteractiveItemPlacement( &placer, _( "Place microwave feature" ), + IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP | IPO_PROPERTIES ); frame.SetNoToolSelected(); diff --git a/pcbnew/tools/microwave_tool.h b/pcbnew/tools/microwave_tool.h index b8a60390b1..44d065b7fd 100644 --- a/pcbnew/tools/microwave_tool.h +++ b/pcbnew/tools/microwave_tool.h @@ -43,9 +43,6 @@ public: ///> React to model/view changes void Reset( RESET_REASON aReason ) override; - ///> Basic initalization - bool Init() override; - ///> Bind handlers to corresponding TOOL_ACTIONs void setTransitions() override; @@ -59,9 +56,6 @@ private: ///> Draw a microwave inductor interactively int drawMicrowaveInductor( const TOOL_EVENT& aEvent ); - - /// Menu model displayed by the tool. - TOOL_MENU m_menu; }; diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index e3485629d0..25daaa0969 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -308,10 +308,10 @@ bool PCB_EDITOR_CONTROL::Init() toolMenu.AddSubMenu( lockMenu ); menu.AddMenu( zoneMenu.get(), false, - SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) ); + SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ), 200 ); menu.AddMenu( lockMenu.get(), false, - SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::LockableItems ) ); + SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::LockableItems ), 200 ); } DRAWING_TOOL* drawingTool = m_toolMgr->GetTool(); @@ -333,7 +333,7 @@ bool PCB_EDITOR_CONTROL::Init() }; }; - menu.AddMenu( zoneMenu.get(), false, toolActiveFunctor( DRAWING_TOOL::MODE::ZONE ) ); + menu.AddMenu( zoneMenu.get(), false, toolActiveFunctor( DRAWING_TOOL::MODE::ZONE ), 200 ); } m_ratsnestTimer.SetOwner( this ); diff --git a/pcbnew/tools/pcb_tool.cpp b/pcbnew/tools/pcb_tool.cpp index 81dcc90f07..89fb02a3db 100644 --- a/pcbnew/tools/pcb_tool.cpp +++ b/pcbnew/tools/pcb_tool.cpp @@ -61,7 +61,7 @@ void PCB_TOOL::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer, aPlacer->m_frame = frame(); aPlacer->m_modifiers = 0; - if( aOptions & IPO_SINGLE_CLICK ) + if( aOptions & IPO_SINGLE_CLICK && !( aOptions & IPO_PROPERTIES ) ) { VECTOR2I cursorPos = controls()->GetCursorPosition(); @@ -101,7 +101,6 @@ void PCB_TOOL::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer, if( evt->IsActivate() ) // now finish unconditionally break; } - else if( evt->IsClick( BUT_LEFT ) ) { if( !newItem ) @@ -151,7 +150,7 @@ void PCB_TOOL::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer, if( !( aOptions & IPO_REPEAT ) ) break; - if( aOptions & IPO_SINGLE_CLICK ) + if( aOptions & IPO_SINGLE_CLICK && !( aOptions & IPO_PROPERTIES ) ) { VECTOR2I pos = controls()->GetCursorPosition(); @@ -162,7 +161,10 @@ void PCB_TOOL::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer, } } } - + else if( evt->IsClick( BUT_RIGHT ) ) + { + m_menu.ShowContextMenu(); + } else if( newItem && evt->Category() == TC_COMMAND ) { /* @@ -198,6 +200,23 @@ void PCB_TOOL::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer, view()->Remove( &preview ); } +bool PCB_TOOL::Init() +{ + // A basic context manu. Many (but not all) tools will choose to override this. + + auto& ctxMenu = m_menu.GetMenu(); + + // cancel current tool goes in main context menu at the top if present + ctxMenu.AddItem( ACTIONS::cancelInteractive, SELECTION_CONDITIONS::ShowAlways, 1 ); + ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1 ); + + // Finally, add the standard zoom/grid items + m_menu.AddStandardSubMenus( *getEditFrame() ); + + return true; +} + + void PCB_TOOL::Reset( RESET_REASON aReason ) { diff --git a/pcbnew/tools/pcb_tool.h b/pcbnew/tools/pcb_tool.h index c4b35ae7c5..78ae48e987 100644 --- a/pcbnew/tools/pcb_tool.h +++ b/pcbnew/tools/pcb_tool.h @@ -35,7 +35,7 @@ #include #include - +#include /** * Class PCB_TOOL @@ -70,6 +70,7 @@ public: * Creates a tool with given id & name. The name must be unique. */ PCB_TOOL( TOOL_ID aId, const std::string& aName ) : TOOL_INTERACTIVE ( aId, aName ), + m_menu( *this ), m_editModules( false ) {}; /** @@ -78,10 +79,12 @@ public: * Creates a tool with given name. The name must be unique. */ PCB_TOOL( const std::string& aName ) : TOOL_INTERACTIVE ( aName ), + m_menu( *this ), m_editModules( false ) {}; virtual ~PCB_TOOL() {}; + virtual bool Init() override; virtual void Reset( RESET_REASON aReason ) override; /** @@ -141,6 +144,9 @@ protected: const SELECTION& selection() const; SELECTION& selection(); + /// Menu model displayed by the tool. + TOOL_MENU m_menu; + bool m_editModules; };