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)
 

Function Documentation

static size_t hash_board_item ( const BOARD_ITEM aItem,
int  aFlags 
)
inlinestatic

Definition at line 37 of file hash_eda.cpp.

References BOARD_ITEM::GetLayerSet().

Referenced by hash_eda().

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 }
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Class LAYER holds information pertinent to a layer of a BOARD.
Definition: class_board.h:87
size_t hash_eda ( const EDA_ITEM aItem,
int  aFlags 
)

Definition at line 48 of file hash_eda.cpp.

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::GraphicalItemsList(), hash_board_item(), hash_eda(), i, EDA_TEXT::IsBold(), EDA_TEXT::IsItalic(), EDA_TEXT::IsMirrored(), NET, MODULE::PadsList(), 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().

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( const BOARD_ITEM* i = module->GraphicalItemsList(); i; i = i->Next() )
70  ret ^= hash_eda( i, aFlags );
71 
72  for( const D_PAD* i = module->PadsList(); i; i = i->Next() )
73  ret ^= hash_eda( 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 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
use coordinates relative to the parent object
Definition: hash_eda.h:40
bool IsItalic() const
Definition: eda_text.h:183
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
TEXT_TYPE GetType() const
const wxPoint & GetPos0() const
int GetTextWidth() const
Definition: eda_text.h:231
const wxPoint & GetEnd0() const
const wxPoint & GetPos0() const
Definition: class_pad.h:263
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:388
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:216
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:203
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
Field Reference of part, i.e. "IC21".
double GetTextAngle() const
Definition: eda_text.h:177
bool IsBold() const
Definition: eda_text.h:186
class MODULE, a footprint
Definition: typeinfo.h:89
#define VALUE
STROKE_T GetShape() const
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
double GetOrientation() const
Definition: class_module.h:188
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:143
const wxSize & GetSize() const
Definition: class_pad.h:269
Definition: hash_eda.h:43
int GetType() const
static size_t hash_board_item(const BOARD_ITEM *aItem, int aFlags)
Definition: hash_eda.cpp:37
int GetNetCode() const
Function GetNetCode.
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:204
double GetAngle() const
const wxPoint & GetStart0() const
bool IsMirrored() const
Definition: eda_text.h:192
virtual const wxPoint GetPosition() const override
size_t i
Definition: json11.cpp:597
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:382
const wxSize & GetDelta() const
Definition: class_pad.h:272
int GetWidth() const
int GetTextHeight() const
Definition: eda_text.h:234
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:165
DLIST< D_PAD > & PadsList()
Definition: class_module.h:162
const wxPoint GetPosition() const override
Definition: class_pad.h:220
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
size_t hash_eda(const EDA_ITEM *aItem, int aFlags)
Definition: hash_eda.cpp:48
int GetRadius() const
Function GetRadius returns the radius of this item Has meaning only for arc and circle.
const wxPoint GetPosition() const override
Definition: class_module.h:183
const wxPoint & GetOffset() const
Definition: class_pad.h:278