KiCad PCB EDA Suite
hash_eda.cpp File Reference
#include <hash_eda.h>
#include <hash.h>
#include <footprint.h>
#include <fp_text.h>
#include <fp_textbox.h>
#include <fp_shape.h>
#include <pad.h>
#include <functional>

Go to the source code of this file.

Functions

static size_t hash_board_item (const BOARD_ITEM *aItem, int aFlags)
 
size_t hash_fp_item (const EDA_ITEM *aItem, int aFlags)
 Calculate hash of an EDA_ITEM. More...
 

Function Documentation

◆ hash_board_item()

static size_t hash_board_item ( const BOARD_ITEM aItem,
int  aFlags 
)
inlinestatic

Definition at line 39 of file hash_eda.cpp.

40{
41 size_t ret = 0;
42
43 if( aFlags & HASH_LAYER )
44 ret = hash<unsigned long long>{}( aItem->GetLayerSet().to_ullong() );
45
46 return ret;
47}
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:197
@ HASH_LAYER
Definition: hash_eda.h:48

References BOARD_ITEM::GetLayerSet(), and HASH_LAYER.

Referenced by hash_fp_item().

◆ hash_fp_item()

size_t hash_fp_item ( const EDA_ITEM aItem,
int  aFlags = HASH_FLAGS::HASH_ALL 
)

Calculate hash of an EDA_ITEM.

Parameters
aItemis the item for which the hash will be computed.
Returns
Hash value.

Definition at line 50 of file hash_eda.cpp.

51{
52 size_t ret = 0;
53
54 switch( aItem->Type() )
55 {
56 case PCB_FOOTPRINT_T:
57 {
58 const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( aItem );
59
60 ret = hash_board_item( footprint, aFlags );
61
62 if( aFlags & HASH_POS )
63 hash_combine( ret, footprint->GetPosition().x, footprint->GetPosition().y );
64
65 if( aFlags & HASH_ROT )
66 hash_combine( ret, footprint->GetOrientation().AsDegrees() );
67
68 for( BOARD_ITEM* item : footprint->GraphicalItems() )
69 hash_combine( ret, hash_fp_item( item, aFlags ) );
70
71 for( PAD* pad : footprint->Pads() )
72 hash_combine( ret, hash_fp_item( static_cast<EDA_ITEM*>( pad ), aFlags ) );
73 }
74 break;
75
76 case PCB_PAD_T:
77 {
78 const PAD* pad = static_cast<const PAD*>( aItem );
79
80 ret = hash<int>{}( static_cast<int>( pad->GetShape() ) );
81 hash_combine( ret, pad->GetDrillShape() );
82 hash_combine( ret, pad->GetSize().x, pad->GetSize().y );
83 hash_combine( ret, pad->GetOffset().x, pad->GetOffset().y );
84 hash_combine( ret, pad->GetDelta().x, pad->GetDelta().y );
85
86 hash_combine( ret, hash_board_item( pad, aFlags ) );
87
88 if( aFlags & HASH_POS )
89 {
90 if( aFlags & REL_COORD )
91 hash_combine( ret, pad->GetPos0().x, pad->GetPos0().y );
92 else
93 hash_combine( ret, pad->GetPosition().x, pad->GetPosition().y );
94 }
95
96 if( aFlags & HASH_ROT )
97 hash_combine( ret, pad->GetOrientation().AsDegrees() );
98
99 if( aFlags & HASH_NET )
100 hash_combine( ret, pad->GetNetCode() );
101 }
102 break;
103
104 case PCB_FP_TEXT_T:
105 {
106 const FP_TEXT* text = static_cast<const FP_TEXT*>( aItem );
107
108 if( !( aFlags & HASH_REF ) && text->GetType() == FP_TEXT::TEXT_is_REFERENCE )
109 break;
110
111 if( !( aFlags & HASH_VALUE ) && text->GetType() == FP_TEXT::TEXT_is_VALUE )
112 break;
113
114 ret = hash_board_item( text, aFlags );
115 hash_combine( ret, text->GetText().ToStdString() );
116 hash_combine( ret, text->IsItalic() );
117 hash_combine( ret, text->IsBold() );
118 hash_combine( ret, text->IsMirrored() );
119 hash_combine( ret, text->GetTextWidth() );
120 hash_combine( ret, text->GetTextHeight() );
121 hash_combine( ret, text->GetHorizJustify() );
122 hash_combine( ret, text->GetVertJustify() );
123
124 if( aFlags & HASH_POS )
125 {
126 if( aFlags & REL_COORD )
127 hash_combine( ret, text->GetPos0().x, text->GetPos0().y );
128 else
129 hash_combine( ret, text->GetPosition().x, text->GetPosition().y );
130 }
131
132 if( aFlags & HASH_ROT )
133 hash_combine( ret, text->GetTextAngle().AsDegrees() );
134 }
135 break;
136
137 case PCB_FP_SHAPE_T:
138 {
139 const FP_SHAPE* shape = static_cast<const FP_SHAPE*>( aItem );
140 ret = hash_board_item( shape, aFlags );
141 hash_combine( ret, shape->GetShape() );
142 hash_combine( ret, shape->GetWidth() );
143 hash_combine( ret, shape->IsFilled() );
144
145 if( shape->GetShape() == SHAPE_T::ARC || shape->GetShape() == SHAPE_T::CIRCLE )
146 hash_combine( ret, shape->GetRadius() );
147
148 if( aFlags & HASH_POS )
149 {
150 if( aFlags & REL_COORD )
151 {
152 hash_combine( ret, shape->GetStart0().x );
153 hash_combine( ret, shape->GetStart0().y );
154 hash_combine( ret, shape->GetEnd0().x );
155 hash_combine( ret, shape->GetEnd0().y );
156
157 if( shape->GetShape() == SHAPE_T::ARC )
158 {
159 hash_combine( ret, shape->GetCenter0().x );
160 hash_combine( ret, shape->GetCenter0().y );
161 }
162 }
163 else
164 {
165 hash_combine( ret, shape->GetStart().x );
166 hash_combine( ret, shape->GetStart().y );
167 hash_combine( ret, shape->GetEnd().x );
168 hash_combine( ret, shape->GetEnd().y );
169
170 if( shape->GetShape() == SHAPE_T::ARC )
171 {
172 hash_combine( ret, shape->GetCenter().x );
173 hash_combine( ret, shape->GetCenter().y );
174 }
175 }
176 }
177 }
178 break;
179
180 case PCB_FP_TEXTBOX_T:
181 {
182 const FP_TEXTBOX* textbox = static_cast<const FP_TEXTBOX*>( aItem );
183
184 ret = hash_board_item( textbox, aFlags );
185 hash_combine( ret, textbox->GetText().ToStdString() );
186 hash_combine( ret, textbox->IsItalic() );
187 hash_combine( ret, textbox->IsBold() );
188 hash_combine( ret, textbox->IsMirrored() );
189 hash_combine( ret, textbox->GetTextWidth() );
190 hash_combine( ret, textbox->GetTextHeight() );
191 hash_combine( ret, textbox->GetHorizJustify() );
192 hash_combine( ret, textbox->GetVertJustify() );
193
194 if( aFlags & HASH_ROT )
195 hash_combine( ret, textbox->GetTextAngle().AsDegrees() );
196
197 hash_combine( ret, textbox->GetShape() );
198 hash_combine( ret, textbox->GetWidth() );
199
200 if( aFlags & HASH_POS )
201 {
202 if( aFlags & REL_COORD )
203 {
204 hash_combine( ret, textbox->GetStart0().x );
205 hash_combine( ret, textbox->GetStart0().y );
206 hash_combine( ret, textbox->GetEnd0().x );
207 hash_combine( ret, textbox->GetEnd0().y );
208 }
209 else
210 {
211 hash_combine( ret, textbox->GetStart().x );
212 hash_combine( ret, textbox->GetStart().y );
213 hash_combine( ret, textbox->GetEnd().x );
214 hash_combine( ret, textbox->GetEnd().y );
215 }
216 }
217 }
218 break;
219
220 default:
221 wxASSERT_MSG( false, "Unhandled type in function hash_fp_item() (exporter_gencad.cpp)" );
222 }
223
224 return ret;
225}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:70
double AsDegrees() const
Definition: eda_angle.h:149
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
bool IsFilled() const
Definition: eda_shape.h:90
int GetRadius() const
Definition: eda_shape.cpp:523
SHAPE_T GetShape() const
Definition: eda_shape.h:113
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:145
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:120
int GetWidth() const
Definition: eda_shape.h:109
int GetTextHeight() const
Definition: eda_text.h:202
bool IsItalic() const
Definition: eda_text.h:130
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:120
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
int GetTextWidth() const
Definition: eda_text.h:199
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:149
bool IsMirrored() const
Definition: eda_text.h:139
bool IsBold() const
Definition: eda_text.h:133
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:152
EDA_ANGLE GetOrientation() const
Definition: footprint.h:191
PADS & Pads()
Definition: footprint.h:170
VECTOR2I GetPosition() const override
Definition: footprint.h:188
DRAWINGS & GraphicalItems()
Definition: footprint.h:173
const VECTOR2I & GetEnd0() const
Definition: fp_shape.h:95
VECTOR2I GetCenter0() const
Definition: fp_shape.cpp:144
const VECTOR2I & GetStart0() const
Definition: fp_shape.h:92
@ TEXT_is_REFERENCE
Definition: fp_text.h:49
@ TEXT_is_VALUE
Definition: fp_text.h:50
Definition: pad.h:59
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.h:67
static void hash_combine(std::size_t &seed)
This is a dummy function to take the final case of hash_combine below.
Definition: hash.h:34
size_t hash_fp_item(const EDA_ITEM *aItem, int aFlags)
Calculate hash of an EDA_ITEM.
Definition: hash_eda.cpp:50
static size_t hash_board_item(const BOARD_ITEM *aItem, int aFlags)
Definition: hash_eda.cpp:39
@ HASH_POS
use coordinates relative to the parent object
Definition: hash_eda.h:43
@ HASH_VALUE
Definition: hash_eda.h:51
@ REL_COORD
Definition: hash_eda.h:46
@ HASH_REF
Definition: hash_eda.h:50
@ HASH_ROT
Definition: hash_eda.h:47
@ HASH_NET
Definition: hash_eda.h:49
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
@ PCB_FP_TEXTBOX_T
class FP_TEXTBOX, wrapped text in a footprint
Definition: typeinfo.h:93
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ PCB_FP_TEXT_T
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92

References ARC, EDA_ANGLE::AsDegrees(), CIRCLE, PCB_SHAPE::GetCenter(), FP_SHAPE::GetCenter0(), EDA_SHAPE::GetEnd(), FP_SHAPE::GetEnd0(), EDA_TEXT::GetHorizJustify(), FOOTPRINT::GetOrientation(), FOOTPRINT::GetPosition(), EDA_SHAPE::GetRadius(), EDA_SHAPE::GetShape(), EDA_SHAPE::GetStart(), FP_SHAPE::GetStart0(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextHeight(), EDA_TEXT::GetTextWidth(), EDA_TEXT::GetVertJustify(), EDA_SHAPE::GetWidth(), FOOTPRINT::GraphicalItems(), hash_board_item(), hash_combine(), hash_fp_item(), HASH_NET, HASH_POS, HASH_REF, HASH_ROT, HASH_VALUE, EDA_TEXT::IsBold(), EDA_SHAPE::IsFilled(), EDA_TEXT::IsItalic(), EDA_TEXT::IsMirrored(), pad, FOOTPRINT::Pads(), PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_TEXTBOX_T, PCB_PAD_T, REL_COORD, text, FP_TEXT::TEXT_is_REFERENCE, FP_TEXT::TEXT_is_VALUE, EDA_ITEM::Type(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by hash_fp_item(), and hashFootprint().