From a179893d700ad5a5a5ccb28d4ff5031043e2d62b Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 29 Dec 2020 17:35:03 +0100 Subject: [PATCH] specctra_export: fix an issue with custom pads. From Master, commit 686254. In some cases a created pad stack name had the same name as an other pad stack having a slightly different shape, thus creating pads with a incorrect shape on board. Fixes #6495 for the 5.1.10 branch. --- common/md5_hash.cpp | 28 +++++++++++++++++++ include/md5_hash.h | 8 ++++++ .../specctra_export.cpp | 5 ++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/common/md5_hash.cpp b/common/md5_hash.cpp index 0c9f650b8b..6ed83b6c42 100644 --- a/common/md5_hash.cpp +++ b/common/md5_hash.cpp @@ -92,6 +92,34 @@ bool MD5_HASH::operator!=( const MD5_HASH& aOther ) const } +std::string MD5_HASH::Format( bool aCompactForm ) +{ + std::string data; + + // Build a hexadecimal string from the 16 bytes of MD5_HASH: + for( int ii = 0; ii < 16; ++ii ) + { + char lsb = ( m_hash[ii] & 0x0F ) + '0'; + + if( lsb > '9' ) + lsb += 'A'-'9'; + + char msb = ( ( m_hash[ii] >> 4 ) & 0x0F ) + '0'; + + if( msb > '9' ) + msb += 'A'-'9'; + + data += msb; + data += lsb; + + if( !aCompactForm ) + data += ' '; + } + + return data; +} + + void MD5_HASH::md5_transform(MD5_CTX *ctx, uint8_t data[]) { uint32_t a,b,c,d,m[16],i,j; diff --git a/include/md5_hash.h b/include/md5_hash.h index 1c8fe98934..240fe92163 100644 --- a/include/md5_hash.h +++ b/include/md5_hash.h @@ -6,6 +6,7 @@ #define __MD5_HASH_H #include +#include class MD5_HASH { @@ -29,6 +30,13 @@ public: bool operator==( const MD5_HASH& aOther ) const; bool operator!=( const MD5_HASH& aOther ) const; + /** @return a hexadecimal string from the 16 bytes of MD5_HASH + * Mainly for debug purposes. + * @param aCompactForm = false to generate a string with spaces between each byte (2 chars) + * = true to generate a string filled with 32 hexadecimal chars + */ + std::string Format( bool aCompactForm = false ); + private: struct MD5_CTX { uint8_t data[64]; diff --git a/pcbnew/specctra_import_export/specctra_export.cpp b/pcbnew/specctra_import_export/specctra_export.cpp index 1b5ea27a89..b91e9c2f59 100644 --- a/pcbnew/specctra_import_export/specctra_export.cpp +++ b/pcbnew/specctra_import_export/specctra_export.cpp @@ -594,11 +594,12 @@ PADSTACK* SPECCTRA_DB::makePADSTACK( BOARD* aBoard, D_PAD* aPad ) } // this string _must_ be unique for a given physical shape, so try to make it unique + MD5_HASH hash = pad_shape.GetHash(); EDA_RECT rect = aPad->GetBoundingBox(); - snprintf( name, sizeof(name), "Cust%sPad_%.6gx%.6g_%.6gx_%.6g_%d_um", + snprintf( name, sizeof(name), "Cust%sPad_%.6gx%.6g_%.6gx_%.6g_%d_um_%s", uniqifier.c_str(), IU2um( aPad->GetSize().x ), IU2um( aPad->GetSize().y ), IU2um( rect.GetWidth() ), IU2um( rect.GetHeight() ), - (int)polygonal_shape.size() ); + (int)polygonal_shape.size(), hash.Format( true ).c_str() ); name[ sizeof(name)-1 ] = 0; padstack->SetPadstackId( name );