diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index db16c4b7a2..57742e281e 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -45,6 +45,11 @@ #include #include #include +#include +#include +#include +#include +#include /** * Definition for enabling and disabling scroll bar setting trace output. See the @@ -328,6 +333,31 @@ double EDA_DRAW_FRAME::GetZoom() } +void EDA_DRAW_FRAME::AddStandardSubMenus( TOOL_MENU& aToolMenu ) +{ + COMMON_TOOLS* commonTools = m_toolManager->GetTool(); + CONDITIONAL_MENU& aMenu = aToolMenu.GetMenu(); + + aMenu.AddItem( ACTIONS::zoomCenter, SELECTION_CONDITIONS::ShowAlways, 1000 ); + aMenu.AddItem( ACTIONS::zoomIn, SELECTION_CONDITIONS::ShowAlways, 1000 ); + aMenu.AddItem( ACTIONS::zoomOut, SELECTION_CONDITIONS::ShowAlways, 1000 ); + aMenu.AddItem( ACTIONS::zoomFitScreen, SELECTION_CONDITIONS::ShowAlways, 1000 ); + + aMenu.AddSeparator(SELECTION_CONDITIONS::ShowAlways, 1000 ); + + auto zoomMenu = std::make_shared( this ); + zoomMenu->SetTool( commonTools ); + aToolMenu.AddSubMenu( zoomMenu ); + + auto gridMenu = std::make_shared( this ); + gridMenu->SetTool( commonTools ); + aToolMenu.AddSubMenu( gridMenu ); + + aMenu.AddMenu( zoomMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 ); + aMenu.AddMenu( gridMenu.get(), SELECTION_CONDITIONS::ShowAlways, 1000 ); +} + + void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg ) { m_toolMsg = msg; diff --git a/common/tool/tool_menu.cpp b/common/tool/tool_menu.cpp index 0166f7c1c8..120a26ec57 100644 --- a/common/tool/tool_menu.cpp +++ b/common/tool/tool_menu.cpp @@ -76,24 +76,3 @@ void TOOL_MENU::CloseContextMenu( OPT_TOOL_EVENT& evt ) { } - -// This makes the factory functions a bit less verbose -using S_C = SELECTION_CONDITIONS; - -void TOOL_MENU::AddStandardSubMenus( EDA_DRAW_FRAME* aFrame ) -{ -#if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) || defined( GERBVIEW ) || defined( PL_EDITOR ) - m_menu.AddItem( ACTIONS::zoomCenter, S_C::ShowAlways, 1000 ); - m_menu.AddItem( ACTIONS::zoomIn, S_C::ShowAlways, 1000 ); - m_menu.AddItem( ACTIONS::zoomOut, S_C::ShowAlways, 1000 ); - m_menu.AddItem( ACTIONS::zoomFitScreen, S_C::ShowAlways, 1000 ); - - m_menu.AddSeparator(SELECTION_CONDITIONS::ShowAlways, 1000 ); - - if( aFrame ) - { - m_menu.AddMenu( createOwnSubMenu( aFrame ).get(), S_C::ShowAlways, 1000 ); - m_menu.AddMenu( createOwnSubMenu( aFrame ).get(), S_C::ShowAlways, 1000 ); - } -#endif -} diff --git a/cvpcb/tools/cvpcb_selection_tool.cpp b/cvpcb/tools/cvpcb_selection_tool.cpp index 630302d56f..0cb2fdb1e2 100644 --- a/cvpcb/tools/cvpcb_selection_tool.cpp +++ b/cvpcb/tools/cvpcb_selection_tool.cpp @@ -45,8 +45,7 @@ CVPCB_SELECTION_TOOL::CVPCB_SELECTION_TOOL() : bool CVPCB_SELECTION_TOOL::Init() { - m_menu.AddStandardSubMenus( getEditFrame() ); - + getEditFrame()->AddStandardSubMenus( m_menu ); return true; } diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index b70792479f..63cdae709b 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -238,7 +238,7 @@ bool EE_SELECTION_TOOL::Init() menu.AddItem( EE_ACTIONS::pinTable, havePartCondition && EE_CONDITIONS::Empty, 400 ); menu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 ); - m_menu.AddStandardSubMenus( m_frame ); + m_frame->AddStandardSubMenus( m_menu ); return true; } diff --git a/eeschema/tools/ee_tool_base.h b/eeschema/tools/ee_tool_base.h index af401d3fca..e5aa7d00d5 100644 --- a/eeschema/tools/ee_tool_base.h +++ b/eeschema/tools/ee_tool_base.h @@ -80,7 +80,7 @@ public: ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1 ); // Finally, add the standard zoom/grid items - m_menu.AddStandardSubMenus( m_frame ); + m_frame->AddStandardSubMenus( m_menu ); return true; } diff --git a/gerbview/tools/gerbview_selection_tool.cpp b/gerbview/tools/gerbview_selection_tool.cpp index 1c991bad6a..dbf1899982 100644 --- a/gerbview/tools/gerbview_selection_tool.cpp +++ b/gerbview/tools/gerbview_selection_tool.cpp @@ -165,7 +165,7 @@ bool GERBVIEW_SELECTION_TOOL::Init() menu.AddMenu( selectMenu.get() ); menu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 ); - m_menu.AddStandardSubMenus( getEditFrame() ); + getEditFrame()->AddStandardSubMenus( m_menu ); return true; } diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h index f695eb9216..c2692fcf4f 100644 --- a/include/eda_draw_frame.h +++ b/include/eda_draw_frame.h @@ -37,6 +37,7 @@ class wxSingleInstanceChecker; class EDA_HOTKEY; class ACTION_TOOLBAR; +class TOOL_MENU; using KIGFX::COLOR4D; @@ -515,6 +516,14 @@ public: */ double GetZoom(); + /** + * Function CreateBasicMenu + * + * Construct a "basic" menu for a tool, containing only items + * that apply to all tools (e.g. zoom and grid) + */ + void AddStandardSubMenus( TOOL_MENU& aMenu ); + /** * Prints the page layout with the frame and the basic inscriptions. * diff --git a/include/tool/tool_menu.h b/include/tool/tool_menu.h index 72ad8624fa..94b449b1e3 100644 --- a/include/tool/tool_menu.h +++ b/include/tool/tool_menu.h @@ -118,36 +118,7 @@ public: */ void CloseContextMenu( OPT_TOOL_EVENT& evt ); - /** - * Function CreateBasicMenu - * - * Construct a "basic" menu for a tool, containing only items - * that apply to all tools (e.g. zoom and grid) - */ - void AddStandardSubMenus( EDA_DRAW_FRAME* aFrame ); - private: - - /*! - * Helper function for factories to abe able to easily add - * their own new sub menus. This sets the tool to the TOOL_MENUs - * owner and adds to the store. - * - * Note, this won't share the menu between multiple invocations - * of the factory. But if different top-level tools are using the - * same factory, which one would be used for SetTool()? - */ - template - std::shared_ptr createOwnSubMenu( Args&& ... args ) - { - auto subMenuPtr = std::make_shared( args ... ); - - subMenuPtr->SetTool( &m_tool ); - AddSubMenu( subMenuPtr ); - - return subMenuPtr; - } - /** * The conditional menu displayed by the tool */ diff --git a/pagelayout_editor/tools/pl_drawing_tools.cpp b/pagelayout_editor/tools/pl_drawing_tools.cpp index 533314d86d..d1eab244bf 100644 --- a/pagelayout_editor/tools/pl_drawing_tools.cpp +++ b/pagelayout_editor/tools/pl_drawing_tools.cpp @@ -100,7 +100,7 @@ bool PL_DRAWING_TOOLS::Init() ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1 ); // Finally, add the standard zoom/grid items - m_menu.AddStandardSubMenus( m_frame ); + m_frame->AddStandardSubMenus( m_menu ); return true; } diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp index e031b0995d..e1842f2c04 100644 --- a/pagelayout_editor/tools/pl_edit_tool.cpp +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -80,7 +80,7 @@ bool PL_EDIT_TOOL::Init() ctxMenu.AddItem( PL_ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty, 200 ); // Finally, add the standard zoom/grid items - m_menu.AddStandardSubMenus( m_frame ); + m_frame->AddStandardSubMenus( m_menu ); // // Add editing actions to the selection tool menu diff --git a/pagelayout_editor/tools/pl_picker_tool.cpp b/pagelayout_editor/tools/pl_picker_tool.cpp index d6d1383185..e1fab86b83 100644 --- a/pagelayout_editor/tools/pl_picker_tool.cpp +++ b/pagelayout_editor/tools/pl_picker_tool.cpp @@ -53,7 +53,7 @@ bool PL_PICKER_TOOL::Init() ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1 ); // Finally, add the standard zoom/grid items - m_menu.AddStandardSubMenus( m_frame ); + m_frame->AddStandardSubMenus( m_menu ); return true; } diff --git a/pagelayout_editor/tools/pl_selection_tool.cpp b/pagelayout_editor/tools/pl_selection_tool.cpp index 736572b14c..e55f9e7a73 100644 --- a/pagelayout_editor/tools/pl_selection_tool.cpp +++ b/pagelayout_editor/tools/pl_selection_tool.cpp @@ -102,7 +102,7 @@ bool PL_SELECTION_TOOL::Init() menu.AddItem( PL_ACTIONS::appendImportedWorksheet, PL_CONDITIONS::Idle, 250 ); menu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 ); - m_menu.AddStandardSubMenus( m_frame ); + m_frame->AddStandardSubMenus( m_menu ); return true; } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 3a9dbee87f..a63468a8c5 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -224,7 +224,7 @@ bool DRAWING_TOOL::Init() // For example, zone fill/unfill is provided by the PCB control tool // Finally, add the standard zoom/grid items - m_menu.AddStandardSubMenus( getEditFrame() ); + getEditFrame()->AddStandardSubMenus( m_menu ); return true; } diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index bba3524d4f..059ab5c162 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -282,7 +282,7 @@ bool EDIT_TOOL::Init() ctxMenu.AddSeparator( activeToolCondition, 1 ); if( frame ) - m_menu.AddStandardSubMenus( frame ); + frame->AddStandardSubMenus( m_menu ); return true; } diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index a9a2125476..42499ae11e 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -382,7 +382,7 @@ bool PCB_EDITOR_CONTROL::Init() ctxMenu.AddSeparator( placeModuleCondition, 1000 ); // Finally, add the standard zoom & grid items - m_menu.AddStandardSubMenus( getEditFrame() ); + getEditFrame()->AddStandardSubMenus( m_menu ); auto zoneMenu = std::make_shared(); zoneMenu->SetTool( this ); diff --git a/pcbnew/tools/pcb_tool_base.cpp b/pcbnew/tools/pcb_tool_base.cpp index 752bd1e7f0..e18f20062e 100644 --- a/pcbnew/tools/pcb_tool_base.cpp +++ b/pcbnew/tools/pcb_tool_base.cpp @@ -219,7 +219,7 @@ bool PCB_TOOL_BASE::Init() ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1 ); // Finally, add the standard zoom/grid items - m_menu.AddStandardSubMenus( getEditFrame() ); + getEditFrame()->AddStandardSubMenus( m_menu ); return true; } diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 1a2fda6db6..5653a1da6d 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -211,7 +211,7 @@ bool SELECTION_TOOL::Init() if( frame && ( frame->IsType( FRAME_PCB_MODULE_VIEWER ) || frame->IsType( FRAME_PCB_MODULE_VIEWER_MODAL ) ) ) { - m_menu.AddStandardSubMenus( frame ); + frame->AddStandardSubMenus( m_menu ); return true; } @@ -225,7 +225,7 @@ bool SELECTION_TOOL::Init() menu.AddSeparator( SELECTION_CONDITIONS::NotEmpty, 1000 ); if( frame ) - m_menu.AddStandardSubMenus( frame ); + frame->AddStandardSubMenus( m_menu ); return true; }