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:145

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>{}( static_cast<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* shape = static_cast<const FP_SHAPE*>( aItem );
142  ret = hash_board_item( shape, aFlags );
143  hash_combine( ret, shape->GetShape() );
144  hash_combine( ret, shape->GetWidth() );
145  hash_combine( ret, shape->IsFilled() );
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  hash_combine( ret, shape->GetArcAngle() );
162  }
163  }
164  else
165  {
166  hash_combine( ret, shape->GetStart().x );
167  hash_combine( ret, shape->GetStart().y );
168  hash_combine( ret, shape->GetEnd().x );
169  hash_combine( ret, shape->GetEnd().y );
170 
171  if( shape->GetShape() == SHAPE_T::ARC )
172  {
173  hash_combine( ret, shape->GetCenter().x );
174  hash_combine( ret, shape->GetCenter().y );
175  hash_combine( ret, shape->GetArcAngle() );
176  }
177  }
178  }
179  }
180  break;
181 
182  default:
183  wxASSERT_MSG( false, "Unhandled type in function hash_fp_item() (exporter_gencad.cpp)" );
184  }
185 
186  return ret;
187 }
int GetWidth() const
Definition: eda_shape.h:89
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:97
use coordinates relative to the parent object
Definition: hash_eda.h:43
double GetOrientation() const
Definition: footprint.h:190
double GetArcAngle() const
Definition: eda_shape.cpp:495
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:168
bool IsFilled() const
Definition: eda_shape.h:81
wxPoint GetCenter0() const
Definition: fp_shape.cpp:141
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
wxPoint GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.h:79
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:171
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
const wxPoint & GetEnd0() const
Definition: fp_shape.h:115
wxPoint GetPosition() const override
Definition: footprint.h:186
SHAPE_T GetShape() const
Definition: eda_shape.h:92
int GetRadius() const
Definition: eda_shape.cpp:463
Definition: pad.h:57
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References ARC, EDA_SHAPE::GetArcAngle(), PCB_SHAPE::GetCenter(), FP_SHAPE::GetCenter0(), EDA_SHAPE::GetEnd(), FP_SHAPE::GetEnd0(), FOOTPRINT::GetOrientation(), FOOTPRINT::GetPosition(), EDA_SHAPE::GetRadius(), EDA_SHAPE::GetShape(), EDA_SHAPE::GetStart(), FP_SHAPE::GetStart0(), EDA_SHAPE::GetWidth(), FOOTPRINT::GraphicalItems(), hash_board_item(), hash_combine(), hash_fp_item(), HASH_NET, HASH_POS, HASH_REF, HASH_ROT, HASH_VALUE, EDA_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().