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
 @breif Returns the plugin name. More...
 
const wxArrayString GetFileExtensions () const override
 Returns a string array of the file extensions handled by this plugin. More...
 
bool Load (const wxString &aFileName) override
 Loads 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)
 
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 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
 
void SetImporter (GRAPHICS_IMPORTER *aImporter)
 Sets the receiver of the imported shapes. More...
 
wxString GetWildcards () const
 Returns a list of wildcards that contains the file extensions handled by this plugin, separated with a coma. 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 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)
 Converts 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
 
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 116 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_defaultThickness = 0.2; // default thickness (in mm)
66  m_brdLayer = Dwgs_User; // The default import layer
70 }
#define max(a, b)
Definition: auxiliary.h:86
#define min(a, b)
Definition: auxiliary.h:85

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

◆ ~DXF_IMPORT_PLUGIN()

DXF_IMPORT_PLUGIN::~DXF_IMPORT_PLUGIN ( )

Definition at line 73 of file dxf_import_plugin.cpp.

74 {
75 }

Member Function Documentation

◆ add3dFace()

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

Definition at line 308 of file dxf_import_plugin.h.

308 { reportMsg( "DL_3dFace not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addArc()

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

Definition at line 313 of file dxf_import_plugin.cpp.

314 {
315  // Init arc centre:
316  VECTOR2D center( mapX( aData.cx ), mapY( aData.cy ) );
317 
318  // aData.anglex is in degrees.
319  double startangle = aData.angle1;
320  double endangle = aData.angle2;
321 
322  // Init arc start point
323  VECTOR2D startPoint( aData.radius, 0.0 );
324  startPoint = startPoint.Rotate( startangle * M_PI / 180.0 );
325  VECTOR2D arcStart( mapX( startPoint.x + aData.cx ), mapY( startPoint.y + aData.cy ) );
326 
327  // calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew)
328  double angle = -( endangle - startangle );
329 
330  if( angle > 0.0 )
331  angle -= 360.0;
332 
333  double lineWidth = mapWidth( attributes.getWidth() );
334  m_internalImporter.AddArc( center, arcStart, angle, lineWidth );
335 
336  VECTOR2D radiusDelta( mapDim( aData.radius ), mapDim( aData.radius ) );
337 
338  updateImageLimits( center + radiusDelta );
339  updateImageLimits( center - radiusDelta );
340 }
void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth) override
Creates 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_internalImporter, mapDim(), mapWidth(), mapX(), mapY(), VECTOR2< T >::Rotate(), updateImageLimits(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ addCircle()

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

Definition at line 297 of file dxf_import_plugin.cpp.

298 {
299  VECTOR2D center( mapX( aData.cx ), mapY( aData.cy ) );
300  double lineWidth = mapWidth( attributes.getWidth() );
301  m_internalImporter.AddCircle( center, mapDim( aData.radius ), lineWidth );
302 
303  VECTOR2D radiusDelta( mapDim( aData.radius ), mapDim( aData.radius ) );
304 
305  updateImageLimits( center + radiusDelta );
306  updateImageLimits( center - radiusDelta );
307 }
double mapX(double aDxfCoordX)
void updateImageLimits(const VECTOR2D &aPoint)
void AddCircle(const VECTOR2D &aCenter, double aRadius, double aWidth) override
Creates 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_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 178 of file dxf_import_plugin.cpp.

179 {
180  // Called for every spline control point, when reading a spline entity
181  m_curr_entity.m_SplineControlPointList.push_back( SPLINE_CTRL_POINT( aData.x , aData.y, aData.w ) );
182 }
DXF2BRD_ENTITY_DATA m_curr_entity
A helper class to store a spline control point (in X,Y plane only)
std::vector< SPLINE_CTRL_POINT > m_SplineControlPointList

References m_curr_entity, and DXF2BRD_ENTITY_DATA::m_SplineControlPointList.

◆ addDimAlign()

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

Definition at line 288 of file dxf_import_plugin.h.

289  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addDimAngular()

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

Definition at line 296 of file dxf_import_plugin.h.

297  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addDimAngular3P()

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

Definition at line 298 of file dxf_import_plugin.h.

299  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addDimDiametric()

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

Definition at line 294 of file dxf_import_plugin.h.

295  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addDimLinear()

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

Definition at line 290 of file dxf_import_plugin.h.

291  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addDimOrdinate()

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

Definition at line 300 of file dxf_import_plugin.h.

301  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addDimRadial()

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

Definition at line 292 of file dxf_import_plugin.h.

293  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addFitPoint()

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

Called for every spline fit point.

Definition at line 184 of file dxf_import_plugin.cpp.

185 {
186  // Called for every spline fit point, when reading a spline entity
187  // we store only the X,Y coord values in a VECTOR2D
188  m_curr_entity.m_SplineFitPointList.push_back( VECTOR2D( aData.x, aData.y ) );
189 }
DXF2BRD_ENTITY_DATA m_curr_entity
std::vector< VECTOR2D > m_SplineFitPointList
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586

References m_curr_entity, and DXF2BRD_ENTITY_DATA::m_SplineFitPointList.

◆ addHatch()

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

Definition at line 305 of file dxf_import_plugin.h.

305 { reportMsg( "DL_Hatch not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addHatchEdge()

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

Definition at line 314 of file dxf_import_plugin.h.

314 { reportMsg( "DL_HatchEdge not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addHatchLoop()

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

Definition at line 313 of file dxf_import_plugin.h.

313 { reportMsg( "DL_HatchLoop not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addImage()

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

Definition at line 311 of file dxf_import_plugin.h.

311 { reportMsg( "DL_ImageDa not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addKnot()

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

Called for every spline knot value.

Definition at line 192 of file dxf_import_plugin.cpp.

193 {
194  // Called for every spline knot value, when reading a spline entity
195  m_curr_entity.m_SplineKnotsList.push_back( aData.k );
196 }
DXF2BRD_ENTITY_DATA m_curr_entity
std::vector< double > m_SplineKnotsList

References m_curr_entity, and DXF2BRD_ENTITY_DATA::m_SplineKnotsList.

◆ addLayer()

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

Definition at line 199 of file dxf_import_plugin.cpp.

200 {
201  // Not yet useful in Pcbnew.
202 #if 0
203  wxString name = wxString::FromUTF8( aData.name.c_str() );
204  wxLogMessage( name );
205 #endif
206 }
const char * name
Definition: DXF_plotter.cpp:61

References name.

◆ addLeader()

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

Definition at line 302 of file dxf_import_plugin.h.

302 { reportMsg( "DL_Leader not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addLeaderVertex()

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

Definition at line 303 of file dxf_import_plugin.h.

303 { reportMsg( "DL_LeaderVertex not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addLine()

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

Definition at line 209 of file dxf_import_plugin.cpp.

210 {
211  VECTOR2D start( mapX( aData.x1 ), mapY( aData.y1 ) );
212  VECTOR2D end( mapX( aData.x2 ), mapY( aData.y2 ) );
213  double lineWidth = mapWidth( attributes.getWidth() );
214 
215  m_internalImporter.AddLine( start, end, lineWidth );
216 
217  updateImageLimits( start );
218  updateImageLimits( end );
219 }
void AddLine(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth) override
Creates 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_internalImporter, mapWidth(), mapX(), mapY(), and updateImageLimits().

◆ addMText()

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

Definition at line 483 of file dxf_import_plugin.cpp.

484 {
485  wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
486  wxString attrib, tmp;
487 
488  double textHeight = mapDim( aData.height );
489  // The 0.9 factor gives a better height/width ratio with our font
490  double charWidth = textHeight * 0.9;
491  double textWidth = charWidth * text.length(); // Rough approximation
492  double textThickness = textHeight/8.0; // Use a reasonable line thickness for this text
493 
494  VECTOR2D bottomLeft(0.0, 0.0);
495  VECTOR2D bottomRight(0.0, 0.0);
496  VECTOR2D topLeft(0.0, 0.0);
497  VECTOR2D topRight(0.0, 0.0);
498 
499  /* Some texts start by '\' and have formating chars (font name, font option...)
500  * ending with ';'
501  * Here are some mtext formatting codes:
502  * Format code Purpose
503  * \0...\o Turns overline on and off
504  * \L...\l Turns underline on and off
505  * \~ Inserts a nonbreaking space
506  \\ Inserts a backslash
507  \\\{...\} Inserts an opening and closing brace
508  \\ \File name; Changes to the specified font file
509  \\ \Hvalue; Changes to the text height specified in drawing units
510  \\ \Hvaluex; Changes the text height to a multiple of the current text height
511  \\ \S...^...; Stacks the subsequent text at the \, #, or ^ symbol
512  \\ \Tvalue; Adjusts the space between characters, from.75 to 4 times
513  \\ \Qangle; Changes obliquing angle
514  \\ \Wvalue; Changes width factor to produce wide text
515  \\ \A Sets the alignment value; valid values: 0, 1, 2 (bottom, center, top) while( text.StartsWith( wxT("\\") ) )
516  */
517  while( text.StartsWith( wxT( "\\" ) ) )
518  {
519  attrib << text.BeforeFirst( ';' );
520  tmp = text.AfterFirst( ';' );
521  text = tmp;
522  }
523 
524  VECTOR2D textpos( mapX( aData.ipx ), mapY( aData.ipy ) );
525 
526  // Initialize text justifications:
529 
530  if( aData.attachmentPoint <= 3 )
531  {
532  vJustify = GR_TEXT_VJUSTIFY_TOP;
533 
534  bottomLeft.y = -textHeight;
535  bottomRight.y = -textHeight;
536  }
537  else if( aData.attachmentPoint <= 6 )
538  {
539  vJustify = GR_TEXT_VJUSTIFY_CENTER;
540 
541  bottomRight.y = -textHeight / 2.0;
542  bottomLeft.y = -textHeight / 2.0;
543  topLeft.y = textHeight / 2.0;
544  topRight.y = textHeight / 2.0;
545  }
546  else
547  {
548  vJustify = GR_TEXT_VJUSTIFY_BOTTOM;
549 
550  topLeft.y = textHeight;
551  topRight.y = textHeight;
552  }
553 
554  if( aData.attachmentPoint % 3 == 1 )
555  {
556  hJustify = GR_TEXT_HJUSTIFY_LEFT;
557 
558  bottomRight.x = textWidth;
559  topRight.x = textWidth;
560  }
561  else if( aData.attachmentPoint % 3 == 2 )
562  {
563  hJustify = GR_TEXT_HJUSTIFY_CENTER;
564 
565  bottomLeft.x = -textWidth / 2.0;
566  topLeft.x = -textWidth / 2.0;
567  bottomRight.x = textWidth / 2.0;
568  topRight.x = textWidth / 2.0;
569  }
570  else
571  {
572  hJustify = GR_TEXT_HJUSTIFY_RIGHT;
573 
574  bottomLeft.x = -textWidth;
575  topLeft.x = -textWidth;
576  }
577 
578 #if 0 // These setting have no mening in Pcbnew
579  if( data.alignH == 1 )
580  {
581  // Text is left to right;
582  }
583  else if( data.alignH == 3 )
584  {
585  // Text is top to bottom;
586  }
587  else
588  {
589  // use ByStyle;
590  }
591 
592  if( aData.alignV == 1 )
593  {
594  // use AtLeast;
595  }
596  else
597  {
598  // useExact;
599  }
600 #endif
601 
602  // dxf_lib imports text angle in radians (although there are no comment about that.
603  // So, for the moment, convert this angle to degrees
604  double angle_degree = aData.angle * 180/M_PI;
605  // We also need the angle in radians. so convert angle_degree to radians
606  // regardless the aData.angle unit
607  double angleInRads = angle_degree * M_PI / 180.0;
608  double cosine = cos(angleInRads);
609  double sine = sin(angleInRads);
610 
611  m_internalImporter.AddText( textpos, text, textHeight, charWidth,
612  textThickness, angle_degree, hJustify, vJustify );
613 
614  bottomLeft.x = bottomLeft.x * cosine - bottomLeft.y * sine;
615  bottomLeft.y = bottomLeft.x * sine + bottomLeft.y * cosine;
616 
617  bottomRight.x = bottomRight.x * cosine - bottomRight.y * sine;
618  bottomRight.y = bottomRight.x * sine + bottomRight.y * cosine;
619 
620  topLeft.x = topLeft.x * cosine - topLeft.y * sine;
621  topLeft.y = topLeft.x * sine + topLeft.y * cosine;
622 
623  topRight.x = topRight.x * cosine - topRight.y * sine;
624  topRight.y = topRight.x * sine + topRight.y * cosine;
625 
626  bottomLeft += textpos;
627  bottomRight += textpos;
628  topLeft += textpos;
629  topRight += textpos;
630 
631  updateImageLimits( bottomLeft );
632  updateImageLimits( bottomRight );
633  updateImageLimits( topLeft );
634  updateImageLimits( topRight );
635 
636 }
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:62
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
Creates an object representing a text.
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:69
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_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 222 of file dxf_import_plugin.cpp.

223 {
224  // Convert DXF Polylines into a series of KiCad Lines and Arcs.
225  // A Polyline (as opposed to a LWPolyline) may be a 3D line or
226  // even a 3D Mesh. The only type of Polyline which is guaranteed
227  // to import correctly is a 2D Polyline in X and Y, which is what
228  // we assume of all Polylines. The width used is the width of the Polyline.
229  // per-vertex line widths, if present, are ignored.
232  m_curr_entity.m_EntityFlag = aData.flags;
233  m_curr_entity.m_EntityType = DL_ENTITY_POLYLINE;
234 }
DXF2BRD_ENTITY_DATA m_curr_entity

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

◆ addSolid()

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

Definition at line 309 of file dxf_import_plugin.h.

309 { reportMsg( "DL_Solid not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addSpline()

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

Called for every spline.

Definition at line 160 of file dxf_import_plugin.cpp.

161 {
162  // Called when starting reading a spline
165  m_curr_entity.m_EntityFlag = aData.flags;
166  m_curr_entity.m_EntityType = DL_ENTITY_SPLINE;
167  m_curr_entity.m_SplineDegree = aData.degree;
168  m_curr_entity.m_SplineTangentStartX = aData.tangentStartX;
169  m_curr_entity.m_SplineTangentStartY = aData.tangentStartY;
170  m_curr_entity.m_SplineTangentEndX = aData.tangentEndX;
171  m_curr_entity.m_SplineTangentEndY = aData.tangentEndY;
172  m_curr_entity.m_SplineKnotsCount = aData.nKnots;
173  m_curr_entity.m_SplineControlCount = aData.nControl;
174  m_curr_entity.m_SplineFitCount = aData.nFit;
175 }
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, 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 343 of file dxf_import_plugin.cpp.

344 {
345  VECTOR2D refPoint( mapX( aData.ipx ), mapY( aData.ipy ) );
346  VECTOR2D secPoint( mapX( aData.apx ), mapY( aData.apy ) );
347 
348  if( aData.vJustification != 0 || aData.hJustification != 0 || aData.hJustification == 4 )
349  {
350  if( aData.hJustification != 3 && aData.hJustification != 5 )
351  {
352  VECTOR2D tmp = secPoint;
353  secPoint = refPoint;
354  refPoint = tmp;
355  }
356  }
357 
358  wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
359 
360  double textHeight = mapDim( aData.height );
361  // The 0.9 factor gives a better height/width ratio with our font
362  double charWidth = textHeight * 0.9;
363  double textWidth = charWidth * text.length(); // Rough approximation
364  double textThickness = textHeight/8.0; // Use a reasonable line thickness for this text
365 
366  VECTOR2D bottomLeft(0.0, 0.0);
367  VECTOR2D bottomRight(0.0, 0.0);
368  VECTOR2D topLeft(0.0, 0.0);
369  VECTOR2D topRight(0.0, 0.0);
370 
373 
374  switch( aData.vJustification )
375  {
376  case 0: //DRW_Text::VBaseLine:
377  case 1: //DRW_Text::VBottom:
378  vJustify = GR_TEXT_VJUSTIFY_BOTTOM;
379 
380  topLeft.y = textHeight;
381  topRight.y = textHeight;
382  break;
383 
384  case 2: //DRW_Text::VMiddle:
385  vJustify = GR_TEXT_VJUSTIFY_CENTER;
386 
387  bottomRight.y = -textHeight / 2.0;
388  bottomLeft.y = -textHeight / 2.0;
389  topLeft.y = textHeight / 2.0;
390  topRight.y = textHeight / 2.0;
391  break;
392 
393  case 3: //DRW_Text::VTop:
394  vJustify = GR_TEXT_VJUSTIFY_TOP;
395 
396  bottomLeft.y = -textHeight;
397  bottomRight.y = -textHeight;
398  break;
399  }
400 
401  switch( aData.hJustification )
402  {
403  case 0: //DRW_Text::HLeft:
404  case 3: //DRW_Text::HAligned: // no equivalent options in text pcb.
405  case 5: //DRW_Text::HFit: // no equivalent options in text pcb.
406  hJustify = GR_TEXT_HJUSTIFY_LEFT;
407 
408  bottomRight.x = textWidth;
409  topRight.x = textWidth;
410  break;
411 
412  case 1: //DRW_Text::HCenter:
413  case 4: //DRW_Text::HMiddle: // no equivalent options in text pcb.
414  hJustify = GR_TEXT_HJUSTIFY_CENTER;
415 
416  bottomLeft.x = -textWidth / 2.0;
417  topLeft.x = -textWidth / 2.0;
418  bottomRight.x = textWidth / 2.0;
419  topRight.x = textWidth / 2.0;
420  break;
421 
422  case 2: //DRW_Text::HRight:
423  hJustify = GR_TEXT_HJUSTIFY_RIGHT;
424 
425  bottomLeft.x = -textWidth;
426  topLeft.x = -textWidth;
427  break;
428  }
429 
430 #if 0
431  wxString sty = wxString::FromUTF8( aData.style.c_str() );
432  sty = sty.ToLower();
433 
434  if( aData.textgen == 2 )
435  {
436  // Text dir = left to right;
437  } else if( aData.textgen == 4 )
438  {
439  // Text dir = top to bottom;
440  } else
441  {
442  }
443 #endif
444 
445  // dxf_lib imports text angle in radians (although there are no comment about that.
446  // So, for the moment, convert this angle to degrees
447  double angle_degree = aData.angle * 180 / M_PI;
448  // We also need the angle in radians. so convert angle_degree to radians
449  // regardless the aData.angle unit
450  double angleInRads = angle_degree * M_PI / 180.0;
451  double cosine = cos(angleInRads);
452  double sine = sin(angleInRads);
453 
454  m_internalImporter.AddText( refPoint, text, textHeight, charWidth, textThickness,
455  angle_degree, hJustify, vJustify );
456 
457  // Calculate the boundary box and update the image limits:
458  bottomLeft.x = bottomLeft.x * cosine - bottomLeft.y * sine;
459  bottomLeft.y = bottomLeft.x * sine + bottomLeft.y * cosine;
460 
461  bottomRight.x = bottomRight.x * cosine - bottomRight.y * sine;
462  bottomRight.y = bottomRight.x * sine + bottomRight.y * cosine;
463 
464  topLeft.x = topLeft.x * cosine - topLeft.y * sine;
465  topLeft.y = topLeft.x * sine + topLeft.y * cosine;
466 
467  topRight.x = topRight.x * cosine - topRight.y * sine;
468  topRight.y = topRight.x * sine + topRight.y * cosine;
469 
470  bottomLeft += refPoint;
471  bottomRight += refPoint;
472  topLeft += refPoint;
473  topRight += refPoint;
474 
475  updateImageLimits( bottomLeft );
476  updateImageLimits( bottomRight );
477  updateImageLimits( topLeft );
478  updateImageLimits( topRight );
479 
480 }
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:62
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
Creates an object representing a text.
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:69
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_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 856 of file dxf_import_plugin.cpp.

857 {
858  // TODO
859 }

◆ addTrace()

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

Definition at line 307 of file dxf_import_plugin.h.

307 { reportMsg( "DL_Trace not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ addVertex()

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

Called for every polyline vertex.

Definition at line 237 of file dxf_import_plugin.cpp.

238 {
240  return; // Error
241 
242  double lineWidth = mapWidth( attributes.getWidth() );
243 
244  const DL_VertexData* vertex = &aData;
245 
246  if( m_curr_entity.m_EntityParseStatus == 1 ) // This is the first vertex of an entity
247  {
251  m_curr_entity.m_BulgeVertex = vertex->bulge;
253  return;
254  }
255 
256  VECTOR2D seg_end( m_xOffset + vertex->x * m_DXF2mm,
257  m_yOffset - vertex->y * m_DXF2mm );
258 
260  insertLine( m_curr_entity.m_LastCoordinate, seg_end, lineWidth );
261  else
263 
265  m_curr_entity.m_BulgeVertex = vertex->bulge;
266 }
DXF2BRD_ENTITY_DATA m_curr_entity
void insertArc(const VECTOR2D &aSegStart, const VECTOR2D &aSegEnd, double aBulge, int aWidth)
#define MIN_BULGE
#define abs(a)
Definition: auxiliary.h:84
double mapWidth(double aDxfWidth)
void insertLine(const VECTOR2D &aSegStart, const VECTOR2D &aSegEnd, int aWidth)

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

◆ endEntity()

void DXF_IMPORT_PLUGIN::endEntity ( )
overrideprivatevirtual

Definition at line 269 of file dxf_import_plugin.cpp.

270 {
271  if( m_curr_entity.m_EntityType == DL_ENTITY_POLYLINE ||
272  m_curr_entity.m_EntityType == DL_ENTITY_LWPOLYLINE )
273  {
274  // Polyline flags bit 0 indicates closed (1) or open (0) polyline
275  if( m_curr_entity.m_EntityFlag & 1 )
276  {
277  double lineWidth = mapWidth( attributes.getWidth() );
278 
281  else
283  m_curr_entity.m_BulgeVertex, lineWidth );
284  }
285  }
286 
287  if( m_curr_entity.m_EntityType == DL_ENTITY_SPLINE )
288  {
289  double lineWidth = mapWidth( attributes.getWidth() );
290  insertSpline( lineWidth );
291  }
292 
294 }
DXF2BRD_ENTITY_DATA m_curr_entity
void insertArc(const VECTOR2D &aSegStart, const VECTOR2D &aSegEnd, double aBulge, int aWidth)
#define MIN_BULGE
#define abs(a)
Definition: auxiliary.h:84
double mapWidth(double aDxfWidth)
void insertSpline(int aWidth)
void insertLine(const VECTOR2D &aSegStart, const VECTOR2D &aSegEnd, int aWidth)

References abs, 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 wxArrayString DXF_IMPORT_PLUGIN::GetFileExtensions ( ) const
inlineoverridevirtual

Returns a string array of the file extensions handled by this plugin.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 147 of file dxf_import_plugin.h.

148  {
149  wxArrayString list;
150  list.Add( "dxf" );
151  return list;
152  }

◆ 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 99 of file dxf_import_plugin.cpp.

100 {
101  return m_maxY - m_minY;
102 }

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 93 of file dxf_import_plugin.cpp.

94 {
95  return m_maxX - m_minX;
96 }

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 215 of file dxf_import_plugin.h.

216  {
217  return m_messages;
218  }

References m_messages.

◆ GetName()

const wxString DXF_IMPORT_PLUGIN::GetName ( ) const
inlineoverridevirtual

@breif Returns the plugin name.

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

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 142 of file dxf_import_plugin.h.

143  {
144  return "AutoCAD DXF";
145  }

◆ GetWildcards()

wxString GRAPHICS_IMPORT_PLUGIN::GetWildcards ( ) const
inlineinherited

Returns a list of wildcards that contains the file extensions handled by this plugin, separated with a coma.

Definition at line 66 of file graphics_import_plugin.h.

67  {
68  wxString ret;
69  bool first = true;
70 
71  for( const auto& extension : GetFileExtensions() )
72  {
73  if( first )
74  first = false;
75  else
76  ret += ", ";
77 
78  ret += "*." + extension;
79  }
80 
81  return ret;
82  }
virtual const wxArrayString GetFileExtensions() const =0
Returns a string array of the file extensions handled by this plugin.

References 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 84 of file dxf_import_plugin.cpp.

85 {
86  wxCHECK( m_importer, false );
88 
89  return true;
90 }
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 167 of file dxf_import_plugin.h.

168  {
169  m_importAsfootprintGraphicItems = aImportAsFootprintGraphic;
170  }

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 134 of file dxf_import_plugin.cpp.

135 {
136  DL_Dxf dxf_reader;
137 
138  // wxFopen takes care of unicode filenames across platforms
139  FILE* fp = wxFopen( aFile, "rt" );
140 
141  if( fp == nullptr )
142  return false;
143 
144  // Note the dxf reader takes care of switching to "C" locale before reading the file
145  // and will close the file after reading
146  bool success = dxf_reader.in( fp, this );
147 
148  return success;
149 }

Referenced by Load().

◆ insertArc()

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

Definition at line 874 of file dxf_import_plugin.cpp.

876 {
877  VECTOR2D segment_startpoint( SCALE_FACTOR( aSegStart.x ), SCALE_FACTOR( aSegStart.y ) );
878  VECTOR2D segment_endpoint( SCALE_FACTOR( aSegEnd.x ), SCALE_FACTOR( aSegEnd.y ) );
879 
880  // ensure aBulge represents an angle from +/- ( 0 .. approx 359.8 deg )
881  if( aBulge < -2000.0 )
882  aBulge = -2000.0;
883  else if( aBulge > 2000.0 )
884  aBulge = 2000.0;
885 
886  double ang = 4.0 * atan( aBulge );
887 
888  // reflect the Y values to put everything in a RHCS
889  VECTOR2D sp( aSegStart.x, -aSegStart.y );
890  VECTOR2D ep( aSegEnd.x, -aSegEnd.y );
891  // angle from end->start
892  double offAng = atan2( ep.y - sp.y, ep.x - sp.x );
893  // length of subtended segment = 1/2 distance between the 2 points
894  double d = 0.5 * sqrt( (sp.x - ep.x) * (sp.x - ep.x) + (sp.y - ep.y) * (sp.y - ep.y) );
895  // midpoint of the subtended segment
896  double xm = ( sp.x + ep.x ) * 0.5;
897  double ym = ( sp.y + ep.y ) * 0.5;
898  double radius = d / sin( ang * 0.5 );
899 
900  if( radius < 0.0 )
901  radius = -radius;
902 
903  // calculate the height of the triangle with base d and hypotenuse r
904  double dh2 = radius * radius - d * d;
905 
906  // this should only ever happen due to rounding errors when r == d
907  if( dh2 < 0.0 )
908  dh2 = 0.0;
909 
910  double h = sqrt( dh2 );
911 
912  if( ang < 0.0 )
913  offAng -= M_PI_2;
914  else
915  offAng += M_PI_2;
916 
917  // for angles greater than 180 deg we need to flip the
918  // direction in which the arc center is found relative
919  // to the midpoint of the subtended segment.
920  if( ang < -M_PI )
921  offAng += M_PI;
922  else if( ang > M_PI )
923  offAng -= M_PI;
924 
925  // center point
926  double cx = h * cos( offAng ) + xm;
927  double cy = h * sin( offAng ) + ym;
928  VECTOR2D center( SCALE_FACTOR( cx ), SCALE_FACTOR( -cy ) );
929  VECTOR2D arc_start;
930  double angle = RAD2DEG( ang );
931 
932  if( ang < 0.0 )
933  {
934  arc_start = VECTOR2D( SCALE_FACTOR( ep.x ), SCALE_FACTOR( -ep.y ) );
935  }
936  else
937  {
938  arc_start = VECTOR2D( SCALE_FACTOR( sp.x ), SCALE_FACTOR( -sp.y ) );
939  angle = -angle;
940  }
941 
942  m_internalImporter.AddArc( center, arc_start, angle, aWidth );
943 
944  VECTOR2D radiusDelta( SCALE_FACTOR( radius ), SCALE_FACTOR( radius ) );
945 
946  updateImageLimits( center + radiusDelta );
947  updateImageLimits( center - radiusDelta );
948  return;
949 }
void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth) override
Creates an object representing an arc.
double RAD2DEG(double rad)
Definition: trigo.h:200
void updateImageLimits(const VECTOR2D &aPoint)
#define SCALE_FACTOR(x)
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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, 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 862 of file dxf_import_plugin.cpp.

864 {
865  VECTOR2D origin( SCALE_FACTOR( aSegStart.x ), SCALE_FACTOR( aSegStart.y ) );
866  VECTOR2D end( SCALE_FACTOR( aSegEnd.x ), SCALE_FACTOR( aSegEnd.y ) );
867  m_internalImporter.AddLine( origin, end, aWidth );
868 
869  updateImageLimits( origin );
870  updateImageLimits( end );
871 }
void AddLine(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth) override
Creates 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 954 of file dxf_import_plugin.cpp.

955 {
956  #if 0 // Debug only
957  wxLogMessage("spl deg %d kn %d ctr %d fit %d",
962  #endif
963 
964  unsigned imax = m_curr_entity.m_SplineControlPointList.size();
965 
966  if( imax < 2 ) // malformed spline
967  return;
968 
969 #if 0 // set to 1 to approximate the spline by segments between 2 control points
970  VECTOR2D startpoint( mapX( m_curr_entity.m_SplineControlPointList[0].m_x ),
972 
973  for( unsigned int ii = 1; ii < imax; ++ii )
974  {
977 
978  if( startpoint != endpoint )
979  {
980  m_internalImporter.AddLine( startpoint, endpoint );
981 
982  updateImageLimits( startpoint );
983  updateImageLimits( endpoint );
984 
985  startpoint = endpoint;
986  }
987  }
988 #else // Use bezier curves, supported by pcbnew, to approximate the spline
989  tinyspline::BSpline dxfspline( m_curr_entity.m_SplineControlPointList.size(),
990  /* coord dim */ 2, m_curr_entity.m_SplineDegree );
991  std::vector<double> ctrlp;
992 
993  for( unsigned ii = 0; ii < imax; ++ii )
994  {
995  ctrlp.push_back( m_curr_entity.m_SplineControlPointList[ii].m_x );
996  ctrlp.push_back( m_curr_entity.m_SplineControlPointList[ii].m_y );
997  }
998 
999  dxfspline.setCtrlp( ctrlp );
1000  dxfspline.setKnots( m_curr_entity.m_SplineKnotsList );
1001  tinyspline::BSpline beziers( dxfspline.toBeziers() );
1002 
1003  std::vector<double> coords = beziers.ctrlp();
1004 
1005  // Each Bezier curve uses 4 vertices (a start point, 2 control points and a end point).
1006  // So we can have more than one Bezier curve ( there are one curve each four vertices)
1007  for( unsigned ii = 0; ii < coords.size(); ii += 8 )
1008  {
1009  VECTOR2D start( mapX( coords[ii] ), mapY( coords[ii+1] ) );
1010  VECTOR2D bezierControl1( mapX( coords[ii+2] ), mapY( coords[ii+3] ) );
1011  VECTOR2D bezierControl2( mapX( coords[ii+4] ), mapY( coords[ii+5] ) );
1012  VECTOR2D end( mapX( coords[ii+6] ), mapY( coords[ii+7] ) );
1013  m_internalImporter.AddSpline( start, bezierControl1, bezierControl2, end , aWidth );
1014  }
1015 #endif
1016 }
DXF2BRD_ENTITY_DATA m_curr_entity
void AddLine(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth) override
Creates 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
Creates an object representing an arc.
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 312 of file dxf_import_plugin.h.

312 { reportMsg( "DL_ImageDef not managed" ); }
void reportMsg(const char *aMessage)

References reportMsg().

◆ Load()

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

Loads file for import.

It is necessary to have the GRAPHICS_IMPORTER object set before.

Implements GRAPHICS_IMPORT_PLUGIN.

Definition at line 78 of file dxf_import_plugin.cpp.

79 {
80  return ImportDxfFile( aFileName );
81 }
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 117 of file dxf_import_plugin.cpp.

118 {
119  return SCALE_FACTOR( aDxfValue * m_DXF2mm );
120 }
#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 123 of file dxf_import_plugin.cpp.

124 {
125  // Always return the default line width
126 #if 0
127  // mapWidth returns the aDxfValue if aDxfWidth > 0 m_defaultThickness
128  if( aDxfWidth > 0.0 )
129  return SCALE_FACTOR( aDxfWidth * m_DXF2mm );
130 #endif
132 }
#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 105 of file dxf_import_plugin.cpp.

106 {
107  return SCALE_FACTOR( m_xOffset + ( aDxfCoordX * m_DXF2mm ) );
108 }
#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 111 of file dxf_import_plugin.cpp.

112 {
113  return SCALE_FACTOR( m_yOffset - ( aDxfCoordY * m_DXF2mm ) );
114 }
#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 152 of file dxf_import_plugin.cpp.

153 {
154  // Add message to keep trace of not handled dxf entities
155  m_messages += aMessage;
156  m_messages += '\n';
157 }

References m_messages.

Referenced by add3dFace(), addDimAlign(), addDimAngular(), addDimAngular3P(), addDimDiametric(), addDimLinear(), addDimOrdinate(), addDimRadial(), addHatch(), addHatchEdge(), addHatchLoop(), addImage(), addLeader(), addLeaderVertex(), addSolid(), addTrace(), and linkImage().

◆ SetBrdLayer()

void DXF_IMPORT_PLUGIN::SetBrdLayer ( int  aBrdLayer)
inline

Set the layer number to import dxf items.

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

Definition at line 202 of file dxf_import_plugin.h.

202 { 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 179 of file dxf_import_plugin.h.

180  {
181  m_defaultThickness = aWidth;
182  }

References m_defaultThickness.

◆ SetImporter()

void GRAPHICS_IMPORT_PLUGIN::SetImporter ( GRAPHICS_IMPORTER aImporter)
inlineinherited

Sets the receiver of the imported shapes.

Definition at line 45 of file graphics_import_plugin.h.

46  {
47  m_importer = aImporter;
48  }
GRAPHICS_IMPORTER * m_importer
Importer used to create objects representing the imported shapes.

References GRAPHICS_IMPORT_PLUGIN::m_importer.

◆ 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 192 of file dxf_import_plugin.h.

193  {
194  m_xOffset = aOffsetX;
195  m_yOffset = aOffsetY;
196  }

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 258 of file dxf_import_plugin.h.

258 {}

◆ 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 639 of file dxf_import_plugin.cpp.

640 {
641  // Called for every int variable in the DXF file (e.g. "$INSUNITS").
642 
643  if( key == "$DWGCODEPAGE" )
644  {
645  m_codePage = value;
646  return;
647  }
648 
649  if( key == "$INSUNITS" ) // Drawing units
650  {
651  switch( value )
652  {
653  case 1: // inches
654  m_DXF2mm = 25.4;
655  break;
656 
657  case 2: // feet
658  m_DXF2mm = 304.8;
659  break;
660 
661  case 4: // mm
662  m_DXF2mm = 1.0;
663  break;
664 
665  case 5: // centimeters
666  m_DXF2mm = 10.0;
667  break;
668 
669  case 6: // meters
670  m_DXF2mm = 1000.0;
671  break;
672 
673  case 8: // microinches
674  m_DXF2mm = 2.54e-5;
675  break;
676 
677  case 9: // mils
678  m_DXF2mm = 0.0254;
679  break;
680 
681  case 10: // yards
682  m_DXF2mm = 914.4;
683  break;
684 
685  case 11: // Angstroms
686  m_DXF2mm = 1.0e-7;
687  break;
688 
689  case 12: // nanometers
690  m_DXF2mm = 1.0e-6;
691  break;
692 
693  case 13: // micrometers
694  m_DXF2mm = 1.0e-3;
695  break;
696 
697  case 14: // decimeters
698  m_DXF2mm = 100.0;
699  break;
700 
701  default:
702  // use the default of 1.0 for:
703  // 0: Unspecified Units
704  // 3: miles
705  // 7: kilometers
706  // 15: decameters
707  // 16: hectometers
708  // 17: gigameters
709  // 18: AU
710  // 19: lightyears
711  // 20: parsecs
712  m_DXF2mm = 1.0;
713  break;
714  }
715 
716  return;
717  }
718 }

References m_codePage, and m_DXF2mm.

◆ 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 721 of file dxf_import_plugin.cpp.

723 {
724  // Called for every string variable in the DXF file (e.g. "$ACADVER").
725 }

◆ toDxfString()

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

Converts a native unicode string into a DXF encoded string.

DXF endoding includes the following special sequences:

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

Definition at line 728 of file dxf_import_plugin.cpp.

729 {
730  wxString res;
731  int j = 0;
732 
733  for( unsigned i = 0; i<aStr.length(); ++i )
734  {
735  int c = aStr[i];
736 
737  if( c > 175 || c < 11 )
738  {
739  res.append( aStr.Mid( j, i - j ) );
740  j = i;
741 
742  switch( c )
743  {
744  case 0x0A:
745  res += wxT( "\\P" );
746  break;
747 
748  // diameter:
749 #ifdef __WINDOWS_
750  // windows, as always, is special.
751  case 0x00D8:
752 #else
753  case 0x2205:
754 #endif
755  res += wxT( "%%C" );
756  break;
757 
758  // degree:
759  case 0x00B0:
760  res += wxT( "%%D" );
761  break;
762 
763  // plus/minus
764  case 0x00B1:
765  res += wxT( "%%P" );
766  break;
767 
768  default:
769  j--;
770  break;
771  }
772 
773  j++;
774  }
775  }
776 
777  res.append( aStr.Mid( j ) );
778  return res;
779 }
size_t i
Definition: json11.cpp:597

References i.

◆ toNativeString()

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

Converts a DXF encoded string into a native Unicode string.

Definition at line 782 of file dxf_import_plugin.cpp.

783 {
784  wxString res;
785 
786  // Ignore font tags:
787  int j = 0;
788 
789  for( unsigned i = 0; i < aData.length(); ++i )
790  {
791  if( aData[ i ] == 0x7B ) // is '{' ?
792  {
793  if( aData[ i + 1 ] == 0x5c && aData[ i + 2 ] == 0x66 ) // is "\f" ?
794  {
795  // found font tag, append parsed part
796  res.append( aData.Mid( j, i - j ) );
797 
798  // skip to ';'
799  for( unsigned k = i + 3; k < aData.length(); ++k )
800  {
801  if( aData[ k ] == 0x3B )
802  {
803  i = j = ++k;
804  break;
805  }
806  }
807 
808  // add to '}'
809  for( unsigned k = i; k < aData.length(); ++k )
810  {
811  if( aData[ k ] == 0x7D )
812  {
813  res.append( aData.Mid( i, k - i ) );
814  i = j = ++k;
815  break;
816  }
817  }
818  }
819  }
820  }
821 
822  res.append( aData.Mid( j ) );
823 
824 #if 1
825  wxRegEx regexp;
826  // Line feed:
827  regexp.Compile( wxT( "\\\\P" ) );
828  regexp.Replace( &res, wxT( "\n" ) );
829 
830  // Space:
831  regexp.Compile( wxT( "\\\\~" ) );
832  regexp.Replace( &res, wxT( " " ) );
833 
834  // diameter:
835  regexp.Compile( wxT( "%%[cC]" ) );
836 #ifdef __WINDOWS__
837  // windows, as always, is special.
838  regexp.Replace( &res, wxChar( 0xD8 ) );
839 #else
840  // Empty_set, diameter is 0x2300
841  regexp.Replace( &res, wxChar( 0x2205 ) );
842 #endif
843 
844  // degree:
845  regexp.Compile( wxT( "%%[dD]" ) );
846  regexp.Replace( &res, wxChar( 0x00B0 ) );
847  // plus/minus
848  regexp.Compile( wxT( "%%[pP]" ) );
849  regexp.Replace( &res, wxChar( 0x00B1 ) );
850 #endif
851 
852  return res;
853 }
size_t i
Definition: json11.cpp:597

References i.

Referenced by addMText(), and addText().

◆ updateImageLimits()

void DXF_IMPORT_PLUGIN::updateImageLimits ( const VECTOR2D aPoint)

Definition at line 1019 of file dxf_import_plugin.cpp.

1020 {
1021  m_minX = std::min( aPoint.x, m_minX );
1022  m_maxX = std::max( aPoint.x, m_maxX );
1023 
1024  m_minY = std::min( aPoint.y, m_minY );
1025  m_maxY = std::max( aPoint.y, m_maxY );
1026 }
#define max(a, b)
Definition: auxiliary.h:86
#define min(a, b)
Definition: auxiliary.h:85

References m_maxX, m_maxY, m_minX, m_minY, max, min, 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 123 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 125 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 121 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 126 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 122 of file graphics_import_plugin.h.

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

◆ m_internalImporter

GRAPHICS_IMPORTER_BUFFER DXF_IMPORT_PLUGIN::m_internalImporter
private

◆ m_maxX

double DXF_IMPORT_PLUGIN::m_maxX
private

Definition at line 132 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 133 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 128 of file dxf_import_plugin.h.

Referenced by GetMessages(), and reportMsg().

◆ m_minX

double DXF_IMPORT_PLUGIN::m_minX
private

Definition at line 132 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 133 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 124 of file dxf_import_plugin.h.

Referenced by DXF_IMPORT_PLUGIN().

◆ m_xOffset

double DXF_IMPORT_PLUGIN::m_xOffset
private

Definition at line 119 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 120 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: