38#include <wx/mstream.h>
50 "BOM_Manufacturer Part",
72static wxString
optionalField(
const wxArrayString& aArr,
size_t aIndex )
74 return aIndex < aArr.size() ? aArr[aIndex] : wxString();
85 m_reporter->Report( wxString::Format(
_(
"Skipped a text with %d of %d fields." ), (
int) aArr.size(),
99static std::vector<std::vector<wxString>>
RegexMatchAll( wxRegEx& aRegex,
const wxString& aString )
101 std::vector<std::vector<wxString>> allMatches;
105 size_t prevstart = 0;
107 wxString str = aString;
109 while( aRegex.Matches( str ) )
111 std::vector<wxString> matches;
112 aRegex.GetMatch( &start, &len );
114 for(
size_t i = 0; i < aRegex.GetMatchCount(); i++ )
115 matches.emplace_back( aRegex.GetMatch( str, i ) );
117 allMatches.emplace_back( matches );
119 prevstart = start + len;
120 str = str.Mid( prevstart );
134static std::vector<std::pair<wxString, std::vector<double>>>
137 wxRegEx transformRegex(
"(rotate|translate|scale)\\(([\\w\\s,\\.\\-]*)\\)", wxRE_ICASE );
138 std::vector<std::vector<wxString>> allMatches =
RegexMatchAll( transformRegex, transformData );
140 std::vector<std::pair<wxString, std::vector<double>>> transformCmds;
142 for(
int cmdId = allMatches.size() - 1; cmdId >= 0; cmdId-- )
144 std::vector<wxString>& groups = allMatches[cmdId];
146 if( groups.size() != 3 )
149 const wxString& cmdName = groups[1].Strip( wxString::both ).Lower();
150 const wxString& cmdArgsStr = groups[2];
152 wxArrayString cmdParts = wxSplit( cmdArgsStr,
',',
'\0' );
153 std::vector<double> cmdArgs;
155 for(
const wxString& cmdPart : cmdParts )
158 wxASSERT( cmdPart.Strip( wxString::both ).ToCDouble( &arg ) );
160 cmdArgs.push_back( arg );
163 transformCmds.emplace_back( cmdName, cmdArgs );
166 return transformCmds;
174 wxString key = !aLibName.empty() ? ( aLibName +
':' + libReference ) : libReference;
177 libId.
Parse( key,
true );
185 if( aStyle == wxS(
"0" ) )
187 else if( aStyle == wxS(
"1" ) )
189 else if( aStyle == wxS(
"2" ) )
198 if( aType == wxS(
"0" ) )
200 else if( aType == wxS(
"1" ) )
202 else if( aType == wxS(
"2" ) )
204 else if( aType == wxS(
"3" ) )
206 else if( aType == wxS(
"4" ) )
398 aReporter->
Report(
_(
"Power Port with unknown style imported as 'Bar' type." ),
420 std::map<wxString, wxString> paramMap,
421 wxArrayString aShapes )
423 for( wxString shapeStr : aShapes )
425 wxArrayString arr = wxSplit( shapeStr,
'~',
'\0' );
427 wxString elType = arr[0];
428 if( elType == wxS(
"PL" ) || elType == wxS(
"PG" ) )
430 wxArrayString ptArr = wxSplit( arr[1],
' ',
'\0' );
431 wxString strokeColor = arr[2];
432 double lineWidth =
Convert( arr[3] );
434 wxString fillColor = arr[5].Lower();
439 for(
size_t i = 1; i < ptArr.size(); i += 2 )
447 if( elType == wxS(
"PG" ) )
448 chain.SetClosed(
true );
450 if(
chain.PointCount() < 2 )
453 for(
int i = 0; i <
chain.PointCount(); i++ )
454 line->AddPoint(
chain.CPoint( i ) );
456 if(
chain.IsClosed() )
457 line->AddPoint(
chain.CPoint( 0 ) );
462 if( fillColor != wxS(
"none" ) )
464 line->SetFilled(
true );
466 if( fillColor == strokeColor )
474 else if( elType == wxS(
"PT" ) )
476 wxString pointsData = arr[1];
477 wxString strokeColor = arr[2];
478 double lineWidth =
Convert( arr[3] );
480 wxString fillColor = arr[5].Lower();
483 std::vector<SHAPE_LINE_CHAIN> lineChains =
490 if( outline.IsClosed() )
491 outline.Append( outline.CPoint( 0 ),
true );
493 for(
const VECTOR2I& pt : outline.CPoints() )
494 shape->AddPoint( pt );
499 if( fillColor != wxS(
"none" ) )
501 shape->SetFilled(
true );
503 if( fillColor == strokeColor )
512 else if( elType == wxS(
"Pimage" ) )
517 wxString imageUrl = arr[10];
519 if( imageUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
521 wxArrayString paramsArr =
522 wxSplit( imageUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
524 wxString data = imageUrl.AfterFirst(
',' );
526 if( paramsArr.size() > 0 )
528 wxString mimeType = paramsArr[0];
529 wxMemoryBuffer buf = wxBase64Decode( data );
531 if( mimeType == wxS(
"image/svg+xml" ) )
547 libsymImporter.
SetScale( pixelScale );
556 for( std::unique_ptr<EDA_ITEM>& item : libsymImporter.
GetItems() )
561 wxMemoryInputStream memis( buf.GetData(), buf.GetDataLen() );
563 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
564 & ~wxImage::Load_Verbose );
566 if( img.LoadFile( memis, mimeType ) )
568 int dimMul = img.GetWidth() * img.GetHeight();
569 double maxPixels = 30000;
571 if( dimMul > maxPixels )
573 double scale = sqrt( maxPixels / dimMul );
574 img.Rescale( img.GetWidth() *
scale, img.GetHeight() *
scale );
587 else if( elType == wxS(
"A" ) )
589 wxString data = arr[1];
590 wxString strokeColor = arr[3];
591 double lineWidth =
Convert( arr[4] );
593 wxString fillColor = arr[6].Lower();
596 std::vector<SHAPE_LINE_CHAIN> chains =
599 auto transform = [](
VECTOR2I aVec )
606 for(
int i = 0; i <=
chain.PointCount() && i != -1; i =
chain.NextShape( i ) )
608 if(
chain.IsArcStart( i ) )
612 std::unique_ptr<SCH_SHAPE> shape =
615 shape->SetArcGeometry( transform( arc.
GetP0() ),
617 transform( arc.
GetP1() ) );
622 if( fillColor != wxS(
"none" ) )
624 shape->SetFilled(
true );
626 if( fillColor == strokeColor )
638 std::unique_ptr<SCH_SHAPE> shape =
641 shape->AddPoint( transform( seg.
A ) );
642 shape->AddPoint( transform( seg.
B ) );
652 else if( elType == wxS(
"R" ) )
657 cr.
x = !arr[3].empty() ?
Convert( arr[3] ) : 0,
658 cr.
y = !arr[4].empty() ?
Convert( arr[4] ) : 0;
661 wxString strokeColor = arr[7];
662 double lineWidth =
Convert( arr[8] );
664 wxString fillColor = arr[10].Lower();
677 if( fillColor != wxS(
"none" ) )
679 rect->SetFilled(
true );
681 if( fillColor == strokeColor )
691 else if( elType == wxS(
"E" ) )
697 wxString strokeColor = arr[5];
698 double lineWidth =
Convert( arr[6] );
700 wxString fillColor = arr[8].Lower();
709 if( fillColor != wxS(
"none" ) )
711 circle->SetFilled(
true );
713 if( fillColor == strokeColor )
721 else if( elType == wxS(
"P" ) )
723 wxString sepShapeStr = shapeStr;
724 sepShapeStr.Replace( wxS(
"^^" ), wxS(
"\n" ) );
726 wxArrayString segments = wxSplit( sepShapeStr,
'\n',
'\0' );
727 wxArrayString mainParts = wxSplit( segments[0],
'~',
'\0' );
728 wxArrayString pinDotParts = wxSplit( segments[1],
'~',
'\0' );
729 wxArrayString pinPathColorParts = wxSplit( segments[2],
'~',
'\0' );
730 wxArrayString pinNameParts = wxSplit( segments[3],
'~',
'\0' );
731 wxArrayString pinNumParts = wxSplit( segments[4],
'~',
'\0' );
735 wxString pinNumber = mainParts[3];
741 bool nameVisible = pinNameParts[0] != wxS(
"0" );
742 wxString pinName = pinNameParts[4];
744 bool numVisible = pinNumParts[0] != wxS(
"0" );
748 if( pinNumParts.size() > 4 && !pinNumParts[4].Trim().IsEmpty() )
749 pinNumber = pinNumParts[4].Trim();
752 bool vertical =
false;
756 wxString lineData = pinPathColorParts[0];
757 wxRegEx regex( wxS(
"^M\\s*([-\\d.]+)[,\\s]([-\\d.]+)\\s*([h|v])\\s*([-\\d.]+)\\s*$" ) );
759 if( regex.Matches( lineData ) )
761 startPoint.
x =
Convert( regex.GetMatch( lineData, 1 ) );
762 startPoint.
y =
Convert( regex.GetMatch( lineData, 2 ) );
764 vertical = regex.GetMatch( lineData, 3 ).Contains( wxS(
"v" ) );
765 pinLen =
Convert( regex.GetMatch( lineData, 4 ) );
772 if( startPoint.
x == pinPos.
x && pinLen < 0 )
774 else if( startPoint.
x == pinPos.
x && pinLen > 0 )
776 else if( startPoint.
x != pinPos.
x && pinLen < 0 )
778 else if( startPoint.
x != pinPos.
x && pinLen > 0 )
783 if( startPoint.
y == pinPos.
y && pinLen < 0 )
785 else if( startPoint.
y == pinPos.
y && pinLen > 0 )
787 else if( startPoint.
y != pinPos.
y && pinLen < 0 )
789 else if( startPoint.
y != pinPos.
y && pinLen > 0 )
795 if( pinRotation == 0 )
797 else if( pinRotation == 90 )
799 else if( pinRotation == 180 )
801 else if( pinRotation == 270 )
807 if( segments.size() > 5 )
809 wxArrayString dotParts = wxSplit( segments[5],
'~',
'\0' );
810 wxArrayString clockParts = wxSplit( segments[6],
'~',
'\0' );
812 if( dotParts.size() == 3 && clockParts.size() == 2 )
814 if( dotParts[0] == wxS(
"1" ) )
822 pinPos + ( dotPos - pinPos ).Resize(
std::abs( pinLen ) ) ) );
829 if( clockParts[0] == wxS(
"1" ) )
831 std::vector<SHAPE_LINE_CHAIN> lineChains =
838 if( outline.IsClosed() )
839 outline.Append( outline.CPoint( 0 ),
true );
841 for(
const VECTOR2I& pt : outline.CPoints() )
842 shape->AddPoint( pt );
852 std::unique_ptr<SCH_PIN>
pin = std::make_unique<SCH_PIN>( aSymbol );
854 pin->SetName( pinName );
855 pin->SetNumber( pinNumber );
856 pin->SetOrientation( orient );
857 pin->SetType( elecType );
858 pin->SetLength( kPinLen );
860 pin->SetUnit( pinUnit );
862 if(
pin->GetNumberTextSize() *
int( pinNumber.size() ) > kPinLen )
863 pin->SetNumberTextSize( kPinLen / pinNumber.size() );
873 else if( elType == wxS(
"T" ) )
878 wxString textType = arr[1];
882 wxString fontname = arr[6];
883 wxString fontSize = arr[7];
884 wxString baselineAlign = arr[10];
885 wxString textStr = arr[12];
888 textStr.Replace( wxS(
"\\n" ), wxS(
"\n" ) );
896 if( textType == wxS(
"P" ) )
902 else if( textType == wxS(
"N" ) )
917 if( halignStr == wxS(
"middle" ) )
919 else if( halignStr == wxS(
"end" ) )
929 if( !fontSize.IsEmpty() )
931 if( fontSize.EndsWith( wxS(
"pt" ) ) )
932 ptSize =
Convert( fontSize.BeforeFirst(
'p' ) );
933 else if( fontSize.IsNumber() )
939 if( textStr.Contains( wxS(
"\n" ) ) )
956 std::map<wxString, wxString> aParams,
957 wxArrayString aShapes )
959 std::unique_ptr<LIB_SYMBOL> ksymbol = std::make_unique<LIB_SYMBOL>( wxEmptyString );
963 std::optional<wxString> valOpt;
964 wxString symbolName = wxS(
"Unknown" );
966 if( ( valOpt =
get_opt( aParams, wxS(
"name" ) ) ) )
967 symbolName = *valOpt;
968 else if( ( valOpt =
get_opt( aParams, wxS(
"spiceSymbolName" ) ) ) )
969 symbolName = *valOpt;
971 wxString symbolPrefix;
973 if( ( valOpt =
get_opt( aParams, wxS(
"pre" ) ) ) )
974 symbolPrefix = *valOpt;
975 else if( ( valOpt =
get_opt( aParams, wxS(
"spicePre" ) ) ) )
976 symbolPrefix = *valOpt;
980 ksymbol->SetLibId( libId );
981 ksymbol->SetName( symbolName );
983 ksymbol->GetReferenceField().SetText( symbolPrefix );
984 ksymbol->GetValueField().SetText( symbolName );
987 if( ( valOpt =
get_opt( aParams, wxS(
"package" ) ) ) && *valOpt == wxS(
"NONE" ) )
989 ksymbol->SetExcludedFromBoard(
true );
990 ksymbol->SetExcludedFromBOM(
true );
995 wxString srcName = attrName;
997 if( srcName == wxS(
"Datasheet" ) )
998 srcName = wxS(
"link" );
1000 if( ( valOpt =
get_opt( aParams, srcName ) ) )
1002 if( valOpt->empty() )
1005 SCH_FIELD* fd = ksymbol->FindFieldCaseInsensitive( attrName );
1010 ksymbol->AddField( fd );
1020 return ksymbol.release();
1024 const wxString& aNetname )
1026 std::unique_ptr<LIB_SYMBOL> ksymbol = std::make_unique<LIB_SYMBOL>( wxEmptyString );
1032 ksymbol->SetGlobalPower();
1033 ksymbol->SetLibId( libId );
1034 ksymbol->SetName( aNetname );
1035 ksymbol->GetReferenceField().SetText( wxS(
"#PWR" ) );
1036 ksymbol->GetReferenceField().SetVisible(
false );
1037 ksymbol->GetValueField().SetText( aNetname );
1038 ksymbol->GetValueField().SetVisible(
true );
1039 ksymbol->SetDescription( wxString::Format(
_(
"Power symbol creates a global "
1040 "label with name '%s'" ),
1042 ksymbol->SetKeyWords( wxS(
"power-flag" ) );
1043 ksymbol->SetShowPinNames(
false );
1044 ksymbol->SetShowPinNumbers(
false );
1046 std::unique_ptr<SCH_PIN>
pin = std::make_unique<SCH_PIN>( ksymbol.get() );
1048 pin->SetName( aNetname );
1049 pin->SetNumber( wxS(
"1" ) );
1052 pin->SetLength( 0 );
1054 ksymbol->AddDrawItem(
pin.release() );
1060 if( aFlagTypename == wxS(
"part_netLabel_gnD" ) )
1064 else if( aFlagTypename == wxS(
"part_netLabel_GNd" ) )
1068 else if( aFlagTypename == wxS(
"part_netLabel_gNd" ) )
1072 else if( aFlagTypename == wxS(
"part_netLabel_GnD" ) )
1076 else if( aFlagTypename == wxS(
"part_netLabel_VCC" ) )
1081 else if( aFlagTypename == wxS(
"part_netLabel_+5V" ) )
1086 else if( aFlagTypename == wxS(
"part_netLabel_VEE" ) )
1090 else if( aFlagTypename == wxS(
"part_netLabel_-5V" ) )
1094 else if( aFlagTypename == wxS(
"part_netLabel_Bar" ) )
1101 ksymbol->GetValueField().SetPosition( valueFieldPos );
1103 return std::make_pair( ksymbol.release(), flip );
1107 const wxString& aFileName, wxArrayString aShapes )
1109 std::map<wxString, std::unique_ptr<LIB_SYMBOL>> loadedSymbols;
1110 std::map<wxString, int> namesCounter;
1111 std::vector<std::unique_ptr<SCH_ITEM>> createdItems;
1113 for( wxString shap : aShapes )
1115 shap.Replace( wxS(
"#@$" ), wxS(
"\n" ) );
1116 wxArrayString parts = wxSplit( shap,
'\n',
'\0' );
1118 if( parts.size() < 1 )
1121 wxArrayString arr = wxSplit( parts[0],
'~',
'\0' );
1123 if( arr.size() < 1 )
1126 wxString rootType = arr[0];
1128 if( rootType == wxS(
"LIB" ) )
1130 if( arr.size() < 4 )
1135 wxString symbolName = wxString::Format( wxS(
"Unknown_%s_%s" ), arr[1], arr[2] );
1137 wxArrayString paramParts = wxSplit( arr[3],
'`',
'\0' );
1139 std::map<wxString, wxString> paramMap;
1141 for(
size_t i = 1; i < paramParts.size(); i += 2 )
1143 wxString key = paramParts[i - 1];
1144 wxString value = paramParts[i];
1146 if( key == wxS(
"spiceSymbolName" ) && !value.IsEmpty() )
1149 paramMap[key] = value;
1152 int& serial = namesCounter[symbolName];
1155 symbolName << wxS(
"_" ) << serial;
1159 paramMap[wxS(
"spiceSymbolName" )] = symbolName;
1161 parts.RemoveAt( 0 );
1166 loadedSymbols.emplace( symbolName, sym );
1172 referenceStr = wxS(
"#" ) + referenceStr;
1177 std::unique_ptr<SCH_SYMBOL> schSym =
1178 std::make_unique<SCH_SYMBOL>( *sym, libId, &aSchematic->
CurrentSheet(), 0 );
1180 schSym->SetPosition(
RelPos( origin ) );
1181 schSym->SetRef( &aSchematic->
CurrentSheet(), referenceStr );
1183 createdItems.push_back( std::move( schSym ) );
1185 else if( rootType == wxS(
"F" ) )
1187 wxString sepShapeStr = parts[0];
1188 sepShapeStr.Replace( wxS(
"^^" ), wxS(
"\n" ) );
1190 wxArrayString segments = wxSplit( sepShapeStr,
'\n',
'\0' );
1193 wxArrayString valueParts = wxSplit( segments[2],
'~',
'\0' );
1195 wxString flagTypename = arr[1];
1197 double angle =
Convert( arr[4] );
1199 wxString netnameValue = valueParts[0];
1201 double textAngle =
Convert( valueParts[4] );
1202 wxString halignStr = valueParts[5];
1203 wxString valueFontname = valueParts[7];
1204 wxString valueFontsize = valueParts[8];
1206 if( flagTypename == wxS(
"part_netLabel_netPort" ) )
1208 std::unique_ptr<SCH_GLOBALLABEL> label =
1209 std::make_unique<SCH_GLOBALLABEL>(
RelPos( pos ), netnameValue );
1213 for(
double i = angle; i > 0; i -= 90 )
1217 if( segments.size() > 3 )
1219 wxArrayString shapeParts = wxSplit( segments[3],
'~',
'\0' );
1220 if( shapeParts[0] == wxS(
"PL" ) )
1222 wxArrayString ptArr = wxSplit( shapeParts[1],
' ',
'\0' );
1226 for(
size_t i = 1; i < ptArr.size(); i += 2 )
1238 if( shapeCenter.
x >= 0 )
1245 if( shapeCenter.
y >= 0 )
1253 label->SetSpinStyle( spin );
1256 createdItems.push_back( std::move( label ) );
1262 bool flip = pair.second;
1266 std::unique_ptr<SCH_SYMBOL> schSym = std::make_unique<SCH_SYMBOL>(
1275 else if( angle == 90 )
1289 schSym->SetPosition(
RelPos( pos ) );
1301 if( halignStr == wxS(
"middle" ) )
1303 else if( halignStr == wxS(
"end" ) )
1308 if( flip && ( angle == 90 || angle == 270 ) )
1320 if( flagTypename == wxS(
"part_netLabel_Bar" ) )
1324 if( angle == 0 && flagTypename == wxS(
"part_netLabel_Bar" ) )
1331 if( valueFontsize.EndsWith( wxS(
"pt" ) ) )
1332 ptSize =
Convert( valueFontsize.BeforeFirst(
'p' ) );
1336 if( netnameValue.Contains( wxS(
"\n" ) ) )
1345 createdItems.push_back( std::move( schSym ) );
1348 else if( rootType == wxS(
"W" ) )
1350 wxArrayString ptArr = wxSplit( arr[1],
' ',
'\0' );
1359 for(
size_t i = 1; i < ptArr.size(); i += 2 )
1362 for(
int segId = 0; segId <
chain.SegmentCount(); segId++ )
1364 const SEG& seg =
chain.CSegment( segId );
1366 std::unique_ptr<SCH_LINE> line = std::make_unique<SCH_LINE>( seg.
A,
LAYER_WIRE );
1367 line->SetEndPoint( seg.
B );
1369 createdItems.push_back( std::move( line ) );
1372 else if( rootType == wxS(
"N" ) )
1375 double angle =
Convert( arr[3] );
1376 wxString netname = arr[5];
1377 wxString halignStr = arr[7];
1384 std::unique_ptr<SCH_LABEL> label =
1385 std::make_unique<SCH_LABEL>(
RelPos( pos ), netname );
1387 if( halignStr == wxS(
"middle" ) )
1389 else if( halignStr == wxS(
"end" ) )
1395 label->Rotate90(
false );
1397 createdItems.push_back( std::move( label ) );
1399 else if( rootType == wxS(
"O" ) )
1403 std::unique_ptr<SCH_NO_CONNECT> noConn =
1404 std::make_unique<SCH_NO_CONNECT>(
RelPos( pos ) );
1406 createdItems.push_back( std::move( noConn ) );
1408 else if( rootType == wxS(
"J" ) )
1413 std::unique_ptr<SCH_JUNCTION> junction =
1414 std::make_unique<SCH_JUNCTION>(
RelPos( pos ) );
1416 createdItems.push_back( std::move( junction ) );
1418 else if( rootType == wxS(
"T" ) )
1424 int angle =
Convert( arr[4] );
1426 wxString fontname = arr[6];
1427 wxString fontSize = arr[7];
1428 wxString baselineAlign = arr[10];
1429 wxString textStr = arr[12];
1431 textStr.Replace( wxS(
"\\n" ), wxS(
"\n" ) );
1436 std::unique_ptr<SCH_TEXT> textItem =
1437 std::make_unique<SCH_TEXT>(
RelPos( pos ), textStr );
1439 textItem->SetTextAngleDegrees( ( 360 - angle ) % 360 );
1442 if( halignStr == wxS(
"middle" ) )
1444 else if( halignStr == wxS(
"end" ) )
1453 if( fontSize.EndsWith( wxS(
"pt" ) ) )
1454 ptSize =
Convert( fontSize.BeforeFirst(
'p' ) );
1458 if( textStr.Contains( wxS(
"\n" ) ) )
1463 textItem->SetTextSize(
VECTOR2I( ktextSize, ktextSize ) );
1467 createdItems.push_back( std::move( textItem ) );
1469 else if( rootType == wxS(
"R" ) )
1474 cr.
x = !arr[3].empty() ?
Convert( arr[3] ) : 0,
1475 cr.
y = !arr[4].empty() ?
Convert( arr[4] ) : 0;
1478 wxString strokeColor = arr[7];
1479 double lineWidth =
Convert( arr[8] );
1481 wxString fillColor = arr[10].Lower();
1493 if( fillColor != wxS(
"none" ) )
1495 rect->SetFilled(
true );
1497 if( fillColor == strokeColor )
1503 createdItems.push_back( std::move(
rect ) );
1509 else if( rootType == wxS(
"I" ) )
1514 wxString imageUrl = arr[6];
1515 wxString transformData = arr[9];
1520 std::vector<std::pair<wxString, std::vector<double>>> transformCmds =
1523 auto applyTransform = [&](
SCH_ITEM* aSchItem )
1525 for(
const auto& cmd : transformCmds )
1527 if( cmd.first == wxS(
"rotate" ) )
1529 if( cmd.second.size() != 3 )
1532 double cmdAngle = 360 - cmd.second[0];
1533 VECTOR2D cmdAround( cmd.second[1], cmd.second[2] );
1535 for(
double i = cmdAngle; i > 0; i -= 90 )
1541 aSchItem->Rotate(
RelPos( cmdAround ),
false );
1545 aSchItem->Rotate(
RelPos( cmdAround ),
false );
1550 aSchItem->Rotate(
RelPos( cmdAround ),
false );
1554 else if( cmd.first == wxS(
"translate" ) )
1556 if( cmd.second.size() != 2 )
1559 VECTOR2D cmdOffset( cmd.second[0], cmd.second[1] );
1560 aSchItem->Move(
ScalePos( cmdOffset ) );
1562 else if( cmd.first == wxS(
"scale" ) )
1564 if( cmd.second.size() != 2 )
1567 double cmdScaleX = cmd.second[0];
1568 double cmdScaleY = cmd.second[1];
1574 if( cmdScaleX < 0 && cmdScaleY > 0 )
1576 aSchItem->MirrorHorizontally( 0 );
1578 else if( cmdScaleX > 0 && cmdScaleY < 0 )
1580 aSchItem->MirrorVertically( 0 );
1582 else if( cmdScaleX < 0 && cmdScaleY < 0 )
1584 aSchItem->MirrorHorizontally( 0 );
1585 aSchItem->MirrorVertically( 0 );
1594 if( imageUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
1596 wxArrayString paramsArr =
1597 wxSplit( imageUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
1599 wxString data = imageUrl.AfterFirst(
',' );
1601 if( paramsArr.size() > 0 )
1603 wxString mimeType = paramsArr[0];
1604 wxMemoryBuffer buf = wxBase64Decode( data );
1606 if( mimeType == wxS(
"image/svg+xml" ) )
1622 schImporter.
SetScale( pixelScale );
1629 svgImportPlugin.
Import();
1631 for( std::unique_ptr<EDA_ITEM>& item : schImporter.
GetItems() )
1635 applyTransform( schItem );
1637 createdItems.emplace_back( schItem );
1642 std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>();
1645 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
1646 & ~wxImage::Load_Verbose );
1650 VECTOR2D kcenter = kstart + ksize / 2;
1654 bitmap->SetPosition( kcenter );
1656 applyTransform( bitmap.get() );
1658 createdItems.push_back( std::move( bitmap ) );
1668 for( std::unique_ptr<SCH_ITEM>& ptr : createdItems )
1678 offset.
x =
KiROUND( offset.
x / alignGrid ) * alignGrid;
1679 offset.
y =
KiROUND( offset.
y / alignGrid ) * alignGrid;
1686 for( std::unique_ptr<SCH_ITEM>& ptr : createdItems )
1688 ptr->Move( offset );
1689 screen->
Append( ptr.release() );
constexpr EDA_IU_SCALE schIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
constexpr size_type GetWidth() const
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr size_type GetHeight() const
constexpr coord_type GetLeft() const
constexpr coord_type GetTop() const
static double Convert(const wxString &aValue)
double RelPosX(double aValue)
double RelPosY(double aValue)
VECTOR2< T > RelPos(const VECTOR2< T > &aVec)
VECTOR2< T > ScalePos(const VECTOR2< T > &aValue)
void TransformTextToBaseline(EDA_TEXT *textItem, const wxString &baselineAlign)
std::vector< SHAPE_LINE_CHAIN > ParseLineChains(const wxString &aData, int aMaxError, bool aForceClosed)
virtual void SetEnd(const VECTOR2I &aEnd)
virtual void SetBezierC2(const VECTOR2I &aPt)
virtual void SetBezierC1(const VECTOR2I &aPt)
virtual void SetStart(const VECTOR2I &aStart)
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
virtual void SetTextPos(const VECTOR2I &aPoint)
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
GR_TEXT_H_ALIGN_T GetHorizJustify() const
virtual void SetVisible(bool aVisible)
void SetTextAngleDegrees(double aOrientation)
GR_TEXT_V_ALIGN_T GetVertJustify() const
virtual void SetText(const wxString &aText)
void SetFont(KIFONT::FONT *aFont)
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
void SetImportOffsetMM(const VECTOR2D &aOffset)
Set the offset in millimeters to add to coordinates when importing graphic items.
void SetScale(const VECTOR2D &aScale)
Set the scale factor affecting the imported shapes.
std::list< std::unique_ptr< EDA_ITEM > > & GetItems()
Return the list of objects representing the imported shapes.
virtual void SetImporter(GRAPHICS_IMPORTER *aImporter)
Set the receiver of the imported shapes.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Define a library symbol object.
SCH_FIELD & GetValueField()
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
SCH_FIELD & GetReferenceField()
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetHeightMils(double aHeightInMils)
void SetWidthMils(double aWidthInMils)
A progress reporter interface for use in multi-threaded environments.
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
bool ReadImageFile(const wxString &aFullFilename)
Read and store an image file.
void SetImageScale(double aScale)
Set the image "zoom" value.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Holds all the data relating to one schematic.
SCH_SHEET_PATH & CurrentSheet() const
void ParseSymbolShapes(LIB_SYMBOL *aContainer, std::map< wxString, wxString > paramMap, wxArrayString aShapes)
std::pair< LIB_SYMBOL *, bool > MakePowerSymbol(const wxString &aFlagTypename, const wxString &aNetname)
double ScaleSize(double aValue) override
void ParseSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName, wxArrayString aShapes)
VECTOR2< T > RelPosSym(const VECTOR2< T > &aVec)
bool checkTextFields(const wxArrayString &aArr)
SCH_EASYEDA_PARSER(SCHEMATIC *aSchematic, PROGRESS_REPORTER *aProgressReporter, REPORTER *aReporter)
LIB_SYMBOL * ParseSymbol(const VECTOR2D &aOrigin, std::map< wxString, wxString > aParams, wxArrayString aShapes)
virtual const wxString & GetText() const override
Return the string associated with the text object.
void SetPosition(const VECTOR2I &aPosition) override
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
const PAGE_INFO & GetPageSettings() const
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetPageSettings(const PAGE_INFO &aPageSettings)
void SetStroke(const STROKE_PARAMS &aStroke) override
void AddPoint(const VECTOR2I &aPosition)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
SCH_SCREEN * GetScreen() const
BOX2I GetBodyBoundingBox() const override
Return a bounding box for the symbol body but not the pins or fields.
const VECTOR2I & GetArcMid() const
const VECTOR2I & GetP1() const
const VECTOR2I & GetP0() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Spin style for labels of all kinds on schematics.
Simple container to manage line stroke parameters.
bool Import() override
Actually imports the file.
virtual double GetImageWidth() const override
Return image width from original imported file.
bool LoadFromMemory(const wxMemoryBuffer &aMemBuffer) override
Set memory buffer with content for import.
virtual double GetImageHeight() const override
Return image height from original imported file.
bool GetExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
@ FILLED_WITH_BG_BODYCOLOR
@ FILLED_SHAPE
Fill with object color.
#define ENDPOINT
ends. (Used to support dragging.)
#define STARTPOINT
When a line is selected, these flags indicate which.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
void ConvertImageToLibShapes(LIB_SYMBOL *aSymbol, int unit, wxImage img, VECTOR2D pixelScale, VECTOR2D offset)
std::optional< V > get_opt(const std::map< wxString, V > &aMap, const wxString &aKey)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
@ PT_INPUT
usual pin input: must be connected
@ PT_BIDI
input or output (like port for a microprocessor)
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
PIN_ORIENTATION
The symbol library pin object orientations.
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
@ PIN_RIGHT
The pin extends rightwards from the connection point.
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
static std::vector< std::vector< wxString > > RegexMatchAll(wxRegEx &aRegex, const wxString &aString)
static const std::vector< wxString > c_attributesWhitelist
static ELECTRICAL_PINTYPE ConvertElecType(const wxString &aType)
static wxString optionalField(const wxArrayString &aArr, size_t aIndex)
VECTOR2I HelperGeneratePowerPortGraphics(LIB_SYMBOL *aKsymbol, EASYEDA::POWER_FLAG_STYLE aStyle, REPORTER *aReporter)
static constexpr size_t TEXT_MIN_FIELDS
static LIB_ID EasyEdaToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
static std::vector< std::pair< wxString, std::vector< double > > > ParseImageTransform(const wxString &transformData)
EasyEDA image transformations are in the form of:
static LINE_STYLE ConvertStrokeStyle(const wxString &aStyle)
VECTOR2I HelperGeneratePowerPortGraphics(LIB_SYMBOL *aKsymbol, ASCH_POWER_PORT_STYLE aStyle, REPORTER *aReporter)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
wxString UnescapeHTML(const wxString &aString)
Return a new wxString unescaped from HTML format.
LINE_STYLE
Dashed line types.
@ SYM_ROTATE_COUNTERCLOCKWISE
@ USER
The field ID hasn't been set yet; field is invalid.
@ VALUE
Field Value of part, i.e. "3.3K".
const SHAPE_LINE_CHAIN chain
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)