44#include <wx/mstream.h>
67 if( !aValue.ToCDouble( &value ) )
68 THROW_IO_ERROR( wxString::Format(
_(
"Failed to parse value: '%s'" ), aValue ) );
84 else if( aStyle == 1 )
86 else if( aStyle == 2 )
88 else if( aStyle == 3 )
97 T&
text,
const wxString& styleStr )
99 auto it = fontStyles.find( styleStr );
101 if( it == fontStyles.end() )
104 nlohmann::json style = it->second;
106 if( !style.is_array() )
109 if( style.size() < 12 )
112 if( style.at( 3 ).is_string() )
118 if( style.at( 4 ).is_string() )
120 wxString fontname = ( style.at( 4 ) );
122 if( !fontname.IsSameAs( wxS(
"default" ),
false ) )
126 if( style.at( 5 ).is_number() )
128 double size = style.at( 5 ).get<
double>() * 0.5;
132 if( style.at( 10 ).is_number() )
134 int valign = style.at( 10 );
136 if( !
text->GetText().Contains( wxS(
"\n" ) ) )
140 else if( valign == 1 )
142 else if( valign == 2 )
156 if( style.at( 11 ).is_number() )
158 int halign = style.at( 11 );
162 else if( halign == 1 )
164 else if( halign == 2 )
176 T& shape,
const wxString& styleStr )
178 auto it = lineStyles.find( styleStr );
180 if( it == lineStyles.end() )
183 nlohmann::json style = it->second;
185 if( !style.is_array() )
188 if( style.size() < 6 )
193 if( style.at( 2 ).is_string() )
195 wxString colorStr = style.at( 2 ).get<wxString>();
197 if( !colorStr.empty() && colorStr.starts_with( wxS(
"#" ) ) )
204 if( style.at( 3 ).is_number() )
206 int dashStyle = style.at( 3 );
210 if( style.at( 5 ).is_number() )
212 double thickness = style.at( 5 );
216 shape->SetStroke( stroke );
221 const wxString aInput,
const std::map<wxString, wxString>& aDeviceAttributes )
223 wxString inputText = aInput;
224 wxString resolvedText;
225 int variableCount = 0;
231 if( !inputText.StartsWith( wxS(
"={" ) ) )
234 resolvedText.Clear();
237 for(
size_t i = 1; i < inputText.size(); )
239 wxUniChar c = inputText[i++];
244 bool endFound =
false;
246 while( i < inputText.size() )
263 get_def( aDeviceAttributes, varName, wxString::Format(
"{%s!}", varName ) );
265 resolvedText << varValue;
273 inputText = resolvedText;
275 }
while( variableCount > 0 );
284 bool aIsSym,
bool aToSym,
285 const std::map<wxString, wxString>& aDeviceAttributes,
303 auto parent = aParent;
306 int orient =
static_cast<SCH_SYMBOL*
>( parent )->GetOrientation();
386 std::unique_ptr<LIB_SYMBOL> ksymbolPtr = std::make_unique<LIB_SYMBOL>( wxEmptyString );
389 std::map<wxString, nlohmann::json> lineStyles;
390 std::map<wxString, nlohmann::json> fontStyles;
391 std::map<wxString, int> partUnits;
393 std::map<int, std::map<wxString, EASYEDAPRO::SCH_ATTR>> unitAttributes;
394 std::map<int, std::map<wxString, std::vector<nlohmann::json>>> unitParentedLines;
398 for(
const nlohmann::json& line : aLines )
400 wxString type = line.at( 0 );
402 if( type == wxS(
"LINESTYLE" ) )
403 lineStyles[line.at( 1 )] = line;
404 else if( type == wxS(
"FONTSTYLE" ) )
405 fontStyles[line.at( 1 )] = line;
406 else if( type == wxS(
"PART" ) )
407 partUnits[line.at( 1 )] = ++totalUnits;
415 for(
const nlohmann::json& line : aLines )
417 wxString type = line.at( 0 );
419 if( type == wxS(
"PART" ) )
421 currentUnit = partUnits.at( line.at( 1 ) );
423 else if( type == wxS(
"RECT" ) )
425 VECTOR2D start( line.at( 2 ), line.at( 3 ) );
426 VECTOR2D end( line.at( 4 ), line.at( 5 ) );
427 wxString styleStr = line.at( 9 );
429 auto rect = std::make_unique<SCH_SHAPE>( SHAPE_T::RECTANGLE,
LAYER_DEVICE );
434 rect->SetUnit( currentUnit );
439 else if( type == wxS(
"CIRCLE" ) )
441 VECTOR2D center( line.at( 2 ), line.at( 3 ) );
442 double radius = line.at( 4 );
443 wxString styleStr = line.at( 5 );
445 auto circle = std::make_unique<SCH_SHAPE>( SHAPE_T::CIRCLE,
LAYER_DEVICE );
450 circle->SetUnit( currentUnit );
455 else if( type == wxS(
"ARC" ) )
457 VECTOR2D start( line.at( 2 ), line.at( 3 ) );
458 VECTOR2D mid( line.at( 4 ), line.at( 5 ) );
459 VECTOR2D end( line.at( 6 ), line.at( 7 ) );
460 wxString styleStr = line.at( 8 );
468 auto shape = std::make_unique<SCH_SHAPE>( SHAPE_T::ARC,
LAYER_DEVICE );
470 shape->SetStart( kstart );
471 shape->SetEnd( kend );
472 shape->SetCenter( kcenter );
474 if(
SEG( start, end ).Side( mid ) !=
SEG( kstart, kend ).Side( shape->GetArcMid() ) )
476 shape->SetStart( kend );
477 shape->SetEnd( kstart );
480 shape->SetUnit( currentUnit );
485 else if( type == wxS(
"POLY" ) )
487 std::vector<double> points = line.at( 2 );
488 wxString styleStr = line.at( 4 );
490 auto shape = std::make_unique<SCH_SHAPE>( SHAPE_T::POLY,
LAYER_DEVICE );
492 for(
size_t i = 1; i < points.size(); i += 2 )
495 shape->SetUnit( currentUnit );
500 else if( type == wxS(
"TEXT" ) )
502 VECTOR2D pos( line.at( 2 ), line.at( 3 ) );
503 double angle = line.at( 4 );
504 wxString textStr = line.at( 5 );
505 wxString fontStyleStr = line.at( 6 );
512 text->SetTextAngleDegrees( angle );
514 text->SetUnit( currentUnit );
519 else if( type == wxS(
"OBJ" ) )
522 wxString mimeType, data;
526 if( line.at( 3 ).is_number() )
528 start =
VECTOR2D( line.at( 3 ), line.at( 4 ) );
529 size =
VECTOR2D( line.at( 5 ), line.at( 6 ) );
531 upsideDown = line.at( 8 );
533 wxString imageUrl = line.at( 9 );
535 if( imageUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
537 wxArrayString paramsArr =
538 wxSplit( imageUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
540 data = imageUrl.AfterFirst(
',' );
542 if( paramsArr.size() > 0 )
544 mimeType = paramsArr[0];
548 else if( line.at( 3 ).is_string() )
550 mimeType = line.at( 3 ).get<wxString>().BeforeFirst(
';' );
552 start =
VECTOR2D( line.at( 4 ), line.at( 5 ) );
553 size =
VECTOR2D( line.at( 6 ), line.at( 7 ) );
555 data = line.at( 9 ).get<wxString>();
558 if( mimeType.empty() || data.empty() )
561 wxMemoryBuffer buf = wxBase64Decode( data );
563 if( mimeType == wxS(
"image/svg+xml" ) )
582 libsymImporter.
SetScale( pixelScale );
591 for( std::unique_ptr<EDA_ITEM>& item : libsymImporter.
GetItems() )
596 wxMemoryInputStream memis( buf.GetData(), buf.GetDataLen() );
598 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
599 & ~wxImage::Load_Verbose );
601 if( img.LoadFile( memis, mimeType ) )
603 int dimMul = img.GetWidth() * img.GetHeight();
604 double maxPixels = 30000;
606 if( dimMul > maxPixels )
608 double scale = sqrt( maxPixels / dimMul );
609 img.Rescale( img.GetWidth() *
scale, img.GetHeight() *
scale );
620 else if( type == wxS(
"HEAD" ) )
624 else if( type == wxS(
"PIN" ) )
626 wxString pinId = line.at( 1 );
627 unitParentedLines[currentUnit][pinId].push_back( line );
629 else if( type == wxS(
"ATTR" ) )
631 wxString parentId = line.at( 2 );
633 if( parentId.empty() )
636 unitAttributes[currentUnit].emplace( attr.
key, attr );
640 unitParentedLines[currentUnit][parentId].push_back( line );
655 if(
auto globalNetAttr =
get_opt( unitAttributes[1], wxS(
"Global Net Name" ) ) )
659 wxString globalNetname = globalNetAttr->value;
661 if( !globalNetname.empty() )
664 _(
"Power symbol creates a global label with name '%s'" ),
671 auto designatorAttr =
get_opt( unitAttributes[1], wxS(
"Designator" ) );
673 if( designatorAttr && !designatorAttr->value.empty() )
675 wxString symbolPrefix = designatorAttr->value;
677 if( !symbolPrefix.EndsWith( wxS(
"?" ) ) )
678 symbolPrefix += wxS(
"?" );
684 for(
auto& [unitId, parentedLines] : unitParentedLines )
686 for(
auto& [pinId, lines] : parentedLines )
688 std::optional<EASYEDAPRO::SYM_PIN> epin;
689 std::map<wxString, EASYEDAPRO::SCH_ATTR> pinAttributes;
691 for(
const nlohmann::json& line : lines )
693 wxString type = line.at( 0 );
695 if( type == wxS(
"ATTR" ) )
698 pinAttributes.emplace( attr.
key, attr );
700 else if( type == wxS(
"PIN" ) )
712 std::unique_ptr<SCH_PIN>
pin = std::make_unique<SCH_PIN>( ksymbol );
714 pin->SetUnit( unitId );
721 if( epin->rotation == 0 )
722 orient = PIN_ORIENTATION::PIN_RIGHT;
723 if( epin->rotation == 90 )
724 orient = PIN_ORIENTATION::PIN_UP;
725 if( epin->rotation == 180 )
726 orient = PIN_ORIENTATION::PIN_LEFT;
727 if( epin->rotation == 270 )
728 orient = PIN_ORIENTATION::PIN_DOWN;
730 pin->SetOrientation( orient );
737 else if(
auto pinNameAttr =
get_opt( pinAttributes,
"NAME" ) )
739 pin->SetName( pinNameAttr->value );
740 pinInfo.
name = pinNameAttr->value;
742 if( !pinNameAttr->valVisible )
746 if(
auto pinNumAttr =
get_opt( pinAttributes,
"NUMBER" ) )
748 pin->SetNumber( pinNumAttr->value );
749 pinInfo.
number = pinNumAttr->value;
751 if( !pinNumAttr->valVisible )
757 pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
759 else if(
auto pinTypeAttr =
get_opt( pinAttributes,
"Pin Type" ) )
761 if( pinTypeAttr->value == wxS(
"IN" ) )
762 pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
763 if( pinTypeAttr->value == wxS(
"OUT" ) )
764 pin->SetType( ELECTRICAL_PINTYPE::PT_OUTPUT );
765 if( pinTypeAttr->value == wxS(
"BI" ) )
766 pin->SetType( ELECTRICAL_PINTYPE::PT_BIDI );
769 if(
get_opt( pinAttributes,
"NO_CONNECT" ) )
770 pin->SetType( ELECTRICAL_PINTYPE::PT_NC );
772 if(
pin->GetNumberTextSize() *
int(
pin->GetNumber().size() ) >
pin->GetLength() )
773 pin->SetNumberTextSize(
pin->GetLength() /
pin->GetNumber().size() );
775 symInfo.
pins.push_back( pinInfo );
793 symInfo.
libSymbol = std::move( ksymbolPtr );
800 const nlohmann::json& aProject,
801 std::map<wxString, EASYEDAPRO::SYM_INFO>& aSymbolMap,
802 const std::map<wxString, EASYEDAPRO::BLOB>& aBlobMap,
803 const std::vector<nlohmann::json>& aLines,
804 const wxString& aLibName )
806 std::vector<std::unique_ptr<SCH_ITEM>> createdItems;
808 std::map<wxString, std::vector<nlohmann::json>> parentedLines;
809 std::map<wxString, std::vector<nlohmann::json>> ruleLines;
811 std::map<wxString, nlohmann::json> lineStyles;
812 std::map<wxString, nlohmann::json> fontStyles;
814 for(
const nlohmann::json& line : aLines )
816 wxString type = line.at( 0 );
818 if( type == wxS(
"LINESTYLE" ) )
819 lineStyles[line.at( 1 )] = line;
820 else if( type == wxS(
"FONTSTYLE" ) )
821 fontStyles[line.at( 1 )] = line;
824 for(
const nlohmann::json& line : aLines )
826 wxString type = line.at( 0 );
828 if( type == wxS(
"RECT" ) )
830 VECTOR2D start( line.at( 2 ), line.at( 3 ) );
831 VECTOR2D end( line.at( 4 ), line.at( 5 ) );
832 wxString styleStr = line.at( 9 );
834 std::unique_ptr<SCH_SHAPE> rect = std::make_unique<SCH_SHAPE>( SHAPE_T::RECTANGLE );
836 rect->SetStart(
ScalePos( start ) );
841 createdItems.push_back( std::move( rect ) );
843 else if( type == wxS(
"CIRCLE" ) )
845 VECTOR2D center( line.at( 2 ), line.at( 3 ) );
846 double radius = line.at( 4 );
847 wxString styleStr = line.at( 5 );
849 std::unique_ptr<SCH_SHAPE> circle = std::make_unique<SCH_SHAPE>( SHAPE_T::CIRCLE );
851 circle->SetCenter(
ScalePos( center ) );
856 createdItems.push_back( std::move( circle ) );
858 else if( type == wxS(
"POLY" ) )
860 std::vector<double> points = line.at( 2 );
861 wxString styleStr = line.at( 4 );
865 for(
size_t i = 1; i < points.size(); i += 2 )
868 for(
int segId = 0; segId < chain.
SegmentCount(); segId++ )
872 std::unique_ptr<SCH_LINE> schLine =
874 schLine->SetEndPoint( seg.
B );
878 createdItems.push_back( std::move( schLine ) );
881 else if( type == wxS(
"TEXT" ) )
883 VECTOR2D pos( line.at( 2 ), line.at( 3 ) );
884 double angle = line.at( 4 );
885 wxString textStr = line.at( 5 );
886 wxString fontStyleStr = line.at( 6 );
888 std::unique_ptr<SCH_TEXT>
text =
894 text->SetTextAngleDegrees( angle );
898 createdItems.push_back( std::move(
text ) );
900 else if( type == wxS(
"OBJ" ) )
903 wxString mimeType, base64Data;
907 if( line.at( 3 ).is_number() )
909 start =
VECTOR2D( line.at( 3 ), line.at( 4 ) );
910 size =
VECTOR2D( line.at( 5 ), line.at( 6 ) );
911 angle = line.at( 7 );
912 flipped = line.at( 8 );
914 wxString imageUrl = line.at( 9 );
916 if( imageUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
918 wxArrayString paramsArr =
919 wxSplit( imageUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
921 base64Data = imageUrl.AfterFirst(
',' );
923 if( paramsArr.size() > 0 )
924 mimeType = paramsArr[0];
926 else if( imageUrl.BeforeFirst(
':' ) == wxS(
"blob" ) )
928 wxString objectId = imageUrl.AfterLast(
':' );
930 if(
auto blob =
get_opt( aBlobMap, objectId ) )
932 wxString blobUrl = blob->url;
934 if( blobUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
936 wxArrayString paramsArr = wxSplit(
937 blobUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
939 base64Data = blobUrl.AfterFirst(
',' );
941 if( paramsArr.size() > 0 )
942 mimeType = paramsArr[0];
947 else if( line.at( 3 ).is_string() )
949 mimeType = line.at( 3 ).get<wxString>().BeforeFirst(
';' );
951 start =
VECTOR2D( line.at( 4 ), line.at( 5 ) );
952 size =
VECTOR2D( line.at( 6 ), line.at( 7 ) );
953 angle = line.at( 8 );
954 base64Data = line.at( 9 ).get<wxString>();
960 if( mimeType.empty() || base64Data.empty() )
963 wxMemoryBuffer buf = wxBase64Decode( base64Data );
965 if( mimeType == wxS(
"image/svg+xml" ) )
987 for( std::unique_ptr<EDA_ITEM>& item : schImporter.
GetItems() )
991 for(
double i = angle; i > 0; i -= 90 )
997 schItem->
Rotate( kstart,
false );
1001 schItem->
Rotate( kstart,
false );
1006 schItem->
Rotate( kstart,
false );
1022 createdItems.emplace_back( schItem );
1027 std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>();
1029 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
1030 & ~wxImage::Load_Verbose );
1032 if( bitmap->ReadImageFile( buf ) )
1034 VECTOR2D kcenter = kstart + ksize / 2;
1036 double scaleFactor =
ScaleSize( size.
x ) / bitmap->GetSize().x;
1037 bitmap->SetImageScale( scaleFactor );
1038 bitmap->SetPosition( kcenter );
1040 for(
double i = angle; i > 0; i -= 90 )
1041 bitmap->Rotate( kstart,
false );
1044 bitmap->MirrorHorizontally( kstart.
x );
1046 createdItems.push_back( std::move( bitmap ) );
1050 if( type == wxS(
"WIRE" ) )
1052 wxString wireId = line.at( 1 );
1053 parentedLines[wireId].push_back( line );
1055 else if( type == wxS(
"COMPONENT" ) )
1057 wxString compId = line.at( 1 );
1058 parentedLines[compId].push_back( line );
1060 else if( type == wxS(
"ATTR" ) )
1062 wxString compId = line.at( 2 );
1063 parentedLines[compId].push_back( line );
1067 for(
auto& [parentId, lines] : parentedLines )
1069 std::optional<EASYEDAPRO::SCH_COMPONENT> component;
1070 std::optional<EASYEDAPRO::SCH_WIRE> wire;
1071 std::map<wxString, EASYEDAPRO::SCH_ATTR> attributes;
1073 for(
const nlohmann::json& line : lines )
1075 if( line.at( 0 ) ==
"COMPONENT" )
1079 else if( line.at( 0 ) ==
"WIRE" )
1083 else if( line.at( 0 ) ==
"ATTR" )
1086 attributes.emplace( attr.
key, attr );
1092 auto deviceAttr =
get_opt( attributes,
"Device" );
1093 auto symbolAttr =
get_opt( attributes,
"Symbol" );
1098 nlohmann::json compAttrs =
1099 aProject.at(
"devices" ).at( deviceAttr->value ).at(
"attributes" );
1103 if( symbolAttr && !symbolAttr->value.IsEmpty() )
1104 symbolId = symbolAttr->value;
1106 symbolId = compAttrs.at(
"Symbol" ).get<wxString>();
1108 auto it = aSymbolMap.find( symbolId );
1109 if( it == aSymbolMap.end() )
1111 wxLogError(
"Symbol of '%s' with uuid '%s' not found.", component->name, symbolId );
1118 wxString unitName = component->name;
1123 auto schSym = std::make_unique<SCH_SYMBOL>( newLibSymbol, libId,
1129 for(
double i = component->rotation; i > 0; i -= 90 )
1130 schSym->Rotate(
VECTOR2I(),
false );
1132 if( component->mirror )
1133 schSym->MirrorHorizontally( 0 );
1135 schSym->SetPosition(
ScalePos( component->position ) );
1139 if(
auto globalNetAttr =
get_opt( attributes,
"Global Net Name" ) )
1142 false,
true, compAttrs, schSym.get() );
1144 for(
SCH_PIN*
pin : schSym->GetAllLibPins() )
1145 pin->SetName( globalNetAttr->value );
1153 schSym->SetRef( &aSchematic->
CurrentSheet(), wxS(
"#PWR?" ) );
1158 auto nameAttr =
get_opt( attributes,
"Name" );
1162 std::unique_ptr<SCH_GLOBALLABEL> label = std::make_unique<SCH_GLOBALLABEL>(
1163 ScalePos( component->position ), nameAttr->value );
1169 wxString symStr = esymInfo.
symbolAttr->value;
1171 if( symStr == wxS(
"Netport-IN" ) )
1174 label->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
1176 if( symStr == wxS(
"Netport-OUT" ) )
1179 label->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT );
1181 if( symStr == wxS(
"Netport-BI" ) )
1184 label->SetShape( LABEL_FLAG_SHAPE::L_BIDI );
1188 for(
double i = component->rotation; i > 0; i -= 90 )
1191 label->SetSpinStyle( spin );
1193 nlohmann::json style = fontStyles[nameAttr->fontStyle];
1195 if( !style.is_null() && style.at( 5 ).is_number() )
1197 double size = style.at( 5 ).get<
double>() * 0.5;
1201 createdItems.push_back( std::move( label ) );
1208 auto nameAttr =
get_opt( attributes,
"Name" );
1209 auto valueAttr =
get_opt( attributes,
"Value" );
1211 std::optional<EASYEDAPRO::SCH_ATTR> targetValueAttr;
1213 if( valueAttr && !valueAttr->value.empty() && valueAttr->valVisible )
1214 targetValueAttr = valueAttr;
1215 else if( nameAttr && !nameAttr->value.empty() && nameAttr->valVisible )
1216 targetValueAttr = nameAttr;
1217 else if( valueAttr && !valueAttr->value.empty() )
1218 targetValueAttr = valueAttr;
1219 else if( nameAttr && !nameAttr->value.empty() )
1220 targetValueAttr = nameAttr;
1222 if( targetValueAttr )
1225 false,
true, compAttrs, schSym.get() );
1228 if(
auto descrAttr =
get_opt( attributes,
"Description" ) )
1231 false,
true, compAttrs, schSym.get() );
1234 if(
auto designatorAttr =
get_opt( attributes,
"Designator" ) )
1237 *designatorAttr,
false,
true, compAttrs, schSym.get() );
1239 schSym->SetRef( &aSchematic->
CurrentSheet(), designatorAttr->value );
1242 for(
auto& [attrKey, attr] : attributes )
1244 if( attrKey == wxS(
"Name" ) || attrKey == wxS(
"Value" )
1245 || attrKey == wxS(
"Global Net Name" ) || attrKey == wxS(
"Designator" )
1246 || attrKey == wxS(
"Description" ) || attrKey == wxS(
"Device" )
1247 || attrKey == wxS(
"Footprint" ) || attrKey == wxS(
"Symbol" )
1248 || attrKey == wxS(
"Unique ID" ) )
1253 if( attr.value.IsEmpty() )
1257 new SCH_FIELD( schSym.get(), schSym->GetFieldCount(), attrKey );
1259 text->SetPosition( schSym->GetPosition() );
1264 schSym->AddField( *
text );
1270 wxString pinKey = parentId + pinInfo.
pin.
id;
1271 auto pinLines =
get_opt( parentedLines, pinKey );
1276 for(
const nlohmann::json& pinLine : *pinLines )
1278 if( pinLine.at( 0 ) !=
"ATTR" )
1283 if( attr.
key != wxS(
"NO_CONNECT" ) )
1288 VECTOR2I pos = schSym->GetPinPhysicalPosition( schPin->GetLibPin() );
1290 std::unique_ptr<SCH_NO_CONNECT> noConn =
1291 std::make_unique<SCH_NO_CONNECT>( pos );
1293 createdItems.push_back( std::move( noConn ) );
1298 createdItems.push_back( std::move( schSym ) );
1302 std::vector<SHAPE_LINE_CHAIN> wireLines;
1306 for(
const std::vector<double>& ptArr : wire->geometry )
1310 for(
size_t i = 1; i < ptArr.size(); i += 2 )
1316 wireLines.push_back( chain );
1318 for(
int segId = 0; segId < chain.
SegmentCount(); segId++ )
1322 std::unique_ptr<SCH_LINE> schLine =
1324 schLine->SetEndPoint( seg.
B );
1326 createdItems.push_back( std::move( schLine ) );
1331 auto netAttr =
get_opt( attributes,
"NET" );
1335 if( !netAttr->valVisible )
1344 VECTOR2I nearestPt = chain.NearestPoint( kpos,
false );
1345 SEG::ecoord dist_sq = ( nearestPt - kpos ).SquaredEuclideanNorm();
1347 if( dist_sq < min_dist_sq )
1349 min_dist_sq = dist_sq;
1350 nearestPos = nearestPt;
1354 std::unique_ptr<SCH_LABEL> label = std::make_unique<SCH_LABEL>();
1359 for(
double i = netAttr->rotation; i > 0; i -= 90 )
1360 label->Rotate90(
true );
1362 label->SetPosition( nearestPos );
1363 label->SetText( netAttr->value );
1367 createdItems.push_back( std::move( label ) );
1375 for( std::unique_ptr<SCH_ITEM>& ptr : createdItems )
1380 sheetBBox.
Merge( ptr->GetBoundingBox() );
1389 offset.
x =
KiROUND( offset.
x / alignGrid ) * alignGrid;
1390 offset.
y =
KiROUND( offset.
y / alignGrid ) * alignGrid;
1397 for( std::unique_ptr<SCH_ITEM>& ptr : createdItems )
1399 ptr->Move( offset );
1400 screen->
Append( ptr.release() );
constexpr EDA_IU_SCALE schIUScale
size_type GetHeight() const
coord_type GetTop() const
size_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)
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
Define a library symbol object.
const LIB_ID & GetLibId() const override
void SetUnitCount(int aCount, bool aDuplicateDrawItems=true)
Set the units per symbol count.
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.
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.
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 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.
void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
void SetShowPinNumbers(bool aShow)
Set or clear the pin number 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)
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