44 m_cols.push_back( { aFieldName, aLabel, aAddedByUser,
false,
false } );
55 const wxString& aFieldName )
63 if( field->IsPrivate() )
106 node.key() = newName;
111 m_cols[aCol].m_fieldName = newName;
112 m_cols[aCol].m_label = newName;
118 for(
size_t i = 0; i <
m_cols.size(); i++ )
120 if(
m_cols[i].m_fieldName == aFieldName )
121 return static_cast<int>( i );
130 std::vector<BOM_FIELD> fields;
133 fields.push_back( { col.m_fieldName, col.m_label, col.m_show, col.m_group } );
141 size_t foundCount = 0;
143 for(
const wxString& newField : aNewOrder )
145 if( foundCount >=
m_cols.size() )
150 if( col.m_fieldName == newField )
152 std::swap(
m_cols[foundCount], col );
183 wxGridCellAttr::wxAttrKind aKind )
206 const wxString& refDelimiter,
207 const wxString& refRangeDelimiter,
209 bool listMixedValues )
211 std::vector<SCH_REFERENCE> references;
212 std::set<wxString> mixedValues;
219 references.push_back( ref );
241 else if( refFieldValue.Contains( wxT(
"${" ) ) )
245 std::function<bool( wxString* )> symbolResolver =
246 [&]( wxString* token ) ->
bool
251 refFieldValue =
ExpandTextVars( refFieldValue, & symbolResolver );
255 if( listMixedValues )
256 mixedValues.insert( refFieldValue );
257 else if( &ref == &
group.m_Refs.front() )
258 fieldValue = refFieldValue;
259 else if( fieldValue != refFieldValue )
264 if( listMixedValues )
266 fieldValue = wxEmptyString;
268 for(
const wxString& value : mixedValues )
270 if( value.IsEmpty() )
272 else if( fieldValue.IsEmpty() )
275 fieldValue +=
"," + value;
282 std::sort( references.begin(), references.end(),
285 wxString l_ref( l.GetRef() << l.GetRefNumber() );
286 wxString r_ref( r.GetRef() << r.GetRefNumber() );
287 return StrNumCmp( l_ref, r_ref, true ) < 0;
290 auto logicalEnd = std::unique( references.begin(), references.end(),
295 if( l.GetRefNumber() == wxT(
"?" ) )
298 wxString l_ref( l.GetRef() << l.GetRefNumber() );
299 wxString r_ref( r.GetRef() << r.GetRefNumber() );
300 return l_ref == r_ref;
303 references.erase( logicalEnd, references.end() );
309 fieldValue = wxString::Format( wxT(
"%d" ), (
int) references.size() );
311 fieldValue = wxString::Format( wxT(
"%d" ),
group.m_ItemNumber );
319 wxCHECK_RET( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ), wxS(
"Invalid column number" ) );
339 wxCHECK( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ),
false );
346 wxCHECK( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ),
false );
353 wxCHECK( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ),
false );
360 wxCHECK( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ),
false );
367 wxCHECK( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ),
false );
378 if( lhGroup.
m_Refs.size() == 0 )
380 else if( rhGroup.
m_Refs.size() == 0 )
386 [ ascending ](
const auto a,
const auto b )
398 wxString lhs = dataModel->
GetValue( lhGroup, sortCol ).Trim(
true ).Trim(
false );
399 wxString rhs = dataModel->
GetValue( rhGroup, sortCol ).Trim(
true ).Trim(
false );
403 wxString lhRef = lhGroup.
m_Refs[0].GetRef() + lhGroup.
m_Refs[0].GetRefNumber();
404 wxString rhRef = rhGroup.
m_Refs[0].GetRef() + rhGroup.
m_Refs[0].GetRefNumber();
405 return local_cmp(
StrNumCmp( lhRef, rhRef,
true ), 0 );
422 std::sort( row.m_Refs.begin(), row.m_Refs.end(),
425 wxString lhs_ref( lhs.GetRef() << lhs.GetRefNumber() );
426 wxString rhs_ref( rhs.GetRef() << rhs.GetRefNumber() );
427 return StrNumCmp( lhs_ref, rhs_ref, true ) < 0;
434 return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
441 row.m_ItemNumber = itemNumber++;
464 bool matchFound =
false;
471 if(
m_cols[refCol].m_group )
484 for(
size_t i = 0; i <
m_cols.size(); ++i )
487 if(
static_cast<int>( i ) == refCol )
518 wxString fieldName =
m_cols[i].m_fieldName;
531 const wxString& aFieldName )
538 return wxEmptyString;
550 std::function<bool( wxString* )> symbolResolver =
551 [&]( wxString* token ) ->
bool
559 return wxEmptyString;
565 return aFieldName == wxS(
"${DNP}" )
566 || aFieldName == wxS(
"${EXCLUDE_FROM_BOARD}" )
567 || aFieldName == wxS(
"${EXCLUDE_FROM_BOM}" )
568 || aFieldName == wxS(
"${EXCLUDE_FROM_SIM}" );
573 const wxString& aAttributeName )
575 if( aAttributeName == wxS(
"${DNP}" ) )
576 return aSymbol.
GetDNP() ? wxS(
"1" ) : wxS(
"0" );
578 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
581 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
584 if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
591 const wxString& aAttributeName,
592 const wxString& aValue )
594 if( aAttributeName == wxS(
"${DNP}" ) )
595 aSymbol.
SetDNP( aValue == wxS(
"1" ) );
596 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
598 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
600 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
626 static_cast<WX_GRID*
>( GetView() )->CommitPendingChanges(
true );
628 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0,
m_rows.size() );
629 GetView()->ProcessTableMessage( msg );
658 || (
m_scope == SCOPE::SCOPE_SHEET_RECURSIVE
664 bool matchFound =
false;
682 row.m_Refs.push_back( ref );
688 row.m_Refs.push_back( ref );
700 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_rows.size() );
701 GetView()->ProcessTableMessage( msg );
710 std::vector<DATA_MODEL_ROW> children;
714 bool matchFound =
false;
724 child.m_Refs.push_back( ref );
733 if( children.size() < 2 )
736 std::sort( children.begin(), children.end(),
739 return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
743 m_rows.insert(
m_rows.begin() + aRow + 1, children.begin(), children.end() );
745 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, aRow, children.size() );
746 GetView()->ProcessTableMessage( msg );
752 auto firstChild =
m_rows.begin() + aRow + 1;
753 auto afterLastChild = firstChild;
756 while( afterLastChild !=
m_rows.end() && afterLastChild->m_Flag ==
CHILD_ITEM )
763 m_rows.erase( firstChild, afterLastChild );
765 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow + 1, deleted );
766 GetView()->ProcessTableMessage( msg );
783 for(
size_t i = 0; i <
m_rows.size(); ++i )
796 for(
size_t i = 0; i <
m_rows.size(); ++i )
811 aCommit.
Modify( &symbol, instance.GetSheetPath().LastScreen() );
815 for(
const auto& [srcName, srcValue] : fieldStore )
831 if( destField && destField->
IsPrivate() )
833 if( srcValue.IsEmpty() )
840 bool userAdded = ( col != -1 &&
m_cols[col].m_userAdded );
843 bool createField = !destField && ( !srcValue.IsEmpty() || userAdded );
851 destField->
SetVisible( srcTemplate->m_Visible );
861 if( destField->
GetId() == FIELD_T::REFERENCE )
870 for(
int ii =
static_cast<int>( symbol.
GetFields().size() ) - 1; ii >= 0; ii-- )
875 if( fieldStore.count( symbol.
GetFields()[ii].GetName() ) == 0 )
913 for(
size_t i = 0; i <
m_cols.size(); i++ )
919 std::set<wxString> seen;
920 std::vector<wxString> order;
926 if( !field.
name || seen.count( field.
name ) )
929 seen.insert( field.
name );
930 order.emplace_back( field.
name );
1000 for(
size_t col = 0; col <
m_cols.size(); col++ )
1003 last_col =
static_cast<int>( col );
1007 if( last_col == -1 )
1011 [&]( wxString field,
bool last ) -> wxString
1015 field.Replace( wxS(
"\r" ), wxS(
"" ) );
1016 field.Replace( wxS(
"\n" ), wxS(
"" ) );
1021 field.Replace( wxS(
"\t" ), wxS(
"" ) );
1035 for(
size_t col = 0; col <
m_cols.size(); col++ )
1037 if( !
m_cols[col].m_show )
1040 out.Append( formatField(
m_cols[col].m_label, col ==
static_cast<size_t>( last_col ) ) );
1044 for(
size_t row = 0; row <
m_rows.size(); row++ )
1050 for(
size_t col = 0; col <
m_cols.size(); col++ )
1052 if( !
m_cols[col].m_show )
1056 out.Append( formatField(
GetExportValue(
static_cast<int>( row ),
static_cast<int>( col ),
1058 col ==
static_cast<size_t>( last_col ) ) );
1079 if( !field.IsPrivate() )
1081 wxString
name = field.GetCanonicalName();
1103 return ref.GetSymbol()->m_Uuid == aSymbol.m_Uuid;
1120 if( ref.GetSymbol()->GetInstances().empty() )
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
bool Find(const wxString &aTerm, int &aMatchersTriggered, int &aPosition)
Look in all existing matchers, return the earliest match of any of the existing.
const EDA_ANGLE & GetTextAngle() const
void SetTextPos(const VECTOR2I &aPoint)
virtual void SetVisible(bool aVisible)
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
int GetFieldNameCol(const wxString &aFieldName) const
wxString GetColFieldName(int aCol)
std::vector< DATA_MODEL_ROW > m_rows
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)
int GetNumberCols() override
bool ColIsQuantity(int aCol)
void updateDataStoreSymbolField(const SCH_SYMBOL &aSymbol, const wxString &aFieldName)
bool groupMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef)
wxGridCellAttr * m_urlEditor
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)
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind) override
void SetFilter(const wxString &aFilter)
std::map< int, wxGridCellAttr * > m_colAttrs
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
void ApplyData(SCH_COMMIT &aCommit, TEMPLATES &aTemplateFieldnames)
void SetIncludeExcludedFromBOM(bool include)
bool isAttribute(const wxString &aFieldName)
wxString GetValue(int aRow, int aCol) override
int GetDataWidth(int aCol)
void UpdateReferences(const SCH_REFERENCE_LIST &aRefs)
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)
std::vector< BOM_FIELD > GetFieldsOrdered()
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)
bool GetIncludeExcludedFromBOM()
void SetShowColumn(int aCol, bool show)
void setAttributeValue(SCH_SYMBOL &aSymbol, const wxString &aAttributeName, const wxString &aValue)
void AddReferences(const SCH_REFERENCE_LIST &aRefs)
wxString ConvertKIIDsToRefs(const wxString &aSource) const
wxString ConvertRefsToKIIDs(const wxString &aSource) const
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
void SetText(const wxString &aText) override
void SetPrivate(bool aPrivate)
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
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
SCH_SYMBOL * GetSymbol() const
wxString GetFullRef(bool aIncludeUnit=true) const
Return reference name with unit altogether.
wxString GetRefNumber() const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool GetExcludedFromBOM() const
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
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.
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
void SetExcludedFromBoard(bool aExcludeFromBoard) override
Set or clear exclude from board netlist flag.
void SetDNP(bool aDNP) override
void SetExcludedFromSim(bool aExcludeFromSim) override
Set or clear the exclude from simulation flag.
bool GetExcludedFromBoard() const override
void SetExcludedFromBOM(bool aExcludeFromBOM) override
Set or clear the exclude from schematic bill of materials flag.
bool GetDNP() const override
Set or clear the 'Do Not Populate' flag.
bool GetExcludedFromBOM() const override
bool GetExcludedFromSim() const override
const TEMPLATE_FIELDNAME * GetFieldName(const wxString &aName)
Search for aName in the template field name list.
wxGridCellAttr * enhanceAttr(wxGridCellAttr *aInputAttr, int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind)
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
bool IsGeneratedField(const wxString &aSource)
Returns true if the string is generated, e.g contains a single text var reference.
@ GROUP_COLLAPSED_DURING_SORT
KICOMMON_API 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.
int ValueStringCompare(const wxString &strFWord, const wxString &strSWord)
Compare strings like the strcmp function but handle numbers and modifiers within the string text corr...
bool IsURL(wxString aStr)
Performs a URL sniff-test on a string.
wxString refRangeDelimiter
std::vector< BOM_FIELD > fieldsOrdered
bool includeExcludedFromBOM
std::vector< SCH_REFERENCE > m_Refs
Hold a name of a symbol's field, field value, and default visibility.
wxString GetCanonicalFieldName(FIELD_T aFieldType)
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...