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 (C) 1992-2023 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef PCB_FIELD_H
26#define PCB_FIELD_H
27
28#include <pcb_text.h>
29#include <template_fieldnames.h>
30
32
33class PCB_FIELD : public PCB_TEXT
34{
35public:
36 PCB_FIELD( FOOTPRINT* aParent, int aFieldId, const wxString& aName = wxEmptyString );
37
38 PCB_FIELD( const PCB_TEXT& aText, int aFieldId, const wxString& aName = wxEmptyString );
39
40 void Serialize( google::protobuf::Any &aContainer ) const override;
41 bool Deserialize( const google::protobuf::Any &aContainer ) override;
42
43 static inline bool ClassOf( const EDA_ITEM* aItem )
44 {
45 return aItem && PCB_FIELD_T == aItem->Type();
46 }
47
48 wxString GetClass() const override { return wxT( "PCB_FIELD" ); }
49
50 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
51 {
52 if( BOARD_ITEM::IsType( aScanTypes ) )
53 return true;
54
55 for( KICAD_T scanType : aScanTypes )
56 {
58 return true;
59 else if( scanType == PCB_FIELD_LOCATE_VALUE_T && m_id == VALUE_FIELD )
60 return true;
61 else if( scanType == PCB_FIELD_LOCATE_FOOTPRINT_T && m_id == FOOTPRINT_FIELD )
62 return true;
63 else if( scanType == PCB_FIELD_LOCATE_DATASHEET_T && m_id == DATASHEET_FIELD )
64 return true;
65 }
66
67 return false;
68 }
69
70 bool IsReference() const { return m_id == REFERENCE_FIELD; }
71 bool IsValue() const { return m_id == VALUE_FIELD; }
72 bool IsFootprint() const { return m_id == FOOTPRINT_FIELD; }
73 bool IsDatasheet() const { return m_id == DATASHEET_FIELD; }
74 bool IsComponentClass() const { return GetName() == wxT( "Component Class" ); }
75
76 bool IsMandatoryField() const { return m_id < MANDATORY_FIELDS; }
77
78 wxString GetTextTypeDescription() const override;
79
80 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
81
82 double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
83
84 EDA_ITEM* Clone() const override;
85
91 PCB_FIELD* CloneField() const { return (PCB_FIELD*) Clone(); }
92
100 wxString GetName( bool aUseDefaultName = true ) const;
101
106 wxString GetCanonicalName() const;
107
108 void SetName( const wxString& aName ) { m_name = aName; }
109
110 int GetId() const { return m_id; }
111 void SetId( int aId ) { m_id = aId; }
112
113 double Similarity( const BOARD_ITEM& aOther ) const override;
114
115 bool operator==( const PCB_FIELD& aOther ) const;
116 bool operator==( const BOARD_ITEM& aOther ) const override;
117
118protected:
119 void swapData( BOARD_ITEM* aImage ) override;
120
121private:
122 void setId( int aId ) { m_id = aId; }
123
124 int m_id;
125
126 wxString m_name;
127};
128
129#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:79
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:176
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
bool IsDatasheet() const
Definition: pcb_field.h:73
void setId(int aId)
Definition: pcb_field.h:122
bool operator==(const PCB_FIELD &aOther) const
Definition: pcb_field.cpp:222
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: pcb_field.h:50
wxString GetTextTypeDescription() const override
Definition: pcb_field.cpp:133
bool IsReference() const
Definition: pcb_field.h:70
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: pcb_field.cpp:92
bool IsComponentClass() const
Definition: pcb_field.h:74
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: pcb_field.cpp:49
bool IsValue() const
Definition: pcb_field.h:71
wxString m_name
Definition: pcb_field.h:126
int m_id
Field index,.
Definition: pcb_field.h:124
bool IsFootprint() const
Definition: pcb_field.h:72
bool IsMandatoryField() const
Definition: pcb_field.h:76
int GetId() const
Definition: pcb_field.h:110
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: pcb_field.cpp:111
void SetName(const wxString &aName)
Definition: pcb_field.h:108
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: pcb_field.cpp:170
void swapData(BOARD_ITEM *aImage) override
Definition: pcb_field.cpp:203
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition: pcb_field.cpp:228
static bool ClassOf(const EDA_ITEM *aItem)
Definition: pcb_field.h:43
wxString GetClass() const override
Return the class name.
Definition: pcb_field.h:48
void SetId(int aId)
Definition: pcb_field.h:111
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: pcb_field.cpp:64
PCB_FIELD * CloneField() const
Same as Clone, but returns a PCB_FIELD item.
Definition: pcb_field.h:91
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_field.cpp:197
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: pcb_field.cpp:142
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ PCB_FIELD_LOCATE_VALUE_T
Definition: typeinfo.h:116
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition: typeinfo.h:90
@ PCB_FIELD_LOCATE_REFERENCE_T
Definition: typeinfo.h:115
@ PCB_FIELD_LOCATE_DATASHEET_T
Definition: typeinfo.h:118
@ PCB_FIELD_LOCATE_FOOTPRINT_T
Definition: typeinfo.h:117