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 38 of file hash_eda.cpp.

39 {
40  size_t ret = 0;
41 
42  if( aFlags & HASH_LAYER )
43  ret = hash<unsigned long long>{}( aItem->GetLayerSet().to_ullong() );
44 
45  return ret;
46 }
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(), and HASH_LAYER.

Referenced by hash_eda().

◆ hash_eda()

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

Calculates hash of an EDA_ITEM.

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

Definition at line 49 of file hash_eda.cpp.

50 {
51  size_t ret = 0;
52 
53  switch( aItem->Type() )
54  {
55  case PCB_MODULE_T:
56  {
57  const MODULE* module = static_cast<const MODULE*>( aItem );
58 
59  ret = hash_board_item( module, aFlags );
60 
61  if( aFlags & HASH_POS )
62  hash_combine( ret, module->GetPosition().x, module->GetPosition().y );
63 
64  if( aFlags & HASH_ROT )
65  hash_combine( ret, module->GetOrientation() );
66 
67  for( auto i : module->GraphicalItems() )
68  hash_combine( ret, hash_eda( i, aFlags ) );
69 
70  for( auto i : module->Pads() )
71  hash_combine( ret, hash_eda( static_cast<EDA_ITEM*>( i ), aFlags ) );
72  }
73  break;
74 
75  case PCB_PAD_T:
76  {
77  const D_PAD* pad = static_cast<const D_PAD*>( aItem );
78 
79  ret = hash<int>{}( pad->GetShape() << 16 );
80  hash_combine( ret, pad->GetDrillShape() << 18 );
81  hash_combine( ret, pad->GetSize().x << 8 );
82  hash_combine( ret, pad->GetSize().y << 9 );
83  hash_combine( ret, pad->GetOffset().x << 6 );
84  hash_combine( ret, pad->GetOffset().y << 7 );
85  hash_combine( ret, pad->GetDelta().x << 4 );
86  hash_combine( ret, pad->GetDelta().y << 5 );
87 
88  hash_combine( ret, hash_board_item( pad, aFlags ) );
89 
90  if( aFlags & HASH_POS )
91  {
92  if( aFlags & REL_COORD )
93  hash_combine( ret, pad->GetPos0().x, pad->GetPos0().y );
94  else
95  hash_combine( ret, pad->GetPosition().x, pad->GetPosition().y );
96  }
97 
98  if( aFlags & HASH_ROT )
99  hash_combine( ret, pad->GetOrientation() );
100 
101  if( aFlags & HASH_NET )
102  hash_combine( ret, pad->GetNetCode() );
103  }
104  break;
105 
106  case PCB_MODULE_TEXT_T:
107  {
108  const TEXTE_MODULE* text = static_cast<const TEXTE_MODULE*>( aItem );
109 
110  if( !( aFlags & HASH_REF ) && text->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE )
111  break;
112 
113  if( !( aFlags & HASH_VALUE ) && text->GetType() == TEXTE_MODULE::TEXT_is_VALUE )
114  break;
115 
116  ret = hash_board_item( text, aFlags );
117  hash_combine( ret, text->GetText().ToStdString() );
118  hash_combine( ret, text->IsItalic() );
119  hash_combine( ret, text->IsBold() );
120  hash_combine( ret, text->IsMirrored() );
121  hash_combine( ret, text->GetTextWidth() );
122  hash_combine( ret, text->GetTextHeight() );
123  hash_combine( ret, text->GetHorizJustify() );
124  hash_combine( ret, text->GetVertJustify() );
125 
126  if( aFlags & HASH_POS )
127  {
128  if( aFlags & REL_COORD )
129  hash_combine( ret, text->GetPos0().x, text->GetPos0().y );
130  else
131  hash_combine( ret, text->GetPosition().x, text->GetPosition().y );
132  }
133 
134  if( aFlags & HASH_ROT )
135  hash_combine( ret, text->GetTextAngle() );
136  }
137  break;
138 
139  case PCB_MODULE_EDGE_T:
140  {
141  const EDGE_MODULE* segment = static_cast<const EDGE_MODULE*>( aItem );
142  ret = hash_board_item( segment, aFlags );
143  hash_combine( ret, segment->GetType() );
144  hash_combine( ret, segment->GetShape() );
145  hash_combine( ret, segment->GetWidth() );
146  hash_combine( ret, segment->GetRadius() );
147 
148  if( aFlags & HASH_POS )
149  {
150  if( aFlags & REL_COORD )
151  {
152  hash_combine( ret, segment->GetStart0().x );
153  hash_combine( ret, segment->GetStart0().y );
154  hash_combine( ret, segment->GetEnd0().x );
155  hash_combine( ret, segment->GetEnd0().y );
156  }
157  else
158  {
159  hash_combine( ret, segment->GetStart().x );
160  hash_combine( ret, segment->GetStart().y );
161  hash_combine( ret, segment->GetEnd().x );
162  hash_combine( ret, segment->GetEnd().y );
163  }
164  }
165 
166  if( aFlags & HASH_ROT )
167  hash_combine( ret, segment->GetAngle() );
168  }
169  break;
170 
171  default:
172  wxASSERT_MSG( false, "Unhandled type in function hashModItem() (exporter_gencad.cpp)" );
173  }
174 
175  return ret;
176 }
bool IsBold() const
Definition: eda_text.h:183
double GetOrientation() const
Definition: class_module.h:221
int GetNetCode() const
Function GetNetCode.
const wxPoint & GetPos0() const
Definition: class_pad.h:218
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:200
use coordinates relative to the parent object
Definition: hash_eda.h:44
bool IsMirrored() const
Definition: eda_text.h:189
wxPoint GetPosition() const override
Definition: class_pad.h:165
STROKE_T GetShape() const
PADS & Pads()
Definition: class_module.h:173
int GetType() const
double GetTextAngle() const
Definition: eda_text.h:174
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
DRAWINGS & GraphicalItems()
Definition: class_module.h:183
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
static void hash_combine(std::size_t &seed)
This is a dummy function to take the final case of hash_combine below.
Definition: hash_eda.h:64
int GetTextHeight() const
Definition: eda_text.h:245
bool IsItalic() const
Definition: eda_text.h:180
const wxPoint & GetStart0() const
class MODULE, a footprint
Definition: typeinfo.h:89
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:199
const wxPoint & GetOffset() const
Definition: class_pad.h:233
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:330
TEXT_TYPE GetType() const
int GetRadius() const
Function GetRadius returns the radius of this item Has meaning only for arc and circle.
const wxSize & GetDelta() const
Definition: class_pad.h:227
static size_t hash_board_item(const BOARD_ITEM *aItem, int aFlags)
Definition: hash_eda.cpp:38
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:242
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:325
const wxPoint & GetEnd0() const
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
wxPoint GetPosition() const override
Definition: class_module.h:216
virtual wxPoint GetPosition() const override
PAD_SHAPE_T GetShape() const
Definition: class_pad.h:157
const wxSize & GetSize() const
Definition: class_pad.h:224
size_t hash_eda(const EDA_ITEM *aItem, int aFlags)
Calculates hash of an EDA_ITEM.
Definition: hash_eda.cpp:49
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

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(), D_PAD::GetPosition(), MODULE::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_combine(), hash_eda(), HASH_NET, HASH_POS, HASH_REF, HASH_ROT, HASH_VALUE, EDA_TEXT::IsBold(), EDA_TEXT::IsItalic(), EDA_TEXT::IsMirrored(), MODULE::Pads(), PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, REL_COORD, TEXTE_MODULE::TEXT_is_REFERENCE, TEXTE_MODULE::TEXT_is_VALUE, EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by hash_eda(), and hashModule().