25#include <wx/settings.h>
60 wxGridCellAttr* attr =
nullptr;
63 bool needsVariantHighlight =
false;
65 wxColour highlightColor;
69 && aCol < (
int)
m_cols.size() )
71 const wxString& fieldName =
m_cols[aCol].m_fieldName;
84 wxString currentValue;
89 if( currentValue != defaultValue )
91 needsVariantHighlight =
true;
93 bool isPriority2 =
false;
101 && variantData->m_SymbolOverride
102 && !variantData->m_Fields.count( fieldName ) )
108 wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
109 bool isDark = ( bg.Red() + bg.Green() + bg.Blue() ) < 384;
129 if( !needsReadOnly && !needsUrlEditor && !needsVariantHighlight && !needsResolvedTextRenderer )
143 attr =
new wxGridCellAttr();
149 if( needsVariantHighlight )
150 attr->SetBackgroundColour( highlightColor );
152 if( needsResolvedTextRenderer )
161 wxCHECK_RET( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ), wxS(
"Invalid column number" ) );
170 const wxString& fieldName =
m_cols[aCol].m_fieldName;
172 std::set<const SCH_SYMBOL*> editedSymbols;
184 if( !editedSymbols.contains( ref.
GetSymbol() ) )
209 if( !editedSymbols.contains( ref.
GetSymbol() ) )
222 wxCHECK_RET( aRow >= 0 && aRow <
static_cast<int>(
m_rows.size() ), wxS(
"Invalid row number" ) );
223 wxCHECK_RET( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ), wxS(
"Invalid column number" ) );
228 const wxString& fieldName =
m_cols[aCol].m_fieldName;
229 std::set<const SCH_SYMBOL*> clearedSymbols;
232 clearedSymbols.insert( ref.GetSymbol() );
241 if( clearedSymbols.contains( ref.
GetSymbol() ) )
251 wxCHECK_RET( aRow >= 0 && aRow <
static_cast<int>(
m_rows.size() ), wxS(
"Invalid row number" ) );
253 std::set<const SCH_SYMBOL*> rowSymbols;
256 rowSymbols.insert( ref.GetSymbol() );
265 if( !revertAllPaths )
271 if( !rowSymbols.contains( ref.
GetSymbol() ) )
275 wxString storedValue;
279 if( liveFieldPresent != storedFieldPresent )
281 revertAllPaths =
true;
287 if( !revertAllPaths )
294 if( rowSymbols.contains( ref.
GetSymbol() ) )
314 const wxString& aFieldName,
323 std::vector<SCH_REFERENCE> items;
336 const wxString& aFieldName )
343 return wxEmptyString;
355 std::function<bool( wxString* )> symbolResolver =
356 [&]( wxString* token ) ->
bool
364 return wxEmptyString;
376 std::function<bool( wxString* )> symbolResolver =
377 [&]( wxString* token ) ->
bool
391 if( aFieldName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
399 const wxString& aAttributeName,
400 const wxString& aVariantName )
402 if( aAttributeName == wxS(
"${DNP}" ) )
403 return aRef.
GetSymbolDNP( aVariantName ) ? wxS(
"1" ) : wxS(
"0" );
405 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
408 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
411 if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
414 if( aAttributeName == wxS(
"${EXCLUDE_FROM_POS_FILES}" ) )
422 const wxString& aAttributeName )
const
426 if( aAttributeName == wxS(
"${DNP}" ) )
428 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
430 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
432 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
440 const wxString& aFieldName,
441 const wxString& aVariantName, wxString& aValue )
458 if( field->IsPrivate() )
477 const wxString& aFieldName )
486 const wxString& aAttributeName,
487 const wxString& aValue,
488 const wxString& aVariantName )
490 bool attrChanged =
false;
491 bool newValue = aValue == wxS(
"1" );
493 if( aAttributeName == wxS(
"${DNP}" ) )
495 attrChanged = aRef.
GetSymbolDNP( aVariantName ) != newValue;
500 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
507 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
514 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
521 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_POS_FILES}" ) )
542 static_cast<WX_GRID*
>( GetView() )->CommitPendingChanges(
true );
544 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0,
m_rows.size() );
545 GetView()->ProcessTableMessage( msg );
556 if(
m_scope == SCOPE::SCOPE_SELECTION
593 bool isExcluded =
false;
620 || (
m_scope == SCOPE::SCOPE_SHEET_RECURSIVE
626 bool matchFound =
false;
644 row.m_items.push_back( ref );
650 row.m_items.push_back( ref );
651 row.m_state = ROW_STATE::COLLAPSED;
662 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_rows.size() );
663 GetView()->ProcessTableMessage( msg );
671 const wxString& aVariantName )
673 bool symbolModified =
false;
674 std::unique_ptr<SCH_SYMBOL> symbolCopy;
685 symbolCopy = std::make_unique<SCH_SYMBOL>( *symbol );
689 for(
const auto& [srcName, srcValue] : fieldStore )
705 if( destField && destField->
IsPrivate() )
707 if( srcValue.IsEmpty() )
715 bool createField = !destField;
723 destField->
SetVisible( srcTemplate->m_Visible );
728 symbolModified =
true;
743 if( !createField && ( previousValue != srcValue ) )
744 symbolModified =
true;
747 for(
int ii =
static_cast<int>( symbol->
GetFields().size() ) - 1; ii >= 0; ii-- )
752 const wxString& existingName = symbol->
GetFields()[ii].GetName();
754 bool stillTracked = std::any_of( fieldStore.begin(), fieldStore.end(),
755 [&](
const auto&
kv )
757 return kv.first == existingName;
763 symbolModified =
true;
767 if( symbolModified && ( symbol != nextSymbol ) )
771 if( symbol != nextSymbol )
774 symbolCopy = std::make_unique<SCH_SYMBOL>( *nextSymbol );
776 symbolCopy.reset(
nullptr );
778 symbolModified =
false;
788 bool refListChanged =
false;
812 wxString existingValue;
821 value = existingValue;
838 refListChanged =
true;
856 std::vector<KIID_PATH> keysToRemove;
860 if( !key.empty() && ( key.back() == symbolUuid ) )
861 keysToRemove.push_back( key );
864 for(
const KIID_PATH& key : keysToRemove )
871 return ref.GetSymbol()->m_Uuid == aSymbol.m_Uuid;
894 bool refListChanged =
false;
895 std::set<SCH_SYMBOL*> updatedSymbols;
899 if( incomingRef.GetSymbol() )
900 updatedSymbols.insert( incomingRef.GetSymbol() );
909 *cachedRef = incomingRef;
914 refListChanged =
true;
927 if( !updatedSymbols.contains( ref.
GetSymbol() ) )
937 size_t curNumRows =
m_rows.size();
939 if( aPosition >= curNumRows )
941 wxFAIL_MSG( wxString::Format( wxT(
"Called SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL::DeleteRows(aPosition=%lu, "
942 "aNumRows=%lu)\nPosition value is invalid for present table with %lu rows" ),
943 (
unsigned long) aPosition, (
unsigned long) aNumRows,
944 (
unsigned long) curNumRows ) );
949 if( aNumRows > curNumRows - aPosition )
951 aNumRows = curNumRows - aPosition;
954 if( aNumRows >= curNumRows )
962 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aPosition, aNumRows );
963 GetView()->ProcessTableMessage( msg );
970 auto first =
m_rows.begin() + aPosition;
971 auto last = first + aNumRows;
974 for(
auto it = first; it != last && it !=
m_rows.end(); ++it )
991 std::vector<FIELD_CASE_CONFLICT> conflicts;
993 for(
unsigned i = 0; i < aSymbols.
GetCount(); ++i )
1000 std::map<wxString, std::vector<std::pair<wxString, wxString>>> groups;
1004 if( field.IsMandatory() || field.IsPrivate() )
1007 groups[field.GetName().Lower()].emplace_back( field.GetName(), field.GetText() );
1010 for(
const auto& [key, members] : groups )
1012 if( members.size() < 2 )
1017 c.
sheetPath = aSymbols[i].GetSheetPath();
1021 conflicts.push_back( std::move( c ) );
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
virtual void SetTextPos(const VECTOR2I &aPoint)
virtual void SetVisible(bool aVisible)
virtual EDA_ANGLE GetTextAngle() const
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
bool cellUsesResolvedTextRenderer(int aRow, int aCol)
bool cellUsesUrlEditor(int aRow, int aCol)
bool CanClearCell(int aRow, int aCol)
void applyResolvedTextRenderer(wxGridCellAttr *aAttr, bool aApplyTint)
bool ColIsReference(int aCol) const
wxGridCellAttr * cloneUrlEditorAttr()
bool ColIsQuantity(int aCol) const
virtual bool fieldIsAttribute(const wxString &aFieldName) const
wxGridCellAttr * applyCellDecorations(wxGridCellAttr *aAttr, int aRow, int aCol)
std::unordered_set< KIID_PATH > m_selectionItems
bool ColIsItemNumber(int aCol) const
std::vector< wxString > m_variantNames
std::vector< DATA_MODEL_COL > m_cols
wxString m_currentVariant
std::map< KIID_PATH, std::map< wxString, wxString > > m_dataStore
void RevertRow(int aRow) override
Go through and revert all the fields in the row to their live values from the item (symbol/footprint/...
bool groupMatch(const SCH_REFERENCE &lhItem, const SCH_REFERENCE &rhItem)
void ensureStoredFieldPresent(const SCH_REFERENCE &aItem, const wxString &aFieldName)
void setStoredFieldValue(const SCH_REFERENCE &aItem, const wxString &aFieldName, const wxString &aValue)
const std::map< wxString, wxString > & getStoredFields(const SCH_REFERENCE &aItem) const
void initializeDataStoreItem(const SCH_REFERENCE &aItem)
void clearStoredField(const SCH_REFERENCE &aItem, const wxString &aFieldName)
bool getStoredFieldValue(const SCH_REFERENCE &aItem, const wxString &aFieldName, wxString &aValue) const
std::vector< DATA_MODEL_ROW< SCH_REFERENCE > > m_rows
bool IsCellReadOnly(int aRow, int aCol) override
bool MatchesFilter(const SCH_REFERENCE &aItem, const wxString &aReference, EDA_COMBINED_MATCHER &aMatcher)
void updateDataStoreItemFieldFromLive(const SCH_REFERENCE &aItem, const wxString &aFieldName)
wxString ConvertKIIDsToRefs(const wxString &aSource) const
wxString ConvertRefsToKIIDs(const wxString &aSource) const
virtual const wxString & GetText() const override
Return the string associated with the text object.
wxString GetShownText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString, 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.
bool ResolveExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
bool ResolveDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void AddItem(const SCH_REFERENCE &aItem)
A helper to define a symbol's reference designator in a schematic.
void SetSymbolExcludedFromBoard(bool aEnable)
const SCH_SHEET_PATH & GetSheetPath() const
void SetSymbolExcludedFromBOM(bool aEnable, const wxString &aVariant=wxEmptyString)
bool GetSymbolExcludedFromBOM(const wxString &aVariant=wxEmptyString) const
bool GetSymbolDNP(const wxString &aVariant=wxEmptyString) const
SCH_SYMBOL * GetSymbol() const
bool GetSymbolExcludedFromPosFiles(const wxString &aVariant=wxEmptyString) const
void SetSymbolExcludedFromSim(bool aEnable, const wxString &aVariant=wxEmptyString)
bool GetSymbolExcludedFromBoard() const
wxString GetFullRef(bool aIncludeUnit=true) const
Return reference name with unit altogether.
bool GetSymbolExcludedFromSim(const wxString &aVariant=wxEmptyString) const
void SetSymbolExcludedFromPosFiles(bool aEnable, const wxString &aVariant=wxEmptyString)
wxString GetRefNumber() const
void SetSymbolDNP(bool aEnable, const wxString &aVariant=wxEmptyString)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool GetExcludedFromBOM() const
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
void RemoveField(const wxString &aFieldName)
Remove a user field from the symbol.
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.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
void RemoveReferences(const SCH_REFERENCE_LIST &aRefs)
wxString getAttributeValue(const SCH_REFERENCE &aRef, const wxString &aAttributeName, const wxString &aVariantNames)
bool attributeForcedOnBySheet(const SCH_REFERENCE &aRef, const wxString &aAttributeName) const override
Sheets can force all the symbols in them to have certain attributes on, like DNP.
wxString getFieldResolvedLiveValue(const SCH_REFERENCE &aRef, const wxString &aFieldName) override
Explicitly bypasses the data store's field values and retries them from the item's current field valu...
void UpdateReferences(const SCH_REFERENCE_LIST &aRefs)
bool getLiveFieldValueForVariant(const SCH_REFERENCE &aRef, const wxString &aFieldName, const wxString &aVariantName, wxString &aValue)
wxString getItemIdentifier(const SCH_REFERENCE &aItem) const override
bool setAttributeValue(SCH_REFERENCE &aRef, const wxString &aAttributeName, const wxString &aValue, const wxString &aVariantName=wxEmptyString)
Set the attribute value.
SCH_REFERENCE_LIST m_symbolsList
The flattened by hierarchy list of symbols.
void RemoveSymbol(const SCH_SYMBOL &aSymbol)
bool getLiveFieldValue(const SCH_REFERENCE &aRef, const wxString &aFieldName, wxString &aValue) override
Gets the current value of the field from the live item, e.g.
void RevertRow(int aRow) override
Go through and revert all the fields in the row to their live values from the item (symbol/footprint/...
void AddReferences(const SCH_REFERENCE_LIST &aRefs)
wxString resolveTextVars(const SCH_REFERENCE &aRef, const wxString &aText) override
bool unitMatch(const SCH_REFERENCE &lhItem, const SCH_REFERENCE &rhItem) override
void ClearCell(int aRow, int aCol) override
Clears the field from the data store, rather than setting its value to an empty string.
void SetValue(int aRow, int aCol, const wxString &aValue) override
void ApplyData(SCH_COMMIT &aCommit, TEMPLATES &aTemplateFieldnames, const wxString &aVariantName)
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind) override
KIID_PATH getDataStoreKey(const SCH_REFERENCE &aItem) const override
Create a unique key for the data store by combining the KIID_PATH from the SCH_SHEET_PATH with the sy...
void RebuildRows() override
wxString getDefaultFieldValue(const SCH_REFERENCE &aRef, const wxString &aFieldName)
Get the default (non-variant) value for a field.
std::vector< SCH_REFERENCE > getAllItems() const override
bool storageIsSharedAcrossPaths(const wxString &aFieldName) const
Test whether a field's storage is common to every sheet path that reaches a symbol.
bool DeleteRows(size_t aPosition=0, size_t aNumRows=1) 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)
std::map< int, wxGridCellAttr * > m_colAttrs
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind) override
bool IsGeneratedField(const wxString &aFieldName)
Returns true if the entire string is generated, e.g is a single text var reference.
wxString ResolveTextVars(const wxString &aSource, const std::function< bool(wxString *)> *aResolver, int &aDepth)
Multi-pass text variable expansion and math expression evaluation.
const wxColour VARIANT_FIELD_OVERRIDE_DARK_YELLOW(80, 80, 40)
const wxColour VARIANT_FIELD_OVERRIDE_LIGHT_YELLOW(255, 255, 200)
const wxColour VARIANT_SYMBOL_OVERRIDE_LIGHT_BLUE(220, 235, 255)
const wxColour VARIANT_SYMBOL_OVERRIDE_DARK_BLUE(40, 60, 80)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
The point of the data model classes is fundamentally to represent three things:
std::vector< ITEM_TYPE > m_items
std::vector< std::pair< wxString, wxString > > variants
Hold a name of a symbol's field, field value, and default visibility.
std::vector< FIELD_CASE_CONFLICT > DetectFieldCaseConflicts(const SCH_REFERENCE_LIST &aSymbols)
DATA_MODEL_ROW< SCH_REFERENCE > SYMBOL_FIELDS_TABLE_DATA_MODEL_ROW
@ USER
The field ID hasn't been set yet; field is invalid.
@ REFERENCE
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...