Store imported Eagle symbols in a library

This commit is contained in:
Maciej Suminski 2017-07-03 16:02:55 +02:00
parent 3298387f7b
commit 0d76b2947f
3 changed files with 38 additions and 31 deletions

View File

@ -102,15 +102,6 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
// AddPart() does first clone the part before adding.
archLib->AddPart( part );
}
// Russell: This is a hack to get a part to save into the cache file the components PART_REF when imported with the eagle plugin.
// Don't think it is kosher, but it works for now.
else
{
PART_REF partref = component->GetPartRef();
if( !partref.expired()){
cacheLib->AddPart( partref.lock().get() );
}
}
}
catch( ... /* IO_ERROR ioe */ )
{

View File

@ -19,6 +19,7 @@
*/
#include <properties.h>
#include <kiway.h>
#include <wx/filename.h>
#include <memory>
@ -200,19 +201,19 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
m_rootSheet->SetScreen( screen );
}
// // Create a schematic symbol library
// wxFileName libfn = fn;
// libfn.SetName( libfn.GetName() );
// libfn.SetExt( SchematicLibraryFileExtension );
// std::unique_ptr<PART_LIB> lib( new PART_LIB( LIBRARY_TYPE_EESCHEMA, libfn.GetFullPath() ) );
// lib->EnableBuffering();
//
// if( !wxFileName::FileExists( lib->GetFullFileName() ) )
// {
// lib->Create();
// }
//
// m_partlib = lib.release();
// Create a schematic symbol library
wxFileName libfn = aFileName;
libfn.SetName( libfn.GetName() );
libfn.SetExt( SchematicLibraryFileExtension );
std::unique_ptr<PART_LIB> lib( new PART_LIB( LIBRARY_TYPE_EESCHEMA, libfn.GetFullPath() ) );
lib->EnableBuffering();
if( !wxFileName::FileExists( lib->GetFullFileName() ) )
{
lib->Create();
}
m_partlib = lib.release();
// Retrieve the root as current node
wxXmlNode* currentNode = xmlDocument.GetRoot();
@ -230,7 +231,12 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
// Load drawing
loadDrawing( children["drawing"] );
// There are two ways to add a new library, the official one that requires creating a file:
//m_partlib->Save( false );
//aKiway->Prj().SchLibs()->AddLibrary( m_partlib->GetFullFileName() );
// or undocumented one:
aKiway->Prj().SchLibs()->push_back( m_partlib );
deleter.release();
return m_rootSheet;
}
@ -601,27 +607,37 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
//std::cout << gatename << '\n';
//std::cout << "Gate to unit number " << m_eaglelibraries[epart->library]->gate_unit[gatename] << '\n';
int unit = m_eaglelibraries[epart->library]->gate_unit[gatename];
LIB_PART* part = m_eaglelibraries[epart->library]->kicadsymbols[symbolname];
//LIB_PART* part = m_eaglelibraries[epart->library]->kicadsymbols[symbolname];
std::cout << "Instance> part: " << einstance.part << " Gate: " << einstance.gate << " " << symbolname << '\n';
//SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* sheet, int unit, int convert, const wxPoint& pos, bool setNewItemFlag )
std::unique_ptr< SCH_COMPONENT > component( new SCH_COMPONENT( *part, NULL, unit, 0, wxPoint(einstance.x*EUNIT_TO_MIL, -einstance.y*EUNIT_TO_MIL), true ) );
std::unique_ptr<SCH_COMPONENT> component( new SCH_COMPONENT() );
LIB_ID libId( wxEmptyString, symbolname );
component->SetLibId( libId );
component->SetUnit( unit );
component->SetConvert( 0 );
component->SetPosition( wxPoint( einstance.x * EUNIT_TO_MIL, -einstance.y * EUNIT_TO_MIL ) );
//component->SetTimeStamp( parseHex( aReader, line, &line ) ); // TODO we need to find a way
// to correlate symbols and footprints
//component->AddHierarchicalReference( path, reference, (int)tmp ); // TODO ??
if(einstance.rot){
if(einstance.rot->mirror){
if( einstance.rot )
{
if( einstance.rot->mirror )
{
component->MirrorY( einstance.x * EUNIT_TO_MIL );
std::cout << "Mirror" << '\n';
}
}
component->GetField( 0 )->SetText( einstance.part );
component->SetModified();
component->ClearFlags();
screen->Append( component.release() );
}

View File

@ -152,7 +152,7 @@ private:
SCH_SHEET* m_currentSheet; ///< The current sheet of the schematic being loaded..
wxString m_version; ///< Eagle file version.
wxFileName m_filename;
//PART_LIB* m_partlib; ///< symbol library for imported file.
PART_LIB* m_partlib; ///< symbol library for imported file.
EPART_LIST m_partlist;
std::map<std::string, EAGLE_LIBRARY*> m_eaglelibraries;