KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_field.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 (C) 2023 Mike Williams, [email protected]
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef PCB_FIELD_H
22#define PCB_FIELD_H
23
24#include <pcb_text.h>
25#include <template_fieldnames.h>
26
28
29class PCB_FIELD : public PCB_TEXT
30{
31public:
32 PCB_FIELD( FOOTPRINT* aParent, FIELD_T aFieldId, const wxString& aName = wxEmptyString );
33
34 PCB_FIELD( const PCB_TEXT& aText, FIELD_T aFieldId, const wxString& aName = wxEmptyString );
35
36 void Serialize( google::protobuf::Any &aContainer ) const override;
37 bool Deserialize( const google::protobuf::Any &aContainer ) override;
38
39 void CopyFrom( const BOARD_ITEM* aOther ) override;
40
41 static inline bool ClassOf( const EDA_ITEM* aItem )
42 {
43 return aItem && PCB_FIELD_T == aItem->Type();
44 }
45
46 wxString GetClass() const override { return wxT( "PCB_FIELD" ); }
47
48 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
49 {
50 if( BOARD_ITEM::IsType( aScanTypes ) )
51 return true;
52
53 for( KICAD_T scanType : aScanTypes )
54 {
56 return true;
57 else if( scanType == PCB_FIELD_LOCATE_VALUE_T && m_id == FIELD_T::VALUE )
58 return true;
59 else if( scanType == PCB_FIELD_LOCATE_DATASHEET_T && m_id == FIELD_T::DATASHEET )
60 return true;
61 }
62
63 return false;
64 }
65
66 bool IsReference() const { return m_id == FIELD_T::REFERENCE; }
67 bool IsValue() const { return m_id == FIELD_T::VALUE; }
68 bool IsDatasheet() const { return m_id == FIELD_T::DATASHEET; }
69 bool IsComponentClass() const { return GetName() == wxT( "Component Class" ); }
70
71 bool IsMandatory() const;
72
73 bool HasHypertext() const;
74
75 wxString GetTextTypeDescription() const override;
76
77 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
78
79 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
80
81 double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
82
83 EDA_ITEM* Clone() const override;
84
90 PCB_FIELD* CloneField() const { return (PCB_FIELD*) Clone(); }
91
98 wxString GetName( bool aUseDefaultName = true ) const;
99
104 wxString GetCanonicalName() const;
105
106 wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
107
108 void SetName( const wxString& aName ) { m_name = aName; }
109
110 FIELD_T GetId() const { return m_id; }
111
112 int GetOrdinal() const
113 {
114 return IsMandatory() ? (int) m_id : m_ordinal;
115 }
116 void SetOrdinal( int aOrdinal )
117 {
119 m_ordinal = aOrdinal;
120 }
121
122 double Similarity( const BOARD_ITEM& aOther ) const override;
123
124 bool operator==( const PCB_FIELD& aOther ) const;
125 bool operator==( const BOARD_ITEM& aOther ) const override;
126
127protected:
128 void swapData( BOARD_ITEM* aImage ) override;
129
130private:
131 void setId( FIELD_T aId ) { m_id = aId; }
132
133private:
136 wxString m_name;
137};
138
139#endif
Container for design settings for a BOARD object.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:83
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition eda_item.h:202
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:37
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
bool IsMandatory() const
FIELD_T GetId() const
Definition pcb_field.h:110
bool IsDatasheet() const
Definition pcb_field.h:68
void SetOrdinal(int aOrdinal)
Definition pcb_field.h:116
bool operator==(const PCB_FIELD &aOther) const
PCB_FIELD(FOOTPRINT *aParent, FIELD_T aFieldId, const wxString &aName=wxEmptyString)
Definition pcb_field.cpp:35
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition pcb_field.h:48
void setId(FIELD_T aId)
Definition pcb_field.h:131
wxString GetTextTypeDescription() const override
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
void CopyFrom(const BOARD_ITEM *aOther) override
bool IsReference() const
Definition pcb_field.h:66
bool HasHypertext() const
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
bool IsComponentClass() const
Definition pcb_field.h:69
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition pcb_field.cpp:61
bool IsValue() const
Definition pcb_field.h:67
wxString m_name
Definition pcb_field.h:136
FIELD_T m_id
Field id,.
Definition pcb_field.h:134
int m_ordinal
Sort order for non-mandatory fields.
Definition pcb_field.h:135
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
int GetOrdinal() const
Definition pcb_field.h:112
void SetName(const wxString &aName)
Definition pcb_field.h:108
void swapData(BOARD_ITEM *aImage) override
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
static bool ClassOf(const EDA_ITEM *aItem)
Definition pcb_field.h:41
wxString GetClass() const override
Return the class name.
Definition pcb_field.h:46
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition pcb_field.cpp:77
PCB_FIELD * CloneField() const
Same as Clone, but returns a PCB_FIELD item.
Definition pcb_field.h:90
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
PCB_TEXT(BOARD_ITEM *parent, KICAD_T idtype=PCB_TEXT_T)
Definition pcb_text.cpp:49
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ USER
The field ID hasn't been set yet; field is invalid.
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71
@ PCB_FIELD_LOCATE_VALUE_T
Definition typeinfo.h:112
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:83
@ PCB_FIELD_LOCATE_REFERENCE_T
Definition typeinfo.h:111
@ PCB_FIELD_LOCATE_DATASHEET_T
Definition typeinfo.h:114