KiCad PCB EDA Suite
hash_eda.h File Reference
#include <cstdlib>

Go to the source code of this file.

Enumerations

enum  HASH_FLAGS {
  POSITION = 0x01, REL_COORD = 0x02, ROTATION = 0x04, LAYER = 0x08,
  NET = 0x10, REFERENCE = 0x20, VALUE = 0x40, ALL = 0xff
}
 

Enables/disables properties that will be used for calculating the hash.

More...
 

Functions

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

Enumeration Type Documentation

◆ HASH_FLAGS

enum HASH_FLAGS

Enables/disables properties that will be used for calculating the hash.

The properties might be combined using the bitwise 'or' operator.

Enumerator
POSITION 
REL_COORD 

use coordinates relative to the parent object

ROTATION 
LAYER 
NET 
REFERENCE 
VALUE 
ALL 

Definition at line 35 of file hash_eda.h.

36 {
37  POSITION = 0x01,
38 
40  REL_COORD = 0x02,
41  ROTATION = 0x04,
42  LAYER = 0x08,
43  NET = 0x10,
44  REFERENCE = 0x20,
45  VALUE = 0x40,
46  ALL = 0xff
47 };
use coordinates relative to the parent object
Definition: hash_eda.h:40
Definition: hash_eda.h:45
Definition: hash_eda.h:46
Definition: hash_eda.h:43
Class LAYER holds information pertinent to a layer of a BOARD.
Definition: class_board.h:80

Function Documentation

◆ hash_eda()

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

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:167
double GetOrientation() const
Definition: class_module.h:202
int GetNetCode() const
Function GetNetCode.
const wxPoint & GetPos0() const
Definition: class_pad.h:278
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:185
use coordinates relative to the parent object
Definition: hash_eda.h:40
bool IsMirrored() const
Definition: eda_text.h:173
STROKE_T GetShape() const
PADS & Pads()
Definition: class_module.h:165
int GetType() const
double GetTextAngle() const
Definition: eda_text.h:158
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
DRAWINGS & GraphicalItems()
Definition: class_module.h:175
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:229
bool IsItalic() const
Definition: eda_text.h:164
const wxPoint & GetStart0() const
class MODULE, a footprint
Definition: typeinfo.h:89
#define VALUE
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:184
const wxPoint & GetOffset() const
Definition: class_pad.h:293
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:412
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:287
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:226
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:406
virtual const wxPoint GetPosition() const override
size_t i
Definition: json11.cpp:597
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:221
const wxSize & GetSize() const
Definition: class_pad.h:284
const wxPoint GetPosition() const override
Definition: class_pad.h:225
size_t hash_eda(const EDA_ITEM *aItem, int aFlags)
Definition: hash_eda.cpp:48
const wxPoint GetPosition() const override
Definition: class_module.h:197
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

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(), i, 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(), and VALUE.

Referenced by hash_eda(), and hashModule().