43 m_cols.push_back( { aFieldName, aLabel, aAddedByUser,
false,
false } );
54 const wxString& aFieldName )
62 if( field->IsPrivate() )
101 node.key() = newName;
106 m_cols[aCol].m_fieldName = newName;
107 m_cols[aCol].m_label = newName;
113 for(
size_t i = 0; i <
m_cols.size(); i++ )
115 if(
m_cols[i].m_fieldName == aFieldName )
125 std::vector<BOM_FIELD> fields;
128 fields.push_back( { col.m_fieldName, col.m_label, col.m_show, col.m_group } );
136 size_t foundCount = 0;
138 for(
const wxString& newField : aNewOrder )
140 for(
size_t i = 0; i <
m_cols.size(); i++ )
142 if(
m_cols[i].m_fieldName == newField )
174 const wxString& refDelimiter,
175 const wxString& refRangeDelimiter,
177 bool listMixedValues )
179 std::vector<SCH_REFERENCE> references;
180 std::set<wxString> mixedValues;
187 references.push_back( ref );
199 wxString refFieldValue;
214 if( listMixedValues )
215 mixedValues.insert( refFieldValue );
216 else if( &ref == &
group.m_Refs.front() )
217 fieldValue = refFieldValue;
218 else if( fieldValue != refFieldValue )
223 if( listMixedValues )
225 fieldValue = wxEmptyString;
227 for(
const wxString& value : mixedValues )
229 if( value.IsEmpty() )
231 else if( fieldValue.IsEmpty() )
234 fieldValue +=
"," + value;
241 std::sort( references.begin(), references.end(),
244 wxString l_ref( l.GetRef() << l.GetRefNumber() );
245 wxString r_ref( r.GetRef() << r.GetRefNumber() );
246 return StrNumCmp( l_ref, r_ref, true ) < 0;
249 auto logicalEnd = std::unique( references.begin(), references.end(),
254 if( l.GetRefNumber() == wxT(
"?" ) )
257 wxString l_ref( l.GetRef() << l.GetRefNumber() );
258 wxString r_ref( r.GetRef() << r.GetRefNumber() );
259 return l_ref == r_ref;
262 references.erase( logicalEnd, references.end() );
268 fieldValue = wxString::Format( wxT(
"%d" ), (
int) references.size() );
270 fieldValue = wxString::Format( wxT(
"%d" ),
group.m_ItemNumber );
278 wxCHECK_RET( aCol >= 0 && aCol < (
int)
m_cols.size(), wxS(
"Invalid column number" ) );
298 wxCHECK( aCol >= 0 && aCol < (
int)
m_cols.size(),
false );
305 wxCHECK( aCol >= 0 && aCol < (
int)
m_cols.size(),
false );
312 wxCHECK( aCol >= 0 && aCol < (
int)
m_cols.size(),
false );
319 wxCHECK( aCol >= 0 && aCol < (
int)
m_cols.size(),
false );
326 wxCHECK( aCol >= 0 && aCol < (
int)
m_cols.size(),
false );
337 if( lhGroup.
m_Refs.size() == 0 )
339 else if( rhGroup.
m_Refs.size() == 0 )
345 [ ascending ](
const auto a,
const auto b )
355 wxString lhs = dataModel->
GetValue( lhGroup, sortCol ).Trim(
true ).Trim(
false );
356 wxString rhs = dataModel->
GetValue( rhGroup, sortCol ).Trim(
true ).Trim(
false );
360 wxString lhRef = lhGroup.
m_Refs[0].GetRef() + lhGroup.
m_Refs[0].GetRefNumber();
361 wxString rhRef = rhGroup.
m_Refs[0].GetRef() + rhGroup.
m_Refs[0].GetRefNumber();
362 return local_cmp(
StrNumCmp( lhRef, rhRef,
true ), 0 );
379 std::sort( row.m_Refs.begin(), row.m_Refs.end(),
382 wxString lhs_ref( lhs.GetRef() << lhs.GetRefNumber() );
383 wxString rhs_ref( rhs.GetRef() << rhs.GetRefNumber() );
384 return StrNumCmp( lhs_ref, rhs_ref, true ) < 0;
391 return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
398 row.m_ItemNumber = itemNumber++;
421 bool matchFound =
false;
428 if(
m_cols[refCol].m_group )
441 for(
size_t i = 0; i <
m_cols.size(); ++i )
444 if( (
int) i == refCol )
476 wxString fieldName =
m_cols[i].m_fieldName;
489 const wxString& aFieldName )
496 return wxEmptyString;
508 std::function<bool( wxString* )> symbolResolver =
509 [&]( wxString* token ) ->
bool
517 return wxEmptyString;
523 return aFieldName == wxS(
"${DNP}" )
524 || aFieldName == wxS(
"${EXCLUDE_FROM_BOARD}" )
525 || aFieldName == wxS(
"${EXCLUDE_FROM_BOM}" )
526 || aFieldName == wxS(
"${EXCLUDE_FROM_SIM}" );
531 const wxString& aAttributeName )
533 if( aAttributeName == wxS(
"${DNP}" ) )
534 return aSymbol.
GetDNP() ? wxS(
"1" ) : wxS(
"0" );
536 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
539 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
542 if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
549 const wxString& aAttributeName,
550 const wxString& aValue )
552 if( aAttributeName == wxS(
"${DNP}" ) )
553 aSymbol.
SetDNP( aValue == wxS(
"1" ) );
554 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
556 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
558 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
584 static_cast<WX_GRID*
>( GetView() )->CommitPendingChanges(
true );
586 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0,
m_rows.size() );
587 GetView()->ProcessTableMessage( msg );
614 || (
m_scope == SCOPE::SCOPE_SHEET_RECURSIVE
620 bool matchFound =
false;
638 row.m_Refs.push_back( ref );
644 row.m_Refs.push_back( ref );
656 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_rows.size() );
657 GetView()->ProcessTableMessage( msg );
666 std::vector<DATA_MODEL_ROW> children;
670 bool matchFound =
false;
680 child.m_Refs.push_back( ref );
689 if( children.size() < 2 )
692 std::sort( children.begin(), children.end(),
695 return cmp( lhs, rhs, this, m_sortColumn, m_sortAscending );
699 m_rows.insert(
m_rows.begin() + aRow + 1, children.begin(), children.end() );
701 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, aRow, children.size() );
702 GetView()->ProcessTableMessage( msg );
708 auto firstChild =
m_rows.begin() + aRow + 1;
709 auto afterLastChild = firstChild;
712 while( afterLastChild !=
m_rows.end() && afterLastChild->m_Flag ==
CHILD_ITEM )
719 m_rows.erase( firstChild, afterLastChild );
721 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow + 1, deleted );
722 GetView()->ProcessTableMessage( msg );
739 for(
size_t i = 0; i <
m_rows.size(); ++i )
752 for(
size_t i = 0; i <
m_rows.size(); ++i )
767 symbolChangeHandler( symbol,
m_symbolsList[i].GetSheetPath() );
771 for(
const std::pair<wxString, wxString> srcData : fieldStore )
773 const wxString& srcName = srcData.first;
774 const wxString& srcValue = srcData.second;
790 if( destField && destField->
IsPrivate() )
792 if( srcValue.IsEmpty() )
799 bool userAdded = ( col != -1 &&
m_cols[col].m_userAdded );
802 bool createField = !destField && ( !srcValue.IsEmpty() || userAdded );
820 if( !srcValue.IsEmpty() )
829 destField->
SetText( srcValue );
835 if( fieldStore.count( symbol.
GetFields()[ii].GetName() ) == 0 )
837 if( !symbol.
GetFields()[ii].IsPrivate() )
876 for(
size_t i = 0; i <
m_cols.size(); i++ )
882 std::vector<wxString> order;
891 order.emplace_back( field.
name );
956 for(
size_t col = 0; col <
m_cols.size(); col++ )
959 last_col = (int) col;
967 [&]( wxString field,
bool last ) -> wxString
971 field.Replace( wxS(
"\r" ), wxS(
"" ) );
972 field.Replace( wxS(
"\n" ), wxS(
"" ) );
977 field.Replace( wxS(
"\t" ), wxS(
"" ) );
989 for(
size_t col = 0; col <
m_cols.size(); col++ )
994 out.Append( formatField(
m_cols[col].m_label, col == (
size_t) last_col ) );
998 for(
size_t row = 0; row <
m_rows.size(); row++ )
1004 for(
size_t col = 0; col <
m_cols.size(); col++ )
1006 if( !
m_cols[col].m_show )
1012 col == (
size_t) last_col ) );
1029 for(
const SCH_FIELD& field : ref.GetSymbol()->GetFields() )
1031 if( !field.IsPrivate() )
1032 m_dataStore[ref.GetSymbol()->m_Uuid][field.GetCanonicalName()] = field.GetText();
1050 return ref.GetSymbol()->m_Uuid == aSymbol.m_Uuid;
1067 if( ref.GetSymbol()->GetInstances().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
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 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)
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)
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
void SetPrivate(bool aPrivate)
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 GetExcludedFromBOM() const
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 GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) override
Populate a std::vector with SCH_FIELDs.
void SetFootprintFieldText(const wxString &aFootprint)
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.
bool GetExcludedFromBoard() const
bool GetExcludedFromBOM() const
void SetExcludedFromSim(bool aExcludeFromSim) override
Set or clear the exclude from simulation flag.
bool GetDNP() const
Set or clear the 'Do Not Populate' flag.
void SetExcludedFromBOM(bool aExcludeFromBOM)
Set or clear the exclude from schematic bill of materials flag.
void SetExcludedFromBoard(bool aExcludeFromBoard)
Set or clear exclude from board netlist flag.
bool GetExcludedFromSim() const override
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
bool IsTextVar(const wxString &aSource)
Returns true if the string is a text var, e.g starts with ${.
@ 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.
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
bool includeExcludedFromBOM
std::vector< SCH_REFERENCE > m_Refs
wxString GetCanonicalFieldName(int idx)
@ 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, LIB_PART, and FOOTPRINT constru...
@ 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...