KiCad PCB EDA Suite
Loading...
Searching...
No Matches
cadstar_archive_parser.cpp
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#include <wx/filename.h>
26#include <wx/log.h>
27#include <wx/xml/xml.h>
28
29#include <dsnlexer.h>
32#include <eda_item.h>
33#include <eda_text.h>
34#include <macros.h>
35#include <progress_reporter.h>
36#include <string_utils.h>
37#include <trigo.h>
38
39// Re-throw a child-node parse failure with the enclosing element added to the message. The
40// leaf error only names the offending node type (e.g. "PT"), which is ambiguous in a large
41// archive; prefixing the specific child and its parent section locates the failure.
42[[noreturn]] static void reThrowWithParentContext( const IO_ERROR& aError, XNODE* aChildNode,
43 XNODE* aParentNode )
44{
45 // TRANSLATORS: %s are, in order, the underlying error message, the child XML node name,
46 // and the enclosing (parent) XML node name.
47 THROW_IO_ERROR( wxString::Format( _( "%s (whilst parsing '%s' in '%s')" ), aError.Problem(),
48 aChildNode->GetName(), aParentNode->GetName() ) );
49}
50
51
52// Ratio derived from CADSTAR default font. See doxygen comment in cadstar_archive_parser.h
53const double CADSTAR_ARCHIVE_PARSER::TXT_HEIGHT_RATIO = ( 24.0 - 5.0 ) / 24.0;
54
55// Cadstar fields and their KiCad equivalent
56const std::map<CADSTAR_ARCHIVE_PARSER::TEXT_FIELD_NAME, wxString>
58 { { TEXT_FIELD_NAME::DESIGN_TITLE, wxT( "DESIGN_TITLE" ) },
59 { TEXT_FIELD_NAME::SHORT_JOBNAME, wxT( "SHORT_JOBNAME" ) },
60 { TEXT_FIELD_NAME::LONG_JOBNAME, wxT( "LONG_JOBNAME" ) },
61 { TEXT_FIELD_NAME::NUM_OF_SHEETS, wxT( "##" ) },
62 { TEXT_FIELD_NAME::SHEET_NUMBER, wxT( "#" ) },
63 { TEXT_FIELD_NAME::SHEET_NAME, wxT( "SHEETNAME" ) },
64 { TEXT_FIELD_NAME::VARIANT_NAME, wxT( "VARIANT_NAME" ) },
65 { TEXT_FIELD_NAME::VARIANT_DESCRIPTION, wxT( "VARIANT_DESCRIPTION" ) },
66 { TEXT_FIELD_NAME::REG_USER, wxT( "REG_USER" ) },
67 { TEXT_FIELD_NAME::COMPANY_NAME, wxT( "COMPANY_NAME" ) },
68 { TEXT_FIELD_NAME::CURRENT_USER, wxT( "CURRENT_USER" ) },
69 { TEXT_FIELD_NAME::DATE, wxT( "DATE" ) },
70 { TEXT_FIELD_NAME::TIME, wxT( "TIME" ) },
71 { TEXT_FIELD_NAME::MACHINE_NAME, wxT( "MACHINE_NAME" ) } };
72
73
75{
76 wxASSERT( aNode->GetName() == wxT( "FORMAT" ) );
77
78 Type = GetXmlAttributeIDString( aNode, 0 );
79 SomeInt = GetXmlAttributeIDLong( aNode, 1 );
80 Version = GetXmlAttributeIDLong( aNode, 2 );
81}
82
83
85{
86 wxASSERT( aNode->GetName() == wxT( "TIMESTAMP" ) );
87
88 if( !GetXmlAttributeIDString( aNode, 0 ).ToLong( &Year )
89 || !GetXmlAttributeIDString( aNode, 1 ).ToLong( &Month )
90 || !GetXmlAttributeIDString( aNode, 2 ).ToLong( &Day )
91 || !GetXmlAttributeIDString( aNode, 3 ).ToLong( &Hour )
92 || !GetXmlAttributeIDString( aNode, 4 ).ToLong( &Minute )
93 || !GetXmlAttributeIDString( aNode, 5 ).ToLong( &Second ) )
94 {
95 THROW_PARSING_IO_ERROR( wxT( "TIMESTAMP" ), wxString::Format( "HEADER" ) );
96 }
97}
98
99
101{
102 wxASSERT( aNode->GetName() == wxT( "HEADER" ) );
103
104 XNODE* cNode = aNode->GetChildren();
105
106 for( ; cNode; cNode = cNode->GetNext() )
107 {
108 wxString nodeName = cNode->GetName();
109
110 if( nodeName == wxT( "FORMAT" ) )
111 {
112 Format.Parse( cNode, aContext );
113 }
114 else if( nodeName == wxT( "JOBFILE" ) )
115 {
116 JobFile = GetXmlAttributeIDString( cNode, 0 );
117 }
118 else if( nodeName == wxT( "JOBTITLE" ) )
119 {
120 JobTitle = GetXmlAttributeIDString( cNode, 0 );
121 }
122 else if( nodeName == wxT( "GENERATOR" ) )
123 {
125 }
126 else if( nodeName == wxT( "RESOLUTION" ) )
127 {
128 XNODE* subNode = cNode->GetChildren();
129
130 if( subNode
131 && subNode->GetName() == wxT( "METRIC" )
132 && GetXmlAttributeIDString( subNode, 0 ) == wxT( "HUNDREDTH" )
133 && GetXmlAttributeIDString( subNode, 1 ) == wxT( "MICRON" ) )
134 {
136 }
137 else
138 {
139 // TODO Need to find out if there are other possible resolutions. Logically
140 // there must be other base units that could be used, such as "IMPERIAL INCH"
141 // or "METRIC MM" but so far none of settings in CADSTAR generated a different
142 // output resolution to "HUNDREDTH MICRON"
143 WARN_UNKNOWN_NODE_IO_ERROR( subNode->GetName(), wxT( "HEADER->RESOLUTION" ) );
144 }
145 }
146 else if( nodeName == wxT( "TIMESTAMP" ) )
147 {
148 Timestamp.Parse( cNode, aContext );
149 }
150 else
151 {
152 WARN_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), wxT( "HEADER" ) );
153 }
154 }
155}
156
157
159{
160 wxASSERT( aNode->GetName() == wxT( "VMASTER" ) || aNode->GetName() == wxT( "VARIANT" ) );
161
162 ID = GetXmlAttributeIDString( aNode, 0 );
163
164 if( aNode->GetName() == wxT( "VMASTER" ) )
165 {
166 Name = GetXmlAttributeIDString( aNode, 1 );
168 }
169 else
170 {
171 ParentID = GetXmlAttributeIDString( aNode, 1 );
172 Name = GetXmlAttributeIDString( aNode, 2 );
174 }
175}
176
177
179{
180 wxASSERT( aNode->GetName() == wxT( "VHIERARCHY" ) );
181
182 XNODE* cNode = aNode->GetChildren();
183
184 for( ; cNode; cNode = cNode->GetNext() )
185 {
186 if( cNode->GetName() == wxT( "VMASTER" ) || cNode->GetName() == wxT( "VARIANT" ) )
187 {
188 VARIANT variant;
189 variant.Parse( cNode, aContext );
190 Variants.insert( std::make_pair( variant.ID, variant ) );
191 }
192 else
193 {
194 WARN_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), cNode->GetName() );
195 }
196 }
197}
198
199
201{
202 wxASSERT( aNode->GetName() == wxT( "LINECODE" ) );
203
204 ID = GetXmlAttributeIDString( aNode, 0 );
205 Name = GetXmlAttributeIDString( aNode, 1 );
206
207 if( !GetXmlAttributeIDString( aNode, 2 ).ToLong( &Width ) )
208 THROW_PARSING_IO_ERROR( wxT( "Line Width" ), wxString::Format( "LINECODE -> %s", Name ) );
209
210 XNODE* cNode = aNode->GetChildren();
211
212 if( !cNode || cNode->GetName() != wxT( "STYLE" ) )
213 THROW_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), wxString::Format( "LINECODE -> %s", Name ) );
214
215 wxString styleStr = GetXmlAttributeIDString( cNode, 0 );
216
217 if( styleStr == wxT( "SOLID" ) )
218 {
220 }
221 else if( styleStr == wxT( "DASH" ) )
222 {
224 }
225 else if( styleStr == wxT( "DASHDOT" ) )
226 {
228 }
229 else if( styleStr == wxT( "DASHDOTDOT" ) )
230 {
232 }
233 else if( styleStr == wxT( "DOT" ) )
234 {
236 }
237 else
238 {
239 WARN_UNKNOWN_PARAMETER_IO_ERROR( wxString::Format( "STYLE %s", styleStr ),
240 wxString::Format( "LINECODE -> %s", Name ) );
241 }
242}
243
244
246{
247 wxASSERT( aNode->GetName() == wxT( "HATCH" ) );
248
249 Step = GetXmlAttributeIDLong( aNode, 0 );
250 LineWidth = GetXmlAttributeIDLong( aNode, 2 );
251
252 XNODE* cNode = aNode->GetChildren();
253
254 if( !cNode || cNode->GetName() != wxT( "ORIENT" ) )
255 THROW_MISSING_NODE_IO_ERROR( wxT( "ORIENT" ), wxT( "HATCH" ) );
256
258}
259
260
262{
263 wxASSERT( aNode->GetName() == wxT( "HATCHCODE" ) );
264
265 ID = GetXmlAttributeIDString( aNode, 0 );
266 Name = GetXmlAttributeIDString( aNode, 1 );
267
268 XNODE* cNode = aNode->GetChildren();
269 wxString location = wxString::Format( "HATCHCODE -> %s", Name );
270
271 for( ; cNode; cNode = cNode->GetNext() )
272 {
273 if( cNode->GetName() != wxT( "HATCH" ) )
274 {
275 WARN_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), location );
276 continue;
277 }
278
279 HATCH hatch;
280 hatch.Parse( cNode, aContext );
281 Hatches.push_back( hatch );
282 }
283}
284
285
287{
288 wxASSERT( aNode->GetName() == wxT( "FONT" ) );
289
290 Name = GetXmlAttributeIDString( aNode, 0 );
291 Modifier1 = GetXmlAttributeIDLong( aNode, 1 );
292 Modifier2 = GetXmlAttributeIDLong( aNode, 2 );
293
294 XNODE* cNode = aNode->GetChildren();
295
296 for( ; cNode; cNode = cNode->GetNext() )
297 {
298 wxString cNodeName = cNode->GetName();
299
300 if( cNodeName == wxT( "ITALIC" ) )
301 Italic = true;
302 else if( cNodeName == wxT( "KERNING" ) )
303 KerningPairs = true;
304 else
305 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
306 }
307}
308
309
311{
312 wxASSERT( aNode->GetName() == wxT( "TEXTCODE" ) );
313
314 ID = GetXmlAttributeIDString( aNode, 0 );
315 Name = GetXmlAttributeIDString( aNode, 1 );
316
317 LineWidth = GetXmlAttributeIDLong( aNode, 2 );
318 Height = GetXmlAttributeIDLong( aNode, 3 );
319 Width = GetXmlAttributeIDLong( aNode, 4 );
320
321 XNODE* cNode = aNode->GetChildren();
322
323 if( cNode )
324 {
325 if( cNode->GetName() == wxT( "FONT" ) )
326 Font.Parse( cNode, aContext );
327 else
328 WARN_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), aNode->GetName() );
329 }
330}
331
332
334{
335 wxASSERT( aNode->GetName() == wxT( "ROUTEREASSIGN" ) );
336
337 LayerID = GetXmlAttributeIDString( aNode, 0 );
338 OptimalWidth = GetXmlAttributeIDLong( aNode, 1, false );
339
340 XNODE* cNode = aNode->GetChildren();
341
342 for( ; cNode; cNode = cNode->GetNext() )
343 {
344 wxString cNodeName = cNode->GetName();
345
346 if( cNodeName == wxT( "NECKWIDTH" ) )
348 else if( cNodeName == wxT( "SROUTEWIDTH" ) )
350 else if( cNodeName == wxT( "MINWIDTH" ) )
351 MinWidth = GetXmlAttributeIDLong( cNode, 0 );
352 else if( cNodeName == wxT( "MAXWIDTH" ) )
353 MaxWidth = GetXmlAttributeIDLong( cNode, 0 );
354 else
355 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
356 }
357}
358
359
361{
362 wxASSERT( aNode->GetName() == wxT( "ROUTECODE" ) );
363
364 ID = GetXmlAttributeIDString( aNode, 0 );
365 Name = GetXmlAttributeIDString( aNode, 1 );
366 OptimalWidth = GetXmlAttributeIDLong( aNode, 2, false );
367
368 XNODE* cNode = aNode->GetChildren();
369
370 for( ; cNode; cNode = cNode->GetNext() )
371 {
372 wxString cNodeName = cNode->GetName();
373
374 if( cNodeName == wxT( "NECKWIDTH" ) )
375 {
377 }
378 else if( cNodeName == wxT( "SROUTEWIDTH" ) )
379 {
381 }
382 else if( cNodeName == wxT( "MINWIDTH" ) )
383 {
384 MinWidth = GetXmlAttributeIDLong( cNode, 0 );
385 }
386 else if( cNodeName == wxT( "MAXWIDTH" ) )
387 {
388 MaxWidth = GetXmlAttributeIDLong( cNode, 0 );
389 }
390 else if( cNodeName == wxT( "ROUTEREASSIGN" ) )
391 {
392 ROUTEREASSIGN routereassign;
393 routereassign.Parse( cNode, aContext );
394 RouteReassigns.push_back( routereassign );
395 }
396 else
397 {
398 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
399 }
400 }
401}
402
403
405{
406 return Base * std::pow( 10.0, Exponent );
407}
408
409
411{
412 wxASSERT( aNode->GetName() == wxT( "E" ) );
413
414 if( ( !GetXmlAttributeIDString( aNode, 0 ).ToLong( &Base ) )
415 || ( !GetXmlAttributeIDString( aNode, 1 ).ToLong( &Exponent ) ) )
416 {
417 THROW_PARSING_IO_ERROR( wxT( "Base and Exponent" ),
418 wxString::Format( "%s->%s", aNode->GetParent()->GetName(),
419 aNode->GetParent()->GetName() ) );
420 }
421}
422
423
425{
426 wxASSERT( aNode->GetName() == wxT( "PT" ) );
427
428 x = GetXmlAttributeIDLong( aNode, 0 );
429 y = GetXmlAttributeIDLong( aNode, 1 );
430}
431
432
434{
435 wxASSERT( aNode->GetName() == wxT( "PT" ) );
436
437 x = GetXmlAttributeIDLong( aNode, 0 );
438 y = GetXmlAttributeIDLong( aNode, 1 );
439}
440
441
443{
444 wxString aNodeName = aNode->GetName();
445
446 if( aNodeName == wxT( "PT" ) || aNodeName == wxT( "ACWARC" ) || aNodeName == wxT( "CWARC" )
447 || aNodeName == wxT( "CWSEMI" ) || aNodeName == wxT( "ACWSEMI" ) )
448 {
449 return true;
450 }
451 else
452 {
453 return false;
454 }
455}
456
457
459{
460 wxASSERT( IsVertex( aNode ) );
461
462 wxString aNodeName = aNode->GetName();
463
464 if( aNodeName == wxT( "PT" ) )
465 {
469 End.Parse( aNode, aContext );
470 }
471 else if( aNodeName == wxT( "ACWARC" ) || aNodeName == wxT( "CWARC" ) )
472 {
473 if( aNodeName == wxT( "ACWARC" ) )
475 else
477
478 std::vector<POINT> pts = ParseAllChildPoints( aNode, aContext, true, 2 );
479
480 Center = pts[0];
481 End = pts[1];
482 }
483 else if( aNodeName == wxT( "ACWSEMI" ) || aNodeName == wxT( "CWSEMI" ) )
484 {
485 if( aNodeName == wxT( "ACWSEMI" ) )
487 else
489
492
493 std::vector<POINT> pts = ParseAllChildPoints( aNode, aContext, true, 1 );
494
495 End = pts[0];
496 }
497 else
498 {
499 wxASSERT_MSG( true, wxT( "Unknown VERTEX type" ) );
500 }
501}
502
503
505 const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
506 int aAccuracy ) const
507{
509 {
510 aChainToAppendTo->Append( aCadstarToKicadPointCallback( End ) );
511 return;
512 }
513
514 wxCHECK_MSG( aChainToAppendTo->PointCount() > 0, /*void*/,
515 "Can't append an arc to vertex to an empty chain" );
516
517 aChainToAppendTo->Append( BuildArc( aChainToAppendTo->GetPoint( -1 ),
518 aCadstarToKicadPointCallback ),
519 aAccuracy );
520}
521
522
524 const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback ) const
525{
526 wxCHECK_MSG( Type != VERTEX_TYPE::VT_POINT, SHAPE_ARC(),
527 "Can't build an arc for a straight segment!" );
528
529 VECTOR2I startPoint = aPrevPoint;
530 VECTOR2I endPoint = aCadstarToKicadPointCallback( End );
531 VECTOR2I centerPoint;
532
534 centerPoint = ( startPoint / 2 ) + ( endPoint / 2 );
535 else
536 centerPoint = aCadstarToKicadPointCallback( Center );
537
538 bool clockwise = Type == VERTEX_TYPE::CLOCKWISE_ARC
540
541 // A bit of a hack to figure out if we need to invert clockwise due to the transform
542 VECTOR2I transform = aCadstarToKicadPointCallback( { 500, 500 } )
543 - aCadstarToKicadPointCallback( { 0, 0 } );
544
545 if( ( transform.x > 0 && transform.y < 0 ) || ( transform.x < 0 && transform.y > 0 ) )
546 clockwise = !clockwise;
547
548 SHAPE_ARC arc;
549
550 return arc.ConstructFromStartEndCenter( startPoint, endPoint, centerPoint, clockwise );
551}
552
553
555{
556 wxASSERT( aNode->GetName() == wxT( "CUTOUT" ) );
557
558 Vertices = ParseAllChildVertices( aNode, aContext, true );
559}
560
561
563{
564 wxString aNodeName = aNode->GetName();
565
566 if( aNodeName == wxT( "OPENSHAPE" ) || aNodeName == wxT( "OUTLINE" )
567 || aNodeName == wxT( "SOLID" ) || aNodeName == wxT( "HATCHED" ) )
568 {
569 return true;
570 }
571 else
572 {
573 return false;
574 }
575}
576
577
579{
580 wxASSERT( IsShape( aNode ) );
581
582 wxString aNodeName = aNode->GetName();
583
584 if( aNodeName == wxT( "OPENSHAPE" ) )
585 {
587 Vertices = ParseAllChildVertices( aNode, aContext, true );
588 Cutouts.clear();
589 HatchCodeID = wxEmptyString;
590 }
591 else if( aNodeName == wxT( "OUTLINE" ) )
592 {
594 Vertices = ParseAllChildVertices( aNode, aContext, false );
595 Cutouts = ParseAllChildCutouts( aNode, aContext, false );
596 HatchCodeID = wxEmptyString;
597 }
598 else if( aNodeName == wxT( "SOLID" ) )
599 {
601 Vertices = ParseAllChildVertices( aNode, aContext, false );
602 Cutouts = ParseAllChildCutouts( aNode, aContext, false );
603 HatchCodeID = wxEmptyString;
604 }
605 else if( aNodeName == wxT( "HATCHED" ) )
606 {
608 Vertices = ParseAllChildVertices( aNode, aContext, false );
609 Cutouts = ParseAllChildCutouts( aNode, aContext, false );
611 }
612 else
613 {
614 wxASSERT_MSG( true, wxT( "Unknown SHAPE type" ) );
615 }
616}
617
619 const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
620 int aMaxError ) const
621{
622 SHAPE_LINE_CHAIN outline;
623
624 if( Vertices.size() == 0 )
625 return outline;
626
627 for( const auto& vertex : Vertices )
628 vertex.AppendToChain( &outline, aCadstarToKicadPointCallback, aMaxError );
629
631 {
632 outline.SetClosed( true );
633
634 // Append after closing, to ensre first and last point remain the same
635 outline.Append( outline.CPoint( 0 ), true );
636 }
637
638 return outline;
639}
640
641
643 const std::function<VECTOR2I( const VECTOR2I& )> aCadstarToKicadPointCallback,
644 int aMaxError ) const
645{
646 SHAPE_POLY_SET polyset;
647
648 // We shouldn't convert openshapes to polyset!
649 wxCHECK( Type != SHAPE_TYPE::OPENSHAPE, polyset );
650
651 polyset.AddOutline( OutlineAsChain( aCadstarToKicadPointCallback, aMaxError ) );
652
653 for( const auto& cutout : Cutouts )
654 {
655 SHAPE_LINE_CHAIN hole;
656
657 if( cutout.Vertices.size() == 0 )
658 continue;
659
660 for( const auto& cutoutVertex : cutout.Vertices )
661 cutoutVertex.AppendToChain( &hole, aCadstarToKicadPointCallback, aMaxError );
662
663 hole.SetClosed( true );
664
665 // Append after closing, to ensre first and last point remain the same
666 cutout.Vertices.at( 0 ).AppendToChain( &hole, aCadstarToKicadPointCallback, aMaxError );
667
668 polyset.AddHole( hole );
669 }
670
671 return polyset;
672}
673
674
676{
677 wxASSERT( aNode->GetName() == wxT( "UNITS" ) );
678
679 wxString unit = GetXmlAttributeIDString( aNode, 0 );
680
681 if( unit == wxT( "CENTIMETER" ) )
682 return UNITS::CENTIMETER;
683 else if( unit == wxT( "INCH" ) )
684 return UNITS::INCH;
685 else if( unit == wxT( "METER" ) )
686 return UNITS::METER;
687 else if( unit == wxT( "MICROMETRE" ) )
688 return UNITS::MICROMETRE;
689 else if( unit == wxT( "MM" ) )
690 return UNITS::MM;
691 else if( unit == wxT( "THOU" ) )
692 return UNITS::THOU;
693 else if( unit == wxT( "DESIGN" ) )
694 return UNITS::DESIGN;
695 else
696 WARN_UNKNOWN_PARAMETER_IO_ERROR( unit, wxT( "UNITS" ) );
697
698 return UNITS::DESIGN;
699}
700
701
703{
704 wxASSERT( aNode->GetName() == wxT( "ANGUNITS" ) );
705
706 wxString angUnitStr = GetXmlAttributeIDString( aNode, 0 );
707
708 if( angUnitStr == wxT( "DEGREES" ) )
709 return ANGUNITS::DEGREES;
710 else if( angUnitStr == wxT( "RADIANS" ) )
711 return ANGUNITS::RADIANS;
712 else
713 WARN_UNKNOWN_PARAMETER_IO_ERROR( angUnitStr, aNode->GetName() );
714
715 return ANGUNITS::DEGREES;
716}
717
718
720{
721 if( !aNode )
722 return false;
723
724 wxString aNodeName = aNode->GetName();
725
726 if( aNodeName == wxT( "FRACTIONALGRID" ) || aNodeName == wxT( "STEPGRID" ) )
727 return true;
728 else
729 return false;
730}
731
732
734{
735 wxASSERT( IsGrid( aNode ) );
736
737 wxString aNodeName = aNode->GetName();
738
739 if( aNodeName == wxT( "FRACTIONALGRID" ) )
741 else if( aNodeName == wxT( "STEPGRID" ) )
743 else
744 wxASSERT_MSG( true, wxT( "Unknown Grid Type" ) );
745
746 Name = GetXmlAttributeIDString( aNode, 0 );
747 Param1 = GetXmlAttributeIDLong( aNode, 1 );
748 Param2 = GetXmlAttributeIDLong( aNode, 2 );
749}
750
751
753{
754 wxASSERT( aNode->GetName() == wxT( "GRIDS" ) );
755
756 XNODE* cNode = aNode->GetChildren();
757
758 for( ; cNode; cNode = cNode->GetNext() )
759 {
760 wxString cNodeName = cNode->GetName();
761
762 if( cNodeName == wxT( "WORKINGGRID" ) )
763 {
764 XNODE* workingGridNode = cNode->GetChildren();
765
766 if( !GRID::IsGrid( workingGridNode ) )
767 {
768 wxString found = workingGridNode ? workingGridNode->GetName() : wxString( "(empty)" );
769 WARN_UNKNOWN_NODE_IO_ERROR( found, wxT( "GRIDS -> WORKINGGRID" ) );
770 }
771 else
772 {
773 WorkingGrid.Parse( workingGridNode, aContext );
774 }
775 }
776 else if( cNodeName == wxT( "SCREENGRID" ) )
777 {
778 XNODE* screenGridNode = cNode->GetChildren();
779
780 if( !GRID::IsGrid( screenGridNode ) )
781 {
782 wxString found = screenGridNode ? screenGridNode->GetName() : wxString( "(empty)" );
783 WARN_UNKNOWN_NODE_IO_ERROR( found, wxT( "GRIDS -> SCREENGRID" ) );
784 }
785 else
786 {
787 ScreenGrid.Parse( screenGridNode, aContext );
788 }
789 }
790 else if( GRID::IsGrid( cNode ) )
791 {
792 GRID userGrid;
793 userGrid.Parse( cNode, aContext );
794 UserGrids.push_back( userGrid );
795 }
796 else
797 {
798 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, wxT( "GRIDS" ) );
799 }
800 }
801}
802
803
805{
806 wxString cNodeName = aChildNode->GetName();
807
808 if( cNodeName == wxT( "UNITS" ) )
809 {
810 Units = ParseUnits( aChildNode );
811 }
812 else if( cNodeName == wxT( "UNITSPRECISION" ) )
813 {
814 UnitDisplPrecision = GetXmlAttributeIDLong( aChildNode, 0 );
815 }
816 else if( cNodeName == wxT( "INTERLINEGAP" ) )
817 {
818 InterlineGap = GetXmlAttributeIDLong( aChildNode, 0 );
819 }
820 else if( cNodeName == wxT( "BARLINEGAP" ) )
821 {
822 BarlineGap = GetXmlAttributeIDLong( aChildNode, 0 );
823 }
824 else if( cNodeName == wxT( "ALLOWBARTEXT" ) )
825 {
826 AllowBarredText = true;
827 }
828 else if( cNodeName == wxT( "ANGULARPRECISION" ) )
829 {
830 AngularPrecision = GetXmlAttributeIDLong( aChildNode, 0 );
831 }
832 else if( cNodeName == wxT( "DESIGNORIGIN" ) )
833 {
834 DesignOrigin.Parse( aChildNode->GetChildren(), aContext );
835 }
836 else if( cNodeName == wxT( "DESIGNAREA" ) )
837 {
838 std::vector<POINT> pts = ParseAllChildPoints( aChildNode, aContext, true, 2 );
839 DesignArea = std::make_pair( pts[0], pts[1] );
840 }
841 else if( cNodeName == wxT( "DESIGNREF" ) )
842 {
843 DesignOrigin.Parse( aChildNode->GetChildren(), aContext );
844 }
845 else if( cNodeName == wxT( "DESIGNLIMIT" ) )
846 {
847 DesignLimit.Parse( aChildNode->GetChildren(), aContext );
848 }
849 else if( cNodeName == wxT( "PINNOOFFSET" ) )
850 {
851 PinNoOffset = GetXmlAttributeIDLong( aChildNode, 0 );
852 }
853 else if( cNodeName == wxT( "PINNOANGLE" ) )
854 {
855 PinNoAngle = GetXmlAttributeIDLong( aChildNode, 0 );
856 }
857 else
858 {
859 return false;
860 }
861
862 return true;
863}
864
865
867{
868 wxASSERT( aNode->GetName() == wxT( "SETTINGS" ) );
869
870 XNODE* cNode = aNode->GetChildren();
871
872 for( ; cNode; cNode = cNode->GetNext() )
873 {
874 wxString cNodeName = cNode->GetName();
875
876 if( ParseSubNode( cNode, aContext ) )
877 continue;
878 else
879 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, wxT( "SETTINGS" ) );
880 }
881}
882
883
884wxString CADSTAR_ARCHIVE_PARSER::ParseTextFields( const wxString& aTextString,
885 PARSER_CONTEXT* aContext )
886{
887 static const std::map<TEXT_FIELD_NAME, wxString> txtTokens =
888 {
889 { TEXT_FIELD_NAME::DESIGN_TITLE, wxT( "DESIGN TITLE" ) },
890 { TEXT_FIELD_NAME::SHORT_JOBNAME, wxT( "SHORT_JOBNAME" ) },
891 { TEXT_FIELD_NAME::LONG_JOBNAME, wxT( "LONG_JOBNAME" ) },
892 { TEXT_FIELD_NAME::NUM_OF_SHEETS, wxT( "NUM_OF_SHEETS" ) },
893 { TEXT_FIELD_NAME::SHEET_NUMBER, wxT( "SHEET_NUMBER" ) },
894 { TEXT_FIELD_NAME::SHEET_NAME, wxT( "SHEET_NAME" ) },
895 { TEXT_FIELD_NAME::VARIANT_NAME, wxT( "VARIANT_NAME" ) },
896 { TEXT_FIELD_NAME::VARIANT_DESCRIPTION, wxT( "VARIANT_DESCRIPTION" ) },
897 { TEXT_FIELD_NAME::REG_USER, wxT( "REG_USER" ) },
898 { TEXT_FIELD_NAME::COMPANY_NAME, wxT( "COMPANY_NAME" ) },
899 { TEXT_FIELD_NAME::CURRENT_USER, wxT( "CURRENT_USER" ) },
900 { TEXT_FIELD_NAME::DATE, wxT( "DATE" ) },
901 { TEXT_FIELD_NAME::TIME, wxT( "TIME" ) },
902 { TEXT_FIELD_NAME::MACHINE_NAME, wxT( "MACHINE_NAME" ) },
903 { TEXT_FIELD_NAME::FROM_FILE, wxT( "FROM_FILE" ) },
904 { TEXT_FIELD_NAME::DISTANCE, wxT( "DISTANCE" ) },
905 { TEXT_FIELD_NAME::UNITS_SHORT, wxT( "UNITS SHORT" ) },
906 { TEXT_FIELD_NAME::UNITS_ABBREV, wxT( "UNITS ABBREV" ) },
907 { TEXT_FIELD_NAME::UNITS_FULL, wxT( "UNITS FULL" ) },
908 { TEXT_FIELD_NAME::HYPERLINK, wxT( "HYPERLINK" ) }
909 };
910
911 wxString remainingStr = aTextString;
912 wxString returnStr;
913
914 while( remainingStr.size() > 0 )
915 {
916 // Find the start token
917 size_t startpos = remainingStr.Find( wxT( "<@" ) );
918
919 if( static_cast<int>( startpos ) == wxNOT_FOUND )
920 {
921 // No more fields to parse, add to return string
922 returnStr += remainingStr;
923 break;
924 }
925
926 if( startpos > 0 )
927 returnStr += remainingStr.SubString( 0, startpos - 1 );
928
929 if( ( startpos + 2 ) >= remainingStr.size() )
930 break;
931
932 remainingStr = remainingStr.Mid( startpos + 2 );
933
934 //Find the expected token for the field
936
937 for( std::pair<TEXT_FIELD_NAME, wxString> txtF : txtTokens )
938 {
939 if( remainingStr.StartsWith( txtF.second ) )
940 {
941 foundField = txtF.first;
942 break;
943 }
944 }
945
946 if( foundField == TEXT_FIELD_NAME::NONE )
947 {
948 // Not a valid field, lets keep looking
949 returnStr += wxT( "<@" );
950 continue;
951 }
952
953 //Now lets find the end token
954 size_t endpos = remainingStr.Find( wxT( "@>" ) );
955
956 if( static_cast<int>( endpos ) == wxNOT_FOUND )
957 {
958 // The field we found isn't valid as it doesn't have a termination
959 // Lets append the whole thing as plain text
960 returnStr += wxT( "<@" ) + remainingStr;
961 break;
962 }
963
964 size_t valueStart = txtTokens.at( foundField ).size();
965 wxString fieldValue = remainingStr.SubString( valueStart, endpos - 1 );
966 wxString address;
967
968 if( foundField == TEXT_FIELD_NAME::FROM_FILE || foundField == TEXT_FIELD_NAME::HYPERLINK )
969 {
970 // The first character should always be a double quotation mark
971 wxASSERT_MSG( fieldValue.at( 0 ) == '"', "Expected '\"' as the first character" );
972
973 size_t splitPos = fieldValue.find_first_of( '"', 1 );
974 address = fieldValue.SubString( 1, splitPos - 1 );
975
976 if( foundField == TEXT_FIELD_NAME::HYPERLINK )
977 {
978 // Assume the last two characters are "@>"
979 wxASSERT_MSG( remainingStr.EndsWith( wxT( "@>" ) ),
980 "Expected '@>' at the end of a hyperlink" );
981
982 fieldValue = remainingStr.SubString( valueStart + splitPos + 1,
983 remainingStr.Length() - 3 );
984
985 remainingStr = wxEmptyString;
986 }
987 else
988 {
989 fieldValue = fieldValue.Mid( splitPos + 1 );
990 }
991 }
992
993 switch( foundField )
994 {
1006
1007 if( aContext->TextFieldToValuesMap.find( foundField )
1008 != aContext->TextFieldToValuesMap.end() )
1009 {
1010 aContext->InconsistentTextFields.insert( foundField );
1011 }
1012 else
1013 {
1014 aContext->TextFieldToValuesMap.insert( { foundField, fieldValue } );
1015 }
1016
1018
1022 returnStr += wxT( "${" ) + CADSTAR_TO_KICAD_FIELDS.at( foundField ) + wxT( "}" );
1023 break;
1024
1029 // Just flatten the text for distances
1030 returnStr += fieldValue;
1031 break;
1032
1034 {
1035 wxFileName fn( address );
1036 wxString fieldFmt = wxT( "FROM_FILE_%s_%s" );
1037 wxString fieldName = wxString::Format( fieldFmt, fn.GetName(), fn.GetExt() );
1038
1039 int version = 1;
1040
1041 while(
1042 aContext->FilenamesToTextMap.find( fieldName )
1043 != aContext->FilenamesToTextMap.end()
1044 && aContext->FilenamesToTextMap.at( fieldName ) != fieldValue )
1045 {
1046 fieldName = wxString::Format( fieldFmt, fn.GetName(), fn.GetExt() )
1047 + wxString::Format( wxT( "_%d" ), version++ );
1048 }
1049
1050 aContext->FilenamesToTextMap[fieldName] = fieldValue;
1051 returnStr += wxT( "${" ) + fieldName + wxT( "}" );
1052 }
1053 break;
1054
1056 {
1057 aContext->TextToHyperlinksMap[fieldValue] = address;
1058 returnStr += ParseTextFields( fieldValue, aContext );
1059 }
1060 break;
1061
1063 wxFAIL_MSG( "We should have already covered this scenario above" );
1064 break;
1065 }
1066
1067
1068 if( ( endpos + 2 ) >= remainingStr.size() )
1069 break;
1070
1071 remainingStr = remainingStr.Mid( endpos + 2 );
1072 }
1073
1074 return returnStr;
1075}
1076
1077
1079{
1080 wxASSERT( aNode->GetName() == wxT( "ALIGN" ) );
1081
1082 wxString alignmentStr = GetXmlAttributeIDString( aNode, 0 );
1083
1084 if( alignmentStr == wxT( "BOTTOMCENTER" ) )
1086 else if( alignmentStr == wxT( "BOTTOMLEFT" ) )
1087 return ALIGNMENT::BOTTOMLEFT;
1088 else if( alignmentStr == wxT( "BOTTOMRIGHT" ) )
1090 else if( alignmentStr == wxT( "CENTERCENTER" ) )
1092 else if( alignmentStr == wxT( "CENTERLEFT" ) )
1093 return ALIGNMENT::CENTERLEFT;
1094 else if( alignmentStr == wxT( "CENTERRIGHT" ) )
1096 else if( alignmentStr == wxT( "TOPCENTER" ) )
1097 return ALIGNMENT::TOPCENTER;
1098 else if( alignmentStr == wxT( "TOPLEFT" ) )
1099 return ALIGNMENT::TOPLEFT;
1100 else if( alignmentStr == wxT( "TOPRIGHT" ) )
1101 return ALIGNMENT::TOPRIGHT;
1102 else
1103 WARN_UNKNOWN_PARAMETER_IO_ERROR( alignmentStr, wxT( "ALIGN" ) );
1104
1105 //shouldn't be here but avoids compiler warning
1107}
1108
1109
1111{
1112 wxASSERT( aNode->GetName() == wxT( "JUSTIFICATION" ) );
1113
1114 wxString justificationStr = GetXmlAttributeIDString( aNode, 0 );
1115
1116 if( justificationStr == wxT( "LEFT" ) )
1117 return JUSTIFICATION::LEFT;
1118 else if( justificationStr == wxT( "RIGHT" ) )
1119 return JUSTIFICATION::RIGHT;
1120 else if( justificationStr == wxT( "CENTER" ) )
1121 return JUSTIFICATION::CENTER;
1122 else
1123 WARN_UNKNOWN_PARAMETER_IO_ERROR( justificationStr, wxT( "JUSTIFICATION" ) );
1124
1125 return JUSTIFICATION::LEFT;
1126}
1127
1128
1130{
1131 wxASSERT( aNode->GetName() == wxT( "READABILITY" ) );
1132
1133 wxString readabilityStr = GetXmlAttributeIDString( aNode, 0 );
1134
1135 if( readabilityStr == wxT( "BOTTOM_TO_TOP" ) )
1137 else if( readabilityStr == wxT( "TOP_TO_BOTTOM" ) )
1139 else
1140 WARN_UNKNOWN_PARAMETER_IO_ERROR( readabilityStr, wxT( "READABILITY" ) );
1141
1143}
1144
1145
1152
1153
1155 PARSER_CONTEXT* aContext )
1156{
1157 wxString cNodeName = aChildNode->GetName();
1158
1159 if( cNodeName == wxT( "PT" ) )
1160 Position.Parse( aChildNode, aContext );
1161 else if( cNodeName == wxT( "ORIENT" ) )
1162 OrientAngle = GetXmlAttributeIDLong( aChildNode, 0 );
1163 else if( cNodeName == wxT( "MIRROR" ) )
1164 Mirror = true;
1165 else if( cNodeName == wxT( "FIX" ) )
1166 Fixed = true;
1167 else if( cNodeName == wxT( "ALIGN" ) )
1168 Alignment = ParseAlignment( aChildNode );
1169 else if( cNodeName == wxT( "JUSTIFICATION" ) )
1170 Justification = ParseJustification( aChildNode );
1171 else
1172 return false;
1173
1174 return true;
1175}
1176
1177
1179{
1180 wxASSERT( aNode->GetName() == wxT( "ATTRLOC" ) );
1181
1182 ParseIdentifiers( aNode, aContext );
1183
1184 //Parse child nodes
1185 XNODE* cNode = aNode->GetChildren();
1186
1187 for( ; cNode; cNode = cNode->GetNext() )
1188 {
1189 if( ParseSubNode( cNode, aContext ) )
1190 continue;
1191 else
1192 WARN_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), wxT( "ATTRLOC" ) );
1193 }
1194
1196 THROW_MISSING_NODE_IO_ERROR( wxT( "PT" ), wxT( "ATTRLOC" ) );
1197}
1198
1199
1201{
1202 wxASSERT( aNode->GetName() == wxT( "COLUMNORDER" ) );
1203
1204 ID = GetXmlAttributeIDLong( aNode, 0 );
1205 Order = GetXmlAttributeIDLong( aNode, 1 );
1206
1207 CheckNoChildNodes( aNode );
1208}
1209
1210
1212{
1213 wxASSERT( aNode->GetName() == wxT( "COLUMNWIDTH" ) );
1214
1215 ID = GetXmlAttributeIDLong( aNode, 0 );
1216 Width = GetXmlAttributeIDLong( aNode, 1 );
1217
1218 CheckNoChildNodes( aNode );
1219}
1220
1221
1223{
1224 wxASSERT( aNode->GetName() == wxT( "ATTRNAME" ) );
1225
1226 ID = GetXmlAttributeIDString( aNode, 0 );
1227 Name = GetXmlAttributeIDString( aNode, 1 );
1228
1229 XNODE* cNode = aNode->GetChildren();
1230 wxString location = wxString::Format( "ATTRNAME -> %s", Name );
1231
1232 for( ; cNode; cNode = cNode->GetNext() )
1233 {
1234 wxString cNodeName = cNode->GetName();
1235
1236 if( cNodeName == wxT( "ATTROWNER" ) )
1237 {
1238 wxString attOwnerVal = GetXmlAttributeIDString( cNode, 0 );
1239
1240 if( attOwnerVal == wxT( "ALL_ITEMS" ) )
1242 else if( attOwnerVal == wxT( "AREA" ) )
1244 else if( attOwnerVal == wxT( "BOARD" ) )
1246 else if( attOwnerVal == wxT( "COMPONENT" ) )
1248 else if( attOwnerVal == wxT( "CONNECTION" ) )
1250 else if( attOwnerVal == wxT( "COPPER" ) )
1252 else if( attOwnerVal == wxT( "DOCSYMBOL" ) )
1254 else if( attOwnerVal == wxT( "FIGURE" ) )
1256 else if( attOwnerVal == wxT( "NET" ) )
1258 else if( attOwnerVal == wxT( "NETCLASS" ) )
1260 else if( attOwnerVal == wxT( "PART" ) )
1262 else if( attOwnerVal == wxT( "PART_DEFINITION" ) )
1264 else if( attOwnerVal == wxT( "PIN" ) )
1266 else if( attOwnerVal == wxT( "SIGNALREF" ) )
1268 else if( attOwnerVal == wxT( "SYMBOL" ) )
1270 else if( attOwnerVal == wxT( "SYMDEF" ) )
1272 else if( attOwnerVal == wxT( "TEMPLATE" ) )
1274 else if( attOwnerVal == wxT( "TESTPOINT" ) )
1276 else
1278 }
1279 else if( cNodeName == wxT( "ATTRUSAGE" ) )
1280 {
1281 wxString attUsageVal = GetXmlAttributeIDString( cNode, 0 );
1282
1283 if( attUsageVal == wxT( "BOTH" ) )
1285 else if( attUsageVal == wxT( "COMPONENT" ) )
1287 else if( attUsageVal == wxT( "PART_DEFINITION" ) )
1289 else if( attUsageVal == wxT( "PART_LIBRARY" ) )
1291 else if( attUsageVal == wxT( "SYMBOL" ) )
1293 else
1295 }
1296 else if( cNodeName == wxT( "NOTRANSFER" ) )
1297 {
1298 NoTransfer = true;
1299 }
1300 else if( cNodeName == wxT( "COLUMNORDER" ) )
1301 {
1302 COLUMNORDER cOrder;
1303 cOrder.Parse( cNode, aContext );
1304 ColumnOrders.push_back( cOrder );
1305 }
1306 else if( cNodeName == wxT( "COLUMNWIDTH" ) )
1307 {
1308 COLUMNWIDTH cWidth;
1309 cWidth.Parse( cNode, aContext );
1310 ColumnWidths.push_back( cWidth );
1311 }
1312 else if( cNodeName == wxT( "COLUMNINVISIBLE" ) )
1313 {
1314 ColumnInvisible = true;
1315 }
1316 else
1317 {
1319 }
1320 }
1321}
1322
1323
1325{
1326 wxASSERT( aNode->GetName() == wxT( "ATTR" ) );
1327
1329 Value = GetXmlAttributeIDString( aNode, 1 );
1330
1331 XNODE* cNode = aNode->GetChildren();
1332
1333 for( ; cNode; cNode = cNode->GetNext() )
1334 {
1335 if( cNode->GetName() == wxT( "READONLY" ) )
1336 {
1337 ReadOnly = true;
1338 }
1339 else if( cNode->GetName() == wxT( "ATTRLOC" ) )
1340 {
1341 AttributeLocation.Parse( cNode, aContext );
1342 HasLocation = true;
1343 }
1344 else
1345 {
1346 WARN_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), wxT( "ATTR" ) );
1347 }
1348 }
1349}
1350
1351
1353{
1354 wxASSERT( aNode->GetName() == wxT( "TEXTLOC" ) );
1355
1356 wxString attributeStr = GetXmlAttributeIDString( aNode, 0 );
1357 bool attributeIDisSet = false;
1358
1359 if( attributeStr == wxT( "PART_NAME" ) )
1360 {
1362 attributeIDisSet = true;
1363 }
1364 else if( attributeStr == wxT( "COMP_NAME" ) )
1365 {
1367 attributeIDisSet = true;
1368 }
1369 else if( attributeStr == wxT( "COMP_NAME2" ) )
1370 {
1372 attributeIDisSet = true;
1373 }
1374 else if( attributeStr == wxT( "SYMBOL_NAME" ) )
1375 {
1377 attributeIDisSet = true;
1378 }
1379 else if( attributeStr == wxT( "LINK_ORIGIN" ) )
1380 {
1382 attributeIDisSet = true;
1383 }
1384 else if( attributeStr == wxT( "SIGNALNAME_ORIGIN" ) )
1385 {
1387 attributeIDisSet = true;
1388 }
1389 else if( attributeStr == wxT( "ATTRREF" ) )
1390 {
1391 //We will initialise when we parse all child nodes
1392 attributeIDisSet = false;
1393 }
1394 else
1395 {
1396 WARN_UNKNOWN_PARAMETER_IO_ERROR( attributeStr, wxT( "TEXTLOC" ) );
1397 }
1398
1399 TextCodeID = GetXmlAttributeIDString( aNode, 1 );
1400 LayerID = GetXmlAttributeIDString( aNode, 2, false );
1401
1402 //Parse child nodes
1403 XNODE* cNode = aNode->GetChildren();
1404
1405 for( ; cNode; cNode = cNode->GetNext() )
1406 {
1407 wxString cNodeName = cNode->GetName();
1408
1409 if( ParseSubNode( cNode, aContext ) )
1410 {
1411 continue;
1412 }
1413 else if( !attributeIDisSet && cNodeName == wxT( "ATTRREF" ) )
1414 {
1416 attributeIDisSet = true;
1417 }
1418 else if( cNodeName == wxT( "ORIENT" ) )
1419 {
1420 OrientAngle = GetXmlAttributeIDLong( cNode, 0 );
1421 }
1422 else if( cNodeName == wxT( "MIRROR" ) )
1423 {
1424 Mirror = true;
1425 }
1426 else if( cNodeName == wxT( "FIX" ) )
1427 {
1428 Fixed = true;
1429 }
1430 else if( cNodeName == wxT( "ALIGN" ) )
1431 {
1432 Alignment = ParseAlignment( cNode );
1433 }
1434 else if( cNodeName == wxT( "JUSTIFICATION" ) )
1435 {
1437 }
1438 else
1439 {
1440 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, wxT( "TEXTLOC" ) );
1441 }
1442 }
1443
1445 THROW_MISSING_NODE_IO_ERROR( wxT( "PT" ), wxT( "TEXTLOC" ) );
1446}
1447
1448
1450{
1451 wxASSERT( aNode->GetName() == wxT( "NETCLASS" ) );
1452
1453 ID = GetXmlAttributeIDString( aNode, 0 );
1454 Name = GetXmlAttributeIDString( aNode, 1 );
1455
1456 XNODE* cNode = aNode->GetChildren();
1457 wxString location = wxString::Format( "NETCLASS -> %s", Name );
1458
1459 for( ; cNode; cNode = cNode->GetNext() )
1460 {
1461 wxString cNodeName = cNode->GetName();
1462
1463 if( cNodeName == wxT( "ATTR" ) )
1464 {
1465 ATTRIBUTE_VALUE attribute_val;
1466 attribute_val.Parse( cNode, aContext );
1467 Attributes.push_back( attribute_val );
1468 }
1469 else
1470 {
1472 }
1473 }
1474}
1475
1476
1478{
1479 wxASSERT( aNode->GetName() == wxT( "SPCCLASSNAME" ) );
1480
1481 ID = GetXmlAttributeIDString( aNode, 0 );
1482 Name = GetXmlAttributeIDString( aNode, 1 );
1483}
1484
1485
1487{
1488 wxString nodeName = aChildNode->GetName();
1489
1490 if( nodeName == wxT( "LINECODE" ) )
1491 {
1492 LINECODE linecode;
1493 linecode.Parse( aChildNode, aContext );
1494 LineCodes.insert( std::make_pair( linecode.ID, linecode ) );
1495 }
1496 else if( nodeName == wxT( "HATCHCODE" ) )
1497 {
1498 HATCHCODE hatchcode;
1499 hatchcode.Parse( aChildNode, aContext );
1500 HatchCodes.insert( std::make_pair( hatchcode.ID, hatchcode ) );
1501 }
1502 else if( nodeName == wxT( "TEXTCODE" ) )
1503 {
1504 TEXTCODE textcode;
1505 textcode.Parse( aChildNode, aContext );
1506 TextCodes.insert( std::make_pair( textcode.ID, textcode ) );
1507 }
1508 else if( nodeName == wxT( "ROUTECODE" ) )
1509 {
1510 ROUTECODE routecode;
1511 routecode.Parse( aChildNode, aContext );
1512 RouteCodes.insert( std::make_pair( routecode.ID, routecode ) );
1513 }
1514 else if( nodeName == wxT( "ATTRNAME" ) )
1515 {
1516 ATTRNAME attrname;
1517 attrname.Parse( aChildNode, aContext );
1518 AttributeNames.insert( std::make_pair( attrname.ID, attrname ) );
1519 }
1520 else if( nodeName == wxT( "NETCLASS" ) )
1521 {
1522 CADSTAR_NETCLASS netclass;
1523 netclass.Parse( aChildNode, aContext );
1524 NetClasses.insert( std::make_pair( netclass.ID, netclass ) );
1525 }
1526 else if( nodeName == wxT( "SPCCLASSNAME" ) )
1527 {
1528 SPCCLASSNAME spcclassname;
1529 spcclassname.Parse( aChildNode, aContext );
1530 SpacingClassNames.insert( std::make_pair( spcclassname.ID, spcclassname ) );
1531 }
1532 else
1533 {
1534 return false;
1535 }
1536
1537 return true;
1538}
1539
1540
1542{
1543 wxASSERT( aNode->GetName() == wxT( "SWAPRULE" ) );
1544
1546 wxString swapRuleStr = GetXmlAttributeIDString( aNode, 0 );
1547
1548 if( swapRuleStr == wxT( "NO_SWAP" ) )
1549 retval = SWAP_RULE::NO_SWAP;
1550 else if( swapRuleStr == wxT( "USE_SWAP_LAYER" ) )
1552 else
1553 WARN_UNKNOWN_PARAMETER_IO_ERROR( swapRuleStr, wxT( "SWAPRULE" ) );
1554
1555 return retval;
1556}
1557
1558
1560{
1561 wxASSERT( aNode->GetName() == wxT( "REUSEBLOCK" ) );
1562
1563 ID = GetXmlAttributeIDString( aNode, 0 );
1564 Name = GetXmlAttributeIDString( aNode, 1 );
1565 FileName = GetXmlAttributeIDString( aNode, 2 );
1566
1567 XNODE* cNode = aNode->GetChildren();
1568
1569 for( ; cNode; cNode = cNode->GetNext() )
1570 {
1571 wxString cNodeName = cNode->GetName();
1572
1573 if( cNodeName == wxT( "MIRROR" ) )
1574 Mirror = true;
1575 else if( cNodeName == wxT( "ORIENT" ) )
1576 OrientAngle = GetXmlAttributeIDLong( cNode, 0 );
1577 else
1578 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, wxT( "REUSEBLOCK" ) );
1579 }
1580}
1581
1582
1584{
1585 return ReuseBlockID == wxEmptyString && ItemReference == wxEmptyString;
1586}
1587
1588
1590{
1591 wxASSERT( aNode->GetName() == wxT( "REUSEBLOCKREF" ) );
1592
1595
1596 CheckNoChildNodes( aNode );
1597}
1598
1599
1601{
1602 wxASSERT( aNode->GetName() == wxT( "GROUP" ) );
1603
1604 ID = GetXmlAttributeIDString( aNode, 0 );
1605 Name = GetXmlAttributeIDString( aNode, 1 );
1606
1607 XNODE* cNode = aNode->GetChildren();
1608
1609 for( ; cNode; cNode = cNode->GetNext() )
1610 {
1611 wxString cNodeName = cNode->GetName();
1612
1613 if( cNodeName == wxT( "FIX" ) )
1614 Fixed = true;
1615 else if( cNodeName == wxT( "TRANSFER" ) )
1616 Transfer = true;
1617 else if( cNodeName == wxT( "GROUPREF" ) )
1618 GroupID = GetXmlAttributeIDString( cNode, 0 );
1619 else if( cNodeName == wxT( "REUSEBLOCKREF" ) )
1620 ReuseBlockRef.Parse( cNode, aContext );
1621 else
1622 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, wxT( "GROUP" ) );
1623 }
1624}
1625
1626
1628{
1629 wxASSERT( aNode->GetName() == wxT( "FIGURE" ) );
1630
1631 ID = GetXmlAttributeIDString( aNode, 0 );
1632 LineCodeID = GetXmlAttributeIDString( aNode, 1 );
1633 LayerID = GetXmlAttributeIDString( aNode, 2 );
1634
1635 XNODE* cNode = aNode->GetChildren();
1636 bool shapeIsInitialised = false; // Stop more than one Shape Object
1637 wxString location = wxString::Format( "Figure %s", ID );
1638
1639 if( !cNode )
1640 THROW_MISSING_NODE_IO_ERROR( wxT( "Shape" ), location );
1641
1642 for( ; cNode; cNode = cNode->GetNext() )
1643 {
1644 wxString cNodeName = cNode->GetName();
1645
1646 if( !shapeIsInitialised && Shape.IsShape( cNode ) )
1647 {
1648 Shape.Parse( cNode, aContext );
1649 shapeIsInitialised = true;
1650 }
1651 else if( cNodeName == wxT( "SWAPRULE" ) )
1652 {
1653 SwapRule = ParseSwapRule( cNode );
1654 }
1655 else if( cNodeName == wxT( "FIX" ) )
1656 {
1657 Fixed = true;
1658 }
1659 else if( cNodeName == wxT( "GROUPREF" ) )
1660 {
1661
1662 GroupID = GetXmlAttributeIDString( cNode, 0 );
1663 }
1664 else if( cNodeName == wxT( "REUSEBLOCKREF" ) )
1665 {
1666 ReuseBlockRef.Parse( cNode, aContext );
1667 }
1668 else if( cNodeName == wxT( "ATTR" ) )
1669 {
1670 ATTRIBUTE_VALUE attr;
1671 attr.Parse( cNode, aContext );
1672 AttributeValues.insert( std::make_pair( attr.AttributeID, attr ) );
1673 }
1674 else
1675 {
1677 }
1678 }
1679}
1680
1681
1683{
1684 Parse( aNode, aContext, true );
1685}
1686
1687
1689 bool aParseFields )
1690{
1691 wxASSERT( aNode->GetName() == wxT( "TEXT" ) );
1692
1693 ID = GetXmlAttributeIDString( aNode, 0 );
1694 Text = GetXmlAttributeIDString( aNode, 1 );
1695
1696 if( aParseFields )
1697 Text = ParseTextFields( Text, aContext );
1698
1699 TextCodeID = GetXmlAttributeIDString( aNode, 2 );
1700 LayerID = GetXmlAttributeIDString( aNode, 3 );
1701
1702 XNODE* cNode = aNode->GetChildren();
1703
1704 if( !cNode )
1705 THROW_MISSING_NODE_IO_ERROR( wxT( "PT" ), wxT( "TEXT" ) );
1706
1707 for( ; cNode; cNode = cNode->GetNext() )
1708 {
1709 wxString cNodeName = cNode->GetName();
1710
1711 if( cNodeName == wxT( "PT" ) )
1712 Position.Parse( cNode, aContext );
1713 else if( cNodeName == wxT( "ORIENT" ) )
1714 OrientAngle = GetXmlAttributeIDLong( cNode, 0 );
1715 else if( cNodeName == wxT( "MIRROR" ) )
1716 Mirror = true;
1717 else if( cNodeName == wxT( "FIX" ) )
1718 Fixed = true;
1719 else if( cNodeName == wxT( "SWAPRULE" ) )
1720 SwapRule = ParseSwapRule( cNode );
1721 else if( cNodeName == wxT( "ALIGN" ) )
1722 Alignment = ParseAlignment( cNode );
1723 else if( cNodeName == wxT( "JUSTIFICATION" ) )
1725 else if( cNodeName == wxT( "GROUPREF" ) )
1726 GroupID = GetXmlAttributeIDString( cNode, 0 );
1727 else if( cNodeName == wxT( "REUSEBLOCKREF" ) )
1728 ReuseBlockRef.Parse( cNode, aContext );
1729 else
1730 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, wxT( "TEXT" ) );
1731 }
1732}
1733
1734
1739
1740
1742{
1743 wxASSERT( aNode->GetName() == wxT( "SYMDEF" ) );
1744
1745 ID = GetXmlAttributeIDString( aNode, 0 );
1747 Alternate = GetXmlAttributeIDString( aNode, 2 );
1748}
1749
1750
1752{
1753 wxString cNodeName = aChildNode->GetName();
1754
1755 if( cNodeName == wxT( "PT" ) )
1756 {
1757 Origin.Parse( aChildNode, aContext );
1758 }
1759 else if( cNodeName == wxT( "STUB" ) )
1760 {
1761 Stub = true;
1762 }
1763 else if( cNodeName == wxT( "VERSION" ) )
1764 {
1765 Version = GetXmlAttributeIDLong( aChildNode, 0 );
1766 }
1767 else if( cNodeName == wxT( "FIGURE" ) )
1768 {
1769 FIGURE figure;
1770 figure.Parse( aChildNode, aContext );
1771 Figures.insert( std::make_pair( figure.ID, figure ) );
1772 }
1773 else if( cNodeName == wxT( "TEXT" ) )
1774 {
1775 TEXT txt;
1776 txt.Parse( aChildNode, aContext );
1777 Texts.insert( std::make_pair( txt.ID, txt ) );
1778 }
1779 else if( cNodeName == wxT( "TEXTLOC" ) )
1780 {
1781 TEXT_LOCATION textloc;
1782 textloc.Parse( aChildNode, aContext );
1783 TextLocations.insert( std::make_pair( textloc.AttributeID, textloc ) );
1784 }
1785 else if( cNodeName == wxT( "ATTR" ) )
1786 {
1787 ATTRIBUTE_VALUE attrVal;
1788 attrVal.Parse( aChildNode, aContext );
1789 AttributeValues.insert( std::make_pair( attrVal.AttributeID, attrVal ) );
1790 }
1791 else
1792 {
1793 return false;
1794 }
1795
1796 return true;
1797}
1798
1799
1801{
1802 wxASSERT( aNode->GetName() == wxT( "GATEDEFINITION" ) );
1803
1804 ID = GetXmlAttributeIDString( aNode, 0 );
1805 Name = GetXmlAttributeIDString( aNode, 1 );
1806 Alternate = GetXmlAttributeIDString( aNode, 2 );
1807 PinCount = GetXmlAttributeIDLong( aNode, 3, true /* is required */ );
1808
1809 CheckNoChildNodes( aNode );
1810}
1811
1812
1814{
1815 wxASSERT( aNode->GetName() == wxT( "PINTYPE" ) );
1816
1817 wxString pinTypeStr = GetXmlAttributeIDString( aNode, 0 );
1818
1819 std::map<wxString, CADSTAR_PIN_TYPE> pinTypeMap = {
1820 { wxT( "INPUT" ), CADSTAR_PIN_TYPE::PIN_INPUT },
1821 { wxT( "OUTPUT_OR" ), CADSTAR_PIN_TYPE::OUTPUT_OR },
1822 { wxT( "OUTPUT_NOT_OR" ), CADSTAR_PIN_TYPE::OUTPUT_NOT_OR },
1823 { wxT( "OUTPUT_NOT_NORM_OR" ), CADSTAR_PIN_TYPE::OUTPUT_NOT_NORM_OR },
1824 { wxT( "POWER" ), CADSTAR_PIN_TYPE::POWER },
1825 { wxT( "GROUND" ), CADSTAR_PIN_TYPE::GROUND },
1826 { wxT( "TRISTATE_BIDIR" ), CADSTAR_PIN_TYPE::TRISTATE_BIDIR },
1827 { wxT( "TRISTATE_INPUT" ), CADSTAR_PIN_TYPE::TRISTATE_INPUT },
1828 { wxT( "TRISTATE_DRIVER" ), CADSTAR_PIN_TYPE::TRISTATE_DRIVER } };
1829
1830 if( pinTypeMap.find( pinTypeStr ) == pinTypeMap.end() )
1831 {
1832 WARN_UNKNOWN_PARAMETER_IO_ERROR( pinTypeStr, aNode->GetName() );
1834 }
1835
1836 return pinTypeMap[pinTypeStr];
1837}
1838
1839
1841{
1842 wxASSERT( aNode->GetName() == wxT( "PARTDEFINITIONPIN" ) );
1843
1844 ID = GetXmlAttributeIDLong( aNode, 0 );
1845
1846 XNODE* cNode = aNode->GetChildren();
1847
1848 for( ; cNode; cNode = cNode->GetNext() )
1849 {
1850 wxString cNodeName = cNode->GetName();
1851
1852 if( cNodeName == wxT( "PINNAME" ) )
1853 {
1854 Name = GetXmlAttributeIDString( cNode, 0 );
1855 }
1856 else if( cNodeName == wxT( "PINLABEL" ) )
1857 {
1858 Label = GetXmlAttributeIDString( cNode, 0 );
1859 }
1860 else if( cNodeName == wxT( "PINSIGNAL" ) )
1861 {
1862 Signal = GetXmlAttributeIDString( cNode, 0 );
1863 }
1864 else if( cNodeName == wxT( "PINTERM" ) )
1865 {
1867 TerminalPin = GetXmlAttributeIDLong( cNode, 1 );
1868 }
1869 else if( cNodeName == wxT( "PINTYPE" ) )
1870 {
1871 Type = GetPinType( cNode );
1872 }
1873 else if( cNodeName == wxT( "PINLOAD" ) )
1874 {
1875 Load = GetXmlAttributeIDLong( cNode, 0 );
1876 }
1877 else if( cNodeName == wxT( "PINPOSITION" ) )
1878 {
1880 }
1881 else if( cNodeName == wxT( "PINIDENTIFIER" ) )
1882 {
1883 Identifier = GetXmlAttributeIDString( cNode, 0 );
1884 }
1885 else
1886 {
1887 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
1888 }
1889 }
1890}
1891
1892
1894{
1895 wxASSERT( aNode->GetName() == wxT( "PARTPIN" ) );
1896
1897 ID = GetXmlAttributeIDLong( aNode, 0 );
1898
1899 XNODE* cNode = aNode->GetChildren();
1900
1901 for( ; cNode; cNode = cNode->GetNext() )
1902 {
1903 wxString cNodeName = cNode->GetName();
1904
1905 if( cNodeName == wxT( "PINNAME" ) )
1906 Name = GetXmlAttributeIDString( cNode, 0 );
1907 else if( cNodeName == wxT( "PINTYPE" ) )
1908 Type = GetPinType( cNode );
1909 else if( cNodeName == wxT( "PINIDENTIFIER" ) )
1910 Identifier = GetXmlAttributeIDString( cNode, 0 );
1911 else
1912 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
1913 }
1914}
1915
1916
1918 PARSER_CONTEXT* aContext )
1919{
1920 wxASSERT( aNode->GetName() == wxT( "PINEQUIVALENCE" ) );
1921
1922 wxXmlAttribute* xmlAttribute = aNode->GetAttributes();
1923
1924 for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() )
1925 {
1926 if( !IsValidAttribute( xmlAttribute ) )
1927 continue;
1928
1929 long pinId;
1930
1931 if( !xmlAttribute->GetValue().ToLong( &pinId ) )
1932 THROW_UNKNOWN_PARAMETER_IO_ERROR( xmlAttribute->GetValue(), aNode->GetName() );
1933
1934 PinIDs.push_back( (PART_DEFINITION_PIN_ID) pinId );
1935 }
1936
1937 CheckNoChildNodes( aNode );
1938}
1939
1940
1942 PARSER_CONTEXT* aContext )
1943{
1944 wxASSERT( aNode->GetName() == wxT( "SWAPGATE" ) );
1945
1946 wxXmlAttribute* xmlAttribute = aNode->GetAttributes();
1947
1948 for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() )
1949 {
1950 if( !IsValidAttribute( xmlAttribute ) )
1951 continue;
1952
1953 long pinId;
1954
1955 if( !xmlAttribute->GetValue().ToLong( &pinId ) )
1956 THROW_UNKNOWN_PARAMETER_IO_ERROR( xmlAttribute->GetValue(), aNode->GetName() );
1957
1958 PinIDs.push_back( (PART_DEFINITION_PIN_ID) pinId );
1959 }
1960
1961 CheckNoChildNodes( aNode );
1962}
1963
1964
1966 PARSER_CONTEXT* aContext )
1967{
1968 wxASSERT( aNode->GetName() == wxT( "SWAPGROUP" ) );
1969
1970 GateName = GetXmlAttributeIDString( aNode, 0 );
1971
1972 XNODE* cNode = aNode->GetChildren();
1973
1974 for( ; cNode; cNode = cNode->GetNext() )
1975 {
1976 wxString cNodeName = cNode->GetName();
1977
1978 if( cNodeName == wxT( "EXTERNAL" ) )
1979 {
1980 External = true;
1981 }
1982 else if( cNodeName == wxT( "SWAPGATE" ) )
1983 {
1984 SWAP_GATE swapGate;
1985 swapGate.Parse( cNode, aContext );
1986 SwapGates.push_back( swapGate );
1987 }
1988 else
1989 {
1990 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
1991 }
1992 }
1993}
1994
1995
1997{
1998 wxASSERT( aNode->GetName() == wxT( "PARTDEFINITION" ) );
1999
2000 Name = GetXmlAttributeIDString( aNode, 0 );
2001
2002 XNODE* cNode = aNode->GetChildren();
2003
2004 for( ; cNode; cNode = cNode->GetNext() )
2005 {
2006 wxString cNodeName = cNode->GetName();
2007
2008 if( cNodeName == wxT( "HIDEPINNAMES" ) )
2009 {
2010 HidePinNames = true;
2011 }
2012 else if( cNodeName == wxT( "MAXPIN" ) )
2013 {
2014 MaxPinCount = GetXmlAttributeIDLong( cNode, 0 );
2015 }
2016 else if( cNodeName == wxT( "GATEDEFINITION" ) )
2017 {
2018 GATE gate;
2019 gate.Parse( cNode, aContext );
2020 GateSymbols.insert( std::make_pair( gate.ID, gate ) );
2021 }
2022 else if( cNodeName == wxT( "PARTDEFINITIONPIN" ) )
2023 {
2024 PIN pin;
2025 pin.Parse( cNode, aContext );
2026 Pins.insert( std::make_pair( pin.ID, pin ) );
2027 }
2028 else if( cNodeName == wxT( "ATTR" ) )
2029 {
2030 ATTRIBUTE_VALUE attr;
2031 attr.Parse( cNode, aContext );
2032 AttributeValues.insert( std::make_pair( attr.AttributeID, attr ) );
2033 }
2034 else if( cNodeName == wxT( "PINEQUIVALENCE" ) )
2035 {
2036 PIN_EQUIVALENCE pinEq;
2037 pinEq.Parse( cNode, aContext );
2038 PinEquivalences.push_back( pinEq );
2039 }
2040 else if( cNodeName == wxT( "SWAPGROUP" ) )
2041 {
2042 SWAP_GROUP swapGroup;
2043 swapGroup.Parse( cNode, aContext );
2044 SwapGroups.push_back( swapGroup );
2045 }
2046 else
2047 {
2048 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
2049 }
2050 }
2051}
2052
2053
2055{
2056 wxASSERT( aNode->GetName() == wxT( "PART" ) );
2057
2058 ID = GetXmlAttributeIDString( aNode, 0 );
2059 Name = GetXmlAttributeIDString( aNode, 1 );
2060
2061 XNODE* cNode = aNode->GetChildren();
2062
2063 for( ; cNode; cNode = cNode->GetNext() )
2064 {
2065 wxString cNodeName = cNode->GetName();
2066
2067 if( cNodeName == wxT( "VERSION" ) )
2068 {
2069 Version = GetXmlAttributeIDLong( cNode, 0 );
2070 }
2071 else if( cNodeName == wxT( "HIDEPINNAMES" ) )
2072 {
2073 HidePinNames = true;
2074 }
2075 else if( cNodeName == wxT( "PARTDEFINITION" ) )
2076 {
2077 Definition.Parse( cNode, aContext );
2078 }
2079 else if( cNodeName == wxT( "PARTPIN" ) )
2080 {
2081 PART_PIN pin;
2082 pin.Parse( cNode, aContext );
2083 PartPins.insert( std::make_pair( pin.ID, pin ) );
2084 }
2085 else if( cNodeName == wxT( "ATTR" ) )
2086 {
2087 ATTRIBUTE_VALUE attr;
2088 attr.Parse( cNode, aContext );
2089 AttributeValues.insert( std::make_pair( attr.AttributeID, attr ) );
2090 }
2091 else
2092 {
2093 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
2094 }
2095 }
2096}
2097
2098
2100{
2101 wxASSERT( aNode->GetName() == wxT( "PARTS" ) );
2102
2103 XNODE* cNode = aNode->GetChildren();
2104
2105 for( ; cNode; cNode = cNode->GetNext() )
2106 {
2107 wxString cNodeName = cNode->GetName();
2108
2109 if( cNodeName == wxT( "PART" ) )
2110 {
2111 PART part;
2112 part.Parse( cNode, aContext );
2113 PartDefinitions.insert( std::make_pair( part.ID, part ) );
2114 }
2115 else
2116 {
2117 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
2118 }
2119
2120 aContext->CheckPointCallback();
2121 }
2122}
2123
2124
2126 PARSER_CONTEXT* aContext )
2127{
2128 wxASSERT( aNode->GetName() == wxT( "JPT" ) );
2129
2130 ID = GetXmlAttributeIDString( aNode, 0 );
2131 LayerID = GetXmlAttributeIDString( aNode, 1 );
2132}
2133
2134
2136 PARSER_CONTEXT* aContext )
2137{
2138 wxString cNodeName = aChildNode->GetName();
2139
2140 if( cNodeName == wxT( "PT" ) )
2141 Location.Parse( aChildNode, aContext );
2142 else if( cNodeName == wxT( "FIX" ) )
2143 Fixed = true;
2144 else if( cNodeName == wxT( "GROUPREF" ) )
2145 GroupID = GetXmlAttributeIDString( aChildNode, 0 );
2146 else if( cNodeName == wxT( "REUSEBLOCKREF" ) )
2147 ReuseBlockRef.Parse( aChildNode, aContext );
2148 else
2149 return false;
2150
2151 return true;
2152}
2153
2154
2156{
2157 ParseIdentifiers( aNode, aContext );
2158 XNODE* cNode = aNode->GetChildren();
2159
2160 for( ; cNode; cNode = cNode->GetNext() )
2161 {
2162 if( ParseSubNode( cNode, aContext ) )
2163 continue;
2164 else
2165 WARN_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), aNode->GetName() );
2166 }
2167}
2168
2169
2171 PARSER_CONTEXT* aContext )
2172{
2173 wxASSERT( aNode->GetName() == wxT( "CONN" ) );
2174
2175 StartNode = GetXmlAttributeIDString( aNode, 0 );
2176 EndNode = GetXmlAttributeIDString( aNode, 1 );
2178}
2179
2180
2182 PARSER_CONTEXT* aContext )
2183{
2184 wxString cNodeName = aChildNode->GetName();
2185
2186 if( cNodeName == wxT( "FIX" ) )
2187 {
2188 Fixed = true;
2189 }
2190 else if( cNodeName == wxT( "HIDDEN" ) )
2191 {
2192 Hidden = true;
2193 }
2194 else if( cNodeName == wxT( "GROUPREF" ) )
2195 {
2196 GroupID = GetXmlAttributeIDString( aChildNode, 0 );
2197 }
2198 else if( cNodeName == wxT( "REUSEBLOCKREF" ) )
2199 {
2200 ReuseBlockRef.Parse( aChildNode, aContext );
2201 }
2202 else if( cNodeName == wxT( "ATTR" ) )
2203 {
2204 ATTRIBUTE_VALUE attrVal;
2205 attrVal.Parse( aChildNode, aContext );
2206 AttributeValues.insert( std::make_pair( attrVal.AttributeID, attrVal ) );
2207 }
2208 else
2209 {
2210 return false;
2211 }
2212
2213 return true;
2214}
2215
2216
2218{
2219 wxASSERT( aNode->GetName() == wxT( "NET" ) );
2220
2221 ID = GetXmlAttributeIDString( aNode, 0 );
2222}
2223
2224
2226{
2227 wxString cNodeName = aChildNode->GetName();
2228
2229 if( cNodeName == wxT( "NETCODE" ) )
2230 {
2231 RouteCodeID = GetXmlAttributeIDString( aChildNode, 0 );
2232 }
2233 else if( cNodeName == wxT( "SIGNAME" ) )
2234 {
2235 Name = GetXmlAttributeIDString( aChildNode, 0 );
2236 }
2237 else if( cNodeName == wxT( "SIGNUM" ) )
2238 {
2239 SignalNum = GetXmlAttributeIDLong( aChildNode, 0 );
2240 }
2241 else if( cNodeName == wxT( "HIGHLIT" ) )
2242 {
2243 Highlight = true;
2244 }
2245 else if( cNodeName == wxT( "JPT" ) )
2246 {
2247 JUNCTION jpt;
2248 jpt.Parse( aChildNode, aContext );
2249 Junctions.insert( std::make_pair( jpt.ID, jpt ) );
2250 }
2251 else if( cNodeName == wxT( "NETCLASSREF" ) )
2252 {
2253 NetClassID = GetXmlAttributeIDString( aChildNode, 0 );
2254 }
2255 else if( cNodeName == wxT( "SPACINGCLASS" ) )
2256 {
2257 SpacingClassID = GetXmlAttributeIDString( aChildNode, 0 );
2258 }
2259 else if( cNodeName == wxT( "ATTR" ) )
2260 {
2261 ATTRIBUTE_VALUE attrVal;
2262 attrVal.Parse( aChildNode, aContext );
2263 AttributeValues.insert( std::make_pair( attrVal.AttributeID, attrVal ) );
2264 }
2265 else
2266 {
2267 return false;
2268 }
2269
2270 return true;
2271}
2272
2273
2275{
2276 wxASSERT( aNode->GetName() == wxT( "DOCSYMBOL" ) );
2277
2278 ID = GetXmlAttributeIDString( aNode, 0 );
2279 SymdefID = GetXmlAttributeIDString( aNode, 1 );
2280 LayerID = GetXmlAttributeIDString( aNode, 2 );
2281
2282 XNODE* cNode = aNode->GetChildren();
2283 bool originParsed = false;
2284
2285 for( ; cNode; cNode = cNode->GetNext() )
2286 {
2287 wxString cNodeName = cNode->GetName();
2288
2289 if( !originParsed && cNodeName == wxT( "PT" ) )
2290 {
2291 Origin.Parse( cNode, aContext );
2292 originParsed = true;
2293 }
2294 else if( cNodeName == wxT( "GROUPREF" ) )
2295 {
2296 GroupID = GetXmlAttributeIDString( cNode, 0 );
2297 }
2298 else if( cNodeName == wxT( "REUSEBLOCKREF" ) )
2299 {
2300 ReuseBlockRef.Parse( cNode, aContext );
2301 }
2302 else if( cNodeName == wxT( "FIX" ) )
2303 {
2304 Fixed = true;
2305 }
2306 else if( cNodeName == wxT( "MIRROR" ) )
2307 {
2308 Mirror = true;
2309 }
2310 else if( cNodeName == wxT( "READABILITY" ) )
2311 {
2312 Readability = ParseReadability( cNode );
2313 }
2314 else if( cNodeName == wxT( "ORIENT" ) )
2315 {
2316 OrientAngle = GetXmlAttributeIDLong( cNode, 0 );
2317 }
2318 else if( cNodeName == wxT( "ATTR" ) )
2319 {
2320 ATTRIBUTE_VALUE attr;
2321 attr.Parse( cNode, aContext );
2322 AttributeValues.insert( std::make_pair( attr.AttributeID, attr ) );
2323 }
2324 else if( cNodeName == wxT( "SCALE" ) )
2325 {
2328 }
2329 else
2330 {
2331 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
2332 }
2333 }
2334
2335 if( !originParsed )
2336 THROW_MISSING_PARAMETER_IO_ERROR( wxT( "PT" ), aNode->GetName() );
2337}
2338
2339
2341{
2342 wxASSERT( aNode->GetName() == wxT( "DFLTSETTINGS" ) );
2343
2344 Color = GetXmlAttributeIDString( aNode, 0 );
2345
2346 XNODE* cNode = aNode->GetChildren();
2347
2348 for( ; cNode; cNode = cNode->GetNext() )
2349 {
2350 wxString cNodeName = cNode->GetName();
2351
2352 if( cNodeName == wxT( "INVISIBLE" ) )
2353 {
2354 IsVisible = false;
2355 }
2356 else
2357 {
2358 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
2359 }
2360 }
2361}
2362
2363
2365{
2366 wxASSERT( aNode->GetName() == wxT( "ATTRCOL" ) );
2367
2369 Color = GetXmlAttributeIDString( aNode, 1 );
2370
2371 XNODE* cNode = aNode->GetChildren();
2372
2373 for( ; cNode; cNode = cNode->GetNext() )
2374 {
2375 wxString cNodeName = cNode->GetName();
2376
2377 if( cNodeName == wxT( "INVISIBLE" ) )
2378 {
2379 IsVisible = false;
2380 }
2381 else if( cNodeName == wxT( "NOTPICKABLE" ) )
2382 {
2383 IsPickable = false;
2384 }
2385 else
2386 {
2387 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
2388 }
2389 }
2390}
2391
2392
2394{
2395 wxASSERT( aNode->GetName() == wxT( "ATTRCOLORS" ) );
2396
2397 XNODE* cNode = aNode->GetChildren();
2398
2399 for( ; cNode; cNode = cNode->GetNext() )
2400 {
2401 wxString cNodeName = cNode->GetName();
2402
2403 if( cNodeName == wxT( "DFLTSETTINGS" ) )
2404 {
2405 DefaultSettings.Parse( cNode, aContext );
2406 }
2407 else if( cNodeName == wxT( "ATTRCOL" ) )
2408 {
2409 ATTRCOL attrcol;
2410 attrcol.Parse( cNode, aContext );
2411 AttributeColors.insert( { attrcol.AttributeID, attrcol } );
2412 }
2413 else if( cNodeName == wxT( "INVISIBLE" ) )
2414 {
2415 IsVisible = false;
2416 }
2417 else
2418 {
2419 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
2420 }
2421 }
2422}
2423
2424
2426{
2427 wxASSERT( aNode->GetName() == wxT( "PARTNAMECOL" ) );
2428
2429 Color = GetXmlAttributeIDString( aNode, 0 );
2430
2431 XNODE* cNode = aNode->GetChildren();
2432
2433 for( ; cNode; cNode = cNode->GetNext() )
2434 {
2435 wxString cNodeName = cNode->GetName();
2436
2437 if( cNodeName == wxT( "INVISIBLE" ) )
2438 {
2439 IsVisible = false;
2440 }
2441 else if( cNodeName == wxT( "NOTPICKABLE" ) )
2442 {
2443 IsPickable = false;
2444 }
2445 else
2446 {
2447 WARN_UNKNOWN_NODE_IO_ERROR( cNodeName, aNode->GetName() );
2448 }
2449 }
2450}
2451
2452
2454{
2455 static const wxString c_numAttributes = wxT( "numAttributes" );
2456
2457 wxString result;
2458 long numAttributes = 0;
2459
2460 if( aNode->GetAttribute( c_numAttributes, &result ) )
2461 {
2462 numAttributes = wxAtol( result );
2463 aNode->DeleteAttribute( c_numAttributes );
2464 ++numAttributes;
2465 }
2466
2467#if wxUSE_UNICODE_WCHAR
2468 std::wstring numAttrStr = std::to_wstring( numAttributes );
2469#else
2470 std::string numAttrStr = std::to_string( numAttributes );
2471#endif
2472
2473 aNode->AddAttribute( c_numAttributes, numAttrStr );
2474
2475 wxString paramName = wxT( "attr" );
2476 paramName << numAttrStr;
2477
2478 aNode->AddAttribute( paramName, aValue );
2479}
2480
2481
2483 const wxString& aFileTypeIdentifier,
2484 PROGRESS_REPORTER* aProgressReporter )
2485{
2486 KEYWORD emptyKeywords[1] = {};
2487 XNODE* rootNode = nullptr;
2488 XNODE* cNode = nullptr;
2489 XNODE* iNode = nullptr;
2490 int tok;
2491 bool cadstarFileCheckDone = false;
2492 wxString str;
2493 wxCSConv win1252( wxT( "windows-1252" ) );
2494 wxMBConv* conv = &win1252; // Initial testing suggests file encoding to be Windows-1252
2495 // More samples required.
2496
2497 // Open the file and get the file size
2498 FILE* fp = wxFopen( aFileName, wxT( "rt" ) );
2499
2500 if( !fp )
2501 THROW_IO_ERRORF( _( "Cannot open file '%s'" ), aFileName );
2502
2503 fseek( fp, 0L, SEEK_END );
2504 long fileSize = ftell( fp );
2505 rewind( fp );
2506
2507 DSNLEXER lexer( emptyKeywords, 0, nullptr, fp, aFileName );
2508
2509 auto currentProgress =
2510 [&]() -> double
2511 {
2512 return static_cast<double>( ftell( fp ) ) / fileSize;
2513 };
2514
2515 double previousReportedProgress = -1.0;
2516
2517 while( ( tok = lexer.NextTok() ) != DSN_EOF )
2518 {
2519 if( aProgressReporter && ( currentProgress() - previousReportedProgress ) > 0.01 )
2520 {
2521 if( !aProgressReporter->KeepRefreshing() )
2522 {
2523 delete rootNode;
2524
2526 }
2527
2528 aProgressReporter->SetCurrentProgress( currentProgress() );
2529 previousReportedProgress = currentProgress();
2530 }
2531
2532 if( tok == DSN_RIGHT )
2533 {
2534 cNode = iNode;
2535 if( cNode )
2536 {
2537 iNode = cNode->GetParent();
2538 }
2539 else
2540 {
2541 //too many closing brackets
2542 delete rootNode;
2543 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2544 }
2545 }
2546 else if( tok == DSN_LEFT )
2547 {
2548 tok = lexer.NextTok();
2549 str = wxString( lexer.CurText(), *conv );
2550 cNode = new XNODE( wxXML_ELEMENT_NODE, str );
2551
2552 if( !rootNode )
2553 rootNode = cNode;
2554
2555 if( iNode )
2556 {
2557 //we will add it as attribute as well as child node
2558 InsertAttributeAtEnd( iNode, str );
2559 iNode->AddChild( cNode );
2560 }
2561 else if( !cadstarFileCheckDone )
2562 {
2563 if( cNode->GetName() != aFileTypeIdentifier )
2564 {
2565 delete rootNode;
2566 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2567 }
2568
2569 cadstarFileCheckDone = true;
2570 }
2571
2572 iNode = cNode;
2573 }
2574 else if( iNode )
2575 {
2576 str = wxString( lexer.CurText(), *conv );
2577 //Insert even if string is empty
2578 InsertAttributeAtEnd( iNode, str );
2579 }
2580 else
2581 {
2582 //not enough closing brackets
2583 delete rootNode;
2584 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2585 }
2586 }
2587
2588 // Not enough closing brackets
2589 if( iNode != nullptr )
2590 {
2591 delete rootNode;
2592 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2593 }
2594
2595 // Throw if no data was parsed
2596 if( rootNode )
2597 {
2598 return rootNode;
2599 }
2600 else
2601 {
2602 delete rootNode;
2603 THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) );
2604 }
2605
2606 return nullptr;
2607}
2608
2609
2610bool CADSTAR_ARCHIVE_PARSER::IsValidAttribute( wxXmlAttribute* aAttribute )
2611{
2612 return aAttribute->GetName() != wxT( "numAttributes" );
2613}
2614
2615
2617 bool aIsRequired )
2618{
2619#if wxUSE_UNICODE_WCHAR
2620 std::wstring idStr = std::to_wstring( aID );
2621#else
2622 std::string idStr = std::to_string( aID );
2623#endif
2624
2625 wxString attrName = wxS( "attr" );
2626 attrName << idStr;
2627
2628 wxString retVal;
2629
2630 if( !aNode->GetAttribute( attrName, &retVal ) )
2631 {
2632 if( aIsRequired )
2633 THROW_MISSING_PARAMETER_IO_ERROR( std::to_string( aID ), aNode->GetName() );
2634 else
2635 return wxEmptyString;
2636 }
2637
2638 return retVal;
2639}
2640
2641
2642long CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDLong( XNODE* aNode, unsigned int aID, bool aIsRequired )
2643{
2644 long retVal;
2645 bool success = GetXmlAttributeIDString( aNode, aID, aIsRequired ).ToLong( &retVal );
2646
2647 if( !success )
2648 {
2649 if( aIsRequired )
2650 THROW_PARSING_IO_ERROR( std::to_string( aID ), aNode->GetName() );
2651 else
2652 return UNDEFINED_VALUE;
2653 }
2654
2655 return retVal;
2656}
2657
2658
2660{
2661 if( aNode && aNode->GetChildren() )
2662 WARN_UNKNOWN_NODE_IO_ERROR( aNode->GetChildren()->GetName(), aNode->GetName() );
2663}
2664
2665
2667{
2668 if( aNode && aNode->GetNext() )
2669 WARN_UNKNOWN_NODE_IO_ERROR( aNode->GetNext()->GetName(), aNode->GetParent()->GetName() );
2670}
2671
2672
2674 EVALUE& aValueToParse )
2675{
2676 if( aNode->GetChildren()->GetName() == wxT( "E" ) )
2677 aValueToParse.Parse( aNode->GetChildren(), aContext );
2678 else
2679 WARN_UNKNOWN_NODE_IO_ERROR( aNode->GetChildren()->GetName(), aNode->GetName() );
2680}
2681
2682
2683std::vector<CADSTAR_ARCHIVE_PARSER::POINT> CADSTAR_ARCHIVE_PARSER::ParseAllChildPoints(
2684 XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes, int aExpectedNumPoints )
2685{
2686 std::vector<POINT> retVal;
2687
2688 XNODE* cNode = aNode->GetChildren();
2689
2690 for( ; cNode; cNode = cNode->GetNext() )
2691 {
2692 if( cNode->GetName() == wxT( "PT" ) )
2693 {
2694 POINT pt;
2695
2696 try
2697 {
2698 pt.Parse( cNode, aContext );
2699 }
2700 catch( const IO_ERROR& e )
2701 {
2702 reThrowWithParentContext( e, cNode, aNode );
2703 }
2704
2705 retVal.push_back( pt );
2706 }
2707 else if( aTestAllChildNodes )
2708 {
2709 WARN_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), aNode->GetName() );
2710 }
2711 }
2712
2713 if( aExpectedNumPoints != UNDEFINED_VALUE && retVal.size() != static_cast<size_t>( aExpectedNumPoints ) )
2714 {
2715 THROW_IO_ERRORF( _( "Unexpected number of points in '%s'. Found %d but expected %d." ),
2716 aNode->GetName(),
2717 retVal.size(),
2718 aExpectedNumPoints );
2719 }
2720
2721 return retVal;
2722}
2723
2724
2725std::vector<CADSTAR_ARCHIVE_PARSER::VERTEX> CADSTAR_ARCHIVE_PARSER::ParseAllChildVertices(
2726 XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes )
2727{
2728 std::vector<VERTEX> retVal;
2729
2730 XNODE* cNode = aNode->GetChildren();
2731
2732 for( ; cNode; cNode = cNode->GetNext() )
2733 {
2734 if( VERTEX::IsVertex( cNode ) )
2735 {
2736 VERTEX vertex;
2737
2738 try
2739 {
2740 vertex.Parse( cNode, aContext );
2741 }
2742 catch( const IO_ERROR& e )
2743 {
2744 reThrowWithParentContext( e, cNode, aNode );
2745 }
2746
2747 retVal.push_back( vertex );
2748 }
2749 else if( aTestAllChildNodes )
2750 {
2751 WARN_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), aNode->GetName() );
2752 }
2753 }
2754
2755 return retVal;
2756}
2757
2758
2759std::vector<CADSTAR_ARCHIVE_PARSER::CUTOUT> CADSTAR_ARCHIVE_PARSER::ParseAllChildCutouts(
2760 XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes )
2761{
2762 std::vector<CUTOUT> retVal;
2763
2764 XNODE* cNode = aNode->GetChildren();
2765
2766 for( ; cNode; cNode = cNode->GetNext() )
2767 {
2768 if( cNode->GetName() == wxT( "CUTOUT" ) )
2769 {
2770 CUTOUT cutout;
2771
2772 try
2773 {
2774 cutout.Parse( cNode, aContext );
2775 }
2776 catch( const IO_ERROR& e )
2777 {
2778 reThrowWithParentContext( e, cNode, aNode );
2779 }
2780
2781 retVal.push_back( cutout );
2782 }
2783 else if( aTestAllChildNodes )
2784 {
2785 WARN_UNKNOWN_NODE_IO_ERROR( cNode->GetName(), aNode->GetName() );
2786 }
2787 }
2788
2789 return retVal;
2790}
2791
2792
2794{
2795 XNODE* childNodes = aNode->GetChildren();
2796 long retval = 0;
2797
2798 for( ; childNodes; childNodes = childNodes->GetNext() )
2799 retval++;
2800
2801 return retval;
2802}
2803
2804
2806 XNODE* aRootNode, std::vector<wxString> aSubNodeChildrenToCount )
2807{
2808 XNODE* level1Node = aRootNode->GetChildren();
2809 long retval = 0;
2810
2811 for( ; level1Node; level1Node = level1Node->GetNext() )
2812 {
2813 for( wxString childNodeName : aSubNodeChildrenToCount )
2814 {
2815 if( level1Node->GetName() == childNodeName )
2816 retval += GetNumberOfChildNodes( level1Node );
2817 }
2818
2819 retval++;
2820 }
2821
2822 return retval;
2823}
2824
2825
2826wxString CADSTAR_ARCHIVE_PARSER::HandleTextOverbar( wxString aCadstarString )
2827{
2828 wxString escapedText = aCadstarString;
2829
2830 escapedText.Replace( wxT( "'" ), wxT( "~" ) );
2831
2832 return ConvertToNewOverbarNotation( escapedText );
2833}
2834
2835
2837{
2838 if( !aKiCadTextItem->GetText().IsEmpty() )
2839 {
2840 VECTOR2I positionOffset( 0, aKiCadTextItem->GetInterline( nullptr ) );
2841 RotatePoint( positionOffset, aKiCadTextItem->GetTextAngle() );
2842
2843 //Count num of additional lines
2844 wxString text = aKiCadTextItem->GetText();
2845 int numExtraLines = text.Replace( "\n", "\n" );
2846 numExtraLines -= text.at( text.size() - 1 ) == '\n'; // Ignore new line character at end
2847 positionOffset.x *= numExtraLines;
2848 positionOffset.y *= numExtraLines;
2849
2850 aKiCadTextItem->Offset( positionOffset );
2851 }
2852}
2853
2854
2855wxString CADSTAR_ARCHIVE_PARSER::generateLibName( const wxString& aRefName,
2856 const wxString& aAlternateName )
2857{
2858 if( aAlternateName.IsEmpty() )
2859 return EscapeString( aRefName, CTX_LIBID );
2860 else
2861 return EscapeString( aRefName + wxT( " (" ) + aAlternateName + wxT( ")" ), CTX_LIBID );
2862}
2863
2864
2866{
2867 if( m_progressReporter )
2868 {
2869 m_progressReporter->AdvanceProgress();
2870
2871 if( !m_progressReporter->KeepRefreshing() )
2873 }
2874}
CADSTAR_PIN_POSITION
Positioning of pin names can be in one of four quadrants.
@ OUTPUT_NOT_OR
Output pin not OR tieable.
@ TRISTATE_DRIVER
Tristate output pin.
@ OUTPUT_OR
Output pin OR tieable.
@ UNCOMMITTED
Uncommitted pin (default)
@ TRISTATE_INPUT
Tristate input pin.
@ TRISTATE_BIDIR
Tristate bi-directional driver pin.
@ OUTPUT_NOT_NORM_OR
Output pin not normally OR tieable.
static void reThrowWithParentContext(const IO_ERROR &aError, XNODE *aChildNode, XNODE *aParentNode)
Helper functions and common defines between schematic and PCB Archive files.
#define SYMBOL_NAME_ATTRID
Symbol Name attribute ID - used for placement of designators on the schematic.
#define SIGNALNAME_ORIGIN_ATTRID
#define WARN_UNKNOWN_NODE_IO_ERROR(nodename, location)
#define THROW_MISSING_NODE_IO_ERROR(nodename, location)
#define THROW_UNKNOWN_NODE_IO_ERROR(nodename, location)
#define LINK_ORIGIN_ATTRID
#define COMPONENT_NAME_2_ATTRID
Component Name 2 Attribute ID - typically used for indicating the placement of designators in placeme...
#define THROW_UNKNOWN_PARAMETER_IO_ERROR(param, location)
#define COMPONENT_NAME_ATTRID
Component Name Attribute ID - typically used for placement of designators on silk screen.
#define PART_NAME_ATTRID
#define WARN_UNKNOWN_PARAMETER_IO_ERROR(param, location)
#define THROW_MISSING_PARAMETER_IO_ERROR(param, location)
#define THROW_PARSING_IO_ERROR(param, location)
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.
@ 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.
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.
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.
@ PART_DEFINITION
From CADSTAR Help: Assigned to Parts library Definitions and displayed by the Library searcher.
@ BOTH
From CADSTAR Help: Assigned to both Schematic symbols and PCB components, and displayed on Schematic ...
@ COMPONENT
From CADSTAR Help: Assigned to PCB components and displayed on PCB designs.
@ SYMBOL
From CADSTAR Help: Assigned to Schematic Symbols and displayed on Schematic Designs.
@ PART_LIBRARY
From CADSTAR Help: Only used by non-Cadstar applications.
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.
@ SOLID
Filled closed shape (solid fill).
@ 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)
PROGRESS_REPORTER * m_progressReporter
static long GetNumberOfChildNodes(XNODE *aNode)
static void InsertAttributeAtEnd(XNODE *aNode, wxString aValue)
@ PART_DEFINITION
Only library Attributes.
Implement a lexical analyzer for the SPECCTRA DSN file format.
Definition dsnlexer.h:75
const char * CurText() const
Return a pointer to the current token's text.
Definition dsnlexer.h:415
int NextTok()
Return the next token found in the input file or DSN_EOF when reaching the end of file.
Definition dsnlexer.cpp:545
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
virtual void Offset(const VECTOR2I &aOffset)
Definition eda_text.cpp:576
virtual EDA_ANGLE GetTextAngle() const
Definition eda_text.h:178
int GetInterline(const RENDER_SETTINGS *aSettings) const
Return the distance between two lines of text.
Definition eda_text.cpp:748
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString Problem() const
what was the problem?
A progress reporter interface for use in multi-threaded environments.
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual const VECTOR2I GetPoint(int aIndex) const override
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Adds a new hole to the given outline (default: last) and returns its index.
An extension of wxXmlNode that can format its contents as KiCad-style s-expressions.
Definition xnode.h:67
XNODE * GetParent() const
Definition xnode.h:107
XNODE * GetChildren() const
Definition xnode.h:97
XNODE * GetNext() const
Definition xnode.h:102
void AddAttribute(const wxString &aName, const wxString &aValue) override
Definition xnode.cpp:88
@ DSN_LEFT
Definition dsnlexer.h:63
@ DSN_RIGHT
Definition dsnlexer.h:62
@ DSN_EOF
Definition dsnlexer.h:65
#define _(s)
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_IO_ERRORF(msg,...)
#define THROW_IO_CANCELLED()
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition macros.h:79
static wxString nodeName(const wxString &aSymbolPin)
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_LIBID
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)
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
SHAPE Shape
Uses the component's coordinate frame if within a component definition, otherwise uses the design's c...
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.
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 subnode="NETCLASSREF".
SPACING_CLASS_ID SpacingClassID
The net might not have a spacing class, in which case it will be wxEmptyString subnode="SPACINGCLASS"...
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.
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.
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.
TERMINAL_ID TerminalPin
(subnode="PINTERM", param1)
wxString Identifier
This should match a pad identifier in the component footprint.
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
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.
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.
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, defaults to equal height (1:1 aspect r...
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
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
< Nodename = "VARIANT" or "VMASTER" (master variant
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
VARIANT_ID ParentID
if empty, then this one is the master
Represents a vertex in a shape.
SHAPE_ARC BuildArc(const VECTOR2I &aPrevPoint, const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback) const
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void AppendToChain(SHAPE_LINE_CHAIN *aChainToAppendTo, const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, int aAccuracy) const
Hold a keyword string and its unique integer token.
Definition dsnlexer.h:36
KIBIS_PIN * pin
VECTOR2I location
wxString result
Test unit parsing edge cases and error handling.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:227
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708