KiCad PCB EDA Suite
DXF2BRD_CONVERTER Class Reference

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

#include <dxf2brd_items.h>

Inheritance diagram for DXF2BRD_CONVERTER:

Public Member Functions

 DXF2BRD_CONVERTER ()
 
 ~DXF2BRD_CONVERTER ()
 
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::list< BOARD_ITEM * > & GetItemsList () const
 
std::string & GetMessages ()
 

Private Member Functions

void reportMsg (const char *aMessage)
 
int mapX (double aDxfCoordX)
 
int mapY (double aDxfCoordY)
 
int mapDim (double aDxfValue)
 
int mapWidth (double aDxfWidth)
 
void insertLine (const wxRealPoint &aSegStart, const wxRealPoint &aSegEnd, int aWidth)
 
void insertArc (const wxRealPoint &aSegStart, const wxRealPoint &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

std::list< BOARD_ITEM * > m_newItemsList
 
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
 

Detailed Description

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

It depends on the dxflib library.

Definition at line 112 of file dxf2brd_items.h.

Constructor & Destructor Documentation

DXF2BRD_CONVERTER::DXF2BRD_CONVERTER ( )

Definition at line 55 of file dxf2brd_items.cpp.

References Dwgs_User, m_brdLayer, m_defaultThickness, m_DXF2mm, m_importAsfootprintGraphicItems, m_version, m_xOffset, and m_yOffset.

55  : DL_CreationAdapter()
56 {
57  m_xOffset = 0.0; // X coord offset for conversion (in mm)
58  m_yOffset = 0.0; // Y coord offset for conversion (in mm)
59  m_DXF2mm = 1.0; // The scale factor to convert DXF units to mm
60  m_version = 0; // the dxf version, not yet used
61  m_defaultThickness = 0.2; // default thickness (in mm)
62  m_brdLayer = Dwgs_User; // The default import layer
64 }
bool m_importAsfootprintGraphicItems
DXF2BRD_CONVERTER::~DXF2BRD_CONVERTER ( )

Definition at line 67 of file dxf2brd_items.cpp.

68 {
69 }

Member Function Documentation

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

Definition at line 284 of file dxf2brd_items.h.

284 { reportMsg( "DL_3dFace not managed" ); }
void reportMsg(const char *aMessage)
void DXF2BRD_CONVERTER::addArc ( const DL_ArcData &  aData)
overrideprivatevirtual

Definition at line 285 of file dxf2brd_items.cpp.

References PNS::angle(), DXF2ANGLEUI, m_brdLayer, m_importAsfootprintGraphicItems, m_newItemsList, mapWidth(), mapX(), mapY(), RotatePoint(), S_ARC, DRAWSEGMENT::SetAngle(), DRAWSEGMENT::SetArcStart(), DRAWSEGMENT::SetCenter(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetShape(), DRAWSEGMENT::SetWidth(), and ToLAYER_ID().

286 {
288  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
289 
290  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
291  segm->SetShape( S_ARC );
292 
293  // Init arc centre:
294  wxPoint center( mapX( aData.cx ), mapY( aData.cy ) );
295  segm->SetCenter( center );
296 
297  // Init arc start point
298  double arcStartx = aData.radius;
299  double arcStarty = 0;
300 
301  // aData.anglex is in degrees. Our internal units are 0.1 degree
302  // so convert DXF angles to our units
303  #define DXF2ANGLEUI 10
304  double startangle = aData.angle1 * DXF2ANGLEUI;
305  double endangle = aData.angle2 * DXF2ANGLEUI;
306 
307  RotatePoint( &arcStartx, &arcStarty, -startangle );
308  wxPoint arcStart( mapX( arcStartx + aData.cx ),
309  mapY( arcStarty + aData.cy ) );
310  segm->SetArcStart( arcStart );
311 
312  // calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew)
313  double angle = -( endangle - startangle );
314 
315  if( angle > 0.0 )
316  angle -= 3600.0;
317 
318  segm->SetAngle( angle );
319 
320  segm->SetWidth( mapWidth( attributes.getWidth() ) );
321  m_newItemsList.push_back( segm );
322 }
bool m_importAsfootprintGraphicItems
#define DXF2ANGLEUI
void SetShape(STROKE_T aShape)
void SetArcStart(const wxPoint &aArcStartPoint)
Initialize the start arc point.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
Arcs (with rounded ends)
int mapX(double aDxfCoordX)
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
int mapWidth(double aDxfWidth)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
void SetWidth(int aWidth)
void DXF2BRD_CONVERTER::addCircle ( const DL_CircleData &  aData)
overrideprivatevirtual

Definition at line 266 of file dxf2brd_items.cpp.

References m_brdLayer, m_importAsfootprintGraphicItems, m_newItemsList, mapWidth(), mapX(), mapY(), S_CIRCLE, DRAWSEGMENT::SetArcStart(), DRAWSEGMENT::SetCenter(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetShape(), DRAWSEGMENT::SetWidth(), and ToLAYER_ID().

267 {
269  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
270 
271  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
272  segm->SetShape( S_CIRCLE );
273  wxPoint center( mapX( aData.cx ), mapY( aData.cy ) );
274  segm->SetCenter( center );
275  wxPoint circle_start( mapX( aData.cx + aData.radius ), mapY( aData.cy ) );
276  segm->SetArcStart( circle_start );
277  segm->SetWidth( mapWidth( attributes.getWidth() ) );
278  m_newItemsList.push_back( segm );
279 }
bool m_importAsfootprintGraphicItems
void SetShape(STROKE_T aShape)
void SetArcStart(const wxPoint &aArcStartPoint)
Initialize the start arc point.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
int mapX(double aDxfCoordX)
int mapWidth(double aDxfWidth)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
void SetWidth(int aWidth)
void DXF2BRD_CONVERTER::addControlPoint ( const DL_ControlPointData &  aData)
overrideprivatevirtual

Called for every spline control point.

Definition at line 143 of file dxf2brd_items.cpp.

References m_curr_entity, and DXF2BRD_ENTITY_DATA::m_SplineControlPointList.

144 {
145  // Called for every spline control point, when reading a spline entity
146  m_curr_entity.m_SplineControlPointList.push_back( SPLINE_CTRL_POINT( aData.x , aData.y, aData.w ) );
147 }
A helper class to store a spline control point (in X,Y plane only)
Definition: dxf2brd_items.h:40
std::vector< SPLINE_CTRL_POINT > m_SplineControlPointList
Definition: dxf2brd_items.h:81
DXF2BRD_ENTITY_DATA m_curr_entity
virtual void DXF2BRD_CONVERTER::addDimAlign ( const DL_DimensionData &  ,
const DL_DimAlignedData &   
)
inlineoverrideprivatevirtual

Definition at line 264 of file dxf2brd_items.h.

265  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)
virtual void DXF2BRD_CONVERTER::addDimAngular ( const DL_DimensionData &  ,
const DL_DimAngularData &   
)
inlineoverrideprivatevirtual

Definition at line 272 of file dxf2brd_items.h.

273  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)
virtual void DXF2BRD_CONVERTER::addDimAngular3P ( const DL_DimensionData &  ,
const DL_DimAngular3PData &   
)
inlineoverrideprivatevirtual

Definition at line 274 of file dxf2brd_items.h.

275  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)
virtual void DXF2BRD_CONVERTER::addDimDiametric ( const DL_DimensionData &  ,
const DL_DimDiametricData &   
)
inlineoverrideprivatevirtual

Definition at line 270 of file dxf2brd_items.h.

271  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)
virtual void DXF2BRD_CONVERTER::addDimLinear ( const DL_DimensionData &  ,
const DL_DimLinearData &   
)
inlineoverrideprivatevirtual

Definition at line 266 of file dxf2brd_items.h.

267  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)
virtual void DXF2BRD_CONVERTER::addDimOrdinate ( const DL_DimensionData &  ,
const DL_DimOrdinateData &   
)
inlineoverrideprivatevirtual

Definition at line 276 of file dxf2brd_items.h.

277  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)
virtual void DXF2BRD_CONVERTER::addDimRadial ( const DL_DimensionData &  ,
const DL_DimRadialData &   
)
inlineoverrideprivatevirtual

Definition at line 268 of file dxf2brd_items.h.

269  { reportMsg( "DL_Dimension not managed" ); }
void reportMsg(const char *aMessage)
void DXF2BRD_CONVERTER::addFitPoint ( const DL_FitPointData &  aData)
overrideprivatevirtual

Called for every spline fit point.

Definition at line 149 of file dxf2brd_items.cpp.

References m_curr_entity, and DXF2BRD_ENTITY_DATA::m_SplineFitPointList.

150 {
151  // Called for every spline fit point, when reading a spline entity
152  // we store only the X,Y coord values in a wxRealPoint
153  m_curr_entity.m_SplineFitPointList.push_back( wxRealPoint( aData.x, aData.y ) );
154 }
std::vector< wxRealPoint > m_SplineFitPointList
Definition: dxf2brd_items.h:83
DXF2BRD_ENTITY_DATA m_curr_entity
virtual void DXF2BRD_CONVERTER::addHatch ( const DL_HatchData &  )
inlineoverrideprivatevirtual

Definition at line 281 of file dxf2brd_items.h.

281 { reportMsg( "DL_Hatch not managed" ); }
void reportMsg(const char *aMessage)
virtual void DXF2BRD_CONVERTER::addHatchEdge ( const DL_HatchEdgeData &  )
inlineoverrideprivatevirtual

Definition at line 290 of file dxf2brd_items.h.

290 { reportMsg( "DL_HatchEdge not managed" ); }
void reportMsg(const char *aMessage)
virtual void DXF2BRD_CONVERTER::addHatchLoop ( const DL_HatchLoopData &  )
inlineoverrideprivatevirtual

Definition at line 289 of file dxf2brd_items.h.

289 { reportMsg( "DL_HatchLoop not managed" ); }
void reportMsg(const char *aMessage)
virtual void DXF2BRD_CONVERTER::addImage ( const DL_ImageData &  )
inlineoverrideprivatevirtual

Definition at line 287 of file dxf2brd_items.h.

287 { reportMsg( "DL_ImageDa not managed" ); }
void reportMsg(const char *aMessage)
void DXF2BRD_CONVERTER::addKnot ( const DL_KnotData &  aData)
overrideprivatevirtual

Called for every spline knot value.

Definition at line 157 of file dxf2brd_items.cpp.

References m_curr_entity, and DXF2BRD_ENTITY_DATA::m_SplineKnotsList.

158 {
159  // Called for every spline knot value, when reading a spline entity
160  m_curr_entity.m_SplineKnotsList.push_back( aData.k );
161 }
std::vector< double > m_SplineKnotsList
Definition: dxf2brd_items.h:79
DXF2BRD_ENTITY_DATA m_curr_entity
void DXF2BRD_CONVERTER::addLayer ( const DL_LayerData &  aData)
overrideprivatevirtual

Definition at line 164 of file dxf2brd_items.cpp.

References name.

165 {
166  // Not yet useful in Pcbnew.
167 #if 0
168  wxString name = wxString::FromUTF8( aData.name.c_str() );
169  wxLogMessage( name );
170 #endif
171 }
const char * name
Definition: DXF_plotter.cpp:61
virtual void DXF2BRD_CONVERTER::addLeader ( const DL_LeaderData &  )
inlineoverrideprivatevirtual

Definition at line 278 of file dxf2brd_items.h.

278 { reportMsg( "DL_Leader not managed" ); }
void reportMsg(const char *aMessage)
virtual void DXF2BRD_CONVERTER::addLeaderVertex ( const DL_LeaderVertexData &  )
inlineoverrideprivatevirtual

Definition at line 279 of file dxf2brd_items.h.

279 { reportMsg( "DL_LeaderVertex not managed" ); }
void reportMsg(const char *aMessage)
void DXF2BRD_CONVERTER::addLine ( const DL_LineData &  aData)
overrideprivatevirtual

Definition at line 174 of file dxf2brd_items.cpp.

References m_brdLayer, m_importAsfootprintGraphicItems, m_newItemsList, mapWidth(), mapX(), mapY(), DRAWSEGMENT::SetEnd(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetStart(), DRAWSEGMENT::SetWidth(), and ToLAYER_ID().

175 {
177  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
178 
179  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
180  wxPoint start( mapX( aData.x1 ), mapY( aData.y1 ) );
181  segm->SetStart( start );
182  wxPoint end( mapX( aData.x2 ), mapY( aData.y2 ) );
183  segm->SetEnd( end );
184  segm->SetWidth( mapWidth( attributes.getWidth() ) );
185  m_newItemsList.push_back( segm );
186 }
bool m_importAsfootprintGraphicItems
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
int mapX(double aDxfCoordX)
void SetStart(const wxPoint &aStart)
void SetEnd(const wxPoint &aEnd)
int mapWidth(double aDxfWidth)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
void SetWidth(int aWidth)
void DXF2BRD_CONVERTER::addMText ( const DL_MTextData &  aData)
overrideprivatevirtual

Definition at line 437 of file dxf2brd_items.cpp.

References DEFAULT_TEXT_WIDTH, 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_brdLayer, m_importAsfootprintGraphicItems, m_newItemsList, mapDim(), mapWidth(), mapX(), mapY(), EDA_TEXT::SetHorizJustify(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetText(), EDA_TEXT::SetTextAngle(), EDA_TEXT::SetTextHeight(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextWidth(), EDA_TEXT::SetThickness(), EDA_TEXT::SetVertJustify(), ToLAYER_ID(), and toNativeString().

438 {
439  wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
440  wxString attrib, tmp;
441 
442  /* Some texts start by '\' and have formating chars (font name, font option...)
443  * ending with ';'
444  * Here are some mtext formatting codes:
445  * Format code Purpose
446  * \0...\o Turns overline on and off
447  * \L...\l Turns underline on and off
448  * \~ Inserts a nonbreaking space
449  \\ Inserts a backslash
450  \\\{...\} Inserts an opening and closing brace
451  \\ \File name; Changes to the specified font file
452  \\ \Hvalue; Changes to the text height specified in drawing units
453  \\ \Hvaluex; Changes the text height to a multiple of the current text height
454  \\ \S...^...; Stacks the subsequent text at the \, #, or ^ symbol
455  \\ \Tvalue; Adjusts the space between characters, from.75 to 4 times
456  \\ \Qangle; Changes obliquing angle
457  \\ \Wvalue; Changes width factor to produce wide text
458  \\ \A Sets the alignment value; valid values: 0, 1, 2 (bottom, center, top) while( text.StartsWith( wxT("\\") ) )
459  */
460  while( text.StartsWith( wxT( "\\" ) ) )
461  {
462  attrib << text.BeforeFirst( ';' );
463  tmp = text.AfterFirst( ';' );
464  text = tmp;
465  }
466 
467  BOARD_ITEM* brdItem;
468  EDA_TEXT* textItem;
469 
471  {
472  TEXTE_MODULE* modText = new TEXTE_MODULE( NULL );
473  brdItem = static_cast< BOARD_ITEM* >( modText );
474  textItem = static_cast< EDA_TEXT* >( modText );
475  }
476  else
477  {
478  TEXTE_PCB* pcbText = new TEXTE_PCB( NULL );
479  brdItem = static_cast< BOARD_ITEM* >( pcbText );
480  textItem = static_cast< EDA_TEXT* >( pcbText );
481  }
482 
483  brdItem->SetLayer( ToLAYER_ID( m_brdLayer ) );
484  wxPoint textpos( mapX( aData.ipx ), mapY( aData.ipy ) );
485 
486  textItem->SetTextPos( textpos );
487  textItem->SetTextAngle( aData.angle * 10 );
488 
489  // The 0.8 factor gives a better height/width ratio with our font
490  textItem->SetTextWidth( mapDim( aData.height * 0.8 ) );
491  textItem->SetTextHeight( mapDim( aData.height ) );
492  textItem->SetThickness( mapWidth( aData.height * DEFAULT_TEXT_WIDTH ) ); // Gives a reasonable text thickness
493  textItem->SetText( text );
494 
495  // Initialize text justifications:
496  if( aData.attachmentPoint <= 3 )
497  {
499  }
500  else if( aData.attachmentPoint <= 6 )
501  {
503  }
504  else
505  {
507  }
508 
509  if( aData.attachmentPoint % 3 == 1 )
510  {
512  }
513  else if( aData.attachmentPoint % 3 == 2 )
514  {
516  }
517  else
518  {
520  }
521 
522 #if 0 // These setting have no meaning in Pcbnew
523  if( data.alignH == 1 )
524  {
525  // Text is left to right;
526  }
527  else if( data.alignH == 3 )
528  {
529  // Text is top to bottom;
530  }
531  else
532  {
533  // use ByStyle;
534  }
535 
536  if( aData.alignV == 1 )
537  {
538  // use AtLeast;
539  }
540  else
541  {
542  // useExact;
543  }
544 #endif
545 
546  m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) );
547 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:169
bool m_importAsfootprintGraphicItems
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:236
static wxString toNativeString(const wxString &aData)
Converts a DXF encoded string into a native Unicode string.
int mapDim(double aDxfValue)
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:127
#define DEFAULT_TEXT_WIDTH
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:207
int mapX(double aDxfCoordX)
void SetTextWidth(int aWidth)
Definition: eda_text.h:230
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:206
void SetTextHeight(int aHeight)
Definition: eda_text.h:233
int mapWidth(double aDxfWidth)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:161
virtual void SetText(const wxString &aText)
Definition: eda_text.h:154
void DXF2BRD_CONVERTER::addPolyline ( const DL_PolylineData &  aData)
overrideprivatevirtual

Definition at line 189 of file dxf2brd_items.cpp.

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

190 {
191  // Convert DXF Polylines into a series of KiCad Lines and Arcs.
192  // A Polyline (as opposed to a LWPolyline) may be a 3D line or
193  // even a 3D Mesh. The only type of Polyline which is guaranteed
194  // to import correctly is a 2D Polyline in X and Y, which is what
195  // we assume of all Polylines. The width used is the width of the Polyline.
196  // per-vertex line widths, if present, are ignored.
197 
200  m_curr_entity.m_EntityFlag = aData.flags;
201  m_curr_entity.m_EntityType = DL_ENTITY_POLYLINE;
202 }
DXF2BRD_ENTITY_DATA m_curr_entity
virtual void DXF2BRD_CONVERTER::addSolid ( const DL_SolidData &  )
inlineoverrideprivatevirtual

Definition at line 285 of file dxf2brd_items.h.

285 { reportMsg( "DL_Solid not managed" ); }
void reportMsg(const char *aMessage)
void DXF2BRD_CONVERTER::addSpline ( const DL_SplineData &  aData)
overrideprivatevirtual

Called for every spline.

Definition at line 125 of file dxf2brd_items.cpp.

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.

126 {
127  // Called when starting reading a spline
130  m_curr_entity.m_EntityFlag = aData.flags;
131  m_curr_entity.m_EntityType = DL_ENTITY_SPLINE;
132  m_curr_entity.m_SplineDegree = aData.degree;
133  m_curr_entity.m_SplineTangentStartX = aData.tangentStartX;
134  m_curr_entity.m_SplineTangentStartY = aData.tangentStartY;
135  m_curr_entity.m_SplineTangentEndX = aData.tangentEndX;
136  m_curr_entity.m_SplineTangentEndY = aData.tangentEndY;
137  m_curr_entity.m_SplineKnotsCount = aData.nKnots;
138  m_curr_entity.m_SplineControlCount = aData.nControl;
139  m_curr_entity.m_SplineFitCount = aData.nFit;
140 }
unsigned int m_SplineFitCount
Definition: dxf2brd_items.h:72
unsigned int m_SplineControlCount
Definition: dxf2brd_items.h:71
unsigned int m_SplineKnotsCount
Definition: dxf2brd_items.h:70
unsigned int m_SplineDegree
Definition: dxf2brd_items.h:69
double m_SplineTangentStartX
Definition: dxf2brd_items.h:73
double m_SplineTangentStartY
Definition: dxf2brd_items.h:74
DXF2BRD_ENTITY_DATA m_curr_entity
void DXF2BRD_CONVERTER::addText ( const DL_TextData &  aData)
overrideprivatevirtual

Definition at line 325 of file dxf2brd_items.cpp.

References DEFAULT_TEXT_WIDTH, 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_brdLayer, m_importAsfootprintGraphicItems, m_newItemsList, mapDim(), mapWidth(), mapX(), mapY(), EDA_TEXT::SetHorizJustify(), BOARD_ITEM::SetLayer(), EDA_TEXT::SetText(), EDA_TEXT::SetTextAngle(), EDA_TEXT::SetTextHeight(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextWidth(), EDA_TEXT::SetThickness(), EDA_TEXT::SetVertJustify(), ToLAYER_ID(), and toNativeString().

326 {
327  BOARD_ITEM* brdItem;
328  EDA_TEXT* textItem;
329 
331  {
332  TEXTE_MODULE* modText = new TEXTE_MODULE( NULL );
333  brdItem = static_cast< BOARD_ITEM* >( modText );
334  textItem = static_cast< EDA_TEXT* >( modText );
335  }
336  else
337  {
338  TEXTE_PCB* pcbText = new TEXTE_PCB( NULL );
339  brdItem = static_cast< BOARD_ITEM* >( pcbText );
340  textItem = static_cast< EDA_TEXT* >( pcbText );
341  }
342 
343  brdItem->SetLayer( ToLAYER_ID( m_brdLayer ) );
344 
345  wxPoint refPoint( mapX( aData.ipx ), mapY( aData.ipy ) );
346  wxPoint 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  wxPoint tmp = secPoint;
353  secPoint = refPoint;
354  refPoint = tmp;
355  }
356  }
357 
358  switch( aData.vJustification )
359  {
360  case 0: //DRW_Text::VBaseLine:
362  break;
363 
364  case 1: //DRW_Text::VBottom:
366  break;
367 
368  case 2: //DRW_Text::VMiddle:
370  break;
371 
372  case 3: //DRW_Text::VTop:
374  break;
375  }
376 
377  switch( aData.hJustification )
378  {
379  case 0: //DRW_Text::HLeft:
381  break;
382 
383  case 1: //DRW_Text::HCenter:
385  break;
386 
387  case 2: //DRW_Text::HRight:
389  break;
390 
391  case 3: //DRW_Text::HAligned:
392  // no equivalent options in text pcb.
394  break;
395 
396  case 4: //DRW_Text::HMiddle:
397  // no equivalent options in text pcb.
399  break;
400 
401  case 5: //DRW_Text::HFit:
402  // no equivalent options in text pcb.
404  break;
405  }
406 
407 #if 0
408  wxString sty = wxString::FromUTF8( aData.style.c_str() );
409  sty = sty.ToLower();
410 
411  if( aData.textgen == 2 )
412  {
413  // Text dir = left to right;
414  } else if( aData.textgen == 4 )
415  {
416  // Text dir = top to bottom;
417  } else
418  {
419  }
420 #endif
421 
422  wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
423 
424  textItem->SetTextPos( refPoint );
425  textItem->SetTextAngle( aData.angle * 10 );
426 
427  // The 0.8 factor gives a better height/width ratio with our font
428  textItem->SetTextWidth( mapDim( aData.height * 0.8 ) );
429  textItem->SetTextHeight( mapDim( aData.height ) );
430  textItem->SetThickness( mapWidth( aData.height * DEFAULT_TEXT_WIDTH ) ); // Gives a reasonable text thickness
431  textItem->SetText( text );
432 
433  m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) );
434 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:169
bool m_importAsfootprintGraphicItems
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:236
static wxString toNativeString(const wxString &aData)
Converts a DXF encoded string into a native Unicode string.
int mapDim(double aDxfValue)
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:127
#define DEFAULT_TEXT_WIDTH
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:207
int mapX(double aDxfCoordX)
void SetTextWidth(int aWidth)
Definition: eda_text.h:230
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:206
void SetTextHeight(int aHeight)
Definition: eda_text.h:233
int mapWidth(double aDxfWidth)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:161
virtual void SetText(const wxString &aText)
Definition: eda_text.h:154
void DXF2BRD_CONVERTER::addTextStyle ( const DL_StyleData &  aData)
overrideprivatevirtual

Definition at line 767 of file dxf2brd_items.cpp.

768 {
769  // TODO
770 }
virtual void DXF2BRD_CONVERTER::addTrace ( const DL_TraceData &  )
inlineoverrideprivatevirtual

Definition at line 283 of file dxf2brd_items.h.

283 { reportMsg( "DL_Trace not managed" ); }
void reportMsg(const char *aMessage)
void DXF2BRD_CONVERTER::addVertex ( const DL_VertexData &  aData)
overrideprivatevirtual

Called for every polyline vertex.

Definition at line 205 of file dxf2brd_items.cpp.

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(), and MIN_BULGE.

206 {
208  return; // Error
209 
210  int lineWidth = mapWidth( attributes.getWidth() );
211 
212  const DL_VertexData* vertex = &aData;
213 
214  if( m_curr_entity.m_EntityParseStatus == 1 ) // This is the first vertex of an entity
215  {
219  m_curr_entity.m_BulgeVertex = vertex->bulge;
221  return;
222  }
223 
224 
225  wxRealPoint seg_end( m_xOffset + vertex->x * m_DXF2mm,
226  m_yOffset - vertex->y * m_DXF2mm );
227 
229  insertLine( m_curr_entity.m_LastCoordinate, seg_end, lineWidth );
230  else
232 
234  m_curr_entity.m_BulgeVertex = vertex->bulge;
235 }
wxRealPoint m_PolylineStart
Definition: dxf2brd_items.h:65
wxRealPoint m_LastCoordinate
Definition: dxf2brd_items.h:64
void insertArc(const wxRealPoint &aSegStart, const wxRealPoint &aSegEnd, double aBulge, int aWidth)
#define abs(a)
Definition: auxiliary.h:84
#define MIN_BULGE
void insertLine(const wxRealPoint &aSegStart, const wxRealPoint &aSegEnd, int aWidth)
int mapWidth(double aDxfWidth)
DXF2BRD_ENTITY_DATA m_curr_entity
void DXF2BRD_CONVERTER::endEntity ( )
overrideprivatevirtual

Definition at line 238 of file dxf2brd_items.cpp.

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.

239 {
240  if( m_curr_entity.m_EntityType == DL_ENTITY_POLYLINE ||
241  m_curr_entity.m_EntityType == DL_ENTITY_LWPOLYLINE )
242  {
243  // Polyline flags bit 0 indicates closed (1) or open (0) polyline
244  if( m_curr_entity.m_EntityFlag & 1 )
245  {
246  int lineWidth = mapWidth( attributes.getWidth() );
247 
250  else
252  m_curr_entity.m_BulgeVertex, lineWidth );
253  }
254  }
255 
256  if( m_curr_entity.m_EntityType == DL_ENTITY_SPLINE )
257  {
258  int lineWidth = mapWidth( attributes.getWidth() );
259  insertSpline( lineWidth );
260  }
261 
263 }
wxRealPoint m_PolylineStart
Definition: dxf2brd_items.h:65
wxRealPoint m_LastCoordinate
Definition: dxf2brd_items.h:64
void insertSpline(int aWidth)
void insertArc(const wxRealPoint &aSegStart, const wxRealPoint &aSegEnd, double aBulge, int aWidth)
#define abs(a)
Definition: auxiliary.h:84
#define MIN_BULGE
void insertLine(const wxRealPoint &aSegStart, const wxRealPoint &aSegEnd, int aWidth)
int mapWidth(double aDxfWidth)
DXF2BRD_ENTITY_DATA m_curr_entity
const std::list<BOARD_ITEM*>& DXF2BRD_CONVERTER::GetItemsList ( ) const
inline
Returns
the list of new BOARD_ITEM

Definition at line 187 of file dxf2brd_items.h.

Referenced by DIALOG_DXF_IMPORT::GetImportedItems().

188  {
189  return m_newItemsList;
190  }
std::list< BOARD_ITEM * > m_newItemsList
std::string& DXF2BRD_CONVERTER::GetMessages ( )
inline
Returns
the list of messages in one string. Each message ends by '
'

Definition at line 195 of file dxf2brd_items.h.

References DSN::mapX(), and DSN::mapY().

Referenced by DIALOG_DXF_IMPORT::TransferDataFromWindow().

195 { return m_messages; }
std::string m_messages
void DXF2BRD_CONVERTER::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 139 of file dxf2brd_items.h.

Referenced by DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT().

140  {
141  m_importAsfootprintGraphicItems = aImportAsFootprintGraphic;
142  }
bool m_importAsfootprintGraphicItems
bool DXF2BRD_CONVERTER::ImportDxfFile ( const wxString &  aFile)

Implementation of the method used for communicate with this filter.

Parameters
aFile= the full filename.

Definition at line 102 of file dxf2brd_items.cpp.

References TO_UTF8.

Referenced by DIALOG_DXF_IMPORT::TransferDataFromWindow().

103 {
104  LOCALE_IO locale;
105 
106  DL_Dxf dxf_reader;
107  std::string filename = TO_UTF8( aFile );
108  bool success = true;
109 
110  if( !dxf_reader.in( filename, this ) ) // if file open failed
111  success = false;
112 
113  return success;
114 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:179
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
void DXF2BRD_CONVERTER::insertArc ( const wxRealPoint &  aSegStart,
const wxRealPoint &  aSegEnd,
double  aBulge,
int  aWidth 
)
private

Definition at line 790 of file dxf2brd_items.cpp.

References m_brdLayer, m_importAsfootprintGraphicItems, m_newItemsList, RAD2DECIDEG(), S_ARC, DRAWSEGMENT::SetAngle(), DRAWSEGMENT::SetArcStart(), DRAWSEGMENT::SetCenter(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetShape(), DRAWSEGMENT::SetWidth(), and ToLAYER_ID().

Referenced by addVertex(), and endEntity().

792 {
794  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
795 
796  wxPoint segment_startpoint( Millimeter2iu( aSegStart.x ), Millimeter2iu( aSegStart.y ) );
797  wxPoint segment_endpoint( Millimeter2iu( aSegEnd.x ), Millimeter2iu( aSegEnd.y ) );
798 
799  // ensure aBulge represents an angle from +/- ( 0 .. approx 359.8 deg )
800  if( aBulge < -2000.0 )
801  aBulge = -2000.0;
802  else if( aBulge > 2000.0 )
803  aBulge = 2000.0;
804 
805  double ang = 4.0 * atan( aBulge );
806 
807  // reflect the Y values to put everything in a RHCS
808  wxRealPoint sp( aSegStart.x, -aSegStart.y );
809  wxRealPoint ep( aSegEnd.x, -aSegEnd.y );
810  // angle from end->start
811  double offAng = atan2( ep.y - sp.y, ep.x - sp.x );
812  // length of subtended segment = 1/2 distance between the 2 points
813  double d = 0.5 * sqrt( (sp.x - ep.x) * (sp.x - ep.x) + (sp.y - ep.y) * (sp.y - ep.y) );
814  // midpoint of the subtended segment
815  double xm = ( sp.x + ep.x ) * 0.5;
816  double ym = ( sp.y + ep.y ) * 0.5;
817  double radius = d / sin( ang * 0.5 );
818 
819  if( radius < 0.0 )
820  radius = -radius;
821 
822  // calculate the height of the triangle with base d and hypotenuse r
823  double dh2 = radius * radius - d * d;
824 
825  // this should only ever happen due to rounding errors when r == d
826  if( dh2 < 0.0 )
827  dh2 = 0.0;
828 
829  double h = sqrt( dh2 );
830 
831  if( ang < 0.0 )
832  offAng -= M_PI_2;
833  else
834  offAng += M_PI_2;
835 
836  // for angles greater than 180 deg we need to flip the
837  // direction in which the arc center is found relative
838  // to the midpoint of the subtended segment.
839  if( ang < -M_PI )
840  offAng += M_PI;
841  else if( ang > M_PI )
842  offAng -= M_PI;
843 
844  // center point
845  double cx = h * cos( offAng ) + xm;
846  double cy = h * sin( offAng ) + ym;
847 
848  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
849  segm->SetShape( S_ARC );
850  segm->SetCenter( wxPoint( Millimeter2iu( cx ), Millimeter2iu( -cy ) ) );
851 
852  if( ang < 0.0 )
853  {
854  segm->SetArcStart( wxPoint( Millimeter2iu( ep.x ), Millimeter2iu( -ep.y ) ) );
855  segm->SetAngle( RAD2DECIDEG( ang ) );
856  }
857  else
858  {
859  segm->SetArcStart( wxPoint( Millimeter2iu( sp.x ), Millimeter2iu( -sp.y ) ) );
860  segm->SetAngle( RAD2DECIDEG( -ang ) );
861  }
862 
863  segm->SetWidth( aWidth );
864 
865  m_newItemsList.push_back( segm );
866  return;
867 }
bool m_importAsfootprintGraphicItems
void SetShape(STROKE_T aShape)
void SetArcStart(const wxPoint &aArcStartPoint)
Initialize the start arc point.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
double RAD2DECIDEG(double rad)
Definition: trigo.h:204
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
std::list< BOARD_ITEM * > m_newItemsList
Arcs (with rounded ends)
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
void SetWidth(int aWidth)
void DXF2BRD_CONVERTER::insertLine ( const wxRealPoint &  aSegStart,
const wxRealPoint &  aSegEnd,
int  aWidth 
)
private

Definition at line 773 of file dxf2brd_items.cpp.

References m_brdLayer, m_importAsfootprintGraphicItems, m_newItemsList, DRAWSEGMENT::SetEnd(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetStart(), DRAWSEGMENT::SetWidth(), and ToLAYER_ID().

Referenced by addVertex(), and endEntity().

775 {
777  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
778  wxPoint segment_startpoint( Millimeter2iu( aSegStart.x ), Millimeter2iu( aSegStart.y ) );
779  wxPoint segment_endpoint( Millimeter2iu( aSegEnd.x ), Millimeter2iu( aSegEnd.y ) );
780 
781  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
782  segm->SetStart( segment_startpoint );
783  segm->SetEnd( segment_endpoint );
784  segm->SetWidth( aWidth );
785 
786  m_newItemsList.push_back( segm );
787 }
bool m_importAsfootprintGraphicItems
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
std::list< BOARD_ITEM * > m_newItemsList
void SetStart(const wxPoint &aStart)
void SetEnd(const wxPoint &aEnd)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
void SetWidth(int aWidth)
void DXF2BRD_CONVERTER::insertSpline ( int  aWidth)
private

Definition at line 872 of file dxf2brd_items.cpp.

References m_brdLayer, m_curr_entity, m_importAsfootprintGraphicItems, m_newItemsList, DXF2BRD_ENTITY_DATA::m_SplineControlPointList, DXF2BRD_ENTITY_DATA::m_SplineDegree, DXF2BRD_ENTITY_DATA::m_SplineFitPointList, DXF2BRD_ENTITY_DATA::m_SplineKnotsList, mapX(), mapY(), DRAWSEGMENT::RebuildBezierToSegmentsPointsList(), S_CURVE, DRAWSEGMENT::SetBezControl1(), DRAWSEGMENT::SetBezControl2(), DRAWSEGMENT::SetEnd(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetShape(), DRAWSEGMENT::SetStart(), DRAWSEGMENT::SetWidth(), and ToLAYER_ID().

Referenced by endEntity().

873 {
874  #if 0 // Debug only
875  wxLogMessage("spl deg %d kn %d ctr %d fit %d",
880  #endif
881 
882  // Very basic conversion to segments
883  unsigned imax = m_curr_entity.m_SplineControlPointList.size();
884 
885  if( imax < 2 ) // malformed spline
886  return;
887 
888 #if 0 // set to 1 to approximate the spline by segments between 2 control points
889  wxPoint startpoint( mapX( m_curr_entity.m_SplineControlPointList[0].m_x ),
891 
892  for( unsigned int ii = 1; ii < imax; ++ii )
893  {
894  wxPoint endpoint( mapX( m_curr_entity.m_SplineControlPointList[ii].m_x ),
896 
897  if( startpoint != endpoint )
898  {
900  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) :
901  new DRAWSEGMENT;
902  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
903  segm->SetStart( startpoint );
904  segm->SetEnd( endpoint );
905  segm->SetWidth( aWidth );
906  m_newItemsList.push_back( segm );
907  startpoint = endpoint;
908  }
909  }
910 #else // Use bezier curves, supported by pcbnew, to approximate the spline
911  tinyspline::BSpline dxfspline( m_curr_entity.m_SplineControlPointList.size(),
912  /* coord dim */ 2, m_curr_entity.m_SplineDegree );
913  std::vector<double> ctrlp;
914 
915  for( unsigned ii = 0; ii < imax; ++ii )
916  {
917  ctrlp.push_back( m_curr_entity.m_SplineControlPointList[ii].m_x );
918  ctrlp.push_back( m_curr_entity.m_SplineControlPointList[ii].m_y );
919  }
920 
921  dxfspline.setCtrlp( ctrlp );
922  dxfspline.setKnots( m_curr_entity.m_SplineKnotsList );
923  tinyspline::BSpline beziers( dxfspline.toBeziers() );
924 
925  std::vector<double> coords = beziers.ctrlp();
926 
927  // Each Bezier curve uses 4 vertices (a start point, 2 control points and a end point).
928  // So we can have more than one Bezier curve ( there are one curve each four vertices)
929  for( unsigned ii = 0; ii < coords.size(); ii += 8 )
930  {
932  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) :
933  new DRAWSEGMENT;
934  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
935  segm->SetShape( S_CURVE );
936  segm->SetStart( wxPoint( mapX( coords[ii] ), mapY( coords[ii+1] ) ) );
937  segm->SetBezControl1( wxPoint( mapX( coords[ii+2] ), mapY( coords[ii+3] ) ) );
938  segm->SetBezControl2( wxPoint( mapX( coords[ii+4] ), mapY( coords[ii+5] ) ) );
939  segm->SetEnd( wxPoint( mapX( coords[ii+6] ), mapY( coords[ii+7] ) ) );
940  segm->SetWidth( aWidth );
941  segm->RebuildBezierToSegmentsPointsList( aWidth );
942  m_newItemsList.push_back( segm );
943  }
944 #endif
945 }
bool m_importAsfootprintGraphicItems
void SetShape(STROKE_T aShape)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
std::vector< wxRealPoint > m_SplineFitPointList
Definition: dxf2brd_items.h:83
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_BezierPoints vertex list that approximate the Bezier curve by a list of segments Has me...
void SetBezControl2(const wxPoint &aPoint)
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
unsigned int m_SplineDegree
Definition: dxf2brd_items.h:69
int mapX(double aDxfCoordX)
Bezier Curve.
void SetStart(const wxPoint &aStart)
void SetEnd(const wxPoint &aEnd)
std::vector< double > m_SplineKnotsList
Definition: dxf2brd_items.h:79
std::vector< SPLINE_CTRL_POINT > m_SplineControlPointList
Definition: dxf2brd_items.h:81
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:810
void SetBezControl1(const wxPoint &aPoint)
DXF2BRD_ENTITY_DATA m_curr_entity
void SetWidth(int aWidth)
virtual void DXF2BRD_CONVERTER::linkImage ( const DL_ImageDefData &  )
inlineoverrideprivatevirtual

Definition at line 288 of file dxf2brd_items.h.

288 { reportMsg( "DL_ImageDef not managed" ); }
void reportMsg(const char *aMessage)
int DXF2BRD_CONVERTER::mapDim ( double  aDxfValue)
private

Definition at line 85 of file dxf2brd_items.cpp.

References m_DXF2mm.

Referenced by addMText(), and addText().

86 {
87  return Millimeter2iu( aDxfValue * m_DXF2mm );
88 }
int DXF2BRD_CONVERTER::mapWidth ( double  aDxfWidth)
private

Definition at line 91 of file dxf2brd_items.cpp.

References m_defaultThickness, and m_DXF2mm.

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

92 {
93  // Always return the default line width
94 #if 0
95  // mapWidth returns the aDxfValue if aDxfWidth > 0 m_defaultThickness
96  if( aDxfWidth > 0.0 )
97  return Millimeter2iu( aDxfWidth * m_DXF2mm );
98 #endif
99  return Millimeter2iu( m_defaultThickness );
100 }
int DXF2BRD_CONVERTER::mapX ( double  aDxfCoordX)
private

Definition at line 73 of file dxf2brd_items.cpp.

References m_DXF2mm, and m_xOffset.

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

74 {
75  return Millimeter2iu( m_xOffset + ( aDxfCoordX * m_DXF2mm ) );
76 }
int DXF2BRD_CONVERTER::mapY ( double  aDxfCoordY)
private

Definition at line 79 of file dxf2brd_items.cpp.

References m_DXF2mm, and m_yOffset.

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

80 {
81  return Millimeter2iu( m_yOffset - ( aDxfCoordY * m_DXF2mm ) );
82 }
void DXF2BRD_CONVERTER::reportMsg ( const char *  aMessage)
private

Definition at line 117 of file dxf2brd_items.cpp.

References m_messages.

118 {
119  // Add message to keep trace of not handled dxf entities
120  m_messages += aMessage;
121  m_messages += '\n';
122 }
std::string m_messages
void DXF2BRD_CONVERTER::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 174 of file dxf2brd_items.h.

Referenced by DIALOG_DXF_IMPORT::TransferDataFromWindow().

174 { m_brdLayer = aBrdLayer; }
void DXF2BRD_CONVERTER::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 151 of file dxf2brd_items.h.

Referenced by DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT(), and DIALOG_DXF_IMPORT::TransferDataFromWindow().

152  {
153  m_defaultThickness = aWidth;
154  }
void DXF2BRD_CONVERTER::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 164 of file dxf2brd_items.h.

Referenced by DIALOG_DXF_IMPORT::TransferDataFromWindow().

165  {
166  m_xOffset = aOffsetX;
167  m_yOffset = aOffsetY;
168  }
virtual void DXF2BRD_CONVERTER::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 234 of file dxf2brd_items.h.

234 {}
void DXF2BRD_CONVERTER::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 550 of file dxf2brd_items.cpp.

References m_codePage, and m_DXF2mm.

551 {
552  // Called for every int variable in the DXF file (e.g. "$INSUNITS").
553 
554  if( key == "$DWGCODEPAGE" )
555  {
556  m_codePage = value;
557  return;
558  }
559 
560  if( key == "$INSUNITS" ) // Drawing units
561  {
562  switch( value )
563  {
564  case 1: // inches
565  m_DXF2mm = 25.4;
566  break;
567 
568  case 2: // feet
569  m_DXF2mm = 304.8;
570  break;
571 
572  case 4: // mm
573  m_DXF2mm = 1.0;
574  break;
575 
576  case 5: // centimeters
577  m_DXF2mm = 10.0;
578  break;
579 
580  case 6: // meters
581  m_DXF2mm = 1000.0;
582  break;
583 
584  case 8: // microinches
585  m_DXF2mm = 2.54e-5;
586  break;
587 
588  case 9: // mils
589  m_DXF2mm = 0.0254;
590  break;
591 
592  case 10: // yards
593  m_DXF2mm = 914.4;
594  break;
595 
596  case 11: // Angstroms
597  m_DXF2mm = 1.0e-7;
598  break;
599 
600  case 12: // nanometers
601  m_DXF2mm = 1.0e-6;
602  break;
603 
604  case 13: // micrometers
605  m_DXF2mm = 1.0e-3;
606  break;
607 
608  case 14: // decimeters
609  m_DXF2mm = 100.0;
610  break;
611 
612  default:
613  // use the default of 1.0 for:
614  // 0: Unspecified Units
615  // 3: miles
616  // 7: kilometers
617  // 15: decameters
618  // 16: hectometers
619  // 17: gigameters
620  // 18: AU
621  // 19: lightyears
622  // 20: parsecs
623  m_DXF2mm = 1.0;
624  break;
625  }
626 
627  return;
628  }
629 }
std::string m_codePage
void DXF2BRD_CONVERTER::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 632 of file dxf2brd_items.cpp.

634 {
635  // Called for every string variable in the DXF file (e.g. "$ACADVER").
636 }
wxString DXF2BRD_CONVERTER::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 639 of file dxf2brd_items.cpp.

References i.

640 {
641  wxString res;
642  int j = 0;
643 
644  for( unsigned i = 0; i<aStr.length(); ++i )
645  {
646  int c = aStr[i];
647 
648  if( c > 175 || c < 11 )
649  {
650  res.append( aStr.Mid( j, i - j ) );
651  j = i;
652 
653  switch( c )
654  {
655  case 0x0A:
656  res += wxT( "\\P" );
657  break;
658 
659  // diameter:
660 #ifdef __WINDOWS_
661  // windows, as always, is special.
662  case 0x00D8:
663 #else
664  case 0x2205:
665 #endif
666  res += wxT( "%%C" );
667  break;
668 
669  // degree:
670  case 0x00B0:
671  res += wxT( "%%D" );
672  break;
673 
674  // plus/minus
675  case 0x00B1:
676  res += wxT( "%%P" );
677  break;
678 
679  default:
680  j--;
681  break;
682  }
683 
684  j++;
685  }
686  }
687 
688  res.append( aStr.Mid( j ) );
689  return res;
690 }
size_t i
Definition: json11.cpp:597
wxString DXF2BRD_CONVERTER::toNativeString ( const wxString &  aData)
staticprivate

Converts a DXF encoded string into a native Unicode string.

Definition at line 693 of file dxf2brd_items.cpp.

References i.

Referenced by addMText(), and addText().

694 {
695  wxString res;
696 
697  // Ignore font tags:
698  int j = 0;
699 
700  for( unsigned i = 0; i < aData.length(); ++i )
701  {
702  if( aData[ i ] == 0x7B ) // is '{' ?
703  {
704  if( aData[ i + 1 ] == 0x5c && aData[ i + 2 ] == 0x66 ) // is "\f" ?
705  {
706  // found font tag, append parsed part
707  res.append( aData.Mid( j, i - j ) );
708 
709  // skip to ';'
710  for( unsigned k = i + 3; k < aData.length(); ++k )
711  {
712  if( aData[ k ] == 0x3B )
713  {
714  i = j = ++k;
715  break;
716  }
717  }
718 
719  // add to '}'
720  for( unsigned k = i; k < aData.length(); ++k )
721  {
722  if( aData[ k ] == 0x7D )
723  {
724  res.append( aData.Mid( i, k - i ) );
725  i = j = ++k;
726  break;
727  }
728  }
729  }
730  }
731  }
732 
733  res.append( aData.Mid( j ) );
734 
735 #if 1
736  wxRegEx regexp;
737  // Line feed:
738  regexp.Compile( wxT( "\\\\P" ) );
739  regexp.Replace( &res, wxT( "\n" ) );
740 
741  // Space:
742  regexp.Compile( wxT( "\\\\~" ) );
743  regexp.Replace( &res, wxT( " " ) );
744 
745  // diameter:
746  regexp.Compile( wxT( "%%[cC]" ) );
747 #ifdef __WINDOWS__
748  // windows, as always, is special.
749  regexp.Replace( &res, wxChar( 0xD8 ) );
750 #else
751  // Empty_set, diameter is 0x2300
752  regexp.Replace( &res, wxChar( 0x2205 ) );
753 #endif
754 
755  // degree:
756  regexp.Compile( wxT( "%%[dD]" ) );
757  regexp.Replace( &res, wxChar( 0x00B0 ) );
758  // plus/minus
759  regexp.Compile( wxT( "%%[pP]" ) );
760  regexp.Replace( &res, wxChar( 0x00B1 ) );
761 #endif
762 
763  return res;
764 }
size_t i
Definition: json11.cpp:597
void DXF2BRD_CONVERTER::writeLine ( )
private
void DXF2BRD_CONVERTER::writeMtext ( )
private

Member Data Documentation

int DXF2BRD_CONVERTER::m_brdLayer
private
std::string DXF2BRD_CONVERTER::m_codePage
private

Definition at line 122 of file dxf2brd_items.h.

Referenced by setVariableInt().

DXF2BRD_ENTITY_DATA DXF2BRD_CONVERTER::m_curr_entity
private
double DXF2BRD_CONVERTER::m_defaultThickness
private

Definition at line 118 of file dxf2brd_items.h.

Referenced by DXF2BRD_CONVERTER(), and mapWidth().

double DXF2BRD_CONVERTER::m_DXF2mm
private

Definition at line 119 of file dxf2brd_items.h.

Referenced by addVertex(), DXF2BRD_CONVERTER(), mapDim(), mapWidth(), mapX(), mapY(), and setVariableInt().

bool DXF2BRD_CONVERTER::m_importAsfootprintGraphicItems
private
std::string DXF2BRD_CONVERTER::m_messages
private

Definition at line 125 of file dxf2brd_items.h.

Referenced by reportMsg().

std::list<BOARD_ITEM*> DXF2BRD_CONVERTER::m_newItemsList
private
int DXF2BRD_CONVERTER::m_version
private

Definition at line 121 of file dxf2brd_items.h.

Referenced by DXF2BRD_CONVERTER().

double DXF2BRD_CONVERTER::m_xOffset
private

Definition at line 116 of file dxf2brd_items.h.

Referenced by addVertex(), DXF2BRD_CONVERTER(), and mapX().

double DXF2BRD_CONVERTER::m_yOffset
private

Definition at line 117 of file dxf2brd_items.h.

Referenced by addVertex(), DXF2BRD_CONVERTER(), and mapY().


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