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 (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
26#ifndef CADSTAR_ARCHIVE_PARSER_H_
27#define CADSTAR_ARCHIVE_PARSER_H_
28
29#include <richio.h>
30#include <wx/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
215 static wxString ParseTextFields( const wxString& aTextString, PARSER_CONTEXT* aParserContext );
216
217
218 struct PARSER
219 {
220 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) = 0;
221
222 virtual ~PARSER() {};
223 };
224
225
226 struct FORMAT : PARSER
227 {
228 wxString Type;
229 long SomeInt;
230 long Version;
233 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
234 };
235
236
238 {
239 long Year;
240 long Month;
241 long Day;
242 long Hour;
243 long Minute;
244 long Second;
245
246 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
247 };
248
249 //Note: there are possibly several other resolutions, but HUNDREDTH MICRON is only one known
250 enum class RESOLUTION
251 {
253 };
254
255
256 struct HEADER : PARSER
257 {
259 wxString JobFile;
260 wxString JobTitle;
261 wxString Generator;
264
265 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
266 };
267
268
269 struct VARIANT : PARSER
270 {
271 VARIANT_ID ID = wxEmptyString;
272 VARIANT_ID ParentID = wxEmptyString;
273 wxString Name = wxEmptyString;
274 wxString Description = wxEmptyString;
275
276 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
277 };
278
279
281 {
282 std::map<VARIANT_ID, VARIANT> Variants;
283
284 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
285 };
286
287
288 enum class LINESTYLE
289 {
290 SOLID,
291 DASH,
292 DASHDOT,
294 DOT
295 };
296
297
299 {
301 wxString Name;
302 long Width;
304
305 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
306 };
307
308
309 struct HATCH : PARSER
310 {
311 long Step;
314
315 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
316 };
317
318
320 {
322 wxString Name;
323 std::vector<HATCH> Hatches;
324
325 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
326 };
327
328
329 static const long FONT_NORMAL = 400;
330 static const long FONT_BOLD = 700;
331
332
333 struct FONT : PARSER
334 {
335 wxString Name = wxT( "CADSTAR" );
337 long Modifier2 = 0;
339 false;
342 bool Italic = false;
343
344 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
345 };
346
347
349 {
351 wxString Name;
353 long Height;
354 long Width;
358
359 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
360 };
361
362
364 {
370
371 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
372 };
373
374
376 {
378 wxString Name;
383
384 std::vector<ROUTEREASSIGN> RouteReassigns;
385
386 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
387 };
388
389
393 struct EVALUE : PARSER
394 {
395 long Base = 0;
396 long Exponent = 0;
397
398 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
399 double GetDouble();
400 };
401
406 {
408 POINT( int aX, int aY ) : VECTOR2I( aX, aY ) {}
409
410 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
411 };
412
413
415 {
418
419 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
420 };
421
422
424 {
425 virtual VECTOR2I Apply( POINT aCadstarPoint ) = 0;
426 };
427
428
429 enum class VERTEX_TYPE
430 {
431 POINT,
436 };
437
442 struct VERTEX : PARSER
443 {
444 VERTEX( VERTEX_TYPE aType = VERTEX_TYPE::POINT, POINT aEnd = POINT(), POINT aCenter = POINT() ) :
445 Type( aType ), End( aEnd ), Center( aCenter )
446 {}
447
451
452 static bool IsVertex( XNODE* aNode );
453 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
454
455 void AppendToChain( SHAPE_LINE_CHAIN* aChainToAppendTo,
456 const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
457 double aAccuracy ) const;
458
459 SHAPE_ARC BuildArc( const VECTOR2I& aPrevPoint,
460 const std::function<VECTOR2I( const VECTOR2I& )>
461 aCadstarToKicadPointCallback ) const;
462 };
463
467 struct CUTOUT : PARSER
468 {
469 std::vector<VERTEX> Vertices;
470
471 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
472 };
473
474
475 enum class SHAPE_TYPE
476 {
477 OPENSHAPE,
478 OUTLINE,
479 SOLID,
480 HATCHED
481 };
482
483
484 struct SHAPE : PARSER
485 {
487 std::vector<VERTEX> Vertices;
488 std::vector<CUTOUT> Cutouts;
489 wxString HatchCodeID;
490
491 static bool IsShape( XNODE* aNode );
492 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
493
494 SHAPE_LINE_CHAIN OutlineAsChain( const std::function<VECTOR2I( const VECTOR2I& )>
495 aCadstarToKicadPointCallback,
496 double aAccuracy ) const;
497
498 SHAPE_POLY_SET ConvertToPolySet( const std::function<VECTOR2I( const VECTOR2I& )>
499 aCadstarToKicadPointCallback,
500 double 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
612 enum class ALIGNMENT
613 {
615 TOPLEFT,
616 TOPCENTER,
617 TOPRIGHT,
624 };
625
626
627 static ALIGNMENT ParseAlignment( XNODE* aNode );
628
638 enum class JUSTIFICATION
639 {
640 LEFT,
641 CENTER,
642 RIGHT
643 };
644
645
646 static JUSTIFICATION ParseJustification( XNODE* aNode );
647
656 enum class READABILITY
657 {
660 };
661
662
663 static READABILITY ParseReadability( XNODE* aNode );
664
665
666 enum class ATTROWNER
667 {
668 ALL_ITEMS,
669 AREA,
670 BOARD,
671 COMPONENT,
673 COPPER,
674 DOCSYMBOL,
675 FIGURE,
676 NET,
677 NETCLASS,
678 PART,
680 PIN,
681 SIGNALREF,
682 SYMBOL,
683 SYMDEF,
684 TEMPLATE,
686 };
687
688
689 enum class ATTRUSAGE
690 {
691 BOTH,
693 COMPONENT,
697 SYMBOL,
699 UNDEFINED
702 };
703
704
706 {
710 long OrientAngle = 0;
711 bool Mirror = false;
712 bool Fixed = false;
720
721 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
722 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
723 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
724 };
725
726
732 {
734 {
735 long ID;
736 long Order;
737
738 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
739 };
740
741
743 {
744 long ID;
745 long Width;
746
747 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
748 };
749
751 wxString Name;
757 bool NoTransfer = false;
764 std::vector<COLUMNORDER> ColumnOrders;
765 std::vector<COLUMNWIDTH> ColumnWidths;
766 bool ColumnInvisible = false;
767
768 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
769 };
770
771
773 {
775 wxString Value;
776 bool ReadOnly = false;
777 bool HasLocation = false;
780
781 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
782 };
783
784
791 {
793 {
794 // The default alignment for TEXT_LOCATION (when "NO_ALIGNMENT" is selected) is
795 // Bottom left, matching CADSTAR's default behaviour
797 }
799
800 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
801 };
802
803
805 {
807 wxString Name;
808 std::vector<ATTRIBUTE_VALUE> Attributes;
809
810 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
811 };
812
813
815 {
817 wxString Name;
818
819 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
820 };
821
822
824 {
825 std::map<LINECODE_ID, LINECODE> LineCodes;
826 std::map<HATCHCODE_ID, HATCHCODE> HatchCodes;
827 std::map<TEXTCODE_ID, TEXTCODE> TextCodes;
828 std::map<ROUTECODE_ID, ROUTECODE> RouteCodes;
829 std::map<ATTRIBUTE_ID, ATTRNAME> AttributeNames;
830 std::map<NETCLASS_ID, CADSTAR_NETCLASS> NetClasses;
831 std::map<SPACING_CLASS_ID, SPCCLASSNAME> SpacingClassNames;
832
833 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
834 };
835
846 enum class SWAP_RULE
847 {
848 NO_SWAP,
850 BOTH
851 };
852
853
854 static SWAP_RULE ParseSwapRule( XNODE* aNode );
855
856
858 {
860 wxString Name;
861 wxString FileName;
862 bool Mirror = false;
863 long OrientAngle = 0;
864
865 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
866 };
867
868
873 {
875 wxString ItemReference = wxEmptyString;
879
880 bool IsEmpty();
881 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
882 };
883
884
885 struct GROUP : PARSER
886 {
888 wxString Name;
889 bool Fixed = false;
890 bool Transfer = false;
891 GROUP_ID GroupID = wxEmptyString;
894
895 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
896 };
897
898
899 struct FIGURE : PARSER
900 {
904 SHAPE Shape; //< Uses the component's coordinate frame if within a component
905 //< definition, otherwise uses the design's coordinate frame.
906 GROUP_ID GroupID = wxEmptyString;
909 bool Fixed = false;
910 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
911
912 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
913 };
914
915
916 struct TEXT : PARSER
917 {
919 wxString Text; //TODO: Need to lex/parse to identify design fields and hyperlinks
923 long OrientAngle = 0;
924 bool Mirror = false;
925 bool Fixed = false;
934 GROUP_ID GroupID = wxEmptyString;
936
937 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
938 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext, bool aParseFields );
939 };
940
941
942 struct SYMDEF : PARSER
943 {
945 wxString ReferenceName;
947 wxString Alternate;
951 bool Stub = false;
959
960 std::map<FIGURE_ID, FIGURE> Figures;
961 std::map<TEXT_ID, TEXT> Texts;
962 std::map<ATTRIBUTE_ID, TEXT_LOCATION> TextLocations;
965 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
967
968 wxString BuildLibName() const;
969 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
970 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
971 };
972
973
974 struct PART : PARSER
975 {
976 static CADSTAR_PIN_TYPE GetPinType( XNODE* aNode );
977
979 {
980 struct GATE : PARSER
981 {
983 wxString Name;
984 wxString Alternate;
985 long PinCount;
986
987 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
988 };
989
990
991 struct PIN : PARSER
992 {
994
995 wxString Identifier = wxEmptyString;
1000 wxString Name = wxEmptyString;
1005 wxString Label = wxEmptyString;
1020 wxString Signal = wxEmptyString;
1024
1025 CADSTAR_PIN_TYPE Type = CADSTAR_PIN_TYPE::UNCOMMITTED;
1026
1033 CADSTAR_PIN_POSITION::TOP_RIGHT;
1036
1037 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1038 };
1039
1040
1042 {
1043 std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1046
1047 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1048 };
1049
1050
1052 {
1053 std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1055
1056 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1057 };
1058
1059
1061 {
1062 wxString GateName =
1063 wxEmptyString;
1066
1067 bool External = false;
1074
1075 std::vector<SWAP_GATE> SwapGates;
1080
1081 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1082 };
1083
1084 wxString Name;
1086 false;
1090
1098
1099 std::map<GATE_ID, GATE> GateSymbols;
1100 std::map<PART_DEFINITION_PIN_ID, PIN> Pins;
1101 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1105 std::vector<PIN_EQUIVALENCE> PinEquivalences;
1106 std::vector<SWAP_GROUP> SwapGroups;
1107
1108 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1109 };
1110
1111
1113 {
1115 wxString Name = wxEmptyString;
1116 CADSTAR_PIN_TYPE Type = CADSTAR_PIN_TYPE::UNCOMMITTED;
1117 wxString Identifier = wxEmptyString;
1118
1119 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1120 };
1121
1122
1124 wxString Name;
1127 std::map<PART_PIN_ID, PART_PIN> PartPins;
1132
1133 bool HidePinNames = false;
1135
1136 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1140
1141 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1142 };
1143
1144
1145 struct PARTS : PARSER
1146 {
1147 std::map<PART_ID, PART> PartDefinitions;
1148
1149 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1150 };
1151
1152
1153 struct NET : PARSER
1154 {
1156 {
1160 GROUP_ID GroupID = wxEmptyString;
1163 bool Fixed = false;
1164
1165 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1166 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1167 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1168 };
1169
1170
1172 {
1176
1177 bool Fixed = false;
1178 bool Hidden = false;
1179 GROUP_ID GroupID = wxEmptyString;
1181
1182 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1185 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1186 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1187
1188 virtual ~CONNECTION() {}
1189 };
1190
1192 ROUTECODE_ID RouteCodeID = wxEmptyString;
1195 wxString Name = wxEmptyString;
1197 bool Highlight = false;
1198
1199 std::map<NETELEMENT_ID, JUNCTION> Junctions;
1200 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1201
1203 wxEmptyString;
1206 wxEmptyString;
1208
1209 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1210 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1211 };
1212
1213
1215 {
1217
1225
1226 GROUP_ID GroupID = wxEmptyString;
1228 long OrientAngle = 0;
1229 bool Mirror = false;
1230 bool Fixed = false;
1232
1237
1238 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1239
1240 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1241 };
1242
1243
1245 {
1247 bool IsVisible = true;
1248
1249 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1250 };
1251
1252
1254 {
1257 bool IsVisible = true;
1258 bool IsPickable = true;
1259
1260 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1261 };
1262
1263
1265 {
1267 std::map<ATTRIBUTE_ID, ATTRCOL> AttributeColors;
1268
1269 bool IsVisible = true; // unclear what this represents - maybe all attributes are hidden?
1270
1271 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1272 };
1273
1274
1276 {
1278 bool IsVisible = true;
1279 bool IsPickable = true;
1280
1281 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1282 };
1283
1285 // HELPER FUNCTIONS: //
1287
1288
1289 static void InsertAttributeAtEnd( XNODE* aNode, wxString aValue );
1290
1302 static XNODE* LoadArchiveFile( const wxString& aFileName, const wxString& aFileTypeIdentifier,
1303 PROGRESS_REPORTER* aProgressReporter = nullptr );
1304
1310 static bool IsValidAttribute( wxXmlAttribute* aAttribute );
1311
1320 static wxString GetXmlAttributeIDString(
1321 XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1322
1331 static long GetXmlAttributeIDLong( XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1332
1338 static void CheckNoChildNodes( XNODE* aNode );
1339
1345 static void CheckNoNextNodes( XNODE* aNode );
1346
1353 static void ParseChildEValue( XNODE* aNode, PARSER_CONTEXT* aContext, EVALUE& aValueToParse );
1354
1367 static std::vector<POINT> ParseAllChildPoints( XNODE* aNode, PARSER_CONTEXT* aContext,
1368 bool aTestAllChildNodes = false, int aExpectedNumPoints = UNDEFINED_VALUE );
1369
1381 static std::vector<VERTEX> ParseAllChildVertices(
1382 XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
1383
1395 static std::vector<CUTOUT> ParseAllChildCutouts(
1396 XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
1397
1398 static long GetNumberOfChildNodes( XNODE* aNode );
1399
1400 static long GetNumberOfStepsForReporting( XNODE* aRootNode,
1401 std::vector<wxString> aSubNodeChildrenToCount );
1402
1403
1404 static wxString EscapeFieldText( const wxString& aFieldText )
1405 {
1406 wxString ret = aFieldText;
1407 ret.Replace( wxT( "\n" ), wxT( "\\n" ) );
1408 ret.Replace( wxT( "\r" ), wxT( "\\r" ) );
1409 ret.Replace( wxT( "\t" ), wxT( "\\t" ) );
1410
1411 return ret;
1412 }
1413
1419 static wxString HandleTextOverbar( wxString aCadstarString );
1420
1426 static void FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem );
1427
1428 static wxString generateLibName( const wxString& aRefName, const wxString& aAlternateName );
1429
1430
1431protected:
1432 void checkPoint();
1433
1435 PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
1436
1437
1438}; // class CADSTAR_ARCHIVE_PARSER
1439
1440#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)
Corrects the position of a text element that had NO_ALIGNMENT in CADSTAR.
static ANGUNITS ParseAngunits(XNODE *aNode)
long PART_DEFINITION_PIN_ID
Pin identifier in the part definition.
@ 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 cancelled.
static bool IsValidAttribute(wxXmlAttribute *aAttribute)
static READABILITY ParseReadability(XNODE *aNode)
static std::vector< POINT > ParseAllChildPoints(XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false, int aExpectedNumPoints=UNDEFINED_VALUE)
if no children are present, it just returns an empty vector (without throwing an exception)
@ 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:83
A progress reporter interface for use in multi-threaded environments.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
Hold an XML or S-expression element.
Definition: xnode.h:44
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< ATTRIBUTE_ID, ATTRCOL > AttributeColors
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
JUSTIFICATION Justification
Note: Justification has no effect on single lines of text.
ALIGNMENT Alignment
In CADSTAR The default alignment for a TEXT object (when "(No Alignment()" is selected) Bottom Left o...
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool HasLocation
Flag to know if this ATTRIBUTE_VALUE has a location i.e.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
NOTE from CADSTAR help: To convert a Part Definition Attribute into a hyperlink, prefix the attribute...
std::vector< COLUMNWIDTH > ColumnWidths
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool NoTransfer
True="All Design Types", False="Current Design Type" "All Design Types" Description from CADSTAR Help...
std::vector< COLUMNORDER > ColumnOrders
wxString Name
Parenthesis aren't permitted in user attributes in CADSTAR.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< SPACING_CLASS_ID, SPCCLASSNAME > SpacingClassNames
std::map< LINECODE_ID, LINECODE > LineCodes
std::map< NETCLASS_ID, CADSTAR_NETCLASS > NetClasses
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
std::map< HATCHCODE_ID, HATCHCODE > HatchCodes
std::map< ATTRIBUTE_ID, ATTRNAME > AttributeNames
std::map< ROUTECODE_ID, ROUTECODE > RouteCodes
std::map< TEXTCODE_ID, TEXTCODE > TextCodes
Represents a cutout in a closed shape (e.g.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
long ScaleRatioNumerator
Documentation symbols can be arbitrarily scaled when added to a design.
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
long ScaleRatioDenominator
Documentation symbols can be arbitrarily scaled when added to a design.
POINT Origin
Origin of the component (this is used as the reference point when placing the component in the design...
GROUP_ID GroupID
If not empty, this component is part of a group.
LAYER_ID LayerID
Move all objects in the Symdef to this layer.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
SYMDEF_ID SymdefID
Normally documentation symbols only have TEXT, FIGURE and TEXT_LOCATION objects which are all drawn o...
Represents a floating value in E notation.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
GROUP_ID GroupID
If not empty, this FIGURE is part of a group.
SWAP_RULE SwapRule
Only applicable to Figures in Components.
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
long Modifier2
It seems this is always 0 regardless of settings.
bool KerningPairs
From CADSTAR Help: "Kerning Pairs is for causing the system to automatically red...
long Modifier1
It seems this is related to weight. 400=Normal, 700=Bold.
long Version
Archive version number (e.g.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
long SomeInt
It is unclear what this parameter is used for.
GRID ScreenGrid
From CADSTAR Help: "There is one Screen Grid, which is visible as dots on the screen.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::vector< GRID > UserGrids
List of predefined grids created by the user.
static bool IsGrid(XNODE *aNode)
long Param1
Either Units or X step, depending on Type (see GRID_TYPE for more details)
long Param2
Either Divisor or Y step, depending on Type (see GRID_TYPE for more details)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
GROUP_ID GroupID
If not empty, this GROUP is part of another GROUP.
bool Transfer
If true, the group is transferred to PCB.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
It is possible to add attributes solely to a particular connection.
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
GROUP_ID GroupID
If not empty, this connection is part of a group.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
GROUP_ID GroupID
If not empty, this JUCTION is part of a group.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
NETELEMENT_ID ID
First character is "J".
ROUTECODE_ID RouteCodeID
"NETCODE" subnode
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
wxString Name
This is undefined (wxEmptyString) if the net is unnamed.
std::map< NETELEMENT_ID, JUNCTION > Junctions
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
NETCLASS_ID NetClassID
The net might not have a net class, in which case it will be wxEmptyString ("NETCLASSREF" subnode)
SPACING_CLASS_ID SpacingClassID
The net might not have a spacing class, in which case it will be wxEmptyString ("SPACINGCLASS" subnod...
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
long SignalNum
This is undefined if the net has been given a name.
std::map< TEXT_FIELD_NAME, wxString > TextFieldToValuesMap
Values for the text field elements used in the CADSTAR design extracted from the text element instanc...
std::map< wxString, wxString > FilenamesToTextMap
CADSTAR doesn't have user defined text fields but does allow loading text from a file.
std::map< wxString, wxString > TextToHyperlinksMap
KiCad doesn't support hyperlinks but we use this map to display warning messages after import.
std::set< TEXT_FIELD_NAME > InconsistentTextFields
Text fields need to be updated in CADSTAR and it is possible that they are not consistent across text...
std::function< void()> CheckPointCallback
Callback function to report progress.
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext)=0
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< PART_ID, PART > PartDefinitions
long PinCount
Number of pins (terminals) in the symbol.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString Alternate
Symbol alternate name in the symbol library.
wxString Name
Symbol name in the symbol library.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::vector< PART_DEFINITION_PIN_ID > PinIDs
All the pins in this vector are equivalent and can be swapped with each other.
wxString Label
This Can be empty (subnode= "PINLABEL") From CADSTAR Help: "Pin Labels are an optional replacement fo...
long Load
The electrical current expected on the pin (It is unclear what the units are, but only accepted value...
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?
Represents a point in x,y coordinates.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
References an element from a design reuse block.
wxString ItemReference
For Components, this references the designator in the reuse file.
bool IsEmpty()
Determines if this is empty (i.e. no design reuse associated)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString FileName
Filename of the reuse block (usually a .pcb). Used for reloading.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::vector< ROUTEREASSIGN > RouteReassigns
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
UNITS Units
Units to display for linear dimensions.
long 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, double aAccuracy) const
SHAPE_LINE_CHAIN OutlineAsChain(const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, double aAccuracy) const
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString HatchCodeID
Only Applicable for HATCHED Type.
std::vector< CUTOUT > Cutouts
Not Applicable to OPENSHAPE Type.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< FIGURE_ID, FIGURE > Figures
std::map< ATTRIBUTE_ID, TEXT_LOCATION > TextLocations
This contains location of any attributes, including designator position.
POINT Origin
Origin of the component (this is used as the reference point when placing the component in the design...
wxString Alternate
This is in addition to ReferenceName.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
bool Stub
When the CADSTAR Archive file is exported without the component library, if components on the board a...
wxString ReferenceName
This is the name which identifies the symbol in the library Multiple components may exist with the sa...
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
These attributes might also have a location.
long Version
Version is a sequential integer number to identify discrepancies between the library and the design.
long Width
Defaults to 0 if using system fonts or, if using CADSTAR font, default to equal height (1:1 aspect ra...
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
Corresponds to CADSTAR "origin".
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
ALIGNMENT Alignment
In CADSTAR The default alignment for a TEXT object (when "(No Alignment()" is selected) Bottom Left o...
JUSTIFICATION Justification
Note: Justification has no effect on single lines of text.
GROUP_ID GroupID
If not empty, this FIGURE is part of a group.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
virtual 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.
VERTEX(VERTEX_TYPE aType=VERTEX_TYPE::POINT, POINT aEnd=POINT(), POINT aCenter=POINT())
SHAPE_ARC BuildArc(const VECTOR2I &aPrevPoint, const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback) const
void AppendToChain(SHAPE_LINE_CHAIN *aChainToAppendTo, const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, double aAccuracy) const
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
VECTOR2< int > VECTOR2I
Definition: vector2d.h:602