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 <[email protected]>
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 <richio.h>
30 #include <wx/gdicmn.h>
31 #include <functional>
32 #include <map>
33 #include <set>
34 #include <vector>
35 #include <xnode.h>
36 
37 // THROW_IO_ERROR definitions to ensure consistent wording is used in the error messages
38 
39 #define THROW_MISSING_NODE_IO_ERROR( nodename, location ) \
40  THROW_IO_ERROR( wxString::Format( _( "Missing node '%s' in '%s'" ), nodename, location ) )
41 
42 #define THROW_UNKNOWN_NODE_IO_ERROR( nodename, location ) \
43  THROW_IO_ERROR( wxString::Format( _( "Unknown node '%s' in '%s'" ), nodename, location ) )
44 
45 #define THROW_MISSING_PARAMETER_IO_ERROR( param, location ) \
46  THROW_IO_ERROR( wxString::Format( _( "Missing Parameter '%s' in '%s'" ), param, location ) )
47 
48 #define THROW_UNKNOWN_PARAMETER_IO_ERROR( param, location ) \
49  THROW_IO_ERROR( wxString::Format( _( "Unknown Parameter '%s' in '%s'" ), param, location ) )
50 
51 #define THROW_PARSING_IO_ERROR( param, location ) \
52  THROW_IO_ERROR( wxString::Format( _( "Unable to parse '%s' in '%s'" ), param, location ) )
53 
54 //=================================
55 // MACRO DEFINITIONS
56 //=================================
57 #define UNDEFINED_LAYER_ID ( LAYER_ID ) wxEmptyString
58 
59 
63 #define COMPONENT_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME__" )
64 
69 #define COMPONENT_NAME_2_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME_2__" )
70 
74 #define SYMBOL_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__SYMBOL_NAME__" )
75 #define LINK_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__LINK_ORIGIN__" )
76 #define SIGNALNAME_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__SIGNALNAME_ORIGIN__" )
77 #define PART_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__PART_NAME__" )
78 
79 class EDA_TEXT;
80 class wxXmlAttribute;
81 class PROGRESS_REPORTER;
82 
87 {
88 public:
90 
91 
92  typedef wxString LINECODE_ID;
93  typedef wxString HATCHCODE_ID;
94  typedef wxString ROUTECODE_ID;
95  typedef wxString NETCLASS_ID;
96  typedef wxString SPACING_CLASS_ID;
97  typedef wxString TEXTCODE_ID;
98  typedef wxString LAYER_ID;
99  typedef wxString VARIANT_ID;
100  typedef wxString ATTRIBUTE_ID;
101  typedef wxString SYMDEF_ID;
102  typedef wxString PART_ID;
103  typedef wxString GATE_ID;
104  typedef long TERMINAL_ID;
105  typedef long PART_DEFINITION_PIN_ID;
106  typedef long PART_PIN_ID;
107  typedef wxString TEXT_ID;
108  typedef wxString FIGURE_ID;
109  typedef wxString GROUP_ID;
110  typedef wxString REUSEBLOCK_ID;
111  typedef wxString NET_ID;
112  typedef wxString NETELEMENT_ID;
113  typedef wxString DOCUMENTATION_SYMBOL_ID;
114  typedef wxString COLOR_ID;
115 
116  static const long UNDEFINED_VALUE = -1;
117 
129  static const double TXT_HEIGHT_RATIO;
130 
135  enum class TEXT_FIELD_NAME
136  {
137  DESIGN_TITLE,
139  LONG_JOBNAME,
141  SHEET_NUMBER,
142  SHEET_NAME,
143  VARIANT_NAME,
145  REG_USER,
146  COMPANY_NAME,
147  CURRENT_USER,
148  DATE,
149  TIME,
150  MACHINE_NAME,
151  FROM_FILE,
152  DISTANCE,
153  UNITS_SHORT,
154  UNITS_ABBREV,
155  UNITS_FULL,
156  HYPERLINK,
157  NONE
158  };
159 
164  static const std::map<TEXT_FIELD_NAME, wxString> CADSTAR_TO_KICAD_FIELDS;
165 
166 
168  {
174  std::map<wxString, wxString> FilenamesToTextMap;
175 
180  std::map<wxString, wxString> TextToHyperlinksMap;
181 
186  std::map<TEXT_FIELD_NAME, wxString> TextFieldToValuesMap;
187 
192  std::set<TEXT_FIELD_NAME> InconsistentTextFields;
193 
197  std::function<void()> CheckPointCallback = []() {};
198  };
199 
207  static wxString ParseTextFields( const wxString& aTextString, PARSER_CONTEXT* aParserContext );
208 
209 
210  struct PARSER
211  {
212  virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) = 0;
213 
214  virtual ~PARSER() {};
215  };
216 
217 
218  struct FORMAT : PARSER
219  {
220  wxString Type;
221  long SomeInt;
222  long Version;
223  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
226  };
227 
228 
229  struct TIMESTAMP : PARSER
230  {
231  long Year;
232  long Month;
233  long Day;
234  long Hour;
235  long Minute;
236  long Second;
237 
238  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
239  };
240 
241  //Note: there are possibly several other resolutions, but HUNDREDTH MICRON is only one known
242  enum class RESOLUTION
243  {
245  };
246 
247 
248  struct HEADER : PARSER
249  {
251  wxString JobFile;
252  wxString JobTitle;
253  wxString Generator;
256 
257  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
258  };
259 
260 
261  struct VARIANT : PARSER
262  {
263  VARIANT_ID ID = wxEmptyString;
264  VARIANT_ID ParentID = wxEmptyString;
265  wxString Name = wxEmptyString;
266  wxString Description = wxEmptyString;
267 
268  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
269  };
270 
271 
273  {
274  std::map<VARIANT_ID, VARIANT> Variants;
275 
276  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
277  };
278 
279 
280  enum class LINESTYLE
281  {
282  SOLID,
283  DASH,
284  DASHDOT,
285  DASHDOTDOT,
286  DOT
287  };
288 
289 
290  struct LINECODE : PARSER
291  {
293  wxString Name;
294  long Width;
296 
297  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
298  };
299 
300 
301  struct HATCH : PARSER
302  {
303  long Step;
304  long LineWidth;
305  long OrientAngle;
306 
307  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
308  };
309 
310 
311  struct HATCHCODE : PARSER
312  {
314  wxString Name;
315  std::vector<HATCH> Hatches;
316 
317  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
318  };
319 
320 
321  static const long FONT_NORMAL = 400;
322  static const long FONT_BOLD = 700;
323 
324 
325  struct FONT : PARSER
326  {
327  wxString Name = wxT( "CADSTAR" );
329  long Modifier2 = 0;
331  false;
332  bool Italic = false;
335 
336  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
337  };
338 
339 
340  struct TEXTCODE : PARSER
341  {
343  wxString Name;
344  long LineWidth;
345  long Height;
346  long Width;
347  FONT Font;
350 
351  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
352  };
353 
354 
356  {
359  long MinWidth;
360  long MaxWidth;
362 
363  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
364  };
365 
366 
367  struct ROUTECODE : PARSER
368  {
370  wxString Name;
372  long MinWidth;
373  long MaxWidth;
375 
376  std::vector<ROUTEREASSIGN> RouteReassigns;
377 
378  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
379  };
380 
381 
385  struct EVALUE : PARSER
386  {
387  long Base = 0;
388  long Exponent = 0;
389 
390  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
391  double GetDouble();
392  };
393 
397  struct POINT : wxPoint, PARSER
398  {
400  {
401  }
402 
403  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
404  };
405 
406 
407  struct LONGPOINT : PARSER
408  {
411 
412  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
413  };
414 
415 
416  enum class VERTEX_TYPE
417  {
418  POINT,
423  };
424 
429  struct VERTEX : PARSER
430  {
434 
435  static bool IsVertex( XNODE* aNode );
436  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
437  };
438 
442  struct CUTOUT : PARSER
443  {
444  std::vector<VERTEX> Vertices;
445 
446  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
447  };
448 
449 
450  enum class SHAPE_TYPE
451  {
452  OPENSHAPE,
453  OUTLINE,
454  SOLID,
455  HATCHED
456  };
457 
458 
459  struct SHAPE : PARSER
460  {
462  std::vector<VERTEX> Vertices;
463  std::vector<CUTOUT> Cutouts;
464  wxString HatchCodeID;
465 
466  static bool IsShape( XNODE* aNode );
467  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
468  };
469 
470 
471  enum class UNITS
472  {
473  DESIGN,
474  THOU,
475  INCH,
476  MICROMETRE,
477  MM,
478  CENTIMETER,
479  METER
480  };
481 
482 
483  static UNITS ParseUnits( XNODE* aNode );
484 
485 
486  enum class ANGUNITS
487  {
488  DEGREES,
489  RADIANS
490  };
491 
492 
493  static ANGUNITS ParseAngunits( XNODE* aNode );
494 
495 
496  enum class GRID_TYPE
497  {
499  STEPGRID
501  };
502 
503 
504  struct GRID : PARSER
505  {
507  wxString Name;
508  long Param1;
509  long Param2;
511 
513  static bool IsGrid( XNODE* aNode );
514  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
515  };
516 
517 
518  struct GRIDS : PARSER
519  {
522  std::vector<GRID> UserGrids;
530 
531  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
532  };
533 
534 
535  struct SETTINGS : PARSER
536  {
540  long BarlineGap;
543  bool AllowBarredText = false;
547 
549  std::pair<POINT, POINT> DesignArea;
552 
553  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
554  virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
555  };
556 
557 
558 
576  enum class ALIGNMENT
577  {
578  NO_ALIGNMENT,
579  TOPLEFT,
580  TOPCENTER,
581  TOPRIGHT,
582  CENTERLEFT,
583  CENTERCENTER,
584  CENTERRIGHT,
585  BOTTOMLEFT,
586  BOTTOMCENTER,
588  };
589 
590 
591  static ALIGNMENT ParseAlignment( XNODE* aNode );
592 
602  enum class JUSTIFICATION
603  {
604  LEFT,
605  CENTER,
606  RIGHT
607  };
608 
609 
610  static JUSTIFICATION ParseJustification( XNODE* aNode );
611 
620  enum class READABILITY
621  {
622  BOTTOM_TO_TOP,
624  };
625 
626 
627  static READABILITY ParseReadability( XNODE* aNode );
628 
629 
630  enum class ATTROWNER
631  {
632  ALL_ITEMS,
633  AREA,
634  BOARD,
635  COMPONENT,
636  CONNECTION,
637  COPPER,
638  DOCSYMBOL,
639  FIGURE,
640  NET,
641  NETCLASS,
642  PART,
644  PIN,
645  SIGNALREF,
646  SYMBOL,
647  SYMDEF,
648  TEMPLATE,
649  TESTPOINT
650  };
651 
652 
653  enum class ATTRUSAGE
654  {
655  BOTH,
656  COMPONENT,
659  PART_LIBRARY,
661  SYMBOL,
662  UNDEFINED
664  };
667 
668 
670  {
674  long OrientAngle = 0;
675  bool Mirror = false;
676  bool Fixed = false;
681 
685  void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
686  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
687  virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
688  };
689 
690 
695  struct ATTRNAME : PARSER
696  {
698  {
699  long ID;
700  long Order;
701 
702  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
703  };
704 
705 
707  {
708  long ID;
709  long Width;
710 
711  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
712  };
713 
715  wxString Name;
721  bool NoTransfer = false;
722  std::vector<COLUMNORDER> ColumnOrders;
729  std::vector<COLUMNWIDTH> ColumnWidths;
730  bool ColumnInvisible = false;
731 
732  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
733  };
734 
735 
737  {
739  wxString Value;
740  bool ReadOnly = false;
741  bool HasLocation = false;
744 
745  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
746  };
747 
748 
755  {
757  {
758  // The default alignment for TEXT_LOCATION (when "NO_ALIGNMENT" is selected) is
759  // Bottom left, matching CADSTAR's default behaviour
761  }
763 
764  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
765  };
766 
767 
769  {
771  wxString Name;
772  std::vector<ATTRIBUTE_VALUE> Attributes;
773 
774  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
775  };
776 
777 
779  {
781  wxString Name;
782 
783  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
784  };
785 
786 
787  struct CODEDEFS : PARSER
788  {
789  std::map<LINECODE_ID, LINECODE> LineCodes;
790  std::map<HATCHCODE_ID, HATCHCODE> HatchCodes;
791  std::map<TEXTCODE_ID, TEXTCODE> TextCodes;
792  std::map<ROUTECODE_ID, ROUTECODE> RouteCodes;
793  std::map<ATTRIBUTE_ID, ATTRNAME> AttributeNames;
794  std::map<NETCLASS_ID, CADSTAR_NETCLASS> NetClasses;
795  std::map<SPACING_CLASS_ID, SPCCLASSNAME> SpacingClassNames;
796 
797  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
798  };
799 
810  enum class SWAP_RULE
811  {
812  NO_SWAP,
814  BOTH
815  };
816 
817 
818  static SWAP_RULE ParseSwapRule( XNODE* aNode );
819 
820 
822  {
824  wxString Name;
825  wxString FileName;
826  bool Mirror = false;
827  long OrientAngle = 0;
828 
829  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
830  };
831 
832 
837  {
838  REUSEBLOCK_ID ReuseBlockID = wxEmptyString;
839  wxString ItemReference = wxEmptyString;
840 
844  bool IsEmpty();
845  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
846  };
847 
848 
849  struct GROUP : PARSER
850  {
852  wxString Name;
853  bool Fixed = false;
854  bool Transfer = false;
855  GROUP_ID GroupID = wxEmptyString;
858 
859  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
860  };
861 
862 
863  struct FIGURE : PARSER
864  {
868  SHAPE Shape; //< Uses the component's coordinate frame if within a component
869  //< definition, otherwise uses the design's coordinate frame.
870  GROUP_ID GroupID = wxEmptyString;
873  bool Fixed = false;
874  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
875 
876  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
877  };
878 
879 
880  struct TEXT : PARSER
881  {
883  wxString Text; //TODO: Need to lex/parse to identify design fields and hyperlinks
887  long OrientAngle = 0;
888  bool Mirror = false;
889  bool Fixed = false;
895  GROUP_ID GroupID = wxEmptyString;
900 
901  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
902  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext, bool aParseFields );
903  };
904 
905 
906  struct SYMDEF : PARSER
907  {
909  wxString ReferenceName;
910  wxString Alternate;
912  POINT Origin;
914  bool Stub = false;
916  long Version = UNDEFINED_VALUE;
922 
924  std::map<FIGURE_ID, FIGURE> Figures;
925  std::map<TEXT_ID, TEXT> Texts;
926  std::map<ATTRIBUTE_ID, TEXT_LOCATION> TextLocations;
927  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
930 
932  void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
933  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
934  };
935 
936 
937  struct PART : PARSER
938  {
939  enum class PIN_TYPE
940  {
941  UNCOMMITTED,
942  INPUT,
943  OUTPUT_OR,
944  OUTPUT_NOT_OR,
946  POWER,
947  GROUND,
951  };
952 
953 
954  static PIN_TYPE GetPinType( XNODE* aNode );
955 
956 
957  struct DEFINITION : PARSER
958  {
959  struct GATE : PARSER
960  {
962  wxString Name;
963  wxString Alternate;
964  long PinCount;
965 
966  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
967  };
968 
969 
970  struct PIN : PARSER
971  {
975  enum class POSITION
976  {
977  TOP_RIGHT = 0,
978  TOP_LEFT = 1,
979  BOTTOM_LEFT = 2,
980  BOTTOM_RIGHT = 3
981  };
982 
984 
985  wxString Identifier = wxEmptyString;
986  wxString Name = wxEmptyString;
991  wxString Label = wxEmptyString;
996  wxString Signal = wxEmptyString;
1016  POSITION Position =
1021 
1024  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1025  };
1026 
1027 
1029  {
1030  std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1031 
1034  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1035  };
1036 
1037 
1038  struct SWAP_GATE : PARSER
1039  {
1040  std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1041 
1043  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1044  };
1045 
1046 
1048  {
1049  wxString GateName =
1050  wxEmptyString;
1051 
1054  bool External = false;
1055 
1062  std::vector<SWAP_GATE> SwapGates;
1063 
1068  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1069  };
1070 
1071  wxString Name;
1073  false;
1074 
1079  UNDEFINED_VALUE;
1080 
1086  std::map<GATE_ID, GATE> GateSymbols;
1087  std::map<PART_DEFINITION_PIN_ID, PIN> Pins;
1088  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1089  std::vector<PIN_EQUIVALENCE> PinEquivalences;
1093  std::vector<SWAP_GROUP> SwapGroups;
1094 
1095  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1096  };
1097 
1098 
1099  struct PART_PIN : PARSER
1100  {
1102  wxString Name = wxEmptyString;
1104  wxString Identifier = wxEmptyString;
1105 
1106  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1107  };
1108 
1109 
1111  wxString Name;
1112  long Version;
1114  std::map<PART_PIN_ID, PART_PIN> PartPins;
1115 
1120  bool HidePinNames = false;
1121 
1123  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1124 
1128  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1129  };
1130 
1131 
1132  struct PARTS : PARSER
1133  {
1134  std::map<PART_ID, PART> PartDefinitions;
1135 
1136  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1137  };
1138 
1139 
1140  struct NET : PARSER
1141  {
1142  struct JUNCTION : PARSER
1143  {
1147  GROUP_ID GroupID = wxEmptyString;
1150  bool Fixed = false;
1151 
1152  void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1153  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1154  virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1155  };
1156 
1157 
1158  struct CONNECTION : PARSER
1159  {
1163 
1164  bool Fixed = false;
1165  bool Hidden = false;
1166  GROUP_ID GroupID = wxEmptyString;
1168 
1169  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1170  void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1173  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1174 
1175  virtual ~CONNECTION() {}
1176  };
1177 
1179  ROUTECODE_ID RouteCodeID = wxEmptyString;
1181  wxString Name = wxEmptyString;
1183  bool Highlight = false;
1185 
1186  std::map<NETELEMENT_ID, JUNCTION> Junctions;
1187  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1188 
1190  wxEmptyString;
1193  wxEmptyString;
1194 
1196  void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1197  bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1198  };
1199 
1200 
1202  {
1204 
1206  LAYER_ID LayerID;
1211 
1213  GROUP_ID GroupID = wxEmptyString;
1215  long OrientAngle = 0;
1216  bool Mirror = false;
1217  bool Fixed = false;
1219 
1221  long ScaleRatioDenominator = 1;
1223 
1225  std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1226 
1227  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1228  };
1229 
1230 
1232  {
1234  bool IsVisible = true;
1235 
1236  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1237  };
1238 
1239 
1240  struct ATTRCOL : PARSER
1241  {
1244  bool IsVisible = true;
1245  bool IsPickable = true;
1246 
1247  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1248  };
1249 
1250 
1252  {
1254  std::map<ATTRIBUTE_ID, ATTRCOL> AttributeColors;
1255 
1256  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1257  };
1258 
1259 
1261  {
1263  bool IsVisible = true;
1264  bool IsPickable = true;
1265 
1266  void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1267  };
1268 
1270  // HELPER FUNCTIONS: //
1272 
1273 
1274  static void InsertAttributeAtEnd( XNODE* aNode, wxString aValue );
1275 
1287  static XNODE* LoadArchiveFile( const wxString& aFileName, const wxString& aFileTypeIdentifier,
1288  PROGRESS_REPORTER* aProgressReporter = nullptr );
1289 
1295  static bool IsValidAttribute( wxXmlAttribute* aAttribute );
1296 
1305  static wxString GetXmlAttributeIDString(
1306  XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1307 
1316  static long GetXmlAttributeIDLong( XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1317 
1323  static void CheckNoChildNodes( XNODE* aNode );
1324 
1330  static void CheckNoNextNodes( XNODE* aNode );
1331 
1338  static void ParseChildEValue( XNODE* aNode, PARSER_CONTEXT* aContext, EVALUE& aValueToParse );
1339 
1352  static std::vector<POINT> ParseAllChildPoints( XNODE* aNode, PARSER_CONTEXT* aContext,
1353  bool aTestAllChildNodes = false, int aExpectedNumPoints = UNDEFINED_VALUE );
1354 
1366  static std::vector<VERTEX> ParseAllChildVertices(
1367  XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
1368 
1380  static std::vector<CUTOUT> ParseAllChildCutouts(
1381  XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
1382 
1383  static long GetNumberOfChildNodes( XNODE* aNode );
1384 
1385  static long GetNumberOfStepsForReporting( XNODE* aRootNode,
1386  std::vector<wxString> aSubNodeChildrenToCount );
1387 
1393  static wxString HandleTextOverbar( wxString aCadstarString );
1394 
1400  static void FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem );
1401 
1402  static wxString generateLibName( const wxString& aRefName, const wxString& aAlternateName )
1403  {
1404  return aRefName
1405  + ( ( aAlternateName.size() > 0 ) ? ( wxT( " (" ) + aAlternateName + wxT( ")" ) )
1406  : wxString() );
1407  }
1408 
1409 
1410 protected:
1411  void checkPoint();
1412 
1414  PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
1415 
1416 
1417 }; // class CADSTAR_ARCHIVE_PARSER
1418 
1419 #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
static long GetNumberOfChildNodes(XNODE *aNode)
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
static XNODE * LoadArchiveFile(const wxString &aFileName, const wxString &aFileTypeIdentifier, PROGRESS_REPORTER *aProgressReporter=nullptr)
Reads a CADSTAR Archive file (S-parameter format)
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.
A progress reporter interface for use in multi-threaded environments.
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:140
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
std::function< void()> CheckPointCallback
Callback function to report progress.
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
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)
static wxString ParseTextFields(const wxString &aTextString, PARSER_CONTEXT *aParserContext)
Replaces CADSTAR fields for the equivalent in KiCad and stores the field values in aParserContext.
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.
void checkPoint()
Updates m_progressReporter or throws if user cancelled.
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
PROGRESS_REPORTER * m_progressReporter
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
static wxString HandleTextOverbar(wxString aCadstarString)
Convert a string with CADSTAR overbar characters to equivalent in KiCad.
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
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 long GetNumberOfStepsForReporting(XNODE *aRootNode, std::vector< wxString > aSubNodeChildrenToCount)
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.