KiCad PCB EDA Suite
PAD_CONTEXT_MENU Class Reference
Inheritance diagram for PAD_CONTEXT_MENU:
CONTEXT_MENU

Classes

struct  ENABLEMENTS
 

Public Types

using SHOW_FUNCTOR = std::function< bool()>
 

Public Member Functions

 PAD_CONTEXT_MENU (bool aEditingFootprint, SHOW_FUNCTOR aHaveGlobalPadSetting)
 
void SetTitle (const wxString &aTitle) override
 Function SetTitle() Sets title for the context menu. More...
 
void DisplayTitle (bool aDisplay=true)
 Function DisplayTitle() Decides whether a title for a pop up menu should be displayed. More...
 
void SetIcon (const BITMAP_OPAQUE *aIcon)
 Function SetIcon() Assigns an icon for the entry. More...
 
wxMenuItem * Add (const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon=NULL)
 Function Add() Adds an entry to the menu. More...
 
wxMenuItem * Add (const TOOL_ACTION &aAction)
 Function Add() Adds an entry to the menu, basing on the TOOL_ACTION object. More...
 
std::list< wxMenuItem * > Add (CONTEXT_MENU *aMenu, bool aExpand=false)
 Function Add() Adds a context menu as a submenu. More...
 
void Clear ()
 Function Clear() Removes all the entries from the menu (as well as its title). More...
 
bool HasEnabledItems () const
 Function HasEnabledItems();. More...
 
int GetSelected () const
 Function GetSelected() Returns the position of selected item. More...
 
void UpdateAll ()
 Function UpdateAll() Runs update handlers for the menu and its submenus. More...
 
void SetTool (TOOL_INTERACTIVE *aTool)
 Function SetTool() Sets a tool that is the creator of the menu. More...
 
CONTEXT_MENUClone () const
 Creates a deep, recursive copy of this CONTEXT_MENU. More...
 

Protected Member Functions

CONTEXT_MENUcreate () const override
 

Returns an instance of this class. It has to be overridden in inheriting classes.

More...
 
TOOL_MANAGERgetToolManager ()
 

Returns an instance of TOOL_MANAGER class.

More...
 
virtual OPT_TOOL_EVENT eventHandler (const wxMenuEvent &)
 Event handler stub. More...
 
void copyFrom (const CONTEXT_MENU &aMenu)
 Copies another menus data to this instance. More...
 

Static Protected Member Functions

static int getMenuId (const TOOL_ACTION &aAction)
 

Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.

More...
 

Private Member Functions

ENABLEMENTS getEnablements (const SELECTION &aSelection)
 
void update () override
 Update menu state stub. More...
 

Private Attributes

bool m_editingFootprint
 
SHOW_FUNCTOR m_haveGlobalPadSettings
 

Detailed Description

Definition at line 65 of file pad_tool.cpp.

Member Typedef Documentation

using PAD_CONTEXT_MENU::SHOW_FUNCTOR = std::function<bool()>

Definition at line 69 of file pad_tool.cpp.

Constructor & Destructor Documentation

PAD_CONTEXT_MENU::PAD_CONTEXT_MENU ( bool  aEditingFootprint,
SHOW_FUNCTOR  aHaveGlobalPadSetting 
)
inline

Definition at line 71 of file pad_tool.cpp.

References CONTEXT_MENU::Add(), PCB_ACTIONS::applyPadSettings, PCB_ACTIONS::copyPadSettings, PCB_ACTIONS::enumeratePads, m_editingFootprint, PCB_ACTIONS::pushPadSettings, CONTEXT_MENU::SetIcon(), and CONTEXT_MENU::SetTitle().

Referenced by create().

72  :
73  m_editingFootprint( aEditingFootprint ),
74  m_haveGlobalPadSettings( aHaveGlobalPadSetting )
75  {
76  SetIcon( pad_xpm );
77  SetTitle( _( "Pads" ) );
78 
82 
83 
84  // show modedit-specific items
85  if( m_editingFootprint )
86  {
87  AppendSeparator();
88 
90  }
91  }
static TOOL_ACTION enumeratePads
Tool for quick pad enumeration.
Definition: pcb_actions.h:298
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon=NULL)
Function Add() Adds an entry to the menu.
static TOOL_ACTION pushPadSettings
Copy the current pad's settings to other pads in the module or on the board.
Definition: pcb_actions.h:326
bool m_editingFootprint
Definition: pad_tool.cpp:143
static TOOL_ACTION copyPadSettings
Copy the selected pad's settings to the board design settings.
Definition: pcb_actions.h:320
static TOOL_ACTION applyPadSettings
Copy the pad settings in the board design settings to the selected pad.
Definition: pcb_actions.h:323
SHOW_FUNCTOR m_haveGlobalPadSettings
Definition: pad_tool.cpp:144
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the context menu.

Member Function Documentation

wxMenuItem * CONTEXT_MENU::Add ( const wxString &  aLabel,
int  aId,
const BITMAP_OPAQUE aIcon = NULL 
)
inherited

Function Add() Adds an entry to the menu.

After highlighting/selecting the entry, a TOOL_EVENT command is sent that contains ID of the entry.

Parameters
aLabelis the text label show in the menu.
aIdis the ID that is sent in the TOOL_EVENT. It should be unique for every entry.
aIconis an optional icon.

Definition at line 130 of file context_menu.cpp.

References set_wxMenuIcon().

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), SELECTION_TOOL::disambiguationMenu(), CONDITIONAL_MENU::Generate(), ALIGN_DISTRIBUTE_TOOL::Init(), PAD_CONTEXT_MENU(), ROUTER_TOOL_MENU::ROUTER_TOOL_MENU(), and TUNER_TOOL_MENU::TUNER_TOOL_MENU().

131 {
132 #ifdef DEBUG
133  if( FindItem( aId ) != NULL )
134  wxLogWarning( wxT( "Adding more than one menu entry with the same ID may result in"
135  "undefined behaviour" ) );
136 #endif
137 
138  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
139  set_wxMenuIcon( item, aIcon );
140 
141  return Append( item );
142 }
static void set_wxMenuIcon(wxMenuItem *aMenu, const BITMAP_OPAQUE *aIcon)
wxMenuItem * CONTEXT_MENU::Add ( const TOOL_ACTION aAction)
inherited

Function Add() Adds an entry to the menu, basing on the TOOL_ACTION object.

After selecting the entry, a TOOL_EVENT command containing name of the action is sent.

Parameters
aActionis the action to be added to menu entry.

ID numbers for tool actions need to have a value higher than ACTION_ID

Definition at line 145 of file context_menu.cpp.

References TOOL_ACTION::GetDescription(), TOOL_ACTION::GetIcon(), CONTEXT_MENU::getMenuId(), TOOL_ACTION::GetMenuItem(), CONTEXT_MENU::m_toolActions, and set_wxMenuIcon().

146 {
148  const BITMAP_OPAQUE* icon = aAction.GetIcon();
149 
150  wxMenuItem* item = new wxMenuItem( this, getMenuId( aAction ), aAction.GetMenuItem(),
151  aAction.GetDescription(), wxITEM_NORMAL );
152 
153  set_wxMenuIcon( item, icon );
154 
155  m_toolActions[getMenuId( aAction )] = &aAction;
156 
157  wxMenuItem* i = Append( item );
158  return i;
159 }
PNG memory record (file in memory).
Definition: bitmap_types.h:38
const wxString & GetDescription() const
Definition: tool_action.h:124
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: context_menu.h:225
const wxString & GetMenuItem() const
Definition: tool_action.h:114
static int getMenuId(const TOOL_ACTION &aAction)
Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.
Definition: context_menu.h:155
const BITMAP_OPAQUE * GetIcon() const
Returns an icon associated with the action.
Definition: tool_action.h:165
static void set_wxMenuIcon(wxMenuItem *aMenu, const BITMAP_OPAQUE *aIcon)
std::list< wxMenuItem * > CONTEXT_MENU::Add ( CONTEXT_MENU aMenu,
bool  aExpand = false 
)
inherited

Function Add() Adds a context menu as a submenu.

The difference between this function and wxMenu::AppendSubMenu() is the capability to handle icons.

Parameters
aMenuis the submenu to be added.
aExpandallows to add all entries from the menu as individual entries rather than add everything as a submenu.

Definition at line 162 of file context_menu.cpp.

References CONTEXT_MENU::appendCopy(), CONTEXT_MENU::Clone(), CONTEXT_MENU::m_icon, CONTEXT_MENU::m_submenus, CONTEXT_MENU::m_title, and set_wxMenuIcon().

163 {
164  std::list<wxMenuItem*> items;
165  CONTEXT_MENU* menuCopy = aMenu->Clone();
166  m_submenus.push_back( menuCopy );
167 
168  if( aExpand )
169  {
170  for( int i = 0; i < (int) aMenu->GetMenuItemCount(); ++i )
171  {
172  wxMenuItem* item = aMenu->FindItemByPosition( i );
173  items.push_back( appendCopy( item ) );
174  }
175  }
176  else
177  {
178  wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), "Set a title for CONTEXT_MENU using SetTitle()" );
179 
180  if( aMenu->m_icon )
181  {
182  wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->m_title );
183  set_wxMenuIcon( newItem, aMenu->m_icon );
184  newItem->SetSubMenu( menuCopy );
185  items.push_back( Append( newItem ) );
186  }
187  else
188  {
189  items.push_back( AppendSubMenu( menuCopy, menuCopy->m_title ) );
190  }
191  }
192 
193  return items;
194 }
Class CONTEXT_MENU.
Definition: context_menu.h:44
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: context_menu.h:231
CONTEXT_MENU * Clone() const
Creates a deep, recursive copy of this CONTEXT_MENU.
std::list< CONTEXT_MENU * > m_submenus
List of submenus.
Definition: context_menu.h:228
wxMenuItem * appendCopy(const wxMenuItem *aSource)
Function appendCopy Appends a copy of wxMenuItem.
wxString m_title
Menu title
Definition: context_menu.h:213
static void set_wxMenuIcon(wxMenuItem *aMenu, const BITMAP_OPAQUE *aIcon)
void CONTEXT_MENU::Clear ( )
inherited

Function Clear() Removes all the entries from the menu (as well as its title).

It leaves the menu in the initial state.

Definition at line 197 of file context_menu.cpp.

References CONTEXT_MENU::m_submenus, CONTEXT_MENU::m_titleDisplayed, and CONTEXT_MENU::m_toolActions.

Referenced by CONTEXT_MENU::Clone(), and TRACK_WIDTH_MENU::SetBoard().

198 {
199  m_titleDisplayed = false;
200 
201  for( int i = GetMenuItemCount() - 1; i >= 0; --i )
202  Destroy( FindItemByPosition( i ) );
203 
204  m_toolActions.clear();
205  m_submenus.clear();
206 
207  wxASSERT( GetMenuItemCount() == 0 );
208 }
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: context_menu.h:225
std::list< CONTEXT_MENU * > m_submenus
List of submenus.
Definition: context_menu.h:228
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: context_menu.h:210
CONTEXT_MENU * CONTEXT_MENU::Clone ( ) const
inherited

Creates a deep, recursive copy of this CONTEXT_MENU.

Definition at line 255 of file context_menu.cpp.

References CONTEXT_MENU::Clear(), CONTEXT_MENU::copyFrom(), and CONTEXT_MENU::create().

Referenced by CONTEXT_MENU::Add(), CONTEXT_MENU::appendCopy(), and TOOL_MANAGER::dispatchContextMenu().

256 {
257  CONTEXT_MENU* clone = create();
258  clone->Clear();
259  clone->copyFrom( *this );
260  return clone;
261 }
Class CONTEXT_MENU.
Definition: context_menu.h:44
void copyFrom(const CONTEXT_MENU &aMenu)
Copies another menus data to this instance.
void Clear()
Function Clear() Removes all the entries from the menu (as well as its title).
virtual CONTEXT_MENU * create() const
Returns an instance of this class. It has to be overridden in inheriting classes. ...
void CONTEXT_MENU::copyFrom ( const CONTEXT_MENU aMenu)
protectedinherited

Copies another menus data to this instance.

Old entries are preserved, and ones form aMenu are copied.

Definition at line 423 of file context_menu.cpp.

References CONTEXT_MENU::appendCopy(), CONTEXT_MENU::m_icon, CONTEXT_MENU::m_selected, CONTEXT_MENU::m_title, CONTEXT_MENU::m_titleDisplayed, CONTEXT_MENU::m_tool, and CONTEXT_MENU::m_toolActions.

Referenced by CONTEXT_MENU::Clone().

424 {
425  m_icon = aMenu.m_icon;
426  m_title = aMenu.m_title;
428  m_selected = -1; // aMenu.m_selected;
429  m_tool = aMenu.m_tool;
431 
432  // Copy all menu entries
433  for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
434  {
435  wxMenuItem* item = aMenu.FindItemByPosition( i );
436  appendCopy( item );
437  }
438 }
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: context_menu.h:219
int m_selected
Stores the id number of selected item.
Definition: context_menu.h:216
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: context_menu.h:231
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: context_menu.h:225
wxMenuItem * appendCopy(const wxMenuItem *aSource)
Function appendCopy Appends a copy of wxMenuItem.
wxString m_title
Menu title
Definition: context_menu.h:213
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: context_menu.h:210
CONTEXT_MENU* PAD_CONTEXT_MENU::create ( ) const
inlineoverrideprotectedvirtual

Returns an instance of this class. It has to be overridden in inheriting classes.

Reimplemented from CONTEXT_MENU.

Definition at line 95 of file pad_tool.cpp.

References m_editingFootprint, m_haveGlobalPadSettings, and PAD_CONTEXT_MENU().

96  {
98  }
bool m_editingFootprint
Definition: pad_tool.cpp:143
PAD_CONTEXT_MENU(bool aEditingFootprint, SHOW_FUNCTOR aHaveGlobalPadSetting)
Definition: pad_tool.cpp:71
SHOW_FUNCTOR m_haveGlobalPadSettings
Definition: pad_tool.cpp:144
void CONTEXT_MENU::DisplayTitle ( bool  aDisplay = true)
inherited

Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.

Definition at line 97 of file context_menu.cpp.

References CONTEXT_MENU::m_title, and CONTEXT_MENU::m_titleDisplayed.

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), SELECTION_TOOL::disambiguationMenu(), CONTEXT_MENU::SetTitle(), and TUNER_TOOL_MENU::TUNER_TOOL_MENU().

98 {
99  if( ( !aDisplay || m_title.IsEmpty() ) && m_titleDisplayed )
100  {
101  // Destroy the menu entry keeping the title..
102  wxMenuItem* item = FindItemByPosition( 0 );
103  wxASSERT( item->GetItemLabelText() == GetTitle() );
104  Destroy( item );
105  // ..and separator
106  item = FindItemByPosition( 0 );
107  wxASSERT( item->IsSeparator() );
108  Destroy( item );
109  m_titleDisplayed = false;
110  }
111 
112  else if( aDisplay && !m_title.IsEmpty() )
113  {
114  if( m_titleDisplayed )
115  {
116  // Simply update the title
117  FindItemByPosition( 0 )->SetItemLabel( m_title );
118  }
119  else
120  {
121  // Add a separator and a menu entry to display the title
122  InsertSeparator( 0 );
123  Insert( 0, new wxMenuItem( this, wxID_NONE, m_title, wxEmptyString, wxITEM_NORMAL ) );
124  m_titleDisplayed = true;
125  }
126  }
127 }
wxString m_title
Menu title
Definition: context_menu.h:213
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: context_menu.h:210
virtual OPT_TOOL_EVENT CONTEXT_MENU::eventHandler ( const wxMenuEvent &  )
inlineprotectedvirtualinherited

Event handler stub.

It should be used if you want to generate a TOOL_EVENT from a wxMenuEvent. It will be called when a menu entry is clicked.

Reimplemented in TRACK_WIDTH_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 172 of file context_menu.h.

Referenced by CONTEXT_MENU::onMenuEvent(), and CONTEXT_MENU::runEventHandlers().

173  {
174  return OPT_TOOL_EVENT();
175  }
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:460
ENABLEMENTS PAD_CONTEXT_MENU::getEnablements ( const SELECTION aSelection)
inlineprivate

Definition at line 109 of file pad_tool.cpp.

References PAD_CONTEXT_MENU::ENABLEMENTS::canExport, PAD_CONTEXT_MENU::ENABLEMENTS::canImport, PAD_CONTEXT_MENU::ENABLEMENTS::canPush, SELECTION_CONDITIONS::Count(), SELECTION_CONDITIONS::HasType(), m_haveGlobalPadSettings, SELECTION_CONDITIONS::OnlyType(), and PCB_PAD_T.

Referenced by update().

110  {
111  using S_C = SELECTION_CONDITIONS;
112  ENABLEMENTS enablements;
113 
114  auto anyPadSel = S_C::HasType( PCB_PAD_T );
115  auto singlePadSel = S_C::Count( 1 ) && S_C::OnlyType( PCB_PAD_T );
116 
117  // Apply pads enabled when any pads selected (it applies to each one
118  // individually), plus need a valid global pad setting
119  enablements.canImport = m_haveGlobalPadSettings() && ( anyPadSel )( aSelection );
120 
121  // Copy pads item enabled only when there is a single pad selected
122  // (otherwise how would we know which one to copy?)
123  enablements.canExport = ( singlePadSel )( aSelection );
124 
125  // Push pads available when there is a single pad to push from
126  enablements.canPush = ( singlePadSel )( aSelection );
127 
128  return enablements;
129  }
static SELECTION_CONDITION HasType(KICAD_T aType)
Function HasType Creates a functor that tests if among the selected items there is at least one of a ...
Class that groups generic conditions for selected items.
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
static SELECTION_CONDITION Count(int aNumber)
Function Count Creates a functor that tests if the number of selected items is equal to the value giv...
SHOW_FUNCTOR m_haveGlobalPadSettings
Definition: pad_tool.cpp:144
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Function OnlyType Creates a functor that tests if the selected items are only of given type...
static int CONTEXT_MENU::getMenuId ( const TOOL_ACTION aAction)
inlinestaticprotectedinherited

Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.

Definition at line 155 of file context_menu.h.

References CONTEXT_MENU::ACTION_ID, and TOOL_ACTION::GetId().

Referenced by CONTEXT_MENU::Add(), and update().

156  {
157  return aAction.GetId() + ACTION_ID;
158  }
static const int ACTION_ID
Menu items with ID higher than that are considered TOOL_ACTIONs
Definition: context_menu.h:222
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:85
int CONTEXT_MENU::GetSelected ( ) const
inlineinherited

Function GetSelected() Returns the position of selected item.

If the returned value is negative, that means that menu was dismissed.

Returns
The position of selected item in the context menu.

Definition at line 124 of file context_menu.h.

References CONTEXT_MENU::m_selected.

125  {
126  return m_selected;
127  }
int m_selected
Stores the id number of selected item.
Definition: context_menu.h:216
TOOL_MANAGER * CONTEXT_MENU::getToolManager ( )
protectedinherited

Returns an instance of TOOL_MANAGER class.

Definition at line 275 of file context_menu.cpp.

References TOOL_BASE::GetManager(), and CONTEXT_MENU::m_tool.

Referenced by update(), and CONTEXT_MENU::updateHotKeys().

276 {
277  wxASSERT( m_tool );
278  return m_tool ? m_tool->GetManager() : nullptr;
279 }
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: context_menu.h:219
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool...
Definition: tool_base.h:144
bool CONTEXT_MENU::HasEnabledItems ( ) const
inherited

Function HasEnabledItems();.

Returns true if the menu has any enabled items

Definition at line 211 of file context_menu.cpp.

212 {
213  bool hasEnabled = false;
214 
215  auto& items = GetMenuItems();
216 
217  for( auto item : items )
218  {
219  if( item->IsEnabled() && !item->IsSeparator() )
220  {
221  hasEnabled = true;
222  break;
223  }
224  }
225 
226  return hasEnabled;
227 }
void CONTEXT_MENU::SetIcon ( const BITMAP_OPAQUE aIcon)
inherited

Function SetIcon() Assigns an icon for the entry.

Parameters
aIconis the icon to be assigned. NULL is used to remove icon.

Definition at line 73 of file context_menu.cpp.

References CONTEXT_MENU::m_icon.

Referenced by GRID_MENU::GRID_MENU(), ALIGN_DISTRIBUTE_TOOL::Init(), PAD_CONTEXT_MENU(), TRACK_VIA_SIZE_MENU::TRACK_VIA_SIZE_MENU(), and ZOOM_MENU::ZOOM_MENU().

74 {
75  m_icon = aIcon;
76 }
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: context_menu.h:231
void CONTEXT_MENU::SetTitle ( const wxString &  aTitle)
overrideinherited

Function SetTitle() Sets title for the context menu.

The title is shown as a text label shown on the top of the menu.

Parameters
aTitleis the new title.

Definition at line 86 of file context_menu.cpp.

References CONTEXT_MENU::DisplayTitle(), CONTEXT_MENU::m_title, and CONTEXT_MENU::m_titleDisplayed.

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), SELECTION_TOOL::disambiguationMenu(), GRID_MENU::GRID_MENU(), ALIGN_DISTRIBUTE_TOOL::Init(), PAD_CONTEXT_MENU(), ROUTER_TOOL_MENU::ROUTER_TOOL_MENU(), TRACK_WIDTH_MENU::TRACK_WIDTH_MENU(), TUNER_TOOL_MENU::TUNER_TOOL_MENU(), and ZOOM_MENU::ZOOM_MENU().

87 {
88  // Unfortunately wxMenu::SetTitle() does not work very well, so this is an alternative version
89  m_title = aTitle;
90 
91  // Update the menu title
92  if( m_titleDisplayed )
93  DisplayTitle( true );
94 }
void DisplayTitle(bool aDisplay=true)
Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.
wxString m_title
Menu title
Definition: context_menu.h:213
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: context_menu.h:210
void CONTEXT_MENU::SetTool ( TOOL_INTERACTIVE aTool)
inherited

Function SetTool() Sets a tool that is the creator of the menu.

Parameters
aToolis the tool that created the menu.

Definition at line 248 of file context_menu.cpp.

References CONTEXT_MENU::m_tool, and CONTEXT_MENU::runOnSubmenus().

Referenced by CONDITIONAL_MENU::Generate(), and TOOL_INTERACTIVE::SetContextMenu().

249 {
250  m_tool = aTool;
251  runOnSubmenus( std::bind( &CONTEXT_MENU::SetTool, _1, aTool ) );
252 }
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: context_menu.h:219
void runOnSubmenus(std::function< void(CONTEXT_MENU *)> aFunction)
Runs a function on the menu and all its submenus.
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
void PAD_CONTEXT_MENU::update ( )
inlineoverrideprivatevirtual

Update menu state stub.

It is called before a menu is shown, in order to update its state. Here you can tick current settings, enable/disable entries, etc.

Reimplemented from CONTEXT_MENU.

Definition at line 131 of file pad_tool.cpp.

References PCB_ACTIONS::applyPadSettings, PCB_ACTIONS::copyPadSettings, getEnablements(), CONTEXT_MENU::getMenuId(), TOOL_MANAGER::GetTool(), CONTEXT_MENU::getToolManager(), and PCB_ACTIONS::pushPadSettings.

132  {
133  auto selTool = getToolManager()->GetTool<SELECTION_TOOL>();
134  const SELECTION& selection = selTool->GetSelection();
135 
136  auto enablements = getEnablements( selection );
137 
138  Enable( getMenuId( PCB_ACTIONS::applyPadSettings ), enablements.canImport );
139  Enable( getMenuId( PCB_ACTIONS::copyPadSettings ), enablements.canExport );
140  Enable( getMenuId( PCB_ACTIONS::pushPadSettings ), enablements.canPush );
141  }
Class SELECTION_TOOL.
ENABLEMENTS getEnablements(const SELECTION &aSelection)
Definition: pad_tool.cpp:109
static TOOL_ACTION pushPadSettings
Copy the current pad's settings to other pads in the module or on the board.
Definition: pcb_actions.h:326
static TOOL_ACTION copyPadSettings
Copy the selected pad's settings to the board design settings.
Definition: pcb_actions.h:320
static TOOL_ACTION applyPadSettings
Copy the pad settings in the board design settings to the selected pad.
Definition: pcb_actions.h:323
static int getMenuId(const TOOL_ACTION &aAction)
Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.
Definition: context_menu.h:155
TOOL_MANAGER * getToolManager()
Returns an instance of TOOL_MANAGER class.
void CONTEXT_MENU::UpdateAll ( )
inherited

Function UpdateAll() Runs update handlers for the menu and its submenus.

Definition at line 230 of file context_menu.cpp.

References Format(), CONTEXT_MENU::m_tool, CONTEXT_MENU::runOnSubmenus(), CONTEXT_MENU::update(), and CONTEXT_MENU::updateHotKeys().

231 {
232  try
233  {
234  update();
235  }
236  catch( std::exception& e )
237  {
238  wxLogDebug( wxString::Format( "CONTEXT_MENU update handler exception: %s", e.what() ) );
239  }
240 
241  if( m_tool )
242  updateHotKeys();
243 
244  runOnSubmenus( std::bind( &CONTEXT_MENU::UpdateAll, _1 ) );
245 }
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: context_menu.h:219
void updateHotKeys()
Updates hot key settings for TOOL_ACTIONs in this menu.
virtual void update()
Update menu state stub.
Definition: context_menu.h:164
void runOnSubmenus(std::function< void(CONTEXT_MENU *)> aFunction)
Runs a function on the menu and all its submenus.
void UpdateAll()
Function UpdateAll() Runs update handlers for the menu and its submenus.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

Member Data Documentation

bool PAD_CONTEXT_MENU::m_editingFootprint
private

Definition at line 143 of file pad_tool.cpp.

Referenced by create(), and PAD_CONTEXT_MENU().

SHOW_FUNCTOR PAD_CONTEXT_MENU::m_haveGlobalPadSettings
private

Definition at line 144 of file pad_tool.cpp.

Referenced by create(), and getEnablements().


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