From daca9d21f2474fd98c75f418901fd786a6576b5b Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sun, 12 Sep 2021 19:38:22 -0400 Subject: [PATCH] Add dxf point import Fix #9149 --- pcbnew/import_gfx/dxf_import_plugin.cpp | 25 +++++++++++++++++++++++++ pcbnew/import_gfx/dxf_import_plugin.h | 3 ++- thirdparty/dxflib_qcad/dl_dxf.cpp | 3 ++- thirdparty/dxflib_qcad/dl_entities.h | 6 +++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/pcbnew/import_gfx/dxf_import_plugin.cpp b/pcbnew/import_gfx/dxf_import_plugin.cpp index feb5999fed..b9b0cbac64 100644 --- a/pcbnew/import_gfx/dxf_import_plugin.cpp +++ b/pcbnew/import_gfx/dxf_import_plugin.cpp @@ -1175,6 +1175,31 @@ void DXF_IMPORT_PLUGIN::addTextStyle( const DL_StyleData& aData ) } +void DXF_IMPORT_PLUGIN::addPoint( const DL_PointData& aData ) +{ + DXF_ARBITRARY_AXIS arbAxis = getArbitraryAxis( getExtrusion() ); + VECTOR3D centerCoords = ocsToWcs( arbAxis, VECTOR3D( aData.x, aData.y, aData.z ) ); + + VECTOR2D center( mapX( centerCoords.x ), mapY( centerCoords.y ) ); + + // we emulate points with filled circles + // set the linewidth to something that even small circles look good with + // thickness is optional for dxf points + // note: we had to modify the dxf library to grab the attribute for thickness + double lineWidth = 0.0001; + double thickness = mapDim( std::max( aData.thickness, 0.01 ) ); + + GRAPHICS_IMPORTER_BUFFER* bufferToUse = + ( m_currentBlock != nullptr ) ? &m_currentBlock->m_buffer : &m_internalImporter; + bufferToUse->AddCircle( center, thickness, lineWidth, true ); + + VECTOR2D radiusDelta( SCALE_FACTOR( thickness ), SCALE_FACTOR( thickness ) ); + + updateImageLimits( center + radiusDelta ); + updateImageLimits( center - radiusDelta ); +} + + void DXF_IMPORT_PLUGIN::insertLine( const VECTOR2D& aSegStart, const VECTOR2D& aSegEnd, int aWidth ) { diff --git a/pcbnew/import_gfx/dxf_import_plugin.h b/pcbnew/import_gfx/dxf_import_plugin.h index 8db120ea94..e5f7b2e53a 100644 --- a/pcbnew/import_gfx/dxf_import_plugin.h +++ b/pcbnew/import_gfx/dxf_import_plugin.h @@ -413,6 +413,8 @@ private: */ virtual void addBlock( const DL_BlockData& ) override; virtual void endBlock() override; + virtual void addTextStyle( const DL_StyleData& aData ) override; + virtual void addPoint( const DL_PointData& aData ) override; virtual void addCircle( const DL_CircleData& aData ) override; virtual void addArc( const DL_ArcData& aData ) override; @@ -428,7 +430,6 @@ private: */ virtual void addVertex( const DL_VertexData& aData ) override; virtual void addMText( const DL_MTextData& aData) override; - virtual void addTextStyle( const DL_StyleData& aData ) override; virtual void endEntity() override; diff --git a/thirdparty/dxflib_qcad/dl_dxf.cpp b/thirdparty/dxflib_qcad/dl_dxf.cpp index 675c735921..a6221b881a 100644 --- a/thirdparty/dxflib_qcad/dl_dxf.cpp +++ b/thirdparty/dxflib_qcad/dl_dxf.cpp @@ -1151,7 +1151,8 @@ void DL_Dxf::addPoint( DL_CreationInterface* creationInterface ) { DL_PointData d( getRealValue( 10, 0.0 ), getRealValue( 20, 0.0 ), - getRealValue( 30, 0.0 ) ); + getRealValue( 30, 0.0 ), + getRealValue( 39, 0.0 ) ); creationInterface->addPoint( d ); } diff --git a/thirdparty/dxflib_qcad/dl_entities.h b/thirdparty/dxflib_qcad/dl_entities.h index 4c08f57a56..779bdeb588 100644 --- a/thirdparty/dxflib_qcad/dl_entities.h +++ b/thirdparty/dxflib_qcad/dl_entities.h @@ -223,11 +223,12 @@ struct DXFLIB_EXPORT DL_PointData * Constructor. * Parameters: see member variables. */ - DL_PointData( double px = 0.0, double py = 0.0, double pz = 0.0 ) + DL_PointData( double px = 0.0, double py = 0.0, double pz = 0.0, double pthickness = 0.0 ) { x = px; y = py; z = pz; + thickness = pthickness; } /*! X Coordinate of the point. */ @@ -238,6 +239,9 @@ struct DXFLIB_EXPORT DL_PointData /*! Z Coordinate of the point. */ double z; + + /*! Thickness of the point. */ + double thickness; };