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
29namespace kiapi::board::types
30{
31 class Field;
32}
33
34class PCB_FIELD : public PCB_TEXT
35{
36public:
37 PCB_FIELD( FOOTPRINT* aParent, FIELD_T aFieldId, const wxString& aName = wxEmptyString );
38
39 PCB_FIELD( const PCB_TEXT& aText, FIELD_T aFieldId, const wxString& aName = wxEmptyString );
40
41 PCB_FIELD( const PCB_FIELD& aField );
42
43 void Serialize( google::protobuf::Any &aContainer ) const override;
44 bool Deserialize( const google::protobuf::Any &aContainer ) override;
45
46 void Serialize( kiapi::board::types::Field& aOutput ) const;
47 bool Deserialize( const kiapi::board::types::Field& aInput );
48
49 void CopyFrom( const BOARD_ITEM* aOther ) override;
50
51 static inline bool ClassOf( const EDA_ITEM* aItem )
52 {
53 return aItem && PCB_FIELD_T == aItem->Type();
54 }
55
56 wxString GetClass() const override { return wxT( "PCB_FIELD" ); }
57
58 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
59 {
60 if( BOARD_ITEM::IsType( aScanTypes ) )
61 return true;
62
63 for( KICAD_T scanType : aScanTypes )
64 {
66 return true;
67 else if( scanType == PCB_FIELD_LOCATE_VALUE_T && m_id == FIELD_T::VALUE )
68 return true;
69 else if( scanType == PCB_FIELD_LOCATE_DATASHEET_T && m_id == FIELD_T::DATASHEET )
70 return true;
71 }
72
73 return false;
74 }
75
76 bool IsReference() const { return m_id == FIELD_T::REFERENCE; }
77 bool IsValue() const { return m_id == FIELD_T::VALUE; }
78 bool IsDatasheet() const { return m_id == FIELD_T::DATASHEET; }
79 bool IsComponentClass() const { return GetName() == wxT( "Component Class" ); }
80 bool IsPrivate() const { return m_private; }
81 void SetPrivate( bool aPrivate ) { m_private = aPrivate; }
82
83 bool IsMandatory() const;
84
85 bool HasHypertext() const;
86
87 wxString GetTextTypeDescription() const override;
88
89 bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
90
91 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
92
93 double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
94
95 EDA_ITEM* Clone() const override;
96
102 PCB_FIELD* CloneField() const { return (PCB_FIELD*) Clone(); }
103
110 wxString GetName( bool aUseDefaultName = true ) const;
111
115 wxString GetUntranslatedName() const;
116
117 wxString GetShownText( RESOLUTION_CONTEXT aContext, int aDepth = 0 ) const override;
118
119 void SetName( const wxString& aName ) { m_name = aName; }
120
121 FIELD_T GetId() const { return m_id; }
122
123 int GetOrdinal() const
124 {
125 return IsMandatory() ? (int) m_id : m_ordinal;
126 }
127 void SetOrdinal( int aOrdinal, FIELD_T aType )
128 {
129 m_id = aType;
130 m_ordinal = aOrdinal;
131 }
132
133 double Similarity( const BOARD_ITEM& aOther ) const override;
134
135 bool operator==( const PCB_FIELD& aOther ) const;
136 bool operator==( const BOARD_ITEM& aOther ) const override;
137
138protected:
139 void swapData( BOARD_ITEM* aImage ) override;
140
141private:
142 void setId( FIELD_T aId ) { m_id = aId; }
143
144private:
147 wxString m_name;
148 bool m_private = false;
149};
150
151#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:84
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition eda_item.h:214
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
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:121
bool IsDatasheet() const
Definition pcb_field.h:78
bool operator==(const PCB_FIELD &aOther) const
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
void SetOrdinal(int aOrdinal, FIELD_T aType)
Definition pcb_field.h:127
PCB_FIELD(FOOTPRINT *aParent, FIELD_T aFieldId, const wxString &aName=wxEmptyString)
Definition pcb_field.cpp:36
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition pcb_field.h:58
void setId(FIELD_T aId)
Definition pcb_field.h:142
wxString GetTextTypeDescription() const override
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
void CopyFrom(const BOARD_ITEM *aOther) override
bool IsReference() const
Definition pcb_field.h:76
bool HasHypertext() const
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
bool IsComponentClass() const
Definition pcb_field.h:79
void SetPrivate(bool aPrivate)
Definition pcb_field.h:81
wxString GetUntranslatedName() const
Get the untranslated field name for storage, variable look-up, etc.
bool m_private
Not fully implemented yet, used in the fields data model.
Definition pcb_field.h:148
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition pcb_field.cpp:75
bool IsValue() const
Definition pcb_field.h:77
wxString m_name
Definition pcb_field.h:147
FIELD_T m_id
Field id,.
Definition pcb_field.h:145
int m_ordinal
Sort order for non-mandatory fields.
Definition pcb_field.h:146
int GetOrdinal() const
Definition pcb_field.h:123
void SetName(const wxString &aName)
Definition pcb_field.h:119
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:51
bool IsPrivate() const
Definition pcb_field.h:80
wxString GetClass() const override
Return the class name.
Definition pcb_field.h:56
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
PCB_FIELD * CloneField() const
Same as Clone, but returns a PCB_FIELD item.
Definition pcb_field.h:102
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
RESOLUTION_CONTEXT
Definition common.h:87
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ 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:70
@ PCB_FIELD_LOCATE_VALUE_T
Definition typeinfo.h:111
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:82
@ PCB_FIELD_LOCATE_REFERENCE_T
Definition typeinfo.h:110
@ PCB_FIELD_LOCATE_DATASHEET_T
Definition typeinfo.h:113