KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_3d_body.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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#ifndef PCB_3D_BODY_H
21#define PCB_3D_BODY_H
22
24#include <board_item.h>
25#include <gal/color4d.h>
26#include <math/vector3.h>
27
28class PCB_3D_BODY;
29
37
39{
40public:
41 EXTRUDED_3D_BODY() = default;
42
43 int m_height = 0;
44 int m_standoff = 0;
48 bool m_show = true;
49
50 VECTOR3D m_scale{ 1.0, 1.0, 1.0 };
51 VECTOR3D m_rotation{ 0.0, 0.0, 0.0 };
52 VECTOR3D m_offset{ 0.0, 0.0, 0.0 };
53
55 {
56 switch( aMaterial )
57 {
58 default:
59 case EXTRUSION_MATERIAL::PLASTIC: return KIGFX::COLOR4D( 0.2, 0.2, 0.2, 1.0 );
60 case EXTRUSION_MATERIAL::MATTE: return KIGFX::COLOR4D( 0.4, 0.4, 0.4, 1.0 );
61 case EXTRUSION_MATERIAL::METAL: return KIGFX::COLOR4D( 0.7, 0.7, 0.7, 1.0 );
62 case EXTRUSION_MATERIAL::COPPER: return KIGFX::COLOR4D( 0.72, 0.45, 0.2, 1.0 );
63 }
64 }
65
66 bool operator==( const EXTRUDED_3D_BODY& aOther ) const
67 {
68 return m_height == aOther.m_height && m_standoff == aOther.m_standoff && m_layer == aOther.m_layer
69 && m_color == aOther.m_color && m_material == aOther.m_material && m_scale == aOther.m_scale
70 && m_rotation == aOther.m_rotation && m_offset == aOther.m_offset && m_show == aOther.m_show;
71 }
72
73 static uint32_t PackColorKey( const KIGFX::COLOR4D& aColor )
74 {
75 return ( (uint8_t) ( aColor.r * 255 ) << 24 ) | ( (uint8_t) ( aColor.g * 255 ) << 16 )
76 | ( (uint8_t) ( aColor.b * 255 ) << 8 ) | (uint8_t) ( aColor.a * 255 );
77 }
78};
79
80namespace kiapi::board::types
81{
82class Body3D;
83}
84
92class PCB_3D_BODY : public BOARD_ITEM
93{
94public:
95 enum class KIND
96 {
98 MODEL // reserved; not constructible yet
99 };
100
101 explicit PCB_3D_BODY( BOARD_ITEM* aParent = nullptr );
102
103 static inline bool ClassOf( const EDA_ITEM* aItem )
104 {
105 return aItem && PCB_3D_BODY_T == aItem->Type();
106 }
107
108 wxString GetClass() const override { return wxT( "PCB_3D_BODY" ); }
109
110 wxString GetFriendlyName() const override { return _( "3D Body" ); }
111
112 KIND GetKind() const { return m_kind; }
113
114 const EXTRUDED_3D_BODY* GetExtruded() const { return &m_extruded; }
116
122 PCB_LAYER_ID GetLayer() const override { return m_extruded.m_layer; }
123 void SetLayer( PCB_LAYER_ID aLayer ) override { m_extruded.m_layer = aLayer; }
124
126 bool IsLayerAgnostic() const override { return true; }
127
128 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
129
130 void Serialize( google::protobuf::Any& aContainer ) const override;
131 bool Deserialize( const google::protobuf::Any& aContainer ) override;
132 void Serialize( kiapi::board::types::Body3D& aOutput ) const;
133 bool Deserialize( const kiapi::board::types::Body3D& aInput );
134
135 EDA_ITEM* Clone() const override { return new PCB_3D_BODY( *this ); }
136
137 void CopyFrom( const BOARD_ITEM* aOther ) override;
138
139 std::vector<int> ViewGetLayers() const override
140 {
141 return {};
142 }
143
144 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override
145 {
146 return _( "3D Body" );
147 }
148
149 BITMAPS GetMenuImage() const override
150 {
151 return BITMAPS::dummy_item;
152 }
153
154 double Similarity( const BOARD_ITEM& aOther ) const override;
155
156 bool operator==( const PCB_3D_BODY& aOther ) const;
157 bool operator==( const BOARD_ITEM& aOther ) const override;
158
159#if defined( DEBUG )
160 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
161#endif
162
163protected:
164 void swapData( BOARD_ITEM* aImage ) override;
165
166private:
169};
170
171#endif // PCB_3D_BODY_H
BITMAPS
A list of all bitmap identifiers.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:87
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
bool operator==(const EXTRUDED_3D_BODY &aOther) const
Definition pcb_3d_body.h:66
KIGFX::COLOR4D m_color
Definition pcb_3d_body.h:46
VECTOR3D m_offset
Definition pcb_3d_body.h:52
EXTRUDED_3D_BODY()=default
PCB_LAYER_ID m_layer
Definition pcb_3d_body.h:45
static KIGFX::COLOR4D GetDefaultColor(EXTRUSION_MATERIAL aMaterial)
Definition pcb_3d_body.h:54
VECTOR3D m_rotation
Definition pcb_3d_body.h:51
static uint32_t PackColorKey(const KIGFX::COLOR4D &aColor)
Definition pcb_3d_body.h:73
EXTRUSION_MATERIAL m_material
Definition pcb_3d_body.h:47
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
double r
Red component.
Definition color4d.h:391
double g
Green component.
Definition color4d.h:392
double a
Alpha component.
Definition color4d.h:394
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:400
double b
Blue component.
Definition color4d.h:393
A 3D body attached to a footprint (or, later, placed on a board).
Definition pcb_3d_body.h:93
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
bool operator==(const PCB_3D_BODY &aOther) const
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
static bool ClassOf(const EDA_ITEM *aItem)
PCB_3D_BODY(BOARD_ITEM *aParent=nullptr)
PCB_LAYER_ID GetLayer() const override
The payload layer names the outline source (auto, pad bbox, or a real layer), so it is semantic rathe...
KIND GetKind() const
const EXTRUDED_3D_BODY * GetExtruded() const
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
wxString GetFriendlyName() const override
bool IsLayerAgnostic() const override
Check if this item's layer set must not be confined to a board's enabled layers.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
wxString GetClass() const override
Return the class name.
void CopyFrom(const BOARD_ITEM *aOther) override
EXTRUDED_3D_BODY m_extruded
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void swapData(BOARD_ITEM *aImage) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
EXTRUDED_3D_BODY * MutableExtruded()
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
FLIP_DIRECTION
Definition mirror.h:23
EXTRUSION_MATERIAL
Definition pcb_3d_body.h:31
@ PCB_3D_BODY_T
class PCB_3D_BODY, a 3D body (extruded or model) on a footprint
Definition typeinfo.h:241
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR3< double > VECTOR3D
Definition vector3.h:230