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

wxPanel * m_netclassesPane
 
WX_GRIDm_netclassGrid
 
wxBitmapButton * m_addButton
 
wxBitmapButton * m_removeButton
 
wxPanel * m_membershipPane
 
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
 
wxSize m_membershipSize
 

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 51 of file panel_setup_netclasses.cpp.

52  :
54 {
55  m_Parent = aParent;
56  m_Frame = aFrame;
57  m_Pcb = m_Frame->GetBoard();
59  m_ConstraintsPanel = aConstraintsPanel;
60 
61  m_netclassesDirty = true;
62 
63  // Figure out the smallest the netclass membership pane can ever be so that nothing is cutoff
64  // and force it to be that size.
65  m_membershipSize = GetSize();
66  m_membershipSize.y -= m_netclassesPane->GetSize().y;
67  m_membershipSize.x = -1;
68  m_membershipPane->SetMinSize( m_membershipSize );
69  m_membershipPane->SetMaxSize( m_membershipSize );
70 
71  // Prevent Size events from firing before we are ready
72  Freeze();
73  m_netclassGrid->BeginBatch();
74  m_membershipGrid->BeginBatch();
75 
76  m_originalColWidths = new int[ m_netclassGrid->GetNumberCols() ];
77  // Calculate a min best size to handle longest usual numeric values:
78  int min_best_width = m_netclassGrid->GetTextExtent( "555,555555 mils" ).x;
79 
80  for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
81  {
82  // We calculate the column min size only from texts sizes, not using the initial col width
83  // as this initial width is sometimes strange depending on the language (wxGrid bug?)
84  int min_width = m_netclassGrid->GetVisibleWidth( i, true, true, false );
85  m_netclassGrid->SetColMinimalWidth( i, min_width );
86  // We use a "best size" >= min_best_width
87  m_originalColWidths[ i ] = std::max( min_width, min_best_width );
88  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
89  }
90 
91  // Be sure the column labels are readable
93 
94  // Membership combobox editors require a bit more room, so increase the row size of
95  // all our grids for consistency
96  m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );
97  m_membershipGrid->SetDefaultRowSize( m_membershipGrid->GetDefaultRowSize() + 4 );
98 
99  m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
100  m_membershipGrid->PushEventHandler( new GRID_TRICKS( m_membershipGrid ) );
101 
102  m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
103  m_membershipGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
104 
105  // Set up the net name column of the netclass membership grid to read-only
106  wxGridCellAttr* attr = new wxGridCellAttr;
107  attr->SetReadOnly( true );
108  m_membershipGrid->SetColAttr( 0, attr );
109 
110  m_addButton->SetBitmap( KiBitmap( small_plus_xpm ) );
111  m_removeButton->SetBitmap( KiBitmap( trash_xpm ) );
112 
113  // wxFormBuilder doesn't include this event...
114  m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging ), NULL, this );
115 
116  m_netclassGrid->EndBatch();
117  m_membershipGrid->EndBatch();
118  Thaw();
119 }
const BITMAP_OPAQUE trash_xpm[1]
Definition: trash.cpp:46
GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID ins...
Definition: grid_tricks.h:51
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:542
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:230
wxTreebook * GetTreebook()
Definition: paged_dialog.h:45
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
#define NULL
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:272
void OnNetclassGridCellChanging(wxGridEvent &event)
BOARD_DESIGN_SETTINGS * m_BrdSettings
PANEL_SETUP_FEATURE_CONSTRAINTS * m_ConstraintsPanel
BOARD * GetBoard() const
const BITMAP_OPAQUE small_plus_xpm[1]
Definition: small_plus.cpp:20

References WX_GRID::EnsureColLabelsVisible(), PCB_BASE_FRAME::GetBoard(), BOARD::GetDesignSettings(), WX_GRID::GetVisibleWidth(), KiBitmap(), PANEL_SETUP_NETCLASSES_BASE::m_addButton, m_BrdSettings, m_ConstraintsPanel, m_Frame, PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid, PANEL_SETUP_NETCLASSES_BASE::m_membershipPane, m_membershipSize, m_netclassesDirty, PANEL_SETUP_NETCLASSES_BASE::m_netclassesPane, PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, m_originalColWidths, m_Parent, m_Pcb, PANEL_SETUP_NETCLASSES_BASE::m_removeButton, NULL, OnNetclassGridCellChanging(), small_plus_xpm, and trash_xpm.

◆ ~PANEL_SETUP_NETCLASSES()

PANEL_SETUP_NETCLASSES::~PANEL_SETUP_NETCLASSES ( )
override

Definition at line 122 of file panel_setup_netclasses.cpp.

123 {
124  delete [] m_originalColWidths;
125 
126  // Delete the GRID_TRICKS.
127  m_netclassGrid->PopEventHandler( true );
128  m_membershipGrid->PopEventHandler( true );
129 
130  m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging ), NULL, this );
131 }
#define NULL
void OnNetclassGridCellChanging(wxGridEvent &event)

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

Member Function Documentation

◆ addNet()

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

Definition at line 192 of file panel_setup_netclasses.cpp.

193 {
194  int i = m_membershipGrid->GetNumberRows();
195 
196  m_membershipGrid->AppendRows( 1 );
197 
198  m_membershipGrid->SetCellValue( i, 0, netName );
199  m_membershipGrid->SetCellValue( i, 1, netclass );
200 }

References PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid.

Referenced by TransferDataToWindow().

◆ AdjustMembershipGridColumns()

void PANEL_SETUP_NETCLASSES::AdjustMembershipGridColumns ( int  aWidth)
private

Definition at line 405 of file panel_setup_netclasses.cpp.

406 {
407  // Account for scroll bars
408  aWidth -= ( m_membershipGrid->GetSize().x - m_membershipGrid->GetClientSize().x );
409 
410  // Set className column width to original className width from netclasses grid
411  int classNameWidth = m_originalColWidths[ 0 ];
412  m_membershipGrid->SetColSize( 1, m_originalColWidths[ 0 ] );
413  m_membershipGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) );
414 }

References PANEL_SETUP_NETCLASSES_BASE::m_membershipGrid, and m_originalColWidths.

Referenced by OnSizeMembershipGrid().

◆ AdjustNetclassGridColumns()

void PANEL_SETUP_NETCLASSES::AdjustNetclassGridColumns ( int  aWidth)
private

Definition at line 382 of file panel_setup_netclasses.cpp.

383 {
384  // Account for scroll bars
385  aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
386 
387  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
388  {
389  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
390  aWidth -= m_originalColWidths[ i ];
391  }
392 
393  m_netclassGrid->SetColSize( 0, std::max( aWidth - 2, m_originalColWidths[ 0 ] ) );
394 }

References PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, and m_originalColWidths.

Referenced by OnSizeNetclassGrid().

◆ doApplyFilters()

void PANEL_SETUP_NETCLASSES::doApplyFilters ( bool  aShowAll)
private

Definition at line 425 of file panel_setup_netclasses.cpp.

426 {
428  return;
429 
430  wxString netClassFilter = m_netClassFilter->GetStringSelection();
431  wxString netFilter = m_netNameFilter->GetValue().MakeLower();
432 
433  if( !netFilter.IsEmpty() )
434  netFilter = wxT( "*" ) + netFilter + wxT( "*" );
435 
436  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
437  {
438  wxString net = m_membershipGrid->GetCellValue( row, 0 );
439  wxString netClass = m_membershipGrid->GetCellValue( row, 1 );
440  bool show = true;
441 
442  if( !aShowAll )
443  {
444  if( !netFilter.IsEmpty() && !net.MakeLower().Matches( netFilter ) )
445  show = false;
446 
447  if( !netClassFilter.IsEmpty() && netClass != netClassFilter )
448  show = false;
449  }
450 
451  if( show )
452  m_membershipGrid->ShowRow( row );
453  else
454  m_membershipGrid->HideRow( row );
455  }
456 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174

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 459 of file panel_setup_netclasses.cpp.

460 {
462  return;
463 
464  wxArrayInt selectedRows = m_membershipGrid->GetSelectedRows();
465 
466  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
467  {
468  if( !m_membershipGrid->IsRowShown( row ) )
469  continue;
470 
471  if( !aAssignAll && selectedRows.Index( row ) == wxNOT_FOUND )
472  continue;
473 
474  m_membershipGrid->SetCellValue( row, 1, m_assignNetClass->GetStringSelection() );
475  }
476 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174

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 506 of file panel_setup_netclasses.cpp.

507 {
508  return ValueFromString( m_Frame->GetUserUnits(), m_netclassGrid->GetCellValue( aRow, aCol ), true );
509 }
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:443
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References EDA_BASE_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 624 of file panel_setup_netclasses.cpp.

625 {
626  // Note: do not change the board, as we need to get the current nets from it for
627  // netclass memberships. All the netclass definitions and dimension lists are in
628  // the BOARD_DESIGN_SETTINGS.
629 
630  BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
631 
632  m_BrdSettings = &aBoard->GetDesignSettings();
634 
636 
637  m_netclassGrid->ForceRefresh();
638  m_membershipGrid->ForceRefresh();
639 
640  m_BrdSettings = savedSettings;
641 }
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:542
BOARD_DESIGN_SETTINGS * m_BrdSettings
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, rebuildNetclassDropdowns(), 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 327 of file panel_setup_netclasses.cpp.

328 {
330  return;
331 
332  int row = m_netclassGrid->GetNumberRows();
333  m_netclassGrid->AppendRows();
334 
335  // Copy values of the default class:
336  for( int col = 1; col < m_netclassGrid->GetNumberCols(); col++ )
337  m_netclassGrid->SetCellValue( row, col, m_netclassGrid->GetCellValue( 0, col ) );
338 
339  m_netclassGrid->MakeCellVisible( row, 0 );
340  m_netclassGrid->SetGridCursor( row, 0 );
341 
342  m_netclassGrid->EnableCellEditControl( true );
343  m_netclassGrid->ShowCellEditControl();
344 
345  m_netclassesDirty = true;
346 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174

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 64 of file panel_setup_netclasses.h.

64 { 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 65 of file panel_setup_netclasses.h.

65 { 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 66 of file panel_setup_netclasses.h.

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

References doAssignments().

◆ OnNetclassGridCellChanging()

void PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging ( wxGridEvent &  event)
private

Definition at line 315 of file panel_setup_netclasses.cpp.

316 {
317  if( event.GetCol() == GRID_NAME )
318  {
319  if( validateNetclassName( event.GetRow(), event.GetString() ) )
320  m_netclassesDirty = true;
321  else
322  event.Veto();
323  }
324 }
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 349 of file panel_setup_netclasses.cpp.

350 {
352  return;
353 
354  int curRow = m_netclassGrid->GetGridCursorRow();
355 
356  if( curRow < 0 )
357  return;
358  else if( curRow == 0 )
359  {
360  DisplayErrorMessage( this, _( "The default net class is required." ) );
361  return;
362  }
363 
364  // reset the net class to default for members of the removed class
365  wxString classname = m_netclassGrid->GetCellValue( curRow, GRID_NAME );
366 
367  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
368  {
369  if( m_membershipGrid->GetCellValue( row, 1 ) == classname )
370  m_membershipGrid->SetCellValue( row, 1, NETCLASS::Default );
371  }
372 
373  m_netclassGrid->DeleteRows( curRow, 1 );
374 
375  m_netclassGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
376  m_netclassGrid->SetGridCursor( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() );
377 
378  m_netclassesDirty = true;
379 }
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
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:174
#define _(s)
Definition: 3d_actions.cpp:33

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

◆ OnShowAll()

void PANEL_SETUP_NETCLASSES::OnShowAll ( wxCommandEvent &  event)
inlineoverrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 63 of file panel_setup_netclasses.h.

63 { 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 417 of file panel_setup_netclasses.cpp.

418 {
419  AdjustMembershipGridColumns( event.GetSize().GetX() );
420 
421  event.Skip();
422 }
void AdjustMembershipGridColumns(int aWidth)

References AdjustMembershipGridColumns().

◆ OnSizeNetclassGrid()

void PANEL_SETUP_NETCLASSES::OnSizeNetclassGrid ( wxSizeEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 397 of file panel_setup_netclasses.cpp.

398 {
399  AdjustNetclassGridColumns( event.GetSize().GetX() );
400 
401  event.Skip();
402 }
void AdjustNetclassGridColumns(int aWidth)

References AdjustNetclassGridColumns().

◆ OnUpdateUI()

void PANEL_SETUP_NETCLASSES::OnUpdateUI ( wxUpdateUIEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 479 of file panel_setup_netclasses.cpp.

480 {
481  if( m_netclassesDirty )
482  {
484  m_netclassesDirty = false;
485  }
486 
487  // Recompute the desired size for the two content panes. We cannot leave this sizing to
488  // wxWidgets because it wants to shrink the membership panel to an unusable size when the
489  // netlist panel grows, and also it introduces undesired artifacts when the window is resized
490  // and the panes can grow/shrink.
491  wxSize netclassSize = GetClientSize();
492  netclassSize.y -= m_membershipSize.y;
493 
494  // Modify m_netclassesPane size only if needed, because calling Layout() has the annoying
495  // effect of closing any open wxChoice dropdowns. So it cannot blindly called inside each
496  // wxUpdateUIEvent event, at least on Windows + wxWidgets 3.0 (not an issue with 3.1.1).
497  if( netclassSize.y != m_netclassesPane->GetSize().y )
498  {
499  m_netclassesPane->SetMinSize( netclassSize );
500  m_netclassesPane->SetMaxSize( netclassSize );
501  Layout();
502  }
503 }

References m_membershipSize, m_netclassesDirty, PANEL_SETUP_NETCLASSES_BASE::m_netclassesPane, and rebuildNetclassDropdowns().

◆ rebuildNetclassDropdowns()

void PANEL_SETUP_NETCLASSES::rebuildNetclassDropdowns ( )
private

Definition at line 205 of file panel_setup_netclasses.cpp.

206 {
208 
209  wxArrayString netclassNames;
210 
211  for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
212  {
213  wxString netclassName = m_netclassGrid->GetCellValue( ii, GRID_NAME );
214  if( !netclassName.IsEmpty() )
215  netclassNames.push_back( netclassName );
216  }
217 
218  wxGridCellAttr* attr = new wxGridCellAttr;
219  attr->SetEditor( new wxGridCellChoiceEditor( netclassNames ) );
220  m_membershipGrid->SetColAttr( 1, attr );
221 
222  m_assignNetClass->Set( netclassNames );
223 
224  netclassNames.Insert( wxEmptyString, 0 );
225  m_netClassFilter->Set( netclassNames );
226 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174

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 ImportSettingsFrom(), and OnUpdateUI().

◆ TransferDataFromWindow()

bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow ( )
override

Definition at line 248 of file panel_setup_netclasses.cpp.

249 {
250  if( !validateData() )
251  return false;
252 
253  NETCLASSES& netclasses = m_BrdSettings->m_NetClasses;
254 
255  // Remove all netclasses from board. We'll copy new list after
256  netclasses.Clear();
257 
258  // Copy the default NetClass:
260 
261  // Copy other NetClasses :
262  for( int row = 1; row < m_netclassGrid->GetNumberRows(); ++row )
263  {
264  NETCLASSPTR nc = std::make_shared<NETCLASS>( m_netclassGrid->GetCellValue( row, GRID_NAME ) );
265 
266  if( m_BrdSettings->m_NetClasses.Add( nc ) )
268  }
269 
270  // Now read all nets and push them in the corresponding netclass net buffer
271  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
272  {
273  NETCLASSPTR nc = netclasses.Find( m_membershipGrid->GetCellValue( row, 1 ) );
274 
275  if( nc )
276  nc->Add( m_membershipGrid->GetCellValue( row, 0 ) );
277  }
278 
281 
282  if( auto toolmgr = m_Frame->GetToolManager() )
283  toolmgr->ResetTools( TOOL_BASE::MODEL_RELOAD );
284 
285  return true;
286 }
NETCLASSPTR Find(const wxString &aName) const
Function Find searches this container for a NETCLASS given by aName.
Definition: netclass.cpp:141
Model changes (required full reload)
Definition: tool_base.h:82
void SynchronizeNetsAndNetClasses()
Function SynchronizeNetsAndNetClasses copies NETCLASS info to each NET, based on NET membership in a ...
Definition: netclass.cpp:155
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
static void gridRowToNetclass(EDA_UNITS 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
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:74
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References NETCLASSES::Add(), NETCLASSES::Clear(), NETCLASS::Default, NETCLASSES::Find(), NETCLASSES::GetDefault(), TOOLS_HOLDER::GetToolManager(), EDA_BASE_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, TOOL_BASE::MODEL_RELOAD, BOARD_DESIGN_SETTINGS::SetCurrentNetClass(), BOARD::SynchronizeNetsAndNetClasses(), and validateData().

◆ TransferDataToWindow()

bool PANEL_SETUP_NETCLASSES::TransferDataToWindow ( )
override

Definition at line 153 of file panel_setup_netclasses.cpp.

154 {
155  NETCLASSES& netclasses = m_BrdSettings->m_NetClasses;
156  NETCLASSPTR netclass = netclasses.GetDefault();
157 
158  if( m_netclassGrid->GetNumberRows() )
159  m_netclassGrid->DeleteRows( 0, m_netclassGrid->GetNumberRows() );
160  m_netclassGrid->AppendRows( netclasses.GetCount() + 1 ); // + 1 for default netclass
161 
162  // enter the Default NETCLASS.
164 
165  // make the Default NETCLASS name read-only
166  wxGridCellAttr* cellAttr = m_netclassGrid->GetOrCreateCellAttr( 0, GRID_NAME );
167  cellAttr->SetReadOnly();
168  cellAttr->DecRef();
169 
170  // enter other netclasses
171  int row = 1;
172 
173  for( NETCLASSES::iterator i = netclasses.begin(); i != netclasses.end(); ++i, ++row )
174  netclassToGridRow( m_Frame->GetUserUnits(), m_netclassGrid, row, i->second );
175 
176  // ensure that all nets have net classes assigned
178 
179  if( m_membershipGrid->GetNumberRows() )
180  m_membershipGrid->DeleteRows( 0, m_membershipGrid->GetNumberRows() );
181 
182  for( NETINFO_ITEM* net : m_Pcb->GetNetInfo() )
183  {
184  if( net->GetNet() > 0 && net->IsCurrent() )
185  addNet( UnescapeString( net->GetNetname() ), net->GetNetClass()->GetName() );
186  }
187 
188  return true;
189 }
void BuildListOfNets()
Definition: class_board.h:710
iterator end()
Definition: netclass.h:249
NETCLASS_MAP::iterator iterator
Definition: netclass.h:247
iterator begin()
Definition: netclass.h:248
NETCLASSES is a container for NETCLASS instances.
Definition: netclass.h:224
void addNet(wxString netName, const wxString &netclass)
BOARD_DESIGN_SETTINGS * m_BrdSettings
NETINFO_LIST & GetNetInfo()
Definition: class_board.h:731
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
unsigned GetCount() const
Function GetCount.
Definition: netclass.h:259
static void netclassToGridRow(EDA_UNITS aUnits, wxGrid *aGrid, int aRow, const NETCLASSPTR &nc)
NETCLASSPTR GetDefault() const
Function GetDefault.
Definition: netclass.h:268
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References addNet(), NETCLASSES::begin(), BOARD::BuildListOfNets(), NETCLASSES::end(), NETCLASSES::GetCount(), NETCLASSES::GetDefault(), BOARD::GetNetInfo(), EDA_BASE_FRAME::GetUserUnits(), GRID_NAME, 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 512 of file panel_setup_netclasses.cpp.

513 {
515  return false;
516 
517  wxString msg;
518  int minViaAnnulus = m_ConstraintsPanel->m_viaMinAnnulus.GetValue();
519  int minViaDia = m_ConstraintsPanel->m_viaMinSize.GetValue();
520  int minThroughHole = m_ConstraintsPanel->m_throughHoleMin.GetValue();
521  int minUViaDia = m_ConstraintsPanel->m_uviaMinSize.GetValue();
522  int minUViaDrill = m_ConstraintsPanel->m_uviaMinDrill.GetValue();
523  int minTrackWidth = m_ConstraintsPanel->m_trackMinWidth.GetValue();
524  int minClearance = m_ConstraintsPanel->m_minClearance.GetValue();
525 
526  // Test net class parameters.
527  for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
528  {
529  wxString netclassName = m_netclassGrid->GetCellValue( row, GRID_NAME );
530  netclassName.Trim( true );
531  netclassName.Trim( false );
532 
533  if( !validateNetclassName( row, netclassName, false ) )
534  return false;
535 
536  if( getNetclassValue( row, GRID_CLEARANCE ) < minClearance )
537  {
538  msg.Printf( _( "Clearance less than minimum clearance (%s)." ),
539  StringFromValue( m_Frame->GetUserUnits(), minClearance, true, true ) );
540  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_CLEARANCE );
541  return false;
542  }
543 
544  if( getNetclassValue( row, GRID_TRACKSIZE ) < minTrackWidth )
545  {
546  msg.Printf( _( "Track width less than minimum track width (%s)." ),
547  StringFromValue( m_Frame->GetUserUnits(), minTrackWidth, true, true ) );
548  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_TRACKSIZE );
549  return false;
550  }
551 
552  if( getNetclassValue( row, GRID_DIFF_PAIR_WIDTH ) < minTrackWidth )
553  {
554  msg.Printf( _( "Differential pair width less than minimum track width (%s)." ),
555  StringFromValue( m_Frame->GetUserUnits(), minTrackWidth, true, true ) );
557  return false;
558  }
559 
560  // Test vias
561  if( getNetclassValue( row, GRID_VIASIZE ) < minViaDia )
562  {
563  msg.Printf( _( "Via diameter less than minimum via diameter (%s)." ),
564  StringFromValue( m_Frame->GetUserUnits(), minViaDia, true, true ) );
565  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_VIASIZE );
566  return false;
567  }
568 
570  {
571  msg = _( "Via drill larger than via diameter." );
572  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_VIADRILL );
573  return false;
574  }
575 
576  if( ( getNetclassValue( row, GRID_VIASIZE )
577  - getNetclassValue( row, GRID_VIADRILL ) ) / 2 < minViaAnnulus )
578  {
579  msg.Printf( _( "Via diameter and drill leave via annulus less than minimum (%s)." ),
580  StringFromValue( m_Frame->GetUserUnits(), minViaAnnulus, true, true ) );
581  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_VIASIZE );
582  return false;
583  }
584 
585  if( getNetclassValue( row, GRID_VIADRILL ) < minThroughHole )
586  {
587  msg.Printf( _( "Via drill less than minimum via drill (%s)." ),
588  StringFromValue( m_Frame->GetUserUnits(), minThroughHole, true, true ) );
589  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_VIADRILL );
590  return false;
591  }
592 
593  // Test Micro vias
594  if( getNetclassValue( row, GRID_uVIASIZE ) < minUViaDia )
595  {
596  msg.Printf( _( "Microvia diameter less than minimum microvia diameter (%s)." ),
597  StringFromValue( m_Frame->GetUserUnits(), minUViaDia, true, true ) );
598  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_uVIASIZE );
599  return false;
600  }
601 
603  {
604  msg = _( "Microvia drill larger than microvia diameter." );
605  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_uVIADRILL );
606  return false;
607  }
608 
609  if( getNetclassValue( row, GRID_uVIADRILL ) < minUViaDrill )
610  {
611  msg.Printf( _( "Microvia drill less than minimum microvia drill (%s)." ),
612  StringFromValue( m_Frame->GetUserUnits(), minUViaDrill, true, true ) );
613  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_uVIADRILL );
614  return false;
615  }
616 
617  // JEY TODO: test microvias agains via min annulus?
618  }
619 
620  return true;
621 }
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:233
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
int getNetclassValue(int aRow, int aCol)
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:174
PANEL_SETUP_FEATURE_CONSTRAINTS * m_ConstraintsPanel
#define _(s)
Definition: 3d_actions.cpp:33
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
bool validateNetclassName(int aRow, wxString aName, bool focusFirst=true)
EDA_UNITS GetUserUnits() const
Return the user units currently in use.

References _, WX_GRID::CommitPendingChanges(), getNetclassValue(), EDA_BASE_FRAME::GetUserUnits(), UNIT_BINDER::GetValue(), GRID_CLEARANCE, 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_FEATURE_CONSTRAINTS::m_minClearance, PANEL_SETUP_NETCLASSES_BASE::m_netclassGrid, m_Parent, PANEL_SETUP_FEATURE_CONSTRAINTS::m_throughHoleMin, PANEL_SETUP_FEATURE_CONSTRAINTS::m_trackMinWidth, PANEL_SETUP_FEATURE_CONSTRAINTS::m_uviaMinDrill, PANEL_SETUP_FEATURE_CONSTRAINTS::m_uviaMinSize, PANEL_SETUP_FEATURE_CONSTRAINTS::m_viaMinAnnulus, 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 289 of file panel_setup_netclasses.cpp.

290 {
291  aName.Trim( true );
292  aName.Trim( false );
293 
294  if( aName.IsEmpty() )
295  {
296  wxString msg = _( "Netclass must have a name." );
297  m_Parent->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME );
298  return false;
299  }
300 
301  for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
302  {
303  if( ii != aRow && m_netclassGrid->GetRowLabelValue( ii ).CmpNoCase( aName ) == 0 )
304  {
305  wxString msg = _( "Netclass name already in use." );
306  m_Parent->SetError( msg, this, m_netclassGrid, focusFirst ? aRow : ii, GRID_NAME );
307  return false;
308  }
309  }
310 
311  return true;
312 }
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
#define _(s)
Definition: 3d_actions.cpp:33

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_membershipPane

wxPanel* PANEL_SETUP_NETCLASSES_BASE::m_membershipPane
protectedinherited

◆ m_membershipSize

wxSize PANEL_SETUP_NETCLASSES::m_membershipSize
private

Definition at line 54 of file panel_setup_netclasses.h.

Referenced by OnUpdateUI(), and PANEL_SETUP_NETCLASSES().

◆ m_ncfilterLabel

wxStaticText* PANEL_SETUP_NETCLASSES_BASE::m_ncfilterLabel
protectedinherited

◆ m_netclassesDirty

bool PANEL_SETUP_NETCLASSES::m_netclassesDirty
private

◆ m_netclassesPane

wxPanel* PANEL_SETUP_NETCLASSES_BASE::m_netclassesPane
protectedinherited

◆ 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: