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, const wxString& aVariantName );
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 unitMatch( const FOOTPRINT_REF& lhItem, const FOOTPRINT_REF& rhItem ) override;
100
105 bool attributeForcedOnBySheet( const FOOTPRINT_REF& aRef, const wxString& aAttributeName ) const override;
106
107 wxString getAttributeValue( const FOOTPRINT_REF& aRef, const wxString& aAttributeName,
108 const wxString& aVariantNames );
109 bool getLiveFieldValueForVariant( const FOOTPRINT_REF& aRef, const wxString& aFieldName,
110 const wxString& aVariantName, wxString& aValue );
111
121 wxString getDefaultFieldValue( const FOOTPRINT_REF& aRef, const wxString& aFieldName );
122
123protected:
127 bool applyDataToFootprint( const FOOTPRINT_REF& aSourceRef, FOOTPRINT& aDestFootprint,
128 TEMPLATES* aTemplateFieldnames, const wxString& aVariantName );
129
140 bool setAttributeValue( const FOOTPRINT_REF& aRef, const wxString& aAttributeName, const wxString& aValue,
141 const wxString& aVariantName = wxEmptyString );
142
143 bool getLiveFieldValue( const FOOTPRINT_REF& aRef, const wxString& aFieldName,
144 wxString& aValue ) override;
145
146private:
147 std::vector<FOOTPRINT_REF> getAllItems() const override;
148
149 wxString getFieldResolvedLiveValue( const FOOTPRINT_REF& aRef, const wxString& aFieldName ) override;
150 wxString resolveTextVars( const FOOTPRINT_REF& aRef, const wxString& aText ) override;
151
152 KIID_PATH getDataStoreKey( const FOOTPRINT_REF& aItem ) const override;
153 wxString getItemIdentifier( const FOOTPRINT_REF& aItem ) const override;
154
155protected:
159};
160
161
163{
164public:
165 static const wxString FOOTPRINT_NAME;
166 static const wxString FOOTPRINT_KEYWORDS;
167 static const wxString FOOTPRINT_LIBRARY_DESCRIPTION;
168
170
171 bool ColIsItemIdentifier( int aCol ) const override;
172
173 bool ApplyData( std::function<bool( FOOTPRINT& )> aChangeHandler );
174
175private:
176 bool fieldIsItemProperty( const wxString& aFieldName ) const override;
177
178 bool getLiveFieldValue( const FOOTPRINT_REF& aRef, const wxString& aFieldName,
179 wxString& aValue ) override;
180
181 wxString getItemIdentifier( const FOOTPRINT_REF& aRef ) const override;
182
183 bool applyDataToFootprint( const FOOTPRINT_REF& aRef, FOOTPRINT& aFootprint );
184};
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
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 setAttributeValue(const FOOTPRINT_REF &aRef, const wxString &aAttributeName, const wxString &aValue, const wxString &aVariantName=wxEmptyString)
Set the attribute value.
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.
void AddReferences(const FOOTPRINT_REFERENCE_LIST &aRefs)
void ApplyData(BOARD_COMMIT &aCommit, TEMPLATES &aTemplateFieldnames, const wxString &aVariantName)
void RemoveReferences(const FOOTPRINT_REFERENCE_LIST &aRefs)
bool attributeForcedOnBySheet(const FOOTPRINT_REF &aRef, const wxString &aAttributeName) const override
Footprint attributes are don't currently track when they are inherited from the sheet,...
wxString getAttributeValue(const FOOTPRINT_REF &aRef, const wxString &aAttributeName, const wxString &aVariantNames)
bool getLiveFieldValueForVariant(const FOOTPRINT_REF &aRef, const wxString &aFieldName, const wxString &aVariantName, wxString &aValue)
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.
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 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
std::vector< FOOTPRINT_REF > FOOTPRINT_REFERENCE_LIST
DATA_MODEL_ROW< FOOTPRINT_REF > FOOTPRINT_FIELDS_TABLE_DATA_MODEL_ROW