Eeschema Eagle Import: Assign timestamps for modules

This commit is contained in:
Maciej Suminski 2017-07-17 14:09:01 +02:00
parent f5e7c2ee48
commit 2adc3d48b4
4 changed files with 37 additions and 9 deletions

View File

@ -26,13 +26,9 @@
#include <eagle_parser.h> #include <eagle_parser.h>
#include <wx/xml/xml.h> #include <functional>
#include <wx/string.h> #include <sstream>
#include <wx/filename.h> #include <iomanip>
#include <convert_to_biu.h>
using std::string;
// Template specializations below parse wxString to the used types: // Template specializations below parse wxString to the used types:
// - string // - 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<string>{}( aName );
std::size_t h2 = std::hash<string>{}( 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 ) wxPoint kicad_arc_center( const wxPoint& aStart, const wxPoint& aEnd, double aAngle )
{ {
// Eagle give us start and end. // Eagle give us start and end.

View File

@ -970,8 +970,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
component->SetConvert( 0 ); component->SetConvert( 0 );
component->SetPosition( wxPoint( einstance.x * EUNIT_TO_MIL, -einstance.y * EUNIT_TO_MIL ) ); component->SetPosition( wxPoint( einstance.x * EUNIT_TO_MIL, -einstance.y * EUNIT_TO_MIL ) );
component->GetField( FOOTPRINT )->SetText( wxString( package ) ); component->GetField( FOOTPRINT )->SetText( wxString( package ) );
// component->SetTimeStamp( parseHex( aReader, line, &line ) ); // TODO we need to find a way component->SetTimeStamp( moduleTstamp( einstance.part, epart->value ? *epart->value : "" ) );
// to correlate symbols and footprints
// component->AddHierarchicalReference( path, reference, (int)tmp ); // TODO ?? // component->AddHierarchicalReference( path, reference, (int)tmp ); // TODO ??
if( einstance.rot ) if( einstance.rot )

View File

@ -364,6 +364,13 @@ string makeKey( const string& aFirst, const string& aSecond );
/// Make a unique time stamp /// Make a unique time stamp
unsigned long timeStamp( wxXmlNode* aTree ); 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 /// Convert an Eagle curve end to a KiCad center for S_ARC
wxPoint kicad_arc_center( const wxPoint& aStart, const wxPoint& aEnd, double aAngle ); wxPoint kicad_arc_center( const wxPoint& aStart, const wxPoint& aEnd, double aAngle );

View File

@ -853,6 +853,9 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
// copy constructor to clone the template // copy constructor to clone the template
MODULE* m = new MODULE( *mi->second ); 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 ); m_board->Add( m, ADD_APPEND );
// update the nets within the pads of the clone // update the nets within the pads of the clone
@ -871,18 +874,21 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
refanceNamePresetInPackageLayout = true; refanceNamePresetInPackageLayout = true;
valueNamePresetInPackageLayout = true; valueNamePresetInPackageLayout = true;
m->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) ); m->SetPosition( wxPoint( kicad_x( e.x ), kicad_y( e.y ) ) );
// Is >NAME field set in package layout ? // Is >NAME field set in package layout ?
if( m->GetReference().size() == 0 ) if( m->GetReference().size() == 0 )
{ {
m->Reference().SetVisible( false ); // No so no show m->Reference().SetVisible( false ); // No so no show
refanceNamePresetInPackageLayout = false; refanceNamePresetInPackageLayout = false;
} }
// Is >VALUE field set in package layout // Is >VALUE field set in package layout
if( m->GetValue().size() == 0 ) if( m->GetValue().size() == 0 )
{ {
m->Value().SetVisible( false ); // No so no show m->Value().SetVisible( false ); // No so no show
valueNamePresetInPackageLayout = false; valueNamePresetInPackageLayout = false;
} }
m->SetReference( FROM_UTF8( e.name.c_str() ) ); m->SetReference( FROM_UTF8( e.name.c_str() ) );
m->SetValue( FROM_UTF8( e.value.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 { // Not smashed so show NAME & VALUE
if( valueNamePresetInPackageLayout ) if( valueNamePresetInPackageLayout )
m->Value().SetVisible( true ); // Only if place holder in package layout m->Value().SetVisible( true ); // Only if place holder in package layout
if( refanceNamePresetInPackageLayout ) if( refanceNamePresetInPackageLayout )
m->Reference().SetVisible( true ); // Only if place holder in package layout m->Reference().SetVisible( true ); // Only if place holder in package layout
} }