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 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_T  aUserUnits)
inline

Definition at line 65 of file dialog_lib_edit_pin_table.cpp.

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

Member Function Documentation

◆ AppendRow()

void PIN_TABLE_DATA_MODEL::AppendRow ( LIB_PIN aPin)
inline

Definition at line 329 of file dialog_lib_edit_pin_table.cpp.

330  {
331  LIB_PINS row;
332  row.push_back( aPin );
333  m_rows.push_back( row );
334 
335  if ( GetView() )
336  {
337  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
338  GetView()->ProcessTableMessage( msg );
339  }
340  }
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_T  units 
)
inlinestatic

Definition at line 235 of file dialog_lib_edit_pin_table.cpp.

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

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

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_T  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[ pin->GetType() ];
121  break;
122  case COL_SHAPE:
123  val = g_shapeNames[ pin->GetShape() ];
124  break;
125  case COL_ORIENTATION:
126  val = g_orientationNames[ LIB_PIN::GetOrientationIndex( pin->GetOrientation() ) ];
127  break;
128  case COL_NUMBER_SIZE:
129  val = StringFromValue( aUserUnits, pin->GetNumberTextSize(), true, true );
130  break;
131  case COL_NAME_SIZE:
132  val = StringFromValue( aUserUnits, pin->GetNameTextSize(), true, true );
133  break;
134  case COL_LENGTH:
135  val = StringFromValue( aUserUnits, pin->GetLength(), true );
136  break;
137  case COL_POSX:
138  val = StringFromValue( aUserUnits, pin->GetPosition().x, true );
139  break;
140  case COL_POSY:
141  val = StringFromValue( aUserUnits, pin->GetPosition().y, true );
142  break;
143  default:
144  wxFAIL;
145  break;
146  }
147 
148  if( aCol == COL_NUMBER )
149  {
150  if( fieldValue.length() )
151  fieldValue += wxT( ", " );
152  fieldValue += val;
153  }
154  else
155  {
156  if( !fieldValue.Length() )
157  fieldValue = val;
158  else if( val != fieldValue )
159  fieldValue = INDETERMINATE;
160  }
161  }
162 
163  return fieldValue;
164  }
static wxArrayString g_typeNames
static wxArrayString g_shapeNames
static int GetOrientationIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:1595
#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 357 of file dialog_lib_edit_pin_table.cpp.

358  {
359  return m_edited;
360  }

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

275  {
276  if ( GetView() )
277  {
278  // Commit any pending in-place edits before the row gets moved out from under
279  // the editor.
280  dynamic_cast<WX_GRID*>( GetView() )->CommitPendingChanges( true );
281 
282  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_rows.size() );
283  GetView()->ProcessTableMessage( msg );
284  }
285 
286  m_rows.clear();
287 
288  for( LIB_PIN* pin : aPins )
289  {
290  int rowIndex = -1;
291 
292  if( groupByName )
293  rowIndex = findRow( m_rows, pin->GetName() );
294 
295  if( rowIndex < 0 )
296  {
297  m_rows.emplace_back( LIB_PINS() );
298  rowIndex = m_rows.size() - 1;
299  }
300 
301  m_rows[ rowIndex ].push_back( pin );
302  }
303 
304  int sortCol = 0;
305  bool ascending = true;
306 
307  if( GetView() && GetView()->GetSortingColumn() != wxNOT_FOUND )
308  {
309  sortCol = GetView()->GetSortingColumn();
310  ascending = GetView()->IsSortOrderAscending();
311  }
312 
313  SortRows( sortCol, ascending );
314 
315  if ( GetView() )
316  {
317  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rows.size() );
318  GetView()->ProcessTableMessage( msg );
319  }
320  }
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, 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 342 of file dialog_lib_edit_pin_table.cpp.

343  {
344  LIB_PINS removedRow = m_rows[ aRow ];
345 
346  m_rows.erase( m_rows.begin() + aRow );
347 
348  if ( GetView() )
349  {
350  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow, 1 );
351  GetView()->ProcessTableMessage( msg );
352  }
353 
354  return removedRow;
355  }
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 166 of file dialog_lib_edit_pin_table.cpp.

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

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

323  {
324  std::sort( m_rows.begin(), m_rows.end(),
325  [ aSortCol, ascending, this ]( LIB_PINS lhs, LIB_PINS rhs ) -> bool
326  { return compare( lhs, rhs, aSortCol, ascending, m_userUnits ); } );
327  }
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_T 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_T 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: