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

Public Member Functions

 FIELDS_EDITOR_GRID_DATA_MODEL (SCH_EDIT_FRAME *aFrame, SCH_REFERENCE_LIST &aComponentList)
 
void AddColumn (const wxString &aFieldName)
 
int GetNumberRows () override
 
int GetNumberCols () override
 
wxString GetColLabelValue (int aCol) override
 
bool IsEmptyCell (int aRow, int aCol) override
 
wxString GetValue (int aRow, int aCol) override
 
std::vector< SCH_REFERENCEGetRowReferences (int aRow)
 
wxString GetValue (DATA_MODEL_ROW &group, int aCol)
 
void SetValue (int aRow, int aCol, const wxString &aValue) override
 
void Sort (int aColumn, bool ascending)
 
bool unitMatch (const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef)
 
bool groupMatch (const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef, wxDataViewListCtrl *fieldsCtrl)
 
void RebuildRows (wxCheckBox *groupComponentsBox, wxDataViewListCtrl *fieldsCtrl)
 
void ExpandRow (int aRow)
 
void CollapseRow (int aRow)
 
void ExpandCollapseRow (int aRow)
 
void CollapseForSort ()
 
void ExpandAfterSort ()
 
void ApplyData ()
 
int GetDataWidth (int aCol)
 
bool IsEdited ()
 

Static Public Member Functions

static bool cmp (const DATA_MODEL_ROW &lhGroup, const DATA_MODEL_ROW &rhGroup, FIELDS_EDITOR_GRID_DATA_MODEL *dataModel, int sortCol, bool ascending)
 

Protected Attributes

SCH_EDIT_FRAMEm_frame
 
SCH_REFERENCE_LIST m_componentRefs
 
bool m_edited
 
std::vector< wxString > m_fieldNames
 
int m_sortColumn
 
bool m_sortAscending
 
std::vector< DATA_MODEL_ROWm_rows
 
std::map< timestamp_t, std::map< wxString, wxString > > m_dataStore
 

Detailed Description

Definition at line 152 of file dialog_fields_editor_global.cpp.

Constructor & Destructor Documentation

FIELDS_EDITOR_GRID_DATA_MODEL::FIELDS_EDITOR_GRID_DATA_MODEL ( SCH_EDIT_FRAME aFrame,
SCH_REFERENCE_LIST aComponentList 
)
inline

Definition at line 180 of file dialog_fields_editor_global.cpp.

References SCH_REFERENCE_LIST::SplitReferences().

180  :
181  m_frame( aFrame ),
182  m_componentRefs( aComponentList ),
183  m_edited( false ),
184  m_sortAscending( false )
185  {
187  }
void SplitReferences()
Function SplitReferences attempts to split all reference designators into a name (U) and number (1)...

Member Function Documentation

void FIELDS_EDITOR_GRID_DATA_MODEL::AddColumn ( const wxString &  aFieldName)
inline

Definition at line 190 of file dialog_fields_editor_global.cpp.

References SCH_REFERENCE_LIST::GetCount(), SCH_COMPONENT::GetFieldText(), EDA_ITEM::GetTimeStamp(), and i.

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::AddField().

191  {
192  m_fieldNames.push_back( aFieldName );
193 
194  for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i )
195  {
196  SCH_COMPONENT* comp = m_componentRefs[ i ].GetComp();
197  timestamp_t compID = comp->GetTimeStamp();
198 
199  m_dataStore[ compID ][ aFieldName ] = comp->GetFieldText( aFieldName, m_frame );
200  }
201  }
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
std::map< timestamp_t, std::map< wxString, wxString > > m_dataStore
wxString GetFieldText(const wxString &aFieldName, SCH_EDIT_FRAME *aFrame) const
Search for a field named aFieldName and returns text associated with this field.
size_t i
Definition: json11.cpp:597
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
unsigned GetCount()
Function GetCount.
timestamp_t GetTimeStamp() const
Definition: base_struct.h:207
void FIELDS_EDITOR_GRID_DATA_MODEL::ApplyData ( )
inline

Definition at line 576 of file dialog_fields_editor_global.cpp.

References SCH_COMPONENT::AddField(), SCH_COMPONENT::FindField(), SCH_REFERENCE_LIST::GetCount(), EDA_ITEM::GetTimeStamp(), i, SCH_COMPONENT::RemoveField(), SCH_EDIT_FRAME::SaveCopyInUndoList(), SCH_EDIT_FRAME::SetCurrentSheet(), EDA_TEXT::SetText(), and UR_CHANGED.

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::TransferDataFromWindow().

577  {
578  for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i )
579  {
580  SCH_COMPONENT* comp = m_componentRefs[ i ].GetComp();
581 
582  m_frame->SetCurrentSheet( m_componentRefs[ i ].GetSheetPath() );
583  m_frame->SaveCopyInUndoList( comp, UR_CHANGED, true );
584 
585  std::map<wxString, wxString>& fieldStore = m_dataStore[ comp->GetTimeStamp() ];
586 
587  for( std::pair<wxString, wxString> srcData : fieldStore )
588  {
589  wxString srcName = srcData.first;
590  wxString srcValue = srcData.second;
591  SCH_FIELD* destField = comp->FindField( srcName );
592 
593  if( !destField && !srcValue.IsEmpty() )
594  destField = comp->AddField( SCH_FIELD( wxPoint( 0, 0 ), -1, comp, srcName ) );
595 
596  if( destField && !srcValue.IsEmpty() )
597  destField->SetText( srcValue );
598  else
599  comp->RemoveField( srcName );
600  }
601  }
602 
603  m_edited = false;
604  }
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
Class SCH_FIELD instances are attached to a component and provide a place for the component&#39;s value...
Definition: sch_field.h:56
SCH_FIELD * FindField(const wxString &aFieldName, bool aIncludeDefaultFields=true)
Search for a SCH_FIELD with aFieldName.
std::map< timestamp_t, std::map< wxString, wxString > > m_dataStore
void SaveCopyInUndoList(SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, bool aAppend=false, const wxPoint &aTransformPoint=wxPoint(0, 0))
Create a copy of the current schematic item, and put it in the undo list.
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
size_t i
Definition: json11.cpp:597
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
void RemoveField(const wxString &aFieldName)
Removes a user field from the symbol.
unsigned GetCount()
Function GetCount.
timestamp_t GetTimeStamp() const
Definition: base_struct.h:207
virtual void SetText(const wxString &aText)
Definition: eda_text.h:154
static bool FIELDS_EDITOR_GRID_DATA_MODEL::cmp ( const DATA_MODEL_ROW lhGroup,
const DATA_MODEL_ROW rhGroup,
FIELDS_EDITOR_GRID_DATA_MODEL dataModel,
int  sortCol,
bool  ascending 
)
inlinestatic

Definition at line 327 of file dialog_fields_editor_global.cpp.

References GetValue(), numEval::lhs, DATA_MODEL_ROW::m_Refs, RefDesStringCompare(), REFERENCE, and ValueStringCompare().

329  {
330  // Empty rows always go to the bottom, whether ascending or descending
331  if( lhGroup.m_Refs.size() == 0 )
332  return true;
333  else if( rhGroup.m_Refs.size() == 0 )
334  return false;
335 
336  bool retVal;
337 
338  // Primary sort key is sortCol; secondary is always REFERENCE (column 0)
339 
340  wxString lhs = dataModel->GetValue( (DATA_MODEL_ROW&) lhGroup, sortCol );
341  wxString rhs = dataModel->GetValue( (DATA_MODEL_ROW&) rhGroup, sortCol );
342 
343  if( lhs == rhs || sortCol == REFERENCE )
344  {
345  wxString lhRef = lhGroup.m_Refs[ 0 ].GetRef() + lhGroup.m_Refs[ 0 ].GetRefNumber();
346  wxString rhRef = rhGroup.m_Refs[ 0 ].GetRef() + rhGroup.m_Refs[ 0 ].GetRefNumber();
347  retVal = RefDesStringCompare( lhRef, rhRef ) < 0;
348  }
349  else
350  retVal = ValueStringCompare( lhs, rhs ) < 0;
351 
352  if( ascending )
353  return retVal;
354  else
355  return !retVal;
356  }
std::vector< SCH_REFERENCE > m_Refs
Field Reference of part, i.e. "IC21".
int ValueStringCompare(wxString strFWord, wxString strSWord)
Function ValueStringCompare acts just like the strcmp function but handles numbers and modifiers with...
Definition: string.cpp:494
YYCODETYPE lhs
wxString GetValue(int aRow, int aCol) override
int RefDesStringCompare(wxString strFWord, wxString strSWord)
Function RefDesStringCompare acts just like the strcmp function but treats numbers within the string ...
Definition: string.cpp:542
void FIELDS_EDITOR_GRID_DATA_MODEL::CollapseForSort ( )
inline

Definition at line 553 of file dialog_fields_editor_global.cpp.

References GROUP_COLLAPSED_DURING_SORT, GROUP_EXPANDED, and i.

554  {
555  for( size_t i = 0; i < m_rows.size(); ++i )
556  {
557  if( m_rows[ i ].m_Flag == GROUP_EXPANDED )
558  {
559  CollapseRow( i );
561  }
562  }
563  }
size_t i
Definition: json11.cpp:597
std::vector< DATA_MODEL_ROW > m_rows
void FIELDS_EDITOR_GRID_DATA_MODEL::CollapseRow ( int  aRow)
inline

Definition at line 522 of file dialog_fields_editor_global.cpp.

References CHILD_ITEM, and GROUP_COLLAPSED.

523  {
524  auto firstChild = m_rows.begin() + aRow + 1;
525  auto afterLastChild = firstChild;
526  int deleted = 0;
527 
528  while( afterLastChild != m_rows.end() && afterLastChild->m_Flag == CHILD_ITEM )
529  {
530  deleted++;
531  afterLastChild++;
532  }
533 
534  m_rows[ aRow ].m_Flag = GROUP_COLLAPSED;
535  m_rows.erase( firstChild, afterLastChild );
536 
537  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow + 1, deleted );
538  GetView()->ProcessTableMessage( msg );
539  }
std::vector< DATA_MODEL_ROW > m_rows
void FIELDS_EDITOR_GRID_DATA_MODEL::ExpandAfterSort ( )
inline

Definition at line 566 of file dialog_fields_editor_global.cpp.

References GROUP_COLLAPSED_DURING_SORT, and i.

567  {
568  for( size_t i = 0; i < m_rows.size(); ++i )
569  {
570  if( m_rows[ i ].m_Flag == GROUP_COLLAPSED_DURING_SORT )
571  ExpandRow( i );
572  }
573  }
size_t i
Definition: json11.cpp:597
std::vector< DATA_MODEL_ROW > m_rows
void FIELDS_EDITOR_GRID_DATA_MODEL::ExpandCollapseRow ( int  aRow)
inline
void FIELDS_EDITOR_GRID_DATA_MODEL::ExpandRow ( int  aRow)
inline

Definition at line 480 of file dialog_fields_editor_global.cpp.

References CHILD_ITEM, GROUP_EXPANDED, and numEval::lhs.

481  {
482  std::vector<DATA_MODEL_ROW> children;
483 
484  for( auto& ref : m_rows[ aRow ].m_Refs )
485  {
486  bool matchFound = false;
487 
488  // See if we already have a child group which this component fits into
489  for( auto& child : children )
490  {
491  // group members are by definition all matching, so just check
492  // against the first member
493  if( unitMatch( ref, child.m_Refs[ 0 ] ) )
494  {
495  matchFound = true;
496  child.m_Refs.push_back( ref );
497  break;
498  }
499  }
500 
501  if( !matchFound )
502  children.push_back( DATA_MODEL_ROW( ref, CHILD_ITEM ) );
503  }
504 
505  if( children.size() < 2 )
506  return;
507 
508  std::sort( children.begin(), children.end(),
509  [ this ] ( const DATA_MODEL_ROW& lhs, const DATA_MODEL_ROW& rhs ) -> bool
510  {
511  return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
512  } );
513 
514  m_rows[ aRow ].m_Flag = GROUP_EXPANDED;
515  m_rows.insert( m_rows.begin() + aRow + 1, children.begin(), children.end() );
516 
517  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, aRow, children.size() );
518  GetView()->ProcessTableMessage( msg );
519  }
bool unitMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef)
YYCODETYPE lhs
static bool cmp(const DATA_MODEL_ROW &lhGroup, const DATA_MODEL_ROW &rhGroup, FIELDS_EDITOR_GRID_DATA_MODEL *dataModel, int sortCol, bool ascending)
std::vector< DATA_MODEL_ROW > m_rows
wxString FIELDS_EDITOR_GRID_DATA_MODEL::GetColLabelValue ( int  aCol)
inlineoverride

Definition at line 210 of file dialog_fields_editor_global.cpp.

References QUANTITY_COLUMN.

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::OnAddField().

211  {
212  if( aCol == QUANTITY_COLUMN )
213  return _( "Qty" );
214  else
215  return m_fieldNames[ aCol ];
216  }
#define QUANTITY_COLUMN
int FIELDS_EDITOR_GRID_DATA_MODEL::GetDataWidth ( int  aCol)
inline

Definition at line 607 of file dialog_fields_editor_global.cpp.

References SCH_REFERENCE_LIST::GetCount(), GetTextSize(), max, and REFERENCE.

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL().

608  {
609  int width = 0;
610 
611  if( aCol == REFERENCE )
612  {
613  for( int row = 0; row < GetNumberRows(); ++row )
614  {
615  width = std::max( width, GetTextSize( GetValue( row, aCol ), GetView() ).x );
616  }
617  }
618  else
619  {
620  wxString column_label = GetColLabelValue( aCol ); // component fieldName or Qty string
621 
622  for( unsigned compRef = 0; compRef < m_componentRefs.GetCount(); ++ compRef )
623  {
624  timestamp_t compId = m_componentRefs[ compRef ].GetComp()->GetTimeStamp();
625  wxString text = m_dataStore[ compId ][ column_label ];
626  width = std::max( width, GetTextSize( text, GetView() ).x );
627  }
628  }
629 
630  return width;
631  }
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
std::map< timestamp_t, std::map< wxString, wxString > > m_dataStore
wxString GetColLabelValue(int aCol) override
Field Reference of part, i.e. "IC21".
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: common.cpp:111
#define max(a, b)
Definition: auxiliary.h:86
wxString GetValue(int aRow, int aCol) override
unsigned GetCount()
Function GetCount.
int FIELDS_EDITOR_GRID_DATA_MODEL::GetNumberCols ( )
inlineoverride

Definition at line 207 of file dialog_fields_editor_global.cpp.

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::OnAddField().

207 { return m_fieldNames.size() + 1; }
int FIELDS_EDITOR_GRID_DATA_MODEL::GetNumberRows ( )
inlineoverride

Definition at line 204 of file dialog_fields_editor_global.cpp.

204 { return m_rows.size(); }
std::vector< DATA_MODEL_ROW > m_rows
std::vector<SCH_REFERENCE> FIELDS_EDITOR_GRID_DATA_MODEL::GetRowReferences ( int  aRow)
inline

Definition at line 243 of file dialog_fields_editor_global.cpp.

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::OnTableCellClick().

244  {
245  wxCHECK( aRow < (int)m_rows.size(), std::vector<SCH_REFERENCE>() );
246  return m_rows[ aRow ].m_Refs;
247  }
std::vector< DATA_MODEL_ROW > m_rows
wxString FIELDS_EDITOR_GRID_DATA_MODEL::GetValue ( int  aRow,
int  aCol 
)
inlineoverride

Definition at line 225 of file dialog_fields_editor_global.cpp.

References CHILD_ITEM, GROUP_COLLAPSED, GROUP_EXPANDED, and REFERENCE.

Referenced by cmp().

226  {
227  if( aCol == REFERENCE )
228  {
229  // Poor-man's tree controls
230  if( m_rows[ aRow ].m_Flag == GROUP_COLLAPSED )
231  return wxT( "> " ) + GetValue( m_rows[ aRow ], aCol );
232  else if (m_rows[ aRow ].m_Flag == GROUP_EXPANDED )
233  return wxT( "v " ) + GetValue( m_rows[ aRow ], aCol );
234  else if( m_rows[ aRow ].m_Flag == CHILD_ITEM )
235  return wxT( " " ) + GetValue( m_rows[ aRow ], aCol );
236  else
237  return wxT( " " ) + GetValue( m_rows[ aRow ], aCol );
238  }
239  else
240  return GetValue( m_rows[ aRow ], aCol );
241  }
Field Reference of part, i.e. "IC21".
wxString GetValue(int aRow, int aCol) override
std::vector< DATA_MODEL_ROW > m_rows
wxString FIELDS_EDITOR_GRID_DATA_MODEL::GetValue ( DATA_MODEL_ROW group,
int  aCol 
)
inline

Definition at line 249 of file dialog_fields_editor_global.cpp.

References Format(), SCH_REFERENCE::GetRef(), SCH_REFERENCE::GetRefNumber(), INDETERMINATE, DATA_MODEL_ROW::m_Refs, QUANTITY_COLUMN, RefDesStringCompare(), REFERENCE, SCH_REFERENCE_LIST::Shorthand(), and UnescapeString().

250  {
251  std::vector<SCH_REFERENCE> references;
252  wxString fieldValue;
253 
254  for( const auto& ref : group.m_Refs )
255  {
256  if( aCol == REFERENCE || aCol == QUANTITY_COLUMN )
257  {
258  references.push_back( ref );
259  }
260  else // Other columns are either a single value or ROW_MULTI_ITEMS
261  {
262  timestamp_t compID = ref.GetComp()->GetTimeStamp();
263 
264  if( &ref == &group.m_Refs.front() )
265  fieldValue = m_dataStore[ compID ][ m_fieldNames[ aCol ] ];
266  else if ( fieldValue != m_dataStore[ compID ][ m_fieldNames[ aCol ] ] )
267  return INDETERMINATE;
268  }
269  }
270 
271  if( aCol == REFERENCE || aCol == QUANTITY_COLUMN )
272  {
273  // Remove duplicates (other units of multi-unit parts)
274  std::sort( references.begin(), references.end(),
275  []( const SCH_REFERENCE& l, const SCH_REFERENCE& r ) -> bool
276  {
277  wxString l_ref( l.GetRef() << l.GetRefNumber() );
278  wxString r_ref( r.GetRef() << r.GetRefNumber() );
279  return RefDesStringCompare( l_ref, r_ref ) < 0;
280  } );
281 
282  auto logicalEnd = std::unique( references.begin(), references.end(),
283  []( const SCH_REFERENCE& l, const SCH_REFERENCE& r ) -> bool
284  {
285  // If unannotated then we can't tell what units belong together
286  // so we have to leave them all
287  if( l.GetRefNumber() == wxT( "?" ) )
288  return false;
289 
290  wxString l_ref( l.GetRef() << l.GetRefNumber() );
291  wxString r_ref( r.GetRef() << r.GetRefNumber() );
292  return l_ref == r_ref;
293  } );
294  references.erase( logicalEnd, references.end() );
295  }
296 
297  if( aCol == REFERENCE )
298  {
299  fieldValue = SCH_REFERENCE_LIST::Shorthand( references );
300  }
301  else if( aCol == QUANTITY_COLUMN )
302  {
303  fieldValue = wxString::Format( wxT( "%d" ), ( int )references.size() );
304  }
305 
306  return UnescapeString( fieldValue );
307  }
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
std::vector< SCH_REFERENCE > m_Refs
std::map< timestamp_t, std::map< wxString, wxString > > m_dataStore
static wxString Shorthand(std::vector< SCH_REFERENCE > aList)
Function Shorthand Returns a shorthand string representing all the references in the list...
Field Reference of part, i.e. "IC21".
#define INDETERMINATE
wxString GetRef() const
#define QUANTITY_COLUMN
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:93
wxString GetRefNumber() const
Class SCH_REFERENCE is used as a helper to define a component&#39;s reference designator in a schematic...
int RefDesStringCompare(wxString strFWord, wxString strSWord)
Function RefDesStringCompare acts just like the strcmp function but treats numbers within the string ...
Definition: string.cpp:542
bool FIELDS_EDITOR_GRID_DATA_MODEL::groupMatch ( const SCH_REFERENCE lhRef,
const SCH_REFERENCE rhRef,
wxDataViewListCtrl *  fieldsCtrl 
)
inline

Definition at line 390 of file dialog_fields_editor_global.cpp.

References FIELD_NAME_COLUMN, SCH_REFERENCE::GetComp(), SCH_REFERENCE::GetRef(), EDA_ITEM::GetTimeStamp(), GROUP_BY_COLUMN, i, and REFERENCE.

392  {
393  bool matchFound = false;
394 
395  // First check the reference column. This can be done directly out of the
396  // SCH_REFERENCEs as the references can't be edited in the grid.
397  if( fieldsCtrl->GetToggleValue( REFERENCE, GROUP_BY_COLUMN ) )
398  {
399  // if we're grouping by reference, then only the prefix must match
400  if( lhRef.GetRef() != rhRef.GetRef() )
401  return false;
402 
403  matchFound = true;
404  }
405 
406  timestamp_t lhRefID = lhRef.GetComp()->GetTimeStamp();
407  timestamp_t rhRefID = rhRef.GetComp()->GetTimeStamp();
408 
409  // Now check all the other columns. This must be done out of the dataStore
410  // for the refresh button to work after editing.
411  for( int i = REFERENCE + 1; i < fieldsCtrl->GetItemCount(); ++i )
412  {
413  if( !fieldsCtrl->GetToggleValue( i, GROUP_BY_COLUMN ) )
414  continue;
415 
416  wxString fieldName = fieldsCtrl->GetTextValue( i, FIELD_NAME_COLUMN );
417 
418  if( m_dataStore[ lhRefID ][ fieldName ] != m_dataStore[ rhRefID ][ fieldName ] )
419  return false;
420 
421  matchFound = true;
422  }
423 
424  return matchFound;
425  }
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
std::map< timestamp_t, std::map< wxString, wxString > > m_dataStore
Field Reference of part, i.e. "IC21".
wxString GetRef() const
#define FIELD_NAME_COLUMN
size_t i
Definition: json11.cpp:597
#define GROUP_BY_COLUMN
SCH_COMPONENT * GetComp() const
timestamp_t GetTimeStamp() const
Definition: base_struct.h:207
bool FIELDS_EDITOR_GRID_DATA_MODEL::IsEdited ( )
inline

Definition at line 634 of file dialog_fields_editor_global.cpp.

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::OnClose().

635  {
636  return m_edited;
637  }
bool FIELDS_EDITOR_GRID_DATA_MODEL::IsEmptyCell ( int  aRow,
int  aCol 
)
inlineoverride

Definition at line 219 of file dialog_fields_editor_global.cpp.

220  {
221  return false; // don't allow adjacent cell overflow, even if we are actually empty
222  }
void FIELDS_EDITOR_GRID_DATA_MODEL::RebuildRows ( wxCheckBox *  groupComponentsBox,
wxDataViewListCtrl *  fieldsCtrl 
)
inline

Definition at line 428 of file dialog_fields_editor_global.cpp.

References SCH_REFERENCE_LIST::GetCount(), GROUP_COLLAPSED, GROUP_SINGLETON, i, and SCH_REFERENCE::m_Flag.

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL(), DIALOG_FIELDS_EDITOR_GLOBAL::OnColumnItemToggled(), DIALOG_FIELDS_EDITOR_GLOBAL::OnGroupComponentsToggled(), and DIALOG_FIELDS_EDITOR_GLOBAL::OnRegroupComponents().

429  {
430  if ( GetView() )
431  {
432  // Commit any pending in-place edits before the row gets moved out from under
433  // the editor.
434  static_cast<WX_GRID*>( GetView() )->CommitPendingChanges( true );
435 
436  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_rows.size() );
437  GetView()->ProcessTableMessage( msg );
438  }
439 
440  m_rows.clear();
441 
442  for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i )
443  {
445  bool matchFound = false;
446 
447  // See if we already have a row which this component fits into
448  for( auto& row : m_rows )
449  {
450  // all group members must have identical refs so just use the first one
451  SCH_REFERENCE rowRef = row.m_Refs[ 0 ];
452 
453  if( unitMatch( ref, rowRef ) )
454  {
455  matchFound = true;
456  row.m_Refs.push_back( ref );
457  break;
458  }
459  else if (groupComponentsBox->GetValue() && groupMatch( ref, rowRef, fieldsCtrl ) )
460  {
461  matchFound = true;
462  row.m_Refs.push_back( ref );
463  row.m_Flag = GROUP_COLLAPSED;
464  break;
465  }
466  }
467 
468  if( !matchFound )
469  m_rows.push_back( DATA_MODEL_ROW( ref, GROUP_SINGLETON ) );
470  }
471 
472  if ( GetView() )
473  {
474  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rows.size() );
475  GetView()->ProcessTableMessage( msg );
476  }
477  }
bool unitMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef)
bool groupMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef, wxDataViewListCtrl *fieldsCtrl)
size_t i
Definition: json11.cpp:597
unsigned GetCount()
Function GetCount.
std::vector< DATA_MODEL_ROW > m_rows
Class SCH_REFERENCE is used as a helper to define a component&#39;s reference designator in a schematic...
void FIELDS_EDITOR_GRID_DATA_MODEL::SetValue ( int  aRow,
int  aCol,
const wxString &  aValue 
)
inlineoverride

Definition at line 310 of file dialog_fields_editor_global.cpp.

References EscapeString(), DATA_MODEL_ROW::m_Refs, QUANTITY_COLUMN, and REFERENCE.

311  {
312  if( aCol == REFERENCE || aCol == QUANTITY_COLUMN )
313  return; // Can't modify references or quantity
314 
315  wxString value = EscapeString( aValue );
316 
317  DATA_MODEL_ROW& rowGroup = m_rows[ aRow ];
318  wxString fieldName = m_fieldNames[ aCol ];
319 
320  for( const auto& ref : rowGroup.m_Refs )
321  m_dataStore[ ref.GetComp()->GetTimeStamp() ][ fieldName ] = value;
322 
323  m_edited = true;
324  }
std::vector< SCH_REFERENCE > m_Refs
std::map< timestamp_t, std::map< wxString, wxString > > m_dataStore
Field Reference of part, i.e. "IC21".
wxString EscapeString(const wxString &aSource)
These Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which ar...
Definition: string.cpp:49
#define QUANTITY_COLUMN
std::vector< DATA_MODEL_ROW > m_rows
void FIELDS_EDITOR_GRID_DATA_MODEL::Sort ( int  aColumn,
bool  ascending 
)
inline

Definition at line 359 of file dialog_fields_editor_global.cpp.

References numEval::lhs.

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL(), DIALOG_FIELDS_EDITOR_GLOBAL::OnColSort(), DIALOG_FIELDS_EDITOR_GLOBAL::OnColumnItemToggled(), DIALOG_FIELDS_EDITOR_GLOBAL::OnGroupComponentsToggled(), and DIALOG_FIELDS_EDITOR_GLOBAL::OnRegroupComponents().

360  {
361  if( aColumn < 0 )
362  aColumn = 0;
363 
364  m_sortColumn = aColumn;
365  m_sortAscending = ascending;
366 
367  CollapseForSort();
368 
369  std::sort( m_rows.begin(), m_rows.end(),
370  [ this ]( const DATA_MODEL_ROW& lhs, const DATA_MODEL_ROW& rhs ) -> bool
371  {
372  return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
373  } );
374 
375  ExpandAfterSort();
376  }
YYCODETYPE lhs
static bool cmp(const DATA_MODEL_ROW &lhGroup, const DATA_MODEL_ROW &rhGroup, FIELDS_EDITOR_GRID_DATA_MODEL *dataModel, int sortCol, bool ascending)
std::vector< DATA_MODEL_ROW > m_rows
bool FIELDS_EDITOR_GRID_DATA_MODEL::unitMatch ( const SCH_REFERENCE lhRef,
const SCH_REFERENCE rhRef 
)
inline

Definition at line 379 of file dialog_fields_editor_global.cpp.

References SCH_REFERENCE::GetRef(), and SCH_REFERENCE::GetRefNumber().

380  {
381  // If items are unannotated then we can't tell if they're units of the same
382  // component or not
383  if( lhRef.GetRefNumber() == wxT( "?" ) )
384  return false;
385 
386  return ( lhRef.GetRef() == rhRef.GetRef() && lhRef.GetRefNumber() == rhRef.GetRefNumber() );
387  }
wxString GetRef() const
wxString GetRefNumber() const

Member Data Documentation

SCH_REFERENCE_LIST FIELDS_EDITOR_GRID_DATA_MODEL::m_componentRefs
protected

Definition at line 158 of file dialog_fields_editor_global.cpp.

std::map< timestamp_t, std::map<wxString, wxString> > FIELDS_EDITOR_GRID_DATA_MODEL::m_dataStore
protected

Definition at line 176 of file dialog_fields_editor_global.cpp.

bool FIELDS_EDITOR_GRID_DATA_MODEL::m_edited
protected

Definition at line 159 of file dialog_fields_editor_global.cpp.

std::vector<wxString> FIELDS_EDITOR_GRID_DATA_MODEL::m_fieldNames
protected

Definition at line 160 of file dialog_fields_editor_global.cpp.

SCH_EDIT_FRAME* FIELDS_EDITOR_GRID_DATA_MODEL::m_frame
protected

Definition at line 157 of file dialog_fields_editor_global.cpp.

std::vector< DATA_MODEL_ROW > FIELDS_EDITOR_GRID_DATA_MODEL::m_rows
protected

Definition at line 172 of file dialog_fields_editor_global.cpp.

bool FIELDS_EDITOR_GRID_DATA_MODEL::m_sortAscending
protected

Definition at line 162 of file dialog_fields_editor_global.cpp.

int FIELDS_EDITOR_GRID_DATA_MODEL::m_sortColumn
protected

Definition at line 161 of file dialog_fields_editor_global.cpp.


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