KiCad PCB EDA Suite
DXF_IMPORT_PLUGIN Class Reference

This class import DXF ASCII files and convert basic entities to board entities. More...

#include <dxf_import_plugin.h>

Inheritance diagram for DXF_IMPORT_PLUGIN:
GRAPHICS_IMPORT_PLUGIN

Public Member Functions

 DXF_IMPORT_PLUGIN ()
 
 ~DXF_IMPORT_PLUGIN ()
 
const wxString GetName () const override
 Return the plugin name. More...
 
const std::vector< std::string > GetFileExtensions () const override
 Return a vector of the file extensions handled by this plugin. More...
 
bool Load (const wxString &aFileName) override
 Load file for import. More...
 
bool Import () override
 Actually imports the file. More...
 
double GetImageWidth () const override
 Return image width from original imported file. More...
 
double GetImageHeight () const override
 Return image height from original imported file. More...
 
void updateImageLimits (const VECTOR2D &aPoint)
 
virtual void SetImporter (GRAPHICS_IMPORTER *aImporter) override
 Set the receiver of the imported shapes. More...
 
void ImportAsFootprintGraphic (bool aImportAsFootprintGraphic)
 Allows the import DXF items converted to board graphic items or footprint graphic items. More...
 
void SetDefaultLineWidthMM (double aWidth)
 Set the default line width when importing dxf items like lines to Pcbnew. More...
 
void SetLineWidthMM (double aWidth) override
 
void SetOffset (double aOffsetX, double aOffsetY)
 Set the coordinate offset between the imported dxf items and Pcbnew. More...
 
void SetBrdLayer (int aBrdLayer)
 Set the layer number to import dxf items. More...
 
bool ImportDxfFile (const wxString &aFile)
 Implementation of the method used for communicate with this filter. More...
 
const std::string & GetMessages () const override
 
wxString GetWildcards () const
 Return a list of wildcards that contains the file extensions handled by this plugin, separated with a semi-colon. More...
 

Protected Attributes

GRAPHICS_IMPORTERm_importer
 

Importer used to create objects representing the imported shapes.

More...
 

Private Member Functions

void reportMsg (const char *aMessage)
 
double mapX (double aDxfCoordX)
 
double mapY (double aDxfCoordY)
 
double mapDim (double aDxfValue)
 
double mapWidth (double aDxfWidth)
 
void insertLine (const VECTOR2D &aSegStart, const VECTOR2D &aSegEnd, int aWidth)
 
void insertArc (const VECTOR2D &aSegStart, const VECTOR2D &aSegEnd, double aBulge, int aWidth)
 
void insertSpline (int aWidth)
 
virtual void setVariableString (const std::string &key, const std::string &value, int code) override
 Called for every string variable in the DXF file (e.g. More...
 
virtual void setVariableInt (const std::string &key, int value, int code) override
 Called for every int variable in the DXF file (e.g. More...
 
virtual void setVariableDouble (const std::string &key, double value, int code) override
 Called for every double variable in the DXF file (e.g. More...
 
virtual void addLayer (const DL_LayerData &aData) override
 
virtual void addLine (const DL_LineData &aData) override
 
virtual void addBlock (const DL_BlockData &) override
 Called for each BLOCK in the DXF file These are re-usable elements that may be placed into the model space. More...
 
virtual void endBlock () override
 
virtual void addCircle (const DL_CircleData &aData) override
 
virtual void addArc (const DL_ArcData &aData) override
 
virtual void addText (const DL_TextData &aData) override
 
virtual void addPolyline (const DL_PolylineData &aData) override
 
virtual void addVertex (const DL_VertexData &aData) override
 Called for every polyline vertex. More...
 
virtual void addMText (const DL_MTextData &aData) override
 
virtual void addTextStyle (const DL_StyleData &aData) override
 
virtual void endEntity () override
 
virtual void addSpline (const DL_SplineData &aData) override
 Called for every spline. More...
 
virtual void addControlPoint (const DL_ControlPointData &aData) override
 Called for every spline control point. More...
 
virtual void addFitPoint (const DL_FitPointData &aData) override
 Called for every spline fit point. More...
 
virtual void addKnot (const DL_KnotData &aData) override
 Called for every spline knot value. More...
 
virtual void addDimAlign (const DL_DimensionData &, const DL_DimAlignedData &) override
 
virtual void addDimLinear (const DL_DimensionData &, const DL_DimLinearData &) override
 
virtual void addDimRadial (const DL_DimensionData &, const DL_DimRadialData &) override
 
virtual void addDimDiametric (const DL_DimensionData &, const DL_DimDiametricData &) override
 
virtual void addDimAngular (const DL_DimensionData &, const DL_DimAngularData &) override
 
virtual void addDimAngular3P (const DL_DimensionData &, const DL_DimAngular3PData &) override
 
virtual void addDimOrdinate (const DL_DimensionData &, const DL_DimOrdinateData &) override
 
virtual void addLeader (const DL_LeaderData &) override
 
virtual void addLeaderVertex (const DL_LeaderVertexData &) override
 
virtual void addHatch (const DL_HatchData &) override
 
virtual void addTrace (const DL_TraceData &) override
 
virtual void add3dFace (const DL_3dFaceData &) override
 
virtual void addSolid (const DL_SolidData &) override
 
virtual void addImage (const DL_ImageData &) override
 
virtual void linkImage (const DL_ImageDefData &) override
 
virtual void addHatchLoop (const DL_HatchLoopData &) override
 
virtual void addHatchEdge (const DL_HatchEdgeData &) override
 
void writeLine ()
 
void writeMtext ()
 

Static Private Member Functions

static wxString toDxfString (const wxString &aStr)
 Convert a native unicode string into a DXF encoded string. More...
 
static wxString toNativeString (const wxString &aData)
 Converts a DXF encoded string into a native Unicode string. More...
 

Private Attributes

double m_xOffset
 
double m_yOffset
 
double m_defaultThickness
 
double m_DXF2mm
 
int m_brdLayer
 
int m_version
 
bool m_inBlock
 
std::string m_codePage
 
bool m_importAsfootprintGraphicItems
 
std::string m_messages
 
DXF2BRD_ENTITY_DATA m_curr_entity
 
double m_minX
 
double m_maxX
 
double m_minY
 
double m_maxY
 
GRAPHICS_IMPORTER_BUFFER m_internalImporter
 

Detailed Description

This class import DXF ASCII files and convert basic entities to board entities.

It depends on the dxflib library.

Definition at line 118 of file dxf_import_plugin.h.

Constructor & Destructor Documentation

◆ DXF_IMPORT_PLUGIN()

DXF_IMPORT_PLUGIN::DXF_IMPORT_PLUGIN ( )

Definition at line 59 of file dxf_import_plugin.cpp.

59  : DL_CreationAdapter()
60 {
61  m_xOffset = 0.0; // X coord offset for conversion (in mm)
62  m_yOffset = 0.0; // Y coord offset for conversion (in mm)
63  m_DXF2mm = 1.0; // The scale factor to convert DXF units to mm
64  m_version = 0; // the dxf version, not yet used
65  m_inBlock = false; // Discard blocks
66  m_defaultThickness = 0.2; // default thickness (in mm)
67  m_brdLayer = Dwgs_User; // The default import layer
69  m_minX = m_minY = std::numeric_limits<double>::max();
70  m_maxX = m_maxY = std::numeric_limits<double>::min();
71 }

References Dwgs_User, m_brdLayer, m_defaultThickness, m_DXF2mm, m_importAsfootprintGraphicItems, m_inBlock, m_maxX, m_maxY, m_minX, m_minY, m_version, m_xOffset, and m_yOffset.

◆ ~DXF_IMPORT_PLUGIN()

DXF_IMPORT_PLUGIN::~DXF_IMPORT_PLUGIN ( )

Definition at line 74 of file dxf_import_plugin.cpp.

75 {
76 }

Member Function Documentation

◆ add3dFace()

virtual void DXF_IMPORT_PLUGIN::add3dFace ( const DL_3dFaceData &  )
inlineoverrideprivatevirtual

Definition at line 323 of file dxf_import_plugin.h.

323 {}

◆ addArc()

void DXF_IMPORT_PLUGIN::addArc ( const DL_ArcData &  aData)
overrideprivatevirtual

Definition at line 364 of file dxf_import_plugin.cpp.

365 {
366  if( m_inBlock )
367  return;
368 
369  // Init arc centre:
370  VECTOR2D center( mapX( aData.cx ), mapY( aData.cy ) );
371 
372  // aData.anglex is in degrees.
373  double startangle = aData.angle1;
374  double endangle = aData.angle2;
375 
376  // Init arc start point
377  VECTOR2D startPoint( aData.radius, 0.0 );
378  startPoint = startPoint.Rotate( startangle * M_PI / 180.0 );
379  VECTOR2D arcStart( mapX( startPoint.x + aData.cx ), mapY( startPoint.y + aData.cy ) );
380 
381  // calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew)
382  double angle = -( endangle - startangle );
383 
384  if( angle > 0.0 )
385  angle -= 360.0;
386 
387  double lineWidth = mapWidth( attributes.getWidth() );
388  m_internalImporter.AddArc( center, arcStart, angle, lineWidth );
389 
390  VECTOR2D radiusDelta( mapDim( aData.radius ), mapDim( aData.radius ) );
391 
392  updateImageLimits( center + radiusDelta );
393  updateImageLimits( center - radiusDelta );
394 }
void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth) override
Create an object representing an arc.
double mapX(double aDxfCoordX)
void updateImageLimits(const VECTOR2D &aPoint)
double mapDim(double aDxfValue)
double mapWidth(double aDxfWidth)
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
double mapY(double aDxfCoordY)
GRAPHICS_IMPORTER_BUFFER m_internalImporter

References GRAPHICS_IMPORTER_BUFFER::AddArc(), PNS::angle(), m_inBlock, m_internalImporter, mapDim(), mapWidth(), mapX(), mapY(), VECTOR2< T >::Rotate(), updateImageLimits(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ addBlock()

void DXF_IMPORT_PLUGIN::addBlock ( const DL_BlockData &  aData)
overrideprivatevirtual

Called for each BLOCK in the DXF file These are re-usable elements that may be placed into the model space.

The elements are dereferenced to the model, so we just need to skip the re-parsing for the block elements.

Definition at line 333 of file dxf_import_plugin.cpp.

334 {
335  // The DXF blocks are not useful in our import, so we skip them with the exception
336  // of the main block that is shown when editing the file
337  if( aData.name.compare( "*Model_Space") )
338  m_inBlock = true;
339 }

References m_inBlock.

◆ addCircle()

void DXF_IMPORT_PLUGIN::addCircle ( const DL_CircleData &  aData)
overrideprivatevirtual

Definition at line 348 of file dxf_import_plugin.cpp.

349 {
350  if( m_inBlock )
351  return;
352 
353  VECTOR2D center( mapX( aData.cx ), mapY( aData.cy ) );
354  double lineWidth = mapWidth( attributes.getWidth() );
355  m_internalImporter.AddCircle( center, mapDim( aData.radius ), lineWidth );
356 
357  VECTOR2D radiusDelta( mapDim( aData.radius ), mapDim( aData.radius ) );
358 
359  updateImageLimits( center + radiusDelta );
360  updateImageLimits( center - radiusDelta );
361 }
double mapX(double aDxfCoordX)
void updateImageLimits(const VECTOR2D &aPoint)
void AddCircle(const VECTOR2D &aCenter, double aRadius, double aWidth) override
Create an object representing a circle.
double mapDim(double aDxfValue)
double mapWidth(double aDxfWidth)
double mapY(double aDxfCoordY)
GRAPHICS_IMPORTER_BUFFER m_internalImporter

References GRAPHICS_IMPORTER_BUFFER::AddCircle(), m_inBlock, m_internalImporter, mapDim(), mapWidth(), mapX(), mapY(), and updateImageLimits().

◆ addControlPoint()

void DXF_IMPORT_PLUGIN::addControlPoint ( const DL_ControlPointData &  aData)
overrideprivatevirtual

Called for every spline control point.

Definition at line 192 of file dxf_import_plugin.cpp.

193 {
194  if( m_inBlock )
195  return;
196 
197  // Called for every spline control point, when reading a spline entity
198  m_curr_entity.m_SplineControlPointList.emplace_back( aData.x , aData.y,
199  aData.w );
200 }
DXF2BRD_ENTITY_DATA m_curr_entity
std::vector< SPLINE_CTRL_POINT > m_SplineControlPointList

References m_curr_entity, m_inBlock, and DXF2BRD_ENTITY_DATA::m_SplineControlPointList.

◆ addDimAlign()

virtual void DXF_IMPORT_PLUGIN::addDimAlign ( const DL_DimensionData &  ,
const DL_DimAlignedData &   
)
inlineoverrideprivatevirtual

Definition at line 302 of file dxf_import_plugin.h.

303  {}

◆ addDimAngular()

virtual void DXF_IMPORT_PLUGIN::addDimAngular ( const DL_DimensionData &  ,
const DL_DimAngularData &   
)
inlineoverrideprivatevirtual

Definition at line 310 of file dxf_import_plugin.h.

311  {}

◆ addDimAngular3P()

virtual void DXF_IMPORT_PLUGIN::addDimAngular3P ( const DL_DimensionData &  ,
const DL_DimAngular3PData &   
)
inlineoverrideprivatevirtual

Definition at line 312 of file dxf_import_plugin.h.

313  {}

◆ addDimDiametric()

virtual void DXF_IMPORT_PLUGIN::addDimDiametric ( const DL_DimensionData &  ,
const DL_DimDiametricData &   
)
inlineoverrideprivatevirtual

Definition at line 308 of file dxf_import_plugin.h.

309  {}

◆ addDimLinear()

virtual void DXF_IMPORT_PLUGIN::addDimLinear ( const DL_DimensionData &  ,
const DL_DimLinearData &   
)
inlineoverrideprivatevirtual

Definition at line 304 of file dxf_import_plugin.h.

305  {}

◆ addDimOrdinate()

virtual void DXF_IMPORT_PLUGIN::addDimOrdinate ( const DL_DimensionData &  ,
const DL_DimOrdinateData &   
)
inlineoverrideprivatevirtual

Definition at line 314 of file dxf_import_plugin.h.

315  {}

◆ addDimRadial()

virtual void DXF_IMPORT_PLUGIN::addDimRadial ( const DL_DimensionData &  ,
const DL_DimRadialData &   
)
inlineoverrideprivatevirtual

Definition at line 306 of file dxf_import_plugin.h.

307  {}

◆ addFitPoint()

void DXF_IMPORT_PLUGIN::addFitPoint ( const DL_FitPointData &  aData)
overrideprivatevirtual

Called for every spline fit point.

Definition at line 203 of file dxf_import_plugin.cpp.

204 {
205  if( m_inBlock )
206  return;
207 
208  // Called for every spline fit point, when reading a spline entity
209  // we store only the X,Y coord values in a VECTOR2D
210  m_curr_entity.m_SplineFitPointList.emplace_back( aData.x, aData.y );
211 }
DXF2BRD_ENTITY_DATA m_curr_entity
std::vector< VECTOR2D > m_SplineFitPointList

References m_curr_entity, m_inBlock, and DXF2BRD_ENTITY_DATA::m_SplineFitPointList.

◆ addHatch()

virtual void DXF_IMPORT_PLUGIN::addHatch ( const DL_HatchData &  )
inlineoverrideprivatevirtual

Definition at line 320 of file dxf_import_plugin.h.

320 {}

◆ addHatchEdge()

virtual void DXF_IMPORT_PLUGIN::addHatchEdge ( const DL_HatchEdgeData &  )
inlineoverrideprivatevirtual

Definition at line 332 of file dxf_import_plugin.h.

332 {}

◆ addHatchLoop()

virtual void DXF_IMPORT_PLUGIN::addHatchLoop ( const DL_HatchLoopData &  )
inlineoverrideprivatevirtual

Definition at line 330 of file dxf_import_plugin.h.

330 {}

◆ addImage()

virtual void DXF_IMPORT_PLUGIN::addImage ( const DL_ImageData &  )
inlineoverrideprivatevirtual

Definition at line 327 of file dxf_import_plugin.h.

327 {}

◆ addKnot()

void DXF_IMPORT_PLUGIN::addKnot ( const DL_KnotData &  aData)
overrideprivatevirtual

Called for every spline knot value.

Definition at line 214 of file dxf_import_plugin.cpp.

215 {
216  if( m_inBlock )
217  return;
218 
219  // Called for every spline knot value, when reading a spline entity
220  m_curr_entity.m_SplineKnotsList.push_back( aData.k );
221 }
DXF2BRD_ENTITY_DATA m_curr_entity
std::vector< double > m_SplineKnotsList

References m_curr_entity, m_inBlock, and DXF2BRD_ENTITY_DATA::m_SplineKnotsList.

◆ addLayer()

void DXF_IMPORT_PLUGIN::addLayer ( const DL_LayerData &  aData)
overrideprivatevirtual

Definition at line 224 of file dxf_import_plugin.cpp.

225 {
226  // Not yet useful in Pcbnew.
227 #if 0
228  wxString name = wxString::FromUTF8( aData.name.c_str() );
229  wxLogMessage( name );
230 #endif
231 }
const char * name
Definition: DXF_plotter.cpp:60

References name.

◆ addLeader()

virtual void DXF_IMPORT_PLUGIN::addLeader ( const DL_LeaderData &  )
inlineoverrideprivatevirtual

Definition at line 316 of file dxf_import_plugin.h.

316 {}

◆ addLeaderVertex()

virtual void DXF_IMPORT_PLUGIN::addLeaderVertex ( const DL_LeaderVertexData &  )
inlineoverrideprivatevirtual

Definition at line 318 of file dxf_import_plugin.h.

318 {}

◆ addLine()

void DXF_IMPORT_PLUGIN::addLine ( const DL_LineData &  aData)
overrideprivatevirtual

Definition at line 234 of file dxf_import_plugin.cpp.

235 {
236  if( m_inBlock )
237  return;
238 
239  VECTOR2D start( mapX( aData.x1 ), mapY( aData.y1 ) );
240  VECTOR2D end( mapX( aData.x2 ), mapY( aData.y2 ) );
241  double lineWidth = mapWidth( attributes.getWidth() );
242 
243  m_internalImporter.AddLine( start, end, lineWidth );
244 
245  updateImageLimits( start );
246  updateImageLimits( end );
247 }
void AddLine(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth) override
Create an object representing a line segment.
double mapX(double aDxfCoordX)
void updateImageLimits(const VECTOR2D &aPoint)
double mapWidth(double aDxfWidth)
double mapY(double aDxfCoordY)
GRAPHICS_IMPORTER_BUFFER m_internalImporter

References GRAPHICS_IMPORTER_BUFFER::AddLine(), m_inBlock, m_internalImporter, mapWidth(), mapX(), mapY(), and updateImageLimits().

◆ addMText()

void DXF_IMPORT_PLUGIN::addMText ( const DL_MTextData &  aData)
overrideprivatevirtual

Definition at line 540 of file dxf_import_plugin.cpp.

541 {
542  if( m_inBlock )
543  return;
544 
545  wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
546  wxString attrib, tmp;
547 
548  double textHeight = mapDim( aData.height );
549  // The 0.9 factor gives a better height/width ratio with our font
550  double charWidth = textHeight * 0.9;
551  double textWidth = charWidth * text.length(); // Rough approximation
552  double textThickness = textHeight/8.0; // Use a reasonable line thickness for this text
553 
554  VECTOR2D bottomLeft(0.0, 0.0);
555  VECTOR2D bottomRight(0.0, 0.0);
556  VECTOR2D topLeft(0.0, 0.0);
557  VECTOR2D topRight(0.0, 0.0);
558 
559  /* Some texts start by '\' and have formatting chars (font name, font option...)
560  * ending with ';'
561  * Here are some mtext formatting codes:
562  * Format code Purpose
563  * \0...\o Turns overline on and off
564  * \L...\l Turns underline on and off
565  * \~ Inserts a nonbreaking space
566  \\ Inserts a backslash
567  \\\{...\} Inserts an opening and closing brace
568  \\ \File name; Changes to the specified font file
569  \\ \Hvalue; Changes to the text height specified in drawing units
570  \\ \Hvaluex; Changes the text height to a multiple of the current text height
571  \\ \S...^...; Stacks the subsequent text at the \, #, or ^ symbol
572  \\ \Tvalue; Adjusts the space between characters, from.75 to 4 times
573  \\ \Qangle; Changes oblique angle
574  \\ \Wvalue; Changes width factor to produce wide text
575  \\ \A Sets the alignment value; valid values: 0, 1, 2 (bottom, center, top) while( text.StartsWith( wxT("\\") ) )
576  */
577  while( text.StartsWith( wxT( "\\" ) ) )
578  {
579  attrib << text.BeforeFirst( ';' );
580  tmp = text.AfterFirst( ';' );
581  text = tmp;
582  }
583 
584  VECTOR2D textpos( mapX( aData.ipx ), mapY( aData.ipy ) );
585 
586  // Initialize text justifications:
589 
590  if( aData.attachmentPoint <= 3 )
591  {
592  vJustify = GR_TEXT_VJUSTIFY_TOP;
593 
594  bottomLeft.y = -textHeight;
595  bottomRight.y = -textHeight;
596  }
597  else if( aData.attachmentPoint <= 6 )
598  {
599  vJustify = GR_TEXT_VJUSTIFY_CENTER;
600 
601  bottomRight.y = -textHeight / 2.0;
602  bottomLeft.y = -textHeight / 2.0;
603  topLeft.y = textHeight / 2.0;
604  topRight.y = textHeight / 2.0;
605  }
606  else
607  {
608  vJustify = GR_TEXT_VJUSTIFY_BOTTOM;
609 
610  topLeft.y = textHeight;
611  topRight.y = textHeight;
612  }
613 
614  if( aData.attachmentPoint % 3 == 1 )
615  {
616  hJustify = GR_TEXT_HJUSTIFY_LEFT;
617 
618  bottomRight.x = textWidth;
619  topRight.x = textWidth;
620  }
621  else if( aData.attachmentPoint % 3 == 2 )
622  {
623  hJustify = GR_TEXT_HJUSTIFY_CENTER;
624 
625  bottomLeft.x = -textWidth / 2.0;
626  topLeft.x = -textWidth / 2.0;
627  bottomRight.x = textWidth / 2.0;
628  topRight.x = textWidth / 2.0;
629  }
630  else
631  {
632  hJustify = GR_TEXT_HJUSTIFY_RIGHT;
633 
634  bottomLeft.x = -textWidth;
635  topLeft.x = -textWidth;
636  }
637 
638 #if 0 // These setting have no meaning in Pcbnew
639  if( data.alignH == 1 )
640  {
641  // Text is left to right;
642  }
643  else if( data.alignH == 3 )
644  {
645  // Text is top to bottom;
646  }
647  else
648  {
649  // use ByStyle;
650  }
651 
652  if( aData.alignV == 1 )
653  {
654  // use AtLeast;
655  }
656  else
657  {
658  // useExact;
659  }
660 #endif
661 
662  // dxf_lib imports text angle in radians (although there are no comment about that.
663  // So, for the moment, convert this angle to degrees
664  double angle_degree = aData.angle * 180/M_PI;
665  // We also need the angle in radians. so convert angle_degree to radians
666  // regardless the aData.angle unit
667  double angleInRads = angle_degree * M_PI / 180.0;
668  double cosine = cos(angleInRads);
669  double sine = sin(angleInRads);
670 
671  m_internalImporter.AddText( textpos, text, textHeight, charWidth,
672  textThickness, angle_degree, hJustify, vJustify );
673 
674  bottomLeft.x = bottomLeft.x * cosine - bottomLeft.y * sine;
675  bottomLeft.y = bottomLeft.x * sine + bottomLeft.y * cosine;
676 
677  bottomRight.x = bottomRight.x * cosine - bottomRight.y * sine;
678  bottomRight.y = bottomRight.x * sine + bottomRight.y * cosine;
679 
680  topLeft.x = topLeft.x * cosine - topLeft.y * sine;
681  topLeft.y = topLeft.x * sine + topLeft.y * cosine;
682 
683  topRight.x = topRight.x * cosine - topRight.y * sine;
684  topRight.y = topRight.x * sine + topRight.y * cosine;
685 
686  bottomLeft += textpos;
687  bottomRight += textpos;
688  topLeft += textpos;
689  topRight += textpos;
690 
691  updateImageLimits( bottomLeft );
692  updateImageLimits( bottomRight );
693  updateImageLimits( topLeft );
694  updateImageLimits( topRight );
695 
696 }
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:44
double mapX(double aDxfCoordX)
void updateImageLimits(const VECTOR2D &aPoint)
static wxString toNativeString(const wxString &aData)
Converts a DXF encoded string into a native Unicode string.
double mapDim(double aDxfValue)
void AddText(const VECTOR2D &aOrigin, const wxString &aText, double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify) override
Create an object representing a text.
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:51
double mapY(double aDxfCoordY)
GRAPHICS_IMPORTER_BUFFER m_internalImporter

References GRAPHICS_IMPORTER_BUFFER::AddText(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, m_inBlock, m_internalImporter, mapDim(), mapX(), mapY(), toNativeString(), updateImageLimits(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ addPolyline()

void DXF_IMPORT_PLUGIN::addPolyline ( const DL_PolylineData &  aData)
overrideprivatevirtual

Definition at line 250 of file dxf_import_plugin.cpp.

251 {
252  if( m_inBlock )
253  return;
254 
255  // Convert DXF Polylines into a series of KiCad Lines and Arcs.
256  // A Polyline (as opposed to a LWPolyline) may be a 3D line or
257  // even a 3D Mesh. The only type of Polyline which is guaranteed
258  // to import correctly is a 2D Polyline in X and Y, which is what
259  // we assume of all Polylines. The width used is the width of the Polyline.
260  // per-vertex line widths, if present, are ignored.
263  m_curr_entity.m_EntityFlag = aData.flags;
264  m_curr_entity.m_EntityType = DL_ENTITY_POLYLINE;
265 }
DXF2BRD_ENTITY_DATA m_curr_entity

References DXF2BRD_ENTITY_DATA::Clear(), m_curr_entity, DXF2BRD_ENTITY_DATA::m_EntityFlag, DXF2BRD_ENTITY_DATA::m_EntityParseStatus, DXF2BRD_ENTITY_DATA::m_EntityType, and m_inBlock.

◆ addSolid()

virtual void DXF_IMPORT_PLUGIN::addSolid ( const DL_SolidData &  )
inlineoverrideprivatevirtual

Definition at line 325 of file dxf_import_plugin.h.

325 {}

◆ addSpline()

void DXF_IMPORT_PLUGIN::addSpline ( const DL_SplineData &  aData)
overrideprivatevirtual

Called for every spline.

Definition at line 171 of file dxf_import_plugin.cpp.

172 {
173  if( m_inBlock )
174  return;
175 
176  // Called when starting reading a spline
179  m_curr_entity.m_EntityFlag = aData.flags;
180  m_curr_entity.m_EntityType = DL_ENTITY_SPLINE;
181  m_curr_entity.m_SplineDegree = aData.degree;
182  m_curr_entity.m_SplineTangentStartX = aData.tangentStartX;
183  m_curr_entity.m_SplineTangentStartY = aData.tangentStartY;
184  m_curr_entity.m_SplineTangentEndX = aData.tangentEndX;
185  m_curr_entity.m_SplineTangentEndY = aData.tangentEndY;
186  m_curr_entity.m_SplineKnotsCount = aData.nKnots;
187  m_curr_entity.m_SplineControlCount = aData.nControl;
188  m_curr_entity.m_SplineFitCount = aData.nFit;
189 }
DXF2BRD_ENTITY_DATA m_curr_entity
unsigned int m_SplineFitCount
unsigned int m_SplineControlCount
unsigned int m_SplineKnotsCount
unsigned int m_SplineDegree

References DXF2BRD_ENTITY_DATA::Clear(), m_curr_entity, DXF2BRD_ENTITY_DATA::m_EntityFlag, DXF2BRD_ENTITY_DATA::m_EntityParseStatus, DXF2BRD_ENTITY_DATA::m_EntityType, m_inBlock, DXF2BRD_ENTITY_DATA::m_SplineControlCount, DXF2BRD_ENTITY_DATA::m_SplineDegree, DXF2BRD_ENTITY_DATA::m_SplineFitCount, DXF2BRD_ENTITY_DATA::m_SplineKnotsCount, DXF2BRD_ENTITY_DATA::m_SplineTangentEndX, DXF2BRD_ENTITY_DATA::m_SplineTangentEndY, DXF2BRD_ENTITY_DATA::m_SplineTangentStartX, and DXF2BRD_ENTITY_DATA::m_SplineTangentStartY.

◆ addText()

void DXF_IMPORT_PLUGIN::addText ( const DL_TextData &  aData)
overrideprivatevirtual

Definition at line 397 of file dxf_import_plugin.cpp.

398 {
399  if( m_inBlock )
400  return;
401 
402  VECTOR2D refPoint( mapX( aData.ipx ), mapY( aData.ipy ) );
403  VECTOR2D secPoint( mapX( aData.apx ), mapY( aData.apy ) );
404 
405  if( aData.vJustification != 0 || aData.hJustification != 0 || aData.hJustification == 4 )
406  {
407  if( aData.hJustification != 3 && aData.hJustification != 5 )
408  {
409  VECTOR2D tmp = secPoint;
410  secPoint = refPoint;
411  refPoint = tmp;
412  }
413  }
414 
415  wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
416 
417  double textHeight = mapDim( aData.height );
418  // The 0.9 factor gives a better height/width ratio with our font
419  double charWidth = textHeight * 0.9;
420  double textWidth = charWidth * text.length(); // Rough approximation
421  double textThickness = textHeight/8.0; // Use a reasonable line thickness for this text
422 
423  VECTOR2D bottomLeft(0.0, 0.0);
424  VECTOR2D bottomRight(0.0, 0.0);
425  VECTOR2D topLeft(0.0, 0.0);
426  VECTOR2D topRight(0.0, 0.0);
427 
430 
431  switch( aData.vJustification )
432  {
433  case 0: //DRW_Text::VBaseLine:
434  case 1: //DRW_Text::VBottom:
435  vJustify = GR_TEXT_VJUSTIFY_BOTTOM;
436 
437  topLeft.y = textHeight;
438  topRight.y = textHeight;
439  break;
440 
441  case 2: //DRW_Text::VMiddle:
442  vJustify = GR_TEXT_VJUSTIFY_CENTER;
443 
444  bottomRight.y = -textHeight / 2.0;
445  bottomLeft.y = -textHeight / 2.0;
446  topLeft.y = textHeight / 2.0;
447  topRight.y = textHeight / 2.0;
448  break;
449 
450  case 3: //DRW_Text::VTop:
451  vJustify = GR_TEXT_VJUSTIFY_TOP;
452 
453  bottomLeft.y = -textHeight;
454  bottomRight.y = -textHeight;
455  break;
456  }
457 
458  switch( aData.hJustification )
459  {
460  case 0: //DRW_Text::HLeft:
461  case 3: //DRW_Text::HAligned: // no equivalent options in text pcb.
462  case 5: //DRW_Text::HFit: // no equivalent options in text pcb.
463  hJustify = GR_TEXT_HJUSTIFY_LEFT;
464 
465  bottomRight.x = textWidth;
466  topRight.x = textWidth;
467  break;
468 
469  case 1: //DRW_Text::HCenter:
470  case 4: //DRW_Text::HMiddle: // no equivalent options in text pcb.
471  hJustify = GR_TEXT_HJUSTIFY_CENTER;
472 
473  bottomLeft.x = -textWidth / 2.0;
474  topLeft.x = -textWidth / 2.0;
475  bottomRight.x = textWidth / 2.0;
476  topRight.x = textWidth / 2.0;
477  break;
478 
479  case 2: //DRW_Text::HRight:
480  hJustify = GR_TEXT_HJUSTIFY_RIGHT;
481 
482  bottomLeft.x = -textWidth;
483  topLeft.x = -textWidth;
484  break;
485  }
486 
487 #if 0
488  wxString sty = wxString::FromUTF8( aData.style.c_str() );
489  sty = sty.ToLower();
490 
491  if( aData.textgen == 2 )
492  {
493  // Text dir = left to right;
494  } else if( aData.textgen == 4 )
495  {
496  // Text dir = top to bottom;
497  } else
498  {
499  }
500 #endif
501 
502  // dxf_lib imports text angle in radians (although there are no comment about that.
503  // So, for the moment, convert this angle to degrees
504  double angle_degree = aData.angle * 180 / M_PI;
505  // We also need the angle in radians. so convert angle_degree to radians
506  // regardless the aData.angle unit
507  double angleInRads = angle_degree * M_PI / 180.0;
508  double cosine = cos(angleInRads);
509  double sine = sin(angleInRads);
510 
511  m_internalImporter.AddText( refPoint, text, textHeight, charWidth, textThickness,
512  angle_degree, hJustify, vJustify );
513 
514  // Calculate the boundary box and update the image limits:
515  bottomLeft.x = bottomLeft.x * cosine - bottomLeft.y * sine;
516  bottomLeft.y = bottomLeft.x * sine + bottomLeft.y * cosine;
517 
518  bottomRight.x = bottomRight.x * cosine - bottomRight.y * sine;
519  bottomRight.y = bottomRight.x * sine + bottomRight.y * cosine;
520 
521  topLeft.x = topLeft.x * cosine - topLeft.y * sine;
522  topLeft.y = topLeft.x * sine + topLeft.y * cosine;
523 
524  topRight.x = topRight.x * cosine - topRight.y * sine;
525  topRight.y = topRight.x * sine + topRight.y * cosine;
526 
527  bottomLeft += refPoint;
528  bottomRight += refPoint;
529  topLeft += refPoint;
530  topRight += refPoint;
531 
532  updateImageLimits( bottomLeft );
533  updateImageLimits( bottomRight );
534  updateImageLimits( topLeft );
535  updateImageLimits( topRight );
536 
537 }
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:44
double mapX(double aDxfCoordX)
void updateImageLimits(const VECTOR2D &aPoint)
static wxString toNativeString(const wxString &aData)
Converts a DXF encoded string into a native Unicode string.
double mapDim(double aDxfValue)
void AddText(const VECTOR2D &aOrigin, const wxString &aText, double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify) override
Create an object representing a text.
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:51
double mapY(double aDxfCoordY)
GRAPHICS_IMPORTER_BUFFER m_internalImporter

References GRAPHICS_IMPORTER_BUFFER::AddText(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, m_inBlock, m_internalImporter, mapDim(), mapX(), mapY(), toNativeString(), updateImageLimits(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ addTextStyle()

void DXF_IMPORT_PLUGIN::addTextStyle ( const DL_StyleData &  aData)
overrideprivatevirtual

Definition at line 919 of file dxf_import_plugin.cpp.

920 {
921  // TODO
922 }

◆ addTrace()

virtual void DXF_IMPORT_PLUGIN::addTrace ( const DL_TraceData &  )
inlineoverrideprivatevirtual

Definition at line 322 of file dxf_import_plugin.h.

322 {}

◆ addVertex()

void DXF_IMPORT_PLUGIN::addVertex ( const DL_VertexData &  aData)
overrideprivatevirtual

Called for every polyline vertex.

Definition at line 268 of file dxf_import_plugin.cpp.

269 {
270  if( m_inBlock )
271  return;
272 
274  return; // Error
275 
276  double lineWidth = mapWidth( attributes.getWidth() );
277 
278  const DL_VertexData* vertex = &aData;
279 
280  if( m_curr_entity.m_EntityParseStatus == 1 ) // This is the first vertex of an entity
281  {
285  m_curr_entity.m_BulgeVertex = vertex->bulge;
287  return;
288  }
289 
290  VECTOR2D seg_end( m_xOffset + vertex->x * m_DXF2mm,
291  m_yOffset - vertex->y * m_DXF2mm );
292 
293  if( std::abs( m_curr_entity.m_BulgeVertex ) < MIN_BULGE )
294  insertLine( m_curr_entity.m_LastCoordinate, seg_end, lineWidth );
295  else
297  lineWidth );
298 
300  m_curr_entity.m_BulgeVertex = vertex->bulge;
301 }
DXF2BRD_ENTITY_DATA m_curr_entity
void insertArc(const VECTOR2D &aSegStart, const VECTOR2D &aSegEnd, double aBulge, int aWidth)
#define MIN_BULGE
double mapWidth(double aDxfWidth)
void insertLine(const VECTOR2D &aSegStart, const VECTOR2D &aSegEnd, int aWidth)

References insertArc(), insertLine(), DXF2BRD_ENTITY_DATA::m_BulgeVertex, m_curr_entity, m_DXF2mm, DXF2BRD_ENTITY_DATA::m_EntityParseStatus, m_inBlock, DXF2BRD_ENTITY_DATA::m_LastCoordinate, DXF2BRD_ENTITY_DATA::m_PolylineStart, m_xOffset, m_yOffset, mapWidth(), MIN_BULGE, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ endBlock()

void DXF_IMPORT_PLUGIN::endBlock ( )
overrideprivatevirtual

Definition at line 342 of file dxf_import_plugin.cpp.

343 {
344  m_inBlock = false;
345 }

References m_inBlock.

◆ endEntity()

void DXF_IMPORT_PLUGIN::endEntity ( )
overrideprivatevirtual

Definition at line 304 of file dxf_import_plugin.cpp.

305 {
306  if( m_curr_entity.m_EntityType == DL_ENTITY_POLYLINE ||
307  m_curr_entity.m_EntityType == DL_ENTITY_LWPOLYLINE )
308  {
309  // Polyline flags bit 0 indicates closed (1) or open (0) polyline
310  if( m_curr_entity.m_EntityFlag & 1 )
311  {
312  double lineWidth = mapWidth( attributes.getWidth() );
313 
314  if( std::abs( m_curr_entity.m_BulgeVertex ) < MIN_BULGE )
316  lineWidth );
317  else
319  m_curr_entity.m_BulgeVertex, lineWidth );
320  }
321  }
322 
323  if( m_curr_entity.m_EntityType == DL_ENTITY_SPLINE )
324  {
325  double lineWidth = mapWidth( attributes.getWidth() );
326  insertSpline( lineWidth );
327  }
328 
330 }
DXF2BRD_ENTITY_DATA m_curr_entity
void insertArc(const VECTOR2D &aSegStart, const VECTOR2D &aSegEnd, double aBulge, int aWidth)
#define MIN_BULGE
double mapWidth(double aDxfWidth)
void insertSpline(int aWidth)
void insertLine(const VECTOR2D &aSegStart, const VECTOR2D &aSegEnd, int aWidth)

References DXF2BRD_ENTITY_DATA::Clear(), insertArc(), insertLine(), insertSpline(), DXF2BRD_ENTITY_DATA::m_BulgeVertex, m_curr_entity, DXF2BRD_ENTITY_DATA::m_EntityFlag, DXF2BRD_ENTITY_DATA::m_EntityType, DXF2BRD_ENTITY_DATA::m_LastCoordinate, DXF2BRD_ENTITY_DATA::m_PolylineStart, mapWidth(), and MIN_BULGE.

◆ GetFileExtensions()

const std::vector<std::string> DXF_IMPORT_PLUGIN::GetFileExtensions ( ) const
inlineoverridevirtual

Return a vector of the file extensions handled by this plugin.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 150 of file dxf_import_plugin.h.

151  {
152  static std::vector<std::string> exts = { "dxf" };
153  return exts;
154  }

◆ GetImageHeight()

double DXF_IMPORT_PLUGIN::GetImageHeight ( ) const
overridevirtual

Return image height from original imported file.

Returns
Original Image height in mm.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 100 of file dxf_import_plugin.cpp.

101 {
102  return m_maxY - m_minY;
103 }

References m_maxY, and m_minY.

◆ GetImageWidth()

double DXF_IMPORT_PLUGIN::GetImageWidth ( ) const
overridevirtual

Return image width from original imported file.

Returns
Original Image width in mm.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 94 of file dxf_import_plugin.cpp.

95 {
96  return m_maxX - m_minX;
97 }

References m_maxX, and m_minX.

◆ GetMessages()

const std::string& DXF_IMPORT_PLUGIN::GetMessages ( ) const
inlineoverridevirtual
Returns
the list of messages in one string. Each message ends by '
'

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 220 of file dxf_import_plugin.h.

221  {
222  return m_messages;
223  }

References m_messages.

◆ GetName()

const wxString DXF_IMPORT_PLUGIN::GetName ( ) const
inlineoverridevirtual

Return the plugin name.

This string will be used as the description in the file dialog.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 145 of file dxf_import_plugin.h.

146  {
147  return "AutoCAD DXF";
148  }

◆ GetWildcards()

wxString GRAPHICS_IMPORT_PLUGIN::GetWildcards ( ) const
inlineinherited

Return a list of wildcards that contains the file extensions handled by this plugin, separated with a semi-colon.

Definition at line 68 of file graphics_import_plugin.h.

69  {
70  wxString ret;
71  bool first = true;
72 
73  for( const auto& extension : GetFileExtensions() )
74  {
75  if( first )
76  first = false;
77  else
78  ret += ";";
79 
80  ret += "*." + formatWildcardExt( extension );
81  }
82 
83  return ret;
84  }
virtual const std::vector< std::string > GetFileExtensions() const =0
Return a vector of the file extensions handled by this plugin.
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.

References formatWildcardExt(), and GRAPHICS_IMPORT_PLUGIN::GetFileExtensions().

◆ Import()

bool DXF_IMPORT_PLUGIN::Import ( )
overridevirtual

Actually imports the file.

It is necessary to have loaded the file beforehand.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 85 of file dxf_import_plugin.cpp.

86 {
87  wxCHECK( m_importer, false );
89 
90  return true;
91 }
GRAPHICS_IMPORTER * m_importer
Importer used to create objects representing the imported shapes.
GRAPHICS_IMPORTER_BUFFER m_internalImporter
void ImportTo(GRAPHICS_IMPORTER &aImporter)

References GRAPHICS_IMPORTER_BUFFER::ImportTo(), GRAPHICS_IMPORT_PLUGIN::m_importer, and m_internalImporter.

◆ ImportAsFootprintGraphic()

void DXF_IMPORT_PLUGIN::ImportAsFootprintGraphic ( bool  aImportAsFootprintGraphic)
inline

Allows the import DXF items converted to board graphic items or footprint graphic items.

Parameters
aImportAsFootprintGraphic= true to import in a footprint, false to import on a board

Definition at line 171 of file dxf_import_plugin.h.

172  {
173  m_importAsfootprintGraphicItems = aImportAsFootprintGraphic;
174  }

References m_importAsfootprintGraphicItems.

◆ ImportDxfFile()

bool DXF_IMPORT_PLUGIN::ImportDxfFile ( const wxString &  aFile)

Implementation of the method used for communicate with this filter.

Parameters
aFile= the full filename.

Definition at line 145 of file dxf_import_plugin.cpp.

146 {
147  DL_Dxf dxf_reader;
148 
149  // wxFopen takes care of unicode filenames across platforms
150  FILE* fp = wxFopen( aFile, "rt" );
151 
152  if( fp == nullptr )
153  return false;
154 
155  // Note the dxf reader takes care of switching to "C" locale before reading the file
156  // and will close the file after reading
157  bool success = dxf_reader.in( fp, this );
158 
159  return success;
160 }

Referenced by Load().

◆ insertArc()

void DXF_IMPORT_PLUGIN::insertArc ( const VECTOR2D aSegStart,
const VECTOR2D aSegEnd,
double  aBulge,
int  aWidth 
)
private

Definition at line 937 of file dxf_import_plugin.cpp.

939 {
940  VECTOR2D segment_startpoint( SCALE_FACTOR( aSegStart.x ), SCALE_FACTOR( aSegStart.y ) );
941  VECTOR2D segment_endpoint( SCALE_FACTOR( aSegEnd.x ), SCALE_FACTOR( aSegEnd.y ) );
942 
943  // ensure aBulge represents an angle from +/- ( 0 .. approx 359.8 deg )
944  if( aBulge < -2000.0 )
945  aBulge = -2000.0;
946  else if( aBulge > 2000.0 )
947  aBulge = 2000.0;
948 
949  double ang = 4.0 * atan( aBulge );
950 
951  // reflect the Y values to put everything in a RHCS
952  VECTOR2D sp( aSegStart.x, -aSegStart.y );
953  VECTOR2D ep( aSegEnd.x, -aSegEnd.y );
954  // angle from end->start
955  double offAng = atan2( ep.y - sp.y, ep.x - sp.x );
956  // length of subtended segment = 1/2 distance between the 2 points
957  double d = 0.5 * sqrt( (sp.x - ep.x) * (sp.x - ep.x) + (sp.y - ep.y) * (sp.y - ep.y) );
958  // midpoint of the subtended segment
959  double xm = ( sp.x + ep.x ) * 0.5;
960  double ym = ( sp.y + ep.y ) * 0.5;
961  double radius = d / sin( ang * 0.5 );
962 
963  if( radius < 0.0 )
964  radius = -radius;
965 
966  // calculate the height of the triangle with base d and hypotenuse r
967  double dh2 = radius * radius - d * d;
968 
969  // this should only ever happen due to rounding errors when r == d
970  if( dh2 < 0.0 )
971  dh2 = 0.0;
972 
973  double h = sqrt( dh2 );
974 
975  if( ang < 0.0 )
976  offAng -= M_PI_2;
977  else
978  offAng += M_PI_2;
979 
980  // for angles greater than 180 deg we need to flip the
981  // direction in which the arc center is found relative
982  // to the midpoint of the subtended segment.
983  if( ang < -M_PI )
984  offAng += M_PI;
985  else if( ang > M_PI )
986  offAng -= M_PI;
987 
988  // center point
989  double cx = h * cos( offAng ) + xm;
990  double cy = h * sin( offAng ) + ym;
991  VECTOR2D center( SCALE_FACTOR( cx ), SCALE_FACTOR( -cy ) );
992  VECTOR2D arc_start;
993  double angle = RAD2DEG( ang );
994 
995  if( ang < 0.0 )
996  {
997  arc_start = VECTOR2D( SCALE_FACTOR( ep.x ), SCALE_FACTOR( -ep.y ) );
998  }
999  else
1000  {
1001  arc_start = VECTOR2D( SCALE_FACTOR( sp.x ), SCALE_FACTOR( -sp.y ) );
1002  angle = -angle;
1003  }
1004 
1005  m_internalImporter.AddArc( center, arc_start, angle, aWidth );
1006 
1007  VECTOR2D radiusDelta( SCALE_FACTOR( radius ), SCALE_FACTOR( radius ) );
1008 
1009  updateImageLimits( center + radiusDelta );
1010  updateImageLimits( center - radiusDelta );
1011  return;
1012 }
void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth) override
Create an object representing an arc.
#define M_PI_2
Definition: transline.cpp:36
double RAD2DEG(double rad)
Definition: trigo.h:215
void updateImageLimits(const VECTOR2D &aPoint)
#define SCALE_FACTOR(x)
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
GRAPHICS_IMPORTER_BUFFER m_internalImporter

References GRAPHICS_IMPORTER_BUFFER::AddArc(), PNS::angle(), m_internalImporter, M_PI_2, RAD2DEG(), SCALE_FACTOR, updateImageLimits(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by addVertex(), and endEntity().

◆ insertLine()

void DXF_IMPORT_PLUGIN::insertLine ( const VECTOR2D aSegStart,
const VECTOR2D aSegEnd,
int  aWidth 
)
private

Definition at line 925 of file dxf_import_plugin.cpp.

927 {
928  VECTOR2D origin( SCALE_FACTOR( aSegStart.x ), SCALE_FACTOR( aSegStart.y ) );
929  VECTOR2D end( SCALE_FACTOR( aSegEnd.x ), SCALE_FACTOR( aSegEnd.y ) );
930  m_internalImporter.AddLine( origin, end, aWidth );
931 
932  updateImageLimits( origin );
933  updateImageLimits( end );
934 }
void AddLine(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth) override
Create an object representing a line segment.
void updateImageLimits(const VECTOR2D &aPoint)
#define SCALE_FACTOR(x)
GRAPHICS_IMPORTER_BUFFER m_internalImporter

References GRAPHICS_IMPORTER_BUFFER::AddLine(), m_internalImporter, SCALE_FACTOR, updateImageLimits(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by addVertex(), and endEntity().

◆ insertSpline()

void DXF_IMPORT_PLUGIN::insertSpline ( int  aWidth)
private

Definition at line 1017 of file dxf_import_plugin.cpp.

1018 {
1019  #if 0 // Debug only
1020  wxLogMessage("spl deg %d kn %d ctr %d fit %d",
1025  #endif
1026 
1027  unsigned imax = m_curr_entity.m_SplineControlPointList.size();
1028 
1029  if( imax < 2 ) // malformed spline
1030  return;
1031 
1032 #if 0 // set to 1 to approximate the spline by segments between 2 control points
1033  VECTOR2D startpoint( mapX( m_curr_entity.m_SplineControlPointList[0].m_x ),
1035 
1036  for( unsigned int ii = 1; ii < imax; ++ii )
1037  {
1038  VECTOR2D endpoint( mapX( m_curr_entity.m_SplineControlPointList[ii].m_x ),
1040 
1041  if( startpoint != endpoint )
1042  {
1043  m_internalImporter.AddLine( startpoint, endpoint, aWidth );
1044 
1045  updateImageLimits( startpoint );
1046  updateImageLimits( endpoint );
1047 
1048  startpoint = endpoint;
1049  }
1050  }
1051 #else // Use bezier curves, supported by pcbnew, to approximate the spline
1052  tinyspline::BSpline dxfspline( m_curr_entity.m_SplineControlPointList.size(),
1053  /* coord dim */ 2, m_curr_entity.m_SplineDegree );
1054  std::vector<double> ctrlp;
1055 
1056  for( unsigned ii = 0; ii < imax; ++ii )
1057  {
1058  ctrlp.push_back( m_curr_entity.m_SplineControlPointList[ii].m_x );
1059  ctrlp.push_back( m_curr_entity.m_SplineControlPointList[ii].m_y );
1060  }
1061 
1062  dxfspline.setCtrlp( ctrlp );
1063  dxfspline.setKnots( m_curr_entity.m_SplineKnotsList );
1064  tinyspline::BSpline beziers( dxfspline.toBeziers() );
1065 
1066  std::vector<double> coords = beziers.ctrlp();
1067 
1068  // Each Bezier curve uses 4 vertices (a start point, 2 control points and a end point).
1069  // So we can have more than one Bezier curve ( there are one curve each four vertices)
1070  // However, one can have one Bezier curve with end point = ctrl point 2, having only 3
1071  // defined points in list.
1072  for( unsigned ii = 0; ii < coords.size(); ii += 8 )
1073  {
1074  VECTOR2D start( mapX( coords[ii] ), mapY( coords[ii+1] ) );
1075  VECTOR2D bezierControl1( mapX( coords[ii+2] ), mapY( coords[ii+3] ) );
1076  VECTOR2D bezierControl2( mapX( coords[ii+4] ), mapY( coords[ii+5] ) );
1077  VECTOR2D end;
1078 
1079  if( ii+7 < coords.size() )
1080  end = VECTOR2D( mapX( coords[ii+6] ), mapY( coords[ii+7] ) );
1081  else
1082  end = bezierControl2;
1083 
1084  m_internalImporter.AddSpline( start, bezierControl1, bezierControl2, end , aWidth );
1085  }
1086 #endif
1087 }
DXF2BRD_ENTITY_DATA m_curr_entity
void AddLine(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth) override
Create an object representing a line segment.
double mapX(double aDxfCoordX)
std::vector< VECTOR2D > m_SplineFitPointList
void updateImageLimits(const VECTOR2D &aPoint)
void AddSpline(const VECTOR2D &aStart, const VECTOR2D &BezierControl1, const VECTOR2D &BezierControl2, const VECTOR2D &aEnd, double aWidth) override
Create an object representing an arc.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
unsigned int m_SplineDegree
double mapY(double aDxfCoordY)
GRAPHICS_IMPORTER_BUFFER m_internalImporter
std::vector< double > m_SplineKnotsList
std::vector< SPLINE_CTRL_POINT > m_SplineControlPointList

References GRAPHICS_IMPORTER_BUFFER::AddLine(), GRAPHICS_IMPORTER_BUFFER::AddSpline(), m_curr_entity, m_internalImporter, DXF2BRD_ENTITY_DATA::m_SplineControlPointList, DXF2BRD_ENTITY_DATA::m_SplineDegree, DXF2BRD_ENTITY_DATA::m_SplineFitPointList, DXF2BRD_ENTITY_DATA::m_SplineKnotsList, mapX(), mapY(), and updateImageLimits().

Referenced by endEntity().

◆ linkImage()

virtual void DXF_IMPORT_PLUGIN::linkImage ( const DL_ImageDefData &  )
inlineoverrideprivatevirtual

Definition at line 328 of file dxf_import_plugin.h.

328 {}

◆ Load()

bool DXF_IMPORT_PLUGIN::Load ( const wxString &  aFileName)
overridevirtual

Load file for import.

It is necessary to have the GRAPHICS_IMPORTER object set before.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 79 of file dxf_import_plugin.cpp.

80 {
81  return ImportDxfFile( aFileName );
82 }
bool ImportDxfFile(const wxString &aFile)
Implementation of the method used for communicate with this filter.

References ImportDxfFile().

◆ mapDim()

double DXF_IMPORT_PLUGIN::mapDim ( double  aDxfValue)
private

Definition at line 127 of file dxf_import_plugin.cpp.

128 {
129  return SCALE_FACTOR( aDxfValue * m_DXF2mm );
130 }
#define SCALE_FACTOR(x)

References m_DXF2mm, and SCALE_FACTOR.

Referenced by addArc(), addCircle(), addMText(), and addText().

◆ mapWidth()

double DXF_IMPORT_PLUGIN::mapWidth ( double  aDxfWidth)
private

Definition at line 133 of file dxf_import_plugin.cpp.

134 {
135  // Always return the default line width
136 #if 0
137  // mapWidth returns the aDxfValue if aDxfWidth > 0 m_defaultThickness
138  if( aDxfWidth > 0.0 )
139  return SCALE_FACTOR( aDxfWidth * m_DXF2mm );
140 #endif
142 }
#define SCALE_FACTOR(x)

References m_defaultThickness, m_DXF2mm, and SCALE_FACTOR.

Referenced by addArc(), addCircle(), addLine(), addVertex(), and endEntity().

◆ mapX()

double DXF_IMPORT_PLUGIN::mapX ( double  aDxfCoordX)
private

Definition at line 115 of file dxf_import_plugin.cpp.

116 {
117  return SCALE_FACTOR( m_xOffset + ( aDxfCoordX * m_DXF2mm ) );
118 }
#define SCALE_FACTOR(x)

References m_DXF2mm, m_xOffset, and SCALE_FACTOR.

Referenced by addArc(), addCircle(), addLine(), addMText(), addText(), and insertSpline().

◆ mapY()

double DXF_IMPORT_PLUGIN::mapY ( double  aDxfCoordY)
private

Definition at line 121 of file dxf_import_plugin.cpp.

122 {
123  return SCALE_FACTOR( m_yOffset - ( aDxfCoordY * m_DXF2mm ) );
124 }
#define SCALE_FACTOR(x)

References m_DXF2mm, m_yOffset, and SCALE_FACTOR.

Referenced by addArc(), addCircle(), addLine(), addMText(), addText(), and insertSpline().

◆ reportMsg()

void DXF_IMPORT_PLUGIN::reportMsg ( const char *  aMessage)
private

Definition at line 163 of file dxf_import_plugin.cpp.

164 {
165  // Add message to keep trace of not handled dxf entities
166  m_messages += aMessage;
167  m_messages += '\n';
168 }

References m_messages.

◆ SetBrdLayer()

void DXF_IMPORT_PLUGIN::SetBrdLayer ( int  aBrdLayer)
inline

Set the layer number to import dxf items.

the layer should be a technical layer, not a copper layer

Definition at line 207 of file dxf_import_plugin.h.

207 { m_brdLayer = aBrdLayer; }

References m_brdLayer.

◆ SetDefaultLineWidthMM()

void DXF_IMPORT_PLUGIN::SetDefaultLineWidthMM ( double  aWidth)
inline

Set the default line width when importing dxf items like lines to Pcbnew.

because dxf files have no line width explicit parameter, it will be most of time the line width of imported lines

Parameters
aWidth= line width in mm

Definition at line 183 of file dxf_import_plugin.h.

184  {
185  m_defaultThickness = aWidth;
186  }

References m_defaultThickness.

Referenced by SetImporter(), and SetLineWidthMM().

◆ SetImporter()

void DXF_IMPORT_PLUGIN::SetImporter ( GRAPHICS_IMPORTER aImporter)
overridevirtual

Set the receiver of the imported shapes.

Reimplemented from GRAPHICS_IMPORT_PLUGIN.

Definition at line 106 of file dxf_import_plugin.cpp.

107 {
109 
110  if( m_importer )
112 }
void SetDefaultLineWidthMM(double aWidth)
Set the default line width when importing dxf items like lines to Pcbnew.
double GetLineWidthMM() const
Returns the line width used for importing the outlines (in mm).
virtual void SetImporter(GRAPHICS_IMPORTER *aImporter)
Set the receiver of the imported shapes.
GRAPHICS_IMPORTER * m_importer
Importer used to create objects representing the imported shapes.

References GRAPHICS_IMPORTER::GetLineWidthMM(), GRAPHICS_IMPORT_PLUGIN::m_importer, SetDefaultLineWidthMM(), and GRAPHICS_IMPORT_PLUGIN::SetImporter().

◆ SetLineWidthMM()

void DXF_IMPORT_PLUGIN::SetLineWidthMM ( double  aWidth)
inlineoverridevirtual

Reimplemented from GRAPHICS_IMPORT_PLUGIN.

Definition at line 188 of file dxf_import_plugin.h.

188 { SetDefaultLineWidthMM( aWidth ); }
void SetDefaultLineWidthMM(double aWidth)
Set the default line width when importing dxf items like lines to Pcbnew.

References SetDefaultLineWidthMM().

◆ SetOffset()

void DXF_IMPORT_PLUGIN::SetOffset ( double  aOffsetX,
double  aOffsetY 
)
inline

Set the coordinate offset between the imported dxf items and Pcbnew.

because dxf files have the Y axis from bottom to top; aOffsetX = 0, and aOffsetY = - vertical page size to import a full page

Parameters
aOffsetX= the X offset in mm
aOffsetY= the Y offset in mm

Definition at line 197 of file dxf_import_plugin.h.

198  {
199  m_xOffset = aOffsetX;
200  m_yOffset = aOffsetY;
201  }

References m_xOffset, and m_yOffset.

◆ setVariableDouble()

virtual void DXF_IMPORT_PLUGIN::setVariableDouble ( const std::string &  key,
double  value,
int  code 
)
inlineoverrideprivatevirtual

Called for every double variable in the DXF file (e.g.

"$DIMEXO").

Definition at line 262 of file dxf_import_plugin.h.

262 {}

◆ setVariableInt()

void DXF_IMPORT_PLUGIN::setVariableInt ( const std::string &  key,
int  value,
int  code 
)
overrideprivatevirtual

Called for every int variable in the DXF file (e.g.

"$ACADMAINTVER").

Definition at line 699 of file dxf_import_plugin.cpp.

700 {
701  if( m_inBlock )
702  return;
703 
704  // Called for every int variable in the DXF file (e.g. "$INSUNITS").
705 
706  if( key == "$DWGCODEPAGE" )
707  {
708  m_codePage = value;
709  return;
710  }
711 
712  if( key == "$INSUNITS" ) // Drawing units
713  {
714  switch( value )
715  {
716  case 1: // inches
717  m_DXF2mm = 25.4;
718  break;
719 
720  case 2: // feet
721  m_DXF2mm = 304.8;
722  break;
723 
724  case 4: // mm
725  m_DXF2mm = 1.0;
726  break;
727 
728  case 5: // centimeters
729  m_DXF2mm = 10.0;
730  break;
731 
732  case 6: // meters
733  m_DXF2mm = 1000.0;
734  break;
735 
736  case 8: // microinches
737  m_DXF2mm = 2.54e-5;
738  break;
739 
740  case 9: // mils
741  m_DXF2mm = 0.0254;
742  break;
743 
744  case 10: // yards
745  m_DXF2mm = 914.4;
746  break;
747 
748  case 11: // Angstroms
749  m_DXF2mm = 1.0e-7;
750  break;
751 
752  case 12: // nanometers
753  m_DXF2mm = 1.0e-6;
754  break;
755 
756  case 13: // micrometers
757  m_DXF2mm = 1.0e-3;
758  break;
759 
760  case 14: // decimeters
761  m_DXF2mm = 100.0;
762  break;
763 
764  default:
765  // use the default of 1.0 for:
766  // 0: Unspecified Units
767  // 3: miles
768  // 7: kilometers
769  // 15: decameters
770  // 16: hectometers
771  // 17: gigameters
772  // 18: AU
773  // 19: lightyears
774  // 20: parsecs
775  m_DXF2mm = 1.0;
776  break;
777  }
778 
779  return;
780  }
781 }

References m_codePage, m_DXF2mm, and m_inBlock.

◆ setVariableString()

void DXF_IMPORT_PLUGIN::setVariableString ( const std::string &  key,
const std::string &  value,
int  code 
)
overrideprivatevirtual

Called for every string variable in the DXF file (e.g.

"$ACADVER").

Definition at line 784 of file dxf_import_plugin.cpp.

786 {
787  // Called for every string variable in the DXF file (e.g. "$ACADVER").
788 }

◆ toDxfString()

wxString DXF_IMPORT_PLUGIN::toDxfString ( const wxString &  aStr)
staticprivate

Convert a native unicode string into a DXF encoded string.

DXF encoding includes the following special sequences:

  • %%c for a diameter sign
  • %%d for a degree sign
  • %%p for a plus/minus sign

Definition at line 791 of file dxf_import_plugin.cpp.

792 {
793  wxString res;
794  int j = 0;
795 
796  for( unsigned i = 0; i<aStr.length(); ++i )
797  {
798  int c = aStr[i];
799 
800  if( c > 175 || c < 11 )
801  {
802  res.append( aStr.Mid( j, i - j ) );
803  j = i;
804 
805  switch( c )
806  {
807  case 0x0A:
808  res += wxT( "\\P" );
809  break;
810 
811  // diameter:
812 #ifdef __WINDOWS_
813  // windows, as always, is special.
814  case 0x00D8:
815 #else
816  case 0x2205:
817 #endif
818  res += wxT( "%%C" );
819  break;
820 
821  // degree:
822  case 0x00B0:
823  res += wxT( "%%D" );
824  break;
825 
826  // plus/minus
827  case 0x00B1:
828  res += wxT( "%%P" );
829  break;
830 
831  default:
832  j--;
833  break;
834  }
835 
836  j++;
837  }
838  }
839 
840  res.append( aStr.Mid( j ) );
841  return res;
842 }

◆ toNativeString()

wxString DXF_IMPORT_PLUGIN::toNativeString ( const wxString &  aData)
staticprivate

Converts a DXF encoded string into a native Unicode string.

Definition at line 845 of file dxf_import_plugin.cpp.

846 {
847  wxString res;
848 
849  // Ignore font tags:
850  int j = 0;
851 
852  for( unsigned i = 0; i < aData.length(); ++i )
853  {
854  if( aData[ i ] == 0x7B ) // is '{' ?
855  {
856  if( aData[ i + 1 ] == 0x5c && aData[ i + 2 ] == 0x66 ) // is "\f" ?
857  {
858  // found font tag, append parsed part
859  res.append( aData.Mid( j, i - j ) );
860 
861  // skip to ';'
862  for( unsigned k = i + 3; k < aData.length(); ++k )
863  {
864  if( aData[ k ] == 0x3B )
865  {
866  i = j = ++k;
867  break;
868  }
869  }
870 
871  // add to '}'
872  for( unsigned k = i; k < aData.length(); ++k )
873  {
874  if( aData[ k ] == 0x7D )
875  {
876  res.append( aData.Mid( i, k - i ) );
877  i = j = ++k;
878  break;
879  }
880  }
881  }
882  }
883  }
884 
885  res.append( aData.Mid( j ) );
886 
887 #if 1
888  wxRegEx regexp;
889  // Line feed:
890  regexp.Compile( wxT( "\\\\P" ) );
891  regexp.Replace( &res, wxT( "\n" ) );
892 
893  // Space:
894  regexp.Compile( wxT( "\\\\~" ) );
895  regexp.Replace( &res, wxT( " " ) );
896 
897  // diameter:
898  regexp.Compile( wxT( "%%[cC]" ) );
899 #ifdef __WINDOWS__
900  // windows, as always, is special.
901  regexp.Replace( &res, wxChar( 0xD8 ) );
902 #else
903  // Empty_set, diameter is 0x2300
904  regexp.Replace( &res, wxChar( 0x2205 ) );
905 #endif
906 
907  // degree:
908  regexp.Compile( wxT( "%%[dD]" ) );
909  regexp.Replace( &res, wxChar( 0x00B0 ) );
910  // plus/minus
911  regexp.Compile( wxT( "%%[pP]" ) );
912  regexp.Replace( &res, wxChar( 0x00B1 ) );
913 #endif
914 
915  return res;
916 }

Referenced by addMText(), and addText().

◆ updateImageLimits()

void DXF_IMPORT_PLUGIN::updateImageLimits ( const VECTOR2D aPoint)

Definition at line 1090 of file dxf_import_plugin.cpp.

1091 {
1092  m_minX = std::min( aPoint.x, m_minX );
1093  m_maxX = std::max( aPoint.x, m_maxX );
1094 
1095  m_minY = std::min( aPoint.y, m_minY );
1096  m_maxY = std::max( aPoint.y, m_maxY );
1097 }

References m_maxX, m_maxY, m_minX, m_minY, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by addArc(), addCircle(), addLine(), addMText(), addText(), insertArc(), insertLine(), and insertSpline().

◆ writeLine()

void DXF_IMPORT_PLUGIN::writeLine ( )
private

◆ writeMtext()

void DXF_IMPORT_PLUGIN::writeMtext ( )
private

Member Data Documentation

◆ m_brdLayer

int DXF_IMPORT_PLUGIN::m_brdLayer
private

Definition at line 125 of file dxf_import_plugin.h.

Referenced by DXF_IMPORT_PLUGIN(), and SetBrdLayer().

◆ m_codePage

std::string DXF_IMPORT_PLUGIN::m_codePage
private

Definition at line 128 of file dxf_import_plugin.h.

Referenced by setVariableInt().

◆ m_curr_entity

DXF2BRD_ENTITY_DATA DXF_IMPORT_PLUGIN::m_curr_entity
private

◆ m_defaultThickness

double DXF_IMPORT_PLUGIN::m_defaultThickness
private

Definition at line 123 of file dxf_import_plugin.h.

Referenced by DXF_IMPORT_PLUGIN(), mapWidth(), and SetDefaultLineWidthMM().

◆ m_DXF2mm

double DXF_IMPORT_PLUGIN::m_DXF2mm
private

◆ m_importAsfootprintGraphicItems

bool DXF_IMPORT_PLUGIN::m_importAsfootprintGraphicItems
private

Definition at line 129 of file dxf_import_plugin.h.

Referenced by DXF_IMPORT_PLUGIN(), and ImportAsFootprintGraphic().

◆ m_importer

GRAPHICS_IMPORTER* GRAPHICS_IMPORT_PLUGIN::m_importer
protectedinherited

Importer used to create objects representing the imported shapes.

Definition at line 125 of file graphics_import_plugin.h.

Referenced by SVG_IMPORT_PLUGIN::DrawLineSegments(), SVG_IMPORT_PLUGIN::DrawPolygon(), Import(), SVG_IMPORT_PLUGIN::Load(), GRAPHICS_IMPORT_PLUGIN::SetImporter(), and SetImporter().

◆ m_inBlock

◆ m_internalImporter

GRAPHICS_IMPORTER_BUFFER DXF_IMPORT_PLUGIN::m_internalImporter
private

◆ m_maxX

double DXF_IMPORT_PLUGIN::m_maxX
private

Definition at line 135 of file dxf_import_plugin.h.

Referenced by DXF_IMPORT_PLUGIN(), GetImageWidth(), and updateImageLimits().

◆ m_maxY

double DXF_IMPORT_PLUGIN::m_maxY
private

Definition at line 136 of file dxf_import_plugin.h.

Referenced by DXF_IMPORT_PLUGIN(), GetImageHeight(), and updateImageLimits().

◆ m_messages

std::string DXF_IMPORT_PLUGIN::m_messages
private

Definition at line 131 of file dxf_import_plugin.h.

Referenced by GetMessages(), and reportMsg().

◆ m_minX

double DXF_IMPORT_PLUGIN::m_minX
private

Definition at line 135 of file dxf_import_plugin.h.

Referenced by DXF_IMPORT_PLUGIN(), GetImageWidth(), and updateImageLimits().

◆ m_minY

double DXF_IMPORT_PLUGIN::m_minY
private

Definition at line 136 of file dxf_import_plugin.h.

Referenced by DXF_IMPORT_PLUGIN(), GetImageHeight(), and updateImageLimits().

◆ m_version

int DXF_IMPORT_PLUGIN::m_version
private

Definition at line 126 of file dxf_import_plugin.h.

Referenced by DXF_IMPORT_PLUGIN().

◆ m_xOffset

double DXF_IMPORT_PLUGIN::m_xOffset
private

Definition at line 121 of file dxf_import_plugin.h.

Referenced by addVertex(), DXF_IMPORT_PLUGIN(), mapX(), and SetOffset().

◆ m_yOffset

double DXF_IMPORT_PLUGIN::m_yOffset
private

Definition at line 122 of file dxf_import_plugin.h.

Referenced by addVertex(), DXF_IMPORT_PLUGIN(), mapY(), and SetOffset().


The documentation for this class was generated from the following files: