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#include <math/vector2d.h>
38
39// THROW_IO_ERROR definitions to ensure consistent wording is used in the error messages
40
41#define THROW_MISSING_NODE_IO_ERROR( nodename, location ) \
42 THROW_IO_ERROR( wxString::Format( _( "Missing node '%s' in '%s'" ), nodename, location ) )
43
44#define THROW_UNKNOWN_NODE_IO_ERROR( nodename, location ) \
45 THROW_IO_ERROR( wxString::Format( _( "Unknown node '%s' in '%s'" ), nodename, location ) )
46
47#define THROW_MISSING_PARAMETER_IO_ERROR( param, location ) \
48 THROW_IO_ERROR( wxString::Format( _( "Missing Parameter '%s' in '%s'" ), param, location ) )
49
50#define THROW_UNKNOWN_PARAMETER_IO_ERROR( param, location ) \
51 THROW_IO_ERROR( wxString::Format( _( "Unknown Parameter '%s' in '%s'" ), param, location ) )
52
53#define THROW_PARSING_IO_ERROR( param, location ) \
54 THROW_IO_ERROR( wxString::Format( _( "Unable to parse '%s' in '%s'" ), param, location ) )
55
56//=================================
57// MACRO DEFINITIONS
58//=================================
59#define UNDEFINED_LAYER_ID ( LAYER_ID ) wxEmptyString
60
61
65#define COMPONENT_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME__" )
66
71#define COMPONENT_NAME_2_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME_2__" )
72
76#define SYMBOL_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__SYMBOL_NAME__" )
77#define LINK_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__LINK_ORIGIN__" )
78#define SIGNALNAME_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__SIGNALNAME_ORIGIN__" )
79#define PART_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__PART_NAME__" )
80
81class EDA_TEXT;
82class wxXmlAttribute;
85class SHAPE_POLY_SET;
86class SHAPE_ARC;
87
92{
93public:
95
97
98
99 typedef wxString LINECODE_ID;
100 typedef wxString HATCHCODE_ID;
101 typedef wxString ROUTECODE_ID;
102 typedef wxString NETCLASS_ID;
103 typedef wxString SPACING_CLASS_ID;
104 typedef wxString TEXTCODE_ID;
105 typedef wxString LAYER_ID;
106 typedef wxString VARIANT_ID;
107 typedef wxString ATTRIBUTE_ID;
108 typedef wxString SYMDEF_ID;
109 typedef wxString PART_ID;
110 typedef wxString GATE_ID;
111 typedef long TERMINAL_ID;
113 typedef long PART_PIN_ID;
114 typedef wxString TEXT_ID;
115 typedef wxString FIGURE_ID;
116 typedef wxString GROUP_ID;
117 typedef wxString REUSEBLOCK_ID;
118 typedef wxString NET_ID;
119 typedef wxString NETELEMENT_ID;
120 typedef wxString DOCUMENTATION_SYMBOL_ID;
121 typedef wxString COLOR_ID;
122
123 static const long UNDEFINED_VALUE = -1;
124
136 static const double TXT_HEIGHT_RATIO;
137
143 {
144 DESIGN_TITLE,
145 SHORT_JOBNAME,
146 LONG_JOBNAME,
147 NUM_OF_SHEETS,
148 SHEET_NUMBER,
150 VARIANT_NAME,
151 VARIANT_DESCRIPTION,
152 REG_USER,
153 COMPANY_NAME,
154 CURRENT_USER,
155 DATE,
156 TIME,
157 MACHINE_NAME,
158 FROM_FILE,
159 DISTANCE,
160 UNITS_SHORT,
161 UNITS_ABBREV,
162 UNITS_FULL,
163 HYPERLINK,
164 NONE
165 };
166
171 static const std::map<TEXT_FIELD_NAME, wxString> CADSTAR_TO_KICAD_FIELDS;
172
173
175 {
181 std::map<wxString, wxString> FilenamesToTextMap;
182
187 std::map<wxString, wxString> TextToHyperlinksMap;
188
193 std::map<TEXT_FIELD_NAME, wxString> TextFieldToValuesMap;
194
199 std::set<TEXT_FIELD_NAME> InconsistentTextFields;
200
204 std::function<void()> CheckPointCallback = []() {};
205 };
206
214 static wxString ParseTextFields( const wxString& aTextString, PARSER_CONTEXT* aParserContext );
215
216
217 struct PARSER
218 {
219 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) = 0;
220
221 virtual ~PARSER() {};
222 };
223
224
225 struct FORMAT : PARSER
226 {
227 wxString Type;
228 long SomeInt;
229 long Version;
232 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
233 };
234
235
237 {
238 long Year;
239 long Month;
240 long Day;
241 long Hour;
242 long Minute;
243 long Second;
244
245 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
246 };
247
248 //Note: there are possibly several other resolutions, but HUNDREDTH MICRON is only one known
249 enum class RESOLUTION
250 {
251 HUNDREDTH_MICRON
252 };
253
254
255 struct HEADER : PARSER
256 {
258 wxString JobFile;
259 wxString JobTitle;
260 wxString Generator;
263
264 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
265 };
266
267
268 struct VARIANT : PARSER
269 {
270 VARIANT_ID ID = wxEmptyString;
271 VARIANT_ID ParentID = wxEmptyString;
272 wxString Name = wxEmptyString;
273 wxString Description = wxEmptyString;
274
275 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
276 };
277
278
280 {
281 std::map<VARIANT_ID, VARIANT> Variants;
282
283 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
284 };
285
286
287 enum class LINESTYLE
288 {
289 SOLID,
290 DASH,
291 DASHDOT,
293 DOT
294 };
295
296
298 {
300 wxString Name;
301 long Width;
303
304 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
305 };
306
307
308 struct HATCH : PARSER
309 {
310 long Step;
313
314 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
315 };
316
317
319 {
321 wxString Name;
322 std::vector<HATCH> Hatches;
323
324 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
325 };
326
327
328 static const long FONT_NORMAL = 400;
329 static const long FONT_BOLD = 700;
330
331
332 struct FONT : PARSER
333 {
334 wxString Name = wxT( "CADSTAR" );
336 long Modifier2 = 0;
338 false;
341 bool Italic = false;
342
343 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
344 };
345
346
348 {
350 wxString Name;
352 long Height;
353 long Width;
357
358 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
359 };
360
361
363 {
369
370 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
371 };
372
373
375 {
377 wxString Name;
382
383 std::vector<ROUTEREASSIGN> RouteReassigns;
384
385 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
386 };
387
388
392 struct EVALUE : PARSER
393 {
394 long Base = 0;
395 long Exponent = 0;
396
397 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
398 double GetDouble();
399 };
400
405 {
407 POINT( int aX, int aY ) : VECTOR2I( aX, aY ) {}
408
409 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
410 };
411
412
414 {
417
418 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
419 };
420
421
423 {
424 virtual wxPoint Apply( POINT aCadstarPoint ) = 0;
425 };
426
427
428 enum class VERTEX_TYPE
429 {
430 POINT,
431 CLOCKWISE_ARC,
432 CLOCKWISE_SEMICIRCLE,
433 ANTICLOCKWISE_ARC,
434 ANTICLOCKWISE_SEMICIRCLE
435 };
436
441 struct VERTEX : PARSER
442 {
443 VERTEX( VERTEX_TYPE aType = VERTEX_TYPE::POINT, POINT aEnd = POINT(), POINT aCenter = POINT() ) :
444 Type( aType ), End( aEnd ), Center( aCenter )
445 {}
446
450
451 static bool IsVertex( XNODE* aNode );
452 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
453
454 void AppendToChain( SHAPE_LINE_CHAIN* aChainToAppendTo,
455 const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
456 double aAccuracy ) const;
457
458 SHAPE_ARC BuildArc( const VECTOR2I& aPrevPoint,
459 const std::function<VECTOR2I( const VECTOR2I& )>
460 aCadstarToKicadPointCallback ) const;
461 };
462
466 struct CUTOUT : PARSER
467 {
468 std::vector<VERTEX> Vertices;
469
470 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
471 };
472
473
474 enum class SHAPE_TYPE
475 {
476 OPENSHAPE,
477 OUTLINE,
478 SOLID,
479 HATCHED
480 };
481
482
483 struct SHAPE : PARSER
484 {
486 std::vector<VERTEX> Vertices;
487 std::vector<CUTOUT> Cutouts;
488 wxString HatchCodeID;
489
490 static bool IsShape( XNODE* aNode );
491 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
492
493 SHAPE_LINE_CHAIN OutlineAsChain( const std::function<VECTOR2I( const VECTOR2I& )>
494 aCadstarToKicadPointCallback,
495 double aAccuracy ) const;
496
497 SHAPE_POLY_SET ConvertToPolySet( const std::function<VECTOR2I( const VECTOR2I& )>
498 aCadstarToKicadPointCallback,
499 double aAccuracy ) const;
500 };
501
502
503 enum class UNITS
504 {
505 DESIGN,
506 THOU,
507 INCH,
508 MICROMETRE,
509 MM,
511 METER
512 };
513
514
515 static UNITS ParseUnits( XNODE* aNode );
516
517
518 enum class ANGUNITS
519 {
520 DEGREES,
521 RADIANS
522 };
523
524
525 static ANGUNITS ParseAngunits( XNODE* aNode );
526
527
528 enum class GRID_TYPE
529 {
530 FRACTIONALGRID,
532 STEPGRID
533 };
534
535
536 struct GRID : PARSER
537 {
539 wxString Name;
540 long Param1;
542 long Param2;
544
545 static bool IsGrid( XNODE* aNode );
546 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
547 };
548
549
550 struct GRIDS : PARSER
551 {
561 std::vector<GRID> UserGrids;
562
563 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
564 };
565
566
568 {
577 bool AllowBarredText = false;
579
581 std::pair<POINT, POINT> DesignArea;
584
585 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
586 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
587 };
588
589
590
608 enum class ALIGNMENT
609 {
610 NO_ALIGNMENT,
611 TOPLEFT,
612 TOPCENTER,
613 TOPRIGHT,
614 CENTERLEFT,
615 CENTERCENTER,
616 CENTERRIGHT,
617 BOTTOMLEFT,
618 BOTTOMCENTER,
619 BOTTOMRIGHT
620 };
621
622
623 static ALIGNMENT ParseAlignment( XNODE* aNode );
624
634 enum class JUSTIFICATION
635 {
636 LEFT,
637 CENTER,
638 RIGHT
639 };
640
641
642 static JUSTIFICATION ParseJustification( XNODE* aNode );
643
652 enum class READABILITY
653 {
654 BOTTOM_TO_TOP,
655 TOP_TO_BOTTOM
656 };
657
658
659 static READABILITY ParseReadability( XNODE* aNode );
660
661
662 enum class ATTROWNER
663 {
664 ALL_ITEMS,
665 AREA,
666 BOARD,
667 COMPONENT,
668 CONNECTION,
669 COPPER,
670 DOCSYMBOL,
671 FIGURE,
672 NET,
673 NETCLASS,
674 PART,
675 PART_DEFINITION,
676 PIN,
677 SIGNALREF,
678 SYMBOL,
679 SYMDEF,
680 TEMPLATE,
682 };
683
684
685 enum class ATTRUSAGE
686 {
687 BOTH,
689 COMPONENT,
690 PART_DEFINITION,
692 PART_LIBRARY,
693 SYMBOL,
695 UNDEFINED
698 };
699
700
702 {
706 long OrientAngle = 0;
707 bool Mirror = false;
708 bool Fixed = false;
716
717 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
718 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
719 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
720 };
721
722
728 {
730 {
731 long ID;
732 long Order;
733
734 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
735 };
736
737
739 {
740 long ID;
741 long Width;
742
743 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
744 };
745
747 wxString Name;
753 bool NoTransfer = false;
760 std::vector<COLUMNORDER> ColumnOrders;
761 std::vector<COLUMNWIDTH> ColumnWidths;
762 bool ColumnInvisible = false;
763
764 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
765 };
766
767
769 {
771 wxString Value;
772 bool ReadOnly = false;
773 bool HasLocation = false;
776
777 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
778 };
779
780
787 {
789 {
790 // The default alignment for TEXT_LOCATION (when "NO_ALIGNMENT" is selected) is
791 // Bottom left, matching CADSTAR's default behaviour
793 }
795
796 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
797 };
798
799
801 {
803 wxString Name;
804 std::vector<ATTRIBUTE_VALUE> Attributes;
805
806 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
807 };
808
809
811 {
813 wxString Name;
814
815 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
816 };
817
818
820 {
821 std::map<LINECODE_ID, LINECODE> LineCodes;
822 std::map<HATCHCODE_ID, HATCHCODE> HatchCodes;
823 std::map<TEXTCODE_ID, TEXTCODE> TextCodes;
824 std::map<ROUTECODE_ID, ROUTECODE> RouteCodes;
825 std::map<ATTRIBUTE_ID, ATTRNAME> AttributeNames;
826 std::map<NETCLASS_ID, CADSTAR_NETCLASS> NetClasses;
827 std::map<SPACING_CLASS_ID, SPCCLASSNAME> SpacingClassNames;
828
829 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
830 };
831
842 enum class SWAP_RULE
843 {
844 NO_SWAP,
845 USE_SWAP_LAYER,
846 BOTH
847 };
848
849
850 static SWAP_RULE ParseSwapRule( XNODE* aNode );
851
852
854 {
856 wxString Name;
857 wxString FileName;
858 bool Mirror = false;
859 long OrientAngle = 0;
860
861 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
862 };
863
864
869 {
871 wxString ItemReference = wxEmptyString;
875
876 bool IsEmpty();
877 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
878 };
879
880
881 struct GROUP : PARSER
882 {
884 wxString Name;
885 bool Fixed = false;
886 bool Transfer = false;
887 GROUP_ID GroupID = wxEmptyString;
890
891 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
892 };
893
894
895 struct FIGURE : PARSER
896 {
900 SHAPE Shape; //< Uses the component's coordinate frame if within a component
901 //< definition, otherwise uses the design's coordinate frame.
902 GROUP_ID GroupID = wxEmptyString;
905 bool Fixed = false;
906 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
907
908 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
909 };
910
911
912 struct TEXT : PARSER
913 {
915 wxString Text; //TODO: Need to lex/parse to identify design fields and hyperlinks
919 long OrientAngle = 0;
920 bool Mirror = false;
921 bool Fixed = false;
930 GROUP_ID GroupID = wxEmptyString;
932
933 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
934 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext, bool aParseFields );
935 };
936
937
938 struct SYMDEF : PARSER
939 {
941 wxString ReferenceName;
943 wxString Alternate;
947 bool Stub = false;
955
956 std::map<FIGURE_ID, FIGURE> Figures;
957 std::map<TEXT_ID, TEXT> Texts;
958 std::map<ATTRIBUTE_ID, TEXT_LOCATION> TextLocations;
961 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
963
964 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
965 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
966 };
967
968
969 struct PART : PARSER
970 {
971 enum class PIN_TYPE
972 {
973 UNCOMMITTED,
974 INPUT,
975 OUTPUT_OR,
976 OUTPUT_NOT_OR,
977 OUTPUT_NOT_NORM_OR,
978 POWER,
979 GROUND,
980 TRISTATE_BIDIR,
981 TRISTATE_INPUT,
982 TRISTATE_DRIVER
983 };
984
985
986 static PIN_TYPE GetPinType( XNODE* aNode );
987
988
990 {
991 struct GATE : PARSER
992 {
994 wxString Name;
995 wxString Alternate;
996 long PinCount;
997
998 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
999 };
1000
1001
1002 struct PIN : PARSER
1003 {
1007 enum class POSITION
1008 {
1009 TOP_RIGHT = 0,
1010 TOP_LEFT = 1,
1011 BOTTOM_LEFT = 2,
1012 BOTTOM_RIGHT = 3
1013 };
1014
1016
1017 wxString Identifier = wxEmptyString;
1022 wxString Name = wxEmptyString;
1027 wxString Label = wxEmptyString;
1042 wxString Signal = wxEmptyString;
1055
1056 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1057 };
1058
1059
1061 {
1062 std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1065
1066 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1067 };
1068
1069
1071 {
1072 std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1074
1075 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1076 };
1077
1078
1080 {
1081 wxString GateName =
1082 wxEmptyString;
1085
1086 bool External = false;
1093
1094 std::vector<SWAP_GATE> SwapGates;
1099
1100 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1101 };
1102
1103 wxString Name;
1105 false;
1109
1117
1118 std::map<GATE_ID, GATE> GateSymbols;
1119 std::map<PART_DEFINITION_PIN_ID, PIN> Pins;
1120 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1124 std::vector<PIN_EQUIVALENCE> PinEquivalences;
1125 std::vector<SWAP_GROUP> SwapGroups;
1126
1127 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1128 };
1129
1130
1132 {
1134 wxString Name = wxEmptyString;
1136 wxString Identifier = wxEmptyString;
1137
1138 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1139 };
1140
1141
1143 wxString Name;
1146 std::map<PART_PIN_ID, PART_PIN> PartPins;
1151
1152 bool HidePinNames = false;
1154
1155 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1159
1160 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1161 };
1162
1163
1164 struct PARTS : PARSER
1165 {
1166 std::map<PART_ID, PART> PartDefinitions;
1167
1168 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1169 };
1170
1171
1172 struct NET : PARSER
1173 {
1175 {
1179 GROUP_ID GroupID = wxEmptyString;
1182 bool Fixed = false;
1183
1184 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1185 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1186 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1187 };
1188
1189
1191 {
1195
1196 bool Fixed = false;
1197 bool Hidden = false;
1198 GROUP_ID GroupID = wxEmptyString;
1200
1201 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1204 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1205 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1206
1207 virtual ~CONNECTION() {}
1208 };
1209
1211 ROUTECODE_ID RouteCodeID = wxEmptyString;
1214 wxString Name = wxEmptyString;
1216 bool Highlight = false;
1217
1218 std::map<NETELEMENT_ID, JUNCTION> Junctions;
1219 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1220
1222 wxEmptyString;
1225 wxEmptyString;
1227
1228 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1229 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1230 };
1231
1232
1234 {
1236
1244
1245 GROUP_ID GroupID = wxEmptyString;
1247 long OrientAngle = 0;
1248 bool Mirror = false;
1249 bool Fixed = false;
1251
1256
1257 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1258
1259 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1260 };
1261
1262
1264 {
1266 bool IsVisible = true;
1267
1268 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1269 };
1270
1271
1273 {
1276 bool IsVisible = true;
1277 bool IsPickable = true;
1278
1279 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1280 };
1281
1282
1284 {
1286 std::map<ATTRIBUTE_ID, ATTRCOL> AttributeColors;
1287
1288 bool IsVisible = true; // unclear what this represents - maybe all attributes are hidden?
1289
1290 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1291 };
1292
1293
1295 {
1297 bool IsVisible = true;
1298 bool IsPickable = true;
1299
1300 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1301 };
1302
1304 // HELPER FUNCTIONS: //
1306
1307
1308 static void InsertAttributeAtEnd( XNODE* aNode, wxString aValue );
1309
1321 static XNODE* LoadArchiveFile( const wxString& aFileName, const wxString& aFileTypeIdentifier,
1322 PROGRESS_REPORTER* aProgressReporter = nullptr );
1323
1329 static bool IsValidAttribute( wxXmlAttribute* aAttribute );
1330
1339 static wxString GetXmlAttributeIDString(
1340 XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1341
1350 static long GetXmlAttributeIDLong( XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1351
1357 static void CheckNoChildNodes( XNODE* aNode );
1358
1364 static void CheckNoNextNodes( XNODE* aNode );
1365
1372 static void ParseChildEValue( XNODE* aNode, PARSER_CONTEXT* aContext, EVALUE& aValueToParse );
1373
1386 static std::vector<POINT> ParseAllChildPoints( XNODE* aNode, PARSER_CONTEXT* aContext,
1387 bool aTestAllChildNodes = false, int aExpectedNumPoints = UNDEFINED_VALUE );
1388
1400 static std::vector<VERTEX> ParseAllChildVertices(
1401 XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
1402
1414 static std::vector<CUTOUT> ParseAllChildCutouts(
1415 XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
1416
1417 static long GetNumberOfChildNodes( XNODE* aNode );
1418
1419 static long GetNumberOfStepsForReporting( XNODE* aRootNode,
1420 std::vector<wxString> aSubNodeChildrenToCount );
1421
1427 static wxString HandleTextOverbar( wxString aCadstarString );
1428
1434 static void FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem );
1435
1436 static wxString generateLibName( const wxString& aRefName, const wxString& aAlternateName )
1437 {
1438 return aRefName
1439 + ( ( aAlternateName.size() > 0 ) ? ( wxT( " (" ) + aAlternateName + wxT( ")" ) )
1440 : wxString( wxT( "" ) ) );
1441 }
1442
1443
1444protected:
1445 void checkPoint();
1446
1448 PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
1449
1450
1451}; // class CADSTAR_ARCHIVE_PARSER
1452
1453#endif // CADSTAR_ARCHIVE_PARSER_H_
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:269
Helper functions and common structures for CADSTAR PCB and Schematic archive files.
READABILITY
Sets the readability direction of text.
@ BOTTOM_TO_TOP
When text is vertical, show it rotated 90 degrees anticlockwise.
static wxString generateLibName(const wxString &aRefName, const wxString &aAlternateName)
SWAP_RULE
Corresponds to "Display when" Item property.
@ BOTH
Always display (Mirrored and Unmirrored)
static UNITS ParseUnits(XNODE *aNode)
static ALIGNMENT ParseAlignment(XNODE *aNode)
static const std::map< TEXT_FIELD_NAME, wxString > CADSTAR_TO_KICAD_FIELDS
Map between CADSTAR fields and KiCad text variables.
long TERMINAL_ID
Terminal is the pin identifier in the schematic.
TEXT_FIELD_NAME
These are special fields in text objects enclosed between the tokens '<@' and '>' such as <@[FIELD_NA...
static SWAP_RULE ParseSwapRule(XNODE *aNode)
ALIGNMENT
From CADSTAR Help: "Text Alignment enables you to define the position of an alignment origin for all ...
@ NO_ALIGNMENT
NO_ALIGNMENT has different meaning depending on the object type.
static const long UNDEFINED_VALUE
static void CheckNoNextNodes(XNODE *aNode)
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)
static XNODE * LoadArchiveFile(const wxString &aFileName, const wxString &aFileTypeIdentifier, PROGRESS_REPORTER *aProgressReporter=nullptr)
Reads a CADSTAR Archive file (S-parameter format)
static JUSTIFICATION ParseJustification(XNODE *aNode)
static wxString ParseTextFields(const wxString &aTextString, PARSER_CONTEXT *aParserContext)
Replaces CADSTAR fields for the equivalent in KiCad and stores the field values in aParserContext.
@ UNDEFINED
Note: It seems that some attribute have no "ATTRUSAGE" defined.
wxString LAYER_ID
ID of a Sheet (if schematic) or board Layer (if PCB)
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)
static void FixTextPositionNoAlignment(EDA_TEXT *aKiCadTextItem)
Corrects the position of a text element that had NO_ALIGNMENT in CADSTAR.
static ANGUNITS ParseAngunits(XNODE *aNode)
long PART_DEFINITION_PIN_ID
Pin identifier in the part definition.
static const double TXT_HEIGHT_RATIO
CADSTAR fonts are drawn on a 24x24 integer matrix, where the each axis goes from 0 to 24.
static wxString GetXmlAttributeIDString(XNODE *aNode, unsigned int aID, bool aIsRequired=true)
void checkPoint()
Updates m_progressReporter or throws if user cancelled.
static bool IsValidAttribute(wxXmlAttribute *aAttribute)
static READABILITY ParseReadability(XNODE *aNode)
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)
static wxString HandleTextOverbar(wxString aCadstarString)
Convert a string with CADSTAR overbar characters to equivalent in KiCad.
static void CheckNoChildNodes(XNODE *aNode)
static long GetXmlAttributeIDLong(XNODE *aNode, unsigned int aID, bool aIsRequired=true)
JUSTIFICATION
From CADSTAR Help: "Multi Line Text can also be justified as Left, Centre or Right.
static void ParseChildEValue(XNODE *aNode, PARSER_CONTEXT *aContext, EVALUE &aValueToParse)
static long GetNumberOfStepsForReporting(XNODE *aRootNode, std::vector< wxString > aSubNodeChildrenToCount)
long PART_PIN_ID
Pin identifier in the part.
PROGRESS_REPORTER * m_progressReporter
static long GetNumberOfChildNodes(XNODE *aNode)
static void InsertAttributeAtEnd(XNODE *aNode, wxString aValue)
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:85
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:72
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:47
A progress reporter interface for use in multi-threaded environments.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
Hold an XML or S-expression element.
Definition: xnode.h:44
@ NONE
Definition: kibis.h:53
@ TESTPOINT
a test point pad
@ INCH
Definition: rs274x.cpp:64
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< ATTRIBUTE_ID, ATTRCOL > AttributeColors
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
JUSTIFICATION Justification
Note: Justification has no effect on single lines of text.
ALIGNMENT Alignment
In CADSTAR The default alignment for a TEXT object (when "(No Alignment()" is selected) Bottom Left o...
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool HasLocation
Flag to know if this ATTRIBUTE_VALUE has a location i.e.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
NOTE from CADSTAR help: To convert a Part Definition Attribute into a hyperlink, prefix the attribute...
std::vector< COLUMNWIDTH > ColumnWidths
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool NoTransfer
True="All Design Types", False="Current Design Type" "All Design Types" Description from CADSTAR Help...
std::vector< COLUMNORDER > ColumnOrders
wxString Name
Parenthesis aren't permitted in user attributes in CADSTAR.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< SPACING_CLASS_ID, SPCCLASSNAME > SpacingClassNames
std::map< LINECODE_ID, LINECODE > LineCodes
std::map< NETCLASS_ID, CADSTAR_NETCLASS > NetClasses
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
std::map< HATCHCODE_ID, HATCHCODE > HatchCodes
std::map< ATTRIBUTE_ID, ATTRNAME > AttributeNames
std::map< ROUTECODE_ID, ROUTECODE > RouteCodes
std::map< TEXTCODE_ID, TEXTCODE > TextCodes
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
long ScaleRatioNumerator
Documentation symbols can be arbitrarily scaled when added to a design.
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
long ScaleRatioDenominator
Documentation symbols can be arbitrarily scaled when added to a design.
POINT Origin
Origin of the component (this is used as the reference point when placing the component in the design...
GROUP_ID GroupID
If not empty, this component is part of a group.
LAYER_ID LayerID
Move all objects in the Symdef to this layer.
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...
Represents a floating value in E notation.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
GROUP_ID GroupID
If not empty, this FIGURE is part of a group.
SWAP_RULE SwapRule
Only applicable to Figures in Components.
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
long Modifier2
It seems this is always 0 regardless of settings.
bool KerningPairs
From CADSTAR Help: "Kerning Pairs is for causing the system to automatically red...
long Modifier1
It seems this is related to weight. 400=Normal, 700=Bold.
long Version
Archive version number (e.g.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
long SomeInt
It is unclear what this parameter is used for.
GRID ScreenGrid
From CADSTAR Help: "There is one Screen Grid, which is visible as dots on the screen.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::vector< GRID > UserGrids
List of predefined grids created by the user.
static bool IsGrid(XNODE *aNode)
long Param1
Either Units or X step, depending on Type (see GRID_TYPE for more details)
long Param2
Either Divisor or Y step, depending on Type (see GRID_TYPE for more details)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
GROUP_ID GroupID
If not empty, this GROUP is part of another GROUP.
bool Transfer
If true, the group is transferred to PCB.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
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.
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
GROUP_ID GroupID
If not empty, this connection is part of a group.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
GROUP_ID GroupID
If not empty, this JUCTION is part of a group.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
NETELEMENT_ID ID
First character is "J".
ROUTECODE_ID RouteCodeID
"NETCODE" subnode
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
wxString Name
This is undefined (wxEmptyString) if the net is unnamed.
std::map< NETELEMENT_ID, JUNCTION > Junctions
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
NETCLASS_ID NetClassID
The net might not have a net class, in which case it will be wxEmptyString ("NETCLASSREF" subnode)
SPACING_CLASS_ID SpacingClassID
The net might not have a spacing class, in which case it will be wxEmptyString ("SPACINGCLASS" subnod...
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
long SignalNum
This is undefined if the net has been given a name.
std::map< TEXT_FIELD_NAME, wxString > TextFieldToValuesMap
Values for the text field elements used in the CADSTAR design extracted from the text element instanc...
std::map< wxString, wxString > FilenamesToTextMap
CADSTAR doesn't have user defined text fields but does allow loading text from a file.
std::map< wxString, wxString > TextToHyperlinksMap
KiCad doesn't support hyperlinks but we use this map to display warning messages after import.
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...
std::function< void()> CheckPointCallback
Callback function to report progress.
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext)=0
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< PART_ID, PART > PartDefinitions
long PinCount
Number of pins (terminals) in the symbol.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString Alternate
Symbol alternate name in the symbol library.
wxString Name
Symbol name in the symbol library.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::vector< PART_DEFINITION_PIN_ID > PinIDs
All the pins in this vector are equivalent and can be swapped with each other.
wxString Label
This Can be empty (subnode= "PINLABEL") From CADSTAR Help: "Pin Labels are an optional replacement fo...
long Load
The electrical current expected on the pin (It is unclear what the units are, but only accepted value...
POSITION
Positioning of pin names can be in one of four quadrants.
TERMINAL_ID TerminalPin
(subnode="PINTERM", param1)
wxString Identifier
This should match a pad identifier in the component footprint subnode="PINIDENTIFIER".
POSITION Position
The pin names will use these positions when the symbol is added to a schematic design subnode="PINPOS...
GATE_ID TerminalGate
(subnode="PINTERM", param0)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString Signal
Usually for Power/Ground pins, (subnode="PINSIGNAL")
< "SWAPGATE" Node name (represents an "Element")
std::vector< PART_DEFINITION_PIN_ID > PinIDs
The pins in this vector describe a "gate".
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.
bool External
Determines if this swap group is external (and internal) or internal only.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool HidePinNames
Specifies whether to display the pin names/identifier in the schematic symbol or not.
std::vector< PIN_EQUIVALENCE > PinEquivalences
wxString Name
This name can be different to the PART name.
long MaxPinCount
Optional parameter which is used for specifying the number of electrical pins on the PCB component sy...
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
Some attributes are defined within the part definition, whilst others are defined in the part.
std::map< PART_DEFINITION_PIN_ID, PIN > Pins
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< PART_PIN_ID, PART_PIN > PartPins
It is unclear why there are two "Pin" structures in CPA files... PART_PIN seems to be a reduced versi...
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
Some attributes are defined within the part definition, whilst others are defined in the part itself.
@ UNCOMMITTED
Uncommitted pin (default)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static PIN_TYPE GetPinType(XNODE *aNode)
bool HidePinNames
This seems to be a duplicate of DEFINITION::HidePinNames Possibly only used in older file formats?
Represents a point in x,y coordinates.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
References an element from a design reuse block.
wxString ItemReference
For Components, this references the designator in the reuse file.
bool IsEmpty()
Determines if this is empty (i.e. no design reuse associated)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString FileName
Filename of the reuse block (usually a .pcb). Used for reloading.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::vector< ROUTEREASSIGN > RouteReassigns
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
UNITS Units
Units to display for linear dimensions.
long InterlineGap
For CADSTAR font only, distance between lines of text, expressed as a percentage of the text height (...
long BarlineGap
For CADSTAR font only, distance between top bar and character, expressed as a percentage of the text ...
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool AllowBarredText
Specifies if barring is allowed in the design.
LONGPOINT DesignRef
Appears to be 0,0 always.
std::pair< POINT, POINT > DesignArea
long AngularPrecision
Number of decimal points to display for angular dimensions.
long UnitDisplPrecision
Number of decimal points to display for linear dimensions.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
SHAPE_POLY_SET ConvertToPolySet(const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, double aAccuracy) const
SHAPE_LINE_CHAIN OutlineAsChain(const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, double aAccuracy) const
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString HatchCodeID
Only Applicable for HATCHED Type.
std::vector< CUTOUT > Cutouts
Not Applicable to OPENSHAPE Type.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< FIGURE_ID, FIGURE > Figures
std::map< ATTRIBUTE_ID, TEXT_LOCATION > TextLocations
This contains location of any attributes, including designator position.
POINT Origin
Origin of the component (this is used as the reference point when placing the component in the design...
wxString Alternate
This is in addition to ReferenceName.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
bool Stub
When the CADSTAR Archive file is exported without the component library, if components on the board a...
wxString ReferenceName
This is the name which identifies the symbol in the library Multiple components may exist with the sa...
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
These attributes might also have a location.
long Version
Version is a sequential integer number to identify discrepancies between the library and the design.
long Width
Defaults to 0 if using system fonts or, if using CADSTAR font, default to equal height (1:1 aspect ra...
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
Corresponds to CADSTAR "origin".
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
ALIGNMENT Alignment
In CADSTAR The default alignment for a TEXT object (when "(No Alignment()" is selected) Bottom Left o...
JUSTIFICATION Justification
Note: Justification has no effect on single lines of text.
GROUP_ID GroupID
If not empty, this FIGURE is part of a group.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
virtual wxPoint Apply(POINT aCadstarPoint)=0
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
< Nodename = "VARIANT" or "VMASTER" (master variant
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
VARIANT_ID ParentID
if empty, then this one is the master
Represents a vertex in a shape.
VERTEX(VERTEX_TYPE aType=VERTEX_TYPE::POINT, POINT aEnd=POINT(), POINT aCenter=POINT())
SHAPE_ARC BuildArc(const VECTOR2I &aPrevPoint, const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback) const
void AppendToChain(SHAPE_LINE_CHAIN *aChainToAppendTo, const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, double aAccuracy) const
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590