KiCad PCB EDA Suite
panel_setup_netclasses.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) 2004-2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2009 Dick Hollenbeck, [email protected]
6  * Copyright (C) 2009-2021 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <algorithm>
27 
28 #include <pgm_base.h>
29 #include <base_units.h>
30 #include <eda_draw_frame.h>
31 #include <bitmaps.h>
32 #include <netclass.h>
33 #include <confirm.h>
34 #include <grid_tricks.h>
36 #include <tool/tool_manager.h>
37 #include <widgets/wx_grid.h>
38 #include <string_utils.h>
42 #include <wx/treebook.h>
43 
44 
45 // PCBNEW columns of netclasses grid
46 enum {
47  GRID_NAME = 0,
48 
58 
64 
66 };
67 
68 
69 std::vector<BITMAPS> g_lineStyleIcons;
70 wxArrayString g_lineStyleNames;
71 
72 
74  NETCLASSES* aNetclasses,
75  const std::vector<wxString>& aNetNames,
76  bool aIsEEschema ) :
77  PANEL_SETUP_NETCLASSES_BASE( aParent->GetTreebook() ),
78  m_frame( aFrame ),
79  m_parent( aParent ),
80  m_netclasses( aNetclasses ),
81  m_netNames( aNetNames ),
82  m_hoveredCol( -1 )
83 {
84  // Clear and re-load each time. Language (or darkmode) might have changed.
85  g_lineStyleIcons.clear();
86  g_lineStyleNames.clear();
87 
89  g_lineStyleNames.push_back( _( "Solid" ) );
91  g_lineStyleNames.push_back( _( "Dashed" ) );
93  g_lineStyleNames.push_back( _( "Dotted" ) );
95  g_lineStyleNames.push_back( _( "Dash-Dot" ) );
96 
97  m_netclassesDirty = true;
98 
99  // Prevent Size events from firing before we are ready
100  Freeze();
101  m_netclassGrid->BeginBatch();
102  m_membershipGrid->BeginBatch();
103 
104  m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
105  // Calculate a min best size to handle longest usual numeric values:
106  int min_best_width = m_netclassGrid->GetTextExtent( "555,555555 mils" ).x;
107 
108  for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
109  {
110  // We calculate the column min size only from texts sizes, not using the initial col width
111  // as this initial width is sometimes strange depending on the language (wxGrid bug?)
112  int min_width = m_netclassGrid->GetVisibleWidth( i, true, true, false );
113 
114  if( i == GRID_LINESTYLE )
115  min_best_width *= 1.5;
116 
117  m_netclassGrid->SetColMinimalWidth( i, min_width );
118 
119  // We use a "best size" >= min_best_width
120  m_originalColWidths[ i ] = std::max( min_width, min_best_width );
121  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
122  }
123 
124  if( aIsEEschema )
125  {
126  for( int i = GRID_FIRST_PCBNEW; i < GRID_FIRST_EESCHEMA; ++i )
127  {
128  m_netclassGrid->HideCol( i );
129  m_originalColWidths[ i ] = 0;
130  }
131 
132  wxGridCellAttr* attr = new wxGridCellAttr;
133  attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( aParent ) );
134  attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( aParent, m_netclassGrid ) );
135  m_netclassGrid->SetColAttr( GRID_SCHEMATIC_COLOR, attr );
136 
137  attr = new wxGridCellAttr;
140  m_netclassGrid->SetColAttr( GRID_LINESTYLE, attr );
141 
142  m_colorDefaultHelpText->SetFont( KIUI::GetInfoFont( this ).Italic() );
143  }
144  else
145  {
146  for( int i = GRID_FIRST_EESCHEMA; i < GRID_END; ++i )
147  {
148  m_netclassGrid->HideCol( i );
149  m_originalColWidths[ i ] = 0;
150  }
151 
152  m_colorDefaultHelpText->Hide();
153  }
154 
155  // Be sure the column labels are readable
157 
158  // Membership combobox editors require a bit more room, so increase the row size of
159  // all our grids for consistency
160  m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );
161  m_membershipGrid->SetDefaultRowSize( m_membershipGrid->GetDefaultRowSize() + 4 );
162 
163  m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
164  m_membershipGrid->PushEventHandler( new GRID_TRICKS( m_membershipGrid ) );
165 
166  m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
167  m_membershipGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
168 
169  // Set up the net name column of the netclass membership grid to read-only
170  wxGridCellAttr* attr = new wxGridCellAttr;
171  attr->SetReadOnly( true );
172  attr->SetRenderer( new GRID_CELL_ESCAPED_TEXT_RENDERER );
173  m_membershipGrid->SetColAttr( 0, attr );
174 
175  COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
176  m_splitter->SetSashPosition( cfg->m_NetclassPanel.sash_pos );
177 
178  m_addButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
180 
181  // wxFormBuilder doesn't include this event...
182  m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING,
184  nullptr, this );
185 
186  // Handle tooltips for grid
187  m_netclassGrid->GetGridColLabelWindow()->Bind( wxEVT_MOTION,
189  this );
190 
191  m_frame->Bind( UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
192 
193  m_netclassGrid->EndBatch();
194  m_membershipGrid->EndBatch();
195  Thaw();
196 }
197 
198 
200 {
201  COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
202  cfg->m_NetclassPanel.sash_pos = m_splitter->GetSashPosition();
203 
204  delete [] m_originalColWidths;
205 
206  // Delete the GRID_TRICKS.
207  m_netclassGrid->PopEventHandler( true );
208  m_membershipGrid->PopEventHandler( true );
209 
210  m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING,
212  nullptr, this );
213 
214  m_frame->Unbind( UNITS_CHANGED, &PANEL_SETUP_NETCLASSES::onUnitsChanged, this );
215 }
216 
217 
218 void PANEL_SETUP_NETCLASSES::onUnitsChanged( wxCommandEvent& aEvent )
219 {
220  NETCLASSES tempNetClasses;
221  NETCLASSES* saveNetClasses = m_netclasses;
222 
223  m_netclasses = &tempNetClasses; // No, address of stack var does not escape function
224 
227 
228  m_netclasses = saveNetClasses;
229 
230  aEvent.Skip();
231 }
232 
233 
234 static void netclassToGridRow( EDA_UNITS aUnits, wxGrid* aGrid, int aRow, const NETCLASSPTR& nc )
235 {
236  aGrid->SetCellValue( aRow, GRID_NAME, nc->GetName() );
237 
238 #define SET_MILS_CELL( col, val ) \
239  aGrid->SetCellValue( aRow, col, StringFromValue( aUnits, val, true ) )
240 
241  SET_MILS_CELL( GRID_CLEARANCE, nc->GetClearance() );
242  SET_MILS_CELL( GRID_TRACKSIZE, nc->GetTrackWidth() );
243  SET_MILS_CELL( GRID_VIASIZE, nc->GetViaDiameter() );
244  SET_MILS_CELL( GRID_VIADRILL, nc->GetViaDrill() );
245  SET_MILS_CELL( GRID_uVIASIZE, nc->GetuViaDiameter() );
246  SET_MILS_CELL( GRID_uVIADRILL, nc->GetuViaDrill() );
247  SET_MILS_CELL( GRID_DIFF_PAIR_WIDTH, nc->GetDiffPairWidth() );
248  SET_MILS_CELL( GRID_DIFF_PAIR_GAP, nc->GetDiffPairGap() );
249 
250  SET_MILS_CELL( GRID_WIREWIDTH, nc->GetWireWidth() );
251  SET_MILS_CELL( GRID_BUSWIDTH, nc->GetBusWidth() );
252 
253  wxString colorAsString = nc->GetSchematicColor().ToWxString( wxC2S_CSS_SYNTAX );
254  aGrid->SetCellValue( aRow, GRID_SCHEMATIC_COLOR, colorAsString );
255 
256  int lineStyleIdx = std::max( 0, nc->GetLineStyle() );
257 
258  if( lineStyleIdx >= (int) g_lineStyleNames.size() )
259  lineStyleIdx = 0;
260 
261  aGrid->SetCellValue( aRow, GRID_LINESTYLE, g_lineStyleNames[ lineStyleIdx ] );
262 }
263 
264 
266 {
267  std::map<wxString, wxString> netToNetclassMap;
268  std::map<wxString, wxString> staleNetMap;
269 
270  for( const wxString& candidate : m_netNames )
271  netToNetclassMap[ candidate ] = wxEmptyString;
272 
274  m_netclassGrid->AppendRows((int) m_netclasses->GetCount() + 1 ); // + 1 for default netclass
275 
276  // enter the Default NETCLASS.
278 
279  // make the Default NETCLASS name read-only
280  wxGridCellAttr* cellAttr = m_netclassGrid->GetOrCreateCellAttr( 0, GRID_NAME );
281  cellAttr->SetReadOnly();
282  cellAttr->DecRef();
283 
284  // enter other netclasses
285  int row = 1;
286 
287  for( NETCLASSES::iterator i = m_netclasses->begin(); i != m_netclasses->end(); ++i, ++row )
288  {
289  NETCLASSPTR netclass = i->second;
290 
292 
293  for( const wxString& net : *netclass )
294  {
295  if( netToNetclassMap.count( net ) )
296  netToNetclassMap[ net ] = i->second->GetName();
297  else
298  staleNetMap[ net ] = i->second->GetName();
299  }
300  }
301 
303 
304  // add currently-assigned and candidate netnames to membership lists
305  for( const std::pair<const wxString, wxString>& ii : netToNetclassMap )
306  addNet( ii.first, ii.second, false );
307 
308  for( const std::pair<const wxString, wxString>& ii : staleNetMap )
309  addNet( ii.first, ii.second, true );
310 
311  return true;
312 }
313 
314 
315 void PANEL_SETUP_NETCLASSES::addNet( const wxString& netName, const wxString& netclass,
316  bool aStale )
317 {
318  int i = m_membershipGrid->GetNumberRows();
319 
320  m_membershipGrid->AppendRows( 1 );
321 
322  m_membershipGrid->SetCellValue( i, 0, netName );
323 
324  if( aStale )
325  {
326  wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
327  m_membershipGrid->SetCellTextColour( i, 0, color );
328  }
329 
330  if( netclass.IsEmpty() )
331  m_membershipGrid->SetCellValue( i, 1, NETCLASS::Default );
332  else
333  m_membershipGrid->SetCellValue( i, 1, netclass );
334 }
335 
336 
337 /*
338  * Populates drop-downs with the list of net classes
339  */
341 {
343 
344  wxArrayString netclassNames;
345 
346  for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
347  {
348  wxString netclassName = m_netclassGrid->GetCellValue( ii, GRID_NAME );
349 
350  if( !netclassName.IsEmpty() )
351  netclassNames.push_back( netclassName );
352  }
353 
354  wxGridCellAttr* attr = new wxGridCellAttr;
355  attr->SetEditor( new wxGridCellChoiceEditor( netclassNames ) );
356  m_membershipGrid->SetColAttr( 1, attr );
357 
358  m_assignNetClass->Set( netclassNames );
359 
360  netclassNames.Insert( wxEmptyString, 0 );
361  m_netClassFilter->Set( netclassNames );
362 }
363 
364 
365 static void gridRowToNetclass( EDA_UNITS aUnits, wxGrid* grid, int row, const NETCLASSPTR& nc )
366 {
367  nc->SetName( grid->GetCellValue( row, GRID_NAME ) );
368 
369 #define MYCELL( col ) \
370  ValueFromString( aUnits, grid->GetCellValue( row, col ) )
371 
372  nc->SetClearance( MYCELL( GRID_CLEARANCE ) );
373  nc->SetTrackWidth( MYCELL( GRID_TRACKSIZE ) );
374  nc->SetViaDiameter( MYCELL( GRID_VIASIZE ) );
375  nc->SetViaDrill( MYCELL( GRID_VIADRILL ) );
376  nc->SetuViaDiameter( MYCELL( GRID_uVIASIZE ) );
377  nc->SetuViaDrill( MYCELL( GRID_uVIADRILL ) );
378  nc->SetDiffPairWidth( MYCELL( GRID_DIFF_PAIR_WIDTH ) );
379  nc->SetDiffPairGap( MYCELL( GRID_DIFF_PAIR_GAP ) );
380 
381  nc->SetWireWidth( MYCELL( GRID_WIREWIDTH ) );
382  nc->SetBusWidth( MYCELL( GRID_BUSWIDTH ) );
383 
384  nc->SetSchematicColor( wxColour( grid->GetCellValue( row, GRID_SCHEMATIC_COLOR ) ) );
385 
386  nc->SetLineStyle( g_lineStyleNames.Index( grid->GetCellValue( row, GRID_LINESTYLE ) ) );
387  wxASSERT_MSG( nc->GetLineStyle() >= 0, "Line style name not found." );
388 }
389 
390 
392 {
393  if( !Validate() )
394  return false;
395 
396  m_netclasses->Clear();
397 
398  // Copy the default NetClass:
400 
401  // Copy other NetClasses:
402  for( int row = 1; row < m_netclassGrid->GetNumberRows(); ++row )
403  {
404  NETCLASSPTR nc = std::make_shared<NETCLASS>( m_netclassGrid->GetCellValue( row,
405  GRID_NAME ) );
406 
407  if( m_netclasses->Add( nc ) )
409  }
410 
411  // Now read all nets and push them in the corresponding netclass net buffer
412  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
413  {
414  const wxString& netname = m_membershipGrid->GetCellValue( row, 0 );
415  const wxString& classname = m_membershipGrid->GetCellValue( row, 1 );
416 
417  if( classname != NETCLASS::Default )
418  {
419  const NETCLASSPTR& nc = m_netclasses->Find( classname );
420 
421  if( nc )
422  nc->Add( netname );
423  }
424  }
425 
426  return true;
427 }
428 
429 
430 bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName,
431  bool focusFirst )
432 {
433  wxString tmp = aName;
434 
435  tmp.Trim( true );
436  tmp.Trim( false );
437 
438  if( tmp.IsEmpty() )
439  {
440  wxString msg = _( "Netclass must have a name." );
441  m_parent->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME );
442  return false;
443  }
444 
445  for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
446  {
447  if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 )
448  {
449  wxString msg = _( "Netclass name already in use." );
450  m_parent->SetError( msg, this, m_netclassGrid, focusFirst ? aRow : ii, GRID_NAME );
451  return false;
452  }
453  }
454 
455  return true;
456 }
457 
458 
460 {
461  if( event.GetCol() == GRID_NAME )
462  {
463  if( validateNetclassName( event.GetRow(), event.GetString() ) )
464  {
465  wxString oldName = m_netclassGrid->GetCellValue( event.GetRow(), GRID_NAME );
466  wxString newName = event.GetString();
467 
468  if( !oldName.IsEmpty() )
469  {
470  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
471  {
472  if( m_membershipGrid->GetCellValue( row, 1 ) == oldName )
473  m_membershipGrid->SetCellValue( row, 1, newName );
474  }
475  }
476 
477  m_netclassesDirty = true;
478  }
479  else
480  {
481  event.Veto();
482  }
483  }
484 }
485 
486 
488 {
489  int col = m_netclassGrid->XToCol( aEvent.GetPosition().x );
490 
491  if( aEvent.Moving() || aEvent.Entering() )
492  {
493  aEvent.Skip();
494 
495  if( col == wxNOT_FOUND )
496  {
497  m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
498  return;
499  }
500 
501  if( col == m_hoveredCol )
502  return;
503 
504  m_hoveredCol = col;
505 
506  wxString tip;
507 
508  switch( col )
509  {
510  case GRID_CLEARANCE: tip = _( "Minimum copper clearance" ); break;
511  case GRID_TRACKSIZE: tip = _( "Minimum track width" ); break;
512  case GRID_VIASIZE: tip = _( "Via pad diameter" ); break;
513  case GRID_VIADRILL: tip = _( "Via plated hole diameter" ); break;
514  case GRID_uVIASIZE: tip = _( "Microvia pad diameter" ); break;
515  case GRID_uVIADRILL: tip = _( "Microvia plated hole diameter" ); break;
516  case GRID_DIFF_PAIR_WIDTH: tip = _( "Differential pair track width" ); break;
517  case GRID_DIFF_PAIR_GAP: tip = _( "Differential pair gap" ); break;
518  case GRID_WIREWIDTH: tip = _( "Schematic wire thickness" ); break;
519  case GRID_BUSWIDTH: tip = _( "Bus wire thickness" ); break;
520  case GRID_SCHEMATIC_COLOR: tip = _( "Schematic wire color" ); break;
521  case GRID_LINESTYLE: tip = _( "Schematic wire line style" ); break;
522  }
523 
524  m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
525  m_netclassGrid->GetGridColLabelWindow()->SetToolTip( tip );
526  }
527  else if( aEvent.Leaving() )
528  {
529  m_netclassGrid->GetGridColLabelWindow()->UnsetToolTip();
530  aEvent.Skip();
531  }
532 
533  aEvent.Skip();
534 }
535 
536 
537 void PANEL_SETUP_NETCLASSES::OnAddNetclassClick( wxCommandEvent& event )
538 {
540  return;
541 
542  int row = m_netclassGrid->GetNumberRows();
543  m_netclassGrid->AppendRows();
544 
545  // Copy values of the default class:
546  for( int col = 1; col < m_netclassGrid->GetNumberCols(); col++ )
547  m_netclassGrid->SetCellValue( row, col, m_netclassGrid->GetCellValue( 0, col ) );
548 
549  m_netclassGrid->MakeCellVisible( row, 0 );
550  m_netclassGrid->SetGridCursor( row, 0 );
551 
552  m_netclassGrid->EnableCellEditControl( true );
553  m_netclassGrid->ShowCellEditControl();
554 
555  m_netclassesDirty = true;
556 }
557 
558 
560 {
562  return;
563 
564  int curRow = m_netclassGrid->GetGridCursorRow();
565 
566  if( curRow < 0 )
567  {
568  return;
569  }
570  else if( curRow == 0 )
571  {
572  DisplayErrorMessage( this, _( "The default net class is required." ) );
573  return;
574  }
575 
576  // reset the net class to default for members of the removed class
577  wxString classname = m_netclassGrid->GetCellValue( curRow, GRID_NAME );
578 
579  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
580  {
581  if( m_membershipGrid->GetCellValue( row, 1 ) == classname )
582  m_membershipGrid->SetCellValue( row, 1, NETCLASS::Default );
583  }
584 
585  m_netclassGrid->DeleteRows( curRow, 1 );
586 
587  m_netclassGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
588  m_netclassGrid->SetGridCursor( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
589 
590  m_netclassesDirty = true;
591 }
592 
593 
595 {
596  // Account for scroll bars
597  aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
598 
599  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
600  {
601  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
602  aWidth -= m_originalColWidths[ i ];
603  }
604 
605  m_netclassGrid->SetColSize( 0, std::max( aWidth - 2, m_originalColWidths[ 0 ] ) );
606 }
607 
608 
610 {
611  AdjustNetclassGridColumns( event.GetSize().GetX() );
612 
613  event.Skip();
614 }
615 
616 
618 {
619  // Account for scroll bars
620  aWidth -= ( m_membershipGrid->GetSize().x - m_membershipGrid->GetClientSize().x );
621 
622  // Set className column width to original className width from netclasses grid
623  int classNameWidth = m_originalColWidths[ 0 ];
624  m_membershipGrid->SetColSize( 1, m_originalColWidths[ 0 ] );
625  m_membershipGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) );
626 }
627 
628 
630 {
631  // When a class name choice widget is selected (activated), in
632  // wxGrid m_membershipGrid, resizing its wxGrid parent is not taken in account
633  // by the widget until it is deselected and stay in the old position.
634  // So we deselect it if this is the case
635  // Note also this is made here, not in OnSizeMembershipGrid because on Linux
636  // there are a lot of wxSizeEvent send to m_membershipGrid when opening a choice widget
637  int c_row = m_membershipGrid->GetGridCursorRow();
638  int c_col = m_membershipGrid->GetGridCursorCol();
639 
640  if( c_row >= 0 && c_col == 1 ) // this means the class name choice widget is selected (opened)
641  m_membershipGrid->SetGridCursor( c_row, 0 ); // Close it
642 
643  event.Skip();
644 }
645 
646 
648 {
649  AdjustMembershipGridColumns( event.GetSize().GetX() );
650 
651  event.Skip();
652 }
653 
654 
656 {
658  return;
659 
660  wxString netClassFilter = m_netClassFilter->GetStringSelection();
661  wxString netFilter = m_netNameFilter->GetValue().MakeLower();
662 
663  if( !netFilter.IsEmpty() )
664  netFilter = wxT( "*" ) + netFilter + wxT( "*" );
665 
666  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
667  {
668  wxString net = m_membershipGrid->GetCellValue( row, 0 );
669  wxString netClass = m_membershipGrid->GetCellValue( row, 1 );
670  bool show = true;
671 
672  if( !aShowAll )
673  {
674  if( !netFilter.IsEmpty() && !net.MakeLower().Matches( netFilter ) )
675  show = false;
676 
677  if( !netClassFilter.IsEmpty() && netClass != netClassFilter )
678  show = false;
679  }
680 
681  if( show )
682  m_membershipGrid->ShowRow( row );
683  else
684  m_membershipGrid->HideRow( row );
685  }
686 }
687 
688 
690 {
692  return;
693 
694  wxArrayInt selectedRows = m_membershipGrid->GetSelectedRows();
695 
696  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
697  {
698  if( !m_membershipGrid->IsRowShown( row ) )
699  continue;
700 
701  if( !aAssignAll && selectedRows.Index( row ) == wxNOT_FOUND )
702  continue;
703 
704  m_membershipGrid->SetCellValue( row, 1, m_assignNetClass->GetStringSelection() );
705  }
706 }
707 
708 
709 void PANEL_SETUP_NETCLASSES::OnUpdateUI( wxUpdateUIEvent& event )
710 {
711  if( m_netclassesDirty )
712  {
714  m_netclassesDirty = false;
715  }
716 }
717 
718 
720 {
722  return false;
723 
724  wxString msg;
725 
726  // Test net class parameters.
727  for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
728  {
729  wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
730  netclassName.Trim( true );
731  netclassName.Trim( false );
732 
733  if( !validateNetclassName( row, netclassName, false ) )
734  return false;
735  }
736 
737  return true;
738 }
739 
740 
742 {
743  NETCLASSES* savedSettings = m_netclasses;
744 
745  m_netclasses = aNetclasses;
747 
749 
750  m_netclassGrid->ForceRefresh();
751  m_membershipGrid->ForceRefresh();
752 
753  m_netclasses = savedSettings;
754 }
755 
756 
NETCLASSPTR Find(const wxString &aName) const
Search this container for a NETCLASS given by aName.
Definition: netclass.cpp:132
void OnSizeNetclassGrid(wxSizeEvent &event) override
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
Implementation of conversion functions that require both schematic and board internal units.
This file is part of the common library.
void onmembershipPanelSize(wxSizeEvent &event) override
int color
Definition: DXF_plotter.cpp:57
#define SET_MILS_CELL(col, val)
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:55
iterator end()
Definition: netclass.h:236
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
PANEL_SETUP_NETCLASSES(PAGED_DIALOG *aParent, EDA_DRAW_FRAME *aFrame, NETCLASSES *aNetclasses, const std::vector< wxString > &aNetNames, bool isEEschema)
The base class for create windows for drawing purpose.
bool validateNetclassName(int aRow, const wxString &aName, bool focusFirst=true)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
void addNet(const wxString &netName, const wxString &netclass, bool aStale)
void doAssignments(bool aAssignAll)
void onUnitsChanged(wxCommandEvent &aEvent)
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=false, bool aKeep=true)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:246
void OnNetclassGridMouseEvent(wxMouseEvent &event)
std::vector< wxString > m_netNames
std::vector< BITMAPS > g_lineStyleIcons
NETCLASS_MAP::iterator iterator
Definition: netclass.h:234
NETCLASS_PANEL m_NetclassPanel
iterator begin()
Definition: netclass.h:235
A container for NETCLASS instances.
Definition: netclass.h:218
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:49
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:291
void OnNetclassGridCellChanging(wxGridEvent &event)
#define _(s)
static void gridRowToNetclass(EDA_UNITS aUnits, wxGrid *grid, int row, const NETCLASSPTR &nc)
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:190
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
Class PANEL_SETUP_NETCLASSES_BASE.
EDA_UNITS
Definition: eda_units.h:38
bool Add(const NETCLASSPTR &aNetclass)
Add aNetclass and puts it into this NETCLASSES container.
Definition: netclass.cpp:90
void Clear()
Destroy any contained NETCLASS instances except the default one, and clears any members from the defa...
Definition: netclass.h:228
see class PGM_BASE
unsigned GetCount() const
Definition: netclass.h:245
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:106
static void netclassToGridRow(EDA_UNITS aUnits, wxGrid *aGrid, int aRow, const NETCLASSPTR &nc)
NETCLASSPTR GetDefault() const
Definition: netclass.h:253
wxArrayString g_lineStyleNames
void ImportSettingsFrom(NETCLASSES *aBoard)
void OnUpdateUI(wxUpdateUIEvent &event) override
#define MYCELL(col)
void OnSizeMembershipGrid(wxSizeEvent &event) override
void OnRemoveNetclassClick(wxCommandEvent &event) override
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
void AdjustNetclassGridColumns(int aWidth)
void AdjustMembershipGridColumns(int aWidth)
void OnAddNetclassClick(wxCommandEvent &event) override
A text renderer that can unescape text for display This is useful where it's desired to keep the unde...
void doApplyFilters(bool aShowAll)