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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
25
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// Warning variants that log instead of throwing, allowing import to continue
58// when encountering unknown nodes from newer CADSTAR versions
59
60#define WARN_UNKNOWN_NODE_IO_ERROR( nodename, location ) \
61 wxLogWarning( wxString::Format( _( "Unknown node '%s' in '%s'" ), nodename, location ) )
62
63#define WARN_UNKNOWN_PARAMETER_IO_ERROR( param, location ) \
64 wxLogWarning( wxString::Format( _( "Unknown Parameter '%s' in '%s'" ), param, location ) )
65
66//=================================
67// MACRO DEFINITIONS
68//=================================
69#define UNDEFINED_LAYER_ID ( LAYER_ID ) wxEmptyString
70
71
72
75#define COMPONENT_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME__" )
76
81#define COMPONENT_NAME_2_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME_2__" )
82
86#define SYMBOL_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__SYMBOL_NAME__" )
87#define LINK_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__LINK_ORIGIN__" )
88#define SIGNALNAME_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__SIGNALNAME_ORIGIN__" )
89#define PART_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__PART_NAME__" )
90
91class EDA_TEXT;
92class wxXmlAttribute;
95class SHAPE_POLY_SET;
96class SHAPE_ARC;
97
102{
103public:
105
107
108
109 typedef wxString LINECODE_ID;
110 typedef wxString HATCHCODE_ID;
111 typedef wxString ROUTECODE_ID;
112 typedef wxString NETCLASS_ID;
113 typedef wxString SPACING_CLASS_ID;
114 typedef wxString TEXTCODE_ID;
115 typedef wxString LAYER_ID;
116 typedef wxString VARIANT_ID;
117 typedef wxString ATTRIBUTE_ID;
118 typedef wxString SYMDEF_ID;
119 typedef wxString PART_ID;
120 typedef wxString GATE_ID;
121 typedef long TERMINAL_ID;
123 typedef long PART_PIN_ID;
124 typedef wxString TEXT_ID;
125 typedef wxString FIGURE_ID;
126 typedef wxString GROUP_ID;
127 typedef wxString REUSEBLOCK_ID;
128 typedef wxString NET_ID;
129 typedef wxString NETELEMENT_ID;
130 typedef wxString DOCUMENTATION_SYMBOL_ID;
131 typedef wxString COLOR_ID;
132
133 static const long UNDEFINED_VALUE = -1;
134
146 static const double TXT_HEIGHT_RATIO;
147
176
181 static const std::map<TEXT_FIELD_NAME, wxString> CADSTAR_TO_KICAD_FIELDS;
182
183
185 {
191 std::map<wxString, wxString> FilenamesToTextMap;
192
197 std::map<wxString, wxString> TextToHyperlinksMap;
198
203 std::map<TEXT_FIELD_NAME, wxString> TextFieldToValuesMap;
204
209 std::set<TEXT_FIELD_NAME> InconsistentTextFields;
210
214 std::function<void()> CheckPointCallback = []() {};
215 };
216
225 static wxString ParseTextFields( const wxString& aTextString, PARSER_CONTEXT* aParserContext );
226
227
228 struct PARSER
229 {
230 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) = 0;
231
232 virtual ~PARSER() {};
233 };
234
235
236 struct FORMAT : PARSER
237 {
238 wxString Type;
239 long SomeInt;
240 long Version;
243 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
244 };
245
246
248 {
249 long Year;
250 long Month;
251 long Day;
252 long Hour;
253 long Minute;
254 long Second;
255
256 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
257 };
258
259 //Note: there are possibly several other resolutions, but HUNDREDTH MICRON is only one known
260 enum class RESOLUTION
261 {
263 };
264
265
266 struct HEADER : PARSER
267 {
269 wxString JobFile;
270 wxString JobTitle;
271 wxString Generator;
274
275 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
276 };
277
278
279 struct VARIANT : PARSER
280 {
281 VARIANT_ID ID = wxEmptyString;
282 VARIANT_ID ParentID = wxEmptyString;
283 wxString Name = wxEmptyString;
284 wxString Description = wxEmptyString;
285
286 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
287 };
288
289
291 {
292 std::map<VARIANT_ID, VARIANT> Variants;
293
294 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
295 };
296
297
306
307
309 {
311 wxString Name;
312 long Width;
314
315 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
316 };
317
318
319 struct HATCH : PARSER
320 {
321 long Step;
324
325 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
326 };
327
328
330 {
332 wxString Name;
333 std::vector<HATCH> Hatches;
334
335 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
336 };
337
338
339 static const long FONT_NORMAL = 400;
340 static const long FONT_BOLD = 700;
341
342
343 struct FONT : PARSER
344 {
345 wxString Name = wxT( "CADSTAR" );
347 long Modifier2 = 0;
348 bool KerningPairs = false;
352 bool Italic = false;
353
354 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
355 };
356
357
359 {
361 wxString Name;
363 long Height;
364 long Width;
368
369 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
370 };
371
372
374 {
380
381 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
382 };
383
384
386 {
388 wxString Name;
393
394 std::vector<ROUTEREASSIGN> RouteReassigns;
395
396 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
397 };
398
399
403 struct EVALUE : PARSER
404 {
405 long Base = 0;
406 long Exponent = 0;
407
408 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
409 double GetDouble();
410 };
411
416 {
418 POINT( int aX, int aY ) : VECTOR2I( aX, aY ) {}
419
420 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
421 };
422
423
425 {
428
429 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
430 };
431
432
434 {
435 virtual VECTOR2I Apply( POINT aCadstarPoint ) = 0;
436 };
437
438
447
452 struct VERTEX : PARSER
453 {
454 VERTEX( VERTEX_TYPE aType = VERTEX_TYPE::VT_POINT, POINT aEnd = POINT(), POINT aCenter = POINT() ) :
455 Type( aType ),
456 End( aEnd ),
457 Center( aCenter )
458 {}
459
463
464 static bool IsVertex( XNODE* aNode );
465 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
466
467 void AppendToChain( SHAPE_LINE_CHAIN* aChainToAppendTo,
468 const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
469 int aAccuracy ) const;
470
471 SHAPE_ARC BuildArc( const VECTOR2I& aPrevPoint,
472 const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback ) const;
473 };
474
478 struct CUTOUT : PARSER
479 {
480 std::vector<VERTEX> Vertices;
481
482 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
483 };
484
485
493
494
495 struct SHAPE : PARSER
496 {
498 std::vector<VERTEX> Vertices;
499 std::vector<CUTOUT> Cutouts;
500 wxString HatchCodeID;
501
502 static bool IsShape( XNODE* aNode );
503 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
504
505 SHAPE_LINE_CHAIN OutlineAsChain( const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
506 int aAccuracy ) const;
507
508 SHAPE_POLY_SET ConvertToPolySet( const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
509 int aAccuracy ) const;
510 };
511
512
523
524
525 static UNITS ParseUnits( XNODE* aNode );
526
527
528 enum class ANGUNITS
529 {
532 };
533
534
535 static ANGUNITS ParseAngunits( XNODE* aNode );
536
537
538 enum class GRID_TYPE
539 {
543 };
544
545
546 struct GRID : PARSER
547 {
549 wxString Name;
550 long Param1;
552 long Param2;
554
555 static bool IsGrid( XNODE* aNode );
556 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
557 };
558
559
560 struct GRIDS : PARSER
561 {
571 std::vector<GRID> UserGrids;
572
573 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
574 };
575
576
578 {
587 bool AllowBarredText = false;
589
592
594 std::pair<POINT, POINT> DesignArea;
597
598 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
599 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
600 };
601
602
603
633
634
635 static ALIGNMENT ParseAlignment( XNODE* aNode );
636
645 enum class JUSTIFICATION
646 {
650 };
651
652
653 static JUSTIFICATION ParseJustification( XNODE* aNode );
654
668
669
670 static READABILITY ParseReadability( XNODE* aNode );
671
672
694
695
710
711
713 {
717 long OrientAngle = 0;
718 bool Mirror = false;
719 bool Fixed = false;
722 ALIGNMENT Alignment = ALIGNMENT::
723 NO_ALIGNMENT;
727
728 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
729 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
730 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
731 };
732
733
739 {
741 {
742 long ID;
743 long Order;
744
745 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
746 };
747
748
750 {
751 long ID;
752 long Width;
753
754 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
755 };
756
758 wxString Name;
764 bool NoTransfer = false;
771 std::vector<COLUMNORDER> ColumnOrders;
772 std::vector<COLUMNWIDTH> ColumnWidths;
773 bool ColumnInvisible = false;
774
775 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
776 };
777
778
780 {
782 wxString Value;
783 bool ReadOnly = false;
784 bool HasLocation = false;
787
788 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
789 };
790
791
798 {
800 {
801 // The default alignment for TEXT_LOCATION (when "NO_ALIGNMENT" is selected) is
802 // Bottom left, matching CADSTAR's default behavior
804 }
806
807 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
808 };
809
810
812 {
814 wxString Name;
815 std::vector<ATTRIBUTE_VALUE> Attributes;
816
817 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
818 };
819
820
822 {
824 wxString Name;
825
826 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
827 };
828
829
831 {
832 std::map<LINECODE_ID, LINECODE> LineCodes;
833 std::map<HATCHCODE_ID, HATCHCODE> HatchCodes;
834 std::map<TEXTCODE_ID, TEXTCODE> TextCodes;
835 std::map<ROUTECODE_ID, ROUTECODE> RouteCodes;
836 std::map<ATTRIBUTE_ID, ATTRNAME> AttributeNames;
837 std::map<NETCLASS_ID, CADSTAR_NETCLASS> NetClasses;
838 std::map<SPACING_CLASS_ID, SPCCLASSNAME> SpacingClassNames;
839
840 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
841 };
842
857
858
859 static SWAP_RULE ParseSwapRule( XNODE* aNode );
860
861
863 {
865 wxString Name;
866 wxString FileName;
867 bool Mirror = false;
868 long OrientAngle = 0;
869
870 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
871 };
872
873
878 {
880 wxString ItemReference = wxEmptyString;
884
885 bool IsEmpty();
886 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
887 };
888
889
890 struct GROUP : PARSER
891 {
893 wxString Name;
894 bool Fixed = false;
895 bool Transfer = false;
896 GROUP_ID GroupID = wxEmptyString;
899
900 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
901 };
902
903
904 struct FIGURE : PARSER
905 {
909 SHAPE Shape; //< Uses the component's coordinate frame if within a component
910 //< definition, otherwise uses the design's coordinate frame.
911 GROUP_ID GroupID = wxEmptyString;
914 bool Fixed = false;
915 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
916
917 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
918 };
919
920
921 struct TEXT : PARSER
922 {
924 wxString Text; //TODO: Need to lex/parse to identify design fields and hyperlinks
928 long OrientAngle = 0;
929 bool Mirror = false;
930 bool Fixed = false;
938 GROUP_ID GroupID = wxEmptyString;
940
941 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
942 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext, bool aParseFields );
943 };
944
945
946 struct SYMDEF : PARSER
947 {
949 wxString ReferenceName;
951 wxString Alternate;
955 bool Stub = false;
963
964 std::map<FIGURE_ID, FIGURE> Figures;
965 std::map<TEXT_ID, TEXT> Texts;
966 std::map<ATTRIBUTE_ID, TEXT_LOCATION> TextLocations;
969 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
971
972 wxString BuildLibName() const;
973 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
974 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
975 };
976
977
978 struct PART : PARSER
979 {
980 static CADSTAR_PIN_TYPE GetPinType( XNODE* aNode );
981
983 {
984 struct GATE : PARSER
985 {
987 wxString Name;
988 wxString Alternate;
989 long PinCount;
990
991 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
992 };
993
994
995 struct PIN : PARSER
996 {
998
999 wxString Identifier = wxEmptyString;
1004 wxString Name = wxEmptyString;
1009 wxString Label = wxEmptyString;
1024 wxString Signal = wxEmptyString;
1028
1030
1039
1040 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1041 };
1042
1043
1045 {
1046 std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1049
1050 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1051 };
1052
1053
1055 {
1056 std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1058
1059 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1060 };
1061
1062
1064 {
1065 wxString GateName =
1066 wxEmptyString;
1069
1070 bool External = false;
1077
1078 std::vector<SWAP_GATE> SwapGates;
1083
1084 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1085 };
1086
1087 wxString Name;
1089 false;
1093
1101
1102 std::map<GATE_ID, GATE> GateSymbols;
1103 std::map<PART_DEFINITION_PIN_ID, PIN> Pins;
1104 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1108 std::vector<PIN_EQUIVALENCE> PinEquivalences;
1109 std::vector<SWAP_GROUP> SwapGroups;
1110
1111 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1112 };
1113
1114
1116 {
1118 wxString Name = wxEmptyString;
1120 wxString Identifier = wxEmptyString;
1121
1122 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1123 };
1124
1125
1127 wxString Name;
1130 std::map<PART_PIN_ID, PART_PIN> PartPins;
1135
1136 bool HidePinNames = false;
1138
1139 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1143
1144 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1145 };
1146
1147
1148 struct PARTS : PARSER
1149 {
1150 std::map<PART_ID, PART> PartDefinitions;
1151
1152 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1153 };
1154
1155
1156 struct NET : PARSER
1157 {
1159 {
1163 GROUP_ID GroupID = wxEmptyString;
1166 bool Fixed = false;
1167
1168 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1169 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1170 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1171 };
1172
1173
1175 {
1179
1180 bool Fixed = false;
1181 bool Hidden = false;
1182 GROUP_ID GroupID = wxEmptyString;
1184
1185 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1188 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1189 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1190
1191 virtual ~CONNECTION() {}
1192 };
1193
1195 ROUTECODE_ID RouteCodeID = wxEmptyString;
1198 wxString Name = wxEmptyString;
1200 bool Highlight = false;
1201
1202 std::map<NETELEMENT_ID, JUNCTION> Junctions;
1203 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1204
1206 wxEmptyString;
1209 wxEmptyString;
1211
1212 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1213 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1214 };
1215
1216
1218 {
1220
1228
1229 GROUP_ID GroupID = wxEmptyString;
1231 long OrientAngle = 0;
1232 bool Mirror = false;
1233 bool Fixed = false;
1235
1240
1241 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1242
1243 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1244 };
1245
1246
1248 {
1250 bool IsVisible = true;
1251
1252 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1253 };
1254
1255
1257 {
1260 bool IsVisible = true;
1261 bool IsPickable = true;
1262
1263 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1264 };
1265
1266
1268 {
1270 std::map<ATTRIBUTE_ID, ATTRCOL> AttributeColors;
1271
1272 bool IsVisible = true; // unclear what this represents - maybe all attributes are hidden?
1273
1274 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1275 };
1276
1277
1279 {
1281 bool IsVisible = true;
1282 bool IsPickable = true;
1283
1284 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1285 };
1286
1288 // HELPER FUNCTIONS: //
1290
1291
1292 static void InsertAttributeAtEnd( XNODE* aNode, wxString aValue );
1293
1306 static XNODE* LoadArchiveFile( const wxString& aFileName, const wxString& aFileTypeIdentifier,
1307 PROGRESS_REPORTER* aProgressReporter = nullptr );
1308
1313 static bool IsValidAttribute( wxXmlAttribute* aAttribute );
1314
1322 static wxString GetXmlAttributeIDString( XNODE* aNode, unsigned int aID,
1323 bool aIsRequired = true );
1324
1332 static long GetXmlAttributeIDLong( XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1333
1339 static void CheckNoChildNodes( XNODE* aNode );
1340
1346 static void CheckNoNextNodes( XNODE* aNode );
1347
1354 static void ParseChildEValue( XNODE* aNode, PARSER_CONTEXT* aContext, EVALUE& aValueToParse );
1355
1371 static std::vector<POINT> ParseAllChildPoints( XNODE* aNode, PARSER_CONTEXT* aContext,
1372 bool aTestAllChildNodes = false,
1373 int aExpectedNumPoints = UNDEFINED_VALUE );
1374
1387 static std::vector<VERTEX> ParseAllChildVertices( XNODE* aNode, PARSER_CONTEXT* aContext,
1388 bool aTestAllChildNodes = false );
1389
1402 static std::vector<CUTOUT> ParseAllChildCutouts( XNODE* aNode, PARSER_CONTEXT* aContext,
1403 bool aTestAllChildNodes = false );
1404
1405 static long GetNumberOfChildNodes( XNODE* aNode );
1406
1407 static long GetNumberOfStepsForReporting( XNODE* aRootNode,
1408 std::vector<wxString> aSubNodeChildrenToCount );
1409
1410
1411 static wxString EscapeFieldText( const wxString& aFieldText )
1412 {
1413 wxString ret = aFieldText;
1414 ret.Replace( wxT( "\n" ), wxT( "\\n" ) );
1415 ret.Replace( wxT( "\r" ), wxT( "\\r" ) );
1416 ret.Replace( wxT( "\t" ), wxT( "\\t" ) );
1417
1418 return ret;
1419 }
1420
1427 static wxString HandleTextOverbar( wxString aCadstarString );
1428
1436 static void FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem );
1437
1438 static wxString generateLibName( const wxString& aRefName, const wxString& aAlternateName );
1439
1440
1441protected:
1442 void checkPoint();
1443
1445 PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
1446
1447
1448}; // class CADSTAR_ARCHIVE_PARSER
1449
1450#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
@ UNCOMMITTED
Uncommitted pin (default)
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.
@ 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 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.
@ 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:89
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.
An extension of wxXmlNode that can format its contents as KiCad-style s-expressions.
Definition xnode.h:67
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 spacing...
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.
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".
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.
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.
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
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 of...
JUSTIFICATION Justification
Note: 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
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:683