Starts the loading layout

This commit is contained in:
Alejandro García Montoro 2017-03-09 13:49:24 +01:00 committed by Maciej Suminski
parent 75b0549f6f
commit df708f8ada
3 changed files with 176 additions and 10 deletions

View File

@ -44,6 +44,6 @@ BOOST_AUTO_TEST_CASE( Load )
{ {
SCH_PLUGIN* pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ); SCH_PLUGIN* pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE );
pi->Load("/home/alejandro/Proyectos/kicad/kicad-alejandro/eeschema/qa/data/eagle_schematics", pi->Load("/home/alejandro/Proyectos/kicad/kicad-alejandro/eeschema/qa/data/eagle_schematics/empty.sch",
&Kiway()); NULL);
} }

View File

@ -22,19 +22,24 @@
#include <properties.h> #include <properties.h>
#include <wx/filename.h> #include <wx/filename.h>
#include <memory>
// #include <richio.h> #include <sch_sheet.h>
#include <sch_eagle_plugin.h> #include <sch_eagle_plugin.h>
using namespace std;
SCH_EAGLE_PLUGIN::SCH_EAGLE_PLUGIN() SCH_EAGLE_PLUGIN::SCH_EAGLE_PLUGIN()
{ {
m_rootSheet = nullptr;
} }
SCH_EAGLE_PLUGIN::~SCH_EAGLE_PLUGIN() SCH_EAGLE_PLUGIN::~SCH_EAGLE_PLUGIN()
{ {
} }
const wxString SCH_EAGLE_PLUGIN::GetName() const const wxString SCH_EAGLE_PLUGIN::GetName() const
{ {
return wxT( "EAGLE" ); return wxT( "EAGLE" );
@ -62,18 +67,174 @@ void SCH_EAGLE_PLUGIN::SaveLibrary( const wxString& aFileName, const PROPERTIES*
SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway, SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties ) SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties )
{ {
wxASSERT( !aFileName || aKiway != NULL ); // TODO: Handle Kiway adn uncomment next line.
// wxASSERT( !aFileName || aKiway != NULL );
SCH_SHEET* sheet = nullptr;
// Load the document
wxXmlDocument xmlDocument;
wxFileName fn = aFileName; wxFileName fn = aFileName;
if( !m_xmlTree.Load( fn.GetFullPath() ) ) if( !xmlDocument.Load( fn.GetFullPath() ) )
THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'" ), fn.GetFullPath() ) ); THROW_IO_ERROR( wxString::Format( _( "Unable to read file '%s'" ), fn.GetFullPath() ) );
return sheet; // Delete on exception, if I own m_rootSheet, according to aAppendToMe
unique_ptr<SCH_SHEET> deleter( aAppendToMe ? nullptr : m_rootSheet );
if( aAppendToMe )
{
m_rootSheet = aAppendToMe->GetRootSheet();
// deleter = make_unique<SCH_SHEET>( nullptr );
}
else
{
m_rootSheet = new SCH_SHEET();
m_rootSheet->SetFileName( aFileName );
// deleter = make_unique<SCH_SHEET>( m_rootSheet );
}
// Retrieve the root as current node
wxXmlNode* currentNode = xmlDocument.GetRoot();
// If the attribute is found, store the Eagle version;
// otherwise, store the dummy "0.0" version.
m_version = currentNode->GetAttribute("version", "0.0");
// Loop through all children
currentNode = currentNode->GetChildren();
while( currentNode )
{
wxString nodeName = currentNode->GetName();
if( nodeName == "compatibility" )
{
// TODO: handle compatibility nodes
}
else if( nodeName == "drawing")
{
loadDrawing( currentNode );
}
else // DEFAULT
{
THROW_IO_ERROR( wxString::Format( _( "XML node '%s' unknown" ), nodeName ) );
}
currentNode = currentNode->GetNext();
}
deleter.release();
return m_rootSheet;
} }
void SCH_EAGLE_PLUGIN::loadDrawing( wxXmlNode* currentNode )
{
currentNode = currentNode->GetChildren();
while( currentNode )
{
wxString nodeName = currentNode->GetName();
if( nodeName == "board" )
{
// TODO: handle board nodes
}
else if( nodeName == "grid" )
{
// TODO: handle grid nodes
}
else if( nodeName == "layers" )
{
// TODO: handle layers nodes
}
else if( nodeName == "library" )
{
// TODO: handle library nodes
}
else if( nodeName == "schematic" )
{
loadSchematic( currentNode );
}
else if( nodeName == "settings" )
{
// TODO: handle settings nodes
}
else // DEFAULT
{
THROW_IO_ERROR( wxString::Format( _( "XML node '%s' unknown" ), nodeName ) );
}
currentNode = currentNode->GetNext();
}
}
void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* currentNode )
{
currentNode = currentNode->GetChildren();
while( currentNode )
{
wxString nodeName = currentNode->GetName();
if( nodeName == "attributes" )
{
wxXmlNode* attributeNode = currentNode->GetChildren();
while( attributeNode )
{
// TODO: handle attributes
// Possible attributes: constant, display, font, layer, name,
// ratio, rot, size, value, x, y.
attributeNode = attributeNode->GetNext();
}
}
else if( nodeName == "classes" )
{
// TODO : handle classes nodes
}
else if( nodeName == "description" )
{
// TODO : handle description nodes
}
else if( nodeName == "errors" )
{
// TODO : handle errors nodes
}
else if( nodeName == "libraries" )
{
// TODO : handle libraries nodes
}
else if( nodeName == "modules" )
{
// TODO : handle modules nodes
}
else if( nodeName == "parts" )
{
// TODO : handle parts nodes
}
else if( nodeName == "sheets" )
{
wxXmlNode* sheetNode = currentNode->GetChildren();
while( sheetNode )
{
loadSheet( sheetNode );
sheetNode = sheetNode->GetNext();
}
}
else if( nodeName == "variantdefs" )
{
// TODO : handle variantdefs nodes
}
else // DEFAULT
{
THROW_IO_ERROR( wxString::Format( _( "XML node '%s' unknown" ), nodeName ) );
}
currentNode = currentNode->GetNext();
}
}
void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* currentNode )
{
}
void SCH_EAGLE_PLUGIN::Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway, void SCH_EAGLE_PLUGIN::Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
const PROPERTIES* aProperties ) const PROPERTIES* aProperties )

View File

@ -34,7 +34,7 @@
// class SCH_JUNCTION; // class SCH_JUNCTION;
// class SCH_NO_CONNECT; // class SCH_NO_CONNECT;
// class SCH_LINE; // class SCH_LINE;
// class SCH_BUS_ENTRY_BASE; // class SCH_BUS_ENTRY_BASE;s
// class SCH_TEXT; // class SCH_TEXT;
// class SCH_COMPONENT; // class SCH_COMPONENT;
// class SCH_FIELD; // class SCH_FIELD;
@ -104,7 +104,12 @@ public:
private: private:
wxXmlDocument m_xmlTree; void loadDrawing( wxXmlNode* node );
void loadSchematic( wxXmlNode* node );
void loadSheet( wxXmlNode* node );
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded..
wxString m_version; ///< Eagle file version.
protected: protected:
}; };