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  // (The 'M' large char is used to give a margin)
79  int min_best_width = m_netclassGrid->GetTextExtent( "555,555555 milsM" ).x;
80 
81  for( int i = 0; i < m_netclassGrid->GetNumberCols(); ++i )
82  {
83  // We calculate the column min size only from texts sizes, not using the initial col width
84  // as this initial width is sometimes strange depending on the language (wxGrid bug?)
85  int min_width = m_netclassGrid->GetVisibleWidth( i, true, true, false );
86  m_netclassGrid->SetColMinimalWidth( i, min_width );
87  // We use a "best size" >= min_best_width
88  m_originalColWidths[ i ] = std::max( min_width, min_best_width );
89  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
90  }
91 
92  // Be sure the column labels are readable
94 
95  // Membership combobox editors require a bit more room, so increase the row size of
96  // all our grids for consistency
97  m_netclassGrid->SetDefaultRowSize( m_netclassGrid->GetDefaultRowSize() + 4 );
98  m_membershipGrid->SetDefaultRowSize( m_membershipGrid->GetDefaultRowSize() + 4 );
99 
100  m_netclassGrid->PushEventHandler( new GRID_TRICKS( m_netclassGrid ) );
101  m_membershipGrid->PushEventHandler( new GRID_TRICKS( m_membershipGrid ) );
102 
103  m_netclassGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
104  m_membershipGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
105 
106  // Set up the net name column of the netclass membership grid to read-only
107  wxGridCellAttr* attr = new wxGridCellAttr;
108  attr->SetReadOnly( true );
109  m_membershipGrid->SetColAttr( 0, attr );
110 
111  m_addButton->SetBitmap( KiBitmap( small_plus_xpm ) );
112  m_removeButton->SetBitmap( KiBitmap( trash_xpm ) );
113 
114  // wxFormBuilder doesn't include this event...
115  m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging ), NULL, this );
116 
117  m_netclassGrid->EndBatch();
118  m_membershipGrid->EndBatch();
119  Thaw();
120 }
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:540
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:228
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:270
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, 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, max, and OnNetclassGridCellChanging().

◆ ~PANEL_SETUP_NETCLASSES()

PANEL_SETUP_NETCLASSES::~PANEL_SETUP_NETCLASSES ( )
override

Definition at line 123 of file panel_setup_netclasses.cpp.

124 {
125  delete [] m_originalColWidths;
126 
127  // Delete the GRID_TRICKS.
128  m_netclassGrid->PopEventHandler( true );
129  m_membershipGrid->PopEventHandler( true );
130 
131  m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging ), NULL, this );
132 }
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 193 of file panel_setup_netclasses.cpp.

194 {
195  int i = m_membershipGrid->GetNumberRows();
196 
197  m_membershipGrid->AppendRows( 1 );
198 
199  m_membershipGrid->SetCellValue( i, 0, netName );
200  m_membershipGrid->SetCellValue( i, 1, netclass );
201 }
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 406 of file panel_setup_netclasses.cpp.

407 {
408  // Account for scroll bars
409  aWidth -= ( m_membershipGrid->GetSize().x - m_membershipGrid->GetClientSize().x );
410 
411  // Set className column width to original className width from netclasses grid
412  int classNameWidth = m_originalColWidths[ 0 ];
413  m_membershipGrid->SetColSize( 1, m_originalColWidths[ 0 ] );
414  m_membershipGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) );
415 }
#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 383 of file panel_setup_netclasses.cpp.

384 {
385  // Account for scroll bars
386  aWidth -= ( m_netclassGrid->GetSize().x - m_netclassGrid->GetClientSize().x );
387 
388  for( int i = 1; i < m_netclassGrid->GetNumberCols(); i++ )
389  {
390  m_netclassGrid->SetColSize( i, m_originalColWidths[ i ] );
391  aWidth -= m_originalColWidths[ i ];
392  }
393 
394  m_netclassGrid->SetColSize( 0, std::max( aWidth, m_originalColWidths[ 0 ] ) );
395 }
#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 426 of file panel_setup_netclasses.cpp.

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

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

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

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

509 {
510  return ValueFromString( m_Frame->GetUserUnits(), m_netclassGrid->GetCellValue( aRow, aCol ), true );
511 }
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
long long 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:427

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

606 {
607  // Note: do not change the board, as we need to get the current nets from it for
608  // netclass memberships. All the netclass definitions and dimension lists are in
609  // the BOARD_DESIGN_SETTINGS.
610 
611  BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
612 
613  m_BrdSettings = &aBoard->GetDesignSettings();
615 
616  m_netclassGrid->ForceRefresh();
617  m_membershipGrid->ForceRefresh();
618 
619  m_BrdSettings = savedSettings;
620 }
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
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 328 of file panel_setup_netclasses.cpp.

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

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

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

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

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

References AdjustMembershipGridColumns().

◆ OnSizeNetclassGrid()

void PANEL_SETUP_NETCLASSES::OnSizeNetclassGrid ( wxSizeEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 398 of file panel_setup_netclasses.cpp.

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

References AdjustNetclassGridColumns().

◆ OnUpdateUI()

void PANEL_SETUP_NETCLASSES::OnUpdateUI ( wxUpdateUIEvent &  event)
overrideprivatevirtual

Reimplemented from PANEL_SETUP_NETCLASSES_BASE.

Definition at line 480 of file panel_setup_netclasses.cpp.

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

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

◆ rebuildNetclassDropdowns()

void PANEL_SETUP_NETCLASSES::rebuildNetclassDropdowns ( )
private

Definition at line 206 of file panel_setup_netclasses.cpp.

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

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

250 {
251  if( !validateData() )
252  return false;
253 
254  NETCLASSES& netclasses = m_BrdSettings->m_NetClasses;
255 
256  // Remove all netclasses from board. We'll copy new list after
257  netclasses.Clear();
258 
259  // Copy the default NetClass:
261 
262  // Copy other NetClasses :
263  for( int row = 1; row < m_netclassGrid->GetNumberRows(); ++row )
264  {
265  NETCLASSPTR nc = std::make_shared<NETCLASS>( m_netclassGrid->GetCellValue( row, GRID_NAME ) );
266 
267  if( m_BrdSettings->m_NetClasses.Add( nc ) )
269  }
270 
271  // Now read all nets and push them in the corresponding netclass net buffer
272  for( int row = 0; row < m_membershipGrid->GetNumberRows(); ++row )
273  {
274  NETCLASSPTR nc = netclasses.Find( m_membershipGrid->GetCellValue( row, 1 ) );
275 
276  if( nc )
277  nc->Add( m_membershipGrid->GetCellValue( row, 0 ) );
278  }
279 
282 
283  if( auto toolmgr = m_Frame->GetToolManager() )
284  toolmgr->ResetTools( TOOL_BASE::MODEL_RELOAD );
285 
286  return true;
287 }
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
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
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
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
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
NETCLASSPTR GetDefault() const
Function GetDefault.
Definition: netclass.h:268

References NETCLASSES::Add(), NETCLASSES::Clear(), NETCLASS::Default, NETCLASSES::Find(), NETCLASSES::GetDefault(), EDA_BASE_FRAME::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 154 of file panel_setup_netclasses.cpp.

155 {
156  NETCLASSES& netclasses = m_BrdSettings->m_NetClasses;
157  NETCLASSPTR netclass = netclasses.GetDefault();
158 
159  if( m_netclassGrid->GetNumberRows() )
160  m_netclassGrid->DeleteRows( 0, m_netclassGrid->GetNumberRows() );
161  m_netclassGrid->AppendRows( netclasses.GetCount() + 1 ); // + 1 for default netclass
162 
163  // enter the Default NETCLASS.
165 
166  // make the Default NETCLASS name read-only
167  wxGridCellAttr* cellAttr = m_netclassGrid->GetOrCreateCellAttr( 0, GRID_NAME );
168  cellAttr->SetReadOnly();
169  cellAttr->DecRef();
170 
171  // enter other netclasses
172  int row = 1;
173 
174  for( NETCLASSES::iterator i = netclasses.begin(); i != netclasses.end(); ++i, ++row )
176 
177  // ensure that all nets have net classes assigned
179 
180  if( m_membershipGrid->GetNumberRows() )
181  m_membershipGrid->DeleteRows( 0, m_membershipGrid->GetNumberRows() );
182 
183  for( NETINFO_ITEM* net : m_Pcb->GetNetInfo() )
184  {
185  if( net->GetNet() > 0 && net->IsCurrent() )
186  addNet( UnescapeString( net->GetNetname() ), net->GetNetClass()->GetName() );
187  }
188 
189  return true;
190 }
void BuildListOfNets()
Definition: class_board.h:729
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)
BOARD_DESIGN_SETTINGS * m_BrdSettings
NETINFO_LIST & GetNetInfo()
Definition: class_board.h:750
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
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_BASE_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 514 of file panel_setup_netclasses.cpp.

515 {
517  return false;
518 
519  wxString msg;
520  int minViaDia = m_ConstraintsPanel->m_viaMinSize.GetValue();
521  int minViaDrill = m_ConstraintsPanel->m_viaMinDrill.GetValue();
522  int minUViaDia = m_ConstraintsPanel->m_uviaMinSize.GetValue();
523  int minUViaDrill = m_ConstraintsPanel->m_uviaMinDrill.GetValue();
524  int minTrackWidth = m_ConstraintsPanel->m_trackMinWidth.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_TRACKSIZE ) < minTrackWidth )
537  {
538  msg.Printf( _( "Track width less than minimum track width (%s)." ),
539  StringFromValue( m_Frame->GetUserUnits(), minTrackWidth, true, true ) );
540  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_TRACKSIZE );
541  return false;
542  }
543 
544  if( getNetclassValue( row, GRID_DIFF_PAIR_WIDTH ) < minTrackWidth )
545  {
546  msg.Printf( _( "Differential pair width less than minimum track width (%s)." ),
547  StringFromValue( m_Frame->GetUserUnits(), minTrackWidth, true, true ) );
549  return false;
550  }
551 
552  // Test vias
553  if( getNetclassValue( row, GRID_VIASIZE ) < minViaDia )
554  {
555  msg.Printf( _( "Via diameter less than minimum via diameter (%s)." ),
556  StringFromValue( m_Frame->GetUserUnits(), minViaDia, true, true ) );
557  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_VIASIZE );
558  return false;
559  }
560 
562  {
563  msg = _( "Via drill larger than via diameter." );
564  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_VIADRILL );
565  return false;
566  }
567 
568  if( getNetclassValue( row, GRID_VIADRILL ) < minViaDrill )
569  {
570  msg.Printf( _( "Via drill less than minimum via drill (%s)." ),
571  StringFromValue( m_Frame->GetUserUnits(), minViaDrill, true, true ) );
572  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_VIADRILL );
573  return false;
574  }
575 
576  // Test Micro vias
577  if( getNetclassValue( row, GRID_uVIASIZE ) < minUViaDia )
578  {
579  msg.Printf( _( "Microvia diameter less than minimum microvia diameter (%s)." ),
580  StringFromValue( m_Frame->GetUserUnits(), minUViaDia, true, true ) );
581  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_uVIASIZE );
582  return false;
583  }
584 
586  {
587  msg = _( "Microvia drill larger than microvia diameter." );
588  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_uVIADRILL );
589  return false;
590  }
591 
592  if( getNetclassValue( row, GRID_uVIADRILL ) < minUViaDrill )
593  {
594  msg.Printf( _( "Microvia drill less than minimum microvia drill (%s)." ),
595  StringFromValue( m_Frame->GetUserUnits(), minUViaDrill, true, true ) );
596  m_Parent->SetError( msg, this, m_netclassGrid, row, GRID_uVIADRILL );
597  return false;
598  }
599  }
600 
601  return true;
602 }
int getNetclassValue(int aRow, int aCol)
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:172
#define _(s)
void SetError(const wxString &aMessage, wxWindow *aPage, wxObject *aCtrl, int aRow=-1, int aCol=-1)
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
PANEL_SETUP_FEATURE_CONSTRAINTS * m_ConstraintsPanel
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
bool validateNetclassName(int aRow, wxString aName, bool focusFirst=true)
wxString StringFromValue(EDA_UNITS_T aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:217

References _, WX_GRID::CommitPendingChanges(), getNetclassValue(), EDA_BASE_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 290 of file panel_setup_netclasses.cpp.

291 {
292  aName.Trim( true );
293  aName.Trim( false );
294 
295  if( aName.IsEmpty() )
296  {
297  wxString msg = _( "Netclass must have a name." );
298  m_Parent->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME );
299  return false;
300  }
301 
302  for( int ii = 0; ii < m_netclassGrid->GetNumberRows(); ii++ )
303  {
304  if( ii != aRow && m_netclassGrid->GetRowLabelValue( ii ).CmpNoCase( aName ) == 0 )
305  {
306  wxString msg = _( "Netclass name already in use." );
307  m_Parent->SetError( msg, this, m_netclassGrid, focusFirst ? aRow : ii, GRID_NAME );
308  return false;
309  }
310  }
311 
312  return true;
313 }
#define _(s)
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_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: