KiCad PCB EDA Suite
ROUTER_TOOL_MENU Class Reference
Inheritance diagram for ROUTER_TOOL_MENU:
ACTION_MENU

Public Member Functions

 ROUTER_TOOL_MENU (PCB_EDIT_FRAME &aFrame, PNS::ROUTER_MODE aMode)
 
void SetTitle (const wxString &aTitle) override
 Function SetTitle() Sets title for the 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, bool aIsCheckmarkEntry=false)
 Function Add() Adds an entry to the menu, basing on the TOOL_ACTION object. More...
 
wxMenuItem * Add (ACTION_MENU *aMenu)
 Function Add() Adds an action 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...
 
ACTION_MENUClone () const
 Creates a deep, recursive copy of this ACTION_MENU. More...
 

Public Attributes

bool m_Dirty
 

Menu requires updating before display.

More...
 

Protected Member Functions

TOOL_MANAGERgetToolManager () const
 

Returns an instance of TOOL_MANAGER class.

More...
 
virtual void update ()
 Update menu state stub. More...
 
virtual OPT_TOOL_EVENT eventHandler (const wxMenuEvent &)
 Event handler stub. More...
 
void copyFrom (const ACTION_MENU &aMenu)
 Copies another menus data to this instance. More...
 
wxMenuItem * appendCopy (const wxMenuItem *aSource)
 Function appendCopy Appends a copy of wxMenuItem. More...
 
void setupEvents ()
 

Initializes handlers for events.

More...
 
void onMenuEvent (wxMenuEvent &aEvent)
 

The default menu event handler.

More...
 
void updateHotKeys ()
 

Updates hot key settings for TOOL_ACTIONs in this menu.

More...
 
void runEventHandlers (const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
 

Traverses the submenus tree looking for a submenu capable of handling a particular menu event.

More...
 
void runOnSubmenus (std::function< void(ACTION_MENU *)> aFunction)
 

Runs a function on the menu and all its submenus.

More...
 
OPT_TOOL_EVENT findToolAction (int aId)
 

Checks if any of submenus contains a TOOL_ACTION with a specific ID.

More...
 

Static Protected Member Functions

static int getMenuId (const TOOL_ACTION &aAction)
 

Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.

More...
 

Protected Attributes

bool m_titleDisplayed
 

Flag indicating that the menu title was set up.

More...
 
wxString m_title
 

Menu title

More...
 
int m_selected
 

Stores the id number of selected item.

More...
 
TOOL_INTERACTIVEm_tool
 

Creator of the menu

More...
 
std::map< int, const TOOL_ACTION * > m_toolActions
 

Associates tool actions with menu item IDs. Non-owning.

More...
 
std::list< ACTION_MENU * > m_submenus
 

List of submenus.

More...
 
const BITMAP_OPAQUE * m_icon
 

Optional icon

More...
 

Static Protected Attributes

static const int ACTION_ID = 20000
 

Menu items with ID higher than that are considered TOOL_ACTIONs

More...
 

Private Member Functions

ACTION_MENUcreate () const override
 

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

More...
 

Private Attributes

PCB_EDIT_FRAMEm_frame
 
PNS::ROUTER_MODE m_mode
 
TRACK_WIDTH_MENU m_trackViaMenu
 
DIFF_PAIR_MENU m_diffPairMenu
 
ZOOM_MENU m_zoomMenu
 
GRID_MENU m_gridMenu
 

Detailed Description

Definition at line 426 of file router_tool.cpp.

Constructor & Destructor Documentation

◆ ROUTER_TOOL_MENU()

ROUTER_TOOL_MENU::ROUTER_TOOL_MENU ( PCB_EDIT_FRAME aFrame,
PNS::ROUTER_MODE  aMode 
)
inline

Definition at line 429 of file router_tool.cpp.

429  :
430  m_frame( aFrame ), m_mode( aMode ), m_trackViaMenu( aFrame ), m_diffPairMenu( aFrame ),
431  m_zoomMenu( &aFrame ), m_gridMenu( &aFrame )
432  {
433  SetTitle( _( "Interactive Router" ) );
434 
436 
437  AppendSeparator();
438 
439  Add( ACT_NewTrack );
440  Add( ACT_EndTrack );
442 
445 
446 // Add( ACT_AutoEndRoute ); // fixme: not implemented yet. Sorry.
453 
454  AppendSeparator();
455 
456  Add( &m_trackViaMenu );
457 
459  Add( &m_diffPairMenu );
460 
462 
463  AppendSeparator();
464 
465  Add( &m_zoomMenu );
466  Add( &m_gridMenu );
467  }
static const TOOL_ACTION ACT_NewTrack("pcbnew.InteractiveRouter.NewTrack", AS_CONTEXT, TOOL_ACTION::LegacyHotKey(HK_ADD_NEW_TRACK), _("New Track"), _("Starts laying a new track."), add_tracks_xpm)
static TOOL_ACTION dragFreeAngle
Definition: pcb_actions.h:133
static TOOL_ACTION cancelInteractive
Definition: actions.h:45
static const TOOL_ACTION ACT_PlaceBlindVia("pcbnew.InteractiveRouter.PlaceBlindVia", AS_CONTEXT, TOOL_ACTION::LegacyHotKey(HK_ADD_BLIND_BURIED_VIA), _("Place Blind/Buried Via"), _("Adds a blind or buried via at the end of currently routed track."), via_buried_xpm, AF_NONE,(void *) VIA_ACTION_FLAGS::BLIND_VIA)
static TOOL_ACTION drag45Degree
Definition: pcb_actions.h:132
static const TOOL_ACTION ACT_PlaceThroughVia("pcbnew.InteractiveRouter.PlaceVia", AS_CONTEXT, TOOL_ACTION::LegacyHotKey(HK_ADD_THROUGH_VIA), _("Place Through Via"), _("Adds a through-hole via at the end of currently routed track."), via_xpm, AF_NONE,(void *) VIA_ACTION_FLAGS::VIA)
GRID_MENU m_gridMenu
PNS::ROUTER_MODE m_mode
static const TOOL_ACTION ACT_SwitchPosture("pcbnew.InteractiveRouter.SwitchPosture", AS_CONTEXT, TOOL_ACTION::LegacyHotKey(HK_SWITCH_TRACK_POSTURE), _("Switch Track Posture"), _("Switches posture of the currently routed track."), change_entry_orient_xpm)
ZOOM_MENU m_zoomMenu
PCB_EDIT_FRAME & m_frame
static const TOOL_ACTION ACT_PlaceMicroVia("pcbnew.InteractiveRouter.PlaceMicroVia", AS_CONTEXT, TOOL_ACTION::LegacyHotKey(HK_ADD_MICROVIA), _("Place Microvia"), _("Adds a microvia at the end of currently routed track."), via_microvia_xpm, AF_NONE,(void *) VIA_ACTION_FLAGS::MICROVIA)
static TOOL_ACTION breakTrack
Break a single track into two segments at the cursor.
Definition: pcb_actions.h:127
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:96
static TOOL_ACTION routerActivateSettingsDialog
Activation of the Push and Shove settings dialogs.
Definition: pcb_actions.h:180
static const TOOL_ACTION ACT_SelLayerAndPlaceThroughVia("pcbnew.InteractiveRouter.SelLayerAndPlaceVia", AS_CONTEXT, TOOL_ACTION::LegacyHotKey(HK_SEL_LAYER_AND_ADD_THROUGH_VIA), _("Select Layer and Place Through Via..."), _("Select a layer, then add a through-hole via at the end of currently routed track."), select_w_layer_xpm, AF_NONE,(void *)(VIA_ACTION_FLAGS::VIA|VIA_ACTION_FLAGS::SELECT_LAYER))
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon=NULL)
Function Add() Adds an entry to the menu.
static const TOOL_ACTION ACT_EndTrack("pcbnew.InteractiveRouter.EndTrack", AS_CONTEXT, WXK_END, _("End Track"), _("Stops laying the current track."), checked_ok_xpm)
static const TOOL_ACTION ACT_SelLayerAndPlaceBlindVia("pcbnew.InteractiveRouter.SelLayerAndPlaceBlindVia", AS_CONTEXT, TOOL_ACTION::LegacyHotKey(HK_SEL_LAYER_AND_ADD_BLIND_BURIED_VIA), _("Select Layer and Place Blind/Buried Via..."), _("Select a layer, then add a blind or buried via at the end of currently routed track."), select_w_layer_xpm, AF_NONE,(void *)(VIA_ACTION_FLAGS::BLIND_VIA|VIA_ACTION_FLAGS::SELECT_LAYER))
DIFF_PAIR_MENU m_diffPairMenu
TRACK_WIDTH_MENU m_trackViaMenu

References ACT_EndTrack, ACT_NewTrack, ACT_PlaceBlindVia, ACT_PlaceMicroVia, ACT_PlaceThroughVia, ACT_SelLayerAndPlaceBlindVia, ACT_SelLayerAndPlaceThroughVia, ACT_SwitchPosture, ACTION_MENU::Add(), PCB_ACTIONS::breakTrack, ACTIONS::cancelInteractive, PCB_ACTIONS::drag45Degree, PCB_ACTIONS::dragFreeAngle, m_diffPairMenu, m_gridMenu, m_mode, m_trackViaMenu, m_zoomMenu, PNS::PNS_MODE_ROUTE_DIFF_PAIR, PCB_ACTIONS::routerActivateSettingsDialog, and ACTION_MENU::SetTitle().

Referenced by create().

Member Function Documentation

◆ Add() [1/3]

wxMenuItem * ACTION_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 144 of file action_menu.cpp.

145 {
146 #ifdef DEBUG
147  if( FindItem( aId ) != NULL )
148  wxLogWarning( wxT( "Adding more than one menu entry with the same ID may result in"
149  "undefined behaviour" ) );
150 #endif
151 
152  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
153  set_wxMenuIcon( item, aIcon );
154 
155  return Append( item );
156 }
static void set_wxMenuIcon(wxMenuItem *aMenu, const BITMAP_OPAQUE *aIcon)
Definition: action_menu.cpp:68

References set_wxMenuIcon().

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

◆ Add() [2/3]

wxMenuItem * ACTION_MENU::Add ( const TOOL_ACTION aAction,
bool  aIsCheckmarkEntry = false 
)
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 159 of file action_menu.cpp.

160 {
162  const BITMAP_OPAQUE* icon = aAction.GetIcon();
163 
164  wxMenuItem* item = new wxMenuItem( this, getMenuId( aAction ), aAction.GetMenuItem(),
165  aAction.GetDescription(),
166  aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
167 
168  set_wxMenuIcon( item, icon );
169 
170  m_toolActions[getMenuId( aAction )] = &aAction;
171 
172  wxMenuItem* i = Append( item );
173  return i;
174 }
static int getMenuId(const TOOL_ACTION &aAction)
Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.
Definition: action_menu.h:156
const wxString & GetDescription() const
Definition: tool_action.h:115
static void set_wxMenuIcon(wxMenuItem *aMenu, const BITMAP_OPAQUE *aIcon)
Definition: action_menu.cpp:68
const BITMAP_OPAQUE * GetIcon() const
Returns an icon associated with the action.
Definition: tool_action.h:156
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:226
const wxString & GetMenuItem() const
Definition: tool_action.h:105
size_t i
Definition: json11.cpp:597

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

◆ Add() [3/3]

wxMenuItem * ACTION_MENU::Add ( ACTION_MENU aMenu)
inherited

Function Add() Adds an action 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.

Definition at line 177 of file action_menu.cpp.

178 {
179  ACTION_MENU* menuCopy = aMenu->Clone();
180  m_submenus.push_back( menuCopy );
181 
182  wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), "Set a title for ACTION_MENU using SetTitle()" );
183 
184  if( aMenu->m_icon )
185  {
186  wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->m_title );
187  set_wxMenuIcon( newItem, aMenu->m_icon );
188  newItem->SetSubMenu( menuCopy );
189  return Append( newItem );
190  }
191  else
192  {
193  return AppendSubMenu( menuCopy, menuCopy->m_title );
194  }
195 }
Class ACTION_MENU.
Definition: action_menu.h:43
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: action_menu.h:232
static void set_wxMenuIcon(wxMenuItem *aMenu, const BITMAP_OPAQUE *aIcon)
Definition: action_menu.cpp:68
wxString m_title
Menu title
Definition: action_menu.h:214
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:229
ACTION_MENU * Clone() const
Creates a deep, recursive copy of this ACTION_MENU.

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

◆ appendCopy()

wxMenuItem * ACTION_MENU::appendCopy ( const wxMenuItem *  aSource)
protectedinherited

Function appendCopy Appends a copy of wxMenuItem.

Definition at line 475 of file action_menu.cpp.

476 {
477  wxMenuItem* newItem = new wxMenuItem( this, aSource->GetId(), aSource->GetItemLabel(),
478  aSource->GetHelp(), aSource->GetKind() );
479 
480  bool useImagesInMenus;
481  Pgm().CommonSettings()->Read( USE_ICONS_IN_MENUS_KEY, &useImagesInMenus );
482 
483  if( aSource->GetKind() == wxITEM_NORMAL && useImagesInMenus )
484  newItem->SetBitmap( aSource->GetBitmap() );
485 
486  if( aSource->IsSubMenu() )
487  {
488  ACTION_MENU* menu = dynamic_cast<ACTION_MENU*>( aSource->GetSubMenu() );
489  wxASSERT_MSG( menu, "Submenus are expected to be a ACTION_MENU" );
490 
491  if( menu )
492  {
493  ACTION_MENU* menuCopy = menu->Clone();
494  newItem->SetSubMenu( menuCopy );
495  m_submenus.push_back( menuCopy );
496  }
497  }
498 
499  // wxMenuItem has to be added before enabling/disabling or checking
500  Append( newItem );
501 
502  if( aSource->IsCheckable() )
503  newItem->Check( aSource->IsChecked() );
504 
505  newItem->Enable( aSource->IsEnabled() );
506 
507  return newItem;
508 }
Class ACTION_MENU.
Definition: action_menu.h:43
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:229
ACTION_MENU * Clone() const
Creates a deep, recursive copy of this ACTION_MENU.
VTBL_ENTRY wxConfigBase * CommonSettings() const
Definition: pgm_base.h:190
#define USE_ICONS_IN_MENUS_KEY
Definition: pgm_base.h:45

References ACTION_MENU::Clone(), PGM_BASE::CommonSettings(), ACTION_MENU::m_submenus, Pgm(), and USE_ICONS_IN_MENUS_KEY.

Referenced by ACTION_MENU::copyFrom().

◆ Clear()

void ACTION_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 198 of file action_menu.cpp.

199 {
200  m_titleDisplayed = false;
201 
202  for( int i = GetMenuItemCount() - 1; i >= 0; --i )
203  Destroy( FindItemByPosition( i ) );
204 
205  m_toolActions.clear();
206  m_submenus.clear();
207 
208  wxASSERT( GetMenuItemCount() == 0 );
209 }
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: action_menu.h:211
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:229
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:226
size_t i
Definition: json11.cpp:597

References i, ACTION_MENU::m_submenus, ACTION_MENU::m_titleDisplayed, and ACTION_MENU::m_toolActions.

Referenced by ACTION_MENU::Clone(), CONDITIONAL_MENU::Evaluate(), TRACK_WIDTH_MENU::update(), and DIFF_PAIR_MENU::update().

◆ Clone()

ACTION_MENU * ACTION_MENU::Clone ( ) const
inherited

Creates a deep, recursive copy of this ACTION_MENU.

Definition at line 256 of file action_menu.cpp.

257 {
258  ACTION_MENU* clone = create();
259  clone->Clear();
260  clone->copyFrom( *this );
261  return clone;
262 }
Class ACTION_MENU.
Definition: action_menu.h:43
virtual ACTION_MENU * create() const
Returns an instance of this class. It has to be overridden in inheriting classes.
void copyFrom(const ACTION_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).

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

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

◆ copyFrom()

void ACTION_MENU::copyFrom ( const ACTION_MENU aMenu)
protectedinherited

Copies another menus data to this instance.

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

Definition at line 457 of file action_menu.cpp.

458 {
459  m_icon = aMenu.m_icon;
460  m_title = aMenu.m_title;
462  m_selected = -1; // aMenu.m_selected;
463  m_tool = aMenu.m_tool;
465 
466  // Copy all menu entries
467  for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
468  {
469  wxMenuItem* item = aMenu.FindItemByPosition( i );
470  appendCopy( item );
471  }
472 }
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: action_menu.h:211
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: action_menu.h:232
wxString m_title
Menu title
Definition: action_menu.h:214
int m_selected
Stores the id number of selected item.
Definition: action_menu.h:217
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:220
wxMenuItem * appendCopy(const wxMenuItem *aSource)
Function appendCopy Appends a copy of wxMenuItem.
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:226
size_t i
Definition: json11.cpp:597

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

Referenced by ACTION_MENU::Clone().

◆ create()

ACTION_MENU* ROUTER_TOOL_MENU::create ( ) const
inlineoverrideprivatevirtual

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

Reimplemented from ACTION_MENU.

Definition at line 470 of file router_tool.cpp.

471  {
472  return new ROUTER_TOOL_MENU( m_frame, m_mode );
473  }
ROUTER_TOOL_MENU(PCB_EDIT_FRAME &aFrame, PNS::ROUTER_MODE aMode)
PNS::ROUTER_MODE m_mode
PCB_EDIT_FRAME & m_frame

References m_frame, m_mode, and ROUTER_TOOL_MENU().

◆ DisplayTitle()

void ACTION_MENU::DisplayTitle ( bool  aDisplay = true)
inherited

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

Definition at line 107 of file action_menu.cpp.

108 {
109  if( ( !aDisplay || m_title.IsEmpty() ) && m_titleDisplayed )
110  {
111  // Destroy the menu entry keeping the title..
112  wxMenuItem* item = FindItemByPosition( 0 );
113  wxASSERT( item->GetItemLabelText() == GetTitle() );
114  Destroy( item );
115  // ..and separator
116  item = FindItemByPosition( 0 );
117  wxASSERT( item->IsSeparator() );
118  Destroy( item );
119  m_titleDisplayed = false;
120  }
121 
122  else if( aDisplay && !m_title.IsEmpty() )
123  {
124  if( m_titleDisplayed )
125  {
126  // Simply update the title
127  FindItemByPosition( 0 )->SetItemLabel( m_title );
128  }
129  else
130  {
131  // Add a separator and a menu entry to display the title
132  InsertSeparator( 0 );
133  Insert( 0, new wxMenuItem( this, wxID_NONE, m_title, wxEmptyString, wxITEM_NORMAL ) );
134 
135  if( m_icon )
136  set_wxMenuIcon( FindItemByPosition( 0 ), m_icon );
137 
138  m_titleDisplayed = true;
139  }
140  }
141 }
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: action_menu.h:211
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: action_menu.h:232
static void set_wxMenuIcon(wxMenuItem *aMenu, const BITMAP_OPAQUE *aIcon)
Definition: action_menu.cpp:68
wxString m_title
Menu title
Definition: action_menu.h:214

References ACTION_MENU::m_icon, ACTION_MENU::m_title, ACTION_MENU::m_titleDisplayed, and set_wxMenuIcon().

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), ACTION_MENU::SetTitle(), and TUNER_TOOL_MENU::TUNER_TOOL_MENU().

◆ eventHandler()

virtual OPT_TOOL_EVENT ACTION_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 DIFF_PAIR_MENU, TRACK_WIDTH_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 173 of file action_menu.h.

174  {
175  return OPT_TOOL_EVENT();
176  }
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:486

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

◆ findToolAction()

OPT_TOOL_EVENT ACTION_MENU::findToolAction ( int  aId)
protectedinherited

Checks if any of submenus contains a TOOL_ACTION with a specific ID.

Definition at line 434 of file action_menu.cpp.

435 {
436  OPT_TOOL_EVENT evt;
437 
438  auto findFunc = [&]( ACTION_MENU* m ) {
439  if( evt )
440  return;
441 
442  const auto it = m->m_toolActions.find( aId );
443 
444  if( it != m->m_toolActions.end() )
445  evt = it->second->MakeEvent();
446  };
447 
448  findFunc( this );
449 
450  if( !evt )
451  runOnSubmenus( findFunc );
452 
453  return evt;
454 }
Class ACTION_MENU.
Definition: action_menu.h:43
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Runs a function on the menu and all its submenus.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:486

References ACTION_MENU::runOnSubmenus().

Referenced by ACTION_MENU::onMenuEvent().

◆ getMenuId()

static int ACTION_MENU::getMenuId ( const TOOL_ACTION aAction)
inlinestaticprotectedinherited

Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.

Definition at line 156 of file action_menu.h.

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

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

Referenced by ACTION_MENU::Add(), and PAD_CONTEXT_MENU::update().

◆ GetSelected()

int ACTION_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 action menu.

Definition at line 121 of file action_menu.h.

122  {
123  return m_selected;
124  }
int m_selected
Stores the id number of selected item.
Definition: action_menu.h:217

References ACTION_MENU::m_selected.

Referenced by LIB_EDIT_FRAME::OnViewEntryDoc().

◆ getToolManager()

TOOL_MANAGER * ACTION_MENU::getToolManager ( ) const
protectedinherited

Returns an instance of TOOL_MANAGER class.

Definition at line 276 of file action_menu.cpp.

277 {
278  wxASSERT( m_tool );
279  return m_tool ? m_tool->GetManager() : nullptr;
280 }
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:144
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:220

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

Referenced by ACTION_MENU::onMenuEvent(), BUS_UNFOLD_MENU::update(), PAD_CONTEXT_MENU::update(), SYMBOL_UNIT_MENU::update(), and ACTION_MENU::updateHotKeys().

◆ HasEnabledItems()

bool ACTION_MENU::HasEnabledItems ( ) const
inherited

Function HasEnabledItems();.

Returns true if the menu has any enabled items

Definition at line 212 of file action_menu.cpp.

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

◆ onMenuEvent()

void ACTION_MENU::onMenuEvent ( wxMenuEvent &  aEvent)
protectedinherited

The default menu event handler.

Definition at line 317 of file action_menu.cpp.

318 {
319  OPT_TOOL_EVENT evt;
320  wxString menuText;
321 
322  wxEventType type = aEvent.GetEventType();
323 
324  if( type == wxEVT_MENU_OPEN && m_Dirty )
325  {
326  getToolManager()->RunAction( ACTIONS::updateMenu, true, this );
327  aEvent.Skip();
328  return;
329  }
330 
331  // When the currently chosen item in the menu is changed, an update event is issued.
332  // For example, the selection tool can use this to dynamically highlight the current item
333  // from selection clarification popup.
334  else if( type == wxEVT_MENU_HIGHLIGHT )
335  evt = TOOL_EVENT( TC_COMMAND, TA_CONTEXT_MENU_UPDATE, aEvent.GetId() );
336 
337  // One of menu entries was selected..
338  else if( type == wxEVT_COMMAND_MENU_SELECTED )
339  {
340  // Store the selected position, so it can be checked by the tools
341  m_selected = aEvent.GetId();
342 
343  ACTION_MENU* parent = dynamic_cast<ACTION_MENU*>( GetParent() );
344 
345  while( parent )
346  {
347  parent->m_selected = m_selected;
348  parent = dynamic_cast<ACTION_MENU*>( parent->GetParent() );
349  }
350 
351  // Check if there is a TOOL_ACTION for the given ID
352  if( m_selected >= ACTION_ID )
353  evt = findToolAction( m_selected );
354 
355  if( !evt )
356  {
357 #ifdef __WINDOWS__
358  if( !evt )
359  {
360  // Try to find the submenu which holds the selected item
361  wxMenu* menu = nullptr;
362  FindItem( m_selected, &menu );
363 
364  // This conditional compilation is probably not needed.
365  // It will be removed later, for the Kicad V 6.x version.
366  // But in "old" 3.0 version, the "&& menu != this" contition was added to avoid hang
367  // This hang is no longer encountered in wxWidgets 3.0.4 version, and this condition is no longer needed.
368  // And in 3.1.2, we have to remove it, as "menu != this" never happens
369  // ("menu != this" always happens in 3.1.1 and older!).
370  #if wxCHECK_VERSION(3, 1, 2)
371  if( menu )
372  #else
373  if( menu && menu != this )
374  #endif
375  {
376  ACTION_MENU* cxmenu = static_cast<ACTION_MENU*>( menu );
377  evt = cxmenu->eventHandler( aEvent );
378  }
379  }
380 #else
381  if( !evt )
382  runEventHandlers( aEvent, evt );
383 #endif
384 
385  // Handling non-action menu entries (e.g. items in clarification list)
386  if( !evt && m_selected < wxID_LOWEST )
387  {
388  menuText = GetLabelText( aEvent.GetId() );
390  &menuText );
391  }
392  }
393  }
394 
395  // forward the action/update event to the TOOL_MANAGER
396  // clients that don't supply a tool will have to check GetSelected() themselves
397  if( evt && m_tool )
398  {
399  //aEvent.StopPropagation();
400  m_tool->GetManager()->ProcessEvent( *evt );
401  }
402  else
403  {
404  aEvent.Skip();
405  }
406 }
OPT_TOOL_EVENT findToolAction(int aId)
Checks if any of submenus contains a TOOL_ACTION with a specific ID.
Class ACTION_MENU.
Definition: action_menu.h:43
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
void runEventHandlers(const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
Traverses the submenus tree looking for a submenu capable of handling a particular menu event.
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:144
virtual OPT_TOOL_EVENT eventHandler(const wxMenuEvent &)
Event handler stub.
Definition: action_menu.h:173
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
Class TOOL_EVENT.
Definition: tool_event.h:167
int m_selected
Stores the id number of selected item.
Definition: action_menu.h:217
static const int ACTION_ID
Menu items with ID higher than that are considered TOOL_ACTIONs
Definition: action_menu.h:223
static TOOL_ACTION updateMenu
Definition: actions.h:49
All active tools
Definition: tool_event.h:143
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:220
bool m_Dirty
Menu requires updating before display.
Definition: action_menu.h:146
TOOL_MANAGER * getToolManager() const
Returns an instance of TOOL_MANAGER class.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:486

References ACTION_MENU::ACTION_ID, AS_GLOBAL, ACTION_MENU::eventHandler(), ACTION_MENU::findToolAction(), TOOL_BASE::GetManager(), ACTION_MENU::getToolManager(), ACTION_MENU::m_Dirty, ACTION_MENU::m_selected, ACTION_MENU::m_tool, TOOL_MANAGER::ProcessEvent(), TOOL_MANAGER::RunAction(), ACTION_MENU::runEventHandlers(), TA_CONTEXT_MENU_CHOICE, TA_CONTEXT_MENU_UPDATE, TC_COMMAND, and ACTIONS::updateMenu.

Referenced by ACTION_MENU::setupEvents().

◆ runEventHandlers()

void ACTION_MENU::runEventHandlers ( const wxMenuEvent &  aMenuEvent,
OPT_TOOL_EVENT aToolEvent 
)
protectedinherited

Traverses the submenus tree looking for a submenu capable of handling a particular menu event.

In case it is handled, it is returned the aToolEvent parameter.

Definition at line 409 of file action_menu.cpp.

410 {
411  aToolEvent = eventHandler( aMenuEvent );
412 
413  if( !aToolEvent )
414  runOnSubmenus( std::bind( &ACTION_MENU::runEventHandlers, _1, aMenuEvent, aToolEvent ) );
415 }
void runEventHandlers(const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
Traverses the submenus tree looking for a submenu capable of handling a particular menu event.
virtual OPT_TOOL_EVENT eventHandler(const wxMenuEvent &)
Event handler stub.
Definition: action_menu.h:173
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Runs a function on the menu and all its submenus.

References ACTION_MENU::eventHandler(), and ACTION_MENU::runOnSubmenus().

Referenced by ACTION_MENU::onMenuEvent().

◆ runOnSubmenus()

void ACTION_MENU::runOnSubmenus ( std::function< void(ACTION_MENU *)>  aFunction)
protectedinherited

Runs a function on the menu and all its submenus.

Definition at line 418 of file action_menu.cpp.

419 {
420  try
421  {
422  std::for_each( m_submenus.begin(), m_submenus.end(), [&]( ACTION_MENU* m ) {
423  aFunction( m );
424  m->runOnSubmenus( aFunction );
425  } );
426  }
427  catch( std::exception& e )
428  {
429  wxLogDebug( wxString::Format( "ACTION_MENU runOnSubmenus exception: %s", e.what() ) );
430  }
431 }
Class ACTION_MENU.
Definition: action_menu.h:43
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:229
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

References Format(), and ACTION_MENU::m_submenus.

Referenced by ACTION_MENU::findToolAction(), ACTION_MENU::runEventHandlers(), ACTION_MENU::SetTool(), and ACTION_MENU::UpdateAll().

◆ SetIcon()

◆ SetTitle()

void ACTION_MENU::SetTitle ( const wxString &  aTitle)
overrideinherited

Function SetTitle() Sets title for the menu.

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

Parameters
aTitleis the new title.

Definition at line 96 of file action_menu.cpp.

97 {
98  // Unfortunately wxMenu::SetTitle() does not work very well, so this is an alternative version
99  m_title = aTitle;
100 
101  // Update the menu title
102  if( m_titleDisplayed )
103  DisplayTitle( true );
104 }
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: action_menu.h:211
wxString m_title
Menu title
Definition: action_menu.h:214
void DisplayTitle(bool aDisplay=true)
Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.

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

Referenced by BUS_UNFOLD_MENU::BUS_UNFOLD_MENU(), DIFF_PAIR_MENU::DIFF_PAIR_MENU(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), GRID_MENU::GRID_MENU(), ALIGN_DISTRIBUTE_TOOL::Init(), PAD_CONTEXT_MENU::PAD_CONTEXT_MENU(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), ROUTER_TOOL_MENU(), SYMBOL_UNIT_MENU::SYMBOL_UNIT_MENU(), TRACK_WIDTH_MENU::TRACK_WIDTH_MENU(), TUNER_TOOL_MENU::TUNER_TOOL_MENU(), and ZOOM_MENU::ZOOM_MENU().

◆ SetTool()

void ACTION_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 249 of file action_menu.cpp.

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

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

Referenced by FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), TOOL_INTERACTIVE::SetContextMenu(), and SCH_WIRE_BUS_TOOL::UnfoldBus().

◆ setupEvents()

void ACTION_MENU::setupEvents ( )
protectedinherited

Initializes handlers for events.

Definition at line 88 of file action_menu.cpp.

89 {
90  Connect( wxEVT_MENU_OPEN, wxMenuEventHandler( ACTION_MENU::onMenuEvent ), NULL, this );
91  Connect( wxEVT_MENU_HIGHLIGHT, wxMenuEventHandler( ACTION_MENU::onMenuEvent ), NULL, this );
92  Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( ACTION_MENU::onMenuEvent ), NULL, this );
93 }
void onMenuEvent(wxMenuEvent &aEvent)
The default menu event handler.

References ACTION_MENU::onMenuEvent().

Referenced by ACTION_MENU::ACTION_MENU().

◆ update()

virtual void ACTION_MENU::update ( )
inlineprotectedvirtualinherited

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 in DIFF_PAIR_MENU, TRACK_WIDTH_MENU, SYMBOL_UNIT_MENU, ZONE_CONTEXT_MENU, SELECT_MENU, PAD_CONTEXT_MENU, BUS_UNFOLD_MENU, HIGHLIGHT_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 165 of file action_menu.h.

166  {
167  }

Referenced by ACTION_MENU::UpdateAll().

◆ UpdateAll()

void ACTION_MENU::UpdateAll ( )
inherited

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

Definition at line 231 of file action_menu.cpp.

232 {
233  try
234  {
235  update();
236  }
237  catch( std::exception& e )
238  {
239  wxLogDebug( wxString::Format( "ACTION_MENU update handler exception: %s", e.what() ) );
240  }
241 
242  if( m_tool )
243  updateHotKeys();
244 
245  runOnSubmenus( std::bind( &ACTION_MENU::UpdateAll, _1 ) );
246 }
virtual void update()
Update menu state stub.
Definition: action_menu.h:165
void UpdateAll()
Function UpdateAll() Runs update handlers for the menu and its submenus.
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:220
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Runs a function on the menu and all 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
void updateHotKeys()
Updates hot key settings for TOOL_ACTIONs in this menu.

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

Referenced by PAD_TOOL::Init(), TOOL_MENU::ShowContextMenu(), EE_SELECTION_TOOL::UpdateMenu(), and SELECTION_TOOL::UpdateMenu().

◆ updateHotKeys()

void ACTION_MENU::updateHotKeys ( )
protectedinherited

Updates hot key settings for TOOL_ACTIONs in this menu.

Definition at line 283 of file action_menu.cpp.

284 {
285  TOOL_MANAGER* toolMgr = getToolManager();
286 
287  for( std::map<int, const TOOL_ACTION*>::const_iterator it = m_toolActions.begin();
288  it != m_toolActions.end(); ++it )
289  {
290  int id = it->first;
291  const TOOL_ACTION& action = *it->second;
292  int key = toolMgr->GetHotKey( action ) & ~MD_MODIFIER_MASK;
293 
294  if( key )
295  {
296  int mod = toolMgr->GetHotKey( action ) & MD_MODIFIER_MASK;
297  int flags = 0;
298  wxMenuItem* item = FindChildItem( id );
299 
300  if( item )
301  {
302  flags |= ( mod & MD_ALT ) ? wxACCEL_ALT : 0;
303  flags |= ( mod & MD_CTRL ) ? wxACCEL_CTRL : 0;
304  flags |= ( mod & MD_SHIFT ) ? wxACCEL_SHIFT : 0;
305 
306  if( !flags )
307  flags = wxACCEL_NORMAL;
308 
309  wxAcceleratorEntry accel( flags, key, id, item );
310  item->SetAccel( &accel );
311  }
312  }
313  }
314 }
int GetHotKey(const TOOL_ACTION &aAction)
Class TOOL_MANAGER.
Definition: tool_manager.h:49
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:226
TOOL_MANAGER * getToolManager() const
Returns an instance of TOOL_MANAGER class.
Class TOOL_ACTION.
Definition: tool_action.h:46
#define mod(a, n)
Definition: greymap.cpp:24

References TOOL_MANAGER::GetHotKey(), ACTION_MENU::getToolManager(), ACTION_MENU::m_toolActions, MD_ALT, MD_CTRL, MD_MODIFIER_MASK, MD_SHIFT, and mod.

Referenced by ACTION_MENU::UpdateAll().

Member Data Documentation

◆ ACTION_ID

const int ACTION_MENU::ACTION_ID = 20000
staticprotectedinherited

Menu items with ID higher than that are considered TOOL_ACTIONs

Definition at line 223 of file action_menu.h.

Referenced by ACTION_MENU::getMenuId(), and ACTION_MENU::onMenuEvent().

◆ m_diffPairMenu

DIFF_PAIR_MENU ROUTER_TOOL_MENU::m_diffPairMenu
private

Definition at line 478 of file router_tool.cpp.

Referenced by ROUTER_TOOL_MENU().

◆ m_Dirty

bool ACTION_MENU::m_Dirty
inherited

Menu requires updating before display.

Definition at line 146 of file action_menu.h.

Referenced by ACTION_MENU::onMenuEvent(), and TOOL_MENU::ShowContextMenu().

◆ m_frame

PCB_EDIT_FRAME& ROUTER_TOOL_MENU::m_frame
private

Definition at line 475 of file router_tool.cpp.

Referenced by create().

◆ m_gridMenu

GRID_MENU ROUTER_TOOL_MENU::m_gridMenu
private

Definition at line 480 of file router_tool.cpp.

Referenced by ROUTER_TOOL_MENU().

◆ m_icon

const BITMAP_OPAQUE* ACTION_MENU::m_icon
protectedinherited

Optional icon

Definition at line 232 of file action_menu.h.

Referenced by ACTION_MENU::Add(), ACTION_MENU::copyFrom(), ACTION_MENU::DisplayTitle(), and ACTION_MENU::SetIcon().

◆ m_mode

PNS::ROUTER_MODE ROUTER_TOOL_MENU::m_mode
private

Definition at line 476 of file router_tool.cpp.

Referenced by create(), and ROUTER_TOOL_MENU().

◆ m_selected

int ACTION_MENU::m_selected
protectedinherited

Stores the id number of selected item.

Definition at line 217 of file action_menu.h.

Referenced by ACTION_MENU::copyFrom(), ACTION_MENU::GetSelected(), and ACTION_MENU::onMenuEvent().

◆ m_submenus

std::list<ACTION_MENU*> ACTION_MENU::m_submenus
protectedinherited

◆ m_title

wxString ACTION_MENU::m_title
protectedinherited

◆ m_titleDisplayed

bool ACTION_MENU::m_titleDisplayed
protectedinherited

Flag indicating that the menu title was set up.

Definition at line 211 of file action_menu.h.

Referenced by ACTION_MENU::Clear(), ACTION_MENU::copyFrom(), ACTION_MENU::DisplayTitle(), and ACTION_MENU::SetTitle().

◆ m_tool

◆ m_toolActions

std::map<int, const TOOL_ACTION*> ACTION_MENU::m_toolActions
protectedinherited

Associates tool actions with menu item IDs. Non-owning.

Definition at line 226 of file action_menu.h.

Referenced by ACTION_MENU::Add(), ACTION_MENU::Clear(), ACTION_MENU::copyFrom(), and ACTION_MENU::updateHotKeys().

◆ m_trackViaMenu

TRACK_WIDTH_MENU ROUTER_TOOL_MENU::m_trackViaMenu
private

Definition at line 477 of file router_tool.cpp.

Referenced by ROUTER_TOOL_MENU().

◆ m_zoomMenu

ZOOM_MENU ROUTER_TOOL_MENU::m_zoomMenu
private

Definition at line 479 of file router_tool.cpp.

Referenced by ROUTER_TOOL_MENU().


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