KiCad PCB EDA Suite
PIN_TABLE_DATA_MODEL Class Reference
Inheritance diagram for PIN_TABLE_DATA_MODEL:

Public Member Functions

 PIN_TABLE_DATA_MODEL (EDA_UNITS aUserUnits)
 
int GetNumberRows () override
 
int GetNumberCols () override
 
wxString GetColLabelValue (int aCol) override
 
bool IsEmptyCell (int row, int col) override
 
wxString GetValue (int aRow, int aCol) override
 
void SetValue (int aRow, int aCol, const wxString &aValue) override
 
void RebuildRows (LIB_PINS &aPins, bool groupByName)
 
void SortRows (int aSortCol, bool ascending)
 
void SortPins (LIB_PINS &aRow)
 
void AppendRow (LIB_PIN *aPin)
 
LIB_PINS RemoveRow (int aRow)
 
bool IsEdited ()
 

Static Public Member Functions

static wxString GetValue (const LIB_PINS &pins, int aCol, EDA_UNITS aUserUnits)
 
static int findRow (const std::vector< LIB_PINS > &aRowSet, const wxString &aName)
 
static bool compare (const LIB_PINS &lhs, const LIB_PINS &rhs, int sortCol, bool ascending, EDA_UNITS units)
 

Private Attributes

std::vector< LIB_PINSm_rows
 
EDA_UNITS m_userUnits
 
bool m_edited
 

Detailed Description

Definition at line 52 of file dialog_lib_edit_pin_table.cpp.

Constructor & Destructor Documentation

◆ PIN_TABLE_DATA_MODEL()

PIN_TABLE_DATA_MODEL::PIN_TABLE_DATA_MODEL ( EDA_UNITS  aUserUnits)
inline

Definition at line 65 of file dialog_lib_edit_pin_table.cpp.

65  : m_userUnits( aUserUnits ), m_edited( false )
66  {
67  }

Member Function Documentation

◆ AppendRow()

void PIN_TABLE_DATA_MODEL::AppendRow ( LIB_PIN aPin)
inline

Definition at line 356 of file dialog_lib_edit_pin_table.cpp.

357  {
358  LIB_PINS row;
359  row.push_back( aPin );
360  m_rows.push_back( row );
361 
362  if ( GetView() )
363  {
364  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
365  GetView()->ProcessTableMessage( msg );
366  }
367  }
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:55
std::vector< LIB_PINS > m_rows

References m_rows.

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::OnAddRow().

◆ compare()

static bool PIN_TABLE_DATA_MODEL::compare ( const LIB_PINS lhs,
const LIB_PINS rhs,
int  sortCol,
bool  ascending,
EDA_UNITS  units 
)
inlinestatic

Definition at line 236 of file dialog_lib_edit_pin_table.cpp.

238  {
239  wxString lhStr = GetValue( lhs, sortCol, units );
240  wxString rhStr = GetValue( rhs, sortCol, units );
241 
242  if( lhStr == rhStr )
243  {
244  // Secondary sort key is always COL_NUMBER
245  sortCol = COL_NUMBER;
246  lhStr = GetValue( lhs, sortCol, units );
247  rhStr = GetValue( rhs, sortCol, units );
248  }
249 
250  bool res;
251 
252  // N.B. To meet the iterator sort conditions, we cannot simply invert the truth
253  // to get the opposite sort. i.e. ~(a<b) != (a>b)
254  auto cmp = [ ascending ]( const auto a, const auto b )
255  {
256  if( ascending )
257  return a < b;
258  else
259  return b < a;
260  };
261 
262  switch( sortCol )
263  {
264  case COL_NUMBER:
265  case COL_NAME:
266  res = cmp( PinNumbers::Compare( lhStr, rhStr ), 0 );
267  break;
268  case COL_NUMBER_SIZE:
269  case COL_NAME_SIZE:
270  res = cmp( ValueFromString( units, lhStr, true ),
271  ValueFromString( units, rhStr, true ) );
272  break;
273  case COL_LENGTH:
274  case COL_POSX:
275  case COL_POSY:
276  res = cmp( ValueFromString( units, lhStr ), ValueFromString( units, rhStr ) );
277  break;
278  default:
279  res = cmp( StrNumCmp( lhStr, rhStr ), 0 );
280  break;
281  }
282 
283  return res;
284  }
static int Compare(PinNumber const &lhs, PinNumber const &rhs)
Definition: pin_number.cpp:111
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
Definition: string.cpp:388
wxString GetValue(int aRow, int aCol) override
YYCODETYPE lhs
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

References COL_LENGTH, COL_NAME, COL_NAME_SIZE, COL_NUMBER, COL_NUMBER_SIZE, COL_POSX, COL_POSY, PinNumbers::Compare(), GetValue(), numEval::lhs, StrNumCmp(), and ValueFromString().

Referenced by SortRows().

◆ findRow()

static int PIN_TABLE_DATA_MODEL::findRow ( const std::vector< LIB_PINS > &  aRowSet,
const wxString &  aName 
)
inlinestatic

Definition at line 225 of file dialog_lib_edit_pin_table.cpp.

226  {
227  for( size_t i = 0; i < aRowSet.size(); ++i )
228  {
229  if( aRowSet[ i ][ 0 ] && aRowSet[ i ][ 0 ]->GetName() == aName )
230  return i;
231  }
232 
233  return -1;
234  }

Referenced by RebuildRows().

◆ GetColLabelValue()

wxString PIN_TABLE_DATA_MODEL::GetColLabelValue ( int  aCol)
inlineoverride

Definition at line 72 of file dialog_lib_edit_pin_table.cpp.

73  {
74  switch( aCol )
75  {
76  case COL_NUMBER: return _( "Number" );
77  case COL_NAME: return _( "Name" );
78  case COL_TYPE: return _( "Electrical Type" );
79  case COL_SHAPE: return _( "Graphic Style" );
80  case COL_ORIENTATION: return _( "Orientation" );
81  case COL_NUMBER_SIZE: return _( "Number Text Size" );
82  case COL_NAME_SIZE: return _( "Name Text Size" );
83  case COL_LENGTH: return _( "Length" );
84  case COL_POSX: return _( "X Position" );
85  case COL_POSY: return _( "Y Position" );
86  default: wxFAIL; return wxEmptyString;
87  }
88  }
#define _(s)
Definition: 3d_actions.cpp:33

References _, COL_LENGTH, COL_NAME, COL_NAME_SIZE, COL_NUMBER, COL_NUMBER_SIZE, COL_ORIENTATION, COL_POSX, COL_POSY, COL_SHAPE, and COL_TYPE.

◆ GetNumberCols()

int PIN_TABLE_DATA_MODEL::GetNumberCols ( )
inlineoverride

Definition at line 70 of file dialog_lib_edit_pin_table.cpp.

References COL_COUNT.

◆ GetNumberRows()

int PIN_TABLE_DATA_MODEL::GetNumberRows ( )
inlineoverride

Definition at line 69 of file dialog_lib_edit_pin_table.cpp.

69 { return (int) m_rows.size(); }
std::vector< LIB_PINS > m_rows

References m_rows.

◆ GetValue() [1/2]

wxString PIN_TABLE_DATA_MODEL::GetValue ( int  aRow,
int  aCol 
)
inlineoverride

Definition at line 95 of file dialog_lib_edit_pin_table.cpp.

96  {
97  return GetValue( m_rows[ aRow ], aCol, m_userUnits );
98  }
wxString GetValue(int aRow, int aCol) override
std::vector< LIB_PINS > m_rows

References m_rows, and m_userUnits.

Referenced by compare().

◆ GetValue() [2/2]

static wxString PIN_TABLE_DATA_MODEL::GetValue ( const LIB_PINS pins,
int  aCol,
EDA_UNITS  aUserUnits 
)
inlinestatic

Definition at line 100 of file dialog_lib_edit_pin_table.cpp.

101  {
102  wxString fieldValue;
103 
104  if( pins.empty())
105  return fieldValue;
106 
107  for( LIB_PIN* pin : pins )
108  {
109  wxString val;
110 
111  switch( aCol )
112  {
113  case COL_NUMBER:
114  val = pin->GetNumber();
115  break;
116  case COL_NAME:
117  val = pin->GetName();
118  break;
119  case COL_TYPE:
120  val = g_typeNames[static_cast<int>( pin->GetType() )];
121  break;
122  case COL_SHAPE:
123  val = g_shapeNames[static_cast<int>( pin->GetShape() )];
124  break;
125  case COL_ORIENTATION:
126  if( LIB_PIN::GetOrientationIndex( pin->GetOrientation() ) >= 0 )
127  val = g_orientationNames[ LIB_PIN::GetOrientationIndex( pin->GetOrientation() ) ];
128  break;
129  case COL_NUMBER_SIZE:
130  val = StringFromValue( aUserUnits, pin->GetNumberTextSize(), true, true );
131  break;
132  case COL_NAME_SIZE:
133  val = StringFromValue( aUserUnits, pin->GetNameTextSize(), true, true );
134  break;
135  case COL_LENGTH:
136  val = StringFromValue( aUserUnits, pin->GetLength(), true );
137  break;
138  case COL_POSX:
139  val = StringFromValue( aUserUnits, pin->GetPosition().x, true );
140  break;
141  case COL_POSY:
142  val = StringFromValue( aUserUnits, pin->GetPosition().y, true );
143  break;
144  default:
145  wxFAIL;
146  break;
147  }
148 
149  if( aCol == COL_NUMBER )
150  {
151  if( fieldValue.length() )
152  fieldValue += wxT( ", " );
153  fieldValue += val;
154  }
155  else
156  {
157  if( !fieldValue.Length() )
158  fieldValue = val;
159  else if( val != fieldValue )
160  fieldValue = INDETERMINATE_STATE;
161  }
162  }
163 
164  return fieldValue;
165  }
static wxArrayString g_typeNames
static wxArrayString g_shapeNames
#define INDETERMINATE_STATE
static int GetOrientationIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:1632
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
static wxArrayString g_orientationNames

References COL_LENGTH, COL_NAME, COL_NAME_SIZE, COL_NUMBER, COL_NUMBER_SIZE, COL_ORIENTATION, COL_POSX, COL_POSY, COL_SHAPE, COL_TYPE, g_orientationNames, g_shapeNames, g_typeNames, LIB_PIN::GetOrientationIndex(), INDETERMINATE_STATE, and StringFromValue().

◆ IsEdited()

bool PIN_TABLE_DATA_MODEL::IsEdited ( )
inline

Definition at line 384 of file dialog_lib_edit_pin_table.cpp.

385  {
386  return m_edited;
387  }

References m_edited.

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::OnClose().

◆ IsEmptyCell()

bool PIN_TABLE_DATA_MODEL::IsEmptyCell ( int  row,
int  col 
)
inlineoverride

Definition at line 90 of file dialog_lib_edit_pin_table.cpp.

91  {
92  return false; // don't allow adjacent cell overflow, even if we are actually empty
93  }

◆ RebuildRows()

void PIN_TABLE_DATA_MODEL::RebuildRows ( LIB_PINS aPins,
bool  groupByName 
)
inline

Definition at line 286 of file dialog_lib_edit_pin_table.cpp.

287  {
288  if ( GetView() )
289  {
290  // Commit any pending in-place edits before the row gets moved out from under
291  // the editor.
292  if( auto grid = dynamic_cast<WX_GRID*>( GetView() ) )
293  grid->CommitPendingChanges( true );
294 
295  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_rows.size() );
296  GetView()->ProcessTableMessage( msg );
297  }
298 
299  m_rows.clear();
300 
301  for( LIB_PIN* pin : aPins )
302  {
303  int rowIndex = -1;
304 
305  if( groupByName )
306  rowIndex = findRow( m_rows, pin->GetName() );
307 
308  if( rowIndex < 0 )
309  {
310  m_rows.emplace_back( LIB_PINS() );
311  rowIndex = m_rows.size() - 1;
312  }
313 
314  m_rows[ rowIndex ].push_back( pin );
315  }
316 
317  int sortCol = 0;
318  bool ascending = true;
319 
320  if( GetView() && GetView()->GetSortingColumn() != wxNOT_FOUND )
321  {
322  sortCol = GetView()->GetSortingColumn();
323  ascending = GetView()->IsSortOrderAscending();
324  }
325 
326  for( LIB_PINS& row : m_rows )
327  SortPins( row );
328 
329  SortRows( sortCol, ascending );
330 
331  if ( GetView() )
332  {
333  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rows.size() );
334  GetView()->ProcessTableMessage( msg );
335  }
336  }
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:55
void SortRows(int aSortCol, bool ascending)
static int findRow(const std::vector< LIB_PINS > &aRowSet, const wxString &aName)
std::vector< LIB_PINS > m_rows

References findRow(), m_rows, SortPins(), and SortRows().

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::OnRebuildRows(), and DIALOG_LIB_EDIT_PIN_TABLE::TransferDataToWindow().

◆ RemoveRow()

LIB_PINS PIN_TABLE_DATA_MODEL::RemoveRow ( int  aRow)
inline

Definition at line 369 of file dialog_lib_edit_pin_table.cpp.

370  {
371  LIB_PINS removedRow = m_rows[ aRow ];
372 
373  m_rows.erase( m_rows.begin() + aRow );
374 
375  if ( GetView() )
376  {
377  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow, 1 );
378  GetView()->ProcessTableMessage( msg );
379  }
380 
381  return removedRow;
382  }
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:55
std::vector< LIB_PINS > m_rows

References m_rows.

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::OnDeleteRow().

◆ SetValue()

void PIN_TABLE_DATA_MODEL::SetValue ( int  aRow,
int  aCol,
const wxString &  aValue 
)
inlineoverride

Definition at line 167 of file dialog_lib_edit_pin_table.cpp.

168  {
169  if( aValue == INDETERMINATE_STATE )
170  return;
171 
172  LIB_PINS pins = m_rows[ aRow ];
173 
174  for( LIB_PIN* pin : pins )
175  {
176  switch( aCol )
177  {
178  case COL_NUMBER:
179  pin->SetNumber( aValue );
180  break;
181  case COL_NAME:
182  pin->SetName( aValue );
183  break;
184  case COL_TYPE:
185  if( g_typeNames.Index( aValue ) != wxNOT_FOUND )
186  pin->SetType( (ELECTRICAL_PINTYPE) g_typeNames.Index( aValue ), false );
187 
188  break;
189  case COL_SHAPE:
190  if( g_shapeNames.Index( aValue ) != wxNOT_FOUND )
191  pin->SetShape( (GRAPHIC_PINSHAPE) g_shapeNames.Index( aValue ) );
192 
193  break;
194  case COL_ORIENTATION:
195  if( g_orientationNames.Index( aValue ) != wxNOT_FOUND )
196  pin->SetOrientation( LIB_PIN::GetOrientationCode(
197  g_orientationNames.Index( aValue ) ), false );
198  break;
199  case COL_NUMBER_SIZE:
200  pin->SetNumberTextSize( ValueFromString( m_userUnits, aValue, true ) );
201  break;
202  case COL_NAME_SIZE:
203  pin->SetNameTextSize( ValueFromString( m_userUnits, aValue, true ) );
204  break;
205  case COL_LENGTH:
206  pin->SetLength( ValueFromString( m_userUnits, aValue ) );
207  break;
208  case COL_POSX:
209  pin->SetPinPosition( wxPoint( ValueFromString( m_userUnits, aValue ),
210  pin->GetPosition().y ) );
211  break;
212  case COL_POSY:
213  pin->SetPinPosition( wxPoint( pin->GetPosition().x,
214  ValueFromString( m_userUnits, aValue ) ) );
215  break;
216  default:
217  wxFAIL;
218  break;
219  }
220  }
221 
222  m_edited = true;
223  }
static wxArrayString g_typeNames
static wxArrayString g_shapeNames
#define INDETERMINATE_STATE
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:55
GRAPHIC_PINSHAPE
Definition: pin_shape.h:35
static wxArrayString g_orientationNames
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
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
std::vector< LIB_PINS > m_rows
static int GetOrientationCode(int aIndex)
Get the orientation code by index used to set the pin orientation.
Definition: lib_pin.cpp:1623

References COL_LENGTH, COL_NAME, COL_NAME_SIZE, COL_NUMBER, COL_NUMBER_SIZE, COL_ORIENTATION, COL_POSX, COL_POSY, COL_SHAPE, COL_TYPE, g_orientationNames, g_shapeNames, g_typeNames, LIB_PIN::GetOrientationCode(), INDETERMINATE_STATE, m_edited, m_rows, m_userUnits, and ValueFromString().

◆ SortPins()

void PIN_TABLE_DATA_MODEL::SortPins ( LIB_PINS aRow)
inline

Definition at line 347 of file dialog_lib_edit_pin_table.cpp.

348  {
349  std::sort( aRow.begin(), aRow.end(),
350  []( LIB_PIN* lhs, LIB_PIN* rhs ) -> bool
351  {
352  return PinNumbers::Compare( lhs->GetNumber(), rhs->GetNumber() ) < 0;
353  } );
354  }
static int Compare(PinNumber const &lhs, PinNumber const &rhs)
Definition: pin_number.cpp:111
YYCODETYPE lhs

References PinNumbers::Compare(), and numEval::lhs.

Referenced by RebuildRows().

◆ SortRows()

void PIN_TABLE_DATA_MODEL::SortRows ( int  aSortCol,
bool  ascending 
)
inline

Definition at line 338 of file dialog_lib_edit_pin_table.cpp.

339  {
340  std::sort( m_rows.begin(), m_rows.end(),
341  [ aSortCol, ascending, this ]( const LIB_PINS& lhs, const LIB_PINS& rhs ) -> bool
342  {
343  return compare( lhs, rhs, aSortCol, ascending, m_userUnits );
344  } );
345  }
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:55
static bool compare(const LIB_PINS &lhs, const LIB_PINS &rhs, int sortCol, bool ascending, EDA_UNITS units)
YYCODETYPE lhs
std::vector< LIB_PINS > m_rows

References compare(), numEval::lhs, m_rows, and m_userUnits.

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::OnColSort(), and RebuildRows().

Member Data Documentation

◆ m_edited

bool PIN_TABLE_DATA_MODEL::m_edited
private

Definition at line 62 of file dialog_lib_edit_pin_table.cpp.

Referenced by IsEdited(), and SetValue().

◆ m_rows

std::vector<LIB_PINS> PIN_TABLE_DATA_MODEL::m_rows
private

◆ m_userUnits

EDA_UNITS PIN_TABLE_DATA_MODEL::m_userUnits
private

Definition at line 61 of file dialog_lib_edit_pin_table.cpp.

Referenced by GetValue(), SetValue(), and SortRows().


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