KiCad PCB EDA Suite
hash_eda.cpp File Reference
#include <hash_eda.h>
#include <class_module.h>
#include <class_text_mod.h>
#include <class_edge_mod.h>
#include <class_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_eda (const EDA_ITEM *aItem, int aFlags)
 Calculates 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 37 of file hash_eda.cpp.

38 {
39  size_t ret = 0;
40 
41  if( aFlags & LAYER )
42  ret = hash<unsigned long long>{}( aItem->GetLayerSet().to_ullong() );
43 
44  return ret;
45 }
LAYER holds information pertinent to a layer of a BOARD.
Definition: class_board.h:81
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...

References BOARD_ITEM::GetLayerSet().

Referenced by hash_eda().

◆ hash_eda()

size_t hash_eda ( const EDA_ITEM aItem,
int  aFlags = HASH_FLAGS::ALL 
)

Calculates hash of an EDA_ITEM.

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

Definition at line 48 of file hash_eda.cpp.

49 {
50  size_t ret = 0xa82de1c0;
51 
52  switch( aItem->Type() )
53  {
54  case PCB_MODULE_T:
55  {
56  const MODULE* module = static_cast<const MODULE*>( aItem );
57 
58  ret += hash_board_item( module, aFlags );
59 
60  if( aFlags & POSITION )
61  {
62  ret += hash<int>{}( module->GetPosition().x );
63  ret += hash<int>{}( module->GetPosition().y );
64  }
65 
66  if( aFlags & ROTATION )
67  ret += hash<double>{}( module->GetOrientation() );
68 
69  for( auto i : module->GraphicalItems() )
70  ret += hash_eda( i, aFlags );
71 
72  for( auto i : module->Pads() )
73  ret += hash_eda( static_cast<EDA_ITEM*>( i ), aFlags );
74  }
75  break;
76 
77  case PCB_PAD_T:
78  {
79  const D_PAD* pad = static_cast<const D_PAD*>( aItem );
80  ret += hash_board_item( pad, aFlags );
81  ret += hash<int>{}( pad->GetShape() << 16 );
82  ret += hash<int>{}( pad->GetDrillShape() << 18 );
83  ret += hash<int>{}( pad->GetSize().x << 8 );
84  ret += hash<int>{}( pad->GetSize().y << 9 );
85  ret += hash<int>{}( pad->GetOffset().x << 6 );
86  ret += hash<int>{}( pad->GetOffset().y << 7 );
87  ret += hash<int>{}( pad->GetDelta().x << 4 );
88  ret += hash<int>{}( pad->GetDelta().y << 5 );
89 
90  if( aFlags & POSITION )
91  {
92  if( aFlags & REL_COORD )
93  {
94  ret += hash<int>{}( pad->GetPos0().x );
95  ret += hash<int>{}( pad->GetPos0().y );
96  }
97  else
98  {
99  ret += hash<int>{}( pad->GetPosition().x );
100  ret += hash<int>{}( pad->GetPosition().y );
101  }
102  }
103 
104  if( aFlags & ROTATION )
105  ret += hash<double>{}( pad->GetOrientation() );
106 
107  if( aFlags & NET )
108  ret += hash<int>{}( pad->GetNetCode() << 6 );
109  }
110  break;
111 
112  case PCB_MODULE_TEXT_T:
113  {
114  const TEXTE_MODULE* text = static_cast<const TEXTE_MODULE*>( aItem );
115 
116  if( !( aFlags & REFERENCE ) && text->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE )
117  break;
118 
119  if( !( aFlags & VALUE ) && text->GetType() == TEXTE_MODULE::TEXT_is_VALUE )
120  break;
121 
122  ret += hash_board_item( text, aFlags );
123  ret += hash<string>{}( text->GetText().ToStdString() );
124  ret += hash<bool>{}( text->IsItalic() );
125  ret += hash<bool>{}( text->IsBold() );
126  ret += hash<bool>{}( text->IsMirrored() );
127  ret += hash<int>{}( text->GetTextWidth() );
128  ret += hash<int>{}( text->GetTextHeight() );
129  ret += hash<int>{}( text->GetHorizJustify() );
130  ret += hash<int>{}( text->GetVertJustify() );
131 
132  if( aFlags & POSITION )
133  {
134  if( aFlags & REL_COORD )
135  {
136  ret += hash<int>{}( text->GetPos0().x );
137  ret += hash<int>{}( text->GetPos0().y );
138  }
139  else
140  {
141  ret += hash<int>{}( text->GetPosition().x );
142  ret += hash<int>{}( text->GetPosition().y );
143  }
144  }
145 
146  if( aFlags & ROTATION )
147  ret += hash<double>{}( text->GetTextAngle() );
148  }
149  break;
150 
151  case PCB_MODULE_EDGE_T:
152  {
153  const EDGE_MODULE* segment = static_cast<const EDGE_MODULE*>( aItem );
154  ret += hash_board_item( segment, aFlags );
155  ret += hash<int>{}( segment->GetType() );
156  ret += hash<int>{}( segment->GetShape() );
157  ret += hash<int>{}( segment->GetWidth() );
158  ret += hash<int>{}( segment->GetRadius() );
159 
160  if( aFlags & POSITION )
161  {
162  if( aFlags & REL_COORD )
163  {
164  ret += hash<int>{}( segment->GetStart0().x );
165  ret += hash<int>{}( segment->GetStart0().y );
166  ret += hash<int>{}( segment->GetEnd0().x );
167  ret += hash<int>{}( segment->GetEnd0().y );
168  }
169  else
170  {
171  ret += hash<int>{}( segment->GetStart().x );
172  ret += hash<int>{}( segment->GetStart().y );
173  ret += hash<int>{}( segment->GetEnd().x );
174  ret += hash<int>{}( segment->GetEnd().y );
175  }
176  }
177 
178  if( aFlags & ROTATION )
179  ret += hash<double>{}( segment->GetAngle() );
180  }
181  break;
182 
183  default:
184  wxASSERT_MSG( false, "Unhandled type in function hashModItem() (exporter_gencad.cpp)" );
185  }
186 
187  return ret;
188 }
bool IsBold() const
Definition: eda_text.h:182
double GetOrientation() const
Definition: class_module.h:211
int GetNetCode() const
Function GetNetCode.
const wxPoint & GetPos0() const
Definition: class_pad.h:279
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
use coordinates relative to the parent object
Definition: hash_eda.h:40
bool IsMirrored() const
Definition: eda_text.h:188
STROKE_T GetShape() const
PADS & Pads()
Definition: class_module.h:169
int GetType() const
double GetTextAngle() const
Definition: eda_text.h:173
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
DRAWINGS & GraphicalItems()
Definition: class_module.h:179
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
Field Reference of part, i.e. "IC21".
int GetTextHeight() const
Definition: eda_text.h:244
bool IsItalic() const
Definition: eda_text.h:179
const wxPoint & GetStart0() const
class MODULE, a footprint
Definition: typeinfo.h:89
#define VALUE
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:198
const wxPoint & GetOffset() const
Definition: class_pad.h:294
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:417
TEXT_TYPE GetType() const
int GetRadius() const
Function GetRadius returns the radius of this item Has meaning only for arc and circle.
Definition: hash_eda.h:43
const wxSize & GetDelta() const
Definition: class_pad.h:288
static size_t hash_board_item(const BOARD_ITEM *aItem, int aFlags)
Definition: hash_eda.cpp:37
int GetWidth() const
const wxPoint & GetPos0() const
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
double GetAngle() const
int GetTextWidth() const
Definition: eda_text.h:241
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:411
virtual const wxPoint GetPosition() const override
const wxPoint & GetEnd0() const
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:222
const wxSize & GetSize() const
Definition: class_pad.h:285
const wxPoint GetPosition() const override
Definition: class_pad.h:226
size_t hash_eda(const EDA_ITEM *aItem, int aFlags)
Calculates hash of an EDA_ITEM.
Definition: hash_eda.cpp:48
const wxPoint GetPosition() const override
Definition: class_module.h:206
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

References DRAWSEGMENT::GetAngle(), D_PAD::GetDelta(), D_PAD::GetDrillShape(), DRAWSEGMENT::GetEnd(), EDGE_MODULE::GetEnd0(), EDA_TEXT::GetHorizJustify(), BOARD_CONNECTED_ITEM::GetNetCode(), D_PAD::GetOffset(), MODULE::GetOrientation(), D_PAD::GetOrientation(), TEXTE_MODULE::GetPos0(), D_PAD::GetPos0(), TEXTE_MODULE::GetPosition(), MODULE::GetPosition(), D_PAD::GetPosition(), DRAWSEGMENT::GetRadius(), DRAWSEGMENT::GetShape(), D_PAD::GetShape(), D_PAD::GetSize(), DRAWSEGMENT::GetStart(), EDGE_MODULE::GetStart0(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextHeight(), EDA_TEXT::GetTextWidth(), DRAWSEGMENT::GetType(), TEXTE_MODULE::GetType(), EDA_TEXT::GetVertJustify(), DRAWSEGMENT::GetWidth(), MODULE::GraphicalItems(), hash_board_item(), hash_eda(), EDA_TEXT::IsBold(), EDA_TEXT::IsItalic(), EDA_TEXT::IsMirrored(), NET, MODULE::Pads(), PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, POSITION, REFERENCE, REL_COORD, ROTATION, TEXTE_MODULE::TEXT_is_REFERENCE, TEXTE_MODULE::TEXT_is_VALUE, EDA_ITEM::Type(), VALUE, wxPoint::x, and wxPoint::y.

Referenced by hash_eda(), and hashModule().