KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_fields_data_model.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
23
24#include <vector>
25
26
27class BOARD_COMMIT;
28class FOOTPRINT;
29class TEMPLATES;
30
38{
39public:
40 explicit FOOTPRINT_REF( FOOTPRINT& aFootprint ) :
41 m_footprint( &aFootprint )
42 {
43 }
44
45 FOOTPRINT& GetFootprint() const { return *m_footprint; }
46 bool operator==( const FOOTPRINT_REF& aOther ) const { return m_footprint == aOther.m_footprint; }
47
48private:
50};
51
52using FOOTPRINT_REFERENCE_LIST = std::vector<FOOTPRINT_REF>;
53
55
57{
58public:
66
68 m_footprintsList( aFootprintReferenceList ),
70 {
71 }
72
73 wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind ) override;
74
75 void SetValue( int aRow, int aCol, const wxString& aValue ) override;
76
77 void RebuildRows() override;
78
79 void ApplyData( BOARD_COMMIT& aCommit, TEMPLATES& aTemplateFieldnames );
80
81 void SetScope( SCOPE aScope ) { m_scope = aScope; }
82 SCOPE GetScope() { return m_scope; }
83
84 void SetPath( const KIID_PATH& aPath ) { m_path = aPath; }
85 const KIID_PATH& GetPath() { return m_path; }
86
87 void AddReferences( const FOOTPRINT_REFERENCE_LIST& aRefs );
88 void RemoveReferences( const FOOTPRINT_REFERENCE_LIST& aRefs );
89 void RemoveFootprint( const FOOTPRINT_REF& aRef );
90 void UpdateReferences( const FOOTPRINT_REFERENCE_LIST& aRefs );
91
92 bool DeleteRows( size_t aPosition = 0, size_t aNumRows = 1 ) override;
93
95
96 bool ColIsReadOnly( int aCol ) const override;
97
98private:
99 bool fieldSupportsVariants( const wxString& aFieldName ) const override;
100
101 bool unitMatch( const FOOTPRINT_REF& lhItem, const FOOTPRINT_REF& rhItem ) override;
102
107 bool attributeForcedOnBySheet( const FOOTPRINT_REF& aRef, const wxString& aAttributeName,
108 const wxString& aVariantName ) const override;
109
110 wxString getAttributeValue( const FOOTPRINT_REF& aRef, const wxString& aAttributeName,
111 const wxString& aVariantNames );
112 bool getLiveFieldValueForVariant( const FOOTPRINT_REF& aRef, const wxString& aFieldName,
113 const wxString& aVariantName, wxString& aValue ) override;
114
124 wxString getDefaultFieldValue( const FOOTPRINT_REF& aRef, const wxString& aFieldName );
125
126protected:
130 bool applyDataToFootprint( const FOOTPRINT_REF& aSourceRef, FOOTPRINT& aDestFootprint,
131 TEMPLATES* aTemplateFieldnames, const wxString& aVariantName );
132
143 bool setAttributeValue( const FOOTPRINT_REF& aReference, const wxString& aAttributeName, const wxString& aValue,
144 const wxString& aVariantName = wxEmptyString );
145
146 bool getLiveFieldValue( const FOOTPRINT_REF& aRef, const wxString& aFieldName,
147 wxString& aValue ) override;
148
149private:
150 std::vector<FOOTPRINT_REF> getAllItems() const override;
151
152 wxString getFieldResolvedLiveValue( const FOOTPRINT_REF& aRef, const wxString& aFieldName ) override;
153 wxString resolveTextVars( const FOOTPRINT_REF& aRef, const wxString& aText ) override;
154
155 KIID_PATH getDataStoreKey( const FOOTPRINT_REF& aItem ) const override;
156 wxString getItemIdentifier( const FOOTPRINT_REF& aItem ) const override;
157
158protected:
162};
163
164
166{
167public:
168 static const wxString FOOTPRINT_NAME;
169 static const wxString FOOTPRINT_KEYWORDS;
170 static const wxString FOOTPRINT_LIBRARY_DESCRIPTION;
171
173
174 bool ColIsItemIdentifier( int aCol ) const override;
175
176 bool ApplyData( std::function<bool( FOOTPRINT& )> aChangeHandler );
177
178private:
179 bool fieldSupportsVariants( const wxString& aFieldName ) const override { return false; }
180 bool fieldIsItemProperty( const wxString& aFieldName ) const override;
181
182 bool getLiveFieldValueForVariant( const FOOTPRINT_REF& aRef, const wxString& aFieldName, const wxString& aVariant,
183 wxString& aValue ) override
184 {
185 return getLiveFieldValue( aRef, aFieldName, aValue );
186 }
187
188 bool getLiveFieldValue( const FOOTPRINT_REF& aRef, const wxString& aFieldName,
189 wxString& aValue ) override;
190
191 wxString getItemIdentifier( const FOOTPRINT_REF& aRef ) const override;
192
193 bool applyDataToFootprint( const FOOTPRINT_REF& aRef, FOOTPRINT& aFootprint );
194};
The rest of the generic fields data model stuff, primarily around row functionality.
bool getLiveFieldValue(const FOOTPRINT_REF &aRef, const wxString &aFieldName, wxString &aValue) override
Gets the current value of the field from the live item, e.g.
const FOOTPRINT_REFERENCE_LIST & GetReferenceList() const
bool fieldSupportsVariants(const wxString &aFieldName) const override
KIID_PATH getDataStoreKey(const FOOTPRINT_REF &aItem) const override
Data store UUID for a footprint is just the footprint's UUID, since footprints are unique across the ...
bool DeleteRows(size_t aPosition=0, size_t aNumRows=1) override
std::vector< FOOTPRINT_REF > getAllItems() const override
bool unitMatch(const FOOTPRINT_REF &lhItem, const FOOTPRINT_REF &rhItem) override
FOOTPRINT_FIELDS_EDITOR_GRID_DATA_MODEL(const FOOTPRINT_REFERENCE_LIST &aFootprintReferenceList)
void UpdateReferences(const FOOTPRINT_REFERENCE_LIST &aRefs)
wxString getDefaultFieldValue(const FOOTPRINT_REF &aRef, const wxString &aFieldName)
Get the default (non-variant) value for a field.
bool attributeForcedOnBySheet(const FOOTPRINT_REF &aRef, const wxString &aAttributeName, const wxString &aVariantName) const override
Footprint attributes are don't currently track when they are inherited from the sheet,...
void AddReferences(const FOOTPRINT_REFERENCE_LIST &aRefs)
void RemoveReferences(const FOOTPRINT_REFERENCE_LIST &aRefs)
void ApplyData(BOARD_COMMIT &aCommit, TEMPLATES &aTemplateFieldnames)
bool setAttributeValue(const FOOTPRINT_REF &aReference, const wxString &aAttributeName, const wxString &aValue, const wxString &aVariantName=wxEmptyString)
Set the attribute value.
wxString getAttributeValue(const FOOTPRINT_REF &aRef, const wxString &aAttributeName, const wxString &aVariantNames)
wxString getItemIdentifier(const FOOTPRINT_REF &aItem) const override
wxString getFieldResolvedLiveValue(const FOOTPRINT_REF &aRef, const wxString &aFieldName) override
Explicitly bypasses the data store's field values and retries them from the item's current field valu...
wxString resolveTextVars(const FOOTPRINT_REF &aRef, const wxString &aText) override
void SetValue(int aRow, int aCol, const wxString &aValue) override
bool applyDataToFootprint(const FOOTPRINT_REF &aSourceRef, FOOTPRINT &aDestFootprint, TEMPLATES *aTemplateFieldnames, const wxString &aVariantName)
Returns whether or the the aDestFootprint was changed by applying the data from aSourceRef.
bool getLiveFieldValueForVariant(const FOOTPRINT_REF &aRef, const wxString &aFieldName, const wxString &aVariantName, wxString &aValue) override
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind) override
This is the minimal equivalent to the SCH_REFERENCE so we can provide similar non-null guarantees thr...
FOOTPRINT & GetFootprint() const
bool operator==(const FOOTPRINT_REF &aOther) const
FOOTPRINT_REF(FOOTPRINT &aFootprint)
LIB_FOOTPRINT_FIELDS_EDITOR_GRID_DATA_MODEL(const FOOTPRINT_REFERENCE_LIST &aFootprints)
bool getLiveFieldValueForVariant(const FOOTPRINT_REF &aRef, const wxString &aFieldName, const wxString &aVariant, wxString &aValue) override
bool getLiveFieldValue(const FOOTPRINT_REF &aRef, const wxString &aFieldName, wxString &aValue) override
Gets the current value of the field from the live item, e.g.
bool ColIsItemIdentifier(int aCol) const override
Reference for symbol/fields tables, lib_id for lib tables.
bool fieldIsItemProperty(const wxString &aFieldName) const override
bool ApplyData(std::function< bool(FOOTPRINT &)> aChangeHandler)
bool applyDataToFootprint(const FOOTPRINT_REF &aRef, FOOTPRINT &aFootprint)
wxString getItemIdentifier(const FOOTPRINT_REF &aRef) const override
bool fieldSupportsVariants(const wxString &aFieldName) const override
std::vector< FOOTPRINT_REF > FOOTPRINT_REFERENCE_LIST
DATA_MODEL_ROW< FOOTPRINT_REF > FOOTPRINT_FIELDS_TABLE_DATA_MODEL_ROW