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 153 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 181 of file dialog_fields_editor_global.cpp.

References SCH_REFERENCE_LIST::SplitReferences().

181  :
182  m_frame( aFrame ),
183  m_componentRefs( aComponentList ),
184  m_edited( false ),
185  m_sortAscending( false )
186  {
188  }
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 191 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().

192  {
193  m_fieldNames.push_back( aFieldName );
194 
195  for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i )
196  {
197  SCH_COMPONENT* comp = m_componentRefs[ i ].GetComp();
198  timestamp_t compID = comp->GetTimeStamp();
199 
200  m_dataStore[ compID ][ aFieldName ] = comp->GetFieldText( aFieldName, m_frame );
201  }
202  }
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:53
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:70
unsigned GetCount()
Function GetCount.
timestamp_t GetTimeStamp() const
Definition: base_struct.h:207
void FIELDS_EDITOR_GRID_DATA_MODEL::ApplyData ( )
inline

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

578  {
579  for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i )
580  {
581  SCH_COMPONENT* comp = m_componentRefs[ i ].GetComp();
582 
583  m_frame->SetCurrentSheet( m_componentRefs[ i ].GetSheetPath() );
584  m_frame->SaveCopyInUndoList( comp, UR_CHANGED, true );
585 
586  std::map<wxString, wxString>& fieldStore = m_dataStore[ comp->GetTimeStamp() ];
587 
588  for( std::pair<wxString, wxString> srcData : fieldStore )
589  {
590  wxString srcName = srcData.first;
591  wxString srcValue = srcData.second;
592  SCH_FIELD* destField = comp->FindField( srcName );
593 
594  if( !destField && !srcValue.IsEmpty() )
595  destField = comp->AddField( SCH_FIELD( wxPoint( 0, 0 ), -1, comp, srcName ) );
596 
597  if( destField && !srcValue.IsEmpty() )
598  destField->SetText( srcValue );
599  else
600  comp->RemoveField( srcName );
601  }
602  }
603 
604  m_edited = false;
605  }
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:70
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 328 of file dialog_fields_editor_global.cpp.

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

330  {
331  // Empty rows always go to the bottom, whether ascending or descending
332  if( lhGroup.m_Refs.size() == 0 )
333  return true;
334  else if( rhGroup.m_Refs.size() == 0 )
335  return false;
336 
337  bool retVal;
338 
339  // Primary sort key is sortCol; secondary is always REFERENCE (column 0)
340 
341  wxString lhs = dataModel->GetValue( (DATA_MODEL_ROW&) lhGroup, sortCol );
342  wxString rhs = dataModel->GetValue( (DATA_MODEL_ROW&) rhGroup, sortCol );
343 
344  if( lhs == rhs || sortCol == REFERENCE )
345  {
346  wxString lhRef = lhGroup.m_Refs[ 0 ].GetRef() + lhGroup.m_Refs[ 0 ].GetRefNumber();
347  wxString rhRef = rhGroup.m_Refs[ 0 ].GetRef() + rhGroup.m_Refs[ 0 ].GetRefNumber();
348  retVal = RefDesStringCompare( lhRef, rhRef ) < 0;
349  }
350  else
351  retVal = ValueStringCompare( lhs, rhs ) < 0;
352 
353  if( ascending )
354  return retVal;
355  else
356  return !retVal;
357  }
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 554 of file dialog_fields_editor_global.cpp.

References GROUP_COLLAPSED_DURING_SORT, GROUP_EXPANDED, and i.

555  {
556  for( size_t i = 0; i < m_rows.size(); ++i )
557  {
558  if( m_rows[ i ].m_Flag == GROUP_EXPANDED )
559  {
560  CollapseRow( i );
562  }
563  }
564  }
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 523 of file dialog_fields_editor_global.cpp.

References CHILD_ITEM, and GROUP_COLLAPSED.

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

Definition at line 567 of file dialog_fields_editor_global.cpp.

References GROUP_COLLAPSED_DURING_SORT, and i.

568  {
569  for( size_t i = 0; i < m_rows.size(); ++i )
570  {
571  if( m_rows[ i ].m_Flag == GROUP_COLLAPSED_DURING_SORT )
572  ExpandRow( i );
573  }
574  }
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 481 of file dialog_fields_editor_global.cpp.

References CHILD_ITEM, GROUP_EXPANDED, and numEval::lhs.

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

References QUANTITY_COLUMN.

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::OnAddField().

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

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

609  {
610  int width = 0;
611 
612  if( aCol == REFERENCE )
613  {
614  for( int row = 0; row < GetNumberRows(); ++row )
615  {
616  width = std::max( width, GetTextSize( GetValue( row, aCol ), GetView() ).x );
617  }
618  }
619  else
620  {
621  wxString column_label = GetColLabelValue( aCol ); // component fieldName or Qty string
622 
623  for( unsigned compRef = 0; compRef < m_componentRefs.GetCount(); ++ compRef )
624  {
625  timestamp_t compId = m_componentRefs[ compRef ].GetComp()->GetTimeStamp();
626  wxString text = m_dataStore[ compId ][ column_label ];
627  width = std::max( width, GetTextSize( text, GetView() ).x );
628  }
629  }
630 
631  return width;
632  }
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:53
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 208 of file dialog_fields_editor_global.cpp.

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::OnAddField().

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

Definition at line 205 of file dialog_fields_editor_global.cpp.

205 { 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 244 of file dialog_fields_editor_global.cpp.

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::OnTableCellClick().

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

Definition at line 226 of file dialog_fields_editor_global.cpp.

References CHILD_ITEM, GROUP_COLLAPSED, GROUP_EXPANDED, and REFERENCE.

Referenced by cmp().

227  {
228  if( aCol == REFERENCE )
229  {
230  // Poor-man's tree controls
231  if( m_rows[ aRow ].m_Flag == GROUP_COLLAPSED )
232  return wxT( "> " ) + GetValue( m_rows[ aRow ], aCol );
233  else if (m_rows[ aRow ].m_Flag == GROUP_EXPANDED )
234  return wxT( "v " ) + GetValue( m_rows[ aRow ], aCol );
235  else if( m_rows[ aRow ].m_Flag == CHILD_ITEM )
236  return wxT( " " ) + GetValue( m_rows[ aRow ], aCol );
237  else
238  return wxT( " " ) + GetValue( m_rows[ aRow ], aCol );
239  }
240  else
241  return GetValue( m_rows[ aRow ], aCol );
242  }
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 250 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().

251  {
252  std::vector<SCH_REFERENCE> references;
253  wxString fieldValue;
254 
255  for( const auto& ref : group.m_Refs )
256  {
257  if( aCol == REFERENCE || aCol == QUANTITY_COLUMN )
258  {
259  references.push_back( ref );
260  }
261  else // Other columns are either a single value or ROW_MULTI_ITEMS
262  {
263  timestamp_t compID = ref.GetComp()->GetTimeStamp();
264 
265  if( &ref == &group.m_Refs.front() )
266  fieldValue = m_dataStore[ compID ][ m_fieldNames[ aCol ] ];
267  else if ( fieldValue != m_dataStore[ compID ][ m_fieldNames[ aCol ] ] )
268  return INDETERMINATE;
269  }
270  }
271 
272  if( aCol == REFERENCE || aCol == QUANTITY_COLUMN )
273  {
274  // Remove duplicates (other units of multi-unit parts)
275  std::sort( references.begin(), references.end(),
276  []( const SCH_REFERENCE& l, const SCH_REFERENCE& r ) -> bool
277  {
278  wxString l_ref( l.GetRef() << l.GetRefNumber() );
279  wxString r_ref( r.GetRef() << r.GetRefNumber() );
280  return RefDesStringCompare( l_ref, r_ref ) < 0;
281  } );
282 
283  auto logicalEnd = std::unique( references.begin(), references.end(),
284  []( const SCH_REFERENCE& l, const SCH_REFERENCE& r ) -> bool
285  {
286  // If unannotated then we can't tell what units belong together
287  // so we have to leave them all
288  if( l.GetRefNumber() == wxT( "?" ) )
289  return false;
290 
291  wxString l_ref( l.GetRef() << l.GetRefNumber() );
292  wxString r_ref( r.GetRef() << r.GetRefNumber() );
293  return l_ref == r_ref;
294  } );
295  references.erase( logicalEnd, references.end() );
296  }
297 
298  if( aCol == REFERENCE )
299  {
300  fieldValue = SCH_REFERENCE_LIST::Shorthand( references );
301  }
302  else if( aCol == QUANTITY_COLUMN )
303  {
304  fieldValue = wxString::Format( wxT( "%d" ), ( int )references.size() );
305  }
306 
307  return UnescapeString( fieldValue );
308  }
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:53
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 391 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.

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

Referenced by DIALOG_FIELDS_EDITOR_GLOBAL::OnClose().

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

Definition at line 220 of file dialog_fields_editor_global.cpp.

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

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

430  {
431  if ( GetView() )
432  {
433  // Commit any pending in-place edits before the row gets moved out from under
434  // the editor.
435  static_cast<WX_GRID*>( GetView() )->CommitPendingChanges( true );
436 
437  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_rows.size() );
438  GetView()->ProcessTableMessage( msg );
439  }
440 
441  m_rows.clear();
442 
443  for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i )
444  {
446  bool matchFound = false;
447 
448  // See if we already have a row which this component fits into
449  for( auto& row : m_rows )
450  {
451  // all group members must have identical refs so just use the first one
452  SCH_REFERENCE rowRef = row.m_Refs[ 0 ];
453 
454  if( unitMatch( ref, rowRef ) )
455  {
456  matchFound = true;
457  row.m_Refs.push_back( ref );
458  break;
459  }
460  else if (groupComponentsBox->GetValue() && groupMatch( ref, rowRef, fieldsCtrl ) )
461  {
462  matchFound = true;
463  row.m_Refs.push_back( ref );
464  row.m_Flag = GROUP_COLLAPSED;
465  break;
466  }
467  }
468 
469  if( !matchFound )
470  m_rows.push_back( DATA_MODEL_ROW( ref, GROUP_SINGLETON ) );
471  }
472 
473  if ( GetView() )
474  {
475  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rows.size() );
476  GetView()->ProcessTableMessage( msg );
477  }
478  }
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 311 of file dialog_fields_editor_global.cpp.

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

312  {
313  if( aCol == REFERENCE || aCol == QUANTITY_COLUMN )
314  return; // Can't modify references or quantity
315 
316  wxString value = EscapeString( aValue );
317 
318  DATA_MODEL_ROW& rowGroup = m_rows[ aRow ];
319  wxString fieldName = m_fieldNames[ aCol ];
320 
321  for( const auto& ref : rowGroup.m_Refs )
322  m_dataStore[ ref.GetComp()->GetTimeStamp() ][ fieldName ] = value;
323 
324  m_edited = true;
325  }
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 360 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().

361  {
362  if( aColumn < 0 )
363  aColumn = 0;
364 
365  m_sortColumn = aColumn;
366  m_sortAscending = ascending;
367 
368  CollapseForSort();
369 
370  std::sort( m_rows.begin(), m_rows.end(),
371  [ this ]( const DATA_MODEL_ROW& lhs, const DATA_MODEL_ROW& rhs ) -> bool
372  {
373  return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
374  } );
375 
376  ExpandAfterSort();
377  }
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 380 of file dialog_fields_editor_global.cpp.

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

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

Member Data Documentation

SCH_REFERENCE_LIST FIELDS_EDITOR_GRID_DATA_MODEL::m_componentRefs
protected

Definition at line 159 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 177 of file dialog_fields_editor_global.cpp.

bool FIELDS_EDITOR_GRID_DATA_MODEL::m_edited
protected

Definition at line 160 of file dialog_fields_editor_global.cpp.

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

Definition at line 161 of file dialog_fields_editor_global.cpp.

SCH_EDIT_FRAME* FIELDS_EDITOR_GRID_DATA_MODEL::m_frame
protected

Definition at line 158 of file dialog_fields_editor_global.cpp.

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

Definition at line 173 of file dialog_fields_editor_global.cpp.

bool FIELDS_EDITOR_GRID_DATA_MODEL::m_sortAscending
protected

Definition at line 163 of file dialog_fields_editor_global.cpp.

int FIELDS_EDITOR_GRID_DATA_MODEL::m_sortColumn
protected

Definition at line 162 of file dialog_fields_editor_global.cpp.


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