KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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/string.h>
31#include <functional>
32#include <map>
33#include <set>
34#include <vector>
35#include <xnode.h>
36
37#include <math/vector2d.h>
39
40// THROW_IO_ERROR definitions to ensure consistent wording is used in the error messages
41
42#define THROW_MISSING_NODE_IO_ERROR( nodename, location ) \
43 THROW_IO_ERROR( wxString::Format( _( "Missing node '%s' in '%s'" ), nodename, location ) )
44
45#define THROW_UNKNOWN_NODE_IO_ERROR( nodename, location ) \
46 THROW_IO_ERROR( wxString::Format( _( "Unknown node '%s' in '%s'" ), nodename, location ) )
47
48#define THROW_MISSING_PARAMETER_IO_ERROR( param, location ) \
49 THROW_IO_ERROR( wxString::Format( _( "Missing Parameter '%s' in '%s'" ), param, location ) )
50
51#define THROW_UNKNOWN_PARAMETER_IO_ERROR( param, location ) \
52 THROW_IO_ERROR( wxString::Format( _( "Unknown Parameter '%s' in '%s'" ), param, location ) )
53
54#define THROW_PARSING_IO_ERROR( param, location ) \
55 THROW_IO_ERROR( wxString::Format( _( "Unable to parse '%s' in '%s'" ), param, location ) )
56
57//=================================
58// MACRO DEFINITIONS
59//=================================
60#define UNDEFINED_LAYER_ID ( LAYER_ID ) wxEmptyString
61
62
66#define COMPONENT_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME__" )
67
72#define COMPONENT_NAME_2_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME_2__" )
73
77#define SYMBOL_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__SYMBOL_NAME__" )
78#define LINK_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__LINK_ORIGIN__" )
79#define SIGNALNAME_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__SIGNALNAME_ORIGIN__" )
80#define PART_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__PART_NAME__" )
81
82class EDA_TEXT;
83class wxXmlAttribute;
86class SHAPE_POLY_SET;
87class SHAPE_ARC;
88
93{
94public:
96
98
99
100 typedef wxString LINECODE_ID;
101 typedef wxString HATCHCODE_ID;
102 typedef wxString ROUTECODE_ID;
103 typedef wxString NETCLASS_ID;
104 typedef wxString SPACING_CLASS_ID;
105 typedef wxString TEXTCODE_ID;
106 typedef wxString LAYER_ID;
107 typedef wxString VARIANT_ID;
108 typedef wxString ATTRIBUTE_ID;
109 typedef wxString SYMDEF_ID;
110 typedef wxString PART_ID;
111 typedef wxString GATE_ID;
112 typedef long TERMINAL_ID;
114 typedef long PART_PIN_ID;
115 typedef wxString TEXT_ID;
116 typedef wxString FIGURE_ID;
117 typedef wxString GROUP_ID;
118 typedef wxString REUSEBLOCK_ID;
119 typedef wxString NET_ID;
120 typedef wxString NETELEMENT_ID;
121 typedef wxString DOCUMENTATION_SYMBOL_ID;
122 typedef wxString COLOR_ID;
123
124 static const long UNDEFINED_VALUE = -1;
125
137 static const double TXT_HEIGHT_RATIO;
138
144 {
153 REG_USER,
156 DATE,
157 TIME,
159 FROM_FILE,
160 DISTANCE,
164 HYPERLINK,
165 NONE
166 };
167
172 static const std::map<TEXT_FIELD_NAME, wxString> CADSTAR_TO_KICAD_FIELDS;
173
174
176 {
182 std::map<wxString, wxString> FilenamesToTextMap;
183
188 std::map<wxString, wxString> TextToHyperlinksMap;
189
194 std::map<TEXT_FIELD_NAME, wxString> TextFieldToValuesMap;
195
200 std::set<TEXT_FIELD_NAME> InconsistentTextFields;
201
205 std::function<void()> CheckPointCallback = []() {};
206 };
207
216 static wxString ParseTextFields( const wxString& aTextString, PARSER_CONTEXT* aParserContext );
217
218
219 struct PARSER
220 {
221 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) = 0;
222
223 virtual ~PARSER() {};
224 };
225
226
227 struct FORMAT : PARSER
228 {
229 wxString Type;
230 long SomeInt;
231 long Version;
234 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
235 };
236
237
239 {
240 long Year;
241 long Month;
242 long Day;
243 long Hour;
244 long Minute;
245 long Second;
246
247 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
248 };
249
250 //Note: there are possibly several other resolutions, but HUNDREDTH MICRON is only one known
251 enum class RESOLUTION
252 {
254 };
255
256
257 struct HEADER : PARSER
258 {
260 wxString JobFile;
261 wxString JobTitle;
262 wxString Generator;
265
266 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
267 };
268
269
270 struct VARIANT : PARSER
271 {
272 VARIANT_ID ID = wxEmptyString;
273 VARIANT_ID ParentID = wxEmptyString;
274 wxString Name = wxEmptyString;
275 wxString Description = wxEmptyString;
276
277 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
278 };
279
280
282 {
283 std::map<VARIANT_ID, VARIANT> Variants;
284
285 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
286 };
287
288
289 enum class LINESTYLE
290 {
291 SOLID,
292 DASH,
293 DASHDOT,
295 DOT
296 };
297
298
300 {
302 wxString Name;
303 long Width;
305
306 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
307 };
308
309
310 struct HATCH : PARSER
311 {
312 long Step;
315
316 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
317 };
318
319
321 {
323 wxString Name;
324 std::vector<HATCH> Hatches;
325
326 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
327 };
328
329
330 static const long FONT_NORMAL = 400;
331 static const long FONT_BOLD = 700;
332
333
334 struct FONT : PARSER
335 {
336 wxString Name = wxT( "CADSTAR" );
338 long Modifier2 = 0;
339 bool KerningPairs = false;
343 bool Italic = false;
344
345 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
346 };
347
348
350 {
352 wxString Name;
354 long Height;
355 long Width;
359
360 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
361 };
362
363
365 {
371
372 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
373 };
374
375
377 {
379 wxString Name;
384
385 std::vector<ROUTEREASSIGN> RouteReassigns;
386
387 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
388 };
389
390
394 struct EVALUE : PARSER
395 {
396 long Base = 0;
397 long Exponent = 0;
398
399 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
400 double GetDouble();
401 };
402
407 {
409 POINT( int aX, int aY ) : VECTOR2I( aX, aY ) {}
410
411 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
412 };
413
414
416 {
419
420 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
421 };
422
423
425 {
426 virtual VECTOR2I Apply( POINT aCadstarPoint ) = 0;
427 };
428
429
430 enum class VERTEX_TYPE
431 {
432 VT_POINT,
437 };
438
443 struct VERTEX : PARSER
444 {
445 VERTEX( VERTEX_TYPE aType = VERTEX_TYPE::VT_POINT, POINT aEnd = POINT(), POINT aCenter = POINT() ) :
446 Type( aType ),
447 End( aEnd ),
448 Center( aCenter )
449 {}
450
454
455 static bool IsVertex( XNODE* aNode );
456 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
457
458 void AppendToChain( SHAPE_LINE_CHAIN* aChainToAppendTo,
459 const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
460 int aAccuracy ) const;
461
462 SHAPE_ARC BuildArc( const VECTOR2I& aPrevPoint,
463 const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback ) const;
464 };
465
469 struct CUTOUT : PARSER
470 {
471 std::vector<VERTEX> Vertices;
472
473 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
474 };
475
476
477 enum class SHAPE_TYPE
478 {
479 OPENSHAPE,
480 OUTLINE,
481 SOLID,
482 HATCHED
483 };
484
485
486 struct SHAPE : PARSER
487 {
489 std::vector<VERTEX> Vertices;
490 std::vector<CUTOUT> Cutouts;
491 wxString HatchCodeID;
492
493 static bool IsShape( XNODE* aNode );
494 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
495
496 SHAPE_LINE_CHAIN OutlineAsChain( const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
497 int aAccuracy ) const;
498
499 SHAPE_POLY_SET ConvertToPolySet( const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
500 int aAccuracy ) const;
501 };
502
503
504 enum class UNITS
505 {
506 DESIGN,
507 THOU,
508 INCH,
510 MM,
512 METER
513 };
514
515
516 static UNITS ParseUnits( XNODE* aNode );
517
518
519 enum class ANGUNITS
520 {
521 DEGREES,
522 RADIANS
523 };
524
525
526 static ANGUNITS ParseAngunits( XNODE* aNode );
527
528
529 enum class GRID_TYPE
530 {
533 STEPGRID
534 };
535
536
537 struct GRID : PARSER
538 {
540 wxString Name;
541 long Param1;
543 long Param2;
545
546 static bool IsGrid( XNODE* aNode );
547 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
548 };
549
550
551 struct GRIDS : PARSER
552 {
562 std::vector<GRID> UserGrids;
563
564 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
565 };
566
567
569 {
578 bool AllowBarredText = false;
580
583
585 std::pair<POINT, POINT> DesignArea;
588
589 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
590 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
591 };
592
593
594
611 enum class ALIGNMENT
612 {
614 TOPLEFT,
615 TOPCENTER,
616 TOPRIGHT,
623 };
624
625
626 static ALIGNMENT ParseAlignment( XNODE* aNode );
627
636 enum class JUSTIFICATION
637 {
638 LEFT,
639 CENTER,
640 RIGHT
641 };
642
643
644 static JUSTIFICATION ParseJustification( XNODE* aNode );
645
654 enum class READABILITY
655 {
658 };
659
660
661 static READABILITY ParseReadability( XNODE* aNode );
662
663
664 enum class ATTROWNER
665 {
666 ALL_ITEMS,
667 AREA,
668 BOARD,
669 COMPONENT,
671 COPPER,
672 DOCSYMBOL,
673 FIGURE,
674 NET,
675 NETCLASS,
676 PART,
678 PIN,
679 SIGNALREF,
680 SYMBOL,
681 SYMDEF,
682 TEMPLATE,
684 };
685
686
687 enum class ATTRUSAGE
688 {
689 BOTH,
691 COMPONENT,
695 SYMBOL,
697 UNDEFINED
700 };
701
702
704 {
708 long OrientAngle = 0;
709 bool Mirror = false;
710 bool Fixed = false;
718
719 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
720 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
721 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
722 };
723
724
730 {
732 {
733 long ID;
734 long Order;
735
736 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
737 };
738
739
741 {
742 long ID;
743 long Width;
744
745 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
746 };
747
749 wxString Name;
755 bool NoTransfer = false;
762 std::vector<COLUMNORDER> ColumnOrders;
763 std::vector<COLUMNWIDTH> ColumnWidths;
764 bool ColumnInvisible = false;
765
766 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
767 };
768
769
771 {
773 wxString Value;
774 bool ReadOnly = false;
775 bool HasLocation = false;
778
779 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
780 };
781
782
789 {
791 {
792 // The default alignment for TEXT_LOCATION (when "NO_ALIGNMENT" is selected) is
793 // Bottom left, matching CADSTAR's default behavior
795 }
797
798 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
799 };
800
801
803 {
805 wxString Name;
806 std::vector<ATTRIBUTE_VALUE> Attributes;
807
808 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
809 };
810
811
813 {
815 wxString Name;
816
817 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
818 };
819
820
822 {
823 std::map<LINECODE_ID, LINECODE> LineCodes;
824 std::map<HATCHCODE_ID, HATCHCODE> HatchCodes;
825 std::map<TEXTCODE_ID, TEXTCODE> TextCodes;
826 std::map<ROUTECODE_ID, ROUTECODE> RouteCodes;
827 std::map<ATTRIBUTE_ID, ATTRNAME> AttributeNames;
828 std::map<NETCLASS_ID, CADSTAR_NETCLASS> NetClasses;
829 std::map<SPACING_CLASS_ID, SPCCLASSNAME> SpacingClassNames;
830
831 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
832 };
833
842 enum class SWAP_RULE
843 {
844 NO_SWAP,
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 wxString BuildLibName() const;
965 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
966 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
967 };
968
969
970 struct PART : PARSER
971 {
972 static CADSTAR_PIN_TYPE GetPinType( XNODE* aNode );
973
975 {
976 struct GATE : PARSER
977 {
979 wxString Name;
980 wxString Alternate;
981 long PinCount;
982
983 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
984 };
985
986
987 struct PIN : PARSER
988 {
990
991 wxString Identifier = wxEmptyString;
996 wxString Name = wxEmptyString;
1001 wxString Label = wxEmptyString;
1016 wxString Signal = wxEmptyString;
1020
1021 CADSTAR_PIN_TYPE Type = CADSTAR_PIN_TYPE::UNCOMMITTED;
1022
1028 CADSTAR_PIN_POSITION::TOP_RIGHT;
1031
1032 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1033 };
1034
1035
1037 {
1038 std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1041
1042 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1043 };
1044
1045
1047 {
1048 std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1050
1051 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1052 };
1053
1054
1056 {
1057 wxString GateName =
1058 wxEmptyString;
1061
1062 bool External = false;
1069
1070 std::vector<SWAP_GATE> SwapGates;
1075
1076 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1077 };
1078
1079 wxString Name;
1081 false;
1085
1093
1094 std::map<GATE_ID, GATE> GateSymbols;
1095 std::map<PART_DEFINITION_PIN_ID, PIN> Pins;
1096 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1100 std::vector<PIN_EQUIVALENCE> PinEquivalences;
1101 std::vector<SWAP_GROUP> SwapGroups;
1102
1103 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1104 };
1105
1106
1108 {
1110 wxString Name = wxEmptyString;
1111 CADSTAR_PIN_TYPE Type = CADSTAR_PIN_TYPE::UNCOMMITTED;
1112 wxString Identifier = wxEmptyString;
1113
1114 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1115 };
1116
1117
1119 wxString Name;
1122 std::map<PART_PIN_ID, PART_PIN> PartPins;
1127
1128 bool HidePinNames = false;
1130
1131 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1135
1136 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1137 };
1138
1139
1140 struct PARTS : PARSER
1141 {
1142 std::map<PART_ID, PART> PartDefinitions;
1143
1144 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1145 };
1146
1147
1148 struct NET : PARSER
1149 {
1151 {
1155 GROUP_ID GroupID = wxEmptyString;
1158 bool Fixed = false;
1159
1160 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1161 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1162 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1163 };
1164
1165
1167 {
1171
1172 bool Fixed = false;
1173 bool Hidden = false;
1174 GROUP_ID GroupID = wxEmptyString;
1176
1177 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1180 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1181 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1182
1183 virtual ~CONNECTION() {}
1184 };
1185
1187 ROUTECODE_ID RouteCodeID = wxEmptyString;
1190 wxString Name = wxEmptyString;
1192 bool Highlight = false;
1193
1194 std::map<NETELEMENT_ID, JUNCTION> Junctions;
1195 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1196
1198 wxEmptyString;
1201 wxEmptyString;
1203
1204 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1205 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1206 };
1207
1208
1210 {
1212
1220
1221 GROUP_ID GroupID = wxEmptyString;
1223 long OrientAngle = 0;
1224 bool Mirror = false;
1225 bool Fixed = false;
1227
1232
1233 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1234
1235 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1236 };
1237
1238
1240 {
1242 bool IsVisible = true;
1243
1244 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1245 };
1246
1247
1249 {
1252 bool IsVisible = true;
1253 bool IsPickable = true;
1254
1255 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1256 };
1257
1258
1260 {
1262 std::map<ATTRIBUTE_ID, ATTRCOL> AttributeColors;
1263
1264 bool IsVisible = true; // unclear what this represents - maybe all attributes are hidden?
1265
1266 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1267 };
1268
1269
1271 {
1273 bool IsVisible = true;
1274 bool IsPickable = true;
1275
1276 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1277 };
1278
1280 // HELPER FUNCTIONS: //
1282
1283
1284 static void InsertAttributeAtEnd( XNODE* aNode, wxString aValue );
1285
1298 static XNODE* LoadArchiveFile( const wxString& aFileName, const wxString& aFileTypeIdentifier,
1299 PROGRESS_REPORTER* aProgressReporter = nullptr );
1300
1305 static bool IsValidAttribute( wxXmlAttribute* aAttribute );
1306
1314 static wxString GetXmlAttributeIDString( XNODE* aNode, unsigned int aID,
1315 bool aIsRequired = true );
1316
1324 static long GetXmlAttributeIDLong( XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1325
1330 static void CheckNoChildNodes( XNODE* aNode );
1331
1336 static void CheckNoNextNodes( XNODE* aNode );
1337
1343 static void ParseChildEValue( XNODE* aNode, PARSER_CONTEXT* aContext, EVALUE& aValueToParse );
1344
1358 static std::vector<POINT> ParseAllChildPoints( XNODE* aNode, PARSER_CONTEXT* aContext,
1359 bool aTestAllChildNodes = false,
1360 int aExpectedNumPoints = UNDEFINED_VALUE );
1361
1373 static std::vector<VERTEX> ParseAllChildVertices( XNODE* aNode, PARSER_CONTEXT* aContext,
1374 bool aTestAllChildNodes = false );
1375
1387 static std::vector<CUTOUT> ParseAllChildCutouts( XNODE* aNode, PARSER_CONTEXT* aContext,
1388 bool aTestAllChildNodes = false );
1389
1390 static long GetNumberOfChildNodes( XNODE* aNode );
1391
1392 static long GetNumberOfStepsForReporting( XNODE* aRootNode,
1393 std::vector<wxString> aSubNodeChildrenToCount );
1394
1395
1396 static wxString EscapeFieldText( const wxString& aFieldText )
1397 {
1398 wxString ret = aFieldText;
1399 ret.Replace( wxT( "\n" ), wxT( "\\n" ) );
1400 ret.Replace( wxT( "\r" ), wxT( "\\r" ) );
1401 ret.Replace( wxT( "\t" ), wxT( "\\t" ) );
1402
1403 return ret;
1404 }
1405
1412 static wxString HandleTextOverbar( wxString aCadstarString );
1413
1421 static void FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem );
1422
1423 static wxString generateLibName( const wxString& aRefName, const wxString& aAlternateName );
1424
1425
1426protected:
1427 void checkPoint();
1428
1430 PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
1431
1432
1433}; // class CADSTAR_ARCHIVE_PARSER
1434
1435#endif // CADSTAR_ARCHIVE_PARSER_H_
CADSTAR_PIN_POSITION
Positioning of pin names can be in one of four quadrants.
CADSTAR_PIN_TYPE
file: cadstar_archive_objects.h Contains common object definitions
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.
@ TOP_TO_BOTTOM
When text is vertical, show it rotated 90 degrees clockwise.
static wxString EscapeFieldText(const wxString &aFieldText)
@ STEPGRID
Param1 = X Step, Param2 = Y Step. A standard x,y grid.
@ FRACTIONALGRID
Param1 = Units, Param2 = Divisor.
SWAP_RULE
Corresponds to "Display when" Item property.
@ USE_SWAP_LAYER
Display when Mirrored.
@ BOTH
Always display (Mirrored and Unmirrored)
@ NO_SWAP
Display when 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 wxString generateLibName(const wxString &aRefName, const wxString &aAlternateName)
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.
@ BOTH
From CADSTAR Help: Assigned to both Schematic symbols and PCB components, and displayed on Schematic ...
@ PART_LIBRARY
From CADSTAR Help: Only used by non-Cadstar applications.
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)
Correct 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.
@ OUTLINE
Unfilled closed shape.
@ OPENSHAPE
Unfilled open shape. Cannot have cutouts.
@ HATCHED
Filled closed shape (hatch fill).
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 canceled.
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).
@ DESIGN
Inherits from design units (assumed Assignments->Technology->Units)
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)
@ PART_DEFINITION
Only library Attributes.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:79
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:43
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
Represent 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...
Represent 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 reduce the spacin...
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 JUNCTION 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...
CADSTAR_PIN_POSITION Position
The pin names will use these positions when the symbol is added to a design subnode="PINPOSITION".
TERMINAL_ID TerminalPin
(subnode="PINTERM", param1)
wxString Identifier
This should match a pad identifier in the component footprint subnode="PINIDENTIFIER".
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
static CADSTAR_PIN_TYPE GetPinType(XNODE *aNode)
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.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool HidePinNames
This seems to be a duplicate of DEFINITION::HidePinNames Possibly only used in older file formats?
Represent 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 PinNoAngle
The angle at which the Pin ID is positioned relative to a terminal.
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)
long PinNoOffset
The distance, of a Pin Name/Identifier from its parent terminal.
SHAPE_POLY_SET ConvertToPolySet(const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, int 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.
SHAPE_LINE_CHAIN OutlineAsChain(const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, int aAccuracy) const
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 VECTOR2I 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.
SHAPE_ARC BuildArc(const VECTOR2I &aPrevPoint, const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback) const
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
VERTEX(VERTEX_TYPE aType=VERTEX_TYPE::VT_POINT, POINT aEnd=POINT(), POINT aCenter=POINT())
void AppendToChain(SHAPE_LINE_CHAIN *aChainToAppendTo, const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, int aAccuracy) const
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695