Gencad export: fix an issue in hash_eda calculation,
that can generate the same hash for 2 different footprints. Therefore, for some footprints, the right footprint was not associated to the component. The hash calculation was using a XOR to combine 2 sub hash values. This is not a reliable way to combine these hash values. They are now added. Looks better to identify similar and different footprints. Fixes: lp:1847575 https://bugs.launchpad.net/kicad/+bug/1847575
This commit is contained in:
parent
0d64b38dbc
commit
6506f77689
|
@ -39,7 +39,7 @@ static inline size_t hash_board_item( const BOARD_ITEM* aItem, int aFlags )
|
||||||
size_t ret = 0;
|
size_t ret = 0;
|
||||||
|
|
||||||
if( aFlags & LAYER )
|
if( aFlags & LAYER )
|
||||||
ret ^= hash<unsigned long long>{}( aItem->GetLayerSet().to_ullong() );
|
ret = hash<unsigned long long>{}( aItem->GetLayerSet().to_ullong() );
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -55,57 +55,57 @@ size_t hash_eda( const EDA_ITEM* aItem, int aFlags )
|
||||||
{
|
{
|
||||||
const MODULE* module = static_cast<const MODULE*>( aItem );
|
const MODULE* module = static_cast<const MODULE*>( aItem );
|
||||||
|
|
||||||
ret ^= hash_board_item( module, aFlags );
|
ret += hash_board_item( module, aFlags );
|
||||||
|
|
||||||
if( aFlags & POSITION )
|
if( aFlags & POSITION )
|
||||||
{
|
{
|
||||||
ret ^= hash<int>{}( module->GetPosition().x );
|
ret += hash<int>{}( module->GetPosition().x );
|
||||||
ret ^= hash<int>{}( module->GetPosition().y );
|
ret += hash<int>{}( module->GetPosition().y );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( aFlags & ROTATION )
|
if( aFlags & ROTATION )
|
||||||
ret ^= hash<double>{}( module->GetOrientation() );
|
ret += hash<double>{}( module->GetOrientation() );
|
||||||
|
|
||||||
for( const BOARD_ITEM* i = module->GraphicalItemsList(); i; i = i->Next() )
|
for( const BOARD_ITEM* i = module->GraphicalItemsList(); i; i = i->Next() )
|
||||||
ret ^= hash_eda( i, aFlags );
|
ret += hash_eda( i, aFlags );
|
||||||
|
|
||||||
for( const D_PAD* i = module->PadsList(); i; i = i->Next() )
|
for( const D_PAD* i = module->PadsList(); i; i = i->Next() )
|
||||||
ret ^= hash_eda( i, aFlags );
|
ret += hash_eda( i, aFlags );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PCB_PAD_T:
|
case PCB_PAD_T:
|
||||||
{
|
{
|
||||||
const D_PAD* pad = static_cast<const D_PAD*>( aItem );
|
const D_PAD* pad = static_cast<const D_PAD*>( aItem );
|
||||||
ret ^= hash_board_item( pad, aFlags );
|
ret += hash_board_item( pad, aFlags );
|
||||||
ret ^= hash<int>{}( pad->GetShape() << 16 );
|
ret += hash<int>{}( pad->GetShape() << 16 );
|
||||||
ret ^= hash<int>{}( pad->GetDrillShape() << 18 );
|
ret += hash<int>{}( pad->GetDrillShape() << 18 );
|
||||||
ret ^= hash<int>{}( pad->GetSize().x << 8 );
|
ret += hash<int>{}( pad->GetSize().x << 8 );
|
||||||
ret ^= hash<int>{}( pad->GetSize().y << 9 );
|
ret += hash<int>{}( pad->GetSize().y << 9 );
|
||||||
ret ^= hash<int>{}( pad->GetOffset().x << 6 );
|
ret += hash<int>{}( pad->GetOffset().x << 6 );
|
||||||
ret ^= hash<int>{}( pad->GetOffset().y << 7 );
|
ret += hash<int>{}( pad->GetOffset().y << 7 );
|
||||||
ret ^= hash<int>{}( pad->GetDelta().x << 4 );
|
ret += hash<int>{}( pad->GetDelta().x << 4 );
|
||||||
ret ^= hash<int>{}( pad->GetDelta().y << 5 );
|
ret += hash<int>{}( pad->GetDelta().y << 5 );
|
||||||
|
|
||||||
if( aFlags & POSITION )
|
if( aFlags & POSITION )
|
||||||
{
|
{
|
||||||
if( aFlags & REL_COORD )
|
if( aFlags & REL_COORD )
|
||||||
{
|
{
|
||||||
ret ^= hash<int>{}( pad->GetPos0().x );
|
ret += hash<int>{}( pad->GetPos0().x );
|
||||||
ret ^= hash<int>{}( pad->GetPos0().y );
|
ret += hash<int>{}( pad->GetPos0().y );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret ^= hash<int>{}( pad->GetPosition().x );
|
ret += hash<int>{}( pad->GetPosition().x );
|
||||||
ret ^= hash<int>{}( pad->GetPosition().y );
|
ret += hash<int>{}( pad->GetPosition().y );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( aFlags & ROTATION )
|
if( aFlags & ROTATION )
|
||||||
ret ^= hash<double>{}( pad->GetOrientation() );
|
ret += hash<double>{}( pad->GetOrientation() );
|
||||||
|
|
||||||
if( aFlags & NET )
|
if( aFlags & NET )
|
||||||
ret ^= hash<int>{}( pad->GetNetCode() << 6 );
|
ret += hash<int>{}( pad->GetNetCode() << 6 );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -119,64 +119,64 @@ size_t hash_eda( const EDA_ITEM* aItem, int aFlags )
|
||||||
if( !( aFlags & VALUE ) && text->GetType() == TEXTE_MODULE::TEXT_is_VALUE )
|
if( !( aFlags & VALUE ) && text->GetType() == TEXTE_MODULE::TEXT_is_VALUE )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ret ^= hash_board_item( text, aFlags );
|
ret += hash_board_item( text, aFlags );
|
||||||
ret ^= hash<string>{}( text->GetText().ToStdString() );
|
ret += hash<string>{}( text->GetText().ToStdString() );
|
||||||
ret ^= hash<bool>{}( text->IsItalic() );
|
ret += hash<bool>{}( text->IsItalic() );
|
||||||
ret ^= hash<bool>{}( text->IsBold() );
|
ret += hash<bool>{}( text->IsBold() );
|
||||||
ret ^= hash<bool>{}( text->IsMirrored() );
|
ret += hash<bool>{}( text->IsMirrored() );
|
||||||
ret ^= hash<int>{}( text->GetTextWidth() );
|
ret += hash<int>{}( text->GetTextWidth() );
|
||||||
ret ^= hash<int>{}( text->GetTextHeight() );
|
ret += hash<int>{}( text->GetTextHeight() );
|
||||||
ret ^= hash<int>{}( text->GetHorizJustify() );
|
ret += hash<int>{}( text->GetHorizJustify() );
|
||||||
ret ^= hash<int>{}( text->GetVertJustify() );
|
ret += hash<int>{}( text->GetVertJustify() );
|
||||||
|
|
||||||
if( aFlags & POSITION )
|
if( aFlags & POSITION )
|
||||||
{
|
{
|
||||||
if( aFlags & REL_COORD )
|
if( aFlags & REL_COORD )
|
||||||
{
|
{
|
||||||
ret ^= hash<int>{}( text->GetPos0().x );
|
ret += hash<int>{}( text->GetPos0().x );
|
||||||
ret ^= hash<int>{}( text->GetPos0().y );
|
ret += hash<int>{}( text->GetPos0().y );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret ^= hash<int>{}( text->GetPosition().x );
|
ret += hash<int>{}( text->GetPosition().x );
|
||||||
ret ^= hash<int>{}( text->GetPosition().y );
|
ret += hash<int>{}( text->GetPosition().y );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( aFlags & ROTATION )
|
if( aFlags & ROTATION )
|
||||||
ret ^= hash<double>{}( text->GetTextAngle() );
|
ret += hash<double>{}( text->GetTextAngle() );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PCB_MODULE_EDGE_T:
|
case PCB_MODULE_EDGE_T:
|
||||||
{
|
{
|
||||||
const EDGE_MODULE* segment = static_cast<const EDGE_MODULE*>( aItem );
|
const EDGE_MODULE* segment = static_cast<const EDGE_MODULE*>( aItem );
|
||||||
ret ^= hash_board_item( segment, aFlags );
|
ret += hash_board_item( segment, aFlags );
|
||||||
ret ^= hash<int>{}( segment->GetType() );
|
ret += hash<int>{}( segment->GetType() );
|
||||||
ret ^= hash<int>{}( segment->GetShape() );
|
ret += hash<int>{}( segment->GetShape() );
|
||||||
ret ^= hash<int>{}( segment->GetWidth() );
|
ret += hash<int>{}( segment->GetWidth() );
|
||||||
ret ^= hash<int>{}( segment->GetRadius() );
|
ret += hash<int>{}( segment->GetRadius() );
|
||||||
|
|
||||||
if( aFlags & POSITION )
|
if( aFlags & POSITION )
|
||||||
{
|
{
|
||||||
if( aFlags & REL_COORD )
|
if( aFlags & REL_COORD )
|
||||||
{
|
{
|
||||||
ret ^= hash<int>{}( segment->GetStart0().x );
|
ret += hash<int>{}( segment->GetStart0().x );
|
||||||
ret ^= hash<int>{}( segment->GetStart0().y );
|
ret += hash<int>{}( segment->GetStart0().y );
|
||||||
ret ^= hash<int>{}( segment->GetEnd0().x );
|
ret += hash<int>{}( segment->GetEnd0().x );
|
||||||
ret ^= hash<int>{}( segment->GetEnd0().y );
|
ret += hash<int>{}( segment->GetEnd0().y );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret ^= hash<int>{}( segment->GetStart().x );
|
ret += hash<int>{}( segment->GetStart().x );
|
||||||
ret ^= hash<int>{}( segment->GetStart().y );
|
ret += hash<int>{}( segment->GetStart().y );
|
||||||
ret ^= hash<int>{}( segment->GetEnd().x );
|
ret += hash<int>{}( segment->GetEnd().x );
|
||||||
ret ^= hash<int>{}( segment->GetEnd().y );
|
ret += hash<int>{}( segment->GetEnd().y );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( aFlags & ROTATION )
|
if( aFlags & ROTATION )
|
||||||
ret ^= hash<double>{}( segment->GetAngle() );
|
ret += hash<double>{}( segment->GetAngle() );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ enum HASH_FLAGS
|
||||||
ALL = 0xff
|
ALL = 0xff
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Calculates hash of an EDA_ITEM.
|
* Calculates hash of an EDA_ITEM.
|
||||||
* @param aItem is the item for which the hash will be computed.
|
* @param aItem is the item for which the hash will be computed.
|
||||||
* @return Hash value.
|
* @return Hash value.
|
||||||
|
|
|
@ -50,7 +50,7 @@ DIALOG_GENCAD_EXPORT_OPTIONS::DIALOG_GENCAD_EXPORT_OPTIONS( PCB_EDIT_FRAME* aPar
|
||||||
|
|
||||||
wxBoxSizer* m_fileSizer = new wxBoxSizer( wxHORIZONTAL );
|
wxBoxSizer* m_fileSizer = new wxBoxSizer( wxHORIZONTAL );
|
||||||
|
|
||||||
m_filePath = new wxTextCtrl( this, wxID_ANY, fn.GetFullPath() );
|
m_filePath = new wxTextCtrl( this, wxID_ANY );
|
||||||
m_fileSizer->Add( m_filePath, 1, wxEXPAND | wxRIGHT, 5 );
|
m_fileSizer->Add( m_filePath, 1, wxEXPAND | wxRIGHT, 5 );
|
||||||
|
|
||||||
wxButton* m_browseBtn = new wxButton( this, wxID_ANY, _( "Browse" ) );
|
wxButton* m_browseBtn = new wxButton( this, wxID_ANY, _( "Browse" ) );
|
||||||
|
@ -73,6 +73,10 @@ DIALOG_GENCAD_EXPORT_OPTIONS::DIALOG_GENCAD_EXPORT_OPTIONS( PCB_EDIT_FRAME* aPar
|
||||||
Layout();
|
Layout();
|
||||||
m_mainSizer->Fit( this );
|
m_mainSizer->Fit( this );
|
||||||
|
|
||||||
|
// Now the widgets sizes are fixed, we can initialize the m_filePath value.
|
||||||
|
// It will be correctly displayed
|
||||||
|
m_filePath->SetValue( fn.GetFullPath() );
|
||||||
|
|
||||||
Centre( wxBOTH );
|
Centre( wxBOTH );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -721,10 +721,10 @@ static size_t hashModule( const MODULE* aModule )
|
||||||
| HASH_FLAGS::ROTATION | HASH_FLAGS::LAYER;
|
| HASH_FLAGS::ROTATION | HASH_FLAGS::LAYER;
|
||||||
|
|
||||||
for( const BOARD_ITEM* i = aModule->GraphicalItemsList(); i; i = i->Next() )
|
for( const BOARD_ITEM* i = aModule->GraphicalItemsList(); i; i = i->Next() )
|
||||||
ret ^= hash_eda( i, flags );
|
ret += hash_eda( i, flags );
|
||||||
|
|
||||||
for( const D_PAD* i = aModule->PadsList(); i; i = i->Next() )
|
for( const D_PAD* i = aModule->PadsList(); i; i = i->Next() )
|
||||||
ret ^= hash_eda( i, flags );
|
ret += hash_eda( i, flags );
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue