KiCad PCB EDA Suite
size_menu.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2017 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation, either version 3 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "size_menu.h"
23 
24 #include <class_board.h>
25 #include <pcbnew_id.h>
26 #include <bitmaps.h>
27 
28 
29 TRACK_VIA_SIZE_MENU::TRACK_VIA_SIZE_MENU( bool aTrackSizes, bool aViaSizes ) :
30  m_designSettings( nullptr ), m_tracks( aTrackSizes ), m_vias( aViaSizes )
31 {
32  SetIcon( width_track_via_xpm );
33 }
34 
35 
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 }
57 
58 
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 }
123 
124 
125 wxString TRACK_VIA_SIZE_MENU::getTrackDescription( unsigned int aIndex ) const
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 }
139 
140 
141 wxString TRACK_VIA_SIZE_MENU::getViaDescription( unsigned int aIndex ) const
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 getTrackDescription(unsigned int aIndex) const
Generates a description string for track size from BOARD_DESIGN_SETTINGS list
Definition: size_menu.cpp:125
virtual void update() override
Update menu state stub.
Definition: size_menu.cpp:59
std::vector< int > m_TrackWidthList
Track width list.
TRACK_VIA_SIZE_MENU(bool aTrackSizes, bool aViaSizes)
Constructor.
Definition: size_menu.cpp:29
Class BOARD to handle a board.
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
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
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
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:57
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
size_t i
Definition: json11.cpp:597
std::vector< VIA_DIMENSION > m_ViasDimensionsList
Vias size and drill list.