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 && aFieldName != wxS(
"${EXCLUDE_FROM_BOARD}" );
182 return lhItem == rhItem;
187 const wxString& aFieldName,
202 const wxString& aFieldName )
210 return wxEmptyString;
221 std::function<bool( wxString* )> footprintResolver =
222 [&]( wxString* token ) ->
bool
230 return wxEmptyString;
238 std::function<bool( wxString* )> footprintResolver =
239 [&]( wxString* token ) ->
bool
242 wxString fieldToken = *token == wxS(
"VALUE" )
259 const wxString& aAttributeName,
260 const wxString& aVariantName )
262 if( aAttributeName == wxS(
"${DNP}" ) )
265 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
268 if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
271 if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
274 if( aAttributeName == wxS(
"${EXCLUDE_FROM_POS_FILES}" ) )
282 const wxString& )
const
300 const wxString& aFieldName,
301 const wxString& aVariantName,
322 if( field->IsPrivate() )
348 const wxString& aFieldName )
357 const wxString& aAttributeName,
358 const wxString& aValue,
359 const wxString& aVariantName )
361 bool attrChanged =
false;
362 bool newValue = aValue == wxS(
"1" );
363 bool defaultVariant = aVariantName.IsEmpty()
366 if( aAttributeName == wxS(
"${DNP}" ) )
376 variant->SetDNP( newValue );
379 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOARD}" ) )
383 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_BOM}" ) )
393 variant->SetExcludedFromBOM( newValue );
396 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_SIM}" ) )
406 variant->SetExcludedFromSim( newValue );
409 else if( aAttributeName == wxS(
"${EXCLUDE_FROM_POS_FILES}" ) )
419 variant->SetExcludedFromPosFiles( newValue );
436 static_cast<WX_GRID*
>( GetView() )->CommitPendingChanges(
true );
438 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0,
m_rows.size() );
439 GetView()->ProcessTableMessage( msg );
450 if(
m_scope == SCOPE::SCOPE_SELECTION
485 bool isExcluded =
false;
509 if( !footprintSheetPath.empty() )
510 footprintSheetPath.pop_back();
512 if( (
m_scope == SCOPE::SCOPE_SHEET && footprintSheetPath !=
m_path )
513 || (
m_scope == SCOPE::SCOPE_SHEET_RECURSIVE
519 bool matchFound =
false;
537 row.m_items.push_back( ref );
543 row.m_items.push_back( ref );
544 row.m_state = ROW_STATE::GROUP_COLLAPSED;
555 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_rows.size() );
556 GetView()->ProcessTableMessage( msg );
566 const wxString& aVariantName )
568 bool defaultVariant = aVariantName.IsEmpty()
570 bool footprintModified =
false;
574 const std::map<wxString, wxString> fieldStore =
getStoredFields( aSourceRef, aVariantName );
576 for(
const auto& [srcName, srcValue] : fieldStore )
581 footprintModified |=
setAttributeValue( destRef, srcName, srcValue, aVariantName );
607 if( destField && destField->
IsPrivate() )
609 if( srcValue.IsEmpty() )
614 footprintModified =
true;
620 bool createField = !destField;
631 if( aTemplateFieldnames )
634 destField->
SetVisible( srcTemplate->m_Visible );
641 aDestFootprint.
Add( destField );
642 footprintModified =
true;
649 wxString newValue = srcValue;
653 newValue = board->ConvertCrossReferencesToKIIDs( srcValue );
655 if( previousValue != newValue )
660 destField->
SetText( newValue );
661 footprintModified =
true;
665 variant->SetFieldValue( srcName, newValue );
666 footprintModified =
true;
671 for(
int ii =
static_cast<int>( aDestFootprint.
GetFields().size() ) - 1; ii >= 0; ii-- )
685 parentGroup->RemoveItem( field );
687 aDestFootprint.
Remove( field );
689 footprintModified =
true;
693 return footprintModified;
708 std::unique_ptr<FOOTPRINT> footprintCopy = std::make_unique<FOOTPRINT>( footprint );
709 footprintCopy->SetParentGroup(
nullptr );
712 bool modified =
false;
718 aCommit.
Modified( &footprint, footprintCopy.release() );
748 return ref == aFootprint;
780 size_t curNumRows =
m_rows.size();
782 if( aPosition >= curNumRows )
784 wxFAIL_MSG( wxString::Format( wxT(
"Called FOOTPRINT_FIELDS_EDITOR_GRID_DATA_MODEL::DeleteRows(aPosition=%lu, "
785 "aNumRows=%lu)\nPosition value is invalid for present table with %lu rows" ),
786 (
unsigned long) aPosition, (
unsigned long) aNumRows,
787 (
unsigned long) curNumRows ) );
792 if( aNumRows > curNumRows - aPosition )
794 aNumRows = curNumRows - aPosition;
797 if( aNumRows >= curNumRows )
805 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aPosition, aNumRows );
806 GetView()->ProcessTableMessage( msg );
813 auto first =
m_rows.begin() + aPosition;
814 auto last = first + aNumRows;
817 for(
auto it = first; it != last && it !=
m_rows.end(); ++it )
820 refsToDelete.push_back( ref );
842 wxCHECK( aCol >= 0 && aCol <
static_cast<int>(
m_cols.size() ),
false );
856 const wxString& aFieldName, wxString& aValue )
889 bool footprintModified =
false;
896 footprintModified =
true;
903 footprintModified =
true;
907 aRef, aFootprint,
nullptr, wxEmptyString );
909 return footprintModified;
915 bool allChangesApplied =
true;
923 FOOTPRINT changedFootprint( ref.GetFootprint() );
937 if( !aChangeHandler( changedFootprint ) )
939 allChangesApplied =
false;
943 ref.GetFootprint() = changedFootprint;
951 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)
std::map< KIID_PATH, std::map< wxString, FIELD_STORE_VALUE > > m_dataStore
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
bool groupMatch(const FOOTPRINT_REF &lhItem, const FOOTPRINT_REF &rhItem)
void setStoredFieldValue(const FOOTPRINT_REF &aItem, const wxString &aFieldName, const wxString &aValue)
void initializeDataStoreItem(const FOOTPRINT_REF &aItem)
bool storedFieldIsRemoved(const FOOTPRINT_REF &aItem, const wxString &aName) const
bool getStoredFieldValue(const FOOTPRINT_REF &aItem, const wxString &aFieldName, wxString &aValue) const
std::vector< DATA_MODEL_ROW< FOOTPRINT_REF > > m_rows
bool resolveStoredTextVar(const FOOTPRINT_REF &aItem, wxString *aToken, bool aCaseSensitive=false) const
bool IsCellReadOnly(int aRow, int aCol) override
std::map< wxString, wxString > getStoredFields(const FOOTPRINT_REF &aItem, const wxString &aVariant) const
void refreshDataStoreItem(const FOOTPRINT_REF &aItem)
bool MatchesFilter(const FOOTPRINT_REF &aItem, const wxString &aReference, EDA_COMBINED_MATCHER &aMatcher)
void acceptDataStoreItem(const FOOTPRINT_REF &aItem)
std::set< wxString > storedVariants(const FOOTPRINT_REF &aItem) const
bool IsContainedWithin(const KIID_PATH &aParentPath) const
virtual wxString GetFootprint() const
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()
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".
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...