KiCad PCB EDA Suite
TOOL_MENU Class Reference

Class TOOL_MENU. More...

#include <tool_menu.h>

Public Member Functions

 TOOL_MENU (TOOL_INTERACTIVE &aTool)
 Function TOOL_MENU. More...
 
 ~TOOL_MENU ()
 Destructor, also destructs any submenus created with TOOL_MENU::CreateSubMenu(). More...
 
CONDITIONAL_MENUGetMenu ()
 Function GetMenu. More...
 
void AddSubMenu (std::shared_ptr< CONTEXT_MENU > aSubMenu)
 Function CreateSubMenu. More...
 
void ShowContextMenu (SELECTION &aSelection)
 Function ShowContextMenu. More...
 
void ShowContextMenu ()
 Function ShowContextMenu. More...
 
void CloseContextMenu (OPT_TOOL_EVENT &evt)
 Function CloseContextMenu. More...
 
void AddStandardSubMenus (EDA_DRAW_FRAME &aFrame)
 Function CreateBasicMenu. More...
 

Private Member Functions

template<typename T , typename... Args>
std::shared_ptr< T > createOwnSubMenu (Args &&...args)
 

Private Attributes

CONDITIONAL_MENU m_menu
 The conditional model of the menu displayed by the tool. More...
 
std::unique_ptr< CONTEXT_MENUm_contextMenu
 The actual menu displayed by the tool. More...
 
TOOL_INTERACTIVEm_tool
 The tool that owns this menu. More...
 
std::vector< std::shared_ptr< CONTEXT_MENU > > m_subMenus
 Lifetime-managing container of submenus. More...
 

Detailed Description

Class TOOL_MENU.

Manages a CONDITIONAL_MENU and some number of CONTEXT_MENUs as sub-menus

Each "top-level" interactive tool can have one of these, and other tools can contribute CONTEXT_MENUS to it.

There are also helper functions for adding common sets of menu items, for example zoom and grid controls.

Definition at line 47 of file tool_menu.h.

Constructor & Destructor Documentation

TOOL_MENU::TOOL_MENU ( TOOL_INTERACTIVE aTool)

Function TOOL_MENU.

Construct a new TOOL_MENU for a specific tool. This menu will be empty - it's up to the caller to add the relevant items. This can be done directy, using the reference returned by TOOL_MENU::GetMenu(), or the helpers for common command sets can be used, or a combination of the two.

Definition at line 37 of file tool_menu.cpp.

37  :
38  m_menu( &aTool ),
39  m_tool( aTool )
40 {
41 }
TOOL_INTERACTIVE & m_tool
The tool that owns this menu.
Definition: tool_menu.h:165
CONDITIONAL_MENU m_menu
The conditional model of the menu displayed by the tool.
Definition: tool_menu.h:155
TOOL_MENU::~TOOL_MENU ( )

Destructor, also destructs any submenus created with TOOL_MENU::CreateSubMenu().

Definition at line 44 of file tool_menu.cpp.

45 {
46 }

Member Function Documentation

void TOOL_MENU::AddStandardSubMenus ( EDA_DRAW_FRAME aFrame)

Function CreateBasicMenu.

Construct a "basic" menu for a tool, containing only items that apply to all tools (e.g. zoom and grid)

Definition at line 95 of file tool_menu.cpp.

References CONDITIONAL_MENU::AddItem(), CONDITIONAL_MENU::AddMenu(), CONDITIONAL_MENU::AddSeparator(), m_menu, SELECTION_CONDITIONS::ShowAlways(), ACTIONS::zoomCenter, ACTIONS::zoomFitScreen, ACTIONS::zoomIn, and ACTIONS::zoomOut.

Referenced by MICROWAVE_TOOL::Init(), DRAWING_TOOL::Init(), and SELECTION_TOOL::Init().

96 {
101 
103 
104  m_menu.AddMenu( createOwnSubMenu<ZOOM_MENU>( &aFrame ).get(), false, S_C::ShowAlways, 1000 );
105  m_menu.AddMenu( createOwnSubMenu<GRID_MENU>( &aFrame ).get(), false, S_C::ShowAlways, 1000 );
106 }
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
void AddSeparator(const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddSeparator()
static TOOL_ACTION zoomFitScreen
Definition: actions.h:56
CONDITIONAL_MENU m_menu
The conditional model of the menu displayed by the tool.
Definition: tool_menu.h:155
void AddMenu(CONTEXT_MENU *aMenu, bool aExpand=false, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
static TOOL_ACTION zoomCenter
Definition: actions.h:55
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddItem()
static TOOL_ACTION zoomIn
Definition: actions.h:51
static TOOL_ACTION zoomOut
Definition: actions.h:52
void TOOL_MENU::AddSubMenu ( std::shared_ptr< CONTEXT_MENU aSubMenu)

Function CreateSubMenu.

Store a submenu of this menu model. This can be shared with other menu models.

It is the callers responsibility to add the submenu to m_menu (via GetMenu() ) in the right way, as well as to set the tool with SetTool(), since it's not a given that the menu's tool is the tool that directly owns this TOOL_MENU

Parameters
aSubMenua sub menu to add

Definition at line 55 of file tool_menu.cpp.

References m_subMenus.

Referenced by createOwnSubMenu(), and SELECTION_TOOL::Init().

56 {
57  // store a copy of the menu (keeps a reference)
58  m_subMenus.push_back( std::move( aSubMenu ) );
59 }
std::vector< std::shared_ptr< CONTEXT_MENU > > m_subMenus
Lifetime-managing container of submenus.
Definition: tool_menu.h:170
void TOOL_MENU::CloseContextMenu ( OPT_TOOL_EVENT evt)

Function CloseContextMenu.

Helper function to close a menu previously opened with ShowContextMenu(), if a suitable event is received

Definition at line 82 of file tool_menu.cpp.

References m_contextMenu.

Referenced by SELECTION_TOOL::Main().

83 {
84  // m_contextMenu can be null here, that's OK
85  if( evt->Parameter<CONTEXT_MENU*>() == m_contextMenu.get() )
86  {
87  m_contextMenu = nullptr;
88  }
89 }
Class CONTEXT_MENU.
Definition: context_menu.h:44
std::unique_ptr< CONTEXT_MENU > m_contextMenu
The actual menu displayed by the tool.
Definition: tool_menu.h:160
template<typename T , typename... Args>
std::shared_ptr<T> TOOL_MENU::createOwnSubMenu ( Args &&...  args)
inlineprivate

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()?

Definition at line 142 of file tool_menu.h.

References AddSubMenu(), and m_tool.

143  {
144  auto subMenuPtr = std::make_shared<T>( args ... );
145 
146  subMenuPtr->SetTool( &m_tool );
147  AddSubMenu( subMenuPtr );
148 
149  return subMenuPtr;
150  }
TOOL_INTERACTIVE & m_tool
The tool that owns this menu.
Definition: tool_menu.h:165
void AddSubMenu(std::shared_ptr< CONTEXT_MENU > aSubMenu)
Function CreateSubMenu.
Definition: tool_menu.cpp:55
CONDITIONAL_MENU & TOOL_MENU::GetMenu ( )

Function GetMenu.

Returns
reference to the CONDITIONAL_MENU model, which can be used tby tools to add their own commands to the menu.

Definition at line 49 of file tool_menu.cpp.

References m_menu.

Referenced by PLACEMENT_TOOL::Init(), PAD_TOOL::Init(), MICROWAVE_TOOL::Init(), POINT_EDITOR::Init(), PCB_EDITOR_CONTROL::Init(), EDIT_TOOL::Init(), DRAWING_TOOL::Init(), and SELECTION_TOOL::Init().

50 {
51  return m_menu;
52 }
CONDITIONAL_MENU m_menu
The conditional model of the menu displayed by the tool.
Definition: tool_menu.h:155
void TOOL_MENU::ShowContextMenu ( SELECTION aSelection)

Function ShowContextMenu.

Helper function to set and immediately show a CONTEXT_MENU based on the internal CONDITIONAL_MENU in concert with the given SELECTION

You don't have to use this function, if the caller has a different way to show the menu, it can create one from the reference returned by TOOL_MENU::GetMenu(), but it will have to be managed externally to this class.

Definition at line 62 of file tool_menu.cpp.

References CMENU_NOW, CONDITIONAL_MENU::Generate(), m_contextMenu, m_menu, m_tool, and TOOL_INTERACTIVE::SetContextMenu().

Referenced by DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), SELECTION_TOOL::Main(), DRAWING_TOOL::PlaceDXF(), DRAWING_TOOL::PlaceText(), DRAWING_TOOL::runPolygonEventLoop(), and DRAWING_TOOL::SetAnchor().

63 {
64  m_contextMenu = std::unique_ptr<CONTEXT_MENU>(
65  m_menu.Generate( aSelection ) );
66 
67  if( m_contextMenu->GetMenuItemCount() > 0 )
68  {
70  }
71 }
TOOL_INTERACTIVE & m_tool
The tool that owns this menu.
Definition: tool_menu.h:165
CONDITIONAL_MENU m_menu
The conditional model of the menu displayed by the tool.
Definition: tool_menu.h:155
void SetContextMenu(CONTEXT_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Function SetContextMenu()
CONTEXT_MENU * Generate(SELECTION &aSelection)
Function Generate()
std::unique_ptr< CONTEXT_MENU > m_contextMenu
The actual menu displayed by the tool.
Definition: tool_menu.h:160
void TOOL_MENU::ShowContextMenu ( )

Function ShowContextMenu.

Helper function to show a context menu without any selection for tools that can't make selections.

Definition at line 74 of file tool_menu.cpp.

75 {
76  SELECTION dummySelection;
77 
78  ShowContextMenu( dummySelection );
79 }
void ShowContextMenu()
Function ShowContextMenu.
Definition: tool_menu.cpp:74

Member Data Documentation

std::unique_ptr<CONTEXT_MENU> TOOL_MENU::m_contextMenu
private

The actual menu displayed by the tool.

Definition at line 160 of file tool_menu.h.

Referenced by CloseContextMenu(), and ShowContextMenu().

CONDITIONAL_MENU TOOL_MENU::m_menu
private

The conditional model of the menu displayed by the tool.

Definition at line 155 of file tool_menu.h.

Referenced by AddStandardSubMenus(), GetMenu(), and ShowContextMenu().

std::vector<std::shared_ptr<CONTEXT_MENU> > TOOL_MENU::m_subMenus
private

Lifetime-managing container of submenus.

Definition at line 170 of file tool_menu.h.

Referenced by AddSubMenu().

TOOL_INTERACTIVE& TOOL_MENU::m_tool
private

The tool that owns this menu.

Definition at line 165 of file tool_menu.h.

Referenced by createOwnSubMenu(), and ShowContextMenu().


The documentation for this class was generated from the following files: