25#include <wx/filename.h>
27#include <wx/xml/xml.h>
43const std::map<CADSTAR_ARCHIVE_PARSER::TEXT_FIELD_NAME, wxString>
45 { { TEXT_FIELD_NAME::DESIGN_TITLE, wxT(
"DESIGN_TITLE" ) },
46 { TEXT_FIELD_NAME::SHORT_JOBNAME, wxT(
"SHORT_JOBNAME" ) },
47 { TEXT_FIELD_NAME::LONG_JOBNAME, wxT(
"LONG_JOBNAME" ) },
48 { TEXT_FIELD_NAME::NUM_OF_SHEETS, wxT(
"##" ) },
49 { TEXT_FIELD_NAME::SHEET_NUMBER, wxT(
"#" ) },
50 { TEXT_FIELD_NAME::SHEET_NAME, wxT(
"SHEETNAME" ) },
51 { TEXT_FIELD_NAME::VARIANT_NAME, wxT(
"VARIANT_NAME" ) },
52 { TEXT_FIELD_NAME::VARIANT_DESCRIPTION, wxT(
"VARIANT_DESCRIPTION" ) },
53 { TEXT_FIELD_NAME::REG_USER, wxT(
"REG_USER" ) },
54 { TEXT_FIELD_NAME::COMPANY_NAME, wxT(
"COMPANY_NAME" ) },
55 { TEXT_FIELD_NAME::CURRENT_USER, wxT(
"CURRENT_USER" ) },
56 { TEXT_FIELD_NAME::DATE, wxT(
"DATE" ) },
57 { TEXT_FIELD_NAME::TIME, wxT(
"TIME" ) },
58 { TEXT_FIELD_NAME::MACHINE_NAME, wxT(
"MACHINE_NAME" ) } };
63 wxASSERT( aNode->GetName() == wxT(
"FORMAT" ) );
73 wxASSERT( aNode->GetName() == wxT(
"TIMESTAMP" ) );
87 wxASSERT( aNode->GetName() == wxT(
"HEADER" ) );
91 for( ; cNode; cNode = cNode->
GetNext() )
93 wxString nodeName = cNode->GetName();
95 if( nodeName == wxT(
"FORMAT" ) )
97 Format.Parse( cNode, aContext );
99 else if( nodeName == wxT(
"JOBFILE" ) )
103 else if( nodeName == wxT(
"JOBTITLE" ) )
107 else if( nodeName == wxT(
"GENERATOR" ) )
111 else if( nodeName == wxT(
"RESOLUTION" ) )
115 if( ( subNode->GetName() == wxT(
"METRIC" ) )
130 else if( nodeName == wxT(
"TIMESTAMP" ) )
132 Timestamp.Parse( cNode, aContext );
144 wxASSERT( aNode->GetName() == wxT(
"VMASTER" ) || aNode->GetName() == wxT(
"VARIANT" ) );
148 if( aNode->GetName() == wxT(
"VMASTER" ) )
164 wxASSERT( aNode->GetName() == wxT(
"VHIERARCHY" ) );
168 for( ; cNode; cNode = cNode->
GetNext() )
170 if( cNode->GetName() == wxT(
"VMASTER" ) || cNode->GetName() == wxT(
"VARIANT" ) )
173 variant.
Parse( cNode, aContext );
174 Variants.insert( std::make_pair( variant.
ID, variant ) );
186 wxASSERT( aNode->GetName() == wxT(
"LINECODE" ) );
196 if( !cNode || cNode->GetName() != wxT(
"STYLE" ) )
201 if( styleStr == wxT(
"SOLID" ) )
205 else if( styleStr == wxT(
"DASH" ) )
209 else if( styleStr == wxT(
"DASHDOT" ) )
213 else if( styleStr == wxT(
"DASHDOTDOT" ) )
217 else if( styleStr == wxT(
"DOT" ) )
224 wxString::Format(
"LINECODE -> %s", Name ) );
231 wxASSERT( aNode->GetName() == wxT(
"HATCH" ) );
238 if( !cNode || cNode->GetName() != wxT(
"ORIENT" ) )
247 wxASSERT( aNode->GetName() == wxT(
"HATCHCODE" ) );
253 wxString location = wxString::Format(
"HATCHCODE -> %s", Name );
255 for( ; cNode; cNode = cNode->
GetNext() )
257 if( cNode->GetName() != wxT(
"HATCH" ) )
261 hatch.
Parse( cNode, aContext );
262 Hatches.push_back( hatch );
269 wxASSERT( aNode->GetName() == wxT(
"FONT" ) );
277 for( ; cNode; cNode = cNode->
GetNext() )
279 wxString cNodeName = cNode->GetName();
281 if( cNodeName == wxT(
"ITALIC" ) )
283 else if( cNodeName == wxT(
"KERNING" ) )
293 wxASSERT( aNode->GetName() == wxT(
"TEXTCODE" ) );
306 if( cNode->GetName() == wxT(
"FONT" ) )
307 Font.Parse( cNode, aContext );
316 wxASSERT( aNode->GetName() == wxT(
"ROUTEREASSIGN" ) );
323 for( ; cNode; cNode = cNode->
GetNext() )
325 wxString cNodeName = cNode->GetName();
327 if( cNodeName == wxT(
"NECKWIDTH" ) )
329 else if( cNodeName == wxT(
"SROUTEWIDTH" ) )
331 else if( cNodeName == wxT(
"MINWIDTH" ) )
333 else if( cNodeName == wxT(
"MAXWIDTH" ) )
343 wxASSERT( aNode->GetName() == wxT(
"ROUTECODE" ) );
351 for( ; cNode; cNode = cNode->
GetNext() )
353 wxString cNodeName = cNode->GetName();
355 if( cNodeName == wxT(
"NECKWIDTH" ) )
359 else if( cNodeName == wxT(
"SROUTEWIDTH" ) )
363 else if( cNodeName == wxT(
"MINWIDTH" ) )
367 else if( cNodeName == wxT(
"MAXWIDTH" ) )
371 else if( cNodeName == wxT(
"ROUTEREASSIGN" ) )
374 routereassign.
Parse( cNode, aContext );
375 RouteReassigns.push_back( routereassign );
387 return Base * std::pow( 10.0, Exponent );
393 wxASSERT( aNode->GetName() == wxT(
"E" ) );
407 wxASSERT( aNode->GetName() == wxT(
"PT" ) );
416 wxASSERT( aNode->GetName() == wxT(
"PT" ) );
425 wxString aNodeName = aNode->GetName();
427 if( aNodeName == wxT(
"PT" ) || aNodeName == wxT(
"ACWARC" ) || aNodeName == wxT(
"CWARC" )
428 || aNodeName == wxT(
"CWSEMI" ) || aNodeName == wxT(
"ACWSEMI" ) )
441 wxASSERT( IsVertex( aNode ) );
443 wxString aNodeName = aNode->GetName();
445 if( aNodeName == wxT(
"PT" ) )
450 End.Parse( aNode, aContext );
452 else if( aNodeName == wxT(
"ACWARC" ) || aNodeName == wxT(
"CWARC" ) )
454 if( aNodeName == wxT(
"ACWARC" ) )
464 else if( aNodeName == wxT(
"ACWSEMI" ) || aNodeName == wxT(
"CWSEMI" ) )
466 if( aNodeName == wxT(
"ACWSEMI" ) )
480 wxASSERT_MSG(
true, wxT(
"Unknown VERTEX type" ) );
486 const std::function<
VECTOR2I(
const VECTOR2I& )> aCadstarToKicadPointCallback,
487 double aAccuracy )
const
491 aChainToAppendTo->
Append( aCadstarToKicadPointCallback( End ) );
495 wxCHECK_MSG( aChainToAppendTo->
PointCount() > 0, ,
496 "Can't append an arc to vertex to an empty chain" );
498 aChainToAppendTo->
Append( BuildArc( aChainToAppendTo->
GetPoint( -1 ), aCadstarToKicadPointCallback),
504 const std::function<
VECTOR2I(
const VECTOR2I& )> aCadstarToKicadPointCallback )
const
507 "Can't build an arc for a straight segment!" );
510 VECTOR2I endPoint = aCadstarToKicadPointCallback( End );
514 centerPoint = ( startPoint / 2 ) + ( endPoint / 2 );
516 centerPoint = aCadstarToKicadPointCallback( Center );
522 VECTOR2I transform = aCadstarToKicadPointCallback( { 500, 500 } )
523 - aCadstarToKicadPointCallback( { 0, 0 } );
525 if( ( transform.
x > 0 && transform.
y < 0 ) || ( transform.
x < 0 && transform.
y > 0 ) )
526 clockwise = !clockwise;
536 wxASSERT( aNode->GetName() == wxT(
"CUTOUT" ) );
544 wxString aNodeName = aNode->GetName();
546 if( aNodeName == wxT(
"OPENSHAPE" ) || aNodeName == wxT(
"OUTLINE" )
547 || aNodeName == wxT(
"SOLID" ) || aNodeName == wxT(
"HATCHED" ) )
560 wxASSERT( IsShape( aNode ) );
562 wxString aNodeName = aNode->GetName();
564 if( aNodeName == wxT(
"OPENSHAPE" ) )
569 HatchCodeID = wxEmptyString;
571 else if( aNodeName == wxT(
"OUTLINE" ) )
576 HatchCodeID = wxEmptyString;
578 else if( aNodeName == wxT(
"SOLID" ) )
583 HatchCodeID = wxEmptyString;
585 else if( aNodeName == wxT(
"HATCHED" ) )
594 wxASSERT_MSG(
true, wxT(
"Unknown SHAPE type" ) );
599 const std::function<
VECTOR2I(
const VECTOR2I& )> aCadstarToKicadPointCallback,
600 double aAccuracy )
const
604 if( Vertices.size() == 0 )
607 for(
const auto& vertex : Vertices )
608 vertex.AppendToChain( &outline, aCadstarToKicadPointCallback, aAccuracy );
623 const std::function<
VECTOR2I(
const VECTOR2I& )> aCadstarToKicadPointCallback,
624 double aAccuracy )
const
630 polyset.
AddOutline( OutlineAsChain( aCadstarToKicadPointCallback, aAccuracy ) );
632 for(
const auto& cutout : Cutouts )
636 if( cutout.Vertices.size() == 0 )
639 for(
const auto& cutoutVertex : cutout.Vertices )
640 cutoutVertex.AppendToChain( &hole, aCadstarToKicadPointCallback, aAccuracy );
645 cutout.Vertices.at( 0 ).AppendToChain( &hole, aCadstarToKicadPointCallback, aAccuracy );
656 wxASSERT( aNode->GetName() == wxT(
"UNITS" ) );
660 if( unit == wxT(
"CENTIMETER" ) )
662 else if( unit == wxT(
"INCH" ) )
664 else if( unit == wxT(
"METER" ) )
666 else if( unit == wxT(
"MICROMETRE" ) )
668 else if( unit == wxT(
"MM" ) )
670 else if( unit == wxT(
"THOU" ) )
672 else if( unit == wxT(
"DESIGN" ) )
683 wxASSERT( aNode->GetName() == wxT(
"ANGUNITS" ) );
687 if( angUnitStr == wxT(
"DEGREES" ) )
689 else if( angUnitStr == wxT(
"RADIANS" ) )
700 wxString aNodeName = aNode->GetName();
702 if( aNodeName == wxT(
"FRACTIONALGRID" ) || aNodeName == wxT(
"STEPGRID" ) )
711 wxASSERT( IsGrid( aNode ) );
713 wxString aNodeName = aNode->GetName();
715 if( aNodeName == wxT(
"FRACTIONALGRID" ) )
717 else if( aNodeName == wxT(
"STEPGRID" ) )
720 wxASSERT_MSG(
true, wxT(
"Unknown Grid Type" ) );
730 wxASSERT( aNode->GetName() == wxT(
"GRIDS" ) );
734 for( ; cNode; cNode = cNode->
GetNext() )
736 wxString cNodeName = cNode->GetName();
738 if( cNodeName == wxT(
"WORKINGGRID" ) )
745 workingGridNode->GetName(), wxT(
"GRIDS -> WORKINGGRID" ) );
749 WorkingGrid.Parse( workingGridNode, aContext );
752 else if( cNodeName == wxT(
"SCREENGRID" ) )
759 screenGridNode->GetName(), wxT(
"GRIDS -> SCREENGRID" ) );
763 ScreenGrid.Parse( screenGridNode, aContext );
769 userGrid.
Parse( cNode, aContext );
770 UserGrids.push_back( userGrid );
778 wxString cNodeName = aChildNode->GetName();
780 if( cNodeName == wxT(
"UNITS" ) )
784 else if( cNodeName == wxT(
"UNITSPRECISION" ) )
788 else if( cNodeName == wxT(
"INTERLINEGAP" ) )
792 else if( cNodeName == wxT(
"BARLINEGAP" ) )
796 else if( cNodeName == wxT(
"ALLOWBARTEXT" ) )
798 AllowBarredText =
true;
800 else if( cNodeName == wxT(
"ANGULARPRECISION" ) )
804 else if( cNodeName == wxT(
"DESIGNORIGIN" ) )
806 DesignOrigin.Parse( aChildNode->
GetChildren(), aContext );
808 else if( cNodeName == wxT(
"DESIGNAREA" ) )
811 DesignArea = std::make_pair( pts[0], pts[1] );
813 else if( cNodeName == wxT(
"DESIGNREF" ) )
815 DesignOrigin.Parse( aChildNode->
GetChildren(), aContext );
817 else if( cNodeName == wxT(
"DESIGNLIMIT" ) )
819 DesignLimit.Parse( aChildNode->
GetChildren(), aContext );
821 else if( cNodeName == wxT(
"PINNOOFFSET" ) )
825 else if( cNodeName == wxT(
"PINNOANGLE" ) )
840 wxASSERT( aNode->GetName() == wxT(
"SETTINGS" ) );
844 for( ; cNode; cNode = cNode->
GetNext() )
846 wxString cNodeName = cNode->GetName();
848 if( ParseSubNode( cNode, aContext ) )
859 static const std::map<TEXT_FIELD_NAME, wxString> txtTokens =
883 wxString remainingStr = aTextString;
886 while( remainingStr.size() > 0 )
889 size_t startpos = remainingStr.Find( wxT(
"<@" ) );
891 if(
static_cast<int>( startpos ) == wxNOT_FOUND )
894 returnStr += remainingStr;
899 returnStr += remainingStr.SubString( 0, startpos - 1 );
901 if( ( startpos + 2 ) >= remainingStr.size() )
904 remainingStr = remainingStr.Mid( startpos + 2 );
909 for( std::pair<TEXT_FIELD_NAME, wxString> txtF : txtTokens )
911 if( remainingStr.StartsWith( txtF.second ) )
913 foundField = txtF.first;
921 returnStr += wxT(
"<@" );
926 size_t endpos = remainingStr.Find( wxT(
"@>" ) );
928 if(
static_cast<int>( endpos ) == wxNOT_FOUND )
932 returnStr += wxT(
"<@" ) + remainingStr;
936 size_t valueStart = txtTokens.at( foundField ).size();
937 wxString fieldValue = remainingStr.SubString( valueStart, endpos - 1 );
943 wxASSERT_MSG( fieldValue.at( 0 ) ==
'"',
"Expected '\"' as the first character" );
945 size_t splitPos = fieldValue.find_first_of(
'"', 1 );
946 address = fieldValue.SubString( 1, splitPos - 1 );
951 wxASSERT_MSG( remainingStr.EndsWith( wxT(
"@>" ) ),
952 "Expected '@>' at the end of a hyperlink" );
954 fieldValue = remainingStr.SubString( valueStart + splitPos + 1,
955 remainingStr.Length() - 3 );
957 remainingStr = wxEmptyString;
961 fieldValue = fieldValue.Mid( splitPos + 1 );
1002 returnStr += fieldValue;
1007 wxFileName fn( address );
1008 wxString fieldFmt = wxT(
"FROM_FILE_%s_%s" );
1009 wxString fieldName = wxString::Format( fieldFmt, fn.GetName(), fn.GetExt() );
1018 fieldName = wxString::Format( fieldFmt, fn.GetName(), fn.GetExt() )
1019 + wxString::Format( wxT(
"_%d" ), version++ );
1023 returnStr += wxT(
"${" ) + fieldName + wxT(
"}" );
1035 wxFAIL_MSG(
"We should have already covered this scenario above" );
1040 if( ( endpos + 2 ) >= remainingStr.size() )
1043 remainingStr = remainingStr.Mid( endpos + 2 );
1052 wxASSERT( aNode->GetName() == wxT(
"ALIGN" ) );
1056 if( alignmentStr == wxT(
"BOTTOMCENTER" ) )
1058 else if( alignmentStr == wxT(
"BOTTOMLEFT" ) )
1060 else if( alignmentStr == wxT(
"BOTTOMRIGHT" ) )
1062 else if( alignmentStr == wxT(
"CENTERCENTER" ) )
1064 else if( alignmentStr == wxT(
"CENTERLEFT" ) )
1066 else if( alignmentStr == wxT(
"CENTERRIGHT" ) )
1068 else if( alignmentStr == wxT(
"TOPCENTER" ) )
1070 else if( alignmentStr == wxT(
"TOPLEFT" ) )
1072 else if( alignmentStr == wxT(
"TOPRIGHT" ) )
1084 wxASSERT( aNode->GetName() == wxT(
"JUSTIFICATION" ) );
1088 if( justificationStr == wxT(
"LEFT" ) )
1090 else if( justificationStr == wxT(
"RIGHT" ) )
1092 else if( justificationStr == wxT(
"CENTER" ) )
1103 wxASSERT( aNode->GetName() == wxT(
"READABILITY" ) );
1107 if( readabilityStr == wxT(
"BOTTOM_TO_TOP" ) )
1109 else if( readabilityStr == wxT(
"TOP_TO_BOTTOM" ) )
1129 wxString cNodeName = aChildNode->GetName();
1131 if( cNodeName == wxT(
"PT" ) )
1132 Position.Parse( aChildNode, aContext );
1133 else if( cNodeName == wxT(
"ORIENT" ) )
1135 else if( cNodeName == wxT(
"MIRROR" ) )
1137 else if( cNodeName == wxT(
"FIX" ) )
1139 else if( cNodeName == wxT(
"ALIGN" ) )
1141 else if( cNodeName == wxT(
"JUSTIFICATION" ) )
1152 wxASSERT( aNode->GetName() == wxT(
"ATTRLOC" ) );
1154 ParseIdentifiers( aNode, aContext );
1159 for( ; cNode; cNode = cNode->
GetNext() )
1161 if( ParseSubNode( cNode, aContext ) )
1174 wxASSERT( aNode->GetName() == wxT(
"COLUMNORDER" ) );
1185 wxASSERT( aNode->GetName() == wxT(
"COLUMNWIDTH" ) );
1196 wxASSERT( aNode->GetName() == wxT(
"ATTRNAME" ) );
1202 wxString location = wxString::Format(
"ATTRNAME -> %s", Name );
1204 for( ; cNode; cNode = cNode->
GetNext() )
1206 wxString cNodeName = cNode->GetName();
1208 if( cNodeName == wxT(
"ATTROWNER" ) )
1212 if( attOwnerVal == wxT(
"ALL_ITEMS" ) )
1214 else if( attOwnerVal == wxT(
"AREA" ) )
1216 else if( attOwnerVal == wxT(
"BOARD" ) )
1218 else if( attOwnerVal == wxT(
"COMPONENT" ) )
1220 else if( attOwnerVal == wxT(
"CONNECTION" ) )
1222 else if( attOwnerVal == wxT(
"COPPER" ) )
1224 else if( attOwnerVal == wxT(
"DOCSYMBOL" ) )
1226 else if( attOwnerVal == wxT(
"FIGURE" ) )
1228 else if( attOwnerVal == wxT(
"NET" ) )
1230 else if( attOwnerVal == wxT(
"NETCLASS" ) )
1232 else if( attOwnerVal == wxT(
"PART" ) )
1234 else if( attOwnerVal == wxT(
"PART_DEFINITION" ) )
1236 else if( attOwnerVal == wxT(
"PIN" ) )
1238 else if( attOwnerVal == wxT(
"SIGNALREF" ) )
1240 else if( attOwnerVal == wxT(
"SYMBOL" ) )
1242 else if( attOwnerVal == wxT(
"SYMDEF" ) )
1244 else if( attOwnerVal == wxT(
"TEMPLATE" ) )
1246 else if( attOwnerVal == wxT(
"TESTPOINT" ) )
1251 else if( cNodeName == wxT(
"ATTRUSAGE" ) )
1255 if( attUsageVal == wxT(
"BOTH" ) )
1257 else if( attUsageVal == wxT(
"COMPONENT" ) )
1259 else if( attUsageVal == wxT(
"PART_DEFINITION" ) )
1261 else if( attUsageVal == wxT(
"PART_LIBRARY" ) )
1263 else if( attUsageVal == wxT(
"SYMBOL" ) )
1268 else if( cNodeName == wxT(
"NOTRANSFER" ) )
1272 else if( cNodeName == wxT(
"COLUMNORDER" ) )
1275 cOrder.
Parse( cNode, aContext );
1276 ColumnOrders.push_back( cOrder );
1278 else if( cNodeName == wxT(
"COLUMNWIDTH" ) )
1281 cWidth.
Parse( cNode, aContext );
1282 ColumnWidths.push_back( cWidth );
1284 else if( cNodeName == wxT(
"COLUMNINVISIBLE" ) )
1286 ColumnInvisible =
true;
1298 wxASSERT( aNode->GetName() == wxT(
"ATTR" ) );
1305 for( ; cNode; cNode = cNode->
GetNext() )
1307 if( cNode->GetName() == wxT(
"READONLY" ) )
1311 else if( cNode->GetName() == wxT(
"ATTRLOC" ) )
1313 AttributeLocation.Parse( cNode, aContext );
1326 wxASSERT( aNode->GetName() == wxT(
"TEXTLOC" ) );
1329 bool attributeIDisSet =
false;
1331 if( attributeStr == wxT(
"PART_NAME" ) )
1334 attributeIDisSet =
true;
1336 else if( attributeStr == wxT(
"COMP_NAME" ) )
1339 attributeIDisSet =
true;
1341 else if( attributeStr == wxT(
"COMP_NAME2" ) )
1344 attributeIDisSet =
true;
1346 else if( attributeStr == wxT(
"SYMBOL_NAME" ) )
1349 attributeIDisSet =
true;
1351 else if( attributeStr == wxT(
"LINK_ORIGIN" ) )
1354 attributeIDisSet =
true;
1356 else if( attributeStr == wxT(
"SIGNALNAME_ORIGIN" ) )
1359 attributeIDisSet =
true;
1361 else if( attributeStr == wxT(
"ATTRREF" ) )
1364 attributeIDisSet =
false;
1377 for( ; cNode; cNode = cNode->
GetNext() )
1379 wxString cNodeName = cNode->GetName();
1381 if( ParseSubNode( cNode, aContext ) )
1385 else if( !attributeIDisSet && cNodeName == wxT(
"ATTRREF" ) )
1388 attributeIDisSet =
true;
1390 else if( cNodeName == wxT(
"ORIENT" ) )
1394 else if( cNodeName == wxT(
"MIRROR" ) )
1398 else if( cNodeName == wxT(
"FIX" ) )
1402 else if( cNodeName == wxT(
"ALIGN" ) )
1406 else if( cNodeName == wxT(
"JUSTIFICATION" ) )
1423 wxASSERT( aNode->GetName() == wxT(
"NETCLASS" ) );
1429 wxString location = wxString::Format(
"NETCLASS -> %s", Name );
1431 for( ; cNode; cNode = cNode->
GetNext() )
1433 wxString cNodeName = cNode->GetName();
1435 if( cNodeName == wxT(
"ATTR" ) )
1438 attribute_val.
Parse( cNode, aContext );
1439 Attributes.push_back( attribute_val );
1451 wxASSERT( aNode->GetName() == wxT(
"SPCCLASSNAME" ) );
1460 wxString nodeName = aChildNode->GetName();
1462 if( nodeName == wxT(
"LINECODE" ) )
1465 linecode.
Parse( aChildNode, aContext );
1466 LineCodes.insert( std::make_pair( linecode.
ID, linecode ) );
1468 else if( nodeName == wxT(
"HATCHCODE" ) )
1471 hatchcode.
Parse( aChildNode, aContext );
1472 HatchCodes.insert( std::make_pair( hatchcode.
ID, hatchcode ) );
1474 else if( nodeName == wxT(
"TEXTCODE" ) )
1477 textcode.
Parse( aChildNode, aContext );
1478 TextCodes.insert( std::make_pair( textcode.
ID, textcode ) );
1480 else if( nodeName == wxT(
"ROUTECODE" ) )
1483 routecode.
Parse( aChildNode, aContext );
1484 RouteCodes.insert( std::make_pair( routecode.
ID, routecode ) );
1486 else if( nodeName == wxT(
"ATTRNAME" ) )
1489 attrname.
Parse( aChildNode, aContext );
1490 AttributeNames.insert( std::make_pair( attrname.
ID, attrname ) );
1492 else if( nodeName == wxT(
"NETCLASS" ) )
1495 netclass.
Parse( aChildNode, aContext );
1496 NetClasses.insert( std::make_pair( netclass.
ID, netclass ) );
1498 else if( nodeName == wxT(
"SPCCLASSNAME" ) )
1501 spcclassname.
Parse( aChildNode, aContext );
1502 SpacingClassNames.insert( std::make_pair( spcclassname.
ID, spcclassname ) );
1515 wxASSERT( aNode->GetName() == wxT(
"SWAPRULE" ) );
1520 if( swapRuleStr == wxT(
"NO_SWAP" ) )
1522 else if( swapRuleStr == wxT(
"USE_SWAP_LAYER" ) )
1533 wxASSERT( aNode->GetName() == wxT(
"REUSEBLOCK" ) );
1541 for( ; cNode; cNode = cNode->
GetNext() )
1543 wxString cNodeName = cNode->GetName();
1545 if( cNodeName == wxT(
"MIRROR" ) )
1547 else if( cNodeName == wxT(
"ORIENT" ) )
1557 return ReuseBlockID == wxEmptyString && ItemReference == wxEmptyString;
1563 wxASSERT( aNode->GetName() == wxT(
"REUSEBLOCKREF" ) );
1574 wxASSERT( aNode->GetName() == wxT(
"GROUP" ) );
1581 for( ; cNode; cNode = cNode->
GetNext() )
1583 wxString cNodeName = cNode->GetName();
1585 if( cNodeName == wxT(
"FIX" ) )
1587 else if( cNodeName == wxT(
"TRANSFER" ) )
1589 else if( cNodeName == wxT(
"GROUPREF" ) )
1591 else if( cNodeName == wxT(
"REUSEBLOCKREF" ) )
1592 ReuseBlockRef.Parse( cNode, aContext );
1601 wxASSERT( aNode->GetName() == wxT(
"FIGURE" ) );
1608 bool shapeIsInitialised =
false;
1609 wxString location = wxString::Format(
"Figure %s",
ID );
1614 for( ; cNode; cNode = cNode->
GetNext() )
1616 wxString cNodeName = cNode->GetName();
1618 if( !shapeIsInitialised && Shape.IsShape( cNode ) )
1620 Shape.Parse( cNode, aContext );
1621 shapeIsInitialised =
true;
1623 else if( cNodeName == wxT(
"SWAPRULE" ) )
1627 else if( cNodeName == wxT(
"FIX" ) )
1631 else if( cNodeName == wxT(
"GROUPREF" ) )
1636 else if( cNodeName == wxT(
"REUSEBLOCKREF" ) )
1638 ReuseBlockRef.Parse( cNode, aContext );
1640 else if( cNodeName == wxT(
"ATTR" ) )
1643 attr.
Parse( cNode, aContext );
1644 AttributeValues.insert( std::make_pair( attr.
AttributeID, attr ) );
1656 Parse( aNode, aContext,
true );
1663 wxASSERT( aNode->GetName() == wxT(
"TEXT" ) );
1679 for( ; cNode; cNode = cNode->
GetNext() )
1681 wxString cNodeName = cNode->GetName();
1683 if( cNodeName == wxT(
"PT" ) )
1684 Position.Parse( cNode, aContext );
1685 else if( cNodeName == wxT(
"ORIENT" ) )
1687 else if( cNodeName == wxT(
"MIRROR" ) )
1689 else if( cNodeName == wxT(
"FIX" ) )
1691 else if( cNodeName == wxT(
"SWAPRULE" ) )
1693 else if( cNodeName == wxT(
"ALIGN" ) )
1695 else if( cNodeName == wxT(
"JUSTIFICATION" ) )
1697 else if( cNodeName == wxT(
"GROUPREF" ) )
1699 else if( cNodeName == wxT(
"REUSEBLOCKREF" ) )
1700 ReuseBlockRef.Parse( cNode, aContext );
1715 wxASSERT( aNode->GetName() == wxT(
"SYMDEF" ) );
1725 wxString cNodeName = aChildNode->GetName();
1727 if( cNodeName == wxT(
"PT" ) )
1729 Origin.Parse( aChildNode, aContext );
1731 else if( cNodeName == wxT(
"STUB" ) )
1735 else if( cNodeName == wxT(
"VERSION" ) )
1739 else if( cNodeName == wxT(
"FIGURE" ) )
1742 figure.
Parse( aChildNode, aContext );
1743 Figures.insert( std::make_pair( figure.
ID, figure ) );
1745 else if( cNodeName == wxT(
"TEXT" ) )
1748 txt.
Parse( aChildNode, aContext );
1749 Texts.insert( std::make_pair( txt.
ID, txt ) );
1751 else if( cNodeName == wxT(
"TEXTLOC" ) )
1754 textloc.
Parse( aChildNode, aContext );
1755 TextLocations.insert( std::make_pair( textloc.
AttributeID, textloc ) );
1757 else if( cNodeName == wxT(
"ATTR" ) )
1760 attrVal.
Parse( aChildNode, aContext );
1761 AttributeValues.insert( std::make_pair( attrVal.
AttributeID, attrVal ) );
1774 wxASSERT( aNode->GetName() == wxT(
"GATEDEFINITION" ) );
1787 wxASSERT( aNode->GetName() == wxT(
"PINTYPE" ) );
1791 std::map<wxString, CADSTAR_PIN_TYPE> pinTypeMap = {
1792 { wxT(
"INPUT" ), CADSTAR_PIN_TYPE::INPUT },
1793 { wxT(
"OUTPUT_OR" ), CADSTAR_PIN_TYPE::OUTPUT_OR },
1794 { wxT(
"OUTPUT_NOT_OR" ), CADSTAR_PIN_TYPE::OUTPUT_NOT_OR },
1795 { wxT(
"OUTPUT_NOT_NORM_OR" ), CADSTAR_PIN_TYPE::OUTPUT_NOT_NORM_OR },
1796 { wxT(
"POWER" ), CADSTAR_PIN_TYPE::POWER },
1797 { wxT(
"GROUND" ), CADSTAR_PIN_TYPE::GROUND },
1798 { wxT(
"TRISTATE_BIDIR" ), CADSTAR_PIN_TYPE::TRISTATE_BIDIR },
1799 { wxT(
"TRISTATE_INPUT" ), CADSTAR_PIN_TYPE::TRISTATE_INPUT },
1800 { wxT(
"TRISTATE_DRIVER" ), CADSTAR_PIN_TYPE::TRISTATE_DRIVER } };
1802 if( pinTypeMap.find( pinTypeStr ) == pinTypeMap.end() )
1805 return pinTypeMap[pinTypeStr];
1811 wxASSERT( aNode->GetName() == wxT(
"PARTDEFINITIONPIN" ) );
1817 for( ; cNode; cNode = cNode->
GetNext() )
1819 wxString cNodeName = cNode->GetName();
1821 if( cNodeName == wxT(
"PINNAME" ) )
1825 else if( cNodeName == wxT(
"PINLABEL" ) )
1829 else if( cNodeName == wxT(
"PINSIGNAL" ) )
1833 else if( cNodeName == wxT(
"PINTERM" ) )
1838 else if( cNodeName == wxT(
"PINTYPE" ) )
1840 Type = GetPinType( cNode );
1842 else if( cNodeName == wxT(
"PINLOAD" ) )
1846 else if( cNodeName == wxT(
"PINPOSITION" ) )
1850 else if( cNodeName == wxT(
"PINIDENTIFIER" ) )
1864 wxASSERT( aNode->GetName() == wxT(
"PARTPIN" ) );
1870 for( ; cNode; cNode = cNode->
GetNext() )
1872 wxString cNodeName = cNode->GetName();
1874 if( cNodeName == wxT(
"PINNAME" ) )
1876 else if( cNodeName == wxT(
"PINTYPE" ) )
1877 Type = GetPinType( cNode );
1878 else if( cNodeName == wxT(
"PINIDENTIFIER" ) )
1889 wxASSERT( aNode->GetName() == wxT(
"PINEQUIVALENCE" ) );
1891 wxXmlAttribute* xmlAttribute = aNode->GetAttributes();
1893 for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() )
1900 if( !xmlAttribute->GetValue().ToLong( &pinId ) )
1913 wxASSERT( aNode->GetName() == wxT(
"SWAPGATE" ) );
1915 wxXmlAttribute* xmlAttribute = aNode->GetAttributes();
1917 for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() )
1924 if( !xmlAttribute->GetValue().ToLong( &pinId ) )
1937 wxASSERT( aNode->GetName() == wxT(
"SWAPGROUP" ) );
1943 for( ; cNode; cNode = cNode->
GetNext() )
1945 wxString cNodeName = cNode->GetName();
1947 if( cNodeName == wxT(
"EXTERNAL" ) )
1951 else if( cNodeName == wxT(
"SWAPGATE" ) )
1954 swapGate.
Parse( cNode, aContext );
1955 SwapGates.push_back( swapGate );
1967 wxASSERT( aNode->GetName() == wxT(
"PARTDEFINITION" ) );
1973 for( ; cNode; cNode = cNode->
GetNext() )
1975 wxString cNodeName = cNode->GetName();
1977 if( cNodeName == wxT(
"HIDEPINNAMES" ) )
1979 HidePinNames =
true;
1981 else if( cNodeName == wxT(
"MAXPIN" ) )
1985 else if( cNodeName == wxT(
"GATEDEFINITION" ) )
1988 gate.
Parse( cNode, aContext );
1989 GateSymbols.insert( std::make_pair( gate.
ID, gate ) );
1991 else if( cNodeName == wxT(
"PARTDEFINITIONPIN" ) )
1994 pin.Parse( cNode, aContext );
1995 Pins.insert( std::make_pair(
pin.ID,
pin ) );
1997 else if( cNodeName == wxT(
"ATTR" ) )
2000 attr.
Parse( cNode, aContext );
2001 AttributeValues.insert( std::make_pair( attr.
AttributeID, attr ) );
2003 else if( cNodeName == wxT(
"PINEQUIVALENCE" ) )
2006 pinEq.
Parse( cNode, aContext );
2007 PinEquivalences.push_back( pinEq );
2009 else if( cNodeName == wxT(
"SWAPGROUP" ) )
2012 swapGroup.
Parse( cNode, aContext );
2013 SwapGroups.push_back( swapGroup );
2025 wxASSERT( aNode->GetName() == wxT(
"PART" ) );
2032 for( ; cNode; cNode = cNode->
GetNext() )
2034 wxString cNodeName = cNode->GetName();
2036 if( cNodeName == wxT(
"VERSION" ) )
2040 else if( cNodeName == wxT(
"HIDEPINNAMES" ) )
2042 HidePinNames =
true;
2044 else if( cNodeName == wxT(
"PARTDEFINITION" ) )
2046 Definition.Parse( cNode, aContext );
2048 else if( cNodeName == wxT(
"PARTPIN" ) )
2051 pin.Parse( cNode, aContext );
2052 PartPins.insert( std::make_pair(
pin.ID,
pin ) );
2054 else if( cNodeName == wxT(
"ATTR" ) )
2057 attr.
Parse( cNode, aContext );
2058 AttributeValues.insert( std::make_pair( attr.
AttributeID, attr ) );
2070 wxASSERT( aNode->GetName() == wxT(
"PARTS" ) );
2074 for( ; cNode; cNode = cNode->
GetNext() )
2076 wxString cNodeName = cNode->GetName();
2078 if( cNodeName == wxT(
"PART" ) )
2081 part.
Parse( cNode, aContext );
2082 PartDefinitions.insert( std::make_pair( part.
ID, part ) );
2097 wxASSERT( aNode->GetName() == wxT(
"JPT" ) );
2107 wxString cNodeName = aChildNode->GetName();
2109 if( cNodeName == wxT(
"PT" ) )
2110 Location.Parse( aChildNode, aContext );
2111 else if( cNodeName == wxT(
"FIX" ) )
2113 else if( cNodeName == wxT(
"GROUPREF" ) )
2115 else if( cNodeName == wxT(
"REUSEBLOCKREF" ) )
2116 ReuseBlockRef.Parse( aChildNode, aContext );
2126 ParseIdentifiers( aNode, aContext );
2129 for( ; cNode; cNode = cNode->
GetNext() )
2131 if( ParseSubNode( cNode, aContext ) )
2142 wxASSERT( aNode->GetName() == wxT(
"CONN" ) );
2153 wxString cNodeName = aChildNode->GetName();
2155 if( cNodeName == wxT(
"FIX" ) )
2159 else if( cNodeName == wxT(
"HIDDEN" ) )
2163 else if( cNodeName == wxT(
"GROUPREF" ) )
2167 else if( cNodeName == wxT(
"REUSEBLOCKREF" ) )
2169 ReuseBlockRef.Parse( aChildNode, aContext );
2171 else if( cNodeName == wxT(
"ATTR" ) )
2174 attrVal.
Parse( aChildNode, aContext );
2175 AttributeValues.insert( std::make_pair( attrVal.
AttributeID, attrVal ) );
2188 wxASSERT( aNode->GetName() == wxT(
"NET" ) );
2196 wxString cNodeName = aChildNode->GetName();
2198 if( cNodeName == wxT(
"NETCODE" ) )
2202 else if( cNodeName == wxT(
"SIGNAME" ) )
2206 else if( cNodeName == wxT(
"SIGNUM" ) )
2210 else if( cNodeName == wxT(
"HIGHLIT" ) )
2214 else if( cNodeName == wxT(
"JPT" ) )
2217 jpt.
Parse( aChildNode, aContext );
2218 Junctions.insert( std::make_pair( jpt.
ID, jpt ) );
2220 else if( cNodeName == wxT(
"NETCLASSREF" ) )
2224 else if( cNodeName == wxT(
"SPACINGCLASS" ) )
2228 else if( cNodeName == wxT(
"ATTR" ) )
2231 attrVal.
Parse( aChildNode, aContext );
2232 AttributeValues.insert( std::make_pair( attrVal.
AttributeID, attrVal ) );
2245 wxASSERT( aNode->GetName() == wxT(
"DOCSYMBOL" ) );
2252 bool originParsed =
false;
2254 for( ; cNode; cNode = cNode->
GetNext() )
2256 wxString cNodeName = cNode->GetName();
2258 if( !originParsed && cNodeName == wxT(
"PT" ) )
2260 Origin.Parse( cNode, aContext );
2261 originParsed =
true;
2263 else if( cNodeName == wxT(
"GROUPREF" ) )
2267 else if( cNodeName == wxT(
"REUSEBLOCKREF" ) )
2269 ReuseBlockRef.Parse( cNode, aContext );
2271 else if( cNodeName == wxT(
"FIX" ) )
2275 else if( cNodeName == wxT(
"MIRROR" ) )
2279 else if( cNodeName == wxT(
"READABILITY" ) )
2283 else if( cNodeName == wxT(
"ORIENT" ) )
2287 else if( cNodeName == wxT(
"ATTR" ) )
2290 attr.
Parse( cNode, aContext );
2291 AttributeValues.insert( std::make_pair( attr.
AttributeID, attr ) );
2293 else if( cNodeName == wxT(
"SCALE" ) )
2311 wxASSERT( aNode->GetName() == wxT(
"DFLTSETTINGS" ) );
2317 for( ; cNode; cNode = cNode->
GetNext() )
2319 wxString cNodeName = cNode->GetName();
2321 if( cNodeName == wxT(
"INVISIBLE" ) )
2335 wxASSERT( aNode->GetName() == wxT(
"ATTRCOL" ) );
2342 for( ; cNode; cNode = cNode->
GetNext() )
2344 wxString cNodeName = cNode->GetName();
2346 if( cNodeName == wxT(
"INVISIBLE" ) )
2350 else if( cNodeName == wxT(
"NOTPICKABLE" ) )
2364 wxASSERT( aNode->GetName() == wxT(
"ATTRCOLORS" ) );
2368 for( ; cNode; cNode = cNode->
GetNext() )
2370 wxString cNodeName = cNode->GetName();
2372 if( cNodeName == wxT(
"DFLTSETTINGS" ) )
2374 DefaultSettings.Parse( cNode, aContext );
2376 else if( cNodeName == wxT(
"ATTRCOL" ) )
2379 attrcol.
Parse( cNode, aContext );
2380 AttributeColors.insert( { attrcol.
AttributeID, attrcol } );
2382 else if( cNodeName == wxT(
"INVISIBLE" ) )
2396 wxASSERT( aNode->GetName() == wxT(
"PARTNAMECOL" ) );
2402 for( ; cNode; cNode = cNode->
GetNext() )
2404 wxString cNodeName = cNode->GetName();
2406 if( cNodeName == wxT(
"INVISIBLE" ) )
2410 else if( cNodeName == wxT(
"NOTPICKABLE" ) )
2424 static const wxString c_numAttributes = wxT(
"numAttributes" );
2427 long numAttributes = 0;
2429 if( aNode->GetAttribute( c_numAttributes, &result ) )
2431 numAttributes = wxAtol( result );
2432 aNode->DeleteAttribute( c_numAttributes );
2436#if wxUSE_UNICODE_WCHAR
2437 std::wstring numAttrStr = std::to_wstring( numAttributes );
2439 std::string numAttrStr = std::to_string( numAttributes );
2442 aNode->AddAttribute( c_numAttributes, numAttrStr );
2444 wxString paramName = wxT(
"attr" );
2445 paramName << numAttrStr;
2447 aNode->AddAttribute( paramName, aValue );
2454 KEYWORD emptyKeywords[1] = {};
2455 XNODE* rootNode =
nullptr;
2456 XNODE* cNode =
nullptr;
2457 XNODE* iNode =
nullptr;
2459 bool cadstarFileCheckDone =
false;
2461 wxCSConv win1252( wxT(
"windows-1252" ) );
2462 wxMBConv* conv = &win1252;
2466 FILE* fp = wxFopen( aFileName, wxT(
"rt" ) );
2469 THROW_IO_ERROR( wxString::Format(
_(
"Cannot open file '%s'" ), aFileName ) );
2471 fseek( fp, 0L, SEEK_END );
2472 long fileSize = ftell( fp );
2475 DSNLEXER lexer( emptyKeywords, 0,
nullptr, fp, aFileName );
2477 auto currentProgress = [&]() ->
double
2479 return static_cast<double>( ftell( fp ) ) / fileSize;
2482 double previousReportedProgress = -1.0;
2486 if( aProgressReporter && ( currentProgress() - previousReportedProgress ) > 0.01 )
2495 previousReportedProgress = currentProgress();
2509 THROW_IO_ERROR(
_(
"The selected file is not valid or might be corrupt!" ) );
2515 str = wxString( lexer.
CurText(), *conv );
2516 cNode =
new XNODE( wxXML_ELEMENT_NODE, str );
2525 iNode->AddChild( cNode );
2527 else if( !cadstarFileCheckDone )
2529 if( cNode->GetName() != aFileTypeIdentifier )
2532 THROW_IO_ERROR(
_(
"The selected file is not valid or might be corrupt!" ) );
2535 cadstarFileCheckDone =
true;
2542 str = wxString( lexer.
CurText(), *conv );
2550 THROW_IO_ERROR(
_(
"The selected file is not valid or might be corrupt!" ) );
2555 if( iNode !=
nullptr )
2558 THROW_IO_ERROR(
_(
"The selected file is not valid or might be corrupt!" ) );
2569 THROW_IO_ERROR(
_(
"The selected file is not valid or might be corrupt!" ) );
2578 return aAttribute->GetName() != wxT(
"numAttributes" );
2585#if wxUSE_UNICODE_WCHAR
2586 std::wstring idStr = std::to_wstring( aID );
2588 std::string idStr = std::to_string( aID );
2591 wxString attrName = wxS(
"attr" );
2596 if( !aNode->GetAttribute( attrName, &retVal ) )
2601 return wxEmptyString;
2635 if( aNode && aNode->
GetNext() )
2643 if( aNode->
GetChildren()->GetName() == wxT(
"E" ) )
2653 std::vector<POINT> retVal;
2657 for( ; cNode; cNode = cNode->
GetNext() )
2659 if( cNode->GetName() == wxT(
"PT" ) )
2663 pt.
Parse( cNode, aContext );
2664 retVal.push_back( pt );
2666 else if( aTestAllChildNodes )
2673 && retVal.size() !=
static_cast<size_t>( aExpectedNumPoints ) )
2676 _(
"Unexpected number of points in '%s'. Found %d but expected %d." ),
2677 aNode->GetName(), retVal.size(), aExpectedNumPoints ) );
2687 std::vector<VERTEX> retVal;
2691 for( ; cNode; cNode = cNode->
GetNext() )
2697 vertex.
Parse( cNode, aContext );
2698 retVal.push_back( vertex );
2700 else if( aTestAllChildNodes )
2713 std::vector<CUTOUT> retVal;
2717 for( ; cNode; cNode = cNode->
GetNext() )
2719 if( cNode->GetName() == wxT(
"CUTOUT" ) )
2723 cutout.
Parse( cNode, aContext );
2724 retVal.push_back( cutout );
2726 else if( aTestAllChildNodes )
2741 for( ; childNodes; childNodes = childNodes->
GetNext() )
2753 for( ; level1Node; level1Node = level1Node->
GetNext() )
2755 for( wxString childNodeName : aSubNodeChildrenToCount )
2757 if( level1Node->GetName() == childNodeName )
2770 wxString escapedText = aCadstarString;
2772 escapedText.Replace( wxT(
"'" ), wxT(
"~" ) );
2780 if( !aKiCadTextItem->
GetText().IsEmpty() )
2787 int numExtraLines =
text.Replace(
"\n",
"\n" );
2788 numExtraLines -=
text.at(
text.size() - 1 ) ==
'\n';
2789 positionOffset.
x *= numExtraLines;
2790 positionOffset.
y *= numExtraLines;
2792 aKiCadTextItem->
Offset( positionOffset );
2798 const wxString& aAlternateName )
2800 if( aAlternateName.IsEmpty() )
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
reads a model file and creates a generic display structure
CADSTAR_PIN_POSITION
Positioning of pin names can be in one of four quadrants.
CADSTAR_PIN_TYPE
file: cadstar_archive_objects.h Contains common object definitions
Helper functions and common 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 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 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.
@ ANTICLOCKWISE_SEMICIRCLE
@ STEPGRID
Param1 = X Step, Param2 = Y Step. A standard x,y grid.
@ FRACTIONALGRID
Param1 = Units, Param2 = Divisor.
SWAP_RULE
Corresponds to "Display when" Item property.
@ USE_SWAP_LAYER
Display when Mirrored.
@ NO_SWAP
Display when Unmirrored.
static UNITS ParseUnits(XNODE *aNode)
static ALIGNMENT ParseAlignment(XNODE *aNode)
static const std::map< TEXT_FIELD_NAME, wxString > CADSTAR_TO_KICAD_FIELDS
Map between CADSTAR fields and KiCad text variables.
TEXT_FIELD_NAME
These are special fields in text objects enclosed between the tokens '<@' and '>' such as <@[FIELD_NA...
@ NONE
Synthetic for flagging.
static SWAP_RULE ParseSwapRule(XNODE *aNode)
ALIGNMENT
From CADSTAR Help: "Text Alignment enables you to define the position of an alignment origin for all ...
@ NO_ALIGNMENT
NO_ALIGNMENT has different meaning depending on the object type.
static const long UNDEFINED_VALUE
static wxString generateLibName(const wxString &aRefName, const wxString &aAlternateName)
static void CheckNoNextNodes(XNODE *aNode)
static std::vector< CUTOUT > ParseAllChildCutouts(XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false)
if no children are present, it just returns an empty vector (without throwing an exception)
static XNODE * LoadArchiveFile(const wxString &aFileName, const wxString &aFileTypeIdentifier, PROGRESS_REPORTER *aProgressReporter=nullptr)
Reads a CADSTAR Archive file (S-parameter format)
static JUSTIFICATION ParseJustification(XNODE *aNode)
static wxString ParseTextFields(const wxString &aTextString, PARSER_CONTEXT *aParserContext)
Replaces CADSTAR fields for the equivalent in KiCad and stores the field values in aParserContext.
@ 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)
Corrects the position of a text element that had NO_ALIGNMENT in CADSTAR.
static ANGUNITS ParseAngunits(XNODE *aNode)
long PART_DEFINITION_PIN_ID
Pin identifier in the part definition.
@ OUTLINE
Unfilled closed shape.
@ OPENSHAPE
Unfilled open shape. Cannot have cutouts.
@ 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 cancelled.
static bool IsValidAttribute(wxXmlAttribute *aAttribute)
static READABILITY ParseReadability(XNODE *aNode)
static std::vector< POINT > ParseAllChildPoints(XNODE *aNode, PARSER_CONTEXT *aContext, bool aTestAllChildNodes=false, int aExpectedNumPoints=UNDEFINED_VALUE)
if no children are present, it just returns an empty vector (without throwing an exception)
@ DESIGN
Inherits from design units (assumed Assignments->Technology->Units)
static wxString HandleTextOverbar(wxString aCadstarString)
Convert a string with CADSTAR overbar characters to equivalent in KiCad.
static void CheckNoChildNodes(XNODE *aNode)
static long GetXmlAttributeIDLong(XNODE *aNode, unsigned int aID, bool aIsRequired=true)
JUSTIFICATION
From CADSTAR Help: "Multi Line Text can also be justified as Left, Centre or Right.
static void ParseChildEValue(XNODE *aNode, PARSER_CONTEXT *aContext, EVALUE &aValueToParse)
static long GetNumberOfStepsForReporting(XNODE *aRootNode, std::vector< wxString > aSubNodeChildrenToCount)
PROGRESS_REPORTER * m_progressReporter
static long GetNumberOfChildNodes(XNODE *aNode)
static void InsertAttributeAtEnd(XNODE *aNode, wxString aValue)
@ PART_DEFINITION
Only library Attributes.
@ PART
Only library Attributes.
Implement a lexical analyzer for the SPECCTRA DSN file format.
const char * CurText() const
Return a pointer to the current token's text.
int NextTok()
Return the next token found in the input file or DSN_EOF when reaching the end of file.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
const EDA_ANGLE & GetTextAngle() const
virtual const wxString & GetText() const
Return the string associated with the text object.
int GetInterline() const
Return the distance between two lines of text.
void Offset(const VECTOR2I &aOffset)
A progress reporter interface for use in multi-threaded environments.
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void AdvanceProgress()=0
Increment the progress bar length (inside the current virtual zone).
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.
Hold an XML or S-expression element.
XNODE * GetParent() const
XNODE * GetChildren() const
#define THROW_IO_ERROR(msg)
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 ...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
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:...
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
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...
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
Represents a cutout in a closed shape (e.g.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
Represents a floating value in E notation.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static bool IsGrid(XNODE *aNode)
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
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
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".
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
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
< "GATEDEFINITION" node name
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
GATE_ID ID
Usually "A", "B", "C", etc.
< "PINEQUIVALENCE" Node name
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
< "PARTDEFINITIONPIN" node name
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
< "SWAPGATE" Node name (represents an "Element")
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
static CADSTAR_PIN_TYPE GetPinType(XNODE *aNode)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
Represents a point in x,y coordinates.
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool IsEmpty()
Determines if this is empty (i.e. no design reuse associated)
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
virtual void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
SHAPE_POLY_SET ConvertToPolySet(const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, double aAccuracy) const
SHAPE_LINE_CHAIN OutlineAsChain(const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, double aAccuracy) const
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
static bool IsShape(XNODE *aNode)
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
bool ParseSubNode(XNODE *aChildNode, PARSER_CONTEXT *aContext)
void ParseIdentifiers(XNODE *aNode, PARSER_CONTEXT *aContext)
wxString BuildLibName() const
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
Corresponds to CADSTAR "origin".
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
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
Represents a vertex in a shape.
static bool IsVertex(XNODE *aNode)
SHAPE_ARC BuildArc(const VECTOR2I &aPrevPoint, const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback) const
void AppendToChain(SHAPE_LINE_CHAIN *aChainToAppendTo, const std::function< VECTOR2I(const VECTOR2I &)> aCadstarToKicadPointCallback, double aAccuracy) const
void Parse(XNODE *aNode, PARSER_CONTEXT *aContext) override
Hold a keyword string and its unique integer token.
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.
VECTOR2< int32_t > VECTOR2I