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" ) );
169 setCellValues( aRow, aCol, std::vector<wxString>(
m_rows[aRow].GetCellItems().size(), aValue ) );
176 wxCHECK_RET( aRow >= 0 && aRow <
static_cast<int>(
m_rows.size() ), wxS(
"Invalid row number" ) );
177 wxCHECK_RET( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ), wxS(
"Invalid column number" ) );
182 const wxString& fieldName =
m_cols[aCol].m_fieldName;
183 std::set<const SCH_SYMBOL*> clearedSymbols;
186 clearedSymbols.insert( ref.GetSymbol() );
195 if( clearedSymbols.contains( ref.
GetSymbol() ) )
205 wxCHECK_RET( aRow >= 0 && aRow <
static_cast<int>(
m_rows.size() ), wxS(
"Invalid row number" ) );
207 std::set<const SCH_SYMBOL*> rowSymbols;
210 rowSymbols.insert( ref.GetSymbol() );
219 if( !revertAllPaths )
225 if( !rowSymbols.contains( ref.
GetSymbol() ) )
229 wxString storedValue;
233 if( liveFieldPresent != storedFieldPresent )
235 revertAllPaths =
true;
241 if( !revertAllPaths )
248 if( rowSymbols.contains( ref.
GetSymbol() ) )
259 std::span<const SCH_REFERENCE> items =
m_rows[aRow].GetCellItems();
260 const wxString& fieldName =
m_cols[aCol].m_fieldName;
262 std::map<const SCH_SYMBOL*, wxString> editedSymbols;
264 for(
size_t i = 0; i < items.size(); ++i )
265 editedSymbols[items[i].GetSymbol()] = aValues[i];
274 if( !editedSymbols.contains( ref.
GetSymbol() ) )
283 for(
size_t i = 0; i < items.size(); ++i )
294 auto it = editedSymbols.find( ref.
GetSymbol() );
296 if( it != editedSymbols.end() )
306 && aFieldName != wxS(
"${EXCLUDE_FROM_BOARD}" );
321 const wxString& aFieldName,
330 std::vector<SCH_REFERENCE> items;
343 const wxString& aFieldName )
350 return wxEmptyString;
362 std::function<bool( wxString* )> symbolResolver =
363 [&]( wxString* token ) ->
bool
371 return wxEmptyString;
379 std::function<bool( wxString* )> symbolResolver =
380 [&]( wxString* token ) ->
bool
396 if( aFieldName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
404 const wxString& aAttributeName,
405 const wxString& aVariantName )
407 if( aAttributeName == wxS(
"${DNP}" ) )
408 return aRef.
GetSymbolDNP( aVariantName ) ? wxS(
"1" ) : wxS(
"0" );
410 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
413 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
416 if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
419 if( aAttributeName == wxS(
"${EXCLUDE_FROM_POS_FILES}" ) )
427 const wxString& aAttributeName,
428 const wxString& aVariantName )
const
432 if( aAttributeName == wxS(
"${DNP}" ) )
433 return path.GetDNP( aVariantName );
434 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
435 return path.GetExcludedFromBoard( aVariantName );
436 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
437 return path.GetExcludedFromBOM( aVariantName );
438 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
439 return path.GetExcludedFromSim( aVariantName );
446 const wxString& aFieldName,
447 const wxString& aVariantName, wxString& aValue )
464 if( field->IsPrivate() )
483 const wxString& aFieldName )
492 const wxString& aAttributeName,
493 const wxString& aValue,
494 const wxString& aVariantName )
496 bool attrChanged =
false;
497 bool newValue = aValue == wxS(
"1" );
499 if( aAttributeName == wxS(
"${DNP}" ) )
501 attrChanged = aRef.
GetSymbolDNP( aVariantName ) != newValue;
506 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
513 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
520 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
527 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_POS_FILES}" ) )
548 static_cast<WX_GRID*
>( GetView() )->CommitPendingChanges(
true );
550 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0,
m_rows.size() );
551 GetView()->ProcessTableMessage( msg );
562 if(
m_scope == SCOPE::SCOPE_SELECTION
599 bool isExcluded =
false;
626 || (
m_scope == SCOPE::SCOPE_SHEET_RECURSIVE
632 bool matchFound =
false;
650 row.m_items.push_back( ref );
656 row.m_items.push_back( ref );
657 row.m_state = ROW_STATE::GROUP_COLLAPSED;
668 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_rows.size() );
669 GetView()->ProcessTableMessage( msg );
681 bool symbolModified =
false;
682 std::unique_ptr<SCH_SYMBOL> symbolCopy;
693 symbolCopy = std::make_unique<SCH_SYMBOL>( *symbol );
699 for(
const auto& [srcName, srcValue] : fieldStore )
715 if( destField && destField->
IsPrivate() )
717 if( srcValue.IsEmpty() )
725 bool createField = !destField;
733 destField->
SetVisible( srcTemplate->m_Visible );
738 symbolModified =
true;
753 if( !createField && ( previousValue != srcValue ) )
754 symbolModified =
true;
758 for(
int ii =
static_cast<int>( symbol->
GetFields().size() ) - 1; ii >= 0; ii-- )
763 const wxString& existingName = symbol->
GetFields()[ii].GetName();
768 symbolModified =
true;
772 if( symbolModified && ( symbol != nextSymbol ) )
776 if( symbol != nextSymbol )
779 symbolCopy = std::make_unique<SCH_SYMBOL>( *nextSymbol );
781 symbolCopy.reset(
nullptr );
783 symbolModified =
false;
796 bool refListChanged =
false;
820 for(
const auto& [
name,
source] : existingFields )
825 for(
const auto& [variant, sourceState] :
source.m_variants )
840 refListChanged =
true;
858 std::vector<KIID_PATH> keysToRemove;
862 if( !key.empty() && ( key.back() == symbolUuid ) )
863 keysToRemove.push_back( key );
866 for(
const KIID_PATH& key : keysToRemove )
873 return ref.GetSymbol()->m_Uuid == aSymbol.m_Uuid;
896 bool refListChanged =
false;
897 std::set<SCH_SYMBOL*> updatedSymbols;
901 if( incomingRef.GetSymbol() )
902 updatedSymbols.insert( incomingRef.GetSymbol() );
911 *cachedRef = incomingRef;
916 refListChanged =
true;
929 if( !updatedSymbols.contains( ref.
GetSymbol() ) )
941 size_t curNumRows =
m_rows.size();
943 if( aPosition >= curNumRows )
945 wxFAIL_MSG( wxString::Format( wxT(
"Called SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL::DeleteRows(aPosition=%lu, "
946 "aNumRows=%lu)\nPosition value is invalid for present table with %lu rows" ),
947 (
unsigned long) aPosition, (
unsigned long) aNumRows,
948 (
unsigned long) curNumRows ) );
953 if( aNumRows > curNumRows - aPosition )
955 aNumRows = curNumRows - aPosition;
958 if( aNumRows >= curNumRows )
966 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aPosition, aNumRows );
967 GetView()->ProcessTableMessage( msg );
974 auto first =
m_rows.begin() + aPosition;
975 auto last = first + aNumRows;
978 for(
auto it = first; it != last && it !=
m_rows.end(); ++it )
995 std::vector<FIELD_CASE_CONFLICT> conflicts;
997 for(
unsigned i = 0; i < aSymbols.
GetCount(); ++i )
1004 std::map<wxString, std::vector<std::pair<wxString, wxString>>> groups;
1008 if( field.IsMandatory() || field.IsPrivate() )
1011 groups[field.GetName().Lower()].emplace_back( field.GetName(), field.GetText() );
1014 for(
const auto& [key, members] : groups )
1016 if( members.size() < 2 )
1021 c.
sheetPath = aSymbols[i].GetSheetPath();
1025 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)
std::map< KIID_PATH, std::map< wxString, FIELD_STORE_VALUE > > m_dataStore
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
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 updateDataStoreItemFieldFromLive(const SCH_REFERENCE &aItem, const wxString &aFieldName, bool aAllVariants=false)
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)
void initializeDataStoreItem(const SCH_REFERENCE &aItem)
bool storedFieldIsRemoved(const SCH_REFERENCE &aItem, const wxString &aName) const
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
FIELD_STORE_VALUE & storedField(const SCH_REFERENCE &aItem, const wxString &aFieldName)
bool resolveStoredTextVar(const SCH_REFERENCE &aItem, wxString *aToken, bool aCaseSensitive=false) const
bool IsCellReadOnly(int aRow, int aCol) override
std::map< wxString, wxString > getStoredFields(const SCH_REFERENCE &aItem, const wxString &aVariant) const
void refreshDataStoreItem(const SCH_REFERENCE &aItem)
bool MatchesFilter(const SCH_REFERENCE &aItem, const wxString &aReference, EDA_COMBINED_MATCHER &aMatcher)
void acceptDataStoreItem(const SCH_REFERENCE &aItem)
std::set< wxString > storedVariants(const SCH_REFERENCE &aItem) const
wxString ConvertKIIDsToRefs(const wxString &aSource) const
wxString ConvertRefsToKIIDs(const wxString &aSource) const
Commit for the schematic and symbol editors.
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)
wxString GetFullRef() const
Return reference name with unit altogether.
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
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)
void setCellValues(int aRow, int aCol, const std::vector< wxString > &aValues) override
Write one value per item represented by the cell. Models may propagate shared storage.
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)
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 fieldSupportsVariants(const wxString &aFieldName) const override
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)
void ApplyData(SCH_COMMIT &aCommit, TEMPLATES &aTemplateFieldnames)
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.
bool getLiveFieldValueForVariant(const SCH_REFERENCE &aRef, const wxString &aFieldName, const wxString &aVariantName, wxString &aValue) override
void SetValue(int aRow, int aCol, const wxString &aValue) override
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...
bool attributeForcedOnBySheet(const SCH_REFERENCE &aRef, const wxString &aAttributeName, const wxString &aVariantName) const override
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
std::map< wxString, FIELD_VALUE_STATE > m_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
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
@ 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...