KiCad PCB EDA Suite
PANEL_SETUP_NETCLASSES Class Reference

#include <panel_setup_netclasses.h>

Inheritance diagram for PANEL_SETUP_NETCLASSES:
PANEL_SETUP_NETCLASSES_BASE

Public Member Functions

 PANEL_SETUP_NETCLASSES (PAGED_DIALOG *aParent, PCB_EDIT_FRAME *aFrame, PANEL_SETUP_FEATURE_CONSTRAINTS *aConstraintsPanel)
 
 ~PANEL_SETUP_NETCLASSES () override
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 
void ImportSettingsFrom (BOARD *aBoard)
 

Protected Attributes

WX_GRIDm_netclassGrid
 
wxBitmapButton * m_addButton
 
wxBitmapButton * m_removeButton
 
wxStaticText * m_ncfilterLabel
 
wxChoice * m_netClassFilter
 
wxStaticText * m_filterLabel
 
wxTextCtrl * m_netNameFilter
 
wxButton * m_showAllButton
 
wxButton * m_filterNetsButton
 
wxStaticText * m_assignLabel
 
wxChoice * m_assignNetClass
 
wxButton * m_assignAllButton
 
wxButton * m_assignSelectedButton
 
WX_GRIDm_membershipGrid
 

Private Member Functions

void OnAddNetclassClick (wxCommandEvent &event) override
 
void OnRemoveNetclassClick (wxCommandEvent &event) override
 
void OnSizeNetclassGrid (wxSizeEvent &event) override
 
void OnSizeMembershipGrid (wxSizeEvent &event) override
 
void OnUpdateUI (wxUpdateUIEvent &event) override
 
void OnNetclassGridCellChanging (wxGridEvent &event)
 
void OnShowAll (wxCommandEvent &event) override
 
void OnApplyFilters (wxCommandEvent &event) override
 
void OnAssignAll (wxCommandEvent &event) override
 
void OnAssignSelected (wxCommandEvent &event) override
 
bool validateNetclassName (int aRow, wxString aName, bool focusFirst=true)
 
bool validateData ()
 
void rebuildNetclassDropdowns ()
 
int getNetclassValue (int aRow, int aCol)
 
void addNet (wxString netName, const wxString &netclass)
 
void doApplyFilters (bool aShowAll)
 
void doAssignments (bool aAssignAll)
 
void AdjustNetclassGridColumns (int aWidth)
 
void AdjustMembershipGridColumns (int aWidth)
 

Private Attributes

PAGED_DIALOGm_Parent
 
PCB_EDIT_FRAMEm_Frame
 
BOARDm_Pcb
 
BOARD_DESIGN_SETTINGSm_BrdSettings
 
PANEL_SETUP_FEATURE_CONSTRAINTSm_ConstraintsPanel
 
int * m_originalColWidths
 
bool m_netclassesDirty
 

Detailed Description

Definition at line 39 of file panel_setup_netclasses.h.

Constructor & Destructor Documentation

◆ PANEL_SETUP_NETCLASSES()

PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES ( PAGED_DIALOG aParent,
PCB_EDIT_FRAME aFrame,
PANEL_SETUP_FEATURE_CONSTRAINTS aConstraintsPanel 
)

Definition at line 55 of file panel_setup_netclasses.cpp.

56  :
58 {
59  m_Parent = aParent;
60  m_Frame = aFrame;
61  m_Pcb = m_Frame->GetBoard();
63  m_ConstraintsPanel = aConstraintsPanel;
64 
65  m_netclassesDirty = true;
66 
67  // Prevent Size events from firing before we are ready
68  Freeze();
69  m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
70  // Calculate a min best size to handle longest usual numeric values:
71  // (The 'M' large char is used to give a margin)
72  int min_best_width = m_netclassGrid->GetTextExtent( "555,555555 milsM" ).x;
73 
74  for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
75  {
76  // We calculate the column min size only from texts sizes, not using the initial col width
77  // as this initial width is sometimes strange depending on the language (wxGrid bug?)
78  int min_width = m_netclassGrid->GetVisibleWidth( i, true, true, false );
79  m_netclassGrid->SetColMinimalWidth( i, min_width );
80  // We use a "best size" >= min_best_width
81  m_originalColWidths[ i ] = std::max( min_width, min_best_width );
82  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
83  }
84 
85  // Be sure the column labels are readable
87 
88  // Membership combobox editors require a bit more room, so increase the row size of
89  // all our grids for consistency
90  m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );
91  m_membershipGrid->SetDefaultRowSize( m_membershipGrid->GetDefaultRowSize() + 4 );
92 
93  m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
94  m_membershipGrid->PushEventHandler( new GRID_TRICKS( m_membershipGrid ) );
95 
96  m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
97  m_membershipGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
98 
99  // Set up the net name column of the netclass membership grid to read-only
100  wxGridCellAttr* attr = new wxGridCellAttr;
101  attr->SetReadOnly( true );
102  m_membershipGrid->SetColAttr( 0, attr );
103 
104  m_addButton->SetBitmap( KiBitmap( small_plus_xpm ) );
105  m_removeButton->SetBitmap( KiBitmap( trash_xpm ) );
106 
107  // wxFormBuilder doesn't include this event...
108  m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging ), NULL, this );
109 
110  Thaw();
111 }
Class GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GR...
Definition: grid_tricks.h:51
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:534
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:223
wxTreebook * GetTreebook()
Definition: paged_dialog.h:43
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
PANEL_SETUP_NETCLASSES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:265
void OnNetclassGridCellChanging(wxGridEvent &event)
BOARD_DESIGN_SETTINGS * m_BrdSettings
PANEL_SETUP_FEATURE_CONSTRAINTS * m_ConstraintsPanel
#define max(a, b)
Definition: auxiliary.h:86
size_t i
Definition: json11.cpp:597
BOARD * GetBoard() const

References WX_GRID::EnsureColLabelsVisible(), PCB_BASE_FRAME::GetBoard(), BOARD::GetDesignSettings(), WX_GRID::GetVisibleWidth(), i, KiBitmap(), PANEL_SETUP_NETCLASSES_BASE::m_addButton, m_BrdSettings, m_ConstraintsPanel, m_Frame, PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid, m_netclassesDirty, PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, m_originalColWidths, m_Parent, m_Pcb, PANEL_SETUP_NETCLASSES_BASE::m_removeButton, max, and OnNetclassGridCellChanging().

◆ ~PANEL_SETUP_NETCLASSES()

PANEL_SETUP_NETCLASSES::~PANEL_SETUP_NETCLASSES ( )
override

Definition at line 114 of file panel_setup_netclasses.cpp.

115 {
116  delete [] m_originalColWidths;
117 
118  // Delete the GRID_TRICKS.
119  m_netclassGrid->PopEventHandler( true );
120  m_membershipGrid->PopEventHandler( true );
121 
122  m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging ), NULL, this );
123 }
void OnNetclassGridCellChanging(wxGridEvent &event)

References PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid, PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, m_originalColWidths, and OnNetclassGridCellChanging().

Member Function Documentation

◆ addNet()

void PANEL_SETUP_NETCLASSES::addNet ( wxString  netName,
const wxString &  netclass 
)
private

Definition at line 184 of file panel_setup_netclasses.cpp.

185 {
186  int i = m_membershipGrid->GetNumberRows();
187 
188  m_membershipGrid->AppendRows( 1 );
189 
190  m_membershipGrid->SetCellValue( i, 0, netName );
191  m_membershipGrid->SetCellValue( i, 1, netclass );
192 }
size_t i
Definition: json11.cpp:597

References i, and PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid.

Referenced by TransferDataToWindow().

◆ AdjustMembershipGridColumns()

void PANEL_SETUP_NETCLASSES::AdjustMembershipGridColumns ( int  aWidth)
private

Definition at line 394 of file panel_setup_netclasses.cpp.

395 {
396  // Account for scroll bars
397  aWidth -= ( m_membershipGrid->GetSize().x - m_membershipGrid->GetClientSize().x );
398 
399  // Set className column width to original className width from netclasses grid
400  int classNameWidth = m_originalColWidths[ 0 ];
401  m_membershipGrid->SetColSize( 1, m_originalColWidths[ 0 ] );
402  m_membershipGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) );
403 }
#define max(a, b)
Definition: auxiliary.h:86

References PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid, m_originalColWidths, and max.

Referenced by OnSizeMembershipGrid().

◆ AdjustNetclassGridColumns()

void PANEL_SETUP_NETCLASSES::AdjustNetclassGridColumns ( int  aWidth)
private

Definition at line 371 of file panel_setup_netclasses.cpp.

372 {
373  // Account for scroll bars
374  aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
375 
376  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
377  {
378  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
379  aWidth -= m_originalColWidths[ i ];
380  }
381 
382  m_netclassGrid->SetColSize( 0, std::max( aWidth, m_originalColWidths[ 0 ] ) );
383 }
#define max(a, b)
Definition: auxiliary.h:86
size_t i
Definition: json11.cpp:597

References i, PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, m_originalColWidths, and max.

Referenced by OnSizeNetclassGrid().

◆ doApplyFilters()

void PANEL_SETUP_NETCLASSES::doApplyFilters ( bool  aShowAll)
private

Definition at line 414 of file panel_setup_netclasses.cpp.

415 {
417  return;
418 
419  wxString netClassFilter = m_netClassFilter->GetStringSelection();
420  wxString netFilter = m_netNameFilter->GetValue().MakeLower();
421 
422  if( !netFilter.IsEmpty() )
423  netFilter = wxT( "*" ) + netFilter + wxT( "*" );
424 
425  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
426  {
427  wxString net = m_membershipGrid->GetCellValue( row, 0 );
428  wxString netClass = m_membershipGrid->GetCellValue( row, 1 );
429  bool show = true;
430 
431  if( !aShowAll )
432  {
433  if( !netFilter.IsEmpty() && !net.MakeLower().Matches( netFilter ) )
434  show = false;
435 
436  if( !netClassFilter.IsEmpty() && netClass != netClassFilter )
437  show = false;
438  }
439 
440  if( show )
441  m_membershipGrid->ShowRow( row );
442  else
443  m_membershipGrid->HideRow( row );
444  }
445 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:167

References WX_GRID::CommitPendingChanges(), PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid, PANEL_SETUP_NETCLASSES_BASE::m_netClassFilter, and PANEL_SETUP_NETCLASSES_BASE::m_netNameFilter.

Referenced by OnApplyFilters(), and OnShowAll().

◆ doAssignments()

void PANEL_SETUP_NETCLASSES::doAssignments ( bool  aAssignAll)
private

Definition at line 448 of file panel_setup_netclasses.cpp.

449 {
451  return;
452 
453  wxArrayInt selectedRows = m_membershipGrid->GetSelectedRows();
454 
455  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
456  {
457  if( !m_membershipGrid->IsRowShown( row ) )
458  continue;
459 
460  if( !aAssignAll && selectedRows.Index( row ) == wxNOT_FOUND )
461  continue;
462 
463  m_membershipGrid->SetCellValue( row, 1, m_assignNetClass->GetStringSelection() );
464  }
465 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:167

References WX_GRID::CommitPendingChanges(), PANEL_SETUP_NETCLASSES_BASE::m_assignNetClass, and PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid.

Referenced by OnAssignAll(), and OnAssignSelected().

◆ getNetclassValue()

int PANEL_SETUP_NETCLASSES::getNetclassValue ( int  aRow,
int  aCol 
)
private

Definition at line 478 of file panel_setup_netclasses.cpp.

479 {
480  return ValueFromString( m_Frame->GetUserUnits(), m_netclassGrid->GetCellValue( aRow, aCol ), true );
481 }
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:409
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:289

References EDA_DRAW_FRAME::GetUserUnits(), m_Frame, PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, and ValueFromString().

Referenced by validateData().

◆ ImportSettingsFrom()

void PANEL_SETUP_NETCLASSES::ImportSettingsFrom ( BOARD aBoard)

Definition at line 575 of file panel_setup_netclasses.cpp.

576 {
577  // Note: do not change the board, as we need to get the current nets from it for
578  // netclass memberships. All the netclass definitions and dimension lists are in
579  // the BOARD_DESIGN_SETTINGS.
580 
581  BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
582 
583  m_BrdSettings = &aBoard->GetDesignSettings();
585 
586  m_netclassGrid->ForceRefresh();
587  m_membershipGrid->ForceRefresh();
588 
589  m_BrdSettings = savedSettings;
590 }
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:534
BOARD_DESIGN_SETTINGS * m_BrdSettings
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.

References BOARD::GetDesignSettings(), m_BrdSettings, PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid, PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, and TransferDataToWindow().

Referenced by DIALOG_BOARD_SETUP::OnAuxiliaryAction().

◆ OnAddNetclassClick()

void PANEL_SETUP_NETCLASSES::OnAddNetclassClick ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 316 of file panel_setup_netclasses.cpp.

317 {
319  return;
320 
321  int row = m_netclassGrid->GetNumberRows();
322  m_netclassGrid->AppendRows();
323 
324  // Copy values of the default class:
325  for( int col = 1; col < m_netclassGrid->GetNumberCols(); col++ )
326  m_netclassGrid->SetCellValue( row, col, m_netclassGrid->GetCellValue( 0, col ) );
327 
328  m_netclassGrid->MakeCellVisible( row, 0 );
329  m_netclassGrid->SetGridCursor( row, 0 );
330 
331  m_netclassGrid->EnableCellEditControl( true );
332  m_netclassGrid->ShowCellEditControl();
333 
334  m_netclassesDirty = true;
335 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:167

References WX_GRID::CommitPendingChanges(), m_netclassesDirty, and PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid.

◆ OnApplyFilters()

void PANEL_SETUP_NETCLASSES::OnApplyFilters ( wxCommandEvent &  event)
inlineoverrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 62 of file panel_setup_netclasses.h.

62 { doApplyFilters( false ); }
void doApplyFilters(bool aShowAll)

References doApplyFilters().

◆ OnAssignAll()

void PANEL_SETUP_NETCLASSES::OnAssignAll ( wxCommandEvent &  event)
inlineoverrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 63 of file panel_setup_netclasses.h.

63 { doAssignments( true ); }
void doAssignments(bool aAssignAll)

References doAssignments().

◆ OnAssignSelected()

void PANEL_SETUP_NETCLASSES::OnAssignSelected ( wxCommandEvent &  event)
inlineoverrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 64 of file panel_setup_netclasses.h.

64 { doAssignments( false ); }
void doAssignments(bool aAssignAll)

References doAssignments().

◆ OnNetclassGridCellChanging()

void PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging ( wxGridEvent &  event)
private

Definition at line 304 of file panel_setup_netclasses.cpp.

305 {
306  if( event.GetCol() == GRID_NAME )
307  {
308  if( validateNetclassName( event.GetRow(), event.GetString() ) )
309  m_netclassesDirty = true;
310  else
311  event.Veto();
312  }
313 }
bool validateNetclassName(int aRow, wxString aName, bool focusFirst=true)

References GRID_NAME, m_netclassesDirty, and validateNetclassName().

Referenced by PANEL_SETUP_NETCLASSES(), and ~PANEL_SETUP_NETCLASSES().

◆ OnRemoveNetclassClick()

void PANEL_SETUP_NETCLASSES::OnRemoveNetclassClick ( wxCommandEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 338 of file panel_setup_netclasses.cpp.

339 {
341  return;
342 
343  int curRow = m_netclassGrid->GetGridCursorRow();
344 
345  if( curRow < 0 )
346  return;
347  else if( curRow == 0 )
348  {
349  DisplayErrorMessage( this, _( "The default net class is required." ) );
350  return;
351  }
352 
353  // reset the net class to default for members of the removed class
354  wxString classname = m_netclassGrid->GetCellValue( curRow, GRID_NAME );
355 
356  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
357  {
358  if( m_membershipGrid->GetCellValue( row, 1 ) == classname )
359  m_membershipGrid->SetCellValue( row, 1, NETCLASS::Default );
360  }
361 
362  m_netclassGrid->DeleteRows( curRow, 1 );
363 
364  m_netclassGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
365  m_netclassGrid->SetGridCursor( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
366 
367  m_netclassesDirty = true;
368 }
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:258
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:80
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:167
#define max(a, b)
Definition: auxiliary.h:86

References WX_GRID::CommitPendingChanges(), NETCLASS::Default, DisplayErrorMessage(), GRID_NAME, PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid, m_netclassesDirty, PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, and max.

◆ OnShowAll()

void PANEL_SETUP_NETCLASSES::OnShowAll ( wxCommandEvent &  event)
inlineoverrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 61 of file panel_setup_netclasses.h.

61 { doApplyFilters( true ); }
void doApplyFilters(bool aShowAll)

References doApplyFilters().

◆ OnSizeMembershipGrid()

void PANEL_SETUP_NETCLASSES::OnSizeMembershipGrid ( wxSizeEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 406 of file panel_setup_netclasses.cpp.

407 {
408  AdjustMembershipGridColumns( event.GetSize().GetX() );
409 
410  event.Skip();
411 }
void AdjustMembershipGridColumns(int aWidth)

References AdjustMembershipGridColumns().

◆ OnSizeNetclassGrid()

void PANEL_SETUP_NETCLASSES::OnSizeNetclassGrid ( wxSizeEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 386 of file panel_setup_netclasses.cpp.

387 {
388  AdjustNetclassGridColumns( event.GetSize().GetX() );
389 
390  event.Skip();
391 }
void AdjustNetclassGridColumns(int aWidth)

References AdjustNetclassGridColumns().

◆ OnUpdateUI()

void PANEL_SETUP_NETCLASSES::OnUpdateUI ( wxUpdateUIEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 468 of file panel_setup_netclasses.cpp.

469 {
470  if( m_netclassesDirty )
471  {
473  m_netclassesDirty = false;
474  }
475 }

References m_netclassesDirty, and rebuildNetclassDropdowns().

◆ rebuildNetclassDropdowns()

void PANEL_SETUP_NETCLASSES::rebuildNetclassDropdowns ( )
private

Definition at line 197 of file panel_setup_netclasses.cpp.

198 {
200 
201  wxArrayString netclassNames;
202 
203  for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
204  {
205  wxString netclassName = m_netclassGrid->GetCellValue( ii, GRID_NAME );
206  if( !netclassName.IsEmpty() )
207  netclassNames.push_back( netclassName );
208  }
209 
210  wxGridCellAttr* attr = new wxGridCellAttr;
211  attr->SetEditor( new wxGridCellChoiceEditor( netclassNames ) );
212  m_membershipGrid->SetColAttr( 1, attr );
213 
214  m_assignNetClass->Set( netclassNames );
215 
216  netclassNames.Insert( wxEmptyString, 0 );
217  m_netClassFilter->Set( netclassNames );
218 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:167

References WX_GRID::CommitPendingChanges(), GRID_NAME, PANEL_SETUP_NETCLASSES_BASE::m_assignNetClass, PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid, PANEL_SETUP_NETCLASSES_BASE::m_netClassFilter, and PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid.

Referenced by OnUpdateUI().

◆ TransferDataFromWindow()

bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow ( )
override

Definition at line 240 of file panel_setup_netclasses.cpp.

241 {
242  if( !validateData() )
243  return false;
244 
245  NETCLASSES& netclasses = m_BrdSettings->m_NetClasses;
246 
247  // Remove all netclasses from board. We'll copy new list after
248  netclasses.Clear();
249 
250  // Copy the default NetClass:
252 
253  // Copy other NetClasses :
254  for( int row = 1; row < m_netclassGrid->GetNumberRows(); ++row )
255  {
256  NETCLASSPTR nc = std::make_shared<NETCLASS>( m_netclassGrid->GetCellValue( row, GRID_NAME ) );
257 
258  if( m_BrdSettings->m_NetClasses.Add( nc ) )
260  }
261 
262  // Now read all nets and push them in the corresponding netclass net buffer
263  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
264  {
265  NETCLASSPTR nc = netclasses.Find( m_membershipGrid->GetCellValue( row, 1 ) );
266 
267  if( nc )
268  nc->Add( m_membershipGrid->GetCellValue( row, 0 ) );
269  }
270 
273 
274  return true;
275 }
NETCLASSPTR Find(const wxString &aName) const
Function Find searches this container for a NETCLASS given by aName.
Definition: netclass.cpp:141
void SynchronizeNetsAndNetClasses()
Function SynchronizeNetsAndNetClasses copies NETCLASS info to each NET, based on NET membership in a ...
Definition: netclass.cpp:155
Class NETCLASSES is a container for NETCLASS instances.
Definition: netclass.h:224
static const char Default[]
the name of the default NETCLASS
Definition: netclass.h:80
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:289
static void gridRowToNetclass(EDA_UNITS_T aUnits, wxGrid *grid, int row, const NETCLASSPTR &nc)
BOARD_DESIGN_SETTINGS * m_BrdSettings
bool Add(const NETCLASSPTR &aNetclass)
Function Add takes aNetclass and puts it into this NETCLASSES container.
Definition: netclass.cpp:99
bool SetCurrentNetClass(const wxString &aNetClassName)
Function SetCurrentNetClass Must be called after a netclass selection (or after a netclass parameter ...
void Clear()
Function Clear destroys any contained NETCLASS instances except the Default one.
Definition: netclass.h:242
NETCLASSPTR GetDefault() const
Function GetDefault.
Definition: netclass.h:268

References NETCLASSES::Add(), NETCLASSES::Clear(), NETCLASS::Default, NETCLASSES::Find(), NETCLASSES::GetDefault(), EDA_DRAW_FRAME::GetUserUnits(), GRID_NAME, gridRowToNetclass(), m_BrdSettings, m_Frame, PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid, BOARD_DESIGN_SETTINGS::m_NetClasses, PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, m_Pcb, BOARD_DESIGN_SETTINGS::SetCurrentNetClass(), BOARD::SynchronizeNetsAndNetClasses(), and validateData().

◆ TransferDataToWindow()

bool PANEL_SETUP_NETCLASSES::TransferDataToWindow ( )
override

Definition at line 145 of file panel_setup_netclasses.cpp.

146 {
147  NETCLASSES& netclasses = m_BrdSettings->m_NetClasses;
148  NETCLASSPTR netclass = netclasses.GetDefault();
149 
150  if( m_netclassGrid->GetNumberRows() )
151  m_netclassGrid->DeleteRows( 0, m_netclassGrid->GetNumberRows() );
152  m_netclassGrid->AppendRows( netclasses.GetCount() + 1 ); // + 1 for default netclass
153 
154  // enter the Default NETCLASS.
156 
157  // make the Default NETCLASS name read-only
158  wxGridCellAttr* cellAttr = m_netclassGrid->GetOrCreateCellAttr( 0, GRID_NAME );
159  cellAttr->SetReadOnly();
160  cellAttr->DecRef();
161 
162  // enter other netclasses
163  int row = 1;
164 
165  for( NETCLASSES::iterator i = netclasses.begin(); i != netclasses.end(); ++i, ++row )
167 
168  // ensure that all nets have net classes assigned
170 
171  if( m_membershipGrid->GetNumberRows() )
172  m_membershipGrid->DeleteRows( 0, m_membershipGrid->GetNumberRows() );
173 
174  for( NETINFO_ITEM* net : m_Pcb->GetNetInfo() )
175  {
176  if( net->GetNet() > 0 && net->IsCurrent() )
177  addNet( UnescapeString( net->GetNetname() ), net->GetNetClass()->GetName() );
178  }
179 
180  return true;
181 }
void BuildListOfNets()
Definition: class_board.h:727
iterator end()
Definition: netclass.h:249
static void netclassToGridRow(EDA_UNITS_T aUnits, wxGrid *aGrid, int aRow, const NETCLASSPTR &nc)
NETCLASS_MAP::iterator iterator
Definition: netclass.h:247
iterator begin()
Definition: netclass.h:248
Class NETCLASSES is a container for NETCLASS instances.
Definition: netclass.h:224
void addNet(wxString netName, const wxString &netclass)
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:289
BOARD_DESIGN_SETTINGS * m_BrdSettings
NETINFO_LIST & GetNetInfo()
Definition: class_board.h:748
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:123
size_t i
Definition: json11.cpp:597
unsigned GetCount() const
Function GetCount.
Definition: netclass.h:259
NETCLASSPTR GetDefault() const
Function GetDefault.
Definition: netclass.h:268

References addNet(), NETCLASSES::begin(), BOARD::BuildListOfNets(), NETCLASSES::end(), NETCLASSES::GetCount(), NETCLASSES::GetDefault(), BOARD::GetNetInfo(), EDA_DRAW_FRAME::GetUserUnits(), GRID_NAME, i, m_BrdSettings, m_Frame, PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid, BOARD_DESIGN_SETTINGS::m_NetClasses, PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, m_Pcb, netclassToGridRow(), and UnescapeString().

Referenced by ImportSettingsFrom().

◆ validateData()

bool PANEL_SETUP_NETCLASSES::validateData ( )
private

Definition at line 484 of file panel_setup_netclasses.cpp.

485 {
487  return false;
488 
489  wxString msg;
490  int minViaDia = m_ConstraintsPanel->m_viaMinSize.GetValue();
491  int minViaDrill = m_ConstraintsPanel->m_viaMinDrill.GetValue();
492  int minUViaDia = m_ConstraintsPanel->m_uviaMinSize.GetValue();
493  int minUViaDrill = m_ConstraintsPanel->m_uviaMinDrill.GetValue();
494  int minTrackWidth = m_ConstraintsPanel->m_trackMinWidth.GetValue();
495 
496  // Test net class parameters.
497  for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
498  {
499  wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
500  netclassName.Trim( true );
501  netclassName.Trim( false );
502 
503  if( !validateNetclassName( row, netclassName, false ) )
504  return false;
505 
506  if( getNetclassValue( row, GRID_TRACKSIZE ) < minTrackWidth )
507  {
508  msg.Printf( _( "Track width less than minimum track width (%s)." ),
509  StringFromValue( m_Frame->GetUserUnits(), minTrackWidth, true, true ) );
510  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_TRACKSIZE );
511  return false;
512  }
513 
514  if( getNetclassValue( row, GRID_DIFF_PAIR_WIDTH ) < minTrackWidth )
515  {
516  msg.Printf( _( "Differential pair width less than minimum track width (%s)." ),
517  StringFromValue( m_Frame->GetUserUnits(), minTrackWidth, true, true ) );
519  return false;
520  }
521 
522  // Test vias
523  if( getNetclassValue( row, GRID_VIASIZE ) < minViaDia )
524  {
525  msg.Printf( _( "Via diameter less than minimum via diameter (%s)." ),
526  StringFromValue( m_Frame->GetUserUnits(), minViaDia, true, true ) );
527  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_VIASIZE );
528  return false;
529  }
530 
532  {
533  msg = _( "Via drill larger than via diameter." );
534  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_VIADRILL );
535  return false;
536  }
537 
538  if( getNetclassValue( row, GRID_VIADRILL ) < minViaDrill )
539  {
540  msg.Printf( _( "Via drill less than minimum via drill (%s)." ),
541  StringFromValue( m_Frame->GetUserUnits(), minViaDrill, true, true ) );
542  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_VIADRILL );
543  return false;
544  }
545 
546  // Test Micro vias
547  if( getNetclassValue( row, GRID_uVIASIZE ) < minUViaDia )
548  {
549  msg.Printf( _( "Microvia diameter less than minimum microvia diameter (%s)." ),
550  StringFromValue( m_Frame->GetUserUnits(), minUViaDia, true, true ) );
551  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_uVIASIZE );
552  return false;
553  }
554 
556  {
557  msg = _( "Microvia drill larger than microvia diameter." );
558  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_uVIADRILL );
559  return false;
560  }
561 
562  if( getNetclassValue( row, GRID_uVIADRILL ) < minUViaDrill )
563  {
564  msg.Printf( _( "Microvia drill less than minimum microvia drill (%s)." ),
565  StringFromValue( m_Frame->GetUserUnits(), minUViaDrill, true, true ) );
566  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_uVIADRILL );
567  return false;
568  }
569  }
570 
571  return true;
572 }
int getNetclassValue(int aRow, int aCol)
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:289
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:167
void SetError(const wxString &aMessage, wxWindow *aPage, wxObject *aCtrl, int aRow=-1, int aCol=-1)
PANEL_SETUP_FEATURE_CONSTRAINTS * m_ConstraintsPanel
wxString StringFromValue(EDA_UNITS_T aUnits, int aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:210
bool validateNetclassName(int aRow, wxString aName, bool focusFirst=true)

References WX_GRID::CommitPendingChanges(), getNetclassValue(), EDA_DRAW_FRAME::GetUserUnits(), UNIT_BINDER::GetValue(), GRID_DIFF_PAIR_WIDTH, GRID_NAME, GRID_TRACKSIZE, GRID_uVIADRILL, GRID_uVIASIZE, GRID_VIADRILL, GRID_VIASIZE, m_ConstraintsPanel, m_Frame, PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid, PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, m_Parent, PANEL_SETUP_FEATURE_CONSTRAINTS::m_trackMinWidth, PANEL_SETUP_FEATURE_CONSTRAINTS::m_uviaMinDrill, PANEL_SETUP_FEATURE_CONSTRAINTS::m_uviaMinSize, PANEL_SETUP_FEATURE_CONSTRAINTS::m_viaMinDrill, PANEL_SETUP_FEATURE_CONSTRAINTS::m_viaMinSize, PAGED_DIALOG::SetError(), StringFromValue(), and validateNetclassName().

Referenced by TransferDataFromWindow().

◆ validateNetclassName()

bool PANEL_SETUP_NETCLASSES::validateNetclassName ( int  aRow,
wxString  aName,
bool  focusFirst = true 
)
private

Definition at line 278 of file panel_setup_netclasses.cpp.

279 {
280  aName.Trim( true );
281  aName.Trim( false );
282 
283  if( aName.IsEmpty() )
284  {
285  wxString msg = _( "Netclass must have a name." );
286  m_Parent->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME );
287  return false;
288  }
289 
290  for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
291  {
292  if( ii != aRow && m_netclassGrid->GetRowLabelValue( ii ).CmpNoCase( aName ) == 0 )
293  {
294  wxString msg = _( "Netclass name already in use." );
295  m_Parent->SetError( msg, this, m_netclassGrid, focusFirst ? aRow : ii, GRID_NAME );
296  return false;
297  }
298  }
299 
300  return true;
301 }
void SetError(const wxString &aMessage, wxWindow *aPage, wxObject *aCtrl, int aRow=-1, int aCol=-1)

References GRID_NAME, PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, m_Parent, and PAGED_DIALOG::SetError().

Referenced by OnNetclassGridCellChanging(), and validateData().

Member Data Documentation

◆ m_addButton

wxBitmapButton* PANEL_SETUP_NETCLASSES_BASE::m_addButton
protectedinherited

◆ m_assignAllButton

wxButton* PANEL_SETUP_NETCLASSES_BASE::m_assignAllButton
protectedinherited

◆ m_assignLabel

wxStaticText* PANEL_SETUP_NETCLASSES_BASE::m_assignLabel
protectedinherited

◆ m_assignNetClass

wxChoice* PANEL_SETUP_NETCLASSES_BASE::m_assignNetClass
protectedinherited

◆ m_assignSelectedButton

wxButton* PANEL_SETUP_NETCLASSES_BASE::m_assignSelectedButton
protectedinherited

◆ m_BrdSettings

BOARD_DESIGN_SETTINGS* PANEL_SETUP_NETCLASSES::m_BrdSettings
private

◆ m_ConstraintsPanel

PANEL_SETUP_FEATURE_CONSTRAINTS* PANEL_SETUP_NETCLASSES::m_ConstraintsPanel
private

Definition at line 49 of file panel_setup_netclasses.h.

Referenced by PANEL_SETUP_NETCLASSES(), and validateData().

◆ m_filterLabel

wxStaticText* PANEL_SETUP_NETCLASSES_BASE::m_filterLabel
protectedinherited

◆ m_filterNetsButton

wxButton* PANEL_SETUP_NETCLASSES_BASE::m_filterNetsButton
protectedinherited

◆ m_Frame

PCB_EDIT_FRAME* PANEL_SETUP_NETCLASSES::m_Frame
private

◆ m_membershipGrid

◆ m_ncfilterLabel

wxStaticText* PANEL_SETUP_NETCLASSES_BASE::m_ncfilterLabel
protectedinherited

◆ m_netclassesDirty

bool PANEL_SETUP_NETCLASSES::m_netclassesDirty
private

◆ m_netClassFilter

wxChoice* PANEL_SETUP_NETCLASSES_BASE::m_netClassFilter
protectedinherited

◆ m_netclassGrid

◆ m_netNameFilter

wxTextCtrl* PANEL_SETUP_NETCLASSES_BASE::m_netNameFilter
protectedinherited

◆ m_originalColWidths

int* PANEL_SETUP_NETCLASSES::m_originalColWidths
private

◆ m_Parent

PAGED_DIALOG* PANEL_SETUP_NETCLASSES::m_Parent
private

◆ m_Pcb

BOARD* PANEL_SETUP_NETCLASSES::m_Pcb
private

◆ m_removeButton

wxBitmapButton* PANEL_SETUP_NETCLASSES_BASE::m_removeButton
protectedinherited

◆ m_showAllButton

wxButton* PANEL_SETUP_NETCLASSES_BASE::m_showAllButton
protectedinherited

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