45#include <wx/mstream.h>
57 "BOM_Manufacturer Part",
83 if( !aValue.ToCDouble( &value ) )
84 THROW_IO_ERROR( wxString::Format(
_(
"Failed to parse value: '%s'" ), aValue ) );
100 else if( aStyle == 1 )
102 else if( aStyle == 2 )
104 else if( aStyle == 3 )
113 T&
text,
const wxString& styleStr )
115 auto it = fontStyles.find( styleStr );
117 if( it == fontStyles.end() )
120 nlohmann::json style = it->second;
122 if( !style.is_array() )
125 if( style.size() < 12 )
128 if( style.at( 3 ).is_string() )
134 if( style.at( 4 ).is_string() )
136 wxString fontname = ( style.at( 4 ) );
138 if( !fontname.IsSameAs( wxS(
"default" ),
false ) )
142 if( style.at( 5 ).is_number() )
144 double size = style.at( 5 ).get<
double>() * 0.5;
148 if( style.at( 10 ).is_number() )
150 int valign = style.at( 10 );
152 if( !
text->GetText().Contains( wxS(
"\n" ) ) )
156 else if( valign == 1 )
158 else if( valign == 2 )
172 if( style.at( 11 ).is_number() )
174 int halign = style.at( 11 );
178 else if( halign == 1 )
180 else if( halign == 2 )
192 T& shape,
const wxString& styleStr )
194 auto it = lineStyles.find( styleStr );
196 if( it == lineStyles.end() )
199 nlohmann::json style = it->second;
201 if( !style.is_array() )
204 if( style.size() < 6 )
209 if( style.at( 2 ).is_string() )
211 wxString colorStr = style.at( 2 ).get<wxString>();
213 if( !colorStr.empty() && colorStr.starts_with( wxS(
"#" ) ) )
220 if( style.at( 3 ).is_number() )
222 int dashStyle = style.at( 3 );
226 if( style.at( 5 ).is_number() )
228 double thickness = style.at( 5 );
232 shape->SetStroke( stroke );
237 const wxString aInput,
const std::map<wxString, wxString>& aDeviceAttributes )
239 wxString inputText = aInput;
240 wxString resolvedText;
241 int variableCount = 0;
247 if( !inputText.StartsWith( wxS(
"={" ) ) )
250 resolvedText.Clear();
253 for(
size_t i = 1; i < inputText.size(); )
255 wxUniChar c = inputText[i++];
260 bool endFound =
false;
262 while( i < inputText.size() )
279 get_def( aDeviceAttributes, varName, wxString::Format(
"{%s!}", varName ) );
281 resolvedText << varValue;
289 inputText = resolvedText;
291 }
while( variableCount > 0 );
300 bool aIsSym,
bool aToSym,
301 const std::map<wxString, wxString>& aDeviceAttributes,
319 auto parent = aParent;
322 int orient =
static_cast<SCH_SYMBOL*
>( parent )->GetOrientation();
400 const std::map<wxString, wxString>& aDeviceAttributes )
404 std::unique_ptr<LIB_SYMBOL> ksymbolPtr = std::make_unique<LIB_SYMBOL>( wxEmptyString );
407 std::map<wxString, nlohmann::json> lineStyles;
408 std::map<wxString, nlohmann::json> fontStyles;
409 std::map<wxString, int> partUnits;
411 std::map<int, std::map<wxString, EASYEDAPRO::SCH_ATTR>> unitAttributes;
412 std::map<int, std::map<wxString, std::vector<nlohmann::json>>> unitParentedLines;
416 for(
const nlohmann::json& line : aLines )
418 wxString type = line.at( 0 );
420 if( type == wxS(
"LINESTYLE" ) )
421 lineStyles[line.at( 1 )] = line;
422 else if( type == wxS(
"FONTSTYLE" ) )
423 fontStyles[line.at( 1 )] = line;
424 else if( type == wxS(
"PART" ) )
425 partUnits[line.at( 1 )] = ++totalUnits;
433 for(
const nlohmann::json& line : aLines )
435 wxString type = line.at( 0 );
437 if( type == wxS(
"PART" ) )
439 currentUnit = partUnits.at( line.at( 1 ) );
441 else if( type == wxS(
"RECT" ) )
443 VECTOR2D start( line.at( 2 ), line.at( 3 ) );
444 VECTOR2D end( line.at( 4 ), line.at( 5 ) );
445 wxString styleStr = line.at( 9 );
447 auto rect = std::make_unique<SCH_SHAPE>( SHAPE_T::RECTANGLE,
LAYER_DEVICE );
452 rect->SetUnit( currentUnit );
457 else if( type == wxS(
"CIRCLE" ) )
459 VECTOR2D center( line.at( 2 ), line.at( 3 ) );
460 double radius = line.at( 4 );
461 wxString styleStr = line.at( 5 );
463 auto circle = std::make_unique<SCH_SHAPE>( SHAPE_T::CIRCLE,
LAYER_DEVICE );
468 circle->SetUnit( currentUnit );
473 else if( type == wxS(
"ARC" ) )
475 VECTOR2D start( line.at( 2 ), line.at( 3 ) );
476 VECTOR2D mid( line.at( 4 ), line.at( 5 ) );
477 VECTOR2D end( line.at( 6 ), line.at( 7 ) );
478 wxString styleStr = line.at( 8 );
484 auto shape = std::make_unique<SCH_SHAPE>( SHAPE_T::ARC,
LAYER_DEVICE );
486 shape->SetArcGeometry( kstart, kmid, kend );
488 shape->SetUnit( currentUnit );
493 else if( type == wxS(
"BEZIER" ) )
495 std::vector<double> points = line.at( 2 );
496 wxString styleStr = line.at( 3 );
498 auto shape = std::make_unique<SCH_SHAPE>( SHAPE_T::BEZIER,
LAYER_DEVICE );
500 for(
size_t i = 1; i < points.size(); i += 2 )
506 case 1: shape->SetStart( pt );
break;
507 case 3: shape->SetBezierC1( pt );
break;
508 case 5: shape->SetBezierC2( pt );
break;
509 case 7: shape->SetEnd( pt );
break;
513 shape->SetUnit( currentUnit );
518 else if( type == wxS(
"POLY" ) )
520 std::vector<double> points = line.at( 2 );
521 wxString styleStr = line.at( 4 );
523 auto shape = std::make_unique<SCH_SHAPE>( SHAPE_T::POLY,
LAYER_DEVICE );
525 for(
size_t i = 1; i < points.size(); i += 2 )
528 shape->SetUnit( currentUnit );
533 else if( type == wxS(
"TEXT" ) )
535 VECTOR2D pos( line.at( 2 ), line.at( 3 ) );
536 double angle = line.at( 4 );
537 wxString textStr = line.at( 5 );
538 wxString fontStyleStr = line.at( 6 );
545 text->SetTextAngleDegrees( angle );
547 text->SetUnit( currentUnit );
552 else if( type == wxS(
"OBJ" ) )
555 wxString mimeType, data;
559 if( line.at( 3 ).is_number() )
561 start =
VECTOR2D( line.at( 3 ), line.at( 4 ) );
562 size =
VECTOR2D( line.at( 5 ), line.at( 6 ) );
564 upsideDown = line.at( 8 );
566 wxString imageUrl = line.at( 9 );
568 if( imageUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
570 wxArrayString paramsArr =
571 wxSplit( imageUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
573 data = imageUrl.AfterFirst(
',' );
575 if( paramsArr.size() > 0 )
577 mimeType = paramsArr[0];
581 else if( line.at( 3 ).is_string() )
583 mimeType = line.at( 3 ).get<wxString>().BeforeFirst(
';' );
585 start =
VECTOR2D( line.at( 4 ), line.at( 5 ) );
586 size =
VECTOR2D( line.at( 6 ), line.at( 7 ) );
588 data = line.at( 9 ).get<wxString>();
591 if( mimeType.empty() || data.empty() )
594 wxMemoryBuffer buf = wxBase64Decode( data );
596 if( mimeType == wxS(
"image/svg+xml" ) )
615 libsymImporter.
SetScale( pixelScale );
624 for( std::unique_ptr<EDA_ITEM>& item : libsymImporter.
GetItems() )
629 wxMemoryInputStream memis( buf.GetData(), buf.GetDataLen() );
631 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
632 & ~wxImage::Load_Verbose );
634 if( img.LoadFile( memis, mimeType ) )
636 int dimMul = img.GetWidth() * img.GetHeight();
637 double maxPixels = 30000;
639 if( dimMul > maxPixels )
641 double scale = sqrt( maxPixels / dimMul );
642 img.Rescale( img.GetWidth() *
scale, img.GetHeight() *
scale );
653 else if( type == wxS(
"HEAD" ) )
657 else if( type == wxS(
"PIN" ) )
659 wxString pinId = line.at( 1 );
660 unitParentedLines[currentUnit][pinId].push_back( line );
662 else if( type == wxS(
"ATTR" ) )
664 wxString parentId = line.at( 2 );
666 if( parentId.empty() )
669 unitAttributes[currentUnit].emplace( attr.
key, attr );
673 unitParentedLines[currentUnit][parentId].push_back( line );
688 if(
auto globalNetAttr =
get_opt( unitAttributes[1], wxS(
"Global Net Name" ) ) )
692 wxString globalNetname = globalNetAttr->value;
694 if( !globalNetname.empty() )
697 _(
"Power symbol creates a global label with name '%s'" ),
704 auto designatorAttr =
get_opt( unitAttributes[1], wxS(
"Designator" ) );
706 if( designatorAttr && !designatorAttr->value.empty() )
708 wxString symbolPrefix = designatorAttr->value;
710 if( symbolPrefix.EndsWith( wxS(
"?" ) ) )
711 symbolPrefix.RemoveLast();
718 if(
auto valOpt =
get_opt( aDeviceAttributes, attrName ) )
720 if( valOpt->empty() )
731 wxString value = *valOpt;
733 value.Replace( wxS(
"\u2103" ), wxS(
"\u00B0C" ),
true );
741 for(
auto& [unitId, parentedLines] : unitParentedLines )
743 for(
auto& [pinId, lines] : parentedLines )
745 std::optional<EASYEDAPRO::SYM_PIN> epin;
746 std::map<wxString, EASYEDAPRO::SCH_ATTR> pinAttributes;
748 for(
const nlohmann::json& line : lines )
750 wxString type = line.at( 0 );
752 if( type == wxS(
"ATTR" ) )
755 pinAttributes.emplace( attr.
key, attr );
757 else if( type == wxS(
"PIN" ) )
769 std::unique_ptr<SCH_PIN>
pin = std::make_unique<SCH_PIN>( ksymbol );
771 pin->SetUnit( unitId );
778 if( epin->rotation == 0 )
779 orient = PIN_ORIENTATION::PIN_RIGHT;
780 if( epin->rotation == 90 )
781 orient = PIN_ORIENTATION::PIN_UP;
782 if( epin->rotation == 180 )
783 orient = PIN_ORIENTATION::PIN_LEFT;
784 if( epin->rotation == 270 )
785 orient = PIN_ORIENTATION::PIN_DOWN;
787 pin->SetOrientation( orient );
794 else if(
auto pinNameAttr =
get_opt( pinAttributes,
"NAME" ) )
796 pin->SetName( pinNameAttr->value );
797 pinInfo.
name = pinNameAttr->value;
799 if( !pinNameAttr->valVisible )
803 if(
auto pinNumAttr =
get_opt( pinAttributes,
"NUMBER" ) )
805 pin->SetNumber( pinNumAttr->value );
806 pinInfo.
number = pinNumAttr->value;
808 if( !pinNumAttr->valVisible )
814 pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
816 else if(
auto pinTypeAttr =
get_opt( pinAttributes,
"Pin Type" ) )
818 if( pinTypeAttr->value == wxS(
"IN" ) )
819 pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
820 if( pinTypeAttr->value == wxS(
"OUT" ) )
821 pin->SetType( ELECTRICAL_PINTYPE::PT_OUTPUT );
822 if( pinTypeAttr->value == wxS(
"BI" ) )
823 pin->SetType( ELECTRICAL_PINTYPE::PT_BIDI );
826 if(
get_opt( pinAttributes,
"NO_CONNECT" ) )
827 pin->SetType( ELECTRICAL_PINTYPE::PT_NC );
829 if(
pin->GetNumberTextSize() *
int(
pin->GetNumber().size() ) >
pin->GetLength() )
830 pin->SetNumberTextSize(
pin->GetLength() /
pin->GetNumber().size() );
832 symInfo.
pins.push_back( pinInfo );
850 symInfo.
libSymbol = std::move( ksymbolPtr );
857 const nlohmann::json& aProject,
858 std::map<wxString, EASYEDAPRO::SYM_INFO>& aSymbolMap,
859 const std::map<wxString, EASYEDAPRO::BLOB>& aBlobMap,
860 const std::vector<nlohmann::json>& aLines,
861 const wxString& aLibName )
863 std::vector<std::unique_ptr<SCH_ITEM>> createdItems;
865 std::map<wxString, std::vector<nlohmann::json>> parentedLines;
866 std::map<wxString, std::vector<nlohmann::json>> ruleLines;
868 std::map<wxString, nlohmann::json> lineStyles;
869 std::map<wxString, nlohmann::json> fontStyles;
871 for(
const nlohmann::json& line : aLines )
873 wxString type = line.at( 0 );
875 if( type == wxS(
"LINESTYLE" ) )
876 lineStyles[line.at( 1 )] = line;
877 else if( type == wxS(
"FONTSTYLE" ) )
878 fontStyles[line.at( 1 )] = line;
881 for(
const nlohmann::json& line : aLines )
883 wxString type = line.at( 0 );
885 if( type == wxS(
"RECT" ) )
887 VECTOR2D start( line.at( 2 ), line.at( 3 ) );
888 VECTOR2D end( line.at( 4 ), line.at( 5 ) );
889 wxString styleStr = line.at( 9 );
891 std::unique_ptr<SCH_SHAPE> rect = std::make_unique<SCH_SHAPE>( SHAPE_T::RECTANGLE );
893 rect->SetStart(
ScalePos( start ) );
898 createdItems.push_back( std::move( rect ) );
900 else if( type == wxS(
"CIRCLE" ) )
902 VECTOR2D center( line.at( 2 ), line.at( 3 ) );
903 double radius = line.at( 4 );
904 wxString styleStr = line.at( 5 );
906 std::unique_ptr<SCH_SHAPE> circle = std::make_unique<SCH_SHAPE>( SHAPE_T::CIRCLE );
908 circle->SetCenter(
ScalePos( center ) );
913 createdItems.push_back( std::move( circle ) );
915 else if( type == wxS(
"POLY" ) )
917 std::vector<double> points = line.at( 2 );
918 wxString styleStr = line.at( 4 );
922 for(
size_t i = 1; i < points.size(); i += 2 )
925 for(
int segId = 0; segId < chain.
SegmentCount(); segId++ )
929 std::unique_ptr<SCH_LINE> schLine =
931 schLine->SetEndPoint( seg.
B );
935 createdItems.push_back( std::move( schLine ) );
938 else if( type == wxS(
"TEXT" ) )
940 VECTOR2D pos( line.at( 2 ), line.at( 3 ) );
941 double angle = line.at( 4 );
942 wxString textStr = line.at( 5 );
943 wxString fontStyleStr = line.at( 6 );
945 std::unique_ptr<SCH_TEXT>
text =
951 text->SetTextAngleDegrees( angle );
955 createdItems.push_back( std::move(
text ) );
957 else if( type == wxS(
"OBJ" ) )
960 wxString mimeType, base64Data;
964 if( line.at( 3 ).is_number() )
966 start =
VECTOR2D( line.at( 3 ), line.at( 4 ) );
967 size =
VECTOR2D( line.at( 5 ), line.at( 6 ) );
968 angle = line.at( 7 );
969 flipped = line.at( 8 );
971 wxString imageUrl = line.at( 9 );
973 if( imageUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
975 wxArrayString paramsArr =
976 wxSplit( imageUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
978 base64Data = imageUrl.AfterFirst(
',' );
980 if( paramsArr.size() > 0 )
981 mimeType = paramsArr[0];
983 else if( imageUrl.BeforeFirst(
':' ) == wxS(
"blob" ) )
985 wxString objectId = imageUrl.AfterLast(
':' );
987 if(
auto blob =
get_opt( aBlobMap, objectId ) )
989 wxString blobUrl = blob->url;
991 if( blobUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
993 wxArrayString paramsArr = wxSplit(
994 blobUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
996 base64Data = blobUrl.AfterFirst(
',' );
998 if( paramsArr.size() > 0 )
999 mimeType = paramsArr[0];
1004 else if( line.at( 3 ).is_string() )
1006 mimeType = line.at( 3 ).get<wxString>().BeforeFirst(
';' );
1008 start =
VECTOR2D( line.at( 4 ), line.at( 5 ) );
1009 size =
VECTOR2D( line.at( 6 ), line.at( 7 ) );
1010 angle = line.at( 8 );
1011 base64Data = line.at( 9 ).get<wxString>();
1017 if( mimeType.empty() || base64Data.empty() )
1020 wxMemoryBuffer buf = wxBase64Decode( base64Data );
1022 if( mimeType == wxS(
"image/svg+xml" ) )
1036 schImporter.
SetScale( pixelScale );
1042 svgImportPlugin.
Import();
1044 for( std::unique_ptr<EDA_ITEM>& item : schImporter.
GetItems() )
1048 for(
double i = angle; i > 0; i -= 90 )
1054 schItem->
Rotate( kstart,
false );
1058 schItem->
Rotate( kstart,
false );
1063 schItem->
Rotate( kstart,
false );
1079 createdItems.emplace_back( schItem );
1084 std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>();
1087 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
1088 & ~wxImage::Load_Verbose );
1092 VECTOR2D kcenter = kstart + ksize / 2;
1096 bitmap->SetPosition( kcenter );
1098 for(
double i = angle; i > 0; i -= 90 )
1099 bitmap->Rotate( kstart,
false );
1102 bitmap->MirrorHorizontally( kstart.
x );
1104 createdItems.push_back( std::move( bitmap ) );
1108 if( type == wxS(
"WIRE" ) )
1110 wxString wireId = line.at( 1 );
1111 parentedLines[wireId].push_back( line );
1113 else if( type == wxS(
"COMPONENT" ) )
1115 wxString compId = line.at( 1 );
1116 parentedLines[compId].push_back( line );
1118 else if( type == wxS(
"ATTR" ) )
1120 wxString compId = line.at( 2 );
1121 parentedLines[compId].push_back( line );
1125 for(
auto& [parentId, lines] : parentedLines )
1127 std::optional<EASYEDAPRO::SCH_COMPONENT> component;
1128 std::optional<EASYEDAPRO::SCH_WIRE> wire;
1129 std::map<wxString, EASYEDAPRO::SCH_ATTR> attributes;
1131 for(
const nlohmann::json& line : lines )
1133 if( line.at( 0 ) ==
"COMPONENT" )
1137 else if( line.at( 0 ) ==
"WIRE" )
1141 else if( line.at( 0 ) ==
"ATTR" )
1144 attributes.emplace( attr.
key, attr );
1150 auto deviceAttr =
get_opt( attributes,
"Device" );
1151 auto symbolAttr =
get_opt( attributes,
"Symbol" );
1157 aProject.at(
"devices" ).at( deviceAttr->value ).at(
"attributes" ) );
1161 if( symbolAttr && !symbolAttr->value.IsEmpty() )
1162 symbolId = symbolAttr->value;
1164 symbolId = compAttrs.at(
"Symbol" );
1166 auto it = aSymbolMap.find( symbolId );
1167 if( it == aSymbolMap.end() )
1169 wxLogError(
"Symbol of '%s' with uuid '%s' not found.", component->name, symbolId );
1176 wxString unitName = component->name;
1181 auto schSym = std::make_unique<SCH_SYMBOL>( newLibSymbol, libId,
1187 for(
double i = component->rotation; i > 0; i -= 90 )
1188 schSym->Rotate(
VECTOR2I(),
true );
1190 if( component->mirror )
1191 schSym->MirrorHorizontally( 0 );
1193 schSym->SetPosition(
ScalePos( component->position ) );
1197 if(
auto globalNetAttr =
get_opt( attributes,
"Global Net Name" ) )
1200 false,
true, compAttrs, schSym.get() );
1202 for(
SCH_PIN*
pin : schSym->GetAllLibPins() )
1203 pin->SetName( globalNetAttr->value );
1211 schSym->SetRef( &aSchematic->
CurrentSheet(), wxS(
"#PWR?" ) );
1216 auto nameAttr =
get_opt( attributes,
"Name" );
1220 if( nameAttr && !nameAttr->value.IsEmpty() )
1221 netName = nameAttr->value;
1223 netName = compAttrs.at(
"Name" );
1225 std::unique_ptr<SCH_GLOBALLABEL> label = std::make_unique<SCH_GLOBALLABEL>(
1226 ScalePos( component->position ), netName );
1228 std::vector<SCH_PIN*> pins = schSym->GetPins( &aSchematic->
CurrentSheet() );
1230 if( pins.size() > 0 )
1232 switch( pins[0]->GetType() )
1234 case ELECTRICAL_PINTYPE::PT_INPUT:
1235 label->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
1237 case ELECTRICAL_PINTYPE::PT_OUTPUT:
1238 label->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
1240 case ELECTRICAL_PINTYPE::PT_BIDI:
1241 label->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
1247 BOX2I bbox = schSym->GetBodyAndPinsBoundingBox();
1248 bbox.
Offset( -schSym->GetPosition() );
1255 if( bboxCenter.
x >= 0 )
1262 if( bboxCenter.
y >= 0 )
1268 label->SetSpinStyle( spin );
1272 nlohmann::json style = fontStyles[nameAttr->fontStyle];
1274 if( !style.is_null() && style.at( 5 ).is_number() )
1276 double size = style.at( 5 ).get<
double>() * 0.5;
1281 createdItems.push_back( std::move( label ) );
1289 if(
auto valOpt =
get_opt( compAttrs, attrKey ) )
1291 if( valOpt->empty() )
1298 text = schSym->AddField(
1299 SCH_FIELD( schSym.get(), schSym->GetFieldCount(), attrKey ) );
1302 wxString value = *valOpt;
1304 value.Replace( wxS(
"\u2103" ), wxS(
"\u00B0C" ), true );
1306 text->SetText( value );
1307 text->SetVisible(
false );
1311 auto nameAttr =
get_opt( attributes,
"Name" );
1312 auto valueAttr =
get_opt( attributes,
"Value" );
1314 if( valueAttr && valueAttr->value.empty() )
1315 valueAttr->value =
get_def( compAttrs,
"Value", wxString() );
1317 if( nameAttr && nameAttr->value.empty() )
1318 nameAttr->value =
get_def( compAttrs,
"Name", wxString() );
1320 std::optional<EASYEDAPRO::SCH_ATTR> targetValueAttr;
1322 if( valueAttr && !valueAttr->value.empty() && valueAttr->valVisible )
1323 targetValueAttr = valueAttr;
1324 else if( nameAttr && !nameAttr->value.empty() && nameAttr->valVisible )
1325 targetValueAttr = nameAttr;
1326 else if( valueAttr && !valueAttr->value.empty() )
1327 targetValueAttr = valueAttr;
1328 else if( nameAttr && !nameAttr->value.empty() )
1329 targetValueAttr = nameAttr;
1331 if( targetValueAttr )
1334 false,
true, compAttrs, schSym.get() );
1337 if(
auto descrAttr =
get_opt( attributes,
"Description" ) )
1340 false,
true, compAttrs, schSym.get() );
1343 if(
auto designatorAttr =
get_opt( attributes,
"Designator" ) )
1346 *designatorAttr,
false,
true, compAttrs, schSym.get() );
1348 schSym->SetRef( &aSchematic->
CurrentSheet(), designatorAttr->value );
1351 for(
auto& [attrKey, attr] : attributes )
1353 if( attrKey == wxS(
"Name" ) || attrKey == wxS(
"Value" )
1354 || attrKey == wxS(
"Global Net Name" ) || attrKey == wxS(
"Designator" )
1355 || attrKey == wxS(
"Description" ) || attrKey == wxS(
"Device" )
1356 || attrKey == wxS(
"Footprint" ) || attrKey == wxS(
"Symbol" )
1357 || attrKey == wxS(
"Unique ID" ) )
1362 if( attr.value.IsEmpty() )
1369 text = schSym->AddField(
1370 SCH_FIELD( schSym.get(), schSym->GetFieldCount(), attrKey ) );
1373 text->SetPosition( schSym->GetPosition() );
1382 wxString pinKey = parentId + pinInfo.
pin.
id;
1383 auto pinLines =
get_opt( parentedLines, pinKey );
1388 for(
const nlohmann::json& pinLine : *pinLines )
1390 if( pinLine.at( 0 ) !=
"ATTR" )
1395 if( attr.
key != wxS(
"NO_CONNECT" ) )
1400 VECTOR2I pos = schSym->GetPinPhysicalPosition( schPin->GetLibPin() );
1402 std::unique_ptr<SCH_NO_CONNECT> noConn =
1403 std::make_unique<SCH_NO_CONNECT>( pos );
1405 createdItems.push_back( std::move( noConn ) );
1410 createdItems.push_back( std::move( schSym ) );
1414 std::vector<SHAPE_LINE_CHAIN> wireLines;
1418 for(
const std::vector<double>& ptArr : wire->geometry )
1422 for(
size_t i = 1; i < ptArr.size(); i += 2 )
1428 wireLines.push_back( chain );
1430 for(
int segId = 0; segId < chain.
SegmentCount(); segId++ )
1434 std::unique_ptr<SCH_LINE> schLine =
1436 schLine->SetEndPoint( seg.
B );
1438 createdItems.push_back( std::move( schLine ) );
1443 auto netAttr =
get_opt( attributes,
"NET" );
1447 if( !netAttr->valVisible || netAttr->value.IsEmpty() )
1456 VECTOR2I nearestPt = chain.NearestPoint( kpos,
false );
1457 SEG::ecoord dist_sq = ( nearestPt - kpos ).SquaredEuclideanNorm();
1459 if( dist_sq < min_dist_sq )
1461 min_dist_sq = dist_sq;
1462 nearestPos = nearestPt;
1466 std::unique_ptr<SCH_LABEL> label = std::make_unique<SCH_LABEL>();
1471 for(
double i = netAttr->rotation; i > 0; i -= 90 )
1472 label->Rotate90(
true );
1474 label->SetPosition( nearestPos );
1475 label->SetText( netAttr->value );
1479 createdItems.push_back( std::move( label ) );
1487 for( std::unique_ptr<SCH_ITEM>& ptr : createdItems )
1492 sheetBBox.
Merge( ptr->GetBoundingBox() );
1501 offset.
x =
KiROUND( offset.
x / alignGrid ) * alignGrid;
1502 offset.
y =
KiROUND( offset.
y / alignGrid ) * alignGrid;
1509 for( std::unique_ptr<SCH_ITEM>& ptr : createdItems )
1511 ptr->Move( offset );
1512 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 const Vec GetCenter() const
constexpr size_type GetHeight() const
constexpr coord_type GetLeft() const
constexpr coord_type GetTop() const
constexpr void Offset(coord_type dx, coord_type dy)
void SetFlags(EDA_ITEM_FLAGS aMask)
KICAD_T Type() const
Returns the type of object.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual void SetVisible(bool aVisible)
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 color representation with 4 components: red, green, blue, alpha.
A logical library item identifier and consists of various portions much like a URI.
const UTF8 & GetLibItemName() const
Define a library symbol object.
const LIB_ID & GetLibId() const override
void SetUnitCount(int aCount, bool aDuplicateDrawItems=true)
Set the units per symbol count.
int GetNextAvailableFieldId() const
SCH_FIELD & GetValueField() const
Return reference to the value field.
SCH_FIELD & GetFootprintField() const
Return reference to the footprint field.
wxString GetName() const override
void SetDescription(const wxString &aDescription)
Gets the Description field text value */.
void SetKeyWords(const wxString &aKeyWords)
SCH_FIELD & GetReferenceField() const
Return reference to the reference designator field.
SCH_FIELD * FindField(const wxString &aFieldName, bool aCaseInsensitive=false)
Find a field within this symbol matching aFieldName and returns it or NULL if not found.
void AddField(SCH_FIELD *aField)
Add a field.
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
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.
Holds all the data relating to one schematic.
SCH_SHEET_PATH & CurrentSheet() const override
static double Convert(wxString aValue)
static VECTOR2< T > ScalePos(VECTOR2< T > aValue)
double SizeToKi(wxString units)
static T ScaleSize(T aValue)
void ApplyFontStyle(const std::map< wxString, nlohmann::json > &fontStyles, T &text, const wxString &styleStr)
static VECTOR2< T > ScalePosSym(VECTOR2< T > aValue)
SCH_EASYEDAPRO_PARSER(SCHEMATIC *aSchematic, PROGRESS_REPORTER *aProgressReporter)
EASYEDAPRO::SYM_INFO ParseSymbol(const std::vector< nlohmann::json > &aLines, const std::map< wxString, wxString > &aDeviceAttributes)
void ApplyAttrToField(const std::map< wxString, nlohmann::json > &fontStyles, T *text, const EASYEDAPRO::SCH_ATTR &aAttr, bool aIsSym, bool aToSym, const std::map< wxString, wxString > &aDeviceAttributes={}, SCH_SYMBOL *aParent=nullptr)
void ParseSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const nlohmann::json &aProject, std::map< wxString, EASYEDAPRO::SYM_INFO > &aSymbolMap, const std::map< wxString, EASYEDAPRO::BLOB > &aBlobMap, const std::vector< nlohmann::json > &aLines, const wxString &aLibName)
wxString ResolveFieldVariables(const wxString aInput, const std::map< wxString, wxString > &aDeviceAttributes)
void ApplyLineStyle(const std::map< wxString, nlohmann::json > &lineStyles, T &shape, const wxString &styleStr)
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
virtual void MirrorHorizontally(int aCenter)
Mirror item horizontally about aCenter.
virtual void Rotate(const VECTOR2I &aCenter, bool aRotateCCW)
Rotate the item around aCenter 90 degrees in the clockwise direction.
const PAGE_INFO & GetPageSettings() const
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetPageSettings(const PAGE_INFO &aPageSettings)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
SCH_SCREEN * GetScreen() const
BOX2I GetBodyAndPinsBoundingBox() const
Return a bounding box for the symbol body and pins but not the fields.
VECTOR2I::extended_type ecoord
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
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.
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
Simple container to manage line stroke parameters.
void SetLineStyle(LINE_STYLE aLineStyle)
void SetWidth(int aWidth)
void SetColor(const KIGFX::COLOR4D &aColor)
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.
virtual void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
virtual void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
static constexpr extended_type ECOORD_MAX
static constexpr EDA_ANGLE ANGLE_VERTICAL
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
#define ENDPOINT
ends. (Used to support dragging.)
#define STARTPOINT
When a line is selected, these flags indicate which.
void ConvertImageToLibShapes(LIB_SYMBOL *aSymbol, int unit, wxImage img, VECTOR2D pixelScale, VECTOR2D offset)
#define THROW_IO_ERROR(msg)
wxString get_def(const std::map< wxString, wxString > &aMap, const char *aKey, const char *aDefval="")
std::optional< V > get_opt(const std::map< wxString, V > &aMap, const wxString &aKey)
LIB_ID ToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
std::map< wxString, wxString > AnyMapToStringMap(const std::map< wxString, nlohmann::json > &aInput)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
PIN_ORIENTATION
The symbol library pin object orientations.
static const std::vector< wxString > c_attributesWhitelist
static LINE_STYLE ConvertStrokeStyle(const wxString &aStyle)
static const std::vector< wxString > c_attributesWhitelist
static LINE_STYLE ConvertStrokeStyle(int aStyle)
wxString UnescapeHTML(const wxString &aString)
Return a new wxString unescaped from HTML format.
LINE_STYLE
Dashed line types.
std::optional< VECTOR2D > position
std::unique_ptr< LIB_SYMBOL > libSymbol
std::vector< PIN_INFO > pins
std::optional< EASYEDAPRO::SCH_ATTR > symbolAttr
std::map< wxString, int > partUnits
EASYEDAPRO::SYM_HEAD head
constexpr double IUTomm(int iu) const
constexpr int IUToMils(int iu) const
constexpr int MilsToIU(int mils) const
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
@ DESCRIPTION_FIELD
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D