You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1044 lines
23 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2012-2018 KiCad Developers, see AUTHORS.txt for contributors.
  6. * Copyright (C) 2017 CERN
  7. * @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #ifndef _EAGLE_PARSER_H_
  27. #define _EAGLE_PARSER_H_
  28. #include <cerrno>
  29. #include <unordered_map>
  30. #include <wx/xml/xml.h>
  31. #include <wx/string.h>
  32. #include <wx/filename.h>
  33. #include <layers_id_colors_and_visibility.h>
  34. #include <convert_to_biu.h>
  35. #include <macros.h>
  36. #include <trigo.h>
  37. #include <kicad_string.h>
  38. #include <common.h>
  39. class MODULE;
  40. struct EINSTANCE;
  41. struct EPART;
  42. struct ETEXT;
  43. typedef std::unordered_map<wxString, wxXmlNode*> NODE_MAP;
  44. typedef std::map<wxString, MODULE*> MODULE_MAP;
  45. typedef std::map<wxString, EINSTANCE*> EINSTANCE_MAP;
  46. typedef std::map<wxString, std::unique_ptr<EPART>> EPART_MAP;
  47. ///> Translates Eagle special characters to their counterparts in KiCad.
  48. wxString escapeName( const wxString& aNetName );
  49. static inline wxXmlNode* getChildrenNodes( NODE_MAP& aMap, const wxString& aName )
  50. {
  51. auto it = aMap.find( aName );
  52. return it == aMap.end() ? nullptr : it->second->GetChildren();
  53. }
  54. /**
  55. * XML_PARSER_ERROR
  56. * implements a simple wrapper around runtime_error to isolate the errors thrown by the
  57. * Eagle XML parser.
  58. */
  59. struct XML_PARSER_ERROR : std::runtime_error
  60. {
  61. /**
  62. * Constructor XML_PARSER_ERROR
  63. * build an XML error by just calling its parent class constructor, std::runtime_error, with
  64. * the passed message.
  65. * @param aMessage is an explanatory error message.
  66. */
  67. XML_PARSER_ERROR( const wxString& aMessage ) noexcept :
  68. std::runtime_error( "XML parser failed - " + aMessage.ToStdString() )
  69. {}
  70. };
  71. /// segment (element) of our XPATH into the Eagle XML document tree in PTREE form.
  72. struct TRIPLET
  73. {
  74. const char* element;
  75. const char* attribute;
  76. const char* value;
  77. TRIPLET( const char* aElement, const char* aAttribute = "", const char* aValue = "" ) :
  78. element( aElement ),
  79. attribute( aAttribute ),
  80. value( aValue )
  81. {}
  82. };
  83. /**
  84. * XPATH
  85. * keeps track of what we are working on within a PTREE.
  86. * Then if an exception is thrown, the place within the tree that gave us
  87. * grief can be reported almost accurately. To minimally impact
  88. * speed, merely assign const char* pointers during the tree walking
  89. * expedition. The const char* pointers must be to C strings residing either in
  90. * the data or code segment (i.e. "compiled in") or within the XML document, but
  91. * not on the stack, since the stack is unwound during the throwing of the
  92. * exception. The XML document will not immediately vanish since we capture
  93. * the xpath (using function Contents()) before the XML document tree (PTREE)
  94. * is destroyed.
  95. */
  96. class XPATH
  97. {
  98. std::vector<TRIPLET> p;
  99. public:
  100. void push( const char* aPathSegment, const char* aAttribute="" )
  101. {
  102. p.emplace_back( aPathSegment, aAttribute );
  103. }
  104. void clear() { p.clear(); }
  105. void pop() { p.pop_back(); }
  106. /// modify the last path node's value
  107. void Value( const char* aValue )
  108. {
  109. p.back().value = aValue;
  110. }
  111. /// modify the last path node's attribute
  112. void Attribute( const char* aAttribute )
  113. {
  114. p.back().attribute = aAttribute;
  115. }
  116. /// return the contents of the XPATH as a single string
  117. wxString Contents()
  118. {
  119. typedef std::vector<TRIPLET>::const_iterator CITER_TRIPLET;
  120. wxString ret;
  121. for( CITER_TRIPLET it = p.begin(); it != p.end(); ++it )
  122. {
  123. if( it != p.begin() )
  124. ret += '.';
  125. ret += it->element;
  126. if( it->attribute[0] && it->value[0] )
  127. {
  128. ret += '[';
  129. ret += it->attribute;
  130. ret += '=';
  131. ret += it->value;
  132. ret += ']';
  133. }
  134. }
  135. return ret;
  136. }
  137. };
  138. /**
  139. * Function Convert
  140. * converts a wxString to a generic type T.
  141. * @param aValue is a wxString containing the value that will be converted to type T.
  142. * @throw XML_PARSER_ERROR - an exception is thrown if the parsing fails or if the conversion to
  143. * type T is unknown.
  144. */
  145. template<typename T>
  146. T Convert( const wxString& aValue )
  147. {
  148. throw XML_PARSER_ERROR( "Conversion failed. Unknown type." );
  149. }
  150. template <>
  151. wxString Convert<wxString>( const wxString& aValue );
  152. /**
  153. * OPTIONAL_XML_ATTRIBUTE
  154. * models an optional XML attribute.
  155. * This was implemented as an alternative to OPT. This class should be replaced with a
  156. * simple typedef per type using std::optional when C++17 is published.
  157. */
  158. template <typename T>
  159. class OPTIONAL_XML_ATTRIBUTE
  160. {
  161. private:
  162. /// A boolean indicating if the data is present or not.
  163. bool m_isAvailable;
  164. /// The actual data if m_isAvailable is true; otherwise, garbage.
  165. T m_data;
  166. public:
  167. /**
  168. * Constructor OPTIONAL_XML_ATTRIBUTE
  169. * construct a default OPTIONAL_XML_ATTRIBUTE, whose data is not available.
  170. */
  171. OPTIONAL_XML_ATTRIBUTE() :
  172. m_isAvailable( false ),
  173. m_data( T() )
  174. {}
  175. /**
  176. * Constructor OPTIONAL_XML_ATTRIBUTE
  177. * @param aData is a wxString containing the value that should be converted to type T. If
  178. * aData is empty, the attribute is understood as unavailable; otherwise, the
  179. * conversion to T is tried.
  180. */
  181. OPTIONAL_XML_ATTRIBUTE( const wxString& aData )
  182. {
  183. m_data = T();
  184. m_isAvailable = !aData.IsEmpty();
  185. if( m_isAvailable )
  186. Set( aData );
  187. }
  188. /**
  189. * Constructor OPTIONAL_XML_ATTRIBUTE
  190. * @param aData is the value of the XML attribute. If this constructor is called, the
  191. * attribute is available.
  192. */
  193. template<typename V = T>
  194. OPTIONAL_XML_ATTRIBUTE( T aData ) :
  195. m_isAvailable( true ),
  196. m_data( aData )
  197. {}
  198. /**
  199. * Operator bool
  200. * @return bool - the availability of the attribute.
  201. */
  202. operator bool() const
  203. {
  204. return m_isAvailable;
  205. }
  206. /**
  207. * Assignment operator
  208. * to a string (optionally) containing the data.
  209. * @param aData is a wxString that should be converted to T. If the string is empty, the
  210. * attribute is set to unavailable.
  211. */
  212. OPTIONAL_XML_ATTRIBUTE<T>& operator =( const wxString& aData )
  213. {
  214. m_isAvailable = !aData.IsEmpty();
  215. if( m_isAvailable )
  216. Set( aData );
  217. return *this;
  218. }
  219. /**
  220. * Assignment operator
  221. * to an object of the base type containing the data.
  222. * @param aData is the actual value of the attribute. Calling this assignment, the attribute
  223. * is automatically made available.
  224. */
  225. OPTIONAL_XML_ATTRIBUTE<T>& operator =( T aData )
  226. {
  227. m_data = aData;
  228. m_isAvailable = true;
  229. return *this;
  230. }
  231. /**
  232. * Equal operator
  233. * to an object of the base type.
  234. * @param aOther is the object of the base type that should be compared with this one.
  235. */
  236. bool operator ==( const T& aOther ) const
  237. {
  238. return m_isAvailable && ( aOther == m_data );
  239. }
  240. /**
  241. * Function Set
  242. * tries to convert a string to the base type.
  243. * @param aString is the string that will be converted to the base type.
  244. */
  245. void Set( const wxString& aString )
  246. {
  247. m_data = Convert<T>( aString );
  248. m_isAvailable = !aString.IsEmpty();
  249. }
  250. /**
  251. * Function Get
  252. * returns a reference to the value of the attribute assuming it is available.
  253. * @return T& - the value of the attribute.
  254. */
  255. T& Get()
  256. {
  257. assert( m_isAvailable );
  258. return m_data;
  259. }
  260. /**
  261. * Function CGet
  262. * returns a constant reference to the value of the attribute assuming it is available.
  263. * @return const T& - the value of the attribute.
  264. */
  265. const T& CGet() const
  266. {
  267. assert( m_isAvailable );
  268. return m_data;
  269. }
  270. /**
  271. * Operator *
  272. * returns a reference to the value of the attribute assuming it is available.
  273. * @return T& - the value of the attribute.
  274. */
  275. T& operator*()
  276. {
  277. return Get();
  278. }
  279. /**
  280. * Operator *
  281. * returns a constant reference to the value of the attribute assuming it is available.
  282. * @return const T& - the value of the attribute.
  283. */
  284. const T& operator*() const
  285. {
  286. return CGet();
  287. }
  288. /**
  289. * Operator ->
  290. * returns a pointer to the value of the attribute assuming it is available.
  291. * @return T* - the value of the attribute.
  292. */
  293. T* operator->()
  294. {
  295. return &Get();
  296. }
  297. /**
  298. * Operator ->
  299. * returns a constant pointer to the value of the attribute assuming it is available.
  300. * @return const T* - the value of the attribute.
  301. */
  302. const T* operator->() const
  303. {
  304. return &CGet();
  305. }
  306. };
  307. /**
  308. * Function MapChildren
  309. * provides an easy access to the children of an XML node via their names.
  310. * @param currentNode is a pointer to a wxXmlNode, whose children will be mapped.
  311. * @return NODE_MAP - a map linking the name of each children to the children itself (via a
  312. * wxXmlNode*)
  313. */
  314. NODE_MAP MapChildren( wxXmlNode* aCurrentNode );
  315. ///> Convert an Eagle curve end to a KiCad center for S_ARC
  316. wxPoint ConvertArcCenter( const wxPoint& aStart, const wxPoint& aEnd, double aAngle );
  317. // Pre-declare for typedefs
  318. struct EROT;
  319. struct ECOORD;
  320. typedef OPTIONAL_XML_ATTRIBUTE<wxString> opt_wxString;
  321. typedef OPTIONAL_XML_ATTRIBUTE<int> opt_int;
  322. typedef OPTIONAL_XML_ATTRIBUTE<double> opt_double;
  323. typedef OPTIONAL_XML_ATTRIBUTE<bool> opt_bool;
  324. typedef OPTIONAL_XML_ATTRIBUTE<EROT> opt_erot;
  325. typedef OPTIONAL_XML_ATTRIBUTE<ECOORD> opt_ecoord;
  326. // All of the 'E'STRUCTS below merely hold Eagle XML information verbatim, in binary.
  327. // For maintenance and troubleshooting purposes, it was thought that we'd need to
  328. // separate the conversion process into distinct steps. There is no intent to have KiCad
  329. // forms of information in these 'E'STRUCTS. They are only binary forms
  330. // of the Eagle information in the corresponding Eagle XML nodes.
  331. // Eagle coordinates
  332. struct ECOORD
  333. {
  334. enum EAGLE_UNIT
  335. {
  336. EU_NM, ///< nanometers
  337. EU_MM, ///< millimeters
  338. EU_INCH, ///< inches
  339. EU_MIL, ///< mils/thous
  340. };
  341. ///> Value expressed in nanometers
  342. long long int value;
  343. ///> Unit used for the value field
  344. static constexpr EAGLE_UNIT ECOORD_UNIT = EU_NM;
  345. ECOORD()
  346. : value( 0 )
  347. {
  348. }
  349. ECOORD( int aValue, enum EAGLE_UNIT aUnit )
  350. : value( ConvertToNm( aValue, aUnit ) )
  351. {
  352. }
  353. ECOORD( const wxString& aValue, enum EAGLE_UNIT aUnit );
  354. int ToMils() const
  355. {
  356. return value / 25400;
  357. }
  358. int To100NanoMeters() const
  359. {
  360. return value / 100;
  361. }
  362. int ToNanoMeters() const
  363. {
  364. return value;
  365. }
  366. float ToMm() const
  367. {
  368. return value / 1000000.0;
  369. }
  370. int ToSchUnits() const { return To100NanoMeters(); }
  371. int ToPcbUnits() const { return ToNanoMeters(); }
  372. ECOORD operator+( const ECOORD& aOther ) const
  373. {
  374. return ECOORD( value + aOther.value, ECOORD_UNIT );
  375. }
  376. ECOORD operator-( const ECOORD& aOther ) const
  377. {
  378. return ECOORD( value - aOther.value, ECOORD_UNIT );
  379. }
  380. bool operator==( const ECOORD& aOther ) const
  381. {
  382. return value == aOther.value;
  383. }
  384. ///> Converts a size expressed in a certain unit to nanometers.
  385. static long long int ConvertToNm( int aValue, enum EAGLE_UNIT aUnit );
  386. };
  387. /// Eagle net
  388. struct ENET
  389. {
  390. int netcode;
  391. wxString netname;
  392. ENET( int aNetCode, const wxString& aNetName ) :
  393. netcode( aNetCode ),
  394. netname( aNetName )
  395. {}
  396. ENET() :
  397. netcode( 0 )
  398. {}
  399. };
  400. /// Eagle rotation
  401. struct EROT
  402. {
  403. bool mirror;
  404. bool spin;
  405. double degrees;
  406. EROT() :
  407. mirror( false ),
  408. spin( false ),
  409. degrees( 0 )
  410. {}
  411. EROT( double aDegrees ) :
  412. mirror( false ),
  413. spin( false ),
  414. degrees( aDegrees )
  415. {}
  416. };
  417. /// Eagle wire
  418. struct EWIRE
  419. {
  420. ECOORD x1;
  421. ECOORD y1;
  422. ECOORD x2;
  423. ECOORD y2;
  424. ECOORD width;
  425. LAYER_NUM layer;
  426. // for style: (continuous | longdash | shortdash | dashdot)
  427. enum {
  428. CONTINUOUS,
  429. LONGDASH,
  430. SHORTDASH,
  431. DASHDOT,
  432. };
  433. opt_int style;
  434. opt_double curve; ///< range is -359.9..359.9
  435. // for cap: (flat | round)
  436. enum {
  437. FLAT,
  438. ROUND,
  439. };
  440. opt_int cap;
  441. EWIRE( wxXmlNode* aWire );
  442. };
  443. /// Eagle Junction
  444. struct EJUNCTION
  445. {
  446. ECOORD x;
  447. ECOORD y;
  448. EJUNCTION( wxXmlNode* aJunction);
  449. };
  450. /// Eagle label
  451. struct ELABEL
  452. {
  453. ECOORD x;
  454. ECOORD y;
  455. ECOORD size;
  456. LAYER_NUM layer;
  457. opt_erot rot;
  458. opt_wxString xref;
  459. wxString netname;
  460. ELABEL( wxXmlNode* aLabel, const wxString& aNetName );
  461. };
  462. /// Eagle via
  463. struct EVIA
  464. {
  465. ECOORD x;
  466. ECOORD y;
  467. int layer_front_most; /// < extent
  468. int layer_back_most; /// < inclusive
  469. ECOORD drill;
  470. opt_ecoord diam;
  471. opt_wxString shape;
  472. EVIA( wxXmlNode* aVia );
  473. };
  474. /// Eagle circle
  475. struct ECIRCLE
  476. {
  477. ECOORD x;
  478. ECOORD y;
  479. ECOORD radius;
  480. ECOORD width;
  481. LAYER_NUM layer;
  482. ECIRCLE( wxXmlNode* aCircle );
  483. };
  484. /// Eagle XML rectangle in binary
  485. struct ERECT
  486. {
  487. ECOORD x1;
  488. ECOORD y1;
  489. ECOORD x2;
  490. ECOORD y2;
  491. int layer;
  492. opt_erot rot;
  493. ERECT( wxXmlNode* aRect );
  494. };
  495. /**
  496. * EATTR
  497. * parses an Eagle "attribute" XML element. Note that an attribute element
  498. * is different than an XML element attribute. The attribute element is a
  499. * full XML node in and of itself, and has attributes of its own. Blame Eagle.
  500. */
  501. struct EATTR
  502. {
  503. wxString name;
  504. opt_wxString value;
  505. opt_ecoord x;
  506. opt_ecoord y;
  507. opt_ecoord size;
  508. opt_int layer;
  509. opt_double ratio;
  510. opt_erot rot;
  511. enum { // for 'display'
  512. Off,
  513. VALUE,
  514. NAME,
  515. BOTH,
  516. };
  517. opt_int display;
  518. opt_int align;
  519. EATTR( wxXmlNode* aTree );
  520. EATTR() {}
  521. };
  522. /// Eagle dimension element
  523. struct EDIMENSION
  524. {
  525. ECOORD x1;
  526. ECOORD y1;
  527. ECOORD x2;
  528. ECOORD y2;
  529. ECOORD x3;
  530. ECOORD y3;
  531. int layer;
  532. opt_wxString dimensionType;
  533. EDIMENSION( wxXmlNode* aDimension );
  534. };
  535. /// Eagle text element
  536. struct ETEXT
  537. {
  538. wxString text;
  539. ECOORD x;
  540. ECOORD y;
  541. ECOORD size;
  542. int layer;
  543. opt_wxString font;
  544. opt_double ratio;
  545. opt_erot rot;
  546. enum { // for align
  547. CENTER,
  548. CENTER_LEFT,
  549. TOP_CENTER,
  550. TOP_LEFT,
  551. TOP_RIGHT,
  552. // opposites are -1 x above, used by code tricks in here
  553. CENTER_RIGHT = -CENTER_LEFT,
  554. BOTTOM_CENTER = -TOP_CENTER,
  555. BOTTOM_LEFT = -TOP_RIGHT,
  556. BOTTOM_RIGHT = -TOP_LEFT,
  557. };
  558. opt_int align;
  559. ETEXT( wxXmlNode* aText );
  560. /// Calculate text size based on font type and size
  561. wxSize ConvertSize() const;
  562. };
  563. /// Structure holding common properties for through-hole and SMD pads
  564. struct EPAD_COMMON
  565. {
  566. wxString name;
  567. ECOORD x, y;
  568. opt_erot rot;
  569. opt_bool stop;
  570. opt_bool thermals;
  571. EPAD_COMMON( wxXmlNode* aPad );
  572. };
  573. /// Eagle thru hole pad
  574. struct EPAD : public EPAD_COMMON
  575. {
  576. ECOORD drill;
  577. opt_ecoord diameter;
  578. // for shape: (square | round | octagon | long | offset)
  579. enum {
  580. UNDEF = -1,
  581. SQUARE,
  582. ROUND,
  583. OCTAGON,
  584. LONG,
  585. OFFSET,
  586. };
  587. opt_int shape;
  588. opt_bool first;
  589. EPAD( wxXmlNode* aPad );
  590. };
  591. /// Eagle SMD pad
  592. struct ESMD : public EPAD_COMMON
  593. {
  594. ECOORD dx;
  595. ECOORD dy;
  596. int layer;
  597. opt_int roundness;
  598. opt_bool cream;
  599. ESMD( wxXmlNode* aSMD );
  600. };
  601. /// Eagle pin element
  602. struct EPIN
  603. {
  604. wxString name;
  605. ECOORD x;
  606. ECOORD y;
  607. opt_wxString visible;
  608. opt_wxString length;
  609. opt_wxString direction;
  610. opt_wxString function;
  611. opt_int swaplevel;
  612. opt_erot rot;
  613. EPIN( wxXmlNode* aPin );
  614. };
  615. /// Eagle vertex
  616. struct EVERTEX
  617. {
  618. ECOORD x;
  619. ECOORD y;
  620. opt_double curve; ///< range is -359.9..359.9
  621. EVERTEX( wxXmlNode* aVertex );
  622. };
  623. /// Eagle polygon, without vertices which are parsed as needed
  624. struct EPOLYGON
  625. {
  626. ECOORD width;
  627. int layer;
  628. opt_ecoord spacing;
  629. // KiCad priority is opposite of Eagle rank, that is:
  630. // - Eagle Low rank drawn first
  631. // - KiCad high priority drawn first
  632. // So since Eagle has an upper limit we define this, used for the cases
  633. // where no rank is specified.
  634. static const int max_priority = 6;
  635. enum { // for pour
  636. SOLID,
  637. HATCH,
  638. CUTOUT,
  639. };
  640. int pour;
  641. opt_ecoord isolate;
  642. opt_bool orphans;
  643. opt_bool thermals;
  644. opt_int rank;
  645. EPOLYGON( wxXmlNode* aPolygon );
  646. };
  647. /// Eagle hole element
  648. struct EHOLE
  649. {
  650. ECOORD x;
  651. ECOORD y;
  652. ECOORD drill;
  653. EHOLE( wxXmlNode* aHole );
  654. };
  655. /// Eagle element element
  656. struct EELEMENT
  657. {
  658. wxString name;
  659. wxString library;
  660. wxString package;
  661. wxString value;
  662. ECOORD x;
  663. ECOORD y;
  664. opt_bool locked;
  665. opt_bool smashed;
  666. opt_erot rot;
  667. EELEMENT( wxXmlNode* aElement );
  668. };
  669. struct ELAYER
  670. {
  671. int number;
  672. wxString name;
  673. int color;
  674. int fill;
  675. opt_bool visible;
  676. opt_bool active;
  677. ELAYER( wxXmlNode* aLayer );
  678. };
  679. struct EAGLE_LAYER
  680. {
  681. enum
  682. {
  683. TOP = 1,
  684. ROUTE2 = 2,
  685. ROUTE3 = 3,
  686. ROUTE4 = 4,
  687. ROUTE5 = 5,
  688. ROUTE6 = 6,
  689. ROUTE7 = 7,
  690. ROUTE8 = 8,
  691. ROUTE9 = 9,
  692. ROUTE10 = 10,
  693. ROUTE11 = 11,
  694. ROUTE12 = 12,
  695. ROUTE13 = 13,
  696. ROUTE14 = 14,
  697. ROUTE15 = 15,
  698. BOTTOM = 16,
  699. PADS = 17,
  700. VIAS = 18,
  701. UNROUTED = 19,
  702. DIMENSION = 20,
  703. TPLACE = 21,
  704. BPLACE = 22,
  705. TORIGINS = 23,
  706. BORIGINS = 24,
  707. TNAMES = 25,
  708. BNAMES = 26,
  709. TVALUES = 27,
  710. BVALUES = 28,
  711. TSTOP = 29,
  712. BSTOP = 30,
  713. TCREAM = 31,
  714. BCREAM = 32,
  715. TFINISH = 33,
  716. BFINISH = 34,
  717. TGLUE = 35,
  718. BGLUE = 36,
  719. TTEST = 37,
  720. BTEST = 38,
  721. TKEEPOUT = 39,
  722. BKEEPOUT = 40,
  723. TRESTRICT = 41,
  724. BRESTRICT = 42,
  725. VRESTRICT = 43,
  726. DRILLS = 44,
  727. HOLES = 45,
  728. MILLING = 46,
  729. MEASURES = 47,
  730. DOCUMENT = 48,
  731. REFERENCELC = 49,
  732. REFERENCELS = 50,
  733. TDOCU = 51,
  734. BDOCU = 52,
  735. NETS = 91,
  736. BUSSES = 92,
  737. PINS = 93,
  738. SYMBOLS = 94,
  739. NAMES = 95,
  740. VALUES = 96,
  741. INFO = 97,
  742. GUIDE = 98,
  743. USERLAYER1 = 160,
  744. USERLAYER2 = 161
  745. };
  746. };
  747. struct EPART
  748. {
  749. /*
  750. * <!ELEMENT part (attribute*, variant*)>
  751. * <!ATTLIST part
  752. * name %String; #REQUIRED
  753. * library %String; #REQUIRED
  754. * deviceset %String; #REQUIRED
  755. * device %String; #REQUIRED
  756. * technology %String; ""
  757. * value %String; #IMPLIED
  758. * >
  759. */
  760. wxString name;
  761. wxString library;
  762. wxString deviceset;
  763. wxString device;
  764. opt_wxString technology;
  765. opt_wxString value;
  766. std::map<std::string,std::string> attribute;
  767. std::map<std::string,std::string> variant;
  768. EPART( wxXmlNode* aPart );
  769. };
  770. struct EINSTANCE
  771. {
  772. /*
  773. * <!ELEMENT instance (attribute)*>
  774. * <!ATTLIST instance
  775. * part %String; #REQUIRED
  776. * gate %String; #REQUIRED
  777. * x %Coord; #REQUIRED
  778. * y %Coord; #REQUIRED
  779. * smashed %Bool; "no"
  780. * rot %Rotation; "R0"
  781. * >
  782. */
  783. wxString part;
  784. wxString gate;
  785. ECOORD x;
  786. ECOORD y;
  787. opt_bool smashed;
  788. opt_erot rot;
  789. EINSTANCE( wxXmlNode* aInstance );
  790. };
  791. struct EGATE
  792. {
  793. /*
  794. * <!ELEMENT gate EMPTY>
  795. * <!ATTLIST gate
  796. * name %String; #REQUIRED
  797. * symbol %String; #REQUIRED
  798. * x %Coord; #REQUIRED
  799. * y %Coord; #REQUIRED
  800. * addlevel %GateAddLevel; "next"
  801. * swaplevel %Int; "0"
  802. * >
  803. */
  804. wxString name;
  805. wxString symbol;
  806. ECOORD x;
  807. ECOORD y;
  808. opt_int addlevel;
  809. opt_int swaplevel;
  810. enum
  811. {
  812. MUST,
  813. CAN,
  814. NEXT,
  815. REQUEST,
  816. ALWAYS
  817. };
  818. EGATE( wxXmlNode* aGate );
  819. };
  820. struct ECONNECT
  821. {
  822. /*
  823. * <!ELEMENT connect EMPTY>
  824. * <!ATTLIST connect
  825. * gate %String; #REQUIRED
  826. * pin %String; #REQUIRED
  827. * pad %String; #REQUIRED
  828. * route %ContactRoute; "all"
  829. * >
  830. */
  831. wxString gate;
  832. wxString pin;
  833. wxString pad;
  834. //int contactroute; // TODO
  835. ECONNECT( wxXmlNode* aConnect );
  836. };
  837. struct EDEVICE
  838. {
  839. /*
  840. <!ELEMENT device (connects?, technologies?)>
  841. <!ATTLIST device
  842. name %String; ""
  843. package %String; #IMPLIED
  844. >
  845. */
  846. wxString name;
  847. opt_wxString package;
  848. std::vector<ECONNECT> connects;
  849. EDEVICE( wxXmlNode* aDevice );
  850. };
  851. struct EDEVICE_SET
  852. {
  853. /*
  854. <!ELEMENT deviceset (description?, gates, devices)>
  855. <!ATTLIST deviceset
  856. name %String; #REQUIRED
  857. prefix %String; ""
  858. uservalue %Bool; "no"
  859. >
  860. */
  861. wxString name;
  862. opt_wxString prefix;
  863. opt_bool uservalue;
  864. //std::vector<EDEVICE> devices;
  865. //std::vector<EGATE> gates;
  866. EDEVICE_SET( wxXmlNode* aDeviceSet );
  867. };
  868. #endif // _EAGLE_PARSER_H_