KiCad PCB EDA Suite
cadstar_archive_parser.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020-2021 Roberto Fernandez Bautista <[email protected]>
5 * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
26#ifndef CADSTAR_ARCHIVE_PARSER_H_
27#define CADSTAR_ARCHIVE_PARSER_H_
28
29#include <richio.h>
30#include <wx/gdicmn.h>
31#include <functional>
32#include <map>
33#include <set>
34#include <vector>
35#include <xnode.h>
36
37// THROW_IO_ERROR definitions to ensure consistent wording is used in the error messages
38
39#define THROW_MISSING_NODE_IO_ERROR( nodename, location ) \
40 THROW_IO_ERROR( wxString::Format( _( "Missing node '%s' in '%s'" ), nodename, location ) )
41
42#define THROW_UNKNOWN_NODE_IO_ERROR( nodename, location ) \
43 THROW_IO_ERROR( wxString::Format( _( "Unknown node '%s' in '%s'" ), nodename, location ) )
44
45#define THROW_MISSING_PARAMETER_IO_ERROR( param, location ) \
46 THROW_IO_ERROR( wxString::Format( _( "Missing Parameter '%s' in '%s'" ), param, location ) )
47
48#define THROW_UNKNOWN_PARAMETER_IO_ERROR( param, location ) \
49 THROW_IO_ERROR( wxString::Format( _( "Unknown Parameter '%s' in '%s'" ), param, location ) )
50
51#define THROW_PARSING_IO_ERROR( param, location ) \
52 THROW_IO_ERROR( wxString::Format( _( "Unable to parse '%s' in '%s'" ), param, location ) )
53
54//=================================
55// MACRO DEFINITIONS
56//=================================
57#define UNDEFINED_LAYER_ID ( LAYER_ID ) wxEmptyString
58
59
63#define COMPONENT_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME__" )
64
69#define COMPONENT_NAME_2_ATTRID ( ATTRIBUTE_ID ) wxT( "__COMPONENT_NAME_2__" )
70
74#define SYMBOL_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__SYMBOL_NAME__" )
75#define LINK_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__LINK_ORIGIN__" )
76#define SIGNALNAME_ORIGIN_ATTRID ( ATTRIBUTE_ID ) wxT( "__SIGNALNAME_ORIGIN__" )
77#define PART_NAME_ATTRID ( ATTRIBUTE_ID ) wxT( "__PART_NAME__" )
78
79class EDA_TEXT;
80class wxXmlAttribute;
82
87{
88public:
90
91
92 typedef wxString LINECODE_ID;
93 typedef wxString HATCHCODE_ID;
94 typedef wxString ROUTECODE_ID;
95 typedef wxString NETCLASS_ID;
96 typedef wxString SPACING_CLASS_ID;
97 typedef wxString TEXTCODE_ID;
98 typedef wxString LAYER_ID;
99 typedef wxString VARIANT_ID;
100 typedef wxString ATTRIBUTE_ID;
101 typedef wxString SYMDEF_ID;
102 typedef wxString PART_ID;
103 typedef wxString GATE_ID;
104 typedef long TERMINAL_ID;
106 typedef long PART_PIN_ID;
107 typedef wxString TEXT_ID;
108 typedef wxString FIGURE_ID;
109 typedef wxString GROUP_ID;
110 typedef wxString REUSEBLOCK_ID;
111 typedef wxString NET_ID;
112 typedef wxString NETELEMENT_ID;
113 typedef wxString DOCUMENTATION_SYMBOL_ID;
114 typedef wxString COLOR_ID;
115
116 static const long UNDEFINED_VALUE = -1;
117
129 static const double TXT_HEIGHT_RATIO;
130
136 {
137 DESIGN_TITLE,
138 SHORT_JOBNAME,
139 LONG_JOBNAME,
140 NUM_OF_SHEETS,
141 SHEET_NUMBER,
143 VARIANT_NAME,
144 VARIANT_DESCRIPTION,
145 REG_USER,
146 COMPANY_NAME,
147 CURRENT_USER,
148 DATE,
149 TIME,
150 MACHINE_NAME,
151 FROM_FILE,
152 DISTANCE,
153 UNITS_SHORT,
154 UNITS_ABBREV,
155 UNITS_FULL,
156 HYPERLINK,
157 NONE
158 };
159
164 static const std::map<TEXT_FIELD_NAME, wxString> CADSTAR_TO_KICAD_FIELDS;
165
166
168 {
174 std::map<wxString, wxString> FilenamesToTextMap;
175
180 std::map<wxString, wxString> TextToHyperlinksMap;
181
186 std::map<TEXT_FIELD_NAME, wxString> TextFieldToValuesMap;
187
192 std::set<TEXT_FIELD_NAME> InconsistentTextFields;
193
197 std::function<void()> CheckPointCallback = []() {};
198 };
199
207 static wxString ParseTextFields( const wxString& aTextString, PARSER_CONTEXT* aParserContext );
208
209
210 struct PARSER
211 {
212 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) = 0;
213
214 virtual ~PARSER() {};
215 };
216
217
218 struct FORMAT : PARSER
219 {
220 wxString Type;
221 long SomeInt;
222 long Version;
225 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
226 };
227
228
230 {
231 long Year;
232 long Month;
233 long Day;
234 long Hour;
235 long Minute;
236 long Second;
237
238 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
239 };
240
241 //Note: there are possibly several other resolutions, but HUNDREDTH MICRON is only one known
242 enum class RESOLUTION
243 {
244 HUNDREDTH_MICRON
245 };
246
247
248 struct HEADER : PARSER
249 {
251 wxString JobFile;
252 wxString JobTitle;
253 wxString Generator;
256
257 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
258 };
259
260
261 struct VARIANT : PARSER
262 {
263 VARIANT_ID ID = wxEmptyString;
264 VARIANT_ID ParentID = wxEmptyString;
265 wxString Name = wxEmptyString;
266 wxString Description = wxEmptyString;
267
268 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
269 };
270
271
273 {
274 std::map<VARIANT_ID, VARIANT> Variants;
275
276 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
277 };
278
279
280 enum class LINESTYLE
281 {
282 SOLID,
283 DASH,
284 DASHDOT,
286 DOT
287 };
288
289
291 {
293 wxString Name;
294 long Width;
296
297 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
298 };
299
300
301 struct HATCH : PARSER
302 {
303 long Step;
306
307 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
308 };
309
310
312 {
314 wxString Name;
315 std::vector<HATCH> Hatches;
316
317 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
318 };
319
320
321 static const long FONT_NORMAL = 400;
322 static const long FONT_BOLD = 700;
323
324
325 struct FONT : PARSER
326 {
327 wxString Name = wxT( "CADSTAR" );
329 long Modifier2 = 0;
331 false;
334 bool Italic = false;
335
336 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
337 };
338
339
341 {
343 wxString Name;
345 long Height;
346 long Width;
350
351 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
352 };
353
354
356 {
362
363 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
364 };
365
366
368 {
370 wxString Name;
375
376 std::vector<ROUTEREASSIGN> RouteReassigns;
377
378 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
379 };
380
381
385 struct EVALUE : PARSER
386 {
387 long Base = 0;
388 long Exponent = 0;
389
390 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
391 double GetDouble();
392 };
393
397 struct POINT : wxPoint, PARSER
398 {
400 {
401 }
402
403 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
404 };
405
406
408 {
411
412 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
413 };
414
415
416 enum class VERTEX_TYPE
417 {
418 POINT,
419 CLOCKWISE_ARC,
420 CLOCKWISE_SEMICIRCLE,
421 ANTICLOCKWISE_ARC,
422 ANTICLOCKWISE_SEMICIRCLE
423 };
424
429 struct VERTEX : PARSER
430 {
434
435 static bool IsVertex( XNODE* aNode );
436 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
437 };
438
442 struct CUTOUT : PARSER
443 {
444 std::vector<VERTEX> Vertices;
445
446 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
447 };
448
449
450 enum class SHAPE_TYPE
451 {
452 OPENSHAPE,
453 OUTLINE,
454 SOLID,
455 HATCHED
456 };
457
458
459 struct SHAPE : PARSER
460 {
462 std::vector<VERTEX> Vertices;
463 std::vector<CUTOUT> Cutouts;
464 wxString HatchCodeID;
465
466 static bool IsShape( XNODE* aNode );
467 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
468 };
469
470
471 enum class UNITS
472 {
473 DESIGN,
474 THOU,
475 INCH,
476 MICROMETRE,
477 MM,
479 METER
480 };
481
482
483 static UNITS ParseUnits( XNODE* aNode );
484
485
486 enum class ANGUNITS
487 {
488 DEGREES,
489 RADIANS
490 };
491
492
493 static ANGUNITS ParseAngunits( XNODE* aNode );
494
495
496 enum class GRID_TYPE
497 {
498 FRACTIONALGRID,
500 STEPGRID
501 };
502
503
504 struct GRID : PARSER
505 {
507 wxString Name;
508 long Param1;
510 long Param2;
512
513 static bool IsGrid( XNODE* aNode );
514 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
515 };
516
517
518 struct GRIDS : PARSER
519 {
529 std::vector<GRID> UserGrids;
530
531 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
532 };
533
534
536 {
545 bool AllowBarredText = false;
547
549 std::pair<POINT, POINT> DesignArea;
552
553 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
554 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
555 };
556
557
558
576 enum class ALIGNMENT
577 {
578 NO_ALIGNMENT,
579 TOPLEFT,
580 TOPCENTER,
581 TOPRIGHT,
582 CENTERLEFT,
583 CENTERCENTER,
584 CENTERRIGHT,
585 BOTTOMLEFT,
586 BOTTOMCENTER,
587 BOTTOMRIGHT
588 };
589
590
591 static ALIGNMENT ParseAlignment( XNODE* aNode );
592
602 enum class JUSTIFICATION
603 {
604 LEFT,
605 CENTER,
606 RIGHT
607 };
608
609
610 static JUSTIFICATION ParseJustification( XNODE* aNode );
611
620 enum class READABILITY
621 {
622 BOTTOM_TO_TOP,
623 TOP_TO_BOTTOM
624 };
625
626
627 static READABILITY ParseReadability( XNODE* aNode );
628
629
630 enum class ATTROWNER
631 {
632 ALL_ITEMS,
633 AREA,
634 BOARD,
635 COMPONENT,
636 CONNECTION,
637 COPPER,
638 DOCSYMBOL,
639 FIGURE,
640 NET,
641 NETCLASS,
642 PART,
643 PART_DEFINITION,
644 PIN,
645 SIGNALREF,
646 SYMBOL,
647 SYMDEF,
648 TEMPLATE,
650 };
651
652
653 enum class ATTRUSAGE
654 {
655 BOTH,
657 COMPONENT,
658 PART_DEFINITION,
660 PART_LIBRARY,
661 SYMBOL,
663 UNDEFINED
666 };
667
668
670 {
674 long OrientAngle = 0;
675 bool Mirror = false;
676 bool Fixed = false;
684
685 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
686 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
687 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
688 };
689
690
696 {
698 {
699 long ID;
700 long Order;
701
702 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
703 };
704
705
707 {
708 long ID;
709 long Width;
710
711 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
712 };
713
715 wxString Name;
721 bool NoTransfer = false;
728 std::vector<COLUMNORDER> ColumnOrders;
729 std::vector<COLUMNWIDTH> ColumnWidths;
730 bool ColumnInvisible = false;
731
732 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
733 };
734
735
737 {
739 wxString Value;
740 bool ReadOnly = false;
741 bool HasLocation = false;
744
745 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
746 };
747
748
755 {
757 {
758 // The default alignment for TEXT_LOCATION (when "NO_ALIGNMENT" is selected) is
759 // Bottom left, matching CADSTAR's default behaviour
761 }
763
764 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
765 };
766
767
769 {
771 wxString Name;
772 std::vector<ATTRIBUTE_VALUE> Attributes;
773
774 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
775 };
776
777
779 {
781 wxString Name;
782
783 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
784 };
785
786
788 {
789 std::map<LINECODE_ID, LINECODE> LineCodes;
790 std::map<HATCHCODE_ID, HATCHCODE> HatchCodes;
791 std::map<TEXTCODE_ID, TEXTCODE> TextCodes;
792 std::map<ROUTECODE_ID, ROUTECODE> RouteCodes;
793 std::map<ATTRIBUTE_ID, ATTRNAME> AttributeNames;
794 std::map<NETCLASS_ID, CADSTAR_NETCLASS> NetClasses;
795 std::map<SPACING_CLASS_ID, SPCCLASSNAME> SpacingClassNames;
796
797 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
798 };
799
810 enum class SWAP_RULE
811 {
812 NO_SWAP,
813 USE_SWAP_LAYER,
814 BOTH
815 };
816
817
818 static SWAP_RULE ParseSwapRule( XNODE* aNode );
819
820
822 {
824 wxString Name;
825 wxString FileName;
826 bool Mirror = false;
827 long OrientAngle = 0;
828
829 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
830 };
831
832
837 {
839 wxString ItemReference = wxEmptyString;
843
844 bool IsEmpty();
845 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
846 };
847
848
849 struct GROUP : PARSER
850 {
852 wxString Name;
853 bool Fixed = false;
854 bool Transfer = false;
855 GROUP_ID GroupID = wxEmptyString;
858
859 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
860 };
861
862
863 struct FIGURE : PARSER
864 {
868 SHAPE Shape; //< Uses the component's coordinate frame if within a component
869 //< definition, otherwise uses the design's coordinate frame.
870 GROUP_ID GroupID = wxEmptyString;
873 bool Fixed = false;
874 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
875
876 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
877 };
878
879
880 struct TEXT : PARSER
881 {
883 wxString Text; //TODO: Need to lex/parse to identify design fields and hyperlinks
887 long OrientAngle = 0;
888 bool Mirror = false;
889 bool Fixed = false;
898 GROUP_ID GroupID = wxEmptyString;
900
901 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
902 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext, bool aParseFields );
903 };
904
905
906 struct SYMDEF : PARSER
907 {
909 wxString ReferenceName;
911 wxString Alternate;
915 bool Stub = false;
923
924 std::map<FIGURE_ID, FIGURE> Figures;
925 std::map<TEXT_ID, TEXT> Texts;
926 std::map<ATTRIBUTE_ID, TEXT_LOCATION> TextLocations;
929 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
931
932 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
933 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
934 };
935
936
937 struct PART : PARSER
938 {
939 enum class PIN_TYPE
940 {
941 UNCOMMITTED,
942 INPUT,
943 OUTPUT_OR,
944 OUTPUT_NOT_OR,
945 OUTPUT_NOT_NORM_OR,
946 POWER,
947 GROUND,
948 TRISTATE_BIDIR,
949 TRISTATE_INPUT,
950 TRISTATE_DRIVER
951 };
952
953
954 static PIN_TYPE GetPinType( XNODE* aNode );
955
956
958 {
959 struct GATE : PARSER
960 {
962 wxString Name;
963 wxString Alternate;
964 long PinCount;
965
966 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
967 };
968
969
970 struct PIN : PARSER
971 {
975 enum class POSITION
976 {
977 TOP_RIGHT = 0,
978 TOP_LEFT = 1,
979 BOTTOM_LEFT = 2,
980 BOTTOM_RIGHT = 3
981 };
982
984
985 wxString Identifier = wxEmptyString;
990 wxString Name = wxEmptyString;
995 wxString Label = wxEmptyString;
1010 wxString Signal = wxEmptyString;
1023
1024 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1025 };
1026
1027
1029 {
1030 std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1033
1034 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1035 };
1036
1037
1039 {
1040 std::vector<PART_DEFINITION_PIN_ID> PinIDs;
1042
1043 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1044 };
1045
1046
1048 {
1049 wxString GateName =
1050 wxEmptyString;
1053
1054 bool External = false;
1061
1062 std::vector<SWAP_GATE> SwapGates;
1067
1068 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1069 };
1070
1071 wxString Name;
1073 false;
1077
1085
1086 std::map<GATE_ID, GATE> GateSymbols;
1087 std::map<PART_DEFINITION_PIN_ID, PIN> Pins;
1088 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1092 std::vector<PIN_EQUIVALENCE> PinEquivalences;
1093 std::vector<SWAP_GROUP> SwapGroups;
1094
1095 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1096 };
1097
1098
1100 {
1102 wxString Name = wxEmptyString;
1104 wxString Identifier = wxEmptyString;
1105
1106 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1107 };
1108
1109
1111 wxString Name;
1114 std::map<PART_PIN_ID, PART_PIN> PartPins;
1119
1120 bool HidePinNames = false;
1122
1123 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1127
1128 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1129 };
1130
1131
1132 struct PARTS : PARSER
1133 {
1134 std::map<PART_ID, PART> PartDefinitions;
1135
1136 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1137 };
1138
1139
1140 struct NET : PARSER
1141 {
1143 {
1147 GROUP_ID GroupID = wxEmptyString;
1150 bool Fixed = false;
1151
1152 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1153 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1154 virtual void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1155 };
1156
1157
1159 {
1163
1164 bool Fixed = false;
1165 bool Hidden = false;
1166 GROUP_ID GroupID = wxEmptyString;
1168
1169 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1172 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1173 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1174
1175 virtual ~CONNECTION() {}
1176 };
1177
1179 ROUTECODE_ID RouteCodeID = wxEmptyString;
1182 wxString Name = wxEmptyString;
1184 bool Highlight = false;
1185
1186 std::map<NETELEMENT_ID, JUNCTION> Junctions;
1187 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1188
1190 wxEmptyString;
1193 wxEmptyString;
1195
1196 void ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext );
1197 bool ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext );
1198 };
1199
1200
1202 {
1204
1212
1213 GROUP_ID GroupID = wxEmptyString;
1215 long OrientAngle = 0;
1216 bool Mirror = false;
1217 bool Fixed = false;
1219
1224
1225 std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE> AttributeValues;
1226
1227 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1228 };
1229
1230
1232 {
1234 bool IsVisible = true;
1235
1236 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1237 };
1238
1239
1241 {
1244 bool IsVisible = true;
1245 bool IsPickable = true;
1246
1247 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1248 };
1249
1250
1252 {
1254 std::map<ATTRIBUTE_ID, ATTRCOL> AttributeColors;
1255
1256 bool IsVisible = true; // unclear what this represents - maybe all attributes are hidden?
1257
1258 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1259 };
1260
1261
1263 {
1265 bool IsVisible = true;
1266 bool IsPickable = true;
1267
1268 void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override;
1269 };
1270
1272 // HELPER FUNCTIONS: //
1274
1275
1276 static void InsertAttributeAtEnd( XNODE* aNode, wxString aValue );
1277
1289 static XNODE* LoadArchiveFile( const wxString& aFileName, const wxString& aFileTypeIdentifier,
1290 PROGRESS_REPORTER* aProgressReporter = nullptr );
1291
1297 static bool IsValidAttribute( wxXmlAttribute* aAttribute );
1298
1307 static wxString GetXmlAttributeIDString(
1308 XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1309
1318 static long GetXmlAttributeIDLong( XNODE* aNode, unsigned int aID, bool aIsRequired = true );
1319
1325 static void CheckNoChildNodes( XNODE* aNode );
1326
1332 static void CheckNoNextNodes( XNODE* aNode );
1333
1340 static void ParseChildEValue( XNODE* aNode, PARSER_CONTEXT* aContext, EVALUE& aValueToParse );
1341
1354 static std::vector<POINT> ParseAllChildPoints( XNODE* aNode, PARSER_CONTEXT* aContext,
1355 bool aTestAllChildNodes = false, int aExpectedNumPoints = UNDEFINED_VALUE );
1356
1368 static std::vector<VERTEX> ParseAllChildVertices(
1369 XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
1370
1382 static std::vector<CUTOUT> ParseAllChildCutouts(
1383 XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
1384
1385 static long GetNumberOfChildNodes( XNODE* aNode );
1386
1387 static long GetNumberOfStepsForReporting( XNODE* aRootNode,
1388 std::vector<wxString> aSubNodeChildrenToCount );
1389
1395 static wxString HandleTextOverbar( wxString aCadstarString );
1396
1402 static void FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem );
1403
1404 static wxString generateLibName( const wxString& aRefName, const wxString& aAlternateName )
1405 {
1406 return aRefName
1407 + ( ( aAlternateName.size() > 0 ) ? ( wxT( " (" ) + aAlternateName + wxT( ")" ) )
1408 : wxT( "" ) );
1409 }
1410
1411
1412protected:
1413 void checkPoint();
1414
1416 PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
1417
1418
1419}; // class CADSTAR_ARCHIVE_PARSER
1420
1421#endif // CADSTAR_ARCHIVE_PARSER_H_
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
Helper functions and common structures for CADSTAR PCB and Schematic archive files.
READABILITY
Sets the readability direction of text.
@ BOTTOM_TO_TOP
When text is vertical, show it rotated 90 degrees anticlockwise.
static wxString generateLibName(const wxString &aRefName, const wxString &aAlternateName)
SWAP_RULE
Corresponds to "Display when" Item property.
@ BOTH
Always display (Mirrored and Unmirrored)
static UNITS ParseUnits(XNODE *aNode)
static ALIGNMENT ParseAlignment(XNODE *aNode)
static const std::map< TEXT_FIELD_NAME, wxString > CADSTAR_TO_KICAD_FIELDS
Map between CADSTAR fields and KiCad text variables.
long TERMINAL_ID
Terminal is the pin identifier in the schematic.
TEXT_FIELD_NAME
These are special fields in text objects enclosed between the tokens '<@' and '>' such as <@[FIELD_NA...
static SWAP_RULE ParseSwapRule(XNODE *aNode)
ALIGNMENT
From CADSTAR Help: "Text Alignment enables you to define the position of an alignment origin for all ...
@ NO_ALIGNMENT
NO_ALIGNMENT has different meaning depending on the object type.
static const long UNDEFINED_VALUE
static void CheckNoNextNodes(XNODE *aNode)
static std::vector< CUTOUT > ParseAllChildCutouts(XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false)
if no children are present, it just returns an empty vector (without throwing an exception)
static XNODE * LoadArchiveFile(const wxString &aFileName, const wxString &aFileTypeIdentifier, PROGRESS_REPORTER *aProgressReporter=nullptr)
Reads a CADSTAR Archive file (S-parameter format)
static JUSTIFICATION ParseJustification(XNODE *aNode)
static wxString ParseTextFields(const wxString &aTextString, PARSER_CONTEXT *aParserContext)
Replaces CADSTAR fields for the equivalent in KiCad and stores the field values in aParserContext.
@ UNDEFINED
Note: It seems that some attribute have no "ATTRUSAGE" defined.
wxString LAYER_ID
ID of a Sheet (if schematic) or board Layer (if PCB)
static std::vector< VERTEX > ParseAllChildVertices(XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false)
if no children are present, it just returns an empty vector (without throwing an exception)
static void FixTextPositionNoAlignment(EDA_TEXT *aKiCadTextItem)
Corrects the position of a text element that had NO_ALIGNMENT in CADSTAR.
static ANGUNITS ParseAngunits(XNODE *aNode)
long PART_DEFINITION_PIN_ID
Pin identifier in the part definition.
static const double TXT_HEIGHT_RATIO
CADSTAR fonts are drawn on a 24x24 integer matrix, where the each axis goes from 0 to 24.
static wxString GetXmlAttributeIDString(XNODE *aNode, unsigned int aID, bool aIsRequired=true)
void checkPoint()
Updates m_progressReporter or throws if user cancelled.
static bool IsValidAttribute(wxXmlAttribute *aAttribute)
static READABILITY ParseReadability(XNODE *aNode)
static std::vector< POINT > ParseAllChildPoints(XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false, int aExpectedNumPoints=UNDEFINED_VALUE)
if no children are present, it just returns an empty vector (without throwing an exception)
static wxString HandleTextOverbar(wxString aCadstarString)
Convert a string with CADSTAR overbar characters to equivalent in KiCad.
static void CheckNoChildNodes(XNODE *aNode)
static long GetXmlAttributeIDLong(XNODE *aNode, unsigned int aID, bool aIsRequired=true)
JUSTIFICATION
From CADSTAR Help: "Multi Line Text can also be justified as Left, Centre or Right.
static void ParseChildEValue(XNODE *aNode, PARSER_CONTEXT *aContext, EVALUE &aValueToParse)
static long GetNumberOfStepsForReporting(XNODE *aRootNode, std::vector< wxString > aSubNodeChildrenToCount)
long PART_PIN_ID
Pin identifier in the part.
PROGRESS_REPORTER * m_progressReporter
static long GetNumberOfChildNodes(XNODE *aNode)
static void InsertAttributeAtEnd(XNODE *aNode, wxString aValue)
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:85
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:72
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:47
A progress reporter interface for use in multi-threaded environments.
Hold an XML or S-expression element.
Definition: xnode.h:44
@ NONE
Definition: kibis.h:53
@ TESTPOINT
a test point pad
@ INCH
Definition: rs274x.cpp:63
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< ATTRIBUTE_ID, ATTRCOL > AttributeColors
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
JUSTIFICATION Justification
Note: Justification has no effect on single lines of text.
ALIGNMENT Alignment
In CADSTAR The default alignment for a TEXT object (when "(No Alignment()" is selected) Bottom Left o...
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool HasLocation
Flag to know if this ATTRIBUTE_VALUE has a location i.e.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
NOTE from CADSTAR help: To convert a Part Definition Attribute into a hyperlink, prefix the attribute...
std::vector< COLUMNWIDTH > ColumnWidths
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool NoTransfer
True="All Design Types", False="Current Design Type" "All Design Types" Description from CADSTAR Help...
std::vector< COLUMNORDER > ColumnOrders
wxString Name
Parenthesis aren't permitted in user attributes in CADSTAR.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< SPACING_CLASS_ID, SPCCLASSNAME > SpacingClassNames
std::map< LINECODE_ID, LINECODE > LineCodes
std::map< NETCLASS_ID, CADSTAR_NETCLASS > NetClasses
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
std::map< HATCHCODE_ID, HATCHCODE > HatchCodes
std::map< ATTRIBUTE_ID, ATTRNAME > AttributeNames
std::map< ROUTECODE_ID, ROUTECODE > RouteCodes
std::map< TEXTCODE_ID, TEXTCODE > TextCodes
Represents a cutout in a closed shape (e.g.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
long ScaleRatioNumerator
Documentation symbols can be arbitrarily scaled when added to a design.
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
long ScaleRatioDenominator
Documentation symbols can be arbitrarily scaled when added to a design.
POINT Origin
Origin of the component (this is used as the reference point when placing the component in the design...
GROUP_ID GroupID
If not empty, this component is part of a group.
LAYER_ID LayerID
Move all objects in the Symdef to this layer.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
SYMDEF_ID SymdefID
Normally documentation symbols only have TEXT, FIGURE and TEXT_LOCATION objects which are all drawn o...
Represents a floating value in E notation.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
GROUP_ID GroupID
If not empty, this FIGURE is part of a group.
SWAP_RULE SwapRule
Only applicable to Figures in Components.
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
long Modifier2
It seems this is always 0 regardless of settings.
bool KerningPairs
From CADSTAR Help: "Kerning Pairs is for causing the system to automatically red...
long Modifier1
It seems this is related to weight. 400=Normal, 700=Bold.
long Version
Archive version number (e.g.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
long SomeInt
It is unclear what this parameter is used for.
GRID ScreenGrid
From CADSTAR Help: "There is one Screen Grid, which is visible as dots on the screen.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::vector< GRID > UserGrids
List of predefined grids created by the user.
static bool IsGrid(XNODE *aNode)
long Param1
Either Units or X step, depending on Type (see GRID_TYPE for more details)
long Param2
Either Divisor or Y step, depending on Type (see GRID_TYPE for more details)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
GROUP_ID GroupID
If not empty, this GROUP is part of another GROUP.
bool Transfer
If true, the group is transferred to PCB.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
It is possible to add attributes solely to a particular connection.
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
GROUP_ID GroupID
If not empty, this connection is part of a group.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
GROUP_ID GroupID
If not empty, this JUCTION is part of a group.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
NETELEMENT_ID ID
First character is "J".
ROUTECODE_ID RouteCodeID
"NETCODE" subnode
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
wxString Name
This is undefined (wxEmptyString) if the net is unnamed.
std::map< NETELEMENT_ID, JUNCTION > Junctions
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
NETCLASS_ID NetClassID
The net might not have a net class, in which case it will be wxEmptyString ("NETCLASSREF" subnode)
SPACING_CLASS_ID SpacingClassID
The net might not have a spacing class, in which case it will be wxEmptyString ("SPACINGCLASS" subnod...
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
long SignalNum
This is undefined if the net has been given a name.
std::map< TEXT_FIELD_NAME, wxString > TextFieldToValuesMap
Values for the text field elements used in the CADSTAR design extracted from the text element instanc...
std::map< wxString, wxString > FilenamesToTextMap
CADSTAR doesn't have user defined text fields but does allow loading text from a file.
std::map< wxString, wxString > TextToHyperlinksMap
KiCad doesn't support hyperlinks but we use this map to display warning messages after import.
std::set< TEXT_FIELD_NAME > InconsistentTextFields
Text fields need to be updated in CADSTAR and it is possible that they are not consistent across text...
std::function< void()> CheckPointCallback
Callback function to report progress.
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext)=0
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< PART_ID, PART > PartDefinitions
long PinCount
Number of pins (terminals) in the symbol.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString Alternate
Symbol alternate name in the symbol library.
wxString Name
Symbol name in the symbol library.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::vector< PART_DEFINITION_PIN_ID > PinIDs
All the pins in this vector are equivalent and can be swapped with each other.
wxString Label
This Can be empty (subnode= "PINLABEL") From CADSTAR Help: "Pin Labels are an optional replacement fo...
long Load
The electrical current expected on the pin (It is unclear what the units are, but only accepted value...
POSITION
Positioning of pin names can be in one of four quadrants.
TERMINAL_ID TerminalPin
(subnode="PINTERM", param1)
wxString Identifier
This should match a pad identifier in the component footprint subnode="PINIDENTIFIER".
POSITION Position
The pin names will use these positions when the symbol is added to a schematic design subnode="PINPOS...
GATE_ID TerminalGate
(subnode="PINTERM", param0)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString Signal
Usually for Power/Ground pins, (subnode="PINSIGNAL")
< "SWAPGATE" Node name (represents an "Element")
std::vector< PART_DEFINITION_PIN_ID > PinIDs
The pins in this vector describe a "gate".
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::vector< SWAP_GATE > SwapGates
Each of the elements in this vector can be swapped with each other - i.e.
bool External
Determines if this swap group is external (and internal) or internal only.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool HidePinNames
Specifies whether to display the pin names/identifier in the schematic symbol or not.
std::vector< PIN_EQUIVALENCE > PinEquivalences
wxString Name
This name can be different to the PART name.
long MaxPinCount
Optional parameter which is used for specifying the number of electrical pins on the PCB component sy...
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
Some attributes are defined within the part definition, whilst others are defined in the part.
std::map< PART_DEFINITION_PIN_ID, PIN > Pins
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::map< PART_PIN_ID, PART_PIN > PartPins
It is unclear why there are two "Pin" structures in CPA files... PART_PIN seems to be a reduced versi...
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
Some attributes are defined within the part definition, whilst others are defined in the part itself.
@ UNCOMMITTED
Uncommitted pin (default)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static PIN_TYPE GetPinType(XNODE *aNode)
bool HidePinNames
This seems to be a duplicate of DEFINITION::HidePinNames Possibly only used in older file formats?
Represents a point in x,y coordinates.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
References an element from a design reuse block.
wxString ItemReference
For Components, this references the designator in the reuse file.
bool IsEmpty()
Determines if this is empty (i.e. no design reuse associated)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
wxString FileName
Filename of the reuse block (usually a .pcb). Used for reloading.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
std::vector< ROUTEREASSIGN > RouteReassigns
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
UNITS Units
Units to display for linear dimensions.
long InterlineGap
For CADSTAR font only, distance between lines of text, expressed as a percentage of the text height (...
long BarlineGap
For CADSTAR font only, distance between top bar and character, expressed as a percentage of the text ...
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool AllowBarredText
Specifies if barring is allowed in the design.
LONGPOINT DesignRef
Appears to be 0,0 always.
std::pair< POINT, POINT > DesignArea
long AngularPrecision
Number of decimal points to display for angular dimensions.
long UnitDisplPrecision
Number of decimal points to display for linear dimensions.
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
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
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.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override