From df708f8ada66a4f861dfd176233fc58caebb52de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Garc=C3=ADa=20Montoro?= Date: Thu, 9 Mar 2017 13:49:24 +0100 Subject: [PATCH] Starts the loading layout --- eeschema/qa/test_basic.cpp | 4 +- eeschema/sch_eagle_plugin.cpp | 173 ++++++++++++++++++++++++++++++++-- eeschema/sch_eagle_plugin.h | 9 +- 3 files changed, 176 insertions(+), 10 deletions(-) diff --git a/eeschema/qa/test_basic.cpp b/eeschema/qa/test_basic.cpp index 7201d35253..5df77c9cbc 100644 --- a/eeschema/qa/test_basic.cpp +++ b/eeschema/qa/test_basic.cpp @@ -44,6 +44,6 @@ BOOST_AUTO_TEST_CASE( Load ) { 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", - &Kiway()); + pi->Load("/home/alejandro/Proyectos/kicad/kicad-alejandro/eeschema/qa/data/eagle_schematics/empty.sch", + NULL); } diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index 1898df4226..4b13fb5f6f 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -22,19 +22,24 @@ #include #include +#include -// #include +#include #include +using namespace std; + SCH_EAGLE_PLUGIN::SCH_EAGLE_PLUGIN() { + m_rootSheet = nullptr; } SCH_EAGLE_PLUGIN::~SCH_EAGLE_PLUGIN() { } + const wxString SCH_EAGLE_PLUGIN::GetName() const { 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* aAppendToMe, const PROPERTIES* aProperties ) { - wxASSERT( !aFileName || aKiway != NULL ); - - SCH_SHEET* sheet = nullptr; + // TODO: Handle Kiway adn uncomment next line. + // wxASSERT( !aFileName || aKiway != NULL ); + // Load the document + wxXmlDocument xmlDocument; 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() ) ); - return sheet; + // Delete on exception, if I own m_rootSheet, according to aAppendToMe + unique_ptr deleter( aAppendToMe ? nullptr : m_rootSheet ); + + if( aAppendToMe ) + { + m_rootSheet = aAppendToMe->GetRootSheet(); + // deleter = make_unique( nullptr ); + } + else + { + m_rootSheet = new SCH_SHEET(); + m_rootSheet->SetFileName( aFileName ); + // deleter = make_unique( 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, const PROPERTIES* aProperties ) diff --git a/eeschema/sch_eagle_plugin.h b/eeschema/sch_eagle_plugin.h index 39f5d3c9b1..7459e59eb0 100644 --- a/eeschema/sch_eagle_plugin.h +++ b/eeschema/sch_eagle_plugin.h @@ -34,7 +34,7 @@ // class SCH_JUNCTION; // class SCH_NO_CONNECT; // class SCH_LINE; -// class SCH_BUS_ENTRY_BASE; +// class SCH_BUS_ENTRY_BASE;s // class SCH_TEXT; // class SCH_COMPONENT; // class SCH_FIELD; @@ -104,7 +104,12 @@ public: 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: };