48#include <wx/mstream.h>
71 if( !aValue.ToCDouble( &value ) )
72 THROW_IO_ERROR( wxString::Format(
_(
"Failed to parse value: '%s'" ), aValue ) );
88 else if( aStyle == 1 )
90 else if( aStyle == 2 )
92 else if( aStyle == 3 )
101 T&
text,
const wxString& styleStr )
103 auto it = fontStyles.find( styleStr );
105 if( it == fontStyles.end() )
108 nlohmann::json style = it->second;
110 if( !style.is_array() )
113 if( style.size() < 12 )
116 if( style.at( 3 ).is_string() )
122 if( style.at( 4 ).is_string() )
124 wxString fontname = ( style.at( 4 ) );
126 if( !fontname.IsSameAs( wxS(
"default" ),
false ) )
130 if( style.at( 5 ).is_number() )
132 double size = style.at( 5 ).get<
double>() * 0.5;
136 if( style.at( 10 ).is_number() )
138 int valign = style.at( 10 );
140 if( !
text->GetText().Contains( wxS(
"\n" ) ) )
144 else if( valign == 1 )
146 else if( valign == 2 )
160 if( style.at( 11 ).is_number() )
162 int halign = style.at( 11 );
166 else if( halign == 1 )
168 else if( halign == 2 )
180 T& shape,
const wxString& styleStr )
182 auto it = lineStyles.find( styleStr );
184 if( it == lineStyles.end() )
187 nlohmann::json style = it->second;
189 if( !style.is_array() )
192 if( style.size() < 6 )
197 if( style.at( 2 ).is_string() )
199 wxString colorStr = style.at( 2 ).get<wxString>();
201 if( !colorStr.empty() && colorStr.starts_with( wxS(
"#" ) ) )
208 if( style.at( 3 ).is_number() )
210 int dashStyle = style.at( 3 );
214 if( style.at( 5 ).is_number() )
216 double thickness = style.at( 5 );
220 shape->SetStroke( stroke );
227 bool aIsSym,
bool aToSym,
SCH_SYMBOL* aParent )
244 auto parent = aParent;
247 int orient =
static_cast<SCH_SYMBOL*
>( parent )->GetOrientation();
327 std::unique_ptr<LIB_SYMBOL> ksymbolPtr = std::make_unique<LIB_SYMBOL>( wxEmptyString );
330 std::map<wxString, nlohmann::json> lineStyles;
331 std::map<wxString, nlohmann::json> fontStyles;
332 std::map<wxString, int> partUnits;
334 std::map<int, std::map<wxString, EASYEDAPRO::SCH_ATTR>> unitAttributes;
335 std::map<int, std::map<wxString, std::vector<nlohmann::json>>> unitParentedLines;
339 for(
const nlohmann::json& line : aLines )
341 wxString type = line.at( 0 );
343 if( type == wxS(
"LINESTYLE" ) )
344 lineStyles[line.at( 1 )] = line;
345 else if( type == wxS(
"FONTSTYLE" ) )
346 fontStyles[line.at( 1 )] = line;
347 else if( type == wxS(
"PART" ) )
348 partUnits[line.at( 1 )] = ++totalUnits;
356 for(
const nlohmann::json& line : aLines )
358 wxString type = line.at( 0 );
360 if( type == wxS(
"PART" ) )
362 currentUnit = partUnits.at( line.at( 1 ) );
364 else if( type == wxS(
"RECT" ) )
366 VECTOR2D start( line.at( 2 ), line.at( 3 ) );
367 VECTOR2D end( line.at( 4 ), line.at( 5 ) );
368 wxString styleStr = line.at( 9 );
370 std::unique_ptr<LIB_SHAPE> rect =
371 std::make_unique<LIB_SHAPE>( ksymbol, SHAPE_T::RECTANGLE );
376 rect->SetUnit( currentUnit );
381 else if( type == wxS(
"CIRCLE" ) )
383 VECTOR2D center( line.at( 2 ), line.at( 3 ) );
384 double radius = line.at( 4 );
385 wxString styleStr = line.at( 5 );
387 std::unique_ptr<LIB_SHAPE> circle =
388 std::make_unique<LIB_SHAPE>( ksymbol, SHAPE_T::CIRCLE );
393 circle->SetUnit( currentUnit );
398 else if( type == wxS(
"ARC" ) )
400 VECTOR2D start( line.at( 2 ), line.at( 3 ) );
401 VECTOR2D mid( line.at( 4 ), line.at( 5 ) );
402 VECTOR2D end( line.at( 6 ), line.at( 7 ) );
403 wxString styleStr = line.at( 8 );
411 std::unique_ptr<LIB_SHAPE> shape = std::make_unique<LIB_SHAPE>( ksymbol, SHAPE_T::ARC );
413 shape->SetStart( kstart );
414 shape->SetEnd( kend );
415 shape->SetCenter( kcenter );
417 if(
SEG( start, end ).Side( mid ) !=
SEG( kstart, kend ).Side( shape->GetArcMid() ) )
419 shape->SetStart( kend );
420 shape->SetEnd( kstart );
423 shape->SetUnit( currentUnit );
428 else if( type == wxS(
"POLY" ) )
430 std::vector<double> points = line.at( 2 );
431 wxString styleStr = line.at( 4 );
433 std::unique_ptr<LIB_SHAPE> shape =
434 std::make_unique<LIB_SHAPE>( ksymbol, SHAPE_T::POLY );
436 for(
size_t i = 1; i < points.size(); i += 2 )
441 shape->SetUnit( currentUnit );
446 else if( type == wxS(
"TEXT" ) )
448 VECTOR2D pos( line.at( 2 ), line.at( 3 ) );
449 double angle = line.at( 4 );
450 wxString textStr = line.at( 5 );
451 wxString fontStyleStr = line.at( 6 );
453 std::unique_ptr<LIB_TEXT>
text = std::make_unique<LIB_TEXT>( ksymbol );
461 text->SetTextAngleDegrees( angle );
463 text->SetUnit( currentUnit );
468 else if( type == wxS(
"OBJ" ) )
471 wxString mimeType, data;
475 if( line.at( 3 ).is_number() )
477 start =
VECTOR2D( line.at( 3 ), line.at( 4 ) );
478 size =
VECTOR2D( line.at( 5 ), line.at( 6 ) );
479 angle = line.at( 7 );
480 upsideDown = line.at( 8 );
482 wxString imageUrl = line.at( 9 );
484 if( imageUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
486 wxArrayString paramsArr =
487 wxSplit( imageUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
489 data = imageUrl.AfterFirst(
',' );
491 if( paramsArr.size() > 0 )
493 mimeType = paramsArr[0];
497 else if( line.at( 3 ).is_string() )
499 mimeType = line.at( 3 ).get<wxString>().BeforeFirst(
';' );
501 start =
VECTOR2D( line.at( 4 ), line.at( 5 ) );
502 size =
VECTOR2D( line.at( 6 ), line.at( 7 ) );
503 angle = line.at( 8 );
504 data = line.at( 9 ).get<wxString>();
507 if( mimeType.empty() || data.empty() )
510 wxMemoryBuffer buf = wxBase64Decode( data );
512 if( mimeType == wxS(
"image/svg+xml" ) )
531 libsymImporter.
SetScale( pixelScale );
540 for( std::unique_ptr<EDA_ITEM>& item : libsymImporter.
GetItems() )
545 wxMemoryInputStream memis( buf.GetData(), buf.GetDataLen() );
547 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
548 & ~wxImage::Load_Verbose );
550 if( img.LoadFile( memis, mimeType ) )
552 int dimMul = img.GetWidth() * img.GetHeight();
553 double maxPixels = 30000;
555 if( dimMul > maxPixels )
557 double scale = sqrt( maxPixels / dimMul );
558 img.Rescale( img.GetWidth() *
scale, img.GetHeight() *
scale );
569 else if( type == wxS(
"HEAD" ) )
573 else if( type == wxS(
"PIN" ) )
575 wxString pinId = line.at( 1 );
576 unitParentedLines[currentUnit][pinId].push_back( line );
578 else if( type == wxS(
"ATTR" ) )
580 wxString parentId = line.at( 2 );
582 if( parentId.empty() )
585 unitAttributes[currentUnit].emplace( attr.
key, attr );
589 unitParentedLines[currentUnit][parentId].push_back( line );
604 if(
auto globalNetAttr =
get_opt( unitAttributes[1], wxS(
"Global Net Name" ) ) )
608 wxString globalNetname = globalNetAttr->value;
610 if( !globalNetname.empty() )
613 _(
"Power symbol creates a global label with name '%s'" ),
620 auto designatorAttr =
get_opt( unitAttributes[1], wxS(
"Designator" ) );
622 if( designatorAttr && !designatorAttr->value.empty() )
624 wxString symbolPrefix = designatorAttr->value;
626 if( !symbolPrefix.EndsWith( wxS(
"?" ) ) )
627 symbolPrefix += wxS(
"?" );
633 for(
auto& [unitId, parentedLines] : unitParentedLines )
635 for(
auto& [pinId, lines] : parentedLines )
637 std::optional<EASYEDAPRO::SYM_PIN> epin;
638 std::map<wxString, EASYEDAPRO::SCH_ATTR> pinAttributes;
640 for(
const nlohmann::json& line : lines )
642 wxString type = line.at( 0 );
644 if( type == wxS(
"ATTR" ) )
647 pinAttributes.emplace( attr.
key, attr );
649 else if( type == wxS(
"PIN" ) )
661 std::unique_ptr<LIB_PIN>
pin = std::make_unique<LIB_PIN>( ksymbol );
663 pin->SetUnit( unitId );
670 if( epin->rotation == 0 )
671 orient = PIN_ORIENTATION::PIN_RIGHT;
672 if( epin->rotation == 90 )
673 orient = PIN_ORIENTATION::PIN_UP;
674 if( epin->rotation == 180 )
675 orient = PIN_ORIENTATION::PIN_LEFT;
676 if( epin->rotation == 270 )
677 orient = PIN_ORIENTATION::PIN_DOWN;
679 pin->SetOrientation( orient );
686 else if(
auto pinNameAttr =
get_opt( pinAttributes,
"NAME" ) )
688 pin->SetName( pinNameAttr->value );
689 pinInfo.
name = pinNameAttr->value;
691 if( !pinNameAttr->valVisible )
695 if(
auto pinNumAttr =
get_opt( pinAttributes,
"NUMBER" ) )
697 pin->SetNumber( pinNumAttr->value );
698 pinInfo.
number = pinNumAttr->value;
700 if( !pinNumAttr->valVisible )
706 pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
708 else if(
auto pinTypeAttr =
get_opt( pinAttributes,
"Pin Type" ) )
710 if( pinTypeAttr->value == wxS(
"IN" ) )
711 pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
712 if( pinTypeAttr->value == wxS(
"OUT" ) )
713 pin->SetType( ELECTRICAL_PINTYPE::PT_OUTPUT );
714 if( pinTypeAttr->value == wxS(
"BI" ) )
715 pin->SetType( ELECTRICAL_PINTYPE::PT_BIDI );
718 if(
get_opt( pinAttributes,
"NO_CONNECT" ) )
719 pin->SetType( ELECTRICAL_PINTYPE::PT_NC );
721 if(
pin->GetNumberTextSize() *
int(
pin->GetNumber().size() ) >
pin->GetLength() )
722 pin->SetNumberTextSize(
pin->GetLength() /
pin->GetNumber().size() );
724 symInfo.
pins.push_back( pinInfo );
742 symInfo.
libSymbol = std::move( ksymbolPtr );
749 const nlohmann::json& aProject,
750 std::map<wxString, EASYEDAPRO::SYM_INFO>& aSymbolMap,
751 const std::map<wxString, EASYEDAPRO::BLOB>& aBlobMap,
752 const std::vector<nlohmann::json>& aLines,
753 const wxString& aLibName )
755 std::vector<std::unique_ptr<SCH_ITEM>> createdItems;
757 std::map<wxString, std::vector<nlohmann::json>> parentedLines;
758 std::map<wxString, std::vector<nlohmann::json>> ruleLines;
760 std::map<wxString, nlohmann::json> lineStyles;
761 std::map<wxString, nlohmann::json> fontStyles;
763 for(
const nlohmann::json& line : aLines )
765 wxString type = line.at( 0 );
767 if( type == wxS(
"LINESTYLE" ) )
768 lineStyles[line.at( 1 )] = line;
769 else if( type == wxS(
"FONTSTYLE" ) )
770 fontStyles[line.at( 1 )] = line;
773 for(
const nlohmann::json& line : aLines )
775 wxString type = line.at( 0 );
777 if( type == wxS(
"RECT" ) )
779 VECTOR2D start( line.at( 2 ), line.at( 3 ) );
780 VECTOR2D end( line.at( 4 ), line.at( 5 ) );
781 wxString styleStr = line.at( 9 );
783 std::unique_ptr<SCH_SHAPE> rect = std::make_unique<SCH_SHAPE>( SHAPE_T::RECTANGLE );
785 rect->SetStart(
ScalePos( start ) );
790 createdItems.push_back( std::move( rect ) );
792 else if( type == wxS(
"CIRCLE" ) )
794 VECTOR2D center( line.at( 2 ), line.at( 3 ) );
795 double radius = line.at( 4 );
796 wxString styleStr = line.at( 5 );
798 std::unique_ptr<SCH_SHAPE> circle = std::make_unique<SCH_SHAPE>( SHAPE_T::CIRCLE );
800 circle->SetCenter(
ScalePos( center ) );
805 createdItems.push_back( std::move( circle ) );
807 else if( type == wxS(
"POLY" ) )
809 std::vector<double> points = line.at( 2 );
810 wxString styleStr = line.at( 4 );
814 for(
size_t i = 1; i < points.size(); i += 2 )
817 for(
int segId = 0; segId < chain.
SegmentCount(); segId++ )
821 std::unique_ptr<SCH_LINE> schLine =
823 schLine->SetEndPoint( seg.
B );
827 createdItems.push_back( std::move( schLine ) );
830 else if( type == wxS(
"TEXT" ) )
832 VECTOR2D pos( line.at( 2 ), line.at( 3 ) );
833 double angle = line.at( 4 );
834 wxString textStr = line.at( 5 );
835 wxString fontStyleStr = line.at( 6 );
837 std::unique_ptr<SCH_TEXT>
text =
843 text->SetTextAngleDegrees( angle );
847 createdItems.push_back( std::move(
text ) );
849 else if( type == wxS(
"OBJ" ) )
852 wxString mimeType, base64Data;
856 if( line.at( 3 ).is_number() )
858 start =
VECTOR2D( line.at( 3 ), line.at( 4 ) );
859 size =
VECTOR2D( line.at( 5 ), line.at( 6 ) );
860 angle = line.at( 7 );
861 flipped = line.at( 8 );
863 wxString imageUrl = line.at( 9 );
865 if( imageUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
867 wxArrayString paramsArr =
868 wxSplit( imageUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
870 base64Data = imageUrl.AfterFirst(
',' );
872 if( paramsArr.size() > 0 )
873 mimeType = paramsArr[0];
875 else if( imageUrl.BeforeFirst(
':' ) == wxS(
"blob" ) )
877 wxString objectId = imageUrl.AfterLast(
':' );
879 if(
auto blob =
get_opt( aBlobMap, objectId ) )
881 wxString blobUrl = blob->url;
883 if( blobUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
885 wxArrayString paramsArr = wxSplit(
886 blobUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
888 base64Data = blobUrl.AfterFirst(
',' );
890 if( paramsArr.size() > 0 )
891 mimeType = paramsArr[0];
896 else if( line.at( 3 ).is_string() )
898 mimeType = line.at( 3 ).get<wxString>().BeforeFirst(
';' );
900 start =
VECTOR2D( line.at( 4 ), line.at( 5 ) );
901 size =
VECTOR2D( line.at( 6 ), line.at( 7 ) );
902 angle = line.at( 8 );
903 base64Data = line.at( 9 ).get<wxString>();
909 if( mimeType.empty() || base64Data.empty() )
912 wxMemoryBuffer buf = wxBase64Decode( base64Data );
914 if( mimeType == wxS(
"image/svg+xml" ) )
936 for( std::unique_ptr<EDA_ITEM>& item : schImporter.
GetItems() )
940 for(
double i = angle; i > 0; i -= 90 )
946 schItem->
Rotate( kstart );
950 schItem->
Rotate( kstart );
955 schItem->
Rotate( kstart );
971 createdItems.emplace_back( schItem );
976 std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>();
978 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
979 & ~wxImage::Load_Verbose );
981 if( bitmap->ReadImageFile( buf ) )
983 VECTOR2D kcenter = kstart + ksize / 2;
985 double scaleFactor =
ScaleSize( size.
x ) / bitmap->GetSize().x;
986 bitmap->SetImageScale( scaleFactor );
987 bitmap->SetPosition( kcenter );
989 for(
double i = angle; i > 0; i -= 90 )
990 bitmap->Rotate( kstart );
993 bitmap->MirrorHorizontally( kstart.
x );
995 createdItems.push_back( std::move( bitmap ) );
999 if( type == wxS(
"WIRE" ) )
1001 wxString wireId = line.at( 1 );
1002 parentedLines[wireId].push_back( line );
1004 else if( type == wxS(
"COMPONENT" ) )
1006 wxString compId = line.at( 1 );
1007 parentedLines[compId].push_back( line );
1009 else if( type == wxS(
"ATTR" ) )
1011 wxString compId = line.at( 2 );
1012 parentedLines[compId].push_back( line );
1016 for(
auto& [parentId, lines] : parentedLines )
1018 std::optional<EASYEDAPRO::SCH_COMPONENT> component;
1019 std::optional<EASYEDAPRO::SCH_WIRE> wire;
1020 std::map<wxString, EASYEDAPRO::SCH_ATTR> attributes;
1022 for(
const nlohmann::json& line : lines )
1024 if( line.at( 0 ) ==
"COMPONENT" )
1028 else if( line.at( 0 ) ==
"WIRE" )
1032 else if( line.at( 0 ) ==
"ATTR" )
1035 attributes.emplace( attr.
key, attr );
1041 auto deviceAttr =
get_opt( attributes,
"Device" );
1042 auto symbolAttr =
get_opt( attributes,
"Symbol" );
1047 nlohmann::json compAttrs =
1048 aProject.at(
"devices" ).at( deviceAttr->value ).at(
"attributes" );
1052 if( symbolAttr && !symbolAttr->value.IsEmpty() )
1053 symbolId = symbolAttr->value;
1055 symbolId = compAttrs.at(
"Symbol" ).get<wxString>();
1057 auto it = aSymbolMap.find( symbolId );
1058 if( it == aSymbolMap.end() )
1060 wxLogError(
"Symbol of '%s' with uuid '%s' not found.", component->name, symbolId );
1067 wxString unitName = component->name;
1072 std::unique_ptr<SCH_SYMBOL> schSym =
1073 std::make_unique<SCH_SYMBOL>( newLibSymbol, libId, &aSchematic->
CurrentSheet(),
1078 for(
double i = component->rotation; i > 0; i -= 90 )
1081 if( component->mirror )
1082 schSym->MirrorHorizontally( 0 );
1084 schSym->SetPosition(
ScalePos( component->position ) );
1088 if(
auto globalNetAttr =
get_opt( attributes,
"Global Net Name" ) )
1091 false,
true, schSym.get() );
1093 for(
LIB_PIN*
pin : schSym->GetAllLibPins() )
1094 pin->SetName( globalNetAttr->value );
1102 schSym->SetRef( &aSchematic->
CurrentSheet(), wxS(
"#PWR?" ) );
1107 auto nameAttr =
get_opt( attributes,
"Name" );
1111 std::unique_ptr<SCH_GLOBALLABEL> label = std::make_unique<SCH_GLOBALLABEL>(
1112 ScalePos( component->position ), nameAttr->value );
1116 for(
double i = component->rotation; i > 0; i -= 90 )
1119 label->SetSpinStyle( spin );
1123 wxString symStr = esymInfo.
symbolAttr->value;
1125 if( symStr == wxS(
"Netport-IN" ) )
1126 label->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
1127 if( symStr == wxS(
"Netport-OUT" ) )
1128 label->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
1129 if( symStr == wxS(
"Netport-BI" ) )
1130 label->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
1133 nlohmann::json style = fontStyles[nameAttr->fontStyle];
1135 if( !style.is_null() && style.at( 5 ).is_number() )
1137 double size = style.at( 5 ).get<
double>() * 0.5;
1141 createdItems.push_back( std::move( label ) );
1148 auto nameAttr =
get_opt( attributes,
"Name" );
1149 auto valueAttr =
get_opt( attributes,
"Value" );
1151 std::optional<EASYEDAPRO::SCH_ATTR> targetValueAttr;
1153 if( valueAttr && !valueAttr->value.empty() && valueAttr->valVisible )
1154 targetValueAttr = valueAttr;
1155 else if( nameAttr && !nameAttr->value.empty() && nameAttr->valVisible )
1156 targetValueAttr = nameAttr;
1157 else if( valueAttr && !valueAttr->value.empty() )
1158 targetValueAttr = valueAttr;
1159 else if( nameAttr && !nameAttr->value.empty() )
1160 targetValueAttr = nameAttr;
1162 if( targetValueAttr )
1164 false,
true, schSym.get() );
1166 if(
auto descrAttr =
get_opt( attributes,
"Description" ) )
1168 false,
true, schSym.get() );
1170 if(
auto designatorAttr =
get_opt( attributes,
"Designator" ) )
1173 *designatorAttr,
false,
true, schSym.get() );
1175 schSym->SetRef( &aSchematic->
CurrentSheet(), designatorAttr->value );
1178 for(
auto& [attrKey, attr] : attributes )
1180 if( attrKey == wxS(
"Name" ) || attrKey == wxS(
"Value" )
1181 || attrKey == wxS(
"Global Net Name" ) || attrKey == wxS(
"Designator" )
1182 || attrKey == wxS(
"Description" ) || attrKey == wxS(
"Device" )
1183 || attrKey == wxS(
"Footprint" ) || attrKey == wxS(
"Symbol" )
1184 || attrKey == wxS(
"Unique ID" ) )
1189 if( attr.value.IsEmpty() )
1193 new SCH_FIELD( schSym.get(), schSym->GetFieldCount(), attrKey );
1195 text->SetPosition( schSym->GetPosition() );
1198 schSym->AddField( *
text );
1204 wxString pinKey = parentId + pinInfo.
pin.
id;
1205 auto pinLines =
get_opt( parentedLines, pinKey );
1210 for(
const nlohmann::json& pinLine : *pinLines )
1212 if( pinLine.at( 0 ) !=
"ATTR" )
1217 if( attr.
key != wxS(
"NO_CONNECT" ) )
1222 VECTOR2I pos = schSym->GetPinPhysicalPosition( schPin->GetLibPin() );
1224 std::unique_ptr<SCH_NO_CONNECT> noConn =
1225 std::make_unique<SCH_NO_CONNECT>( pos );
1227 createdItems.push_back( std::move( noConn ) );
1232 createdItems.push_back( std::move( schSym ) );
1236 std::vector<SHAPE_LINE_CHAIN> wireLines;
1240 for(
const std::vector<double>& ptArr : wire->geometry )
1244 for(
size_t i = 1; i < ptArr.size(); i += 2 )
1250 wireLines.push_back( chain );
1252 for(
int segId = 0; segId < chain.
SegmentCount(); segId++ )
1256 std::unique_ptr<SCH_LINE> schLine =
1258 schLine->SetEndPoint( seg.
B );
1260 createdItems.push_back( std::move( schLine ) );
1265 auto netAttr =
get_opt( attributes,
"NET" );
1269 if( !netAttr->valVisible )
1278 VECTOR2I nearestPt = chain.NearestPoint( kpos,
false );
1279 SEG::ecoord dist_sq = ( nearestPt - kpos ).SquaredEuclideanNorm();
1281 if( dist_sq < min_dist_sq )
1283 min_dist_sq = dist_sq;
1284 nearestPos = nearestPt;
1288 std::unique_ptr<SCH_LABEL> label = std::make_unique<SCH_LABEL>();
1293 for(
double i = netAttr->rotation; i > 0; i -= 90 )
1294 label->Rotate90(
true );
1296 label->SetPosition( nearestPos );
1297 label->SetText( netAttr->value );
1301 createdItems.push_back( std::move( label ) );
1309 for( std::unique_ptr<SCH_ITEM>& ptr : createdItems )
1314 sheetBBox.
Merge( ptr->GetBoundingBox() );
1323 offset.
x =
KiROUND( offset.
x / alignGrid ) * alignGrid;
1324 offset.
y =
KiROUND( offset.
y / alignGrid ) * alignGrid;
1331 for( std::unique_ptr<SCH_ITEM>& ptr : createdItems )
1333 ptr->Move( offset );
1334 screen->
Append( ptr.release() );
constexpr EDA_IU_SCALE schIUScale
coord_type GetTop() const
coord_type GetHeight() const
coord_type GetWidth() const
coord_type GetLeft() const
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
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)
virtual void SetText(const wxString &aText)
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)
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
The base class for drawable items used by schematic library symbols.
Define a library symbol object.
void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
void SetUnitCount(int aCount, bool aDuplicateDrawItems=true)
Set the units per symbol count.
LIB_FIELD & GetFootprintField()
Return reference to the footprint field.
void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
LIB_ID GetLibId() const override
wxString GetName() const override
void SetDescription(const wxString &aDescription)
Gets the Description field text value */.
void SetKeyWords(const wxString &aKeyWords)
void AddDrawItem(LIB_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
LIB_FIELD & GetValueField()
Return reference to the value field.
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.
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)
EASYEDAPRO::SYM_INFO ParseSymbol(const std::vector< nlohmann::json > &aLines)
static VECTOR2< T > ScalePosSym(VECTOR2< T > aValue)
SCH_EASYEDAPRO_PARSER(SCHEMATIC *aSchematic, PROGRESS_REPORTER *aProgressReporter)
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)
void ApplyAttrToField(const std::map< wxString, nlohmann::json > &fontStyles, T *text, const EASYEDAPRO::SCH_ATTR &aAttr, bool aIsSym, bool aToSym, SCH_SYMBOL *aParent=nullptr)
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,...
Base class for any item which can be embedded within the SCHEMATIC container class,...
virtual void MirrorHorizontally(int aCenter)=0
Mirror item horizontally about aCenter.
virtual void Rotate(const VECTOR2I &aCenter)=0
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.
static constexpr extended_type ECOORD_MAX
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
static constexpr EDA_ANGLE & ANGLE_VERTICAL
#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)
std::optional< V > get_opt(const std::map< wxString, V > &aMap, const wxString &aKey)
LIB_ID ToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
PIN_ORIENTATION
The symbol library pin object orientations.
static LINE_STYLE ConvertStrokeStyle(const wxString &aStyle)
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".
const VECTOR2I CalcArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc or circle given three points on its circumference.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
VECTOR2< double > VECTOR2D