From 7b935f76731d3b449c8c827a06e9ec3c1ac6d8b3 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Wed, 10 Apr 2024 03:21:20 +0300 Subject: [PATCH] EasyEDA Pro: import Colorful Image as Reference Image. --- .../easyedapro/pcb_io_easyedapro_parser.cpp | 92 ++++++++++++++++++- 1 file changed, 89 insertions(+), 3 deletions(-) diff --git a/pcbnew/pcb_io/easyedapro/pcb_io_easyedapro_parser.cpp b/pcbnew/pcb_io/easyedapro/pcb_io_easyedapro_parser.cpp index b642af7985..d15b2bc2a8 100644 --- a/pcbnew/pcb_io/easyedapro/pcb_io_easyedapro_parser.cpp +++ b/pcbnew/pcb_io/easyedapro/pcb_io_easyedapro_parser.cpp @@ -57,6 +57,8 @@ #include #include #include +#include +#include static const wxString QUERY_MODEL_UUID_KEY = wxS( "JLC_3DModel_Q" ); @@ -848,7 +850,7 @@ FOOTPRINT* PCB_IO_EASYEDAPRO_PARSER::ParseFootprint( const nlohmann::json& else if( type == wxS( "REGION" ) ) { wxString uuid = line.at( 1 ); - + // if( line.at( 2 ).is_number() ) // int unk = line.at( 2 ).get(); // else if( line.at( 2 ).is_string() ) @@ -1389,7 +1391,7 @@ void PCB_IO_EASYEDAPRO_PARSER::ParseBoard( else if( type == wxS( "IMAGE" ) ) { wxString uuid = line.at( 1 ); - + // if( line.at( 2 ).is_number() ) // int unk = line.at( 2 ).get(); // else if( line.at( 2 ).is_string() ) @@ -1467,10 +1469,94 @@ void PCB_IO_EASYEDAPRO_PARSER::ParseBoard( if( group ) aBoard->Add( group.release(), ADD_MODE::APPEND ); } + else if( type == wxS( "OBJ" ) ) + { + VECTOR2D start, size; + wxString mimeType, base64Data; + double angle = 0; + int flipped = 0; + + if( !line.at( 3 ).is_number() ) + continue; + + int layer = line.at( 3 ).get(); + PCB_LAYER_ID klayer = LayerToKi( layer ); + + start = VECTOR2D( line.at( 5 ), line.at( 6 ) ); + size = VECTOR2D( line.at( 7 ), line.at( 8 ) ); + angle = line.at( 9 ); + flipped = line.at( 10 ); + + wxString imageUrl = line.at( 11 ); + + if( imageUrl.BeforeFirst( ':' ) == wxS( "blob" ) ) + { + wxString objectId = imageUrl.AfterLast( ':' ); + + if( auto blob = get_opt( aBlobMap, objectId ) ) + { + wxString blobUrl = blob->url; + + if( blobUrl.BeforeFirst( ':' ) == wxS( "data" ) ) + { + wxArrayString paramsArr = + wxSplit( blobUrl.AfterFirst( ':' ).BeforeFirst( ',' ), ';', '\0' ); + + base64Data = blobUrl.AfterFirst( ',' ); + + if( paramsArr.size() > 0 ) + mimeType = paramsArr[0]; + } + } + } + + VECTOR2D kstart = ScalePos( start ); + VECTOR2D ksize = ScaleSize( size ); + + if( mimeType.empty() || base64Data.empty() ) + continue; + + wxMemoryBuffer buf = wxBase64Decode( base64Data ); + + if( mimeType == wxS( "image/svg+xml" ) ) + { + // Not yet supported by EasyEDA + } + else + { + VECTOR2D kcenter = kstart + ksize / 2; + + std::unique_ptr bitmap = + std::make_unique( aBoard, kcenter, klayer ); + + wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags() + & ~wxImage::Load_Verbose ); + + if( bitmap->ReadImageFile( buf ) ) + { + double scaleFactor = ScaleSize( size.x ) / bitmap->GetSize().x; + bitmap->SetImageScale( scaleFactor ); + + // TODO: support non-90-deg angles + bitmap->Rotate( kstart, EDA_ANGLE( angle, DEGREES_T ) ); + + if( flipped ) + { + int x = bitmap->GetPosition().x; + MIRROR( x, KiROUND( kstart.x ) ); + bitmap->SetX( x ); + + bitmap->MutableImage()->Mirror( false ); + } + + aBoard->Add( bitmap.release(), ADD_MODE::APPEND ); + } + } + } else if( type == wxS( "STRING" ) ) { wxString uuid = line.at( 1 ); - + // if( line.at( 2 ).is_number() ) // int unk = line.at( 2 ).get(); // else if( line.at( 2 ).is_string() )