25#include <wx/settings.h>
66 wxGridCellAttr* attr =
nullptr;
69 bool needsVariantHighlight =
false;
71 wxColour highlightColor;
75 && aCol < (
int)
m_cols.size() )
77 const wxString& fieldName =
m_cols[aCol].m_fieldName;
90 wxString currentValue;
95 if( currentValue != defaultValue )
97 needsVariantHighlight =
true;
99 bool isPriority2 =
false;
107 && variantData->m_SymbolOverride
108 && !variantData->m_Fields.count( fieldName ) )
114 wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
115 bool isDark = ( bg.Red() + bg.Green() + bg.Blue() ) < 384;
135 if( !needsReadOnly && !needsUrlEditor && !needsVariantHighlight && !needsResolvedTextRenderer )
149 attr =
new wxGridCellAttr();
155 if( needsVariantHighlight )
156 attr->SetBackgroundColour( highlightColor );
158 if( needsResolvedTextRenderer )
167 wxCHECK_RET( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ), wxS(
"Invalid column number" ) );
175 setCellValues( aRow, aCol, std::vector<wxString>(
m_rows[aRow].GetCellItems().size(), aValue ) );
182 wxCHECK_RET( aRow >= 0 && aRow <
static_cast<int>(
m_rows.size() ), wxS(
"Invalid row number" ) );
183 wxCHECK_RET( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ), wxS(
"Invalid column number" ) );
188 const wxString& fieldName =
m_cols[aCol].m_fieldName;
189 std::set<const SCH_SYMBOL*> clearedSymbols;
192 clearedSymbols.insert( ref.GetSymbol() );
201 if( clearedSymbols.contains( ref.
GetSymbol() ) )
211 wxCHECK_RET( aRow >= 0 && aRow <
static_cast<int>(
m_rows.size() ), wxS(
"Invalid row number" ) );
213 std::set<const SCH_SYMBOL*> rowSymbols;
216 rowSymbols.insert( ref.GetSymbol() );
225 if( !revertAllPaths )
231 if( !rowSymbols.contains( ref.
GetSymbol() ) )
235 wxString storedValue;
239 if( liveFieldPresent != storedFieldPresent )
241 revertAllPaths =
true;
247 if( !revertAllPaths )
254 if( rowSymbols.contains( ref.
GetSymbol() ) )
265 std::span<const SCH_REFERENCE> items =
m_rows[aRow].GetCellItems();
266 const wxString& fieldName =
m_cols[aCol].m_fieldName;
268 std::map<const SCH_SYMBOL*, wxString> editedSymbols;
270 for(
size_t i = 0; i < items.size(); ++i )
271 editedSymbols[items[i].GetSymbol()] = aValues[i];
280 if( !editedSymbols.contains( ref.
GetSymbol() ) )
289 for(
size_t i = 0; i < items.size(); ++i )
300 auto it = editedSymbols.find( ref.
GetSymbol() );
302 if( it != editedSymbols.end() )
312 && aFieldName != wxS(
"${EXCLUDE_FROM_BOARD}" );
328 const wxString& aFieldName,
337 std::vector<SCH_REFERENCE> items;
350 const wxString& aFieldName )
357 return wxEmptyString;
369 std::function<bool( wxString* )> symbolResolver =
370 [&]( wxString* token ) ->
bool
378 return wxEmptyString;
386 std::function<bool( wxString* )> symbolResolver =
387 [&]( wxString* token ) ->
bool
403 if( aFieldName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
411 const wxString& aAttributeName,
412 const wxString& aVariantName )
414 if( aAttributeName == wxS(
"${DNP}" ) )
415 return aRef.
GetSymbolDNP( aVariantName ) ? wxS(
"1" ) : wxS(
"0" );
417 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
420 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
423 if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
426 if( aAttributeName == wxS(
"${EXCLUDE_FROM_POS_FILES}" ) )
434 const wxString& aAttributeName,
435 const wxString& aVariantName )
const
439 if( aAttributeName == wxS(
"${DNP}" ) )
440 return path.GetDNP( aVariantName );
441 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
442 return path.GetExcludedFromBoard( aVariantName );
443 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
444 return path.GetExcludedFromBOM( aVariantName );
445 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
446 return path.GetExcludedFromSim( aVariantName );
453 const wxString& aFieldName,
454 const wxString& aVariantName, wxString& aValue )
471 if( field->IsPrivate() )
490 const wxString& aFieldName )
499 const wxString& aAttributeName,
500 const wxString& aValue,
501 const wxString& aVariantName )
503 bool attrChanged =
false;
504 bool newValue = aValue == wxS(
"1" );
506 if( aAttributeName == wxS(
"${DNP}" ) )
508 attrChanged = aRef.
GetSymbolDNP( aVariantName ) != newValue;
513 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
520 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
527 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
534 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_POS_FILES}" ) )
555 static_cast<WX_GRID*
>( GetView() )->CommitPendingChanges(
true );
557 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0,
m_rows.size() );
558 GetView()->ProcessTableMessage( msg );
569 if(
m_scope == SCOPE::SCOPE_SELECTION
606 bool isExcluded =
false;
633 || (
m_scope == SCOPE::SCOPE_SHEET_RECURSIVE
639 bool matchFound =
false;
657 row.m_items.push_back( ref );
663 row.m_items.push_back( ref );
664 row.m_state = ROW_STATE::GROUP_COLLAPSED;
675 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_rows.size() );
676 GetView()->ProcessTableMessage( msg );
688 bool symbolModified =
false;
689 std::unique_ptr<SCH_SYMBOL> symbolCopy;
700 symbolCopy = std::make_unique<SCH_SYMBOL>( *symbol );
706 for(
const auto& [srcName, srcValue] : fieldStore )
722 if( destField && destField->
IsPrivate() )
724 if( srcValue.IsEmpty() )
732 bool createField = !destField;
740 destField->
SetVisible( srcTemplate->m_Visible );
745 symbolModified =
true;
760 if( !createField && ( previousValue != srcValue ) )
761 symbolModified =
true;
765 for(
int ii =
static_cast<int>( symbol->
GetFields().size() ) - 1; ii >= 0; ii-- )
770 const wxString& existingName = symbol->
GetFields()[ii].GetName();
775 symbolModified =
true;
779 if( symbolModified && ( symbol != nextSymbol ) )
783 if( symbol != nextSymbol )
786 symbolCopy = std::make_unique<SCH_SYMBOL>( *nextSymbol );
788 symbolCopy.reset(
nullptr );
790 symbolModified =
false;
803 bool refListChanged =
false;
827 for(
const auto& [
name,
source] : existingFields )
832 for(
const auto& [variant, sourceState] :
source.m_variants )
847 refListChanged =
true;
865 std::vector<KIID_PATH> keysToRemove;
869 if( !key.empty() && ( key.back() == symbolUuid ) )
870 keysToRemove.push_back( key );
873 for(
const KIID_PATH& key : keysToRemove )
880 return ref.GetSymbol()->m_Uuid == aSymbol.m_Uuid;
903 bool refListChanged =
false;
904 std::set<SCH_SYMBOL*> updatedSymbols;
908 if( incomingRef.GetSymbol() )
909 updatedSymbols.insert( incomingRef.GetSymbol() );
918 *cachedRef = incomingRef;
923 refListChanged =
true;
936 if( !updatedSymbols.contains( ref.
GetSymbol() ) )
948 size_t curNumRows =
m_rows.size();
950 if( aPosition >= curNumRows )
952 wxFAIL_MSG( wxString::Format( wxT(
"Called SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL::DeleteRows(aPosition=%lu, "
953 "aNumRows=%lu)\nPosition value is invalid for present table with %lu rows" ),
954 (
unsigned long) aPosition, (
unsigned long) aNumRows,
955 (
unsigned long) curNumRows ) );
960 if( aNumRows > curNumRows - aPosition )
962 aNumRows = curNumRows - aPosition;
965 if( aNumRows >= curNumRows )
973 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aPosition, aNumRows );
974 GetView()->ProcessTableMessage( msg );
981 auto first =
m_rows.begin() + aPosition;
982 auto last = first + aNumRows;
985 for(
auto it = first; it != last && it !=
m_rows.end(); ++it )
1002 std::vector<FIELD_CASE_CONFLICT> conflicts;
1004 for(
unsigned i = 0; i < aSymbols.
GetCount(); ++i )
1006 SCH_SYMBOL* symbol = aSymbols[i].GetSymbol();
1011 std::map<wxString, std::vector<std::pair<wxString, wxString>>> groups;
1015 if( field.IsMandatory() || field.IsPrivate() )
1018 groups[field.GetName().Lower()].emplace_back( field.GetName(), field.GetText() );
1021 for(
const auto& [key, members] : groups )
1023 if( members.size() < 2 )
1028 c.
sheetPath = aSymbols[i].GetSheetPath();
1032 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)
const wxString & GetRefSuffix() const
Return the sheet suffix this reference composes with, or empty while it is unannotated.
wxString GetFullRef() const
Return reference name with unit and sheet suffix altogether, as in U12A_M4.
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.
wxString getItemRefSuffix(const SCH_REFERENCE &aItem) const override
Return the sheet suffix shown after the item's identifier, which is a base reference.
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...