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#include <trace_helpers.h>
40
41// THROW_IO_ERROR definitions to ensure consistent wording is used in the error messages
42
43#define THROW_MISSING_NODE_IO_ERROR( nodename, location ) \
44 THROW_IO_ERROR( wxString::Format( _( "Missing node '%s' in '%s'" ), nodename, location ) )
45
46#define THROW_UNKNOWN_NODE_IO_ERROR( nodename, location ) \
47 THROW_IO_ERROR( wxString::Format( _( "Unknown node '%s' in '%s'" ), nodename, location ) )
48
49#define THROW_MISSING_PARAMETER_IO_ERROR( param, location ) \
50 THROW_IO_ERROR( wxString::Format( _( "Missing Parameter '%s' in '%s'" ), param, location ) )
51
52#define THROW_UNKNOWN_PARAMETER_IO_ERROR( param, location ) \
53 THROW_IO_ERROR( wxString::Format( _( "Unknown Parameter '%s' in '%s'" ), param, location ) )
54
55#define THROW_PARSING_IO_ERROR( param, location ) \
56 THROW_IO_ERROR( wxString::Format( _( "Unable to parse '%s' in '%s'" ), param, location ) )
58// Trace variants that log instead of throwing, allowing import to continue when encountering
59// unknown nodes from newer CADSTAR versions. These are developer diagnostics rather than
60// anything the user can act on, so they stay silent unless KICAD_CADSTAR_IO is traced.
61
62#define WARN_UNKNOWN_NODE_IO_ERROR( nodename, location ) \
63 wxLogTrace( traceCadstarIo, wxT( "Unknown node '%s' in '%s'" ), nodename, location )
64
65#define WARN_UNKNOWN_PARAMETER_IO_ERROR( param, location ) \
66 wxLogTrace( traceCadstarIo, wxT( "Unknown Parameter '%s' in '%s'" ), param, location )
67
68//=================================
69// MACRO DEFINITIONS
70//=================================
71#define UNDEFINED_LAYER_ID ( LAYER_ID ) wxEmptyString
72
73
77#define COMPONENT_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME__" )
78
83#define COMPONENT_NAME_2_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME_2__" )
84
88#define SYMBOL_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__SYMBOL_NAME__" )
89#define LINK_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__LINK_ORIGIN__" )
90#define SIGNALNAME_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__SIGNALNAME_ORIGIN__" )
91#define PART_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__PART_NAME__" )
92
93class EDA_TEXT;
94class wxXmlAttribute;
97class SHAPE_POLY_SET;
98class SHAPE_ARC;
99
104{
105public:
107
109
110
111 typedef wxString LINECODE_ID;
112 typedef wxString HATCHCODE_ID;
113 typedef wxString ROUTECODE_ID;
114 typedef wxString NETCLASS_ID;
115 typedef wxString SPACING_CLASS_ID;
116 typedef wxString TEXTCODE_ID;
117 typedef wxString LAYER_ID;
118 typedef wxString VARIANT_ID;
119 typedef wxString ATTRIBUTE_ID;
120 typedef wxString SYMDEF_ID;
121 typedef wxString PART_ID;
122 typedef wxString GATE_ID;
123 typedef long TERMINAL_ID;
125 typedef long PART_PIN_ID;
126 typedef wxString TEXT_ID;
127 typedef wxString FIGURE_ID;
128 typedef wxString GROUP_ID;
129 typedef wxString REUSEBLOCK_ID;
130 typedef wxString NET_ID;
131 typedef wxString NETELEMENT_ID;
132 typedef wxString DOCUMENTATION_SYMBOL_ID;
133 typedef wxString COLOR_ID;
134
135 static const long UNDEFINED_VALUE = -1;
136
148 static const double TXT_HEIGHT_RATIO;
149
178
183 static const std::map<TEXT_FIELD_NAME, wxString> CADSTAR_TO_KICAD_FIELDS;
184
185
187 {
193 std::map<wxString, wxString> FilenamesToTextMap;
194
199 std::map<wxString, wxString> TextToHyperlinksMap;
200
205 std::map<TEXT_FIELD_NAME, wxString> TextFieldToValuesMap;
206
211 std::set<TEXT_FIELD_NAME> InconsistentTextFields;
212
216 std::function<void()> CheckPointCallback = []() {};
217 };
218
227 static wxString ParseTextFields( const wxString& aTextString, PARSER_CONTEXT* aParserContext );
228
229
230 struct PARSER
231 {
232 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) = 0;
233
234 virtual ~PARSER() {};
235 };
236
237
238 struct FORMAT : PARSER
239 {
240 wxString Type;
241 long SomeInt;
242 long Version;
245 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
246 };
247
248
250 {
251 long Year;
252 long Month;
253 long Day;
254 long Hour;
255 long Minute;
256 long Second;
257
258 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
259 };
260
261 //Note: there are possibly several other resolutions, but HUNDREDTH MICRON is only one known
262 enum class RESOLUTION
263 {
265 };
266
267
268 struct HEADER : PARSER
269 {
271 wxString JobFile;
272 wxString JobTitle;
273 wxString Generator;
276
277 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
278 };
279
280
281 struct VARIANT : PARSER
282 {
283 VARIANT_ID ID = wxEmptyString;
284 VARIANT_ID ParentID = wxEmptyString;
285 wxString Name = wxEmptyString;
286 wxString Description = wxEmptyString;
287
288 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
289 };
290
291
293 {
294 std::map<VARIANT_ID, VARIANT> Variants;
295
296 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
297 };
298
299
308
309
311 {
313 wxString Name;
314 long Width;
316
317 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
318 };
319
320
321 struct HATCH : PARSER
322 {
323 long Step;
326
327 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
328 };
329
330
332 {
334 wxString Name;
335 std::vector<HATCH> Hatches;
336
337 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
338 };
339
340
341 static const long FONT_NORMAL = 400;
342 static const long FONT_BOLD = 700;
343
344
345 struct FONT : PARSER
346 {
347 wxString Name = wxT( "CADSTAR" );
349 long Modifier2 = 0;
350 bool KerningPairs = false;
354 bool Italic = false;
355
356 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
357 };
358
359
361 {
363 wxString Name;
365 long Height;
366 long Width;
370
371 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
372 };
373
374
376 {
382
383 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
384 };
385
386
388 {
390 wxString Name;
395
396 std::vector<ROUTEREASSIGN> RouteReassigns;
397
398 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
399 };
400
401
405 struct EVALUE : PARSER
406 {
407 long Base = 0;
408 long Exponent = 0;
409
410 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
411 double GetDouble();
412 };
413
418 {
420 POINT( int aX, int aY ) : VECTOR2I( aX, aY ) {}
421
422 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
423 };
424
425
427 {
430
431 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
432 };
433
434
436 {
437 virtual VECTOR2I Apply( POINT aCadstarPoint ) = 0;
438 };
439
440
449
454 struct VERTEX : PARSER
455 {
456 VERTEX( VERTEX_TYPE aType = VERTEX_TYPE::VT_POINT, POINT aEnd = POINT(), POINT aCenter = POINT() ) :
457 Type( aType ),
458 End( aEnd ),
459 Center( aCenter )
460 {}
461
465
466 static bool IsVertex( XNODE* aNode );
467 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
468
469 void AppendToChain( SHAPE_LINE_CHAIN* aChainToAppendTo,
470 const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
471 int aAccuracy ) const;
472
473 SHAPE_ARC BuildArc( const VECTOR2I& aPrevPoint,
474 const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback ) const;
475 };
476
480 struct CUTOUT : PARSER
481 {
482 std::vector<VERTEX> Vertices;
483
484 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
485 };
486
487
495
496
497 struct SHAPE : PARSER
498 {
500 std::vector<VERTEX> Vertices;
501 std::vector<CUTOUT> Cutouts;
502 wxString HatchCodeID;
503
504 static bool IsShape( XNODE* aNode );
505 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
506
507 SHAPE_LINE_CHAIN OutlineAsChain( const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
508 int aAccuracy ) const;
509
510 SHAPE_POLY_SET ConvertToPolySet( const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
511 int aAccuracy ) const;
512 };
513
514
525
526
527 static UNITS ParseUnits( XNODE* aNode );
528
529
530 enum class ANGUNITS
531 {
534 };
535
536
537 static ANGUNITS ParseAngunits( XNODE* aNode );
538
539
540 enum class GRID_TYPE
541 {
545 };
546
547
548 struct GRID : PARSER
549 {
551 wxString Name;
552 long Param1;
554 long Param2;
556
557 static bool IsGrid( XNODE* aNode );
558 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
559 };
560
561
562 struct GRIDS : PARSER
563 {
573 std::vector<GRID> UserGrids;
574
575 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
576 };
577
578
580 {
589 bool AllowBarredText = false;
591
594
596 std::pair<POINT, POINT> DesignArea;
599
600 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
601 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
602 };
603
604
605
635
636
637 static ALIGNMENT ParseAlignment( XNODE* aNode );
638
647 enum class JUSTIFICATION
648 {
652 };
653
654
655 static JUSTIFICATION ParseJustification( XNODE* aNode );
656
670
671
672 static READABILITY ParseReadability( XNODE* aNode );
673
674
696
697
712
713
715 {
719 long OrientAngle = 0;
720 bool Mirror = false;
721 bool Fixed = false;
724 ALIGNMENT Alignment = ALIGNMENT::
725 NO_ALIGNMENT;
729
730 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
731 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
732 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
733 };
734
735
741 {
743 {
744 long ID;
745 long Order;
746
747 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
748 };
749
750
752 {
753 long ID;
754 long Width;
755
756 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
757 };
758
760 wxString Name;
766 bool NoTransfer = false;
773 std::vector<COLUMNORDER> ColumnOrders;
774 std::vector<COLUMNWIDTH> ColumnWidths;
775 bool ColumnInvisible = false;
776
777 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
778 };
779
780
782 {
784 wxString Value;
785 bool ReadOnly = false;
786 bool HasLocation = false;
789
790 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
791 };
792
793
800 {
802 {
803 // The default alignment for TEXT_LOCATION (when "NO_ALIGNMENT" is selected) is
804 // Bottom left, matching CADSTAR's default behavior
806 }
808
809 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
810 };
811
812
814 {
816 wxString Name;
817 std::vector<ATTRIBUTE_VALUE> Attributes;
818
819 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
820 };
821
822
824 {
826 wxString Name;
827
828 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
829 };
830
831
833 {
834 std::map<LINECODE_ID, LINECODE> LineCodes;
835 std::map<HATCHCODE_ID, HATCHCODE> HatchCodes;
836 std::map<TEXTCODE_ID, TEXTCODE> TextCodes;
837 std::map<ROUTECODE_ID, ROUTECODE> RouteCodes;
838 std::map<ATTRIBUTE_ID, ATTRNAME> AttributeNames;
839 std::map<NETCLASS_ID, CADSTAR_NETCLASS> NetClasses;
840 std::map<SPACING_CLASS_ID, SPCCLASSNAME> SpacingClassNames;
841
842 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
843 };
844
859
860
861 static SWAP_RULE ParseSwapRule( XNODE* aNode );
862
863
865 {
867 wxString Name;
868 wxString FileName;
869 bool Mirror = false;
870 long OrientAngle = 0;
871
872 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
873 };
874
875
880 {
882 wxString ItemReference = wxEmptyString;
886
887 bool IsEmpty();
888 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
889 };
890
891
892 struct GROUP : PARSER
893 {
895 wxString Name;
896 bool Fixed = false;
897 bool Transfer = false;
898 GROUP_ID GroupID = wxEmptyString;
901
902 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
903 };
904
905
906 struct FIGURE : PARSER
907 {
911 SHAPE Shape; //< Uses the component's coordinate frame if within a component
912 //< definition, otherwise uses the design's coordinate frame.
913 GROUP_ID GroupID = wxEmptyString;
916 bool Fixed = false;
917 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
918
919 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
920 };
921
922
923 struct TEXT : PARSER
924 {
926 wxString Text; //TODO: Need to lex/parse to identify design fields and hyperlinks
930 long OrientAngle = 0;
931 bool Mirror = false;
932 bool Fixed = false;
940 GROUP_ID GroupID = wxEmptyString;
942
943 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
944 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext, bool aParseFields );
945 };
946
947
948 struct SYMDEF : PARSER
949 {
951 wxString ReferenceName;
953 wxString Alternate;
957 bool Stub = false;
965
966 std::map<FIGURE_ID, FIGURE> Figures;
967 std::map<TEXT_ID, TEXT> Texts;
968 std::map<ATTRIBUTE_ID, TEXT_LOCATION> TextLocations;
971 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
973
974 wxString BuildLibName() const;
975 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
976 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
977 };
978
979
980 struct PART : PARSER
981 {
982 static CADSTAR_PIN_TYPE GetPinType( XNODE* aNode );
983
985 {
986 struct GATE : PARSER
987 {
989 wxString Name;
990 wxString Alternate;
991 long PinCount;
992
993 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
994 };
995
996
997 struct PIN : PARSER
998 {
1000
1001 wxString Identifier = wxEmptyString;
1006 wxString Name = wxEmptyString;
1011 wxString Label = wxEmptyString;
1026 wxString Signal = wxEmptyString;
1030
1032
1041
1042 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1043 };
1044
1045
1047 {
1048 std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1051
1052 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1053 };
1054
1055
1057 {
1058 std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1060
1061 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1062 };
1063
1064
1066 {
1067 wxString GateName =
1068 wxEmptyString;
1071
1072 bool External = false;
1079
1080 std::vector<SWAP_GATE> SwapGates;
1085
1086 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1087 };
1088
1089 wxString Name;
1091 false;
1095
1103
1104 std::map<GATE_ID, GATE> GateSymbols;
1105 std::map<PART_DEFINITION_PIN_ID, PIN> Pins;
1106 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1110 std::vector<PIN_EQUIVALENCE> PinEquivalences;
1111 std::vector<SWAP_GROUP> SwapGroups;
1112
1113 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1114 };
1115
1116
1118 {
1120 wxString Name = wxEmptyString;
1122 wxString Identifier = wxEmptyString;
1123
1124 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1125 };
1126
1127
1129 wxString Name;
1132 std::map<PART_PIN_ID, PART_PIN> PartPins;
1137
1138 bool HidePinNames = false;
1140
1141 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1145
1146 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1147 };
1148
1149
1150 struct PARTS : PARSER
1151 {
1152 std::map<PART_ID, PART> PartDefinitions;
1153
1154 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1155 };
1156
1157
1158 struct NET : PARSER
1159 {
1161 {
1165 GROUP_ID GroupID = wxEmptyString;
1168 bool Fixed = false;
1169
1170 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1171 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1172 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1173 };
1174
1175
1177 {
1181
1182 bool Fixed = false;
1183 bool Hidden = false;
1184 GROUP_ID GroupID = wxEmptyString;
1186
1187 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1190 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1191 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1192
1193 virtual ~CONNECTION() {}
1194 };
1195
1197 ROUTECODE_ID RouteCodeID = wxEmptyString;
1200 wxString Name = wxEmptyString;
1202 bool Highlight = false;
1203
1204 std::map<NETELEMENT_ID, JUNCTION> Junctions;
1205 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1206
1208 wxEmptyString;
1211 wxEmptyString;
1213
1214 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1215 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1216 };
1217
1218
1220 {
1222
1230
1231 GROUP_ID GroupID = wxEmptyString;
1233 long OrientAngle = 0;
1234 bool Mirror = false;
1235 bool Fixed = false;
1237
1242
1243 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1244
1245 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1246 };
1247
1248
1250 {
1252 bool IsVisible = true;
1253
1254 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1255 };
1256
1257
1259 {
1262 bool IsVisible = true;
1263 bool IsPickable = true;
1264
1265 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1266 };
1267
1268
1270 {
1272 std::map<ATTRIBUTE_ID, ATTRCOL> AttributeColors;
1273
1274 bool IsVisible = true; // unclear what this represents - maybe all attributes are hidden?
1275
1276 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1277 };
1278
1279
1281 {
1283 bool IsVisible = true;
1284 bool IsPickable = true;
1285
1286 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1287 };
1288
1290 // HELPER FUNCTIONS: //
1292
1293
1294 static void InsertAttributeAtEnd( XNODE* aNode, wxString aValue );
1295
1308 static XNODE* LoadArchiveFile( const wxString& aFileName, const wxString& aFileTypeIdentifier,
1309 PROGRESS_REPORTER* aProgressReporter = nullptr );
1310
1315 static bool IsValidAttribute( wxXmlAttribute* aAttribute );
1316
1324 static wxString GetXmlAttributeIDString( XNODE* aNode, unsigned int aID,
1325 bool aIsRequired = true );
1326
1334 static long GetXmlAttributeIDLong( XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1335
1341 static void CheckNoChildNodes( XNODE* aNode );
1342
1348 static void CheckNoNextNodes( XNODE* aNode );
1349
1356 static void ParseChildEValue( XNODE* aNode, PARSER_CONTEXT* aContext, EVALUE& aValueToParse );
1357
1373 static std::vector<POINT> ParseAllChildPoints( XNODE* aNode, PARSER_CONTEXT* aContext,
1374 bool aTestAllChildNodes = false,
1375 int aExpectedNumPoints = UNDEFINED_VALUE );
1376
1389 static std::vector<VERTEX> ParseAllChildVertices( XNODE* aNode, PARSER_CONTEXT* aContext,
1390 bool aTestAllChildNodes = false );
1391
1404 static std::vector<CUTOUT> ParseAllChildCutouts( XNODE* aNode, PARSER_CONTEXT* aContext,
1405 bool aTestAllChildNodes = false );
1406
1407 static long GetNumberOfChildNodes( XNODE* aNode );
1408
1409 static long GetNumberOfStepsForReporting( XNODE* aRootNode,
1410 std::vector<wxString> aSubNodeChildrenToCount );
1411
1412
1413 static wxString EscapeFieldText( const wxString& aFieldText )
1414 {
1415 wxString ret = aFieldText;
1416 ret.Replace( wxT( "\n" ), wxT( "\\n" ) );
1417 ret.Replace( wxT( "\r" ), wxT( "\\r" ) );
1418 ret.Replace( wxT( "\t" ), wxT( "\\t" ) );
1419
1420 return ret;
1421 }
1422
1429 static wxString HandleTextOverbar( wxString aCadstarString );
1430
1438 static void FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem );
1439
1440 static wxString generateLibName( const wxString& aRefName, const wxString& aAlternateName );
1441
1442
1443protected:
1444 void checkPoint();
1445
1447 PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
1448
1449
1450}; // class CADSTAR_ARCHIVE_PARSER
1451
1452#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
wxLogTrace helper definitions.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683