KiCad PCB EDA Suite
dialog_global_edit_tracks_and_vias.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) 2009-2016 Jean-Pierre Charras, jean-pierre.charras at wanadoo.fr
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <fctsys.h>
26 #include <confirm.h>
27 #include <pcbnew.h>
28 #include <wxPcbStruct.h>
29 #include <class_drawpanel.h>
30 #include <base_units.h>
31 
32 #include <class_board.h>
33 
35 
36 #include <view/view.h>
37 
45  int aNetcode ) :
47 {
48  m_parent = aParent;
49  m_curr_netcode = aNetcode;
50  m_optionID = 0;
51  MyInit();
52 
53  GetSizer()->SetSizeHints( this );
54 }
55 
56 
58 {
59  SetFocus();
60 
61  // Display current setup for tracks and vias
62  m_brd = m_parent->GetBoard();
63  buildNetsList();
64  updateNetInfo();
65 
67 }
68 
69 
71 {
73  NETCLASSES& netclasses = brdSettings.m_NetClasses;
74  NETCLASSPTR netclass = netclasses.GetDefault();
76 
77  if( net )
78  {
79  netclass = net->GetNetClass();
80  m_CurrentNetclassName->SetLabel( netclass->GetName() );
81  }
82 
83  /* Disable the option "copy current to net" if we have only default netclass values
84  * i.e. when m_TrackWidthSelector and m_ViaSizeSelector are set to 0
85  */
86  if( !brdSettings.GetTrackWidthIndex() && !brdSettings.GetViaSizeIndex() )
87  {
88  m_Net2CurrValueButton->Enable( false );
90  m_NetUseNetclassValueButton->SetValue(true);
91  }
92  else
93  {
95  m_Net2CurrValueButton->SetValue(true);
96  }
97 
98  // Display current values, and current netclass values:
99  wxString msg;
100 
101  int value = netclass->GetTrackWidth(); // Display track width
102  msg = StringFromValue( g_UserUnit, value, true );
103  m_gridDisplayCurrentSettings->SetCellValue( 0, 0, msg );
104 
105  if( brdSettings.GetTrackWidthIndex() > 0 )
106  {
107  value = brdSettings.GetCurrentTrackWidth();
108  msg = StringFromValue( g_UserUnit, value, true );
109  }
110  else
111  msg = _( "Default" );
112 
113  m_gridDisplayCurrentSettings->SetCellValue( 1, 0, msg );
114 
115  value = netclass->GetViaDiameter(); // Display via diameter
116  msg = StringFromValue( g_UserUnit, value, true );
117  m_gridDisplayCurrentSettings->SetCellValue( 0, 1, msg );
118 
119  if( brdSettings.GetViaSizeIndex() > 0 )
120  {
121  value = brdSettings.GetCurrentViaSize();
122  msg = StringFromValue( g_UserUnit, value, true );
123  }
124  else
125  msg = _( "Default" );
126 
127  m_gridDisplayCurrentSettings->SetCellValue( 1, 1, msg );
128 
129  value = netclass->GetViaDrill(); // Display via drill
130  msg = StringFromValue( g_UserUnit, value, true );
131  m_gridDisplayCurrentSettings->SetCellValue( 0, 2, msg );
132  value = brdSettings.GetCurrentViaDrill();
133 
134  if( value >= 0 )
135  msg = StringFromValue( g_UserUnit, value, true );
136  else
137  msg = _( "Default" );
138 
139  m_gridDisplayCurrentSettings->SetCellValue( 1, 2, msg );
140 
141  value = netclass->GetuViaDiameter(); // Display micro via diameter
142  msg = StringFromValue( g_UserUnit, value, true );
143  m_gridDisplayCurrentSettings->SetCellValue( 0, 3, msg );
144  msg = _( "Default" );
145  m_gridDisplayCurrentSettings->SetCellValue( 1, 3, msg );
146 
147  value = netclass->GetuViaDrill(); // Display micro via drill
148  msg = StringFromValue( g_UserUnit, value, true );
149  m_gridDisplayCurrentSettings->SetCellValue( 0, 4, msg );
150  msg = _( "Default" );
151  m_gridDisplayCurrentSettings->SetCellValue( 1, 4, msg );
152 
153  // Set all cells Read Only
154  for( int ii = 0; ii < m_gridDisplayCurrentSettings->GetNumberRows(); ii++ )
155  {
156  for( int jj = 0; jj < m_gridDisplayCurrentSettings->GetNumberCols(); jj++ )
157  m_gridDisplayCurrentSettings->SetReadOnly( ii, jj, true );
158  }
159 
160  m_gridDisplayCurrentSettings->SetRowLabelSize(wxGRID_AUTOSIZE);
161 }
162 
163 
165 {
166  wxString txt;
167 
168  // Populate the nets list with nets names
169  for( unsigned netcode = 0; netcode < m_brd->GetNetCount(); netcode++ )
170  {
171  NETINFO_ITEM* net = m_brd->GetNetInfo().GetNetItem( netcode );
172  wxString netname = net->GetNetname();
173 
174  if( netcode == 0 ) // netcode 0 is the netcode of not connected items
175  netname = "<no net>";
176 
177  txt.Printf( _( "net %.3d" ), net->GetNet() );
178 
179  txt << " " << netname;
180 
181  m_choiceNetName->Append( txt );
182  }
183 
184  if( m_curr_netcode < 0 )
185  m_curr_netcode = 0;
186 
187  m_choiceNetName->SetSelection( m_curr_netcode );
188 
189  updateNetInfo();
190 }
191 
193 {
194  int idx = m_choiceNetName->GetSelection();
195 
196  if( idx == wxNOT_FOUND )
197  return;
198 
199  m_curr_netcode = idx;
200  updateNetInfo();
201 }
202 
203 #include <ratsnest_data.h>
204 
206 {
207  bool change = false;
208 
209  switch( m_optionID )
210  {
212  if( !IsOK( this,
213  _( "Set current Net tracks and vias sizes and drill to the current values?" ) ) )
214  return;
215  {
216  wxBusyCursor dummy;
218  }
219  break;
220 
222  if( !IsOK( this,
223  _( "Set current Net tracks and vias sizes and drill to the Netclass default value?" ) ) )
224  return;
225  {
226  wxBusyCursor dummy;
228  }
229  break;
230 
231  case ID_ALL_TRACKS_VIAS:
232  if( !IsOK( this, _( "Set All Tracks and Vias to Netclass value" ) ) )
233  return;
234  {
235  wxBusyCursor dummy;
237  }
238  break;
239 
240  case ID_ALL_VIAS:
241  if( !IsOK( this, _( "Set All Via to Netclass value" ) ) )
242  return;
243  {
244  wxBusyCursor dummy;
246  }
247  break;
248 
249  case ID_ALL_TRACKS:
250  if( !IsOK( this, _( "Set All Track to Netclass value" ) ) )
251  return;
252  {
253  wxBusyCursor dummy;
255  }
256  break;
257  }
258 
259  if( change )
260  {
261  if( m_parent->IsGalCanvasActive() )
262  {
263  for( TRACK* track = m_parent->GetBoard()->m_Track; track != NULL; track = track->Next() )
265  }
266  else
267  m_parent->GetCanvas()->Refresh();
268  }
269 
270  // Call the default handler
271  event.Skip();
272 }
void onNetSelection(wxCommandEvent &event) override
int GetCurrentViaDrill() const
Function GetCurrentViaDrill.
DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS(PCB_EDIT_FRAME *aParent, int aNetcode)
DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS, derived from DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE_BASE.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:325
Implementation of conversion functions that require both schematic and board internal units...
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:337
#define ID_NETCLASS_VALUES_TO_CURRENT_NET
Class BOARD to handle a board.
Class that computes missing connections on a PCB.
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:203
NETINFO_ITEM * GetNetItem(int aNetCode) const
Function GetItem.
BOARD * GetBoard() const
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
int GetCurrentViaSize() const
Function GetCurrentViaSize.
unsigned GetViaSizeIndex() const
Function GetViaSizeIndex.
Class NETCLASSES is a container for NETCLASS instances.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:862
int GetNet() const
Function GetNet.
void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1385
NETINFO_LIST & GetNetInfo()
Definition: class_board.h:743
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
Class DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS_BASE.
Class NETINFO_ITEM handles the data for a net.
Definition: class_netinfo.h:69
TRACK * Next() const
Definition: class_track.h:98
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
NETCLASSPTR GetNetClass()
void OnOkClick(wxCommandEvent &event) override
NETCLASSPTR GetDefault() const
Function GetDefault.
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
unsigned GetTrackWidthIndex() const
Function GetTrackWidthIndex.
#define ID_CURRENT_VALUES_TO_CURRENT_NET
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:870
DLIST< TRACK > m_Track
Definition: class_board.h:246
const wxString & GetNetname() const
Function GetNetname.
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
bool Change_Net_Tracks_And_Vias_Sizes(int aNetcode, bool aUseNetclassValue)
Function Change_Net_Tracks_And_Vias_Sizes Reset all tracks width and vias diameters and drill to thei...
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:129
bool Reset_All_Tracks_And_Vias_To_Netclass_Values(bool aTrack, bool aVia)
Function Reset_All_Tracks_And_Vias_To_Netclass_Values Reset all tracks width and/or vias diameters an...
NETCLASSES m_NetClasses
List of current netclasses. There is always the default netclass.
unsigned GetNetCount() const
Function GetNetCount.
Definition: class_board.h:772
Color has changed.
Definition: view_item.h:57
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.