EasyEDA Pro: support SVG images in schematic; support bitmap rotation/flip.
This commit is contained in:
parent
847ab093c8
commit
4b083fc342
|
@ -102,7 +102,7 @@ DIALOG_IMPORT_GFX_SCH::DIALOG_IMPORT_GFX_SCH( SCH_BASE_FRAME* aParent ) :
|
|||
}
|
||||
else if( SCH_EDIT_FRAME* schFrame = dynamic_cast<SCH_EDIT_FRAME*>( aParent ) )
|
||||
{
|
||||
m_importer = std::make_unique<GRAPHICS_IMPORTER_SCH>( schFrame->GetScreen() );
|
||||
m_importer = std::make_unique<GRAPHICS_IMPORTER_SCH>();
|
||||
|
||||
EESCHEMA_SETTINGS* cfg = m_parent->eeconfig();
|
||||
initWidgetsFromSettings( cfg );
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <sch_text.h>
|
||||
|
||||
|
||||
GRAPHICS_IMPORTER_SCH::GRAPHICS_IMPORTER_SCH( SCH_SCREEN* aScreen ) : m_screen( aScreen )
|
||||
GRAPHICS_IMPORTER_SCH::GRAPHICS_IMPORTER_SCH()
|
||||
{
|
||||
m_millimeterToIu = schIUScale.mmToIU( 1.0 );
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class SCH_SCREEN;
|
|||
class GRAPHICS_IMPORTER_SCH : public GRAPHICS_IMPORTER
|
||||
{
|
||||
public:
|
||||
GRAPHICS_IMPORTER_SCH( SCH_SCREEN* aScreen );
|
||||
GRAPHICS_IMPORTER_SCH();
|
||||
|
||||
void AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd,
|
||||
const IMPORTED_STROKE& aStroke ) override;
|
||||
|
@ -75,8 +75,6 @@ public:
|
|||
int MapLineWidth( double aLineWidth );
|
||||
|
||||
STROKE_PARAMS MapStrokeParams( const IMPORTED_STROKE& aStroke );
|
||||
|
||||
SCH_SCREEN* m_screen;
|
||||
};
|
||||
|
||||
#endif /* GRAPHICS_IMPORTER_SCH_H_ */
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "sch_easyedapro_parser.h"
|
||||
#include <plugins/easyedapro/easyedapro_import_utils.h>
|
||||
|
||||
#include <core/map_helpers.h>
|
||||
|
||||
#include <sch_io_mgr.h>
|
||||
#include <schematic.h>
|
||||
#include <sch_sheet.h>
|
||||
|
@ -47,7 +49,7 @@
|
|||
#include <gfx_import_utils.h>
|
||||
#include <import_gfx/svg_import_plugin.h>
|
||||
#include <import_gfx/graphics_importer_lib_symbol.h>
|
||||
#include <core/map_helpers.h>
|
||||
#include <import_gfx/graphics_importer_sch.h>
|
||||
|
||||
|
||||
SCH_EASYEDAPRO_PARSER::SCH_EASYEDAPRO_PARSER( SCHEMATIC* aSchematic,
|
||||
|
@ -849,14 +851,14 @@ void SCH_EASYEDAPRO_PARSER::ParseSchematic( SCHEMATIC* aSchematic, SCH_SHEET* aR
|
|||
VECTOR2D start, size;
|
||||
wxString mimeType, base64Data;
|
||||
double angle = 0;
|
||||
int upsideDown = 0;
|
||||
int flipped = 0;
|
||||
|
||||
if( line.at( 3 ).is_number() )
|
||||
{
|
||||
start = VECTOR2D( line.at( 3 ), line.at( 4 ) );
|
||||
size = VECTOR2D( line.at( 5 ), line.at( 6 ) );
|
||||
angle = line.at( 7 );
|
||||
upsideDown = line.at( 8 );
|
||||
flipped = line.at( 8 );
|
||||
|
||||
wxString imageUrl = line.at( 9 );
|
||||
|
||||
|
@ -908,34 +910,56 @@ void SCH_EASYEDAPRO_PARSER::ParseSchematic( SCHEMATIC* aSchematic, SCH_SHEET* aR
|
|||
|
||||
if( mimeType == wxS( "image/svg+xml" ) )
|
||||
{
|
||||
// VECTOR2D offset = ScalePosSym( start );
|
||||
VECTOR2D offset = ScalePos( start );
|
||||
|
||||
//SVG_IMPORT_PLUGIN svgImportPlugin;
|
||||
//GRAPHICS_IMPORTER_LIB_SYMBOL libsymImporter( ksymbol, 0 );
|
||||
SVG_IMPORT_PLUGIN svgImportPlugin;
|
||||
GRAPHICS_IMPORTER_SCH schImporter;
|
||||
|
||||
//svgImportPlugin.SetImporter( &libsymImporter );
|
||||
//svgImportPlugin.LoadFromMemory( buf );
|
||||
svgImportPlugin.SetImporter( &schImporter );
|
||||
svgImportPlugin.LoadFromMemory( buf );
|
||||
|
||||
//VECTOR2D imSize( svgImportPlugin.GetImageWidth(),
|
||||
// svgImportPlugin.GetImageHeight() );
|
||||
VECTOR2D imSize( svgImportPlugin.GetImageWidth(),
|
||||
svgImportPlugin.GetImageHeight() );
|
||||
|
||||
//VECTOR2D pixelScale( schIUScale.IUTomm( ScaleSizeUnit( size.x ) ) / imSize.x,
|
||||
// schIUScale.IUTomm( -ScaleSizeUnit( size.y ) ) / imSize.y );
|
||||
VECTOR2D pixelScale( schIUScale.IUTomm( ScaleSize( size.x ) ) / imSize.x,
|
||||
schIUScale.IUTomm( ScaleSize( size.y ) ) / imSize.y );
|
||||
|
||||
//if( upsideDown )
|
||||
// pixelScale.y *= -1;
|
||||
if( flipped )
|
||||
pixelScale.x *= -1;
|
||||
|
||||
//libsymImporter.SetScale( pixelScale );
|
||||
schImporter.SetScale( pixelScale );
|
||||
|
||||
//VECTOR2D offsetMM( schIUScale.IUTomm( offset.x ), schIUScale.IUTomm( offset.y ) );
|
||||
VECTOR2D offsetMM( schIUScale.IUTomm( offset.x ), schIUScale.IUTomm( offset.y ) );
|
||||
|
||||
//libsymImporter.SetImportOffsetMM( offsetMM );
|
||||
schImporter.SetImportOffsetMM( offsetMM );
|
||||
|
||||
//svgImportPlugin.Import();
|
||||
svgImportPlugin.Import();
|
||||
|
||||
//// TODO: rotation
|
||||
//for( std::unique_ptr<EDA_ITEM>& item : libsymImporter.GetItems() )
|
||||
// ksymbol->AddDrawItem( static_cast<LIB_ITEM*>( item.release() ) );
|
||||
for( std::unique_ptr<EDA_ITEM>& item : schImporter.GetItems() )
|
||||
{
|
||||
SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item.release() );
|
||||
|
||||
for( double i = angle; i > 0; i -= 90 )
|
||||
{
|
||||
if( schItem->Type() == SCH_LINE_T )
|
||||
{
|
||||
// Lines need special handling for some reason
|
||||
schItem->SetFlags( STARTPOINT );
|
||||
schItem->Rotate( offset );
|
||||
schItem->ClearFlags( STARTPOINT );
|
||||
|
||||
schItem->SetFlags( ENDPOINT );
|
||||
schItem->Rotate( offset );
|
||||
schItem->ClearFlags( ENDPOINT );
|
||||
}
|
||||
else
|
||||
{
|
||||
schItem->Rotate( offset );
|
||||
}
|
||||
}
|
||||
|
||||
createdItems.emplace_back( schItem );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -950,13 +974,16 @@ void SCH_EASYEDAPRO_PARSER::ParseSchematic( SCHEMATIC* aSchematic, SCH_SHEET* aR
|
|||
VECTOR2D ksize = ScaleSize( size );
|
||||
VECTOR2D kcenter = kstart + ksize / 2;
|
||||
|
||||
RotatePoint( kcenter, kstart, -EDA_ANGLE( angle, DEGREES_T ) );
|
||||
// TODO: rotation
|
||||
|
||||
double scaleFactor = ScaleSize( size.x ) / bitmap->GetSize().x;
|
||||
bitmap->SetImageScale( scaleFactor );
|
||||
bitmap->SetPosition( kcenter );
|
||||
|
||||
for( double i = angle; i > 0; i -= 90 )
|
||||
bitmap->Rotate( kstart );
|
||||
|
||||
if( flipped )
|
||||
bitmap->MirrorHorizontally( kstart.x );
|
||||
|
||||
createdItems.push_back( std::move( bitmap ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue