From 2adc3d48b45ccf68334302f97f2d9a46481c170e Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 17 Jul 2017 14:09:01 +0200 Subject: [PATCH] Eeschema Eagle Import: Assign timestamps for modules --- common/eagle_parser.cpp | 29 ++++++++++++++++++++++------- eeschema/sch_eagle_plugin.cpp | 3 +-- include/eagle_parser.h | 7 +++++++ pcbnew/eagle_plugin.cpp | 7 +++++++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/common/eagle_parser.cpp b/common/eagle_parser.cpp index 50d85301be..1bdea50892 100644 --- a/common/eagle_parser.cpp +++ b/common/eagle_parser.cpp @@ -26,13 +26,9 @@ #include -#include -#include -#include - -#include - -using std::string; +#include +#include +#include // Template specializations below parse wxString to the used types: // - string @@ -175,6 +171,25 @@ unsigned long timeStamp( wxXmlNode* aTree ) } +time_t moduleTstamp( const string& aName, const string& aValue ) +{ + std::size_t h1 = std::hash{}( aName ); + std::size_t h2 = std::hash{}( aValue ); + return ((h1 ^ h2 << 1) & 0xffffffff); +} + + +string modulePath( const string& aName, const string& aValue ) +{ + std::ostringstream s; + + s << '/' << std::setfill('0') << std::uppercase << std::hex << std::setw(8) + << moduleTstamp( aName, aValue ); + + return s.str(); +} + + wxPoint kicad_arc_center( const wxPoint& aStart, const wxPoint& aEnd, double aAngle ) { // Eagle give us start and end. diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index 2014911504..8d6ed41883 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -970,8 +970,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) component->SetConvert( 0 ); component->SetPosition( wxPoint( einstance.x * EUNIT_TO_MIL, -einstance.y * EUNIT_TO_MIL ) ); component->GetField( FOOTPRINT )->SetText( wxString( package ) ); - // component->SetTimeStamp( parseHex( aReader, line, &line ) ); // TODO we need to find a way - // to correlate symbols and footprints + component->SetTimeStamp( moduleTstamp( einstance.part, epart->value ? *epart->value : "" ) ); // component->AddHierarchicalReference( path, reference, (int)tmp ); // TODO ?? if( einstance.rot ) diff --git a/include/eagle_parser.h b/include/eagle_parser.h index 9b80476d9f..05d7dbfc18 100644 --- a/include/eagle_parser.h +++ b/include/eagle_parser.h @@ -364,6 +364,13 @@ string makeKey( const string& aFirst, const string& aSecond ); /// Make a unique time stamp unsigned long timeStamp( wxXmlNode* aTree ); +/// Computes module path basing on its name and value +time_t moduleTstamp( const string& aName, const string& aValue ); + +/// Returns module path using the module timestamp +// TODO does not handle multisheet schematics correctly +string modulePath( const string& aName, const string& aValue ); + /// Convert an Eagle curve end to a KiCad center for S_ARC wxPoint kicad_arc_center( const wxPoint& aStart, const wxPoint& aEnd, double aAngle ); diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index ce6cb0e70f..35100bb783 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -853,6 +853,9 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements ) // copy constructor to clone the template MODULE* m = new MODULE( *mi->second ); + // TODO currently not handled correctly for multisheet schematics + //m->SetTimeStamp( moduleTstamp( e.name, e.value ) ); + //m->SetPath( modulePath( e.name, e.value ) ); m_board->Add( m, ADD_APPEND ); // update the nets within the pads of the clone @@ -871,18 +874,21 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements ) refanceNamePresetInPackageLayout = true; valueNamePresetInPackageLayout = true; m->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) ); + // Is >NAME field set in package layout ? if( m->GetReference().size() == 0 ) { m->Reference().SetVisible( false ); // No so no show refanceNamePresetInPackageLayout = false; } + // Is >VALUE field set in package layout if( m->GetValue().size() == 0 ) { m->Value().SetVisible( false ); // No so no show valueNamePresetInPackageLayout = false; } + m->SetReference( FROM_UTF8( e.name.c_str() ) ); m->SetValue( FROM_UTF8( e.value.c_str() ) ); @@ -890,6 +896,7 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements ) { // Not smashed so show NAME & VALUE if( valueNamePresetInPackageLayout ) m->Value().SetVisible( true ); // Only if place holder in package layout + if( refanceNamePresetInPackageLayout ) m->Reference().SetVisible( true ); // Only if place holder in package layout }