22#include <wx/settings.h>
43 const wxString& aFieldName,
56 aValue = field->GetText();
82 wxCHECK_RET( aRow >= 0 && aRow < (
int)
m_rows.size(), wxS(
"Invalid row number" ) );
83 wxCHECK_RET( aCol >= 0 && aCol < (
int)
m_cols.size(), wxS(
"Invalid column number" ) );
92 const wxString& fieldName =
m_cols[aCol].m_fieldName;
100 if( aValue == wxS(
"1" ) )
131 wxCHECK( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ),
false );
181 wxGridCellAttr* attr = wxGridTableBase::GetAttr( aRow, aCol, aKind );
185 wxGridCellAttr* modelAttr =
nullptr;
197 if( attr->HasBackgroundColour() && !modelAttr->HasBackgroundColour() )
198 modelAttr->SetBackgroundColour( attr->GetBackgroundColour() );
199 if( attr->HasTextColour() && !modelAttr->HasTextColour() )
200 modelAttr->SetTextColour( attr->GetTextColour() );
201 if( attr->HasFont() && !modelAttr->HasFont() )
202 modelAttr->SetFont( attr->GetFont() );
211 attr =
new wxGridCellAttr;
217 bool rowModified =
false;
218 bool cellModified =
false;
219 bool cellEmpty =
true;
220 bool blankModified =
false;
222 const wxString& fieldName =
m_cols[aCol].m_fieldName;
227 wxString storedValue;
230 bool modified = liveFieldPresent != storedFieldPresent || liveValue != storedValue;
235 bool elementEmpty = !storedFieldPresent || ( !liveFieldPresent && !modified );
240 if( storedValue.IsEmpty() && modified )
241 blankModified =
true;
255 if( cellModified && rowModified && !cellEmpty )
261 attr->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
266 wxString storedValue;
269 bool modified = liveFieldPresent != storedFieldPresent || liveValue != storedValue;
273 if( !storedFieldPresent )
275 if( !liveFieldPresent )
277 attr->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
279 else if( liveValue.empty() )
288 else if( storedValue.IsEmpty() )
302 attr->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWFRAME ) );
308 if( needsResolvedTextRenderer )
315 if( attr->HasFont() )
316 font = attr->GetFont();
318 font = GetView()->GetDefaultCellFont();
325 attr->SetFont( font );
334 wxString& aNewSymbolName )
336 wxCHECK_RET( aRow >= 0 && aRow < (
int)
m_rows.size(),
"Invalid Row Number" );
337 wxCHECK_RET( aCol >= 0 && aCol < (
int)
m_cols.size(),
"Invalid Column Number" );
341 wxLogTrace(
traceLibFieldTable,
"CreateDerivedSymbolImmediate: Creating '%s' from parent '%s' immediately",
342 aNewSymbolName, parentSymbol->
GetName() );
345 KIID newDerivedSymbolUuid;
358 wxLogTrace(
traceLibFieldTable,
"createActualDerivedSymbol: Creating '%s' from parent '%s', symbol list size before: %zu",
365 if( sym->m_Uuid == aNewSymbolUuid )
375 newSymbol->
SetName( aNewSymbolName );
382 const_cast<KIID&
>( newSymbol->
m_Uuid ) = aNewSymbolUuid;
385 wxLogTrace(
traceLibFieldTable,
"createActualDerivedSymbol: Added new symbol to list, size now: %zu",
391 wxLogTrace(
traceLibFieldTable,
"createActualDerivedSymbol: Initialized field data for new symbol" );
398 wxLogTrace(
traceLibFieldTable,
"Created derived symbol '%s' for library '%s', total tracked: %zu",
403 const wxString& aAttributeName )
405 if( aAttributeName == wxS(
"${DNP}" ) )
406 return aSymbol->
GetDNP() ? wxS(
"1" ) : wxS(
"0" );
408 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
411 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
414 if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
417 if( aAttributeName == wxS(
"${EXCLUDE_FROM_POS_FILES}" ) )
421 return aSymbol->
IsPower() ? wxS(
"1" ) : wxS(
"0" );
424 return aSymbol->
IsLocalPower() ? wxS(
"1" ) : wxS(
"0" );
431 const wxString& aAttributeName,
432 const wxString& aValue )
434 if( aAttributeName == wxS(
"${DNP}" ) )
435 aSymbol->
SetDNP( aValue == wxS(
"1" ) );
436 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
438 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
440 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
442 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_POS_FILES}" ) )
445 wxLogDebug(
"Unknown attribute name: %s", aAttributeName );
452 || aFieldName == wxS(
"${EXCLUDE_FROM_BOARD}" )
453 || aFieldName == wxS(
"${EXCLUDE_FROM_BOM}" )
454 || aFieldName == wxS(
"${EXCLUDE_FROM_POS_FILES}" )
455 || aFieldName == wxS(
"${EXCLUDE_FROM_SIM}" );
464 return value == wxS(
"1" );
474 static const std::vector<wxString> exclusionFields = {
475 wxS(
"${EXCLUDE_FROM_BOARD}" ),
476 wxS(
"${EXCLUDE_FROM_BOM}" ),
477 wxS(
"${EXCLUDE_FROM_POS_FILES}" ),
478 wxS(
"${EXCLUDE_FROM_SIM}" ),
481 for(
const wxString& fieldName : exclusionFields )
492 return wxEmptyString;
495 return wxS(
"Power Symbol" );
497 return wxS(
"Local Power Symbol" );
514 static_cast<WX_GRID*
>( GetView() )->CommitPendingChanges(
true );
516 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, (
int)
m_rows.size() );
517 GetView()->ProcessTableMessage( msg );
529 symbol->GetName(), symbol->m_Uuid.AsString() );
531 if(
m_scope == SCOPE::SCOPE_RELATED_SYMBOLS )
533 std::shared_ptr<LIB_SYMBOL> root = symbol->GetRootSymbol();
548 bool matchFound =
false;
566 row.m_items.push_back( symbol );
567 row.m_state = ROW_STATE::COLLAPSED;
578 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, (
int)
m_rows.size() );
579 GetView()->ProcessTableMessage( msg );
589 return lhItem == rhItem;
594 const wxString& aFieldName )
601 return wxEmptyString;
612 std::function<bool( wxString* )> libSymbolResolver =
613 [&]( wxString* token ) ->
bool
621 return wxEmptyString;
633 std::function<bool( wxString* )> libSymbolResolver =
634 [&]( wxString* token ) ->
bool
645 std::function<
void()> postApplyHandler )
652 bool symbolModified =
false;
653 bool symbolIsPower = symbol->IsPower();
654 bool symbolIsLocalPower = symbol->IsLocalPower();
660 if( localPowerCol != -1 )
663 && value == wxS(
"1" );
668 if( powerCol != -1 && !symbolIsPower )
669 symbolIsLocalPower =
false;
670 else if( symbolIsLocalPower )
671 symbolIsPower =
true;
673 if( symbol->IsPower() != symbolIsPower || symbol->IsLocalPower() != symbolIsLocalPower )
675 if( symbolIsLocalPower )
676 symbol->SetLocalPower();
677 else if( symbolIsPower )
678 symbol->SetGlobalPower();
682 symbolModified =
true;
685 for(
size_t i = 0; i <
m_cols.size(); ++i )
701 wxString newValue = currentlyPresent ? srcValue : wxString( wxS(
"0" ) );
706 symbolModified =
true;
714 if( symbol->GetKeyWords() != srcValue )
716 symbol->SetKeyWords( srcValue );
717 symbolModified =
true;
728 SCH_FIELD* destField = symbol->GetField( srcName );
730 if( !currentlyPresent && destField )
737 destField->
SetText( wxEmptyString );
738 symbolModified =
true;
743 symbol->RemoveField( destField );
744 symbolModified =
true;
752 bool createField = !destField && currentlyPresent;
756 const VECTOR2I symbolPos = symbol->GetPosition();
759 symbol->AddField( destField );
760 symbolModified =
true;
769 wxString newValue = symbolIsPower ? symbol->GetName() : srcValue;
771 if( !newValue.IsEmpty() && destField->
GetText() != newValue )
774 symbolModified =
true;
777 else if( destField->
GetText() != srcValue )
779 destField->
SetText( srcValue );
780 symbolModified =
true;
784 std::vector<SCH_FIELD*> symbolFields;
785 symbol->GetFields( symbolFields );
790 if( field->IsMandatory() || field->IsPrivate() )
793 const wxString& existingName = field->GetName();
799 symbol->RemoveField( field );
800 symbolModified =
true;
805 symbolChangeHandler( symbol );
814 if( postApplyHandler )
829 if( symbol->IsDerived() && reference.IsEmpty() )
834 if( !aErrorMessage.IsEmpty() )
848 return wxGRID_VALUE_BOOL;
850 return wxGridTableBase::GetTypeName( row, col );
857 key.push_back( aItem->
m_Uuid );
bool cellUsesResolvedTextRenderer(int aRow, int aCol)
virtual bool fieldIsItemProperty(const wxString &aFieldName) const
bool cellUsesUrlEditor(int aRow, int aCol)
bool ColIsAttribute(int aCol) const
void applyResolvedTextRenderer(wxGridCellAttr *aAttr, bool aApplyTint)
wxGridCellAttr * cloneUrlEditorAttr()
virtual bool fieldIsAttribute(const wxString &aFieldName) const
wxGridCellAttr * applyCellDecorations(wxGridCellAttr *aAttr, int aRow, int aCol)
virtual wxString getAttributeResolvedValue(const wxString &aFieldName, bool aValue) const
int GetFieldNameCol(const wxString &aFieldName) const
std::vector< DATA_MODEL_COL > m_cols
bool groupMatch(const LIB_SYMBOL *&lhItem, const LIB_SYMBOL *&rhItem)
void setStoredFieldValue(const LIB_SYMBOL *&aItem, const wxString &aFieldName, const wxString &aValue)
bool fieldIsModified(const LIB_SYMBOL *&aItem, const wxString &aFieldName)
void initializeDataStoreItem(const LIB_SYMBOL *&aItem)
bool getStoredFieldValue(const LIB_SYMBOL *&aItem, const wxString &aFieldName, wxString &aValue) const
std::vector< DATA_MODEL_ROW< LIB_SYMBOL * > > m_rows
bool IsCellReadOnly(int aRow, int aCol) override
bool MatchesFilter(const LIB_SYMBOL *&aItem, const wxString &aReference, EDA_COMBINED_MATCHER &aMatcher)
void updateDataStoreItemFieldFromLive(const LIB_SYMBOL *&aItem, const wxString &aFieldName)
static const wxString SYMBOL_KEYWORDS
bool fieldIsItemProperty(const wxString &aFieldName) const override
void SetValue(int aRow, int aCol, const wxString &aValue) override
wxString getAttributeResolvedValue(const wxString &aFieldName, bool aValue) const override
wxString getAttributeValue(const LIB_SYMBOL *, const wxString &aAttributeName)
std::vector< std::pair< LIB_SYMBOL *, wxString > > m_createdDerivedSymbols
std::vector< LIB_SYMBOL * > getAllItems() const override
bool IsCellReadOnly(int aRow, int aCol) override
KIID_PATH getDataStoreKey(LIB_SYMBOL *const &aItem) const override
wxGridCellAttr * GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind) override
void RebuildRows() override
static const wxString SYMBOL_NAME
static const wxString SYMBOL_IS_POWER
bool ColIsItemIdentifier(int aCol) const override
Reference for symbol/fields tables, lib_id for lib tables.
void CreateDerivedSymbolImmediate(int aRow, int aCol, wxString &aNewSymbolName)
bool getStoredPowerSymbolValue(LIB_SYMBOL *aSymbol) const
wxString getFieldResolvedLiveValue(LIB_SYMBOL *const &aSymbol, const wxString &aFieldName) override
Explicitly bypasses the data store's field values and retries them from the item's current field valu...
void createActualDerivedSymbol(const LIB_SYMBOL *aParentSymbol, const wxString &aNewSymbolName, const KIID &aNewSymbolUuid)
bool fieldIsAttribute(const wxString &aFieldName) const override
void ApplyData(std::function< void(LIB_SYMBOL *)> symbolChangeHandler, std::function< void()> postApplyHandler=nullptr)
static const wxString SYMBOL_IS_LOCAL_POWER
std::vector< LIB_SYMBOL * > m_symbolsList
void setAttributeValue(LIB_SYMBOL *aSymbol, const wxString &aAttributeName, const wxString &aValue)
bool unitMatch(LIB_SYMBOL *const &lhItem, LIB_SYMBOL *const &rhItem) override
bool getLiveFieldValue(LIB_SYMBOL *const &aSymbol, const wxString &aFieldName, wxString &aValue) override
Gets the current value of the field from the live item, e.g.
wxString getItemIdentifier(LIB_SYMBOL *const &aItem) const override
wxString GetTypeName(int row, int col) override
bool isPowerSymbolControlledField(const wxString &aFieldName) const
wxString resolveTextVars(LIB_SYMBOL *const &aSymbol, const wxString &aText) override
wxString m_relatedSymbolRoot
void setPowerSymbolDefaults(LIB_SYMBOL *aSymbol)
bool ValidateReferences(wxString &aSymbolName, wxString &aErrorMessage) const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Define a library symbol object.
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
const LIB_ID & GetLibId() const override
wxString GetKeyWords() const override
bool IsPower() const override
SCH_FIELD * GetField(const wxString &aFieldName)
Find a field within this symbol matching aFieldName; return nullptr if not found.
void SetParent(LIB_SYMBOL *aParent=nullptr)
wxString GetName() const override
SCH_FIELD & GetValueField()
Return reference to the value field.
bool IsLocalPower() const override
virtual void SetName(const wxString &aName)
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 SetPosition(const VECTOR2I &aPosition) override
void SetText(const wxString &aText) override
bool GetExcludedFromPosFiles(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
void SetExcludedFromBoard(bool aExclude, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear exclude from board netlist flag.
virtual bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flag.
virtual void SetExcludedFromSim(bool aExcludeFromSim, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from simulation flag.
virtual bool GetExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
virtual void SetDNP(bool aDNP, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
bool GetExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
void SetExcludedFromPosFiles(bool aExclude, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear exclude from position files flag.
virtual bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
virtual void SetExcludedFromBOM(bool aExcludeFromBOM, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from schematic bill of materials flag.
std::map< int, wxGridCellAttr * > m_colAttrs
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 wxChar *const traceLibFieldTable
DATA_MODEL_ROW< LIB_SYMBOL * > LIB_FIELDS_TABLE_DATA_MODEL_ROW
const wxColour STRIPED_CLEARED_EMPTY_FIELD_LIGHT_GREEN(180, 220, 180)
const wxColour STRIPED_EDITED_EMPTY_FIELD_MUTED_GREEN(180, 200, 180)
const wxColour EDITED_EMPTY_FIELD_BRIGHT_GREEN(192, 255, 192)
const wxColour STRIPED_EDITED_NONEMPTY_FIELD_MUTED_RED(200, 180, 180)
const wxColour STRIPED_CLEARED_NONEMPTY_FIELD_LIGHT_RED(220, 180, 180)
wxString UnescapeString(const wxString &aSource)
The point of the data model classes is fundamentally to represent three things:
std::vector< ITEM_TYPE > m_items
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".
@ VALUE
Field Value of part, i.e. "3.3K".
wxLogTrace helper definitions.
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
wxString GetFieldValidationErrorMessage(FIELD_T aFieldId, const wxString &aValue)
Return the error message if aValue is invalid for aFieldId.
Custom text control validator definitions.
VECTOR2< int32_t > VECTOR2I