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)
 

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
 

Detailed Description

Definition at line 50 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 62 of file dialog_lib_edit_pin_table.cpp.

62  :
63  m_userUnits( aUserUnits )
64  {}

Member Function Documentation

void PIN_TABLE_DATA_MODEL::AppendRow ( LIB_PIN aPin)
inline

Definition at line 319 of file dialog_lib_edit_pin_table.cpp.

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::OnAddRow().

320  {
321  LIB_PINS row;
322  row.push_back( aPin );
323  m_rows.push_back( row );
324 
325  if ( GetView() )
326  {
327  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
328  GetView()->ProcessTableMessage( msg );
329  }
330  }
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 225 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().

227  {
228  wxString lhStr = GetValue( lhs, sortCol, units );
229  wxString rhStr = GetValue( rhs, sortCol, units );
230 
231  if( lhStr == rhStr )
232  {
233  // Secondary sort key is always COL_NUMBER
234  sortCol = COL_NUMBER;
235  lhStr = GetValue( lhs, sortCol, units );
236  rhStr = GetValue( rhs, sortCol, units );
237  }
238 
239  bool cmp;
240 
241  switch( sortCol )
242  {
243  case COL_NUMBER:
244  case COL_NAME:
245  cmp = PinNumbers::Compare( lhStr, rhStr ) < 0;
246  break;
247  case COL_NUMBER_SIZE:
248  case COL_NAME_SIZE:
249  cmp = ValueFromString( units, lhStr, true ) < ValueFromString( units, rhStr, true );
250  break;
251  case COL_LENGTH:
252  case COL_POSX:
253  case COL_POSY:
254  cmp = ValueFromString( units, lhStr ) < ValueFromString( units, rhStr );
255  break;
256  default:
257  cmp = StrNumCmp( lhStr, rhStr ) < 0;
258  break;
259  }
260 
261  return ascending == cmp;
262  }
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 214 of file dialog_lib_edit_pin_table.cpp.

References i.

Referenced by RebuildRows().

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

Definition at line 69 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.

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

Definition at line 67 of file dialog_lib_edit_pin_table.cpp.

References COL_COUNT.

int PIN_TABLE_DATA_MODEL::GetNumberRows ( )
inlineoverride

Definition at line 66 of file dialog_lib_edit_pin_table.cpp.

66 { 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 92 of file dialog_lib_edit_pin_table.cpp.

Referenced by compare().

93  {
94  return GetValue( m_rows[ aRow ], aCol, m_userUnits );
95  }
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 97 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().

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

Definition at line 87 of file dialog_lib_edit_pin_table.cpp.

88  {
89  return false; // don't allow adjacent cell overflow, even if we are actually empty
90  }
void PIN_TABLE_DATA_MODEL::RebuildRows ( LIB_PINS aPins,
bool  groupByName 
)
inline

Definition at line 264 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().

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

Referenced by DIALOG_LIB_EDIT_PIN_TABLE::OnDeleteRow().

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

164  {
165  if( aValue == INDETERMINATE )
166  return;
167 
168  LIB_PINS pins = m_rows[ aRow ];
169 
170  for( LIB_PIN* pin : pins )
171  {
172  switch( aCol )
173  {
174  case COL_NUMBER:
175  pin->SetNumber( aValue );
176  break;
177  case COL_NAME:
178  pin->SetName( aValue );
179  break;
180  case COL_TYPE:
181  pin->SetType( (ELECTRICAL_PINTYPE) g_typeNames.Index( aValue ), false );
182  break;
183  case COL_SHAPE:
184  pin->SetShape( (GRAPHIC_PINSHAPE) g_shapeNames.Index( aValue ) );
185  break;
186  case COL_ORIENTATION:
187  pin->SetOrientation( LIB_PIN::GetOrientationCode(
188  g_orientationNames.Index( aValue ) ), false );
189  break;
190  case COL_NUMBER_SIZE:
191  pin->SetNumberTextSize( ValueFromString( m_userUnits, aValue, true ) );
192  break;
193  case COL_NAME_SIZE:
194  pin->SetNameTextSize( ValueFromString( m_userUnits, aValue, true ) );
195  break;
196  case COL_LENGTH:
197  pin->SetLength( ValueFromString( m_userUnits, aValue ) );
198  break;
199  case COL_POSX:
200  pin->SetPinPosition( wxPoint( ValueFromString( m_userUnits, aValue ),
201  pin->GetPosition().y ) );
202  break;
203  case COL_POSY:
204  pin->SetPinPosition( wxPoint( pin->GetPosition().x,
205  ValueFromString( m_userUnits, aValue ) ) );
206  break;
207  default:
208  wxFAIL;
209  break;
210  }
211  }
212  }
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 312 of file dialog_lib_edit_pin_table.cpp.

References compare(), and numEval::lhs.

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

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

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

Definition at line 57 of file dialog_lib_edit_pin_table.cpp.

EDA_UNITS_T PIN_TABLE_DATA_MODEL::m_userUnits
private

Definition at line 59 of file dialog_lib_edit_pin_table.cpp.


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