KiCad PCB EDA Suite
cadstar_archive_parser.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020-2021 Roberto Fernandez Bautista <roberto.fer.bau@gmail.com>
5  * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
26 #ifndef CADSTAR_ARCHIVE_PARSER_H_
27 #define CADSTAR_ARCHIVE_PARSER_H_
28 
29 #include <dsnlexer.h>
30 #include <vector>
31 #include <wx/log.h>
32 #include <wx/xml/xml.h>
33 #include <xnode.h>
34 
35 // THROW_IO_ERROR definitions to ensure consistent wording is used in the error messages
36 
37 #define THROW_MISSING_NODE_IO_ERROR( nodename, location ) \
38  THROW_IO_ERROR( wxString::Format( _( "Missing node '%s' in '%s'" ), nodename, location ) )
39 
40 #define THROW_UNKNOWN_NODE_IO_ERROR( nodename, location ) \
41  THROW_IO_ERROR( wxString::Format( _( "Unknown node '%s' in '%s'" ), nodename, location ) )
42 
43 #define THROW_MISSING_PARAMETER_IO_ERROR( param, location ) \
44  THROW_IO_ERROR( wxString::Format( _( "Missing Parameter '%s' in '%s'" ), param, location ) )
45 
46 #define THROW_UNKNOWN_PARAMETER_IO_ERROR( param, location ) \
47  THROW_IO_ERROR( wxString::Format( _( "Unknown Parameter '%s' in '%s'" ), param, location ) )
48 
49 #define THROW_PARSING_IO_ERROR( param, location ) \
50  THROW_IO_ERROR( wxString::Format( _( "Unable to parse '%s' in '%s'" ), param, location ) )
51 
52 //=================================
53 // MACRO DEFINITIONS
54 //=================================
55 #define UNDEFINED_LAYER_ID ( LAYER_ID ) wxEmptyString
56 
57 
61 #define COMPONENT_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME__" )
62 
67 #define COMPONENT_NAME_2_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME_2__" )
68 
72 #define SYMBOL_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__SYMBOL_NAME__" )
73 #define LINK_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__LINK_ORIGIN__" )
74 #define SIGNALNAME_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__SIGNALNAME_ORIGIN__" )
75 #define PART_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__PART_NAME__" )
76 
77 class EDA_TEXT;
78 
83 {
84 public:
85  typedef wxString LINECODE_ID;
86  typedef wxString HATCHCODE_ID;
87  typedef wxString ROUTECODE_ID;
88  typedef wxString NETCLASS_ID;
89  typedef wxString SPACING_CLASS_ID;
90  typedef wxString TEXTCODE_ID;
91  typedef wxString LAYER_ID;
92  typedef wxString VARIANT_ID;
93  typedef wxString ATTRIBUTE_ID;
94  typedef wxString SYMDEF_ID;
95  typedef wxString PART_ID;
96  typedef wxString GATE_ID;
97  typedef long TERMINAL_ID;
98  typedef long PART_DEFINITION_PIN_ID;
99  typedef long PART_PIN_ID;
100  typedef wxString TEXT_ID;
101  typedef wxString FIGURE_ID;
102  typedef wxString GROUP_ID;
103  typedef wxString REUSEBLOCK_ID;
104  typedef wxString NET_ID;
105  typedef wxString NETELEMENT_ID;
106  typedef wxString DOCUMENTATION_SYMBOL_ID;
107  typedef wxString COLOR_ID;
108 
109  static const long UNDEFINED_VALUE = -1;
110 
122  static const double TXT_HEIGHT_RATIO;
123 
128  enum class TEXT_FIELD_NAME
129  {
130  DESIGN_TITLE,
132  LONG_JOBNAME,
134  SHEET_NUMBER,
135  SHEET_NAME,
136  VARIANT_NAME,
138  REG_USER,
139  COMPANY_NAME,
140  CURRENT_USER,
141  DATE,
142  TIME,
143  MACHINE_NAME,
144  FROM_FILE,
145  DISTANCE,
146  UNITS_SHORT,
147  UNITS_ABBREV,
148  UNITS_FULL,
149  HYPERLINK,
150  NONE
151  };
152 
157  static const std::map<TEXT_FIELD_NAME, wxString> CADSTAR_TO_KICAD_FIELDS;
158 
159 
161  {
167  std::map<wxString, wxString> FilenamesToTextMap;
168 
173  std::map<wxString, wxString> TextToHyperlinksMap;
174 
179  std::map<TEXT_FIELD_NAME, wxString> TextFieldToValuesMap;
180 
185  std::set<TEXT_FIELD_NAME> InconsistentTextFields;
186  };
187 
195  static wxString ParseTextFields( wxString aTextString, PARSER_CONTEXT* aParserContext );
196 
197 
198  struct PARSER
199  {
200  virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) = 0;
201 
202  virtual ~PARSER() {};
203  };
204 
205 
206  struct FORMAT : PARSER
207  {
208  wxString Type;
209  long SomeInt;
210  long Version;
211  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
214  };
215 
216 
217  struct TIMESTAMP : PARSER
218  {
219  long Year;
220  long Month;
221  long Day;
222  long Hour;
223  long Minute;
224  long Second;
225 
226  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
227  };
228 
229  //Note: there are possibly several other resolutions, but HUNDREDTH MICRON is only one known
230  enum class RESOLUTION
231  {
233  };
234 
235 
236  struct HEADER : PARSER
237  {
239  wxString JobFile;
240  wxString JobTitle;
241  wxString Generator;
244 
245  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
246  };
247 
248 
249  struct VARIANT : PARSER
250  {
251  VARIANT_ID ID = wxEmptyString;
252  VARIANT_ID ParentID = wxEmptyString;
253  wxString Name = wxEmptyString;
254  wxString Description = wxEmptyString;
255 
256  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
257  };
258 
259 
261  {
262  std::map<VARIANT_ID, VARIANT> Variants;
263 
264  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
265  };
266 
267 
268  enum class LINESTYLE
269  {
270  SOLID,
271  DASH,
272  DASHDOT,
273  DASHDOTDOT,
274  DOT
275  };
276 
277 
278  struct LINECODE : PARSER
279  {
281  wxString Name;
282  long Width;
284 
285  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
286  };
287 
288 
289  struct HATCH : PARSER
290  {
291  long Step;
292  long LineWidth;
293  long OrientAngle;
294 
295  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
296  };
297 
298 
299  struct HATCHCODE : PARSER
300  {
302  wxString Name;
303  std::vector<HATCH> Hatches;
304 
305  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
306  };
307 
308 
309  static const long FONT_NORMAL = 400;
310  static const long FONT_BOLD = 700;
311 
312 
313  struct FONT : PARSER
314  {
315  wxString Name = wxT( "CADSTAR" );
317  long Modifier2 = 0;
319  false;
320  bool Italic = false;
323 
324  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
325  };
326 
327 
328  struct TEXTCODE : PARSER
329  {
331  wxString Name;
332  long LineWidth;
333  long Height;
334  long Width;
335  FONT Font;
338 
339  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
340  };
341 
342 
344  {
347  long MinWidth;
348  long MaxWidth;
350 
351  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
352  };
353 
354 
355  struct ROUTECODE : PARSER
356  {
358  wxString Name;
360  long MinWidth;
361  long MaxWidth;
363 
364  std::vector<ROUTEREASSIGN> RouteReassigns;
365 
366  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
367  };
368 
369 
373  struct EVALUE : PARSER
374  {
375  long Base = 0;
376  long Exponent = 0;
377 
378  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
379  double GetDouble();
380  };
381 
385  struct POINT : wxPoint, PARSER
386  {
388  {
389  }
390 
391  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
392  };
393 
394 
395  struct LONGPOINT : PARSER
396  {
399 
400  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
401  };
402 
403 
404  enum class VERTEX_TYPE
405  {
406  POINT,
411  };
412 
417  struct VERTEX : PARSER
418  {
422 
423  static bool IsVertex( XNODE* aNode );
424  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
425  };
426 
430  struct CUTOUT : PARSER
431  {
432  std::vector<VERTEX> Vertices;
433 
434  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
435  };
436 
437 
438  enum class SHAPE_TYPE
439  {
440  OPENSHAPE,
441  OUTLINE,
442  SOLID,
443  HATCHED
444  };
445 
446 
447  struct SHAPE : PARSER
448  {
450  std::vector<VERTEX> Vertices;
451  std::vector<CUTOUT> Cutouts;
452  wxString HatchCodeID;
453 
454  static bool IsShape( XNODE* aNode );
455  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
456  };
457 
458 
459  enum class UNITS
460  {
461  DESIGN,
462  THOU,
463  INCH,
464  MICROMETRE,
465  MM,
466  CENTIMETER,
467  METER
468  };
469 
470 
471  static UNITS ParseUnits( XNODE* aNode );
472 
473 
474  enum class ANGUNITS
475  {
476  DEGREES,
477  RADIANS
478  };
479 
480 
481  static ANGUNITS ParseAngunits( XNODE* aNode );
482 
483 
484  enum class GRID_TYPE
485  {
487  STEPGRID
489  };
490 
491 
492  struct GRID : PARSER
493  {
495  wxString Name;
496  long Param1;
497  long Param2;
499 
501  static bool IsGrid( XNODE* aNode );
502  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
503  };
504 
505 
506  struct GRIDS : PARSER
507  {
510  std::vector<GRID> UserGrids;
518 
519  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
520  };
521 
522 
523  struct SETTINGS : PARSER
524  {
528  long BarlineGap;
531  bool AllowBarredText = false;
535 
537  std::pair<POINT, POINT> DesignArea;
540 
541  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
542  virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
543  };
544 
545 
546 
564  enum class ALIGNMENT
565  {
566  NO_ALIGNMENT,
567  TOPLEFT,
568  TOPCENTER,
569  TOPRIGHT,
570  CENTERLEFT,
571  CENTERCENTER,
572  CENTERRIGHT,
573  BOTTOMLEFT,
574  BOTTOMCENTER,
576  };
577 
578 
579  static ALIGNMENT ParseAlignment( XNODE* aNode );
580 
590  enum class JUSTIFICATION
591  {
592  LEFT,
593  CENTER,
594  RIGHT
595  };
596 
597 
598  static JUSTIFICATION ParseJustification( XNODE* aNode );
599 
608  enum class READABILITY
609  {
610  BOTTOM_TO_TOP,
612  };
613 
614 
615  static READABILITY ParseReadability( XNODE* aNode );
616 
617 
618  enum class ATTROWNER
619  {
620  ALL_ITEMS,
621  AREA,
622  BOARD,
623  COMPONENT,
624  CONNECTION,
625  COPPER,
626  DOCSYMBOL,
627  FIGURE,
628  NET,
629  NETCLASS,
630  PART,
632  PIN,
633  SIGNALREF,
634  SYMBOL,
635  SYMDEF,
636  TEMPLATE,
637  TESTPOINT
638  };
639 
640 
641  enum class ATTRUSAGE
642  {
643  BOTH,
644  COMPONENT,
647  PART_LIBRARY,
649  SYMBOL,
650  UNDEFINED
652  };
655 
656 
658  {
662  long OrientAngle = 0;
663  bool Mirror = false;
664  bool Fixed = false;
669 
673  void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
674  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
675  virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
676  };
677 
678 
683  struct ATTRNAME : PARSER
684  {
686  {
687  long ID;
688  long Order;
689 
690  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
691  };
692 
693 
695  {
696  long ID;
697  long Width;
698 
699  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
700  };
701 
703  wxString Name;
709  bool NoTransfer = false;
710  std::vector<COLUMNORDER> ColumnOrders;
717  std::vector<COLUMNWIDTH> ColumnWidths;
718  bool ColumnInvisible = false;
719 
720  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
721  };
722 
723 
725  {
727  wxString Value;
728  bool ReadOnly = false;
729  bool HasLocation = false;
732 
733  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
734  };
735 
736 
743  {
745  {
746  // The default alignment for TEXT_LOCATION (when "NO_ALIGNMENT" is selected) is
747  // Bottom left, matching CADSTAR's default behaviour
749  }
751 
752  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
753  };
754 
755 
757  {
759  wxString Name;
760  std::vector<ATTRIBUTE_VALUE> Attributes;
761 
762  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
763  };
764 
765 
767  {
769  wxString Name;
770 
771  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
772  };
773 
774 
775  struct CODEDEFS : PARSER
776  {
777  std::map<LINECODE_ID, LINECODE> LineCodes;
778  std::map<HATCHCODE_ID, HATCHCODE> HatchCodes;
779  std::map<TEXTCODE_ID, TEXTCODE> TextCodes;
780  std::map<ROUTECODE_ID, ROUTECODE> RouteCodes;
781  std::map<ATTRIBUTE_ID, ATTRNAME> AttributeNames;
782  std::map<NETCLASS_ID, CADSTAR_NETCLASS> NetClasses;
783  std::map<SPACING_CLASS_ID, SPCCLASSNAME> SpacingClassNames;
784 
785  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
786  };
787 
798  enum class SWAP_RULE
799  {
800  NO_SWAP,
802  BOTH
803  };
804 
805 
806  static SWAP_RULE ParseSwapRule( XNODE* aNode );
807 
808 
810  {
812  wxString Name;
813  wxString FileName;
814  bool Mirror = false;
815  long OrientAngle = 0;
816 
817  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
818  };
819 
820 
825  {
826  REUSEBLOCK_ID ReuseBlockID = wxEmptyString;
827  wxString ItemReference = wxEmptyString;
828 
832  bool IsEmpty();
833  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
834  };
835 
836 
837  struct GROUP : PARSER
838  {
840  wxString Name;
841  bool Fixed = false;
842  bool Transfer = false;
843  GROUP_ID GroupID = wxEmptyString;
846 
847  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
848  };
849 
850 
851  struct FIGURE : PARSER
852  {
856  SHAPE Shape; //< Uses the component's coordinate frame if within a component
857  //< definition, otherwise uses the design's coordinate frame.
858  GROUP_ID GroupID = wxEmptyString;
861  bool Fixed = false;
862  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
863 
864  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
865  };
866 
867 
868  struct TEXT : PARSER
869  {
871  wxString Text; //TODO: Need to lex/parse to identify design fields and hyperlinks
875  long OrientAngle = 0;
876  bool Mirror = false;
877  bool Fixed = false;
883  GROUP_ID GroupID = wxEmptyString;
888 
889  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
890  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext, bool aParseFields );
891  };
892 
893 
894  struct SYMDEF : PARSER
895  {
897  wxString ReferenceName;
898  wxString Alternate;
900  POINT Origin;
902  bool Stub = false;
904  long Version = UNDEFINED_VALUE;
910 
912  std::map<FIGURE_ID, FIGURE> Figures;
913  std::map<TEXT_ID, TEXT> Texts;
914  std::map<ATTRIBUTE_ID, TEXT_LOCATION> TextLocations;
915  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
918 
920  void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
921  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
922  };
923 
924 
925  struct PART : PARSER
926  {
927  enum class PIN_TYPE
928  {
929  UNCOMMITTED,
930  INPUT,
931  OUTPUT_OR,
932  OUTPUT_NOT_OR,
934  POWER,
935  GROUND,
939  };
940 
941 
942  static PIN_TYPE GetPinType( XNODE* aNode );
943 
944 
945  struct DEFINITION : PARSER
946  {
947  struct GATE : PARSER
948  {
950  wxString Name;
951  wxString Alternate;
952  long PinCount;
953 
954  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
955  };
956 
957 
958  struct PIN : PARSER
959  {
963  enum class POSITION
964  {
965  TOP_RIGHT = 0,
966  TOP_LEFT = 1,
967  BOTTOM_LEFT = 2,
968  BOTTOM_RIGHT = 3
969  };
970 
972 
973  wxString Identifier = wxEmptyString;
974  wxString Name = wxEmptyString;
979  wxString Label = wxEmptyString;
984  wxString Signal = wxEmptyString;
1004  POSITION Position =
1009 
1012  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1013  };
1014 
1015 
1017  {
1018  std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1019 
1022  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1023  };
1024 
1025 
1026  struct SWAP_GATE : PARSER
1027  {
1028  std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1029 
1031  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1032  };
1033 
1034 
1036  {
1037  wxString GateName =
1038  wxEmptyString;
1039 
1042  bool External = false;
1043 
1050  std::vector<SWAP_GATE> SwapGates;
1051 
1056  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1057  };
1058 
1059  wxString Name;
1061  false;
1062 
1067  UNDEFINED_VALUE;
1068 
1074  std::map<GATE_ID, GATE> GateSymbols;
1075  std::map<PART_DEFINITION_PIN_ID, PIN> Pins;
1076  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1077  std::vector<PIN_EQUIVALENCE> PinEquivalences;
1081  std::vector<SWAP_GROUP> SwapGroups;
1082 
1083  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1084  };
1085 
1086 
1087  struct PART_PIN : PARSER
1088  {
1090  wxString Name = wxEmptyString;
1092  wxString Identifier = wxEmptyString;
1093 
1094  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1095  };
1096 
1097 
1099  wxString Name;
1100  long Version;
1102  std::map<PART_PIN_ID, PART_PIN> PartPins;
1103 
1108  bool HidePinNames = false;
1109 
1111  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1112 
1116  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1117  };
1118 
1119 
1120  struct PARTS : PARSER
1121  {
1122  std::map<PART_ID, PART> PartDefinitions;
1123 
1124  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1125  };
1126 
1127 
1128  struct NET : PARSER
1129  {
1130  struct JUNCTION : PARSER
1131  {
1135  GROUP_ID GroupID = wxEmptyString;
1138  bool Fixed = false;
1139 
1140  void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1141  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1142  virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1143  };
1144 
1145 
1146  struct CONNECTION : PARSER
1147  {
1151 
1152  bool Fixed = false;
1153  bool Hidden = false;
1154  GROUP_ID GroupID = wxEmptyString;
1156 
1157  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1158  void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1161  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1162 
1163  virtual ~CONNECTION() {}
1164  };
1165 
1167  ROUTECODE_ID RouteCodeID = wxEmptyString;
1169  wxString Name = wxEmptyString;
1171  bool Highlight = false;
1173 
1174  std::map<NETELEMENT_ID, JUNCTION> Junctions;
1175  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1176 
1178  wxEmptyString;
1181  wxEmptyString;
1182 
1184  void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1185  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1186  };
1187 
1188 
1190  {
1192 
1194  LAYER_ID LayerID;
1199 
1201  GROUP_ID GroupID = wxEmptyString;
1203  long OrientAngle = 0;
1204  bool Mirror = false;
1205  bool Fixed = false;
1207 
1209  long ScaleRatioDenominator = 1;
1211 
1213  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1214 
1215  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1216  };
1217 
1218 
1220  {
1222  bool IsVisible = true;
1223 
1224  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1225  };
1226 
1227 
1228  struct ATTRCOL : PARSER
1229  {
1232  bool IsVisible = true;
1233  bool IsPickable = true;
1234 
1235  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1236  };
1237 
1238 
1240  {
1242  std::map<ATTRIBUTE_ID, ATTRCOL> AttributeColors;
1243 
1244  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1245  };
1246 
1247 
1249  {
1251  bool IsVisible = true;
1252  bool IsPickable = true;
1253 
1254  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1255  };
1256 
1258  // HELPER FUNCTIONS: //
1260 
1261 
1262  static void InsertAttributeAtEnd( XNODE* aNode, wxString aValue );
1263 
1274  static XNODE* LoadArchiveFile( const wxString& aFileName, const wxString& aFileTypeIdentifier );
1275 
1281  static bool IsValidAttribute( wxXmlAttribute* aAttribute );
1282 
1291  static wxString GetXmlAttributeIDString(
1292  XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1293 
1302  static long GetXmlAttributeIDLong( XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1303 
1309  static void CheckNoChildNodes( XNODE* aNode );
1310 
1316  static void CheckNoNextNodes( XNODE* aNode );
1317 
1324  static void ParseChildEValue( XNODE* aNode, PARSER_CONTEXT* aContext, EVALUE& aValueToParse );
1325 
1338  static std::vector<POINT> ParseAllChildPoints( XNODE* aNode, PARSER_CONTEXT* aContext,
1339  bool aTestAllChildNodes = false, int aExpectedNumPoints = UNDEFINED_VALUE );
1340 
1352  static std::vector<VERTEX> ParseAllChildVertices(
1353  XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
1354 
1366  static std::vector<CUTOUT> ParseAllChildCutouts(
1367  XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
1368 
1374  static void FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem );
1375 
1376  static wxString generateLibName( const wxString& aRefName, const wxString& aAlternateName )
1377  {
1378  return aRefName
1379  + ( ( aAlternateName.size() > 0 ) ? ( wxT( " (" ) + aAlternateName + wxT( ")" ) )
1380  : wxT( "" ) );
1381  }
1382 
1383 protected:
1385 
1386 
1387 }; // class CADSTAR_ARCHIVE_PARSER
1388 
1389 #endif // CADSTAR_ARCHIVE_PARSER_H_
long PART_DEFINITION_PIN_ID
Pin identifier in the part definition.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
READABILITY
Sets the readability direction of text.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
wxString Label
This Can be empty (subnode= "PINLABEL") From CADSTAR Help: "Pin Labels are an optional replacement fo...
long PART_PIN_ID
Pin identifier in the part.
LAYER_ID LayerID
Move all objects in the Symdef to this layer.
Note: It seems that some attribute have no "ATTRUSAGE" defined.
From CADSTAR Help: Assigned to Parts library Definitions and displayed by the Library searcher.
std::map< ROUTECODE_ID, ROUTECODE > RouteCodes
long Load
The electrical current expected on the pin (It is unclear what the units are, but only accepted value...
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
bool Transfer
If true, the group is transferred to PCB.
static const double TXT_HEIGHT_RATIO
CADSTAR fonts are drawn on a 24x24 integer matrix, where the each axis goes from 0 to 24.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< PART_DEFINITION_PIN_ID, PIN > Pins
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::pair< POINT, POINT > DesignArea
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString ReferenceName
This is the name which identifies the symbol in the library Multiple components may exist with the sa...
long Modifier2
It seems this is always 0 regardless of settings.
GRID ScreenGrid
From CADSTAR Help: "There is one Screen Grid, which is visible as dots on the screen.
long SignalNum
This is undefined if the net has been given a name.
std::map< ATTRIBUTE_ID, ATTRNAME > AttributeNames
GROUP_ID GroupID
If not empty, this FIGURE is part of a group.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static ANGUNITS ParseAngunits(XNODE *aNode)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
long ScaleRatioNumerator
Documentation symbols can be arbitrarily scaled when added to a design.
static JUSTIFICATION ParseJustification(XNODE *aNode)
TEXT_FIELD_NAME
These are special fields in text objects enclosed between the tokens '<@' and '>' such as <@[FIELD_NA...
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
Helper functions and common structures for CADSTAR PCB and Schematic archive files.
LONGPOINT DesignRef
Appears to be 0,0 always.
static PIN_TYPE GetPinType(XNODE *aNode)
std::map< LINECODE_ID, LINECODE > LineCodes
bool External
Determines if this swap group is external (and internal) or internal only.
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext)=0
wxString ItemReference
For Components, this references the designator in the reuse file.
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
bool HidePinNames
This seems to be a duplicate of DEFINITION::HidePinNames Possibly only used in older file formats?
Filled closed shape (hatch fill).
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static bool IsValidAttribute(wxXmlAttribute *aAttribute)
std::map< NETELEMENT_ID, JUNCTION > Junctions
From CADSTAR Help: Assigned to Schematic Symbols and displayed on Schematic Designs.
long AngularPrecision
Number of decimal points to display for angular dimensions.
std::map< FIGURE_ID, FIGURE > Figures
long ScaleRatioDenominator
Documentation symbols can be arbitrarily scaled when added to a design.
std::vector< COLUMNWIDTH > ColumnWidths
Param1 = X Step, Param2 = Y Step. A standard x,y grid.
std::vector< PIN_EQUIVALENCE > PinEquivalences
bool HasLocation
Flag to know if this ATTRIBUTE_VALUE has a location i.e.
From CADSTAR Help: Only used by non-Cadstar applications.
static SWAP_RULE ParseSwapRule(XNODE *aNode)
long PinCount
Number of pins (terminals) in the symbol.
bool NoTransfer
True="All Design Types", False="Current Design Type" "All Design Types" Description from CADSTAR Help...
ALIGNMENT Alignment
In CADSTAR The default alignment for a TEXT object (when "(No Alignment()" is selected) Bottom Left o...
Always display (Mirrored and Unmirrored)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString Alternate
Symbol alternate name in the symbol library.
TERMINAL_ID TerminalPin
(subnode="PINTERM", param1)
POSITION
Positioning of pin names can be in one of four quadrants.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< wxString, wxString > FilenamesToTextMap
CADSTAR doesn't have user defined text fields but does allow loading text from a file.
long Modifier1
It seems this is related to weight. 400=Normal, 700=Bold.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static void CheckNoChildNodes(XNODE *aNode)
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
POINT Origin
Origin of the component (this is used as the reference point when placing the component in the design...
wxString FileName
Filename of the reuse block (usually a .pcb). Used for reloading.
wxString Name
This name can be different to the PART name.
ALIGNMENT Alignment
In CADSTAR The default alignment for a TEXT object (when "(No Alignment()" is selected) Bottom Left o...
UNITS Units
Units to display for linear dimensions.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static bool IsGrid(XNODE *aNode)
GROUP_ID GroupID
If not empty, this component is part of a group.
GROUP_ID GroupID
If not empty, this connection is part of a group.
std::vector< GRID > UserGrids
List of predefined grids created by the user.
wxString HatchCodeID
Only Applicable for HATCHED Type.
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
Some attributes are defined within the part definition, whilst others are defined in the part itself.
std::set< TEXT_FIELD_NAME > InconsistentTextFields
Text fields need to be updated in CADSTAR and it is possible that they are not consistent across text...
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:119
GROUP_ID GroupID
If not empty, this FIGURE is part of a group.
std::map< wxString, wxString > TextToHyperlinksMap
KiCad doesn't support hyperlinks but we use this map to display warning messages after import.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
long UnitDisplPrecision
Number of decimal points to display for linear dimensions.
std::vector< PART_DEFINITION_PIN_ID > PinIDs
The pins in this vector describe a "gate".
VARIANT_ID ParentID
if empty, then this one is the master
GROUP_ID GroupID
If not empty, this JUCTION is part of a group.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::vector< SWAP_GATE > SwapGates
Each of the elements in this vector can be swapped with each other - i.e.
long SomeInt
It is unclear what this parameter is used for.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
Inherits from design units (assumed Assignments->Technology->Units)
POSITION Position
The pin names will use these positions when the symbol is added to a schematic design subnode="PINPOS...
Represents a point in x,y coordinates.
ALIGNMENT
From CADSTAR Help: "Text Alignment enables you to define the position of an alignment origin for all ...
Represents a floating value in E notation.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static XNODE * LoadArchiveFile(const wxString &aFileName, const wxString &aFileTypeIdentifier)
Reads a CADSTAR Archive file (S-parameter format)
std::map< ATTRIBUTE_ID, ATTRCOL > AttributeColors
long TERMINAL_ID
Terminal is the pin identifier in the schematic.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
std::map< PART_ID, PART > PartDefinitions
References an element from a design reuse block.
GROUP_ID GroupID
If not empty, this GROUP is part of another GROUP.
bool IsEmpty()
Determines if this is empty (i.e. no design reuse associated)
bool Stub
When the CADSTAR Archive file is exported without the component library, if components on the board a...
long Width
Defaults to 0 if using system fonts or, if using CADSTAR font, default to equal height (1:1 aspect ra...
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
ROUTECODE_ID RouteCodeID
"NETCODE" subnode
static std::vector< VERTEX > ParseAllChildVertices(XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false)
if no children are present, it just returns an empty vector (without throwing an exception)
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
When text is vertical, show it rotated 90 degrees clockwise.
long MaxPinCount
Optional parameter which is used for specifying the number of electrical pins on the PCB component sy...
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool AllowBarredText
Specifies if barring is allowed in the design.
static std::vector< CUTOUT > ParseAllChildCutouts(XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false)
if no children are present, it just returns an empty vector (without throwing an exception)
std::map< NETCLASS_ID, CADSTAR_NETCLASS > NetClasses
std::vector< COLUMNORDER > ColumnOrders
SWAP_RULE
Corresponds to "Display when" Item property.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
SYMDEF_ID SymdefID
Normally documentation symbols only have TEXT, FIGURE and TEXT_LOCATION objects which are all drawn o...
std::vector< ROUTEREASSIGN > RouteReassigns
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static void FixTextPositionNoAlignment(EDA_TEXT *aKiCadTextItem)
Corrects the position of a text element that had NO_ALIGNMENT in CADSTAR.
long InterlineGap
For CADSTAR font only, distance between lines of text, expressed as a percentage of the text height (...
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
long Param1
Either Units or X step, depending on Type (see GRID_TYPE for more details)
long BarlineGap
For CADSTAR font only, distance between top bar and character, expressed as a percentage of the text ...
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
std::vector< PART_DEFINITION_PIN_ID > PinIDs
All the pins in this vector are equivalent and can be swapped with each other.
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
These attributes might also have a location.
POINT Origin
Origin of the component (this is used as the reference point when placing the component in the design...
static const long UNDEFINED_VALUE
Corresponds to CADSTAR "origin".
< Nodename = "VARIANT" or "VMASTER" (master variant
std::map< PART_PIN_ID, PART_PIN > PartPins
It is unclear why there are two "Pin" structures in CPA files...
static long GetXmlAttributeIDLong(XNODE *aNode, unsigned int aID, bool aIsRequired=true)
NOTE from CADSTAR help: To convert a Part Definition Attribute into a hyperlink, prefix the attribute...
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString Identifier
This should match a pad identifier in the component footprint subnode="PINIDENTIFIER".
static wxString generateLibName(const wxString &aRefName, const wxString &aAlternateName)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
wxString Name
Parenthesis aren't permitted in user attributes in CADSTAR.
Hold an XML or S-expression element.
Definition: xnode.h:43
JUSTIFICATION Justification
Note: Justification has no effect on single lines of text.
bool HidePinNames
Specifies whether to display the pin names/identifier in the schematic symbol or not.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
JUSTIFICATION
From CADSTAR Help: "Multi Line Text can also be justified as Left, Centre or Right.
wxString Name
Symbol name in the symbol library.
std::vector< CUTOUT > Cutouts
Not Applicable to OPENSHAPE Type.
std::map< TEXTCODE_ID, TEXTCODE > TextCodes
static READABILITY ParseReadability(XNODE *aNode)
Param1 = Units, Param2 = Divisor.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static void CheckNoNextNodes(XNODE *aNode)
< "SWAPGATE" Node name (represents an "Element")
std::map< SPACING_CLASS_ID, SPCCLASSNAME > SpacingClassNames
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static void ParseChildEValue(XNODE *aNode, PARSER_CONTEXT *aContext, EVALUE &aValueToParse)
wxString Name
This is undefined (wxEmptyString) if the net is unnamed.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
long Param2
Either Divisor or Y step, depending on Type (see GRID_TYPE for more details)
std::map< HATCHCODE_ID, HATCHCODE > HatchCodes
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
JUSTIFICATION Justification
Note: Justification has no effect on single lines of text.
long Version
Version is a sequential integer number to identify discrepancies between the library and the design.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString Signal
Usually for Power/Ground pins, (subnode="PINSIGNAL")
static void InsertAttributeAtEnd(XNODE *aNode, wxString aValue)
Unfilled open shape. Cannot have cutouts.
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
Some attributes are defined within the part definition, whilst others are defined in the part.
std::map< ATTRIBUTE_ID, TEXT_LOCATION > TextLocations
This contains location of any attributes, including designator position.
static UNITS ParseUnits(XNODE *aNode)
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
wxString Alternate
This is in addition to ReferenceName.
From CADSTAR Help: Assigned to PCB components and displayed on PCB designs.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
long Version
Archive version number (e.g.
NETELEMENT_ID ID
First character is "J".
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString LAYER_ID
ID of a Sheet (if schematic) or board Layer (if PCB)
bool KerningPairs
From CADSTAR Help: "Kerning Pairs is for causing the system to automatically reduce the spacing betwe...
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
NETCLASS_ID NetClassID
The net might not have a net class, in which case it will be wxEmptyString ("NETCLASSREF" subnode)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static wxString ParseTextFields(wxString aTextString, PARSER_CONTEXT *aParserContext)
Replaces CADSTAR fields for the equivalent in KiCad and stores the field values in aParserContext.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static wxString GetXmlAttributeIDString(XNODE *aNode, unsigned int aID, bool aIsRequired=true)
static ALIGNMENT ParseAlignment(XNODE *aNode)
NO_ALIGNMENT has different meaning depending on the object type.
SPACING_CLASS_ID SpacingClassID
The net might not have a spacing class, in which case it will be wxEmptyString ("SPACINGCLASS" subnod...
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
Filled closed shape (solid fill).
std::map< TEXT_FIELD_NAME, wxString > TextFieldToValuesMap
Values for the text field elements used in the CADSTAR design extracted from the text element instanc...
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static std::vector< POINT > ParseAllChildPoints(XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false, int aExpectedNumPoints=UNDEFINED_VALUE)
if no children are present, it just returns an empty vector (without throwing an exception)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
static const std::map< TEXT_FIELD_NAME, wxString > CADSTAR_TO_KICAD_FIELDS
Map between CADSTAR fields and KiCad text variables.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
It is possible to add attributes solely to a particular connection.
GATE_ID TerminalGate
(subnode="PINTERM", param0)
Represents a cutout in a closed shape (e.g.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
SWAP_RULE SwapRule
Only applicable to Figures in Components.
From CADSTAR Help: Assigned to both Schematic symbols and PCB components, and displayed on Schematic ...
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
Represents a vertex in a shape.
When text is vertical, show it rotated 90 degrees anticlockwise.