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 ( 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

void PIN_TABLE_DATA_MODEL::AppendRow ( LIB_PIN aPin)
inline

Definition at line 323 of file dialog_lib_edit_pin_table.cpp.

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::OnAddRow().

324  {
325  LIB_PINS row;
326  row.push_back( aPin );
327  m_rows.push_back( row );
328 
329  if ( GetView() )
330  {
331  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
332  GetView()->ProcessTableMessage( msg );
333  }
334  }
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
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 229 of file dialog_lib_edit_pin_table.cpp.

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

Referenced by SortRows().

231  {
232  wxString lhStr = GetValue( lhs, sortCol, units );
233  wxString rhStr = GetValue( rhs, sortCol, units );
234 
235  if( lhStr == rhStr )
236  {
237  // Secondary sort key is always COL_NUMBER
238  sortCol = COL_NUMBER;
239  lhStr = GetValue( lhs, sortCol, units );
240  rhStr = GetValue( rhs, sortCol, units );
241  }
242 
243  bool cmp;
244 
245  switch( sortCol )
246  {
247  case COL_NUMBER:
248  case COL_NAME:
249  cmp = PinNumbers::Compare( lhStr, rhStr ) < 0;
250  break;
251  case COL_NUMBER_SIZE:
252  case COL_NAME_SIZE:
253  cmp = ValueFromString( units, lhStr, true ) < ValueFromString( units, rhStr, true );
254  break;
255  case COL_LENGTH:
256  case COL_POSX:
257  case COL_POSY:
258  cmp = ValueFromString( units, lhStr ) < ValueFromString( units, rhStr );
259  break;
260  default:
261  cmp = StrNumCmp( lhStr, rhStr ) < 0;
262  break;
263  }
264 
265  return ascending == cmp;
266  }
static int Compare(PinNumber const &lhs, PinNumber const &rhs)
Definition: pin_number.cpp:110
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
int StrNumCmp(const wxString &aString1, const wxString &aString2, int aLength, bool aIgnoreCase)
Function StrNumCmp is a routine compatible with qsort() to sort by alphabetical order.
Definition: string.cpp:315
static int PIN_TABLE_DATA_MODEL::findRow ( const std::vector< LIB_PINS > &  aRowSet,
const wxString &  aName 
)
inlinestatic

Definition at line 218 of file dialog_lib_edit_pin_table.cpp.

References i.

Referenced by RebuildRows().

219  {
220  for( size_t i = 0; i < aRowSet.size(); ++i )
221  {
222  if( aRowSet[ i ][ 0 ] && aRowSet[ i ][ 0 ]->GetName() == aName )
223  return i;
224  }
225 
226  return -1;
227  }
size_t i
Definition: json11.cpp:597
wxString PIN_TABLE_DATA_MODEL::GetColLabelValue ( int  aCol)
inlineoverride

Definition at line 71 of file dialog_lib_edit_pin_table.cpp.

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

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  }
int PIN_TABLE_DATA_MODEL::GetNumberCols ( )
inlineoverride

Definition at line 69 of file dialog_lib_edit_pin_table.cpp.

References COL_COUNT.

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
wxString PIN_TABLE_DATA_MODEL::GetValue ( int  aRow,
int  aCol 
)
inlineoverride

Definition at line 94 of file dialog_lib_edit_pin_table.cpp.

Referenced by compare().

95  {
96  return GetValue( m_rows[ aRow ], aCol, m_userUnits );
97  }
wxString GetValue(int aRow, int aCol) override
std::vector< LIB_PINS > m_rows
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.

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().

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:1910
#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
bool PIN_TABLE_DATA_MODEL::IsEdited ( )
inline

Definition at line 351 of file dialog_lib_edit_pin_table.cpp.

References m_edited.

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::OnClose().

352  {
353  return m_edited;
354  }
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  }
void PIN_TABLE_DATA_MODEL::RebuildRows ( LIB_PINS aPins,
bool  groupByName 
)
inline

Definition at line 268 of file dialog_lib_edit_pin_table.cpp.

References findRow(), and SortRows().

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

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

Definition at line 336 of file dialog_lib_edit_pin_table.cpp.

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::OnDeleteRow().

337  {
338  LIB_PINS removedRow = m_rows[ aRow ];
339 
340  m_rows.erase( m_rows.begin() + aRow );
341 
342  if ( GetView() )
343  {
344  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow, 1 );
345  GetView()->ProcessTableMessage( msg );
346  }
347 
348  return removedRow;
349  }
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
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.

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

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  pin->SetType( (ELECTRICAL_PINTYPE) g_typeNames.Index( aValue ), false );
184  break;
185  case COL_SHAPE:
186  pin->SetShape( (GRAPHIC_PINSHAPE) g_shapeNames.Index( aValue ) );
187  break;
188  case COL_ORIENTATION:
189  pin->SetOrientation( LIB_PIN::GetOrientationCode(
190  g_orientationNames.Index( aValue ) ), false );
191  break;
192  case COL_NUMBER_SIZE:
193  pin->SetNumberTextSize( ValueFromString( m_userUnits, aValue, true ) );
194  break;
195  case COL_NAME_SIZE:
196  pin->SetNameTextSize( ValueFromString( m_userUnits, aValue, true ) );
197  break;
198  case COL_LENGTH:
199  pin->SetLength( ValueFromString( m_userUnits, aValue ) );
200  break;
201  case COL_POSX:
202  pin->SetPinPosition( wxPoint( ValueFromString( m_userUnits, aValue ),
203  pin->GetPosition().y ) );
204  break;
205  case COL_POSY:
206  pin->SetPinPosition( wxPoint( pin->GetPosition().x,
207  ValueFromString( m_userUnits, aValue ) ) );
208  break;
209  default:
210  wxFAIL;
211  break;
212  }
213  }
214 
215  m_edited = true;
216  }
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:1901
void PIN_TABLE_DATA_MODEL::SortRows ( int  aSortCol,
bool  ascending 
)
inline

Definition at line 316 of file dialog_lib_edit_pin_table.cpp.

References compare(), and numEval::lhs.

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

317  {
318  std::sort( m_rows.begin(), m_rows.end(),
319  [ aSortCol, ascending, this ]( LIB_PINS lhs, LIB_PINS rhs ) -> bool
320  { return compare( lhs, rhs, aSortCol, ascending, m_userUnits ); } );
321  }
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

Member Data Documentation

bool PIN_TABLE_DATA_MODEL::m_edited
private

Definition at line 61 of file dialog_lib_edit_pin_table.cpp.

Referenced by IsEdited().

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

Definition at line 58 of file dialog_lib_edit_pin_table.cpp.

EDA_UNITS_T PIN_TABLE_DATA_MODEL::m_userUnits
private

Definition at line 60 of file dialog_lib_edit_pin_table.cpp.


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