26#include <wx/settings.h>
45 wxS(
"${FOOTPRINT_LIBRARY_DESCRIPTION}" );
67 wxGridCellAttr* attr =
nullptr;
70 bool needsVariantHighlight =
false;
72 wxColour highlightColor;
76 && aCol < (
int)
m_cols.size() )
78 const wxString& fieldName =
m_cols[aCol].m_fieldName;
91 wxString currentValue;
95 if( currentValue != defaultValue )
97 needsVariantHighlight =
true;
99 wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
100 bool isDark = ( bg.Red() + bg.Green() + bg.Blue() ) < 384;
112 if( !needsReadOnly && !needsUrlEditor && !needsVariantHighlight && !needsResolvedTextRenderer )
126 attr =
new wxGridCellAttr();
132 if( needsVariantHighlight )
133 attr->SetBackgroundColour( highlightColor );
135 if( needsResolvedTextRenderer )
144 wxCHECK_RET( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ), wxS(
"Invalid column number" ) );
153 const wxString& fieldName =
m_cols[aCol].m_fieldName;
166 ||
m_cols[aCol].m_fieldName == wxS(
"${EXCLUDE_FROM_BOARD}" );
174 return lhItem == rhItem;
179 const wxString& aFieldName,
193 const wxString& aFieldName )
201 return wxEmptyString;
212 std::function<bool( wxString* )> footprintResolver =
213 [&]( wxString* token ) ->
bool
221 return wxEmptyString;
233 std::function<bool( wxString* )> footprintResolver =
234 [&]( wxString* token ) ->
bool
245 const wxString& aAttributeName,
246 const wxString& aVariantName )
248 if( aAttributeName == wxS(
"${DNP}" ) )
251 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
254 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
257 if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
260 if( aAttributeName == wxS(
"${EXCLUDE_FROM_POS_FILES}" ) )
285 const wxString& aFieldName,
286 const wxString& aVariantName,
307 if( field->IsPrivate() )
333 const wxString& aFieldName )
342 const wxString& aAttributeName,
343 const wxString& aValue,
344 const wxString& aVariantName )
346 bool attrChanged =
false;
347 bool newValue = aValue == wxS(
"1" );
348 bool defaultVariant = aVariantName.IsEmpty()
351 if( aAttributeName == wxS(
"${DNP}" ) )
361 variant->SetDNP( newValue );
364 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
368 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
378 variant->SetExcludedFromBOM( newValue );
381 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
391 variant->SetExcludedFromSim( newValue );
394 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_POS_FILES}" ) )
404 variant->SetExcludedFromPosFiles( newValue );
421 static_cast<WX_GRID*
>( GetView() )->CommitPendingChanges(
true );
423 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0,
m_rows.size() );
424 GetView()->ProcessTableMessage( msg );
435 if(
m_scope == SCOPE::SCOPE_SELECTION
470 bool isExcluded =
false;
494 if( !footprintSheetPath.empty() )
495 footprintSheetPath.pop_back();
497 if( (
m_scope == SCOPE::SCOPE_SHEET && footprintSheetPath !=
m_path )
498 || (
m_scope == SCOPE::SCOPE_SHEET_RECURSIVE
504 bool matchFound =
false;
522 row.m_items.push_back( ref );
528 row.m_items.push_back( ref );
529 row.m_state = ROW_STATE::COLLAPSED;
540 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_rows.size() );
541 GetView()->ProcessTableMessage( msg );
551 const wxString& aVariantName )
553 bool defaultVariant = aVariantName.IsEmpty()
555 bool footprintModified =
false;
559 const std::map<wxString, wxString>& fieldStore =
getStoredFields( aSourceRef );
561 for(
const auto& [srcName, srcValue] : fieldStore )
566 footprintModified |=
setAttributeValue( destRef, srcName, srcValue, aVariantName );
592 if( destField && destField->
IsPrivate() )
594 if( srcValue.IsEmpty() )
599 footprintModified =
true;
605 bool createField = !destField;
616 if( aTemplateFieldnames )
619 destField->
SetVisible( srcTemplate->m_Visible );
626 aDestFootprint.
Add( destField );
627 footprintModified =
true;
634 wxString newValue = srcValue;
638 newValue = board->ConvertCrossReferencesToKIIDs( srcValue );
640 if( previousValue != newValue )
645 destField->
SetText( newValue );
646 footprintModified =
true;
650 variant->SetFieldValue( srcName, newValue );
651 footprintModified =
true;
656 for(
int ii =
static_cast<int>( aDestFootprint.
GetFields().size() ) - 1; ii >= 0; ii-- )
670 parentGroup->RemoveItem( field );
672 aDestFootprint.
Remove( field );
674 footprintModified =
true;
678 return footprintModified;
683 const wxString& aVariantName )
691 std::unique_ptr<FOOTPRINT> footprintCopy = std::make_unique<FOOTPRINT>( footprint );
692 footprintCopy->SetParentGroup(
nullptr );
696 aCommit.
Modified( &footprint, footprintCopy.release() );
724 return ref == aFootprint;
754 size_t curNumRows =
m_rows.size();
756 if( aPosition >= curNumRows )
758 wxFAIL_MSG( wxString::Format( wxT(
"Called FOOTPRINT_FIELDS_EDITOR_GRID_DATA_MODEL::DeleteRows(aPosition=%lu, "
759 "aNumRows=%lu)\nPosition value is invalid for present table with %lu rows" ),
760 (
unsigned long) aPosition, (
unsigned long) aNumRows,
761 (
unsigned long) curNumRows ) );
766 if( aNumRows > curNumRows - aPosition )
768 aNumRows = curNumRows - aPosition;
771 if( aNumRows >= curNumRows )
779 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aPosition, aNumRows );
780 GetView()->ProcessTableMessage( msg );
787 auto first =
m_rows.begin() + aPosition;
788 auto last = first + aNumRows;
791 for(
auto it = first; it != last && it !=
m_rows.end(); ++it )
794 refsToDelete.push_back( ref );
816 wxCHECK( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ),
false );
830 const wxString& aFieldName, wxString& aValue )
863 bool footprintModified =
false;
870 footprintModified =
true;
877 footprintModified =
true;
881 aRef, aFootprint,
nullptr, wxEmptyString );
883 return footprintModified;
889 bool allChangesApplied =
true;
897 FOOTPRINT changedFootprint( ref.GetFootprint() );
912 if( !aChangeHandler( changedFootprint ) )
914 allChangesApplied =
false;
918 ref.GetFootprint() = changedFootprint;
934 return allChangesApplied;
939 return allChangesApplied;
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
void SetFPRelativePosition(const VECTOR2I &aPos)
Information pertinent to a Pcbnew printed circuit board.
wxString ConvertKIIDsToCrossReferences(const wxString &aSource) const
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
A set of EDA_ITEMs (i.e., without duplicates).
virtual EDA_GROUP * GetParentGroup() const
virtual void SetVisible(bool aVisible)
virtual void SetText(const wxString &aText)
bool cellUsesResolvedTextRenderer(int aRow, int aCol)
virtual bool fieldIsItemProperty(const wxString &aFieldName) const
bool cellUsesUrlEditor(int aRow, int aCol)
void applyResolvedTextRenderer(wxGridCellAttr *aAttr, bool aApplyTint)
virtual bool ColIsReadOnly(int aCol) const
bool ColIsReference(int aCol) const
virtual bool ColIsItemIdentifier(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)
bool ColIsFootprint(int aCol) const
int GetFieldNameCol(const wxString &aFieldName) const
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
bool groupMatch(const FOOTPRINT_REF &lhItem, const FOOTPRINT_REF &rhItem)
void setStoredFieldValue(const FOOTPRINT_REF &aItem, const wxString &aFieldName, const wxString &aValue)
bool fieldIsModified(const FOOTPRINT_REF &aItem, const wxString &aFieldName)
const std::map< wxString, wxString > & getStoredFields(const FOOTPRINT_REF &aItem) const
void initializeDataStoreItem(const FOOTPRINT_REF &aItem)
bool getStoredFieldValue(const FOOTPRINT_REF &aItem, const wxString &aFieldName, wxString &aValue) const
std::vector< DATA_MODEL_ROW< FOOTPRINT_REF > > m_rows
bool IsCellReadOnly(int aRow, int aCol) override
bool MatchesFilter(const FOOTPRINT_REF &aItem, const wxString &aReference, EDA_COMBINED_MATCHER &aMatcher)
void updateDataStoreItemFieldFromLive(const FOOTPRINT_REF &aItem, const wxString &aFieldName)
bool IsContainedWithin(const KIID_PATH &aParentPath) const
virtual wxString GetFootprint()
For items with footprint fields.
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
void SetPrivate(bool aPrivate)
wxString GetUntranslatedName() const
Get the untranslated field name for storage, variable look-up, etc.
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings, bool aCheckSide) 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)
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
wxString GetDefaultVariantName()
The point of the data model classes is fundamentally to represent three things:
std::vector< ITEM_TYPE > m_items
Hold a name of a symbol's field, field value, and default visibility.
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.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...