KiCad PCB EDA Suite
hash_eda.cpp File Reference
#include <hash_eda.h>
#include <footprint.h>
#include <fp_text.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 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
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:178

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

50 {
51  size_t ret = 0;
52 
53  switch( aItem->Type() )
54  {
55  case PCB_FOOTPRINT_T:
56  {
57  const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( aItem );
58 
59  ret = hash_board_item( footprint, aFlags );
60 
61  if( aFlags & HASH_POS )
62  hash_combine( ret, footprint->GetPosition().x, footprint->GetPosition().y );
63 
64  if( aFlags & HASH_ROT )
65  hash_combine( ret, footprint->GetOrientation() );
66 
67  for( BOARD_ITEM* item : footprint->GraphicalItems() )
68  hash_combine( ret, hash_fp_item( item, aFlags ) );
69 
70  for( PAD* pad : footprint->Pads() )
71  hash_combine( ret, hash_fp_item( static_cast<EDA_ITEM*>( pad ), aFlags ) );
72  }
73  break;
74 
75  case PCB_PAD_T:
76  {
77  const PAD* pad = static_cast<const 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_FP_TEXT_T:
107  {
108  const FP_TEXT* text = static_cast<const FP_TEXT*>( aItem );
109 
110  if( !( aFlags & HASH_REF ) && text->GetType() == FP_TEXT::TEXT_is_REFERENCE )
111  break;
112 
113  if( !( aFlags & HASH_VALUE ) && text->GetType() == FP_TEXT::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_FP_SHAPE_T:
140  {
141  const FP_SHAPE* segment = static_cast<const FP_SHAPE*>( aItem );
142  ret = hash_board_item( segment, aFlags );
143  hash_combine( ret, segment->GetShape() );
144  hash_combine( ret, segment->GetWidth() );
145  hash_combine( ret, segment->IsFilled() );
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 hash_fp_item() (exporter_gencad.cpp)" );
173  }
174 
175  return ret;
176 }
bool IsFilled() const
Definition: pcb_shape.h:96
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
Definition: pcb_shape.h:156
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
use coordinates relative to the parent object
Definition: hash_eda.h:43
int GetRadius() const
Function GetRadius returns the radius of this item Has meaning only for arc and circle.
Definition: pcb_shape.h:201
int GetWidth() const
Definition: pcb_shape.h:118
double GetOrientation() const
Definition: footprint.h:186
const wxPoint & GetStart0() const
Definition: fp_shape.h:112
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
class PAD, a pad in a footprint
Definition: typeinfo.h:89
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:67
PADS & Pads()
Definition: footprint.h:164
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
Definition: pcb_shape.h:145
size_t hash_fp_item(const EDA_ITEM *aItem, int aFlags)
Calculate hash of an EDA_ITEM.
Definition: hash_eda.cpp:49
DRAWINGS & GraphicalItems()
Definition: footprint.h:167
static size_t hash_board_item(const BOARD_ITEM *aItem, int aFlags)
Definition: hash_eda.cpp:38
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
double GetAngle() const
Definition: pcb_shape.h:127
const wxPoint & GetEnd0() const
Definition: fp_shape.h:115
wxPoint GetPosition() const override
Definition: footprint.h:182
PCB_SHAPE_TYPE_T GetShape() const
Definition: pcb_shape.h:130
Definition: pad.h:60
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163

References PCB_SHAPE::GetAngle(), PCB_SHAPE::GetEnd(), FP_SHAPE::GetEnd0(), FOOTPRINT::GetOrientation(), FOOTPRINT::GetPosition(), PCB_SHAPE::GetRadius(), PCB_SHAPE::GetShape(), PCB_SHAPE::GetStart(), FP_SHAPE::GetStart0(), PCB_SHAPE::GetWidth(), FOOTPRINT::GraphicalItems(), hash_board_item(), hash_combine(), hash_fp_item(), HASH_NET, HASH_POS, HASH_REF, HASH_ROT, HASH_VALUE, PCB_SHAPE::IsFilled(), pad, FOOTPRINT::Pads(), PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_PAD_T, REL_COORD, text, FP_TEXT::TEXT_is_REFERENCE, FP_TEXT::TEXT_is_VALUE, and EDA_ITEM::Type().

Referenced by hash_fp_item(), and hashFootprint().