22 m_cols.push_back( { aFieldName, aLabel, aAddedByUser,
false,
false } );
31 const wxString& aFieldName )
69 m_cols[aCol].m_fieldName = newName;
75 for(
size_t i = 0; i <
m_cols.size(); i++ )
77 if(
m_cols[i].m_fieldName == aFieldName )
87 std::vector<BOM_FIELD> fields;
90 fields.push_back( { col.m_fieldName, col.m_label, col.m_show, col.m_group } );
98 size_t foundCount = 0;
100 for(
const wxString& newField : aNewOrder )
102 for(
size_t i = 0; i <
m_cols.size(); i++ )
104 if(
m_cols[i].m_fieldName == newField )
136 const wxString& refDelimiter,
137 const wxString& refRangeDelimiter,
140 std::vector<SCH_REFERENCE> references;
147 references.push_back( ref );
159 wxString refFieldValue;
166 if( &ref == &
group.m_Refs.front() )
167 fieldValue = refFieldValue;
168 else if( fieldValue != refFieldValue )
176 std::sort( references.begin(), references.end(),
179 wxString l_ref( l.GetRef() << l.GetRefNumber() );
180 wxString r_ref( r.GetRef() << r.GetRefNumber() );
181 return StrNumCmp( l_ref, r_ref, true ) < 0;
184 auto logicalEnd = std::unique( references.begin(), references.end(),
189 if( l.GetRefNumber() == wxT(
"?" ) )
192 wxString l_ref( l.GetRef() << l.GetRefNumber() );
193 wxString r_ref( r.GetRef() << r.GetRefNumber() );
194 return l_ref == r_ref;
197 references.erase( logicalEnd, references.end() );
203 fieldValue = wxString::Format( wxT(
"%d" ), (
int) references.size() );
205 fieldValue = wxString::Format( wxT(
"%d" ),
group.m_ItemNumber );
213 wxCHECK_RET( aCol >= 0 && aCol < (
int)
m_cols.size(), wxS(
"Invalid column number" ) );
233 wxCHECK( aCol >= 0 && aCol < (
int)
m_cols.size(),
false );
239 wxCHECK( aCol >= 0 && aCol < (
int)
m_cols.size(),
false );
245 wxCHECK( aCol >= 0 && aCol < (
int)
m_cols.size(),
false );
251 wxCHECK( aCol >= 0 && aCol < (
int)
m_cols.size(),
false );
257 wxCHECK( aCol >= 0 && aCol < (
int)
m_cols.size(),
false );
268 if( lhGroup.
m_Refs.size() == 0 )
270 else if( rhGroup.
m_Refs.size() == 0 )
276 [ ascending ](
const auto a,
const auto b )
291 wxString lhRef = lhGroup.
m_Refs[0].GetRef() + lhGroup.
m_Refs[0].GetRefNumber();
292 wxString rhRef = rhGroup.
m_Refs[0].GetRef() + rhGroup.
m_Refs[0].GetRefNumber();
293 return local_cmp(
StrNumCmp( lhRef, rhRef,
true ), 0 );
310 std::sort( row.m_Refs.begin(), row.m_Refs.end(),
313 wxString lhs_ref( lhs.GetRef() << lhs.GetRefNumber() );
314 wxString rhs_ref( rhs.GetRef() << rhs.GetRefNumber() );
315 return StrNumCmp( lhs_ref, rhs_ref, true ) < 0;
322 return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
329 row.m_ItemNumber = itemNumber++;
351 bool matchFound =
false;
358 if(
m_cols[refCol].m_group )
369 for(
size_t i = 0; i <
m_cols.size(); ++i )
372 if( (
int) i == refCol )
392 const wxString& aFieldName )
406 std::function<bool( wxString* )> symbolResolver =
407 [&]( wxString* token ) ->
bool
415 return wxEmptyString;
421 return aFieldName == wxS(
"${DNP}" )
422 || aFieldName == wxS(
"${EXCLUDE_FROM_BOARD}" )
423 || aFieldName == wxS(
"${EXCLUDE_FROM_BOM}" )
424 || aFieldName == wxS(
"${EXCLUDE_FROM_SIM}" );
429 const wxString& aAttributeName )
431 if( aAttributeName == wxS(
"${DNP}" ) )
432 return aSymbol.
GetDNP() ? wxS(
"1" ) : wxS(
"0" );
434 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
437 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
440 if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
447 const wxString& aAttributeName,
448 const wxString& aValue )
450 if( aAttributeName == wxS(
"${DNP}" ) )
451 aSymbol.
SetDNP( aValue == wxS(
"1" ) );
452 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
454 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
456 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
482 static_cast<WX_GRID*
>( GetView() )->CommitPendingChanges(
true );
484 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0,
m_rows.size() );
485 GetView()->ProcessTableMessage( msg );
506 || (
m_scope == SCOPE::SCOPE_SHEET_RECURSIVE
512 bool matchFound =
false;
530 row.m_Refs.push_back( ref );
536 row.m_Refs.push_back( ref );
548 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_rows.size() );
549 GetView()->ProcessTableMessage( msg );
557 std::vector<DATA_MODEL_ROW> children;
561 bool matchFound =
false;
571 child.m_Refs.push_back( ref );
580 if( children.size() < 2 )
583 std::sort( children.begin(), children.end(),
586 return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
590 m_rows.insert(
m_rows.begin() + aRow + 1, children.begin(), children.end() );
592 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, aRow, children.size() );
593 GetView()->ProcessTableMessage( msg );
598 auto firstChild =
m_rows.begin() + aRow + 1;
599 auto afterLastChild = firstChild;
602 while( afterLastChild !=
m_rows.end() && afterLastChild->m_Flag ==
CHILD_ITEM )
609 m_rows.erase( firstChild, afterLastChild );
611 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow + 1, deleted );
612 GetView()->ProcessTableMessage( msg );
629 for(
size_t i = 0; i <
m_rows.size(); ++i )
642 for(
size_t i = 0; i <
m_rows.size(); ++i )
657 symbolChangeHandler( symbol,
m_symbolsList[i].GetSheetPath() );
661 for(
const std::pair<wxString, wxString> srcData : fieldStore )
663 const wxString& srcName = srcData.first;
664 const wxString& srcValue = srcData.second;
680 bool userAdded = ( col != -1 &&
m_cols[col].m_userAdded );
683 bool createField = !destField && ( !srcValue.IsEmpty() || userAdded );
701 if( !srcValue.IsEmpty() )
710 destField->
SetText( srcValue );
716 if( fieldStore.count( symbol.
GetFields()[ii].GetName() ) == 0 )
753 for(
size_t i = 0; i <
m_cols.size(); i++ )
759 std::vector<wxString> order;
764 order.emplace_back( field.
name );
828 for(
size_t col = 0; col <
m_cols.size(); col++ )
831 last_col = (int) col;
838 auto formatField = [&]( wxString field,
bool last ) -> wxString
842 field.Replace( wxS(
"\r" ), wxS(
"" ) );
843 field.Replace( wxS(
"\n" ), wxS(
"" ) );
848 field.Replace( wxS(
"\t" ), wxS(
"" ) );
860 for(
size_t col = 0; col <
m_cols.size(); col++ )
865 out.Append( formatField(
m_cols[col].m_label, col == (
size_t) last_col ) );
869 for(
size_t row = 0; row <
m_rows.size(); row++ )
875 for(
size_t col = 0; col <
m_cols.size(); col++ )
883 col == (
size_t) last_col ) );
900 for(
const SCH_FIELD& field : ref.GetSymbol()->GetFields() )
901 m_dataStore[ref.GetSymbol()->m_Uuid][field.GetCanonicalName()] = field.GetText();
918 return ref.GetSymbol()->m_Uuid == aSymbol.m_Uuid;
935 if( ref.GetSymbol()->GetInstanceReferences().empty() )
wxString GetColFieldName(int aCol)
std::vector< DATA_MODEL_ROW > m_rows
int GetFieldNameCol(wxString aFieldName)
void ApplyBomPreset(const BOM_PRESET &preset)
void SetFieldsOrder(const std::vector< wxString > &aNewOrder)
SCH_REFERENCE_LIST m_symbolsList
void SetGroupingEnabled(bool group)
wxString getAttributeValue(const SCH_SYMBOL &, const wxString &aAttributeName)
bool ColIsItemNumber(int aCol)
bool ColIsQuantity(int aCol)
void updateDataStoreSymbolField(const SCH_SYMBOL &aSymbol, const wxString &aFieldName)
bool groupMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef)
BOM_PRESET GetBomSettings()
bool unitMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef)
bool ColIsReference(int aCol)
wxString GetExportValue(int aRow, int aCol, const wxString &refDelimiter, const wxString &refRangeDelimiter)
bool GetGroupingEnabled()
int GetNumberRows() override
void CollapseRow(int aRow)
wxString getFieldShownText(const SCH_REFERENCE &aRef, const wxString &aFieldName)
void RenameColumn(int aCol, const wxString &newName)
wxString Export(const BOM_FMT_PRESET &settings)
void AddColumn(const wxString &aFieldName, const wxString &aLabel, bool aAddedByUser)
std::vector< DATA_MODEL_COL > m_cols
void SetSorting(int aCol, bool ascending)
void ExpandCollapseRow(int aRow)
void SetFilter(const wxString &aFilter)
static bool cmp(const DATA_MODEL_ROW &lhGroup, const DATA_MODEL_ROW &rhGroup, FIELDS_EDITOR_GRID_DATA_MODEL *dataModel, int sortCol, bool ascending)
static const wxString ITEM_NUMBER_VARIABLE
bool isAttribute(const wxString &aFieldName)
wxString GetValue(int aRow, int aCol) override
int GetDataWidth(int aCol)
void UpdateReferences(const SCH_REFERENCE_LIST &aRefs)
void ApplyData(std::function< void(SCH_SYMBOL &, SCH_SHEET_PATH &)> symbolChangeHandler)
void RemoveColumn(int aCol)
GROUP_TYPE GetRowFlags(int aRow)
const wxString & GetFilter()
std::map< KIID, std::map< wxString, wxString > > m_dataStore
static const wxString QUANTITY_VARIABLE
bool ColIsValue(int aCol)
void SetGroupColumn(int aCol, bool group)
void SetExcludeDNP(bool exclude)
void RemoveSymbol(const SCH_SYMBOL &aSymbol)
void SetValue(int aRow, int aCol, const wxString &aValue) override
bool ColIsAttribute(int aCol)
void SetColLabelValue(int aCol, const wxString &aLabel) override
void RemoveReferences(const SCH_REFERENCE_LIST &aRefs)
void SetShowColumn(int aCol, bool show)
void setAttributeValue(SCH_SYMBOL &aSymbol, const wxString &aAttributeName, const wxString &aValue)
void AddReferences(const SCH_REFERENCE_LIST &aRefs)
const std::vector< BOM_FIELD > GetFieldsOrdered()
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
void SetText(const wxString &aText) override
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
bool Contains(const SCH_REFERENCE &aItem) const
Return true if aItem exists in this list.
iterator erase(iterator position)
static wxString Shorthand(std::vector< SCH_REFERENCE > aList, const wxString &refDelimiter, const wxString &refRangeDelimiter)
Return a shorthand string representing all the references in the list.
int FindRefByFullPath(const wxString &aFullPath) const
Search the list for a symbol with the given KIID path (as string).
void AddItem(const SCH_REFERENCE &aItem)
void RemoveItem(unsigned int aIndex)
Remove an item from the list of references.
A helper to define a symbol's reference designator in a schematic.
const SCH_SHEET_PATH & GetSheetPath() const
wxString GetFullRef() const
SCH_SYMBOL * GetSymbol() const
wxString GetRefNumber() const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
SCH_FIELD * GetFieldByName(const wxString &aFieldName)
Return a field in this symbol.
void SetValueFieldText(const wxString &aValue)
SCH_FIELD * FindField(const wxString &aFieldName, bool aIncludeDefaultFields=true, bool aCaseInsensitive=false)
Search for a SCH_FIELD with aFieldName.
void SetExcludedFromSim(bool aExclude) override
void SetFootprintFieldText(const wxString &aFootprint)
bool GetExcludedFromBOM() const
VECTOR2I GetPosition() const override
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
bool GetExcludedFromSim() const override
void SetExcludedFromBOM(bool aIncludeInBOM)
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
bool GetExcludedFromBoard() const
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
void SetExcludedFromBoard(bool aIncludeOnBoard)
bool IsTextVar(const wxString &aSource)
Returns true if the string is a text var, e.g starts with ${.
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
@ GROUP_COLLAPSED_DURING_SORT
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...
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
bool WildCompareString(const wxString &pattern, const wxString &string_to_tst, bool case_sensitive)
Compare a string against wild card (* and ?) pattern using the usual rules.
int ValueStringCompare(const wxString &strFWord, const wxString &strSWord)
Compare strings like the strcmp function but handle numbers and modifiers within the string text corr...
wxString refRangeDelimiter
std::vector< BOM_FIELD > fieldsOrdered
std::vector< SCH_REFERENCE > m_Refs
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...