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 &aSymbolsList)
 
void AddColumn (const wxString &aFieldName)
 
int GetNumberRows () override
 
int GetNumberCols () override
 
wxString GetColLabelValue (int aCol) override
 
wxString GetCanonicalColLabel (int aCol)
 
bool IsEmptyCell (int aRow, int aCol) override
 
wxString GetValue (int aRow, int aCol) override
 
std::vector< SCH_REFERENCEGetRowReferences (int aRow) const
 
wxString GetValue (const 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 *aGroupSymbolsBox, wxDataViewListCtrl *aFieldsCtrl)
 
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_symbolsList
 
bool m_edited
 
std::vector< wxString > m_fieldNames
 
int m_sortColumn
 
bool m_sortAscending
 
std::vector< DATA_MODEL_ROWm_rows
 
std::map< KIID, std::map< wxString, wxString > > m_dataStore
 

Detailed Description

Definition at line 167 of file dialog_symbol_fields_table.cpp.

Constructor & Destructor Documentation

◆ FIELDS_EDITOR_GRID_DATA_MODEL()

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

Definition at line 194 of file dialog_symbol_fields_table.cpp.

194  :
195  m_frame( aFrame ),
196  m_symbolsList( aSymbolsList ),
197  m_edited( false ),
198  m_sortColumn( 0 ),
199  m_sortAscending( false )
200  {
202  }
void SplitReferences()
Attempt to split all reference designators into a name (U) and number (1).

References m_symbolsList, and SCH_REFERENCE_LIST::SplitReferences().

Member Function Documentation

◆ AddColumn()

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

Definition at line 204 of file dialog_symbol_fields_table.cpp.

205  {
206  m_fieldNames.push_back( aFieldName );
207 
208  for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i )
209  {
210  SCH_SYMBOL* symbol = m_symbolsList[ i ].GetSymbol();
211  m_dataStore[ symbol->m_Uuid ][ aFieldName ] = symbol->GetFieldText( aFieldName,
212  m_frame );
213  }
214  }
std::map< KIID, std::map< wxString, wxString > > m_dataStore
size_t GetCount() const
wxString GetFieldText(const wxString &aFieldName, SCH_EDIT_FRAME *aFrame) const
Search for a field named aFieldName and returns text associated with this field.
Definition: sch_symbol.cpp:699
const KIID m_Uuid
Definition: eda_item.h:475
Schematic symbol object.
Definition: sch_symbol.h:78

References SCH_REFERENCE_LIST::GetCount(), SCH_SYMBOL::GetFieldText(), m_dataStore, m_fieldNames, m_frame, m_symbolsList, and EDA_ITEM::m_Uuid.

Referenced by DIALOG_SYMBOL_FIELDS_TABLE::AddField().

◆ ApplyData()

void FIELDS_EDITOR_GRID_DATA_MODEL::ApplyData ( )
inline

Definition at line 591 of file dialog_symbol_fields_table.cpp.

592  {
593  for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i )
594  {
595  SCH_SYMBOL& symbol = *m_symbolsList[ i ].GetSymbol();
596  SCH_SCREEN* screen = m_symbolsList[i].GetSheetPath().LastScreen();
597 
598  m_frame->SaveCopyInUndoList( screen, &symbol, UNDO_REDO::CHANGED, true );
599 
600  const std::map<wxString, wxString>& fieldStore = m_dataStore[symbol.m_Uuid];
601 
602  for( const std::pair<wxString, wxString> srcData : fieldStore )
603  {
604  const wxString& srcName = srcData.first;
605  const wxString& srcValue = srcData.second;
606  SCH_FIELD* destField = symbol.FindField( srcName );
607 
608  if( !destField && !srcValue.IsEmpty() )
609  {
610  const wxPoint symbolPos = symbol.GetPosition();
611  destField = symbol.AddField( SCH_FIELD( symbolPos, -1, &symbol, srcName ) );
612  }
613 
614  if( !destField )
615  {
616  symbol.RemoveField( srcName );
617  }
618  else if( destField->GetId() == REFERENCE_FIELD )
619  {
620  // Reference is not editable
621  }
622  else if( destField->GetId() == VALUE_FIELD )
623  {
624  // Value field cannot be empty
625  if( !srcValue.IsEmpty() )
626  symbol.SetValue( srcValue );
627  }
628  else if( destField->GetId() == FOOTPRINT_FIELD )
629  {
630  symbol.SetFootprint( srcValue );
631  }
632  else
633  {
634  destField->SetText( srcValue );
635  }
636  }
637  }
638 
639  m_edited = false;
640  }
Field Reference of part, i.e. "IC21".
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
void SetValue(const SCH_SHEET_PATH *sheet, const wxString &aValue)
Definition: sch_symbol.cpp:594
std::map< KIID, std::map< wxString, wxString > > m_dataStore
int GetId() const
Definition: sch_field.h:113
void SetFootprint(const SCH_SHEET_PATH *sheet, const wxString &aFootprint)
Definition: sch_symbol.cpp:645
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
Definition: sch_symbol.cpp:721
Field Value of part, i.e. "3.3K".
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:114
size_t GetCount() const
SCH_FIELD * FindField(const wxString &aFieldName, bool aIncludeDefaultFields=true)
Search for a SCH_FIELD with aFieldName.
Definition: sch_symbol.cpp:743
const KIID m_Uuid
Definition: eda_item.h:475
Schematic symbol object.
Definition: sch_symbol.h:78
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend)
Create a copy of the current schematic item, and put it in the undo list.
wxPoint GetPosition() const override
Definition: sch_symbol.h:644
void RemoveField(const wxString &aFieldName)
Remove a user field from the symbol.
Definition: sch_symbol.cpp:730
Field Name Module PCB, i.e. "16DIP300".

References SCH_SYMBOL::AddField(), CHANGED, SCH_SYMBOL::FindField(), FOOTPRINT_FIELD, SCH_REFERENCE_LIST::GetCount(), SCH_FIELD::GetId(), SCH_SYMBOL::GetPosition(), m_dataStore, m_edited, m_frame, m_symbolsList, EDA_ITEM::m_Uuid, REFERENCE_FIELD, SCH_SYMBOL::RemoveField(), SCH_EDIT_FRAME::SaveCopyInUndoList(), SCH_SYMBOL::SetFootprint(), EDA_TEXT::SetText(), SCH_SYMBOL::SetValue(), and VALUE_FIELD.

Referenced by DIALOG_SYMBOL_FIELDS_TABLE::TransferDataFromWindow().

◆ cmp()

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 347 of file dialog_symbol_fields_table.cpp.

349  {
350  // Empty rows always go to the bottom, whether ascending or descending
351  if( lhGroup.m_Refs.size() == 0 )
352  return true;
353  else if( rhGroup.m_Refs.size() == 0 )
354  return false;
355 
356  // N.B. To meet the iterator sort conditions, we cannot simply invert the truth
357  // to get the opposite sort. i.e. ~(a<b) != (a>b)
358  auto local_cmp =
359  [ ascending ]( const auto a, const auto b )
360  {
361  if( ascending )
362  return a < b;
363  else
364  return a > b;
365  };
366 
367  // Primary sort key is sortCol; secondary is always REFERENCE (column 0)
368 
369  wxString lhs = dataModel->GetValue( (DATA_MODEL_ROW&) lhGroup, sortCol );
370  wxString rhs = dataModel->GetValue( (DATA_MODEL_ROW&) rhGroup, sortCol );
371 
372  if( lhs == rhs || sortCol == REFERENCE_FIELD )
373  {
374  wxString lhRef = lhGroup.m_Refs[ 0 ].GetRef() + lhGroup.m_Refs[ 0 ].GetRefNumber();
375  wxString rhRef = rhGroup.m_Refs[ 0 ].GetRef() + rhGroup.m_Refs[ 0 ].GetRefNumber();
376  return local_cmp( StrNumCmp( lhRef, rhRef, true ), 0 );
377  }
378  else
379  {
380  return local_cmp( ValueStringCompare( lhs, rhs ), 0 );
381  }
382  }
Field Reference of part, i.e. "IC21".
std::vector< SCH_REFERENCE > m_Refs
int ValueStringCompare(const wxString &strFWord, const wxString &strSWord)
Compare strings like the strcmp function but handle numbers and modifiers within the string text corr...
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
wxString GetValue(int aRow, int aCol) override

References GetValue(), DATA_MODEL_ROW::m_Refs, REFERENCE_FIELD, StrNumCmp(), and ValueStringCompare().

Referenced by ExpandRow(), and Sort().

◆ CollapseForSort()

void FIELDS_EDITOR_GRID_DATA_MODEL::CollapseForSort ( )
inline

Definition at line 570 of file dialog_symbol_fields_table.cpp.

571  {
572  for( size_t i = 0; i < m_rows.size(); ++i )
573  {
574  if( m_rows[ i ].m_Flag == GROUP_EXPANDED )
575  {
576  CollapseRow( i );
577  m_rows[ i ].m_Flag = GROUP_COLLAPSED_DURING_SORT;
578  }
579  }
580  }
std::vector< DATA_MODEL_ROW > m_rows

References CollapseRow(), GROUP_COLLAPSED_DURING_SORT, GROUP_EXPANDED, and m_rows.

Referenced by Sort().

◆ CollapseRow()

void FIELDS_EDITOR_GRID_DATA_MODEL::CollapseRow ( int  aRow)
inline

Definition at line 541 of file dialog_symbol_fields_table.cpp.

542  {
543  auto firstChild = m_rows.begin() + aRow + 1;
544  auto afterLastChild = firstChild;
545  int deleted = 0;
546 
547  while( afterLastChild != m_rows.end() && afterLastChild->m_Flag == CHILD_ITEM )
548  {
549  deleted++;
550  afterLastChild++;
551  }
552 
553  m_rows[ aRow ].m_Flag = GROUP_COLLAPSED;
554  m_rows.erase( firstChild, afterLastChild );
555 
556  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow + 1, deleted );
557  GetView()->ProcessTableMessage( msg );
558  }
std::vector< DATA_MODEL_ROW > m_rows

References CHILD_ITEM, GROUP_COLLAPSED, and m_rows.

Referenced by CollapseForSort(), and ExpandCollapseRow().

◆ ExpandAfterSort()

void FIELDS_EDITOR_GRID_DATA_MODEL::ExpandAfterSort ( )
inline

Definition at line 582 of file dialog_symbol_fields_table.cpp.

583  {
584  for( size_t i = 0; i < m_rows.size(); ++i )
585  {
586  if( m_rows[ i ].m_Flag == GROUP_COLLAPSED_DURING_SORT )
587  ExpandRow( i );
588  }
589  }
std::vector< DATA_MODEL_ROW > m_rows

References ExpandRow(), GROUP_COLLAPSED_DURING_SORT, and m_rows.

Referenced by Sort().

◆ ExpandCollapseRow()

void FIELDS_EDITOR_GRID_DATA_MODEL::ExpandCollapseRow ( int  aRow)
inline

◆ ExpandRow()

void FIELDS_EDITOR_GRID_DATA_MODEL::ExpandRow ( int  aRow)
inline

Definition at line 500 of file dialog_symbol_fields_table.cpp.

501  {
502  std::vector<DATA_MODEL_ROW> children;
503 
504  for( SCH_REFERENCE& ref : m_rows[ aRow ].m_Refs )
505  {
506  bool matchFound = false;
507 
508  // See if we already have a child group which this symbol fits into
509  for( DATA_MODEL_ROW& child : children )
510  {
511  // group members are by definition all matching, so just check
512  // against the first member
513  if( unitMatch( ref, child.m_Refs[ 0 ] ) )
514  {
515  matchFound = true;
516  child.m_Refs.push_back( ref );
517  break;
518  }
519  }
520 
521  if( !matchFound )
522  children.emplace_back( DATA_MODEL_ROW( ref, CHILD_ITEM ) );
523  }
524 
525  if( children.size() < 2 )
526  return;
527 
528  std::sort( children.begin(), children.end(),
529  [ this ] ( const DATA_MODEL_ROW& lhs, const DATA_MODEL_ROW& rhs ) -> bool
530  {
531  return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
532  } );
533 
534  m_rows[ aRow ].m_Flag = GROUP_EXPANDED;
535  m_rows.insert( m_rows.begin() + aRow + 1, children.begin(), children.end() );
536 
537  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, aRow, children.size() );
538  GetView()->ProcessTableMessage( msg );
539  }
bool unitMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef)
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
A helper to define a symbol's reference designator in a schematic.

References CHILD_ITEM, cmp(), GROUP_EXPANDED, m_rows, m_sortAscending, m_sortColumn, and unitMatch().

Referenced by ExpandAfterSort(), and ExpandCollapseRow().

◆ GetCanonicalColLabel()

wxString FIELDS_EDITOR_GRID_DATA_MODEL::GetCanonicalColLabel ( int  aCol)
inline

Definition at line 231 of file dialog_symbol_fields_table.cpp.

232  {
233  if( aCol == QUANTITY_COLUMN )
234  return _( "Qty" );
235  else
236  return m_fieldNames[ aCol ];
237  }
#define _(s)
#define QUANTITY_COLUMN

References _, m_fieldNames, and QUANTITY_COLUMN.

Referenced by DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE(), and DIALOG_SYMBOL_FIELDS_TABLE::OnTableColSize().

◆ GetColLabelValue()

wxString FIELDS_EDITOR_GRID_DATA_MODEL::GetColLabelValue ( int  aCol)
inlineoverride

Definition at line 221 of file dialog_symbol_fields_table.cpp.

222  {
223  if( aCol == QUANTITY_COLUMN )
224  return _( "Qty" );
225  else if( aCol < MANDATORY_FIELDS )
227  else
228  return m_fieldNames[ aCol ];
229  }
#define _(s)
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Return a default symbol field name for field aFieldNdx for all components.
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
#define QUANTITY_COLUMN

References _, TEMPLATE_FIELDNAME::GetDefaultFieldName(), m_fieldNames, MANDATORY_FIELDS, and QUANTITY_COLUMN.

Referenced by GetDataWidth(), and DIALOG_SYMBOL_FIELDS_TABLE::OnAddField().

◆ GetDataWidth()

int FIELDS_EDITOR_GRID_DATA_MODEL::GetDataWidth ( int  aCol)
inline

Definition at line 642 of file dialog_symbol_fields_table.cpp.

643  {
644  int width = 0;
645 
646  if( aCol == REFERENCE_FIELD )
647  {
648  for( int row = 0; row < GetNumberRows(); ++row )
649  width = std::max( width, KIUI::GetTextSize( GetValue( row, aCol ), GetView() ).x );
650  }
651  else
652  {
653  wxString column_label = GetColLabelValue( aCol ); // symbol fieldName or Qty string
654 
655  for( unsigned symbolRef = 0; symbolRef < m_symbolsList.GetCount(); ++ symbolRef )
656  {
657  const KIID& symbolID = m_symbolsList[ symbolRef ].GetSymbol()->m_Uuid;
658  wxString text = m_dataStore[ symbolID ][ column_label ];
659 
660  width = std::max( width, KIUI::GetTextSize( text, GetView() ).x );
661  }
662  }
663 
664  return width;
665  }
Field Reference of part, i.e. "IC21".
std::map< KIID, std::map< wxString, wxString > > m_dataStore
wxString GetColLabelValue(int aCol) override
Definition: kiid.h:44
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: ui_common.cpp:70
size_t GetCount() const
wxString GetValue(int aRow, int aCol) override

References GetColLabelValue(), SCH_REFERENCE_LIST::GetCount(), GetNumberRows(), KIUI::GetTextSize(), GetValue(), m_dataStore, m_symbolsList, REFERENCE_FIELD, and text.

Referenced by DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE().

◆ GetNumberCols()

int FIELDS_EDITOR_GRID_DATA_MODEL::GetNumberCols ( )
inlineoverride

Definition at line 219 of file dialog_symbol_fields_table.cpp.

219 { return (int) m_fieldNames.size() + 1; }

References m_fieldNames.

Referenced by DIALOG_SYMBOL_FIELDS_TABLE::OnAddField().

◆ GetNumberRows()

int FIELDS_EDITOR_GRID_DATA_MODEL::GetNumberRows ( )
inlineoverride

Definition at line 216 of file dialog_symbol_fields_table.cpp.

216 { return m_rows.size(); }
std::vector< DATA_MODEL_ROW > m_rows

References m_rows.

Referenced by GetDataWidth(), and DIALOG_SYMBOL_FIELDS_TABLE::TransferDataToWindow().

◆ GetRowReferences()

std::vector<SCH_REFERENCE> FIELDS_EDITOR_GRID_DATA_MODEL::GetRowReferences ( int  aRow) const
inline

Definition at line 264 of file dialog_symbol_fields_table.cpp.

265  {
266  wxCHECK( aRow < (int)m_rows.size(), std::vector<SCH_REFERENCE>() );
267  return m_rows[ aRow ].m_Refs;
268  }
std::vector< DATA_MODEL_ROW > m_rows

References m_rows.

Referenced by DIALOG_SYMBOL_FIELDS_TABLE::OnTableCellClick(), and DIALOG_SYMBOL_FIELDS_TABLE::TransferDataToWindow().

◆ GetValue() [1/2]

wxString FIELDS_EDITOR_GRID_DATA_MODEL::GetValue ( int  aRow,
int  aCol 
)
inlineoverride

Definition at line 244 of file dialog_symbol_fields_table.cpp.

245  {
246  if( aCol == REFERENCE_FIELD )
247  {
248  // Poor-man's tree controls
249  if( m_rows[ aRow ].m_Flag == GROUP_COLLAPSED )
250  return wxT( "> " ) + GetValue( m_rows[ aRow ], aCol );
251  else if (m_rows[ aRow ].m_Flag == GROUP_EXPANDED )
252  return wxT( "v " ) + GetValue( m_rows[ aRow ], aCol );
253  else if( m_rows[ aRow ].m_Flag == CHILD_ITEM )
254  return wxT( " " ) + GetValue( m_rows[ aRow ], aCol );
255  else
256  return wxT( " " ) + GetValue( m_rows[ aRow ], aCol );
257  }
258  else
259  {
260  return GetValue( m_rows[ aRow ], aCol );
261  }
262  }
Field Reference of part, i.e. "IC21".
wxString GetValue(int aRow, int aCol) override
std::vector< DATA_MODEL_ROW > m_rows

References CHILD_ITEM, GROUP_COLLAPSED, GROUP_EXPANDED, m_rows, and REFERENCE_FIELD.

Referenced by cmp(), and GetDataWidth().

◆ GetValue() [2/2]

wxString FIELDS_EDITOR_GRID_DATA_MODEL::GetValue ( const DATA_MODEL_ROW group,
int  aCol 
)
inline

Definition at line 270 of file dialog_symbol_fields_table.cpp.

271  {
272  std::vector<SCH_REFERENCE> references;
273  wxString fieldValue;
274 
275  for( const auto& ref : group.m_Refs )
276  {
277  if( aCol == REFERENCE_FIELD || aCol == QUANTITY_COLUMN )
278  {
279  references.push_back( ref );
280  }
281  else // Other columns are either a single value or ROW_MULTI_ITEMS
282  {
283  const KIID& symbolID = ref.GetSymbol()->m_Uuid;
284 
285  if( !m_dataStore.count( symbolID )
286  || !m_dataStore[ symbolID ].count( m_fieldNames[ aCol ] ) )
287  {
288  return INDETERMINATE_STATE;
289  }
290 
291  if( &ref == &group.m_Refs.front() )
292  fieldValue = m_dataStore[ symbolID ][ m_fieldNames[ aCol ] ];
293  else if ( fieldValue != m_dataStore[ symbolID ][ m_fieldNames[ aCol ] ] )
294  return INDETERMINATE_STATE;
295  }
296  }
297 
298  if( aCol == REFERENCE_FIELD || aCol == QUANTITY_COLUMN )
299  {
300  // Remove duplicates (other units of multi-unit parts)
301  std::sort( references.begin(), references.end(),
302  []( const SCH_REFERENCE& l, const SCH_REFERENCE& r ) -> bool
303  {
304  wxString l_ref( l.GetRef() << l.GetRefNumber() );
305  wxString r_ref( r.GetRef() << r.GetRefNumber() );
306  return StrNumCmp( l_ref, r_ref, true ) < 0;
307  } );
308 
309  auto logicalEnd = std::unique( references.begin(), references.end(),
310  []( const SCH_REFERENCE& l, const SCH_REFERENCE& r ) -> bool
311  {
312  // If unannotated then we can't tell what units belong together
313  // so we have to leave them all
314  if( l.GetRefNumber() == wxT( "?" ) )
315  return false;
316 
317  wxString l_ref( l.GetRef() << l.GetRefNumber() );
318  wxString r_ref( r.GetRef() << r.GetRefNumber() );
319  return l_ref == r_ref;
320  } );
321 
322  references.erase( logicalEnd, references.end() );
323  }
324 
325  if( aCol == REFERENCE_FIELD )
326  fieldValue = SCH_REFERENCE_LIST::Shorthand( references );
327  else if( aCol == QUANTITY_COLUMN )
328  fieldValue = wxString::Format( wxT( "%d" ), ( int )references.size() );
329 
330  return fieldValue;
331  }
Field Reference of part, i.e. "IC21".
std::map< KIID, std::map< wxString, wxString > > m_dataStore
static wxString Shorthand(std::vector< SCH_REFERENCE > aList)
Return a shorthand string representing all the references in the list.
wxString GetRefNumber() const
wxString GetRef() const
Definition: kiid.h:44
E_SERIE r
Definition: eserie.cpp:41
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition: base_units.h:47
#define QUANTITY_COLUMN
A helper to define a symbol's reference designator in a schematic.

References Format(), SCH_REFERENCE::GetRef(), SCH_REFERENCE::GetRefNumber(), group, INDETERMINATE_STATE, m_dataStore, m_fieldNames, QUANTITY_COLUMN, r, REFERENCE_FIELD, SCH_REFERENCE_LIST::Shorthand(), and StrNumCmp().

◆ groupMatch()

bool FIELDS_EDITOR_GRID_DATA_MODEL::groupMatch ( const SCH_REFERENCE lhRef,
const SCH_REFERENCE rhRef,
wxDataViewListCtrl *  fieldsCtrl 
)
inline

Definition at line 412 of file dialog_symbol_fields_table.cpp.

414  {
415  bool matchFound = false;
416 
417  // First check the reference column. This can be done directly out of the
418  // SCH_REFERENCEs as the references can't be edited in the grid.
419  if( fieldsCtrl->GetToggleValue( REFERENCE_FIELD, GROUP_BY_COLUMN ) )
420  {
421  // if we're grouping by reference, then only the prefix must match
422  if( lhRef.GetRef() != rhRef.GetRef() )
423  return false;
424 
425  matchFound = true;
426  }
427 
428  const KIID& lhRefID = lhRef.GetSymbol()->m_Uuid;
429  const KIID& rhRefID = rhRef.GetSymbol()->m_Uuid;
430 
431  // Now check all the other columns. This must be done out of the dataStore
432  // for the refresh button to work after editing.
433  for( int i = REFERENCE_FIELD + 1; i < fieldsCtrl->GetItemCount(); ++i )
434  {
435  if( !fieldsCtrl->GetToggleValue( i, GROUP_BY_COLUMN ) )
436  continue;
437 
438  wxString fieldName = fieldsCtrl->GetTextValue( i, CANONICAL_NAME_COLUMN );
439 
440  if( m_dataStore[ lhRefID ][ fieldName ] != m_dataStore[ rhRefID ][ fieldName ] )
441  return false;
442 
443  matchFound = true;
444  }
445 
446  return matchFound;
447  }
Field Reference of part, i.e. "IC21".
std::map< KIID, std::map< wxString, wxString > > m_dataStore
SCH_SYMBOL * GetSymbol() const
wxString GetRef() const
Definition: kiid.h:44
#define CANONICAL_NAME_COLUMN
#define GROUP_BY_COLUMN
const KIID m_Uuid
Definition: eda_item.h:475

References CANONICAL_NAME_COLUMN, SCH_REFERENCE::GetRef(), SCH_REFERENCE::GetSymbol(), GROUP_BY_COLUMN, m_dataStore, EDA_ITEM::m_Uuid, and REFERENCE_FIELD.

Referenced by RebuildRows().

◆ IsEdited()

bool FIELDS_EDITOR_GRID_DATA_MODEL::IsEdited ( )
inline

Definition at line 668 of file dialog_symbol_fields_table.cpp.

669  {
670  return m_edited;
671  }

References m_edited.

Referenced by DIALOG_SYMBOL_FIELDS_TABLE::OnClose().

◆ IsEmptyCell()

bool FIELDS_EDITOR_GRID_DATA_MODEL::IsEmptyCell ( int  aRow,
int  aCol 
)
inlineoverride

Definition at line 239 of file dialog_symbol_fields_table.cpp.

240  {
241  return false; // don't allow adjacent cell overflow, even if we are actually empty
242  }

◆ RebuildRows()

void FIELDS_EDITOR_GRID_DATA_MODEL::RebuildRows ( wxCheckBox *  aGroupSymbolsBox,
wxDataViewListCtrl *  aFieldsCtrl 
)
inline

Definition at line 449 of file dialog_symbol_fields_table.cpp.

450  {
451  if ( GetView() )
452  {
453  // Commit any pending in-place edits before the row gets moved out from under
454  // the editor.
455  static_cast<WX_GRID*>( GetView() )->CommitPendingChanges( true );
456 
457  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_rows.size() );
458  GetView()->ProcessTableMessage( msg );
459  }
460 
461  m_rows.clear();
462 
463  for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i )
464  {
465  SCH_REFERENCE ref = m_symbolsList[ i ];
466  bool matchFound = false;
467 
468  // See if we already have a row which this symbol fits into
469  for( DATA_MODEL_ROW& row : m_rows )
470  {
471  // all group members must have identical refs so just use the first one
472  SCH_REFERENCE rowRef = row.m_Refs[ 0 ];
473 
474  if( unitMatch( ref, rowRef ) )
475  {
476  matchFound = true;
477  row.m_Refs.push_back( ref );
478  break;
479  }
480  else if ( aGroupSymbolsBox->GetValue() && groupMatch( ref, rowRef, aFieldsCtrl ) )
481  {
482  matchFound = true;
483  row.m_Refs.push_back( ref );
484  row.m_Flag = GROUP_COLLAPSED;
485  break;
486  }
487  }
488 
489  if( !matchFound )
490  m_rows.emplace_back( DATA_MODEL_ROW( ref, GROUP_SINGLETON ) );
491  }
492 
493  if ( GetView() )
494  {
495  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rows.size() );
496  GetView()->ProcessTableMessage( msg );
497  }
498  }
size_t GetCount() const
bool unitMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef)
bool groupMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef, wxDataViewListCtrl *fieldsCtrl)
std::vector< DATA_MODEL_ROW > m_rows
A helper to define a symbol's reference designator in a schematic.

References SCH_REFERENCE_LIST::GetCount(), GROUP_COLLAPSED, GROUP_SINGLETON, groupMatch(), m_rows, m_symbolsList, and unitMatch().

Referenced by DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE(), DIALOG_SYMBOL_FIELDS_TABLE::OnColumnItemToggled(), DIALOG_SYMBOL_FIELDS_TABLE::OnGroupSymbolsToggled(), and DIALOG_SYMBOL_FIELDS_TABLE::OnRegroupSymbols().

◆ SetValue()

void FIELDS_EDITOR_GRID_DATA_MODEL::SetValue ( int  aRow,
int  aCol,
const wxString &  aValue 
)
inlineoverride

Definition at line 333 of file dialog_symbol_fields_table.cpp.

334  {
335  if( aCol == REFERENCE_FIELD || aCol == QUANTITY_COLUMN )
336  return; // Can't modify references or quantity
337 
338  DATA_MODEL_ROW& rowGroup = m_rows[ aRow ];
339  wxString fieldName = m_fieldNames[ aCol ];
340 
341  for( const auto& ref : rowGroup.m_Refs )
342  m_dataStore[ ref.GetSymbol()->m_Uuid ][ fieldName ] = aValue;
343 
344  m_edited = true;
345  }
Field Reference of part, i.e. "IC21".
std::vector< SCH_REFERENCE > m_Refs
std::map< KIID, std::map< wxString, wxString > > m_dataStore
#define QUANTITY_COLUMN
std::vector< DATA_MODEL_ROW > m_rows

References m_dataStore, m_edited, m_fieldNames, DATA_MODEL_ROW::m_Refs, m_rows, QUANTITY_COLUMN, and REFERENCE_FIELD.

◆ Sort()

void FIELDS_EDITOR_GRID_DATA_MODEL::Sort ( int  aColumn,
bool  ascending 
)
inline

Definition at line 384 of file dialog_symbol_fields_table.cpp.

385  {
386  if( aColumn < 0 )
387  aColumn = 0;
388 
389  m_sortColumn = aColumn;
390  m_sortAscending = ascending;
391 
392  CollapseForSort();
393 
394  std::sort( m_rows.begin(), m_rows.end(),
395  [ this ]( const DATA_MODEL_ROW& lhs, const DATA_MODEL_ROW& rhs ) -> bool
396  {
397  return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
398  } );
399 
400  ExpandAfterSort();
401  }
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

References cmp(), CollapseForSort(), ExpandAfterSort(), m_rows, m_sortAscending, and m_sortColumn.

Referenced by DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE(), DIALOG_SYMBOL_FIELDS_TABLE::OnColSort(), DIALOG_SYMBOL_FIELDS_TABLE::OnColumnItemToggled(), DIALOG_SYMBOL_FIELDS_TABLE::OnGroupSymbolsToggled(), and DIALOG_SYMBOL_FIELDS_TABLE::OnRegroupSymbols().

◆ unitMatch()

bool FIELDS_EDITOR_GRID_DATA_MODEL::unitMatch ( const SCH_REFERENCE lhRef,
const SCH_REFERENCE rhRef 
)
inline

Definition at line 403 of file dialog_symbol_fields_table.cpp.

404  {
405  // If items are unannotated then we can't tell if they're units of the same symbol or not
406  if( lhRef.GetRefNumber() == wxT( "?" ) )
407  return false;
408 
409  return ( lhRef.GetRef() == rhRef.GetRef() && lhRef.GetRefNumber() == rhRef.GetRefNumber() );
410  }
wxString GetRefNumber() const
wxString GetRef() const

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

Referenced by ExpandRow(), and RebuildRows().

Member Data Documentation

◆ m_dataStore

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

◆ m_edited

bool FIELDS_EDITOR_GRID_DATA_MODEL::m_edited
protected

Definition at line 174 of file dialog_symbol_fields_table.cpp.

Referenced by ApplyData(), IsEdited(), and SetValue().

◆ m_fieldNames

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

◆ m_frame

SCH_EDIT_FRAME* FIELDS_EDITOR_GRID_DATA_MODEL::m_frame
protected

Definition at line 172 of file dialog_symbol_fields_table.cpp.

Referenced by AddColumn(), and ApplyData().

◆ m_rows

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

◆ m_sortAscending

bool FIELDS_EDITOR_GRID_DATA_MODEL::m_sortAscending
protected

Definition at line 177 of file dialog_symbol_fields_table.cpp.

Referenced by ExpandRow(), and Sort().

◆ m_sortColumn

int FIELDS_EDITOR_GRID_DATA_MODEL::m_sortColumn
protected

Definition at line 176 of file dialog_symbol_fields_table.cpp.

Referenced by ExpandRow(), and Sort().

◆ m_symbolsList

SCH_REFERENCE_LIST FIELDS_EDITOR_GRID_DATA_MODEL::m_symbolsList
protected

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