From 96317fb7c37367a97bbedcf9e3649e7a2daa1682 Mon Sep 17 00:00:00 2001 From: Russell Oliver Date: Mon, 26 Jun 2017 17:51:51 +1000 Subject: [PATCH] Common: Reorder some functions in eagle_parser.* --- common/eagle_parser.cpp | 112 ++++++++++++++++++++-------------------- include/eagle_parser.h | 39 ++++++++------ 2 files changed, 80 insertions(+), 71 deletions(-) diff --git a/common/eagle_parser.cpp b/common/eagle_parser.cpp index 83c9592ad1..e4ee047d4c 100644 --- a/common/eagle_parser.cpp +++ b/common/eagle_parser.cpp @@ -136,6 +136,63 @@ OPTIONAL_XML_ATTRIBUTE parseOptionalAttribute( wxXmlNode* aNode, string aAttr } +NODE_MAP MapChildren( wxXmlNode* currentNode ) +{ + // Map node_name -> node_pointer + NODE_MAP nodesMap; + + // Loop through all children mapping them in nodesMap + if( currentNode ) + currentNode = currentNode->GetChildren(); + + while( currentNode ) + { + // Create a new pair in the map + // key: current node name + // value: current node pointer + nodesMap[currentNode->GetName().ToStdString()] = currentNode; + + // Get next child + currentNode = currentNode->GetNext(); + } + + return nodesMap; +} + + +string makeKey( const string& aFirst, const string& aSecond ) +{ + string key = aFirst + '\x02' + aSecond; + return key; +} + + +unsigned long timeStamp( wxXmlNode* aTree ) +{ + // in this case from a unique tree memory location + return (unsigned long)(void*) aTree; +} + + +wxPoint kicad_arc_center( const wxPoint& aStart, const wxPoint& aEnd, double aAngle ) +{ + // Eagle give us start and end. + // S_ARC wants start to give the center, and end to give the start. + double dx = aEnd.x - aStart.x, dy = aEnd.y - aStart.y; + wxPoint mid = ( aStart + aEnd ) / 2; + + double dlen = sqrt( dx*dx + dy*dy ); + double dist = dlen / ( 2 * tan( DEG2RAD( aAngle ) / 2 ) ); + + wxPoint center( + mid.x + dist * ( dy / dlen ), + mid.y - dist * ( dx / dlen ) + ); + + return center; +} + + EWIRE::EWIRE( wxXmlNode* aWire ) { /* @@ -667,58 +724,3 @@ ELAYER::ELAYER( wxXmlNode* aLayer ) } -NODE_MAP MapChildren( wxXmlNode* currentNode ) -{ - // Map node_name -> node_pointer - NODE_MAP nodesMap; - - // Loop through all children mapping them in nodesMap - if( currentNode ) - currentNode = currentNode->GetChildren(); - - while( currentNode ) - { - // Create a new pair in the map - // key: current node name - // value: current node pointer - nodesMap[currentNode->GetName().ToStdString()] = currentNode; - - // Get next child - currentNode = currentNode->GetNext(); - } - - return nodesMap; -} - - -string makeKey( const string& aFirst, const string& aSecond ) -{ - string key = aFirst + '\x02' + aSecond; - return key; -} - - -unsigned long timeStamp( wxXmlNode* aTree ) -{ - // in this case from a unique tree memory location - return (unsigned long)(void*) aTree; -} - - -wxPoint kicad_arc_center( const wxPoint& aStart, const wxPoint& aEnd, double aAngle ) -{ - // Eagle give us start and end. - // S_ARC wants start to give the center, and end to give the start. - double dx = aEnd.x - aStart.x, dy = aEnd.y - aStart.y; - wxPoint mid = ( aStart + aEnd ) / 2; - - double dlen = sqrt( dx*dx + dy*dy ); - double dist = dlen / ( 2 * tan( DEG2RAD( aAngle ) / 2 ) ); - - wxPoint center( - mid.x + dist * ( dy / dlen ), - mid.y - dist * ( dx / dlen ) - ); - - return center; -} diff --git a/include/eagle_parser.h b/include/eagle_parser.h index b033ae3662..06f7e991af 100644 --- a/include/eagle_parser.h +++ b/include/eagle_parser.h @@ -342,6 +342,27 @@ public: } }; + +/** + * Function MapChildren + * provides an easy access to the children of an XML node via their names. + * @param currentNode is a pointer to a wxXmlNode, whose children will be mapped. + * @return NODE_MAP - a map linking the name of each children to the children itself (via a + * wxXmlNode*) + */ +NODE_MAP MapChildren( wxXmlNode* currentNode ); + +/// Assemble a two part key as a simple concatenation of aFirst and aSecond parts, +/// using a separator. +string makeKey( const string& aFirst, const string& aSecond ); + +/// Make a unique time stamp +unsigned long timeStamp( wxXmlNode* aTree ); + +/// Convert an Eagle curve end to a KiCad center for S_ARC +wxPoint kicad_arc_center( const wxPoint& aStart, const wxPoint& aEnd, double aAngle ); + + // Pre-declare for typedefs struct EROT; @@ -352,6 +373,8 @@ typedef OPTIONAL_XML_ATTRIBUTE opt_bool; typedef OPTIONAL_XML_ATTRIBUTE opt_erot; + + // All of the 'E'STRUCTS below merely hold Eagle XML information verbatim, in binary. // For maintenance and troubleshooting purposes, it was thought that we'd need to // separate the conversion process into distinct steps. There is no intent to have KiCad @@ -783,23 +806,7 @@ struct EAGLE_LAYER }; }; -/** - * Function MapChildren - * provides an easy access to the children of an XML node via their names. - * @param currentNode is a pointer to a wxXmlNode, whose children will be mapped. - * @return NODE_MAP - a map linking the name of each children to the children itself (via a - * wxXmlNode*) - */ -NODE_MAP MapChildren( wxXmlNode* currentNode ); -/// Assemble a two part key as a simple concatenation of aFirst and aSecond parts, -/// using a separator. -string makeKey( const string& aFirst, const string& aSecond ); -/// Make a unique time stamp -unsigned long timeStamp( wxXmlNode* aTree ); - -/// Convert an Eagle curve end to a KiCad center for S_ARC -wxPoint kicad_arc_center( const wxPoint& aStart, const wxPoint& aEnd, double aAngle ); #endif // _EAGLE_PARSER_H_