KiCad PCB EDA Suite
TRACK_WIDTH_MENU Class Reference
Inheritance diagram for TRACK_WIDTH_MENU:
TRACK_VIA_SIZE_MENU CONTEXT_MENU

Public Member Functions

 TRACK_WIDTH_MENU (const BOARD *aBoard)
 
void SetBoard (const BOARD *aBoard)
 
virtual void AppendSizes (const BOARD *aBoard)
 Function AppendSizes() Appends the list of tracks/vias (depending on the parameters passed to the constructor). More...
 
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...
 
OPT_TOOL_EVENT eventHandler (const wxMenuEvent &aEvent) override
 Event handler stub. More...
 
virtual void update () override
 Update menu state stub. More...
 
wxString getTrackDescription (unsigned int aIndex) const
 

Generates a description string for track size from BOARD_DESIGN_SETTINGS list

More...
 
wxString getViaDescription (unsigned int aIndex) const
 

Generates a description string for via size from BOARD_DESIGN_SETTINGS list

More...
 
TOOL_MANAGERgetToolManager ()
 

Returns an instance of TOOL_MANAGER class.

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...
 

Protected Attributes

const BOARD_DESIGN_SETTINGSm_designSettings
 

Source of information about track/via sizes

More...
 
bool m_tracks
 

Whether the generated menu should contain track sizes.

More...
 
bool m_vias
 

Whether the generated menu should contain via sizes.

More...
 

Private Attributes

const BOARDm_board
 

Detailed Description

Definition at line 207 of file router_tool.cpp.

Constructor & Destructor Documentation

TRACK_WIDTH_MENU::TRACK_WIDTH_MENU ( const BOARD aBoard)
inline

Definition at line 210 of file router_tool.cpp.

211  : TRACK_VIA_SIZE_MENU( true, true )
212  {
213  SetTitle( _( "Select Track/Via Width" ) );
214  SetBoard( aBoard );
215  }
void SetBoard(const BOARD *aBoard)
TRACK_VIA_SIZE_MENU(bool aTrackSizes, bool aViaSizes)
Constructor.
Definition: size_menu.cpp:29
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 134 of file context_menu.cpp.

References set_wxMenuIcon().

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

135 {
136 #ifdef DEBUG
137  if( FindItem( aId ) != NULL )
138  wxLogWarning( wxT( "Adding more than one menu entry with the same ID may result in"
139  "undefined behaviour" ) );
140 #endif
141 
142  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
143  set_wxMenuIcon( item, aIcon );
144 
145  return Append( item );
146 }
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 149 of file context_menu.cpp.

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

150 {
152  const BITMAP_OPAQUE* icon = aAction.GetIcon();
153 
154  wxMenuItem* item = new wxMenuItem( this, getMenuId( aAction ), aAction.GetMenuItem(),
155  aAction.GetDescription(), wxITEM_NORMAL );
156 
157  set_wxMenuIcon( item, icon );
158 
159  m_toolActions[getMenuId( aAction )] = &aAction;
160 
161  wxMenuItem* i = Append( item );
162  return i;
163 }
PNG memory record (file in memory).
Definition: bitmap_types.h:41
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
size_t i
Definition: json11.cpp:597
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 166 of file context_menu.cpp.

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

167 {
168  std::list<wxMenuItem*> items;
169  CONTEXT_MENU* menuCopy = aMenu->Clone();
170  m_submenus.push_back( menuCopy );
171 
172  if( aExpand )
173  {
174  for( int i = 0; i < (int) aMenu->GetMenuItemCount(); ++i )
175  {
176  wxMenuItem* item = aMenu->FindItemByPosition( i );
177  items.push_back( appendCopy( item ) );
178  }
179  }
180  else
181  {
182  wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), "Set a title for CONTEXT_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  items.push_back( Append( newItem ) );
190  }
191  else
192  {
193  items.push_back( AppendSubMenu( menuCopy, menuCopy->m_title ) );
194  }
195  }
196 
197  return items;
198 }
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.
size_t i
Definition: json11.cpp:597
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 TRACK_VIA_SIZE_MENU::AppendSizes ( const BOARD aBoard)
virtualinherited

Function AppendSizes() Appends the list of tracks/vias (depending on the parameters passed to the constructor).

Parameters
aBoardis the BOARD object whose board settings will be used to generate the list.

Definition at line 36 of file size_menu.cpp.

References BOARD::GetDesignSettings(), TRACK_VIA_SIZE_MENU::getTrackDescription(), TRACK_VIA_SIZE_MENU::getViaDescription(), i, ID_POPUP_PCB_SELECT_VIASIZE1, ID_POPUP_PCB_SELECT_WIDTH1, TRACK_VIA_SIZE_MENU::m_designSettings, TRACK_VIA_SIZE_MENU::m_tracks, BOARD_DESIGN_SETTINGS::m_TrackWidthList, TRACK_VIA_SIZE_MENU::m_vias, and BOARD_DESIGN_SETTINGS::m_ViasDimensionsList.

Referenced by TRACK_VIA_SIZE_MENU::~TRACK_VIA_SIZE_MENU().

37 {
38  wxCHECK( aBoard, /* void */ );
39 
41 
42  if( m_tracks )
43  {
44  for( unsigned i = 0; i < m_designSettings->m_TrackWidthList.size(); i++ )
45  Append( ID_POPUP_PCB_SELECT_WIDTH1 + i, getTrackDescription( i ), wxEmptyString, wxITEM_CHECK );
46  }
47 
48  if( m_tracks && m_vias )
49  AppendSeparator();
50 
51  if( m_vias )
52  {
53  for( unsigned i = 0; i < m_designSettings->m_ViasDimensionsList.size(); i++ )
54  Append( ID_POPUP_PCB_SELECT_VIASIZE1 + i, getViaDescription( i ), wxEmptyString, wxITEM_CHECK );
55  }
56 }
wxString getTrackDescription(unsigned int aIndex) const
Generates a description string for track size from BOARD_DESIGN_SETTINGS list
Definition: size_menu.cpp:125
std::vector< int > m_TrackWidthList
Track width list.
wxString getViaDescription(unsigned int aIndex) const
Generates a description string for via size from BOARD_DESIGN_SETTINGS list
Definition: size_menu.cpp:141
const BOARD_DESIGN_SETTINGS * m_designSettings
Source of information about track/via sizes
Definition: size_menu.h:65
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
bool m_vias
Whether the generated menu should contain via sizes.
Definition: size_menu.h:71
bool m_tracks
Whether the generated menu should contain track sizes.
Definition: size_menu.h:68
size_t i
Definition: json11.cpp:597
std::vector< VIA_DIMENSION > m_ViasDimensionsList
Vias size and drill list.
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 201 of file context_menu.cpp.

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

Referenced by CONTEXT_MENU::Clone().

202 {
203  m_titleDisplayed = false;
204 
205  for( int i = GetMenuItemCount() - 1; i >= 0; --i )
206  Destroy( FindItemByPosition( i ) );
207 
208  m_toolActions.clear();
209  m_submenus.clear();
210 
211  wxASSERT( GetMenuItemCount() == 0 );
212 }
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: context_menu.h:225
size_t i
Definition: json11.cpp:597
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 259 of file context_menu.cpp.

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

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

260 {
261  CONTEXT_MENU* clone = create();
262  clone->Clear();
263  clone->copyFrom( *this );
264  return clone;
265 }
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 435 of file context_menu.cpp.

References CONTEXT_MENU::appendCopy(), i, 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(), and CONTEXT_MENU::eventHandler().

436 {
437  m_icon = aMenu.m_icon;
438  m_title = aMenu.m_title;
440  m_selected = -1; // aMenu.m_selected;
441  m_tool = aMenu.m_tool;
443 
444  // Copy all menu entries
445  for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
446  {
447  wxMenuItem* item = aMenu.FindItemByPosition( i );
448  appendCopy( item );
449  }
450 }
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
size_t i
Definition: json11.cpp:597
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* TRACK_WIDTH_MENU::create ( ) const
inlineoverrideprotectedvirtual

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

Reimplemented from TRACK_VIA_SIZE_MENU.

Definition at line 239 of file router_tool.cpp.

240  {
241  return new TRACK_WIDTH_MENU( m_board );
242  }
const BOARD * m_board
TRACK_WIDTH_MENU(const BOARD *aBoard)
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_icon, CONTEXT_MENU::m_title, CONTEXT_MENU::m_titleDisplayed, and set_wxMenuIcon().

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

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 
125  if( m_icon )
126  set_wxMenuIcon( FindItemByPosition( 0 ), m_icon );
127 
128  m_titleDisplayed = true;
129  }
130  }
131 }
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: context_menu.h:231
wxString m_title
Menu title
Definition: context_menu.h:213
static void set_wxMenuIcon(wxMenuItem *aMenu, const BITMAP_OPAQUE *aIcon)
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: context_menu.h:210
OPT_TOOL_EVENT TRACK_WIDTH_MENU::eventHandler ( const wxMenuEvent &  )
inlineoverrideprotectedvirtual

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 from CONTEXT_MENU.

Definition at line 244 of file router_tool.cpp.

References ID_POPUP_PCB_SELECT_AUTO_WIDTH, ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES, ID_POPUP_PCB_SELECT_VIASIZE1, ID_POPUP_PCB_SELECT_VIASIZE16, ID_POPUP_PCB_SELECT_WIDTH1, ID_POPUP_PCB_SELECT_WIDTH16, json11::in_range(), BOARD_DESIGN_SETTINGS::m_UseConnectedTrackWidth, BOARD_DESIGN_SETTINGS::SetTrackWidthIndex(), BOARD_DESIGN_SETTINGS::SetViaSizeIndex(), PCB_ACTIONS::trackViaSizeChanged, and BOARD_DESIGN_SETTINGS::UseCustomTrackViaSize().

245  {
247  int id = aEvent.GetId();
248 
249  // On Windows, this handler can be called with a non existing event ID not existing
250  // in any menuitem.
251  // So we keep trace of in-range/out-of-range event ID
252  bool in_range = true;
253 
254  // Initial settings, to be modified below, but only if the ID exists in this menu
255  bool useConnectedTrackWidth = false;
256  bool useCustomTrackViaSize = false;
257 
259  {
260  useCustomTrackViaSize = true;
261  }
262  else if( id == ID_POPUP_PCB_SELECT_AUTO_WIDTH )
263  {
264  useConnectedTrackWidth = true;
265  }
267  {
268  bds.SetViaSizeIndex( 0 );
269  bds.SetTrackWidthIndex( 0 );
270  }
271  else if( id >= ID_POPUP_PCB_SELECT_VIASIZE1 &&
273  {
274  // via size has changed
276  }
277  else if( id >= ID_POPUP_PCB_SELECT_WIDTH1 &&
279  {
280  // track width has changed
282  }
283  else
284  {
285  in_range = false; // This event ID does not exist in the menu
286  wxASSERT_MSG( false, "OPT_TOOL_EVENT EventHandler: unexpected id" );
287  // Fix me: How to return this error as OPT_TOOL_EVENT?
288  }
289 
290  if( in_range )
291  {
292  // Update this setup only id the event ID matches the options of this menu
293  bds.m_UseConnectedTrackWidth = useConnectedTrackWidth;
294  bds.UseCustomTrackViaSize( useCustomTrackViaSize );
295  }
296 
297  return OPT_TOOL_EVENT( PCB_ACTIONS::trackViaSizeChanged.MakeEvent() );
298  }
void SetTrackWidthIndex(unsigned aIndex)
Function SetTrackWidthIndex sets the current track width list index to aIndex.
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:291
static bool in_range(long x, long lower, long upper)
Definition: json11.cpp:581
const BOARD * m_board
bool m_UseConnectedTrackWidth
if true, when creating a new track starting on an existing track, use this track width ...
void SetViaSizeIndex(unsigned aIndex)
Function SetViaSizeIndex sets the current via size list index to aIndex.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
void UseCustomTrackViaSize(bool aEnabled)
Function UseCustomTrackViaSize Enables/disables custom track/via size settings.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:465
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
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 PAD_CONTEXT_MENU::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::Clone(), CONTEXT_MENU::create(), CONTEXT_MENU::getToolManager(), CONTEXT_MENU::m_selected, CONTEXT_MENU::SetTool(), and CONTEXT_MENU::UpdateAll().

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 279 of file context_menu.cpp.

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

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

280 {
281  wxASSERT( m_tool );
282  return m_tool ? m_tool->GetManager() : nullptr;
283 }
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
wxString TRACK_VIA_SIZE_MENU::getTrackDescription ( unsigned int  aIndex) const
protectedinherited

Generates a description string for track size from BOARD_DESIGN_SETTINGS list

Definition at line 125 of file size_menu.cpp.

References g_UserUnit, TRACK_VIA_SIZE_MENU::m_designSettings, BOARD_DESIGN_SETTINGS::m_TrackWidthList, TRACK_VIA_SIZE_MENU::m_vias, and StringFromValue().

Referenced by TRACK_VIA_SIZE_MENU::AppendSizes(), TRACK_VIA_SIZE_MENU::create(), and TRACK_VIA_SIZE_MENU::update().

126 {
127  wxString desc;
128 
129  if( m_vias ) // == if( m_tracks && m_vias )
130  desc = _( "Track ");
131 
132  if( aIndex == 0 )
133  desc << _( "net class width" );
134  else
135  desc << StringFromValue( g_UserUnit, m_designSettings->m_TrackWidthList[aIndex], true );
136 
137  return desc;
138 }
std::vector< int > m_TrackWidthList
Track width list.
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:205
const BOARD_DESIGN_SETTINGS * m_designSettings
Source of information about track/via sizes
Definition: size_menu.h:65
bool m_vias
Whether the generated menu should contain via sizes.
Definition: size_menu.h:71
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:57
wxString TRACK_VIA_SIZE_MENU::getViaDescription ( unsigned int  aIndex) const
protectedinherited

Generates a description string for via size from BOARD_DESIGN_SETTINGS list

Definition at line 141 of file size_menu.cpp.

References g_UserUnit, TRACK_VIA_SIZE_MENU::m_designSettings, TRACK_VIA_SIZE_MENU::m_tracks, BOARD_DESIGN_SETTINGS::m_ViasDimensionsList, and StringFromValue().

Referenced by TRACK_VIA_SIZE_MENU::AppendSizes(), TRACK_VIA_SIZE_MENU::create(), and TRACK_VIA_SIZE_MENU::update().

142 {
143  wxString desc;
144 
145  if( m_tracks ) // == if( m_tracks && m_vias )
146  desc = _( "Via " );
147 
148  if( aIndex == 0 )
149  {
150  desc << _( "net class size" );
151  }
152  else
153  {
154  desc << StringFromValue( g_UserUnit,
155  m_designSettings->m_ViasDimensionsList[aIndex].m_Diameter, true );
156 
157  if( m_designSettings->m_ViasDimensionsList[aIndex].m_Drill <= 0 )
158  {
159  desc << _( ", drill: default" );
160  }
161  else
162  {
163  desc << _( ", drill: " ) << StringFromValue( g_UserUnit,
164  m_designSettings->m_ViasDimensionsList[aIndex].m_Drill, true );
165  }
166  }
167 
168  return desc;
169 }
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:205
const BOARD_DESIGN_SETTINGS * m_designSettings
Source of information about track/via sizes
Definition: size_menu.h:65
bool m_tracks
Whether the generated menu should contain track sizes.
Definition: size_menu.h:68
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:57
std::vector< VIA_DIMENSION > m_ViasDimensionsList
Vias size and drill list.
bool CONTEXT_MENU::HasEnabledItems ( ) const
inherited

Function HasEnabledItems();.

Returns true if the menu has any enabled items

Definition at line 215 of file context_menu.cpp.

216 {
217  bool hasEnabled = false;
218 
219  auto& items = GetMenuItems();
220 
221  for( auto item : items )
222  {
223  if( item->IsEnabled() && !item->IsSeparator() )
224  {
225  hasEnabled = true;
226  break;
227  }
228  }
229 
230  return hasEnabled;
231 }
void TRACK_WIDTH_MENU::SetBoard ( const BOARD aBoard)
inline

Definition at line 217 of file router_tool.cpp.

References ID_POPUP_PCB_SELECT_AUTO_WIDTH, ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, and ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES.

218  {
219  m_board = aBoard;
220 
221  Clear();
222 
223  Append( ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, _( "Custom Size" ),
224  wxEmptyString, wxITEM_CHECK );
225 
226  Append( ID_POPUP_PCB_SELECT_AUTO_WIDTH, _( "Use Starting Track Width" ),
227  _( "Route using the width of the starting track." ), wxITEM_CHECK );
228 
229  Append( ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES, _( "Use Net Class Values" ),
230  _( "Use track and via sizes from the net class" ), wxITEM_CHECK );
231 
232  AppendSeparator();
233 
234  // Append the list of tracks & via sizes
235  AppendSizes( aBoard );
236  }
const BOARD * m_board
virtual void AppendSizes(const BOARD *aBoard)
Function AppendSizes() Appends the list of tracks/vias (depending on the parameters passed to the con...
Definition: size_menu.cpp:36
void Clear()
Function Clear() Removes all the entries from the menu (as well as its title).
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 SELECTION_TOOL::disambiguationMenu(), GRID_MENU::GRID_MENU(), ALIGN_DISTRIBUTE_TOOL::Init(), PAD_CONTEXT_MENU::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::PAD_CONTEXT_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 252 of file context_menu.cpp.

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

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

253 {
254  m_tool = aTool;
255  runOnSubmenus( std::bind( &CONTEXT_MENU::SetTool, _1, aTool ) );
256 }
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 TRACK_VIA_SIZE_MENU::update ( )
overrideprotectedvirtualinherited

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 59 of file size_menu.cpp.

References TRACK_VIA_SIZE_MENU::getTrackDescription(), TRACK_VIA_SIZE_MENU::getViaDescription(), i, ID_POPUP_PCB_SELECT_VIASIZE1, ID_POPUP_PCB_SELECT_WIDTH1, TRACK_VIA_SIZE_MENU::m_designSettings, TRACK_VIA_SIZE_MENU::m_tracks, BOARD_DESIGN_SETTINGS::m_TrackWidthList, TRACK_VIA_SIZE_MENU::m_vias, and BOARD_DESIGN_SETTINGS::m_ViasDimensionsList.

Referenced by TRACK_VIA_SIZE_MENU::create().

60 {
61  if( m_tracks )
62  {
63  size_t pos;
64  unsigned int i;
65  wxMenuItem* lastEntry = FindChildItem( ID_POPUP_PCB_SELECT_WIDTH1, &pos );
66  wxCHECK( lastEntry, /* void */ );
67 
68  // Start update with index 1, as 0 is reserved for the 'net class' size
69  for( i = 1; i < m_designSettings->m_TrackWidthList.size(); i++ )
70  {
71  wxMenuItem* menuItem = FindItem( ID_POPUP_PCB_SELECT_WIDTH1 + i );
72 
73  if( menuItem ) // Update an existing entry
74  {
75  menuItem->SetItemLabel( getTrackDescription( i ) );
76  }
77  else // Add a missing entry
78  {
79  Insert( pos + i, ID_POPUP_PCB_SELECT_WIDTH1 + i, getTrackDescription( i ),
80  wxEmptyString, wxITEM_CHECK );
81  }
82  }
83 
84  // Remove entries that have been removed from the design settings
85  while( ( lastEntry = FindItem( ID_POPUP_PCB_SELECT_WIDTH1 + i ) ) )
86  {
87  Destroy( lastEntry );
88  ++i;
89  }
90  }
91 
92  if( m_vias )
93  {
94  size_t pos;
95  unsigned int i;
96  wxMenuItem* lastEntry = FindChildItem( ID_POPUP_PCB_SELECT_VIASIZE1, &pos );
97  wxCHECK( lastEntry, /* void */ );
98 
99  // Start update with index 1, as 0 is reserved for the 'net class' size
100  for( i = 1; i < m_designSettings->m_ViasDimensionsList.size(); i++ )
101  {
102  wxMenuItem* menuItem = FindItem( ID_POPUP_PCB_SELECT_VIASIZE1 + i );
103 
104  if( menuItem ) // Update an existing entry
105  {
106  menuItem->SetItemLabel( getViaDescription( i ) );
107  }
108  else // Add a missing entry
109  {
110  Insert( pos + i, ID_POPUP_PCB_SELECT_VIASIZE1 + i, getViaDescription( i ),
111  wxEmptyString, wxITEM_CHECK );
112  }
113  }
114 
115  // Remove entries that have been removed from the design settings
116  while( ( lastEntry = FindItem( ID_POPUP_PCB_SELECT_VIASIZE1 + i ) ) )
117  {
118  Destroy( lastEntry );
119  ++i;
120  }
121  }
122 }
wxString getTrackDescription(unsigned int aIndex) const
Generates a description string for track size from BOARD_DESIGN_SETTINGS list
Definition: size_menu.cpp:125
std::vector< int > m_TrackWidthList
Track width list.
wxString getViaDescription(unsigned int aIndex) const
Generates a description string for via size from BOARD_DESIGN_SETTINGS list
Definition: size_menu.cpp:141
const BOARD_DESIGN_SETTINGS * m_designSettings
Source of information about track/via sizes
Definition: size_menu.h:65
bool m_vias
Whether the generated menu should contain via sizes.
Definition: size_menu.h:71
bool m_tracks
Whether the generated menu should contain track sizes.
Definition: size_menu.h:68
size_t i
Definition: json11.cpp:597
std::vector< VIA_DIMENSION > m_ViasDimensionsList
Vias size and drill list.
void CONTEXT_MENU::UpdateAll ( )
inherited

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

Definition at line 234 of file context_menu.cpp.

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

Referenced by CONTEXT_MENU::GetSelected().

235 {
236  try
237  {
238  update();
239  }
240  catch( std::exception& e )
241  {
242  wxLogDebug( wxString::Format( "CONTEXT_MENU update handler exception: %s", e.what() ) );
243  }
244 
245  if( m_tool )
246  updateHotKeys();
247 
248  runOnSubmenus( std::bind( &CONTEXT_MENU::UpdateAll, _1 ) );
249 }
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

const BOARD* TRACK_WIDTH_MENU::m_board
private

Definition at line 301 of file router_tool.cpp.

const BOARD_DESIGN_SETTINGS* TRACK_VIA_SIZE_MENU::m_designSettings
protectedinherited
bool TRACK_VIA_SIZE_MENU::m_tracks
protectedinherited

Whether the generated menu should contain track sizes.

Definition at line 68 of file size_menu.h.

Referenced by TRACK_VIA_SIZE_MENU::AppendSizes(), TRACK_VIA_SIZE_MENU::create(), TRACK_VIA_SIZE_MENU::getViaDescription(), and TRACK_VIA_SIZE_MENU::update().

bool TRACK_VIA_SIZE_MENU::m_vias
protectedinherited

Whether the generated menu should contain via sizes.

Definition at line 71 of file size_menu.h.

Referenced by TRACK_VIA_SIZE_MENU::AppendSizes(), TRACK_VIA_SIZE_MENU::create(), TRACK_VIA_SIZE_MENU::getTrackDescription(), and TRACK_VIA_SIZE_MENU::update().


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