KiCad PCB EDA Suite
tool_menu.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2017 KiCad Developers, see CHANGELOG.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #ifndef TOOLS_TOOL_MENU__H_
25 #define TOOLS_TOOL_MENU__H_
26 
27 #include <tool/conditional_menu.h>
28 #include <tool/tool_event.h>
29 
30 #include <vector>
31 #include <memory>
32 
33 class CONTEXT_MENU;
34 
47 class TOOL_MENU
48 {
49 public:
50 
60  TOOL_MENU( TOOL_INTERACTIVE& aTool );
61 
66  ~TOOL_MENU();
67 
75 
90  void AddSubMenu( std::shared_ptr<CONTEXT_MENU> aSubMenu );
91 
104  void ShowContextMenu( SELECTION& aSelection );
105 
112  void ShowContextMenu();
113 
120  void CloseContextMenu( OPT_TOOL_EVENT& evt );
121 
128  void AddStandardSubMenus( EDA_DRAW_FRAME& aFrame );
129 
130 private:
131 
141  template <typename T, typename ... Args>
142  std::shared_ptr<T> createOwnSubMenu( Args&& ... args )
143  {
144  auto subMenuPtr = std::make_shared<T>( args ... );
145 
146  subMenuPtr->SetTool( &m_tool );
147  AddSubMenu( subMenuPtr );
148 
149  return subMenuPtr;
150  }
151 
156 
160  std::unique_ptr<CONTEXT_MENU> m_contextMenu;
161 
166 
170  std::vector<std::shared_ptr<CONTEXT_MENU> > m_subMenus;
171 };
172 
173 #endif // TOOLS_TOOL_MENU__H_
TOOL_INTERACTIVE & m_tool
The tool that owns this menu.
Definition: tool_menu.h:165
void ShowContextMenu()
Function ShowContextMenu.
Definition: tool_menu.cpp:74
~TOOL_MENU()
Destructor, also destructs any submenus created with TOOL_MENU::CreateSubMenu().
Definition: tool_menu.cpp:44
T
enum T contains all this lexer's tokens.
Class CONTEXT_MENU.
Definition: context_menu.h:44
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:49
Class TOOL_MENU.
Definition: tool_menu.h:47
void AddSubMenu(std::shared_ptr< CONTEXT_MENU > aSubMenu)
Function CreateSubMenu.
Definition: tool_menu.cpp:55
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:53
CONDITIONAL_MENU m_menu
The conditional model of the menu displayed by the tool.
Definition: tool_menu.h:155
void AddStandardSubMenus(EDA_DRAW_FRAME &aFrame)
Function CreateBasicMenu.
Definition: tool_menu.cpp:95
std::shared_ptr< T > createOwnSubMenu(Args &&...args)
Definition: tool_menu.h:142
void CloseContextMenu(OPT_TOOL_EVENT &evt)
Function CloseContextMenu.
Definition: tool_menu.cpp:82
std::unique_ptr< CONTEXT_MENU > m_contextMenu
The actual menu displayed by the tool.
Definition: tool_menu.h:160
TOOL_MENU(TOOL_INTERACTIVE &aTool)
Function TOOL_MENU.
Definition: tool_menu.cpp:37
std::vector< std::shared_ptr< CONTEXT_MENU > > m_subMenus
Lifetime-managing container of submenus.
Definition: tool_menu.h:170