Code formatting and cleanup
This commit is contained in:
parent
404457f455
commit
f5b2a2ea57
|
@ -43,14 +43,14 @@ using std::string;
|
||||||
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
string Convert<string>( const wxString& aValue )
|
string Convert<string>( wxString aValue )
|
||||||
{
|
{
|
||||||
return aValue.ToStdString();
|
return aValue.ToStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
double Convert<double>( const wxString& aValue )
|
double Convert<double>( wxString aValue )
|
||||||
{
|
{
|
||||||
double value;
|
double value;
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ double Convert<double>( const wxString& aValue )
|
||||||
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
int Convert<int>( const wxString& aValue )
|
int Convert<int>( wxString aValue )
|
||||||
{
|
{
|
||||||
if( aValue.IsEmpty() )
|
if( aValue.IsEmpty() )
|
||||||
throw XML_PARSER_ERROR( "Conversion to int failed. Original value is empty." );
|
throw XML_PARSER_ERROR( "Conversion to int failed. Original value is empty." );
|
||||||
|
@ -73,7 +73,7 @@ int Convert<int>( const wxString& aValue )
|
||||||
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
bool Convert<bool>( const wxString& aValue )
|
bool Convert<bool>( wxString aValue )
|
||||||
{
|
{
|
||||||
if( aValue != "yes" && aValue != "no" )
|
if( aValue != "yes" && aValue != "no" )
|
||||||
throw XML_PARSER_ERROR( "Conversion to bool failed. Original value, '" +
|
throw XML_PARSER_ERROR( "Conversion to bool failed. Original value, '" +
|
||||||
|
@ -87,7 +87,7 @@ bool Convert<bool>( const wxString& aValue )
|
||||||
/// parse an Eagle XML "rot" field. Unfortunately the DTD seems not to explain
|
/// parse an Eagle XML "rot" field. Unfortunately the DTD seems not to explain
|
||||||
/// this format very well. [S][M]R<degrees>. Examples: "R90", "MR180", "SR180"
|
/// this format very well. [S][M]R<degrees>. Examples: "R90", "MR180", "SR180"
|
||||||
template<>
|
template<>
|
||||||
EROT Convert<EROT>( const wxString& aRot )
|
EROT Convert<EROT>( wxString aRot )
|
||||||
{
|
{
|
||||||
EROT value;
|
EROT value;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017 CERN
|
* Copyright (C) 2017 CERN
|
||||||
*
|
|
||||||
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
|
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
@ -33,24 +32,22 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
typedef unordered_map< string, wxXmlNode* > NodeMap;
|
NODE_MAP mapChildren( wxXmlNode* aCurrentNode )
|
||||||
|
|
||||||
NodeMap mapChildren( wxXmlNode* currentNode )
|
|
||||||
{
|
{
|
||||||
// Map node_name -> node_pointer
|
// Map node_name -> node_pointer
|
||||||
NodeMap nodesMap;
|
NODE_MAP nodesMap;
|
||||||
|
|
||||||
// Loop through all children mapping them in nodesMap
|
// Loop through all children mapping them in nodesMap
|
||||||
currentNode = currentNode->GetChildren();
|
aCurrentNode = aCurrentNode->GetChildren();
|
||||||
while( currentNode )
|
while( aCurrentNode )
|
||||||
{
|
{
|
||||||
// Create a new pair in the map
|
// Create a new pair in the map
|
||||||
// key: current node name
|
// key: current node name
|
||||||
// value: current node pointer
|
// value: current node pointer
|
||||||
nodesMap[currentNode->GetName().ToStdString()] = currentNode;
|
nodesMap[aCurrentNode->GetName().ToStdString()] = aCurrentNode;
|
||||||
|
|
||||||
// Get next child
|
// Get next child
|
||||||
currentNode = currentNode->GetNext();
|
aCurrentNode = aCurrentNode->GetNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodesMap;
|
return nodesMap;
|
||||||
|
@ -74,8 +71,6 @@ void kicadLayer( int aEagleLayer )
|
||||||
* <layer number="97" name="Info" color="7" fill="1" visible="yes" active="yes"/>
|
* <layer number="97" name="Info" color="7" fill="1" visible="yes" active="yes"/>
|
||||||
* <layer number="98" name="Guide" color="6" fill="1" visible="yes" active="yes"/>
|
* <layer number="98" name="Guide" color="6" fill="1" visible="yes" active="yes"/>
|
||||||
* </layers>
|
* </layers>
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
switch( aEagleLayer )
|
switch( aEagleLayer )
|
||||||
|
@ -116,7 +111,6 @@ const wxString SCH_EAGLE_PLUGIN::GetFileExtension() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int SCH_EAGLE_PLUGIN::GetModifyHash() const
|
int SCH_EAGLE_PLUGIN::GetModifyHash() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -125,7 +119,6 @@ int SCH_EAGLE_PLUGIN::GetModifyHash() const
|
||||||
|
|
||||||
void SCH_EAGLE_PLUGIN::SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties )
|
void SCH_EAGLE_PLUGIN::SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,7 +156,7 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
|
||||||
m_version = currentNode->GetAttribute( "version", "0.0" );
|
m_version = currentNode->GetAttribute( "version", "0.0" );
|
||||||
|
|
||||||
// Map all children into a readable dictionary
|
// Map all children into a readable dictionary
|
||||||
NodeMap children = mapChildren( currentNode );
|
NODE_MAP children = mapChildren( currentNode );
|
||||||
|
|
||||||
// TODO: handle compatibility nodes
|
// TODO: handle compatibility nodes
|
||||||
// wxXmlNode* compatibility = children["compatibility"];
|
// wxXmlNode* compatibility = children["compatibility"];
|
||||||
|
@ -179,7 +172,7 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
|
||||||
void SCH_EAGLE_PLUGIN::loadDrawing( wxXmlNode* aDrawingNode )
|
void SCH_EAGLE_PLUGIN::loadDrawing( wxXmlNode* aDrawingNode )
|
||||||
{
|
{
|
||||||
// Map all children into a readable dictionary
|
// Map all children into a readable dictionary
|
||||||
NodeMap drawingChildren = mapChildren( aDrawingNode );
|
NODE_MAP drawingChildren = mapChildren( aDrawingNode );
|
||||||
|
|
||||||
// Board nodes should not appear in .sch files
|
// Board nodes should not appear in .sch files
|
||||||
// wxXmlNode* board = drawingChildren["board"]
|
// wxXmlNode* board = drawingChildren["board"]
|
||||||
|
@ -204,7 +197,7 @@ void SCH_EAGLE_PLUGIN::loadDrawing( wxXmlNode* aDrawingNode )
|
||||||
void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
|
void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
|
||||||
{
|
{
|
||||||
// Map all children into a readable dictionary
|
// Map all children into a readable dictionary
|
||||||
NodeMap schematicChildren = mapChildren( aSchematicNode );
|
NODE_MAP schematicChildren = mapChildren( aSchematicNode );
|
||||||
|
|
||||||
// TODO : handle classes nodes
|
// TODO : handle classes nodes
|
||||||
//wxXmlNode* classes = schematicChildren["classes"];
|
//wxXmlNode* classes = schematicChildren["classes"];
|
||||||
|
@ -230,6 +223,7 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
|
||||||
|
|
||||||
// Loop through all the libraries
|
// Loop through all the libraries
|
||||||
wxXmlNode* libraryNode = schematicChildren["libraries"]->GetChildren();
|
wxXmlNode* libraryNode = schematicChildren["libraries"]->GetChildren();
|
||||||
|
|
||||||
while( libraryNode )
|
while( libraryNode )
|
||||||
{
|
{
|
||||||
loadLibrary( libraryNode );
|
loadLibrary( libraryNode );
|
||||||
|
@ -238,6 +232,7 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
|
||||||
|
|
||||||
// Loop through all the sheets
|
// Loop through all the sheets
|
||||||
wxXmlNode* sheetNode = schematicChildren["sheets"]->GetChildren();
|
wxXmlNode* sheetNode = schematicChildren["sheets"]->GetChildren();
|
||||||
|
|
||||||
while( sheetNode )
|
while( sheetNode )
|
||||||
{
|
{
|
||||||
loadSheet( sheetNode );
|
loadSheet( sheetNode );
|
||||||
|
@ -249,13 +244,14 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
|
||||||
void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode )
|
void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode )
|
||||||
{
|
{
|
||||||
// Map all children into a readable dictionary
|
// Map all children into a readable dictionary
|
||||||
NodeMap sheetChildren = mapChildren( aSheetNode );
|
NODE_MAP sheetChildren = mapChildren( aSheetNode );
|
||||||
|
|
||||||
// Loop through all busses
|
// Loop through all busses
|
||||||
// From the DTD: "Buses receive names which determine which signals they include.
|
// From the DTD: "Buses receive names which determine which signals they include.
|
||||||
// A bus is a drawing object. It does not create any electrical connections.
|
// A bus is a drawing object. It does not create any electrical connections.
|
||||||
// These are always created by means of the nets and their names."
|
// These are always created by means of the nets and their names."
|
||||||
wxXmlNode* busNode = sheetChildren["busses"]->GetChildren();
|
wxXmlNode* busNode = sheetChildren["busses"]->GetChildren();
|
||||||
|
|
||||||
while( busNode )
|
while( busNode )
|
||||||
{
|
{
|
||||||
// Get the bus name
|
// Get the bus name
|
||||||
|
@ -271,6 +267,7 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode )
|
||||||
// Loop through all nets
|
// Loop through all nets
|
||||||
// From the DTD: "Net is an electrical connection in a schematic."
|
// From the DTD: "Net is an electrical connection in a schematic."
|
||||||
wxXmlNode* netNode = sheetChildren["nets"]->GetChildren();
|
wxXmlNode* netNode = sheetChildren["nets"]->GetChildren();
|
||||||
|
|
||||||
while( netNode )
|
while( netNode )
|
||||||
{
|
{
|
||||||
// Get the net name and class
|
// Get the net name and class
|
||||||
|
@ -286,6 +283,7 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode )
|
||||||
|
|
||||||
// Loop through all instances
|
// Loop through all instances
|
||||||
wxXmlNode* instanceNode = sheetChildren["instances"]->GetChildren();
|
wxXmlNode* instanceNode = sheetChildren["instances"]->GetChildren();
|
||||||
|
|
||||||
while( instanceNode )
|
while( instanceNode )
|
||||||
{
|
{
|
||||||
loadInstance( instanceNode );
|
loadInstance( instanceNode );
|
||||||
|
@ -294,6 +292,7 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode )
|
||||||
|
|
||||||
// Loop through all moduleinsts
|
// Loop through all moduleinsts
|
||||||
wxXmlNode* moduleinstNode = sheetChildren["moduleinsts"]->GetChildren();
|
wxXmlNode* moduleinstNode = sheetChildren["moduleinsts"]->GetChildren();
|
||||||
|
|
||||||
while( moduleinstNode )
|
while( moduleinstNode )
|
||||||
{
|
{
|
||||||
loadModuleinst( moduleinstNode );
|
loadModuleinst( moduleinstNode );
|
||||||
|
@ -431,13 +430,13 @@ void SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode )
|
||||||
wxString libName = aLibraryNode->GetAttribute( "name" );
|
wxString libName = aLibraryNode->GetAttribute( "name" );
|
||||||
|
|
||||||
// Query all children and map them into a readable dictionary
|
// Query all children and map them into a readable dictionary
|
||||||
NodeMap libraryChildren = mapChildren( aLibraryNode );
|
NODE_MAP libraryChildren = mapChildren( aLibraryNode );
|
||||||
|
|
||||||
// TODO: Do something with the description
|
// TODO: Do something with the description
|
||||||
// wxXmlNode* libraryChildren["description"];
|
// wxXmlNode* libraryChildren["description"];
|
||||||
|
|
||||||
// Loop through the devicesets and load each of them
|
// Loop through the devicesets and load each of them
|
||||||
// wxXmlNode* devicesetNode = libraryChildren["devicesets"].GetChildren();
|
// wxXmlNode* devicesetNode = libraryChildren["devicesets"]->GetChildren();
|
||||||
// while( devicesetNode )
|
// while( devicesetNode )
|
||||||
// {
|
// {
|
||||||
// loadDeviceset( devicesetNode );
|
// loadDeviceset( devicesetNode );
|
||||||
|
@ -445,7 +444,7 @@ void SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode )
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Loop through the packages and load each of them
|
// Loop through the packages and load each of them
|
||||||
// wxXmlNode* packageNode = libraryChildren["packages"].GetChildren();
|
// wxXmlNode* packageNode = libraryChildren["packages"]->GetChildren();
|
||||||
// while( packageNode )
|
// while( packageNode )
|
||||||
// {
|
// {
|
||||||
// loadPackage( packageNode );
|
// loadPackage( packageNode );
|
||||||
|
@ -454,6 +453,7 @@ void SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode )
|
||||||
|
|
||||||
// Loop through the symbols and load each of them
|
// Loop through the symbols and load each of them
|
||||||
wxXmlNode* symbolNode = libraryChildren["symbols"]->GetChildren();
|
wxXmlNode* symbolNode = libraryChildren["symbols"]->GetChildren();
|
||||||
|
|
||||||
while( symbolNode )
|
while( symbolNode )
|
||||||
{
|
{
|
||||||
loadSymbol( symbolNode );
|
loadSymbol( symbolNode );
|
||||||
|
@ -476,11 +476,13 @@ LIB_PART* SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode )
|
||||||
|
|
||||||
if( nodeName == "description" )
|
if( nodeName == "description" )
|
||||||
{
|
{
|
||||||
// TODO: Do something with the description
|
// TODO
|
||||||
|
wxASSERT_MSG( false, "'description' nodes are not implemented yet" );
|
||||||
}
|
}
|
||||||
else if( nodeName == "dimension" )
|
else if( nodeName == "dimension" )
|
||||||
{
|
{
|
||||||
// TODO: Handle dimension
|
// TODO
|
||||||
|
wxASSERT_MSG( false, "'description' nodes are not implemented yet" );
|
||||||
}
|
}
|
||||||
else if( nodeName == "frame" )
|
else if( nodeName == "frame" )
|
||||||
{
|
{
|
||||||
|
@ -516,6 +518,7 @@ LIB_PART* SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode )
|
||||||
return part.release();
|
return part.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LIB_CIRCLE* SCH_EAGLE_PLUGIN::loadCircle( LIB_PART* aPart, wxXmlNode* aCircleNode )
|
LIB_CIRCLE* SCH_EAGLE_PLUGIN::loadCircle( LIB_PART* aPart, wxXmlNode* aCircleNode )
|
||||||
{
|
{
|
||||||
unique_ptr< LIB_CIRCLE > circle( new LIB_CIRCLE( aPart.get() ) );
|
unique_ptr< LIB_CIRCLE > circle( new LIB_CIRCLE( aPart.get() ) );
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017 CERN
|
* Copyright (C) 2017 CERN
|
||||||
*
|
|
||||||
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
|
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
||||||
* Copyright (C) 2012-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 2012-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
* Copyright (C) 2017 CERN.
|
* Copyright (C) 2017 CERN
|
||||||
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
|
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
@ -159,7 +159,7 @@ public:
|
||||||
* type T is unknown.
|
* type T is unknown.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T Convert( const wxString& aValue )
|
T Convert( wxString aValue )
|
||||||
{
|
{
|
||||||
throw XML_PARSER_ERROR( "Conversion failed. Unknown type." );
|
throw XML_PARSER_ERROR( "Conversion failed. Unknown type." );
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ public:
|
||||||
* aData is empty, the attribute is understood as unavailable; otherwise, the
|
* aData is empty, the attribute is understood as unavailable; otherwise, the
|
||||||
* conversion to T is tried.
|
* conversion to T is tried.
|
||||||
*/
|
*/
|
||||||
OPTIONAL_XML_ATTRIBUTE( const wxString& aData )
|
OPTIONAL_XML_ATTRIBUTE( wxString aData )
|
||||||
{
|
{
|
||||||
m_isAvailable = !aData.IsEmpty();
|
m_isAvailable = !aData.IsEmpty();
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ public:
|
||||||
* @param aData is a wxString that should be converted to T. If the string is empty, the
|
* @param aData is a wxString that should be converted to T. If the string is empty, the
|
||||||
* attribute is set to unavailable.
|
* attribute is set to unavailable.
|
||||||
*/
|
*/
|
||||||
OPTIONAL_XML_ATTRIBUTE<T>& operator =( const wxString& aData )
|
OPTIONAL_XML_ATTRIBUTE<T>& operator =( wxString aData )
|
||||||
{
|
{
|
||||||
m_isAvailable = !aData.IsEmpty();
|
m_isAvailable = !aData.IsEmpty();
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ public:
|
||||||
* tries to convert a string to the base type.
|
* tries to convert a string to the base type.
|
||||||
* @param aString is the string that will be converted to the base type.
|
* @param aString is the string that will be converted to the base type.
|
||||||
*/
|
*/
|
||||||
void Set( const wxString& aString )
|
void Set( wxString aString )
|
||||||
{
|
{
|
||||||
m_data = Convert<T>( aString );
|
m_data = Convert<T>( aString );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue