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_T 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 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_T 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_T units)
 

Private Attributes

std::vector< LIB_PINSm_rows
 
EDA_UNITS_T m_userUnits
 
bool m_edited
 

Detailed Description

Definition at line 51 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_T  aUserUnits)
inline

Definition at line 64 of file dialog_lib_edit_pin_table.cpp.

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

Member Function Documentation

◆ AppendRow()

void PIN_TABLE_DATA_MODEL::AppendRow ( LIB_PIN aPin)
inline

Definition at line 328 of file dialog_lib_edit_pin_table.cpp.

329  {
330  LIB_PINS row;
331  row.push_back( aPin );
332  m_rows.push_back( row );
333 
334  if ( GetView() )
335  {
336  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
337  GetView()->ProcessTableMessage( msg );
338  }
339  }
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:61
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_T  units 
)
inlinestatic

Definition at line 234 of file dialog_lib_edit_pin_table.cpp.

236  {
237  wxString lhStr = GetValue( lhs, sortCol, units );
238  wxString rhStr = GetValue( rhs, sortCol, units );
239 
240  if( lhStr == rhStr )
241  {
242  // Secondary sort key is always COL_NUMBER
243  sortCol = COL_NUMBER;
244  lhStr = GetValue( lhs, sortCol, units );
245  rhStr = GetValue( rhs, sortCol, units );
246  }
247 
248  bool cmp;
249 
250  switch( sortCol )
251  {
252  case COL_NUMBER:
253  case COL_NAME:
254  cmp = PinNumbers::Compare( lhStr, rhStr ) < 0;
255  break;
256  case COL_NUMBER_SIZE:
257  case COL_NAME_SIZE:
258  cmp = ValueFromString( units, lhStr, true ) < ValueFromString( units, rhStr, true );
259  break;
260  case COL_LENGTH:
261  case COL_POSX:
262  case COL_POSY:
263  cmp = ValueFromString( units, lhStr ) < ValueFromString( units, rhStr );
264  break;
265  default:
266  cmp = StrNumCmp( lhStr, rhStr ) < 0;
267  break;
268  }
269 
270  return ascending == cmp;
271  }
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:313
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
wxString GetValue(int aRow, int aCol) override
YYCODETYPE lhs

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 223 of file dialog_lib_edit_pin_table.cpp.

224  {
225  for( size_t i = 0; i < aRowSet.size(); ++i )
226  {
227  if( aRowSet[ i ][ 0 ] && aRowSet[ i ][ 0 ]->GetName() == aName )
228  return i;
229  }
230 
231  return -1;
232  }
size_t i
Definition: json11.cpp:597

References i.

Referenced by RebuildRows().

◆ GetColLabelValue()

wxString PIN_TABLE_DATA_MODEL::GetColLabelValue ( int  aCol)
inlineoverride

Definition at line 71 of file dialog_lib_edit_pin_table.cpp.

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

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 69 of file dialog_lib_edit_pin_table.cpp.

References COL_COUNT.

◆ GetNumberRows()

int PIN_TABLE_DATA_MODEL::GetNumberRows ( )
inlineoverride

Definition at line 68 of file dialog_lib_edit_pin_table.cpp.

68 { 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 94 of file dialog_lib_edit_pin_table.cpp.

95  {
96  return GetValue( m_rows[ aRow ], aCol, m_userUnits );
97  }
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_T  aUserUnits 
)
inlinestatic

Definition at line 99 of file dialog_lib_edit_pin_table.cpp.

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

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

◆ IsEdited()

bool PIN_TABLE_DATA_MODEL::IsEdited ( )
inline

Definition at line 356 of file dialog_lib_edit_pin_table.cpp.

357  {
358  return m_edited;
359  }

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 89 of file dialog_lib_edit_pin_table.cpp.

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

◆ RebuildRows()

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

Definition at line 273 of file dialog_lib_edit_pin_table.cpp.

274  {
275  if ( GetView() )
276  {
277  // Commit any pending in-place edits before the row gets moved out from under
278  // the editor.
279  dynamic_cast<WX_GRID*>( GetView() )->CommitPendingChanges( true );
280 
281  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_rows.size() );
282  GetView()->ProcessTableMessage( msg );
283  }
284 
285  m_rows.clear();
286 
287  for( LIB_PIN* pin : aPins )
288  {
289  int rowIndex = -1;
290 
291  if( groupByName )
292  rowIndex = findRow( m_rows, pin->GetName() );
293 
294  if( rowIndex < 0 )
295  {
296  m_rows.emplace_back( LIB_PINS() );
297  rowIndex = m_rows.size() - 1;
298  }
299 
300  m_rows[ rowIndex ].push_back( pin );
301  }
302 
303  int sortCol = 0;
304  bool ascending = true;
305 
306  if( GetView() && GetView()->GetSortingColumn() != wxNOT_FOUND )
307  {
308  sortCol = GetView()->GetSortingColumn();
309  ascending = GetView()->IsSortOrderAscending();
310  }
311 
312  SortRows( sortCol, ascending );
313 
314  if ( GetView() )
315  {
316  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rows.size() );
317  GetView()->ProcessTableMessage( msg );
318  }
319  }
void SortRows(int aSortCol, bool ascending)
static int findRow(const std::vector< LIB_PINS > &aRowSet, const wxString &aName)
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:61
std::vector< LIB_PINS > m_rows

References findRow(), m_rows, 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 341 of file dialog_lib_edit_pin_table.cpp.

342  {
343  LIB_PINS removedRow = m_rows[ aRow ];
344 
345  m_rows.erase( m_rows.begin() + aRow );
346 
347  if ( GetView() )
348  {
349  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow, 1 );
350  GetView()->ProcessTableMessage( msg );
351  }
352 
353  return removedRow;
354  }
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:61
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 165 of file dialog_lib_edit_pin_table.cpp.

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

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, m_edited, m_rows, m_userUnits, and ValueFromString().

◆ SortRows()

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

Definition at line 321 of file dialog_lib_edit_pin_table.cpp.

322  {
323  std::sort( m_rows.begin(), m_rows.end(),
324  [ aSortCol, ascending, this ]( LIB_PINS lhs, LIB_PINS rhs ) -> bool
325  { return compare( lhs, rhs, aSortCol, ascending, m_userUnits ); } );
326  }
static bool compare(const LIB_PINS &lhs, const LIB_PINS &rhs, int sortCol, bool ascending, EDA_UNITS_T units)
YYCODETYPE lhs
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:61
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 61 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_T PIN_TABLE_DATA_MODEL::m_userUnits
private

Definition at line 60 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: