KiCad PCB EDA Suite
DXF2BRD_CONVERTER Class Reference

This format filter class can import and export DXF files. 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
 

Private Member Functions

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)
 
virtual void addHeader (const DRW_Header *aData) override
 
virtual void addLType (const DRW_LType &aData) override
 
virtual void addLayer (const DRW_Layer &aData) override
 
virtual void addDimStyle (const DRW_Dimstyle &aData) override
 
virtual void addBlock (const DRW_Block &aData) override
 
virtual void endBlock () override
 
virtual void addPoint (const DRW_Point &aData) override
 
virtual void addLine (const DRW_Line &aData) override
 
virtual void addRay (const DRW_Ray &aData) override
 
virtual void addXline (const DRW_Xline &aData) override
 
virtual void addCircle (const DRW_Circle &aData) override
 
virtual void addArc (const DRW_Arc &aData) override
 
virtual void addEllipse (const DRW_Ellipse &aData) override
 
virtual void addLWPolyline (const DRW_LWPolyline &aData) override
 
virtual void addText (const DRW_Text &aData) override
 
virtual void addPolyline (const DRW_Polyline &aData) override
 
virtual void addSpline (const DRW_Spline *aData) override
 
virtual void addKnot (const DRW_Entity &) override
 
virtual void addInsert (const DRW_Insert &aData) override
 
virtual void addTrace (const DRW_Trace &aData) override
 
virtual void addSolid (const DRW_Solid &aData) override
 
virtual void addMText (const DRW_MText &aData) override
 
virtual void addDimAlign (const DRW_DimAligned *aData) override
 
virtual void addDimLinear (const DRW_DimLinear *aData) override
 
virtual void addDimRadial (const DRW_DimRadial *aData) override
 
virtual void addDimDiametric (const DRW_DimDiametric *aData) override
 
virtual void addDimAngular (const DRW_DimAngular *aData) override
 
virtual void addDimAngular3P (const DRW_DimAngular3p *aData) override
 
virtual void addDimOrdinate (const DRW_DimOrdinate *aData) override
 
virtual void addLeader (const DRW_Leader *aData) override
 
virtual void addHatch (const DRW_Hatch *aData) override
 
virtual void addImage (const DRW_Image *aData) override
 
virtual void linkImage (const DRW_ImageDef *aData) override
 
virtual void add3dFace (const DRW_3Dface &aData) override
 
virtual void addComment (const char *) override
 
virtual void addVport (const DRW_Vport &aData) override
 
virtual void addTextStyle (const DRW_Textstyle &aData) override
 
virtual void addViewport (const DRW_Viewport &aData) override
 
virtual void setBlock (const int aHandle) override
 
virtual void writeTextstyles () override
 
virtual void writeVports () override
 
virtual void writeHeader (DRW_Header &aData) override
 
virtual void writeEntities () override
 
virtual void writeLTypes () override
 
virtual void writeLayers () override
 
virtual void writeBlockRecords () override
 
virtual void writeBlocks () override
 
virtual void writeDimstyles () override
 
void writeLine ()
 
void writeMtext ()
 
virtual void addAppId (const DRW_AppId &data) override
 
virtual void writeAppId () override
 

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
 

Detailed Description

This format filter class can import and export DXF files.

It depends on the dxflib library.

Author
Rallaz

Definition at line 42 of file dxf2brd_items.h.

Constructor & Destructor Documentation

DXF2BRD_CONVERTER::DXF2BRD_CONVERTER ( )

Definition at line 57 of file dxf2brd_items.cpp.

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

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

Definition at line 69 of file dxf2brd_items.cpp.

70 {
71 }

Member Function Documentation

virtual void DXF2BRD_CONVERTER::add3dFace ( const DRW_3Dface &  aData)
inlineoverrideprivatevirtual

Definition at line 170 of file dxf2brd_items.h.

170 {}
virtual void DXF2BRD_CONVERTER::addAppId ( const DRW_AppId &  data)
inlineoverrideprivatevirtual

Definition at line 211 of file dxf2brd_items.h.

211 {}
void DXF2BRD_CONVERTER::addArc ( const DRW_Arc &  aData)
overrideprivatevirtual

Definition at line 254 of file dxf2brd_items.cpp.

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

255 {
257  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
258 
259  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
260  segm->SetShape( S_ARC );
261 
262  // Init arc centre:
263  wxPoint center( mapX( data.basePoint.x ), mapY( data.basePoint.y ) );
264  segm->SetCenter( center );
265 
266  // Init arc start point
267  double arcStartx = data.radious;
268  double arcStarty = 0;
269  double startangle = data.staangle;
270  double endangle = data.endangle;
271 
272  RotatePoint( &arcStartx, &arcStarty, -RAD2DECIDEG( startangle ) );
273  wxPoint arcStart( mapX( arcStartx + data.basePoint.x ),
274  mapY( arcStarty + data.basePoint.y ) );
275  segm->SetArcStart( arcStart );
276 
277  // calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew)
278  double angle = -RAD2DECIDEG( endangle - startangle );
279 
280  if( angle > 0.0 )
281  angle -= 3600.0;
282 
283  segm->SetAngle( angle );
284 
285  segm->SetWidth( mapWidth( data.thickness ) );
286  m_newItemsList.push_back( segm );
287 }
bool m_importAsfootprintGraphicItems
Definition: dxf2brd_items.h:53
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 RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
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:796
void SetWidth(int aWidth)
virtual void DXF2BRD_CONVERTER::addBlock ( const DRW_Block &  aData)
inlineoverrideprivatevirtual

Definition at line 140 of file dxf2brd_items.h.

140 {}
void DXF2BRD_CONVERTER::addCircle ( const DRW_Circle &  aData)
overrideprivatevirtual

Definition at line 235 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().

236 {
238  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
239 
240  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
241  segm->SetShape( S_CIRCLE );
242  wxPoint center( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
243  segm->SetCenter( center );
244  wxPoint circle_start( mapX( aData.basePoint.x + aData.radious ), mapY( aData.basePoint.y ) );
245  segm->SetArcStart( circle_start );
246  segm->SetWidth( mapWidth( aData.thickness ) );
247  m_newItemsList.push_back( segm );
248 }
bool m_importAsfootprintGraphicItems
Definition: dxf2brd_items.h:53
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
Definition: dxf2brd_items.h:45
int mapX(double aDxfCoordX)
int mapWidth(double aDxfWidth)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:796
void SetWidth(int aWidth)
virtual void DXF2BRD_CONVERTER::addComment ( const char *  )
inlineoverrideprivatevirtual

Definition at line 171 of file dxf2brd_items.h.

171 {}
virtual void DXF2BRD_CONVERTER::addDimAlign ( const DRW_DimAligned *  aData)
inlineoverrideprivatevirtual

Definition at line 158 of file dxf2brd_items.h.

158 {}
virtual void DXF2BRD_CONVERTER::addDimAngular ( const DRW_DimAngular *  aData)
inlineoverrideprivatevirtual

Definition at line 162 of file dxf2brd_items.h.

162 {}
virtual void DXF2BRD_CONVERTER::addDimAngular3P ( const DRW_DimAngular3p *  aData)
inlineoverrideprivatevirtual

Definition at line 163 of file dxf2brd_items.h.

163 {}
virtual void DXF2BRD_CONVERTER::addDimDiametric ( const DRW_DimDiametric *  aData)
inlineoverrideprivatevirtual

Definition at line 161 of file dxf2brd_items.h.

161 {}
virtual void DXF2BRD_CONVERTER::addDimLinear ( const DRW_DimLinear *  aData)
inlineoverrideprivatevirtual

Definition at line 159 of file dxf2brd_items.h.

159 {}
virtual void DXF2BRD_CONVERTER::addDimOrdinate ( const DRW_DimOrdinate *  aData)
inlineoverrideprivatevirtual

Definition at line 164 of file dxf2brd_items.h.

164 {}
virtual void DXF2BRD_CONVERTER::addDimRadial ( const DRW_DimRadial *  aData)
inlineoverrideprivatevirtual

Definition at line 160 of file dxf2brd_items.h.

160 {}
virtual void DXF2BRD_CONVERTER::addDimStyle ( const DRW_Dimstyle &  aData)
inlineoverrideprivatevirtual

Definition at line 139 of file dxf2brd_items.h.

139 {}
virtual void DXF2BRD_CONVERTER::addEllipse ( const DRW_Ellipse &  aData)
inlineoverrideprivatevirtual

Definition at line 148 of file dxf2brd_items.h.

148 {}
virtual void DXF2BRD_CONVERTER::addHatch ( const DRW_Hatch *  aData)
inlineoverrideprivatevirtual

Definition at line 166 of file dxf2brd_items.h.

166 {}
void DXF2BRD_CONVERTER::addHeader ( const DRW_Header *  aData)
overrideprivatevirtual

Definition at line 515 of file dxf2brd_items.cpp.

References m_codePage, and m_DXF2mm.

516 {
517  std::map<std::string, DRW_Variant*>::const_iterator it;
518  m_DXF2mm = 1.0; // assume no scale factor
519 
520  for( it = data->vars.begin(); it != data->vars.end(); ++it )
521  {
522  std::string key = ( (*it).first ).c_str();
523 
524  if( key == "$DWGCODEPAGE" )
525  {
526  DRW_Variant* var = (*it).second;
527  m_codePage = ( *var->content.s );
528  }
529  else if( key == "$INSUNITS" )
530  {
531  DRW_Variant* var = (*it).second;
532 
533  switch( var->content.i )
534  {
535  case 1: // inches
536  m_DXF2mm = 25.4;
537  break;
538 
539  case 2: // feet
540  m_DXF2mm = 304.8;
541  break;
542 
543  case 5: // centimeters
544  m_DXF2mm = 10.0;
545  break;
546 
547  case 6: // meters
548  m_DXF2mm = 1000.0;
549  break;
550 
551  case 8: // microinches
552  m_DXF2mm = 2.54e-5;
553  break;
554 
555  case 9: // mils
556  m_DXF2mm = 0.0254;
557  break;
558 
559  case 10: // yards
560  m_DXF2mm = 914.4;
561  break;
562 
563  case 11: // Angstroms
564  m_DXF2mm = 1.0e-7;
565  break;
566 
567  case 12: // nanometers
568  m_DXF2mm = 1.0e-6;
569  break;
570 
571  case 13: // micrometers
572  m_DXF2mm = 1.0e-3;
573  break;
574 
575  case 14: // decimeters
576  m_DXF2mm = 100.0;
577  break;
578 
579  default:
580  // use the default of 1.0 for:
581  // 0: Unspecified Units
582  // 4: mm
583  // 3: miles
584  // 7: kilometers
585  // 15: decameters
586  // 16: hectometers
587  // 17: gigameters
588  // 18: AU
589  // 19: lightyears
590  // 20: parsecs
591  break;
592  }
593  }
594  }
595 }
std::string m_codePage
Definition: dxf2brd_items.h:52
virtual void DXF2BRD_CONVERTER::addImage ( const DRW_Image *  aData)
inlineoverrideprivatevirtual

Definition at line 167 of file dxf2brd_items.h.

167 {}
virtual void DXF2BRD_CONVERTER::addInsert ( const DRW_Insert &  aData)
inlineoverrideprivatevirtual

Definition at line 154 of file dxf2brd_items.h.

154 {}
virtual void DXF2BRD_CONVERTER::addKnot ( const DRW_Entity &  )
inlineoverrideprivatevirtual

Definition at line 153 of file dxf2brd_items.h.

153 {}
void DXF2BRD_CONVERTER::addLayer ( const DRW_Layer &  aData)
overrideprivatevirtual

Definition at line 114 of file dxf2brd_items.cpp.

References name.

115 {
116  // Not yet useful in Pcbnew.
117 #if 0
118  wxString name = wxString::FromUTF8( aData.name.c_str() );
119  wxLogMessage( name );
120 #endif
121 }
const char * name
virtual void DXF2BRD_CONVERTER::addLeader ( const DRW_Leader *  aData)
inlineoverrideprivatevirtual

Definition at line 165 of file dxf2brd_items.h.

165 {}
void DXF2BRD_CONVERTER::addLine ( const DRW_Line &  aData)
overrideprivatevirtual

Definition at line 124 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().

125 {
127  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
128 
129  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
130  wxPoint start( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
131  segm->SetStart( start );
132  wxPoint end( mapX( aData.secPoint.x ), mapY( aData.secPoint.y ) );
133  segm->SetEnd( end );
134  segm->SetWidth( mapWidth( aData.thickness ) );
135  m_newItemsList.push_back( segm );
136 }
bool m_importAsfootprintGraphicItems
Definition: dxf2brd_items.h:53
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
Definition: dxf2brd_items.h:45
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:796
void SetWidth(int aWidth)
virtual void DXF2BRD_CONVERTER::addLType ( const DRW_LType &  aData)
inlineoverrideprivatevirtual

Definition at line 137 of file dxf2brd_items.h.

137 {}
void DXF2BRD_CONVERTER::addLWPolyline ( const DRW_LWPolyline &  aData)
overrideprivatevirtual

Definition at line 188 of file dxf2brd_items.cpp.

References abs, insertArc(), insertLine(), m_DXF2mm, m_xOffset, m_yOffset, mapWidth(), and MIN_BULGE.

189 {
190  // Currently, Pcbnew does not know polylines, for boards.
191  // So we have to convert a polyline to a set of segments.
192  // The import is a simplified import: the width of segment is
193  // (obviously constant and is the width of the DRW_LWPolyline.
194  // the variable width of each vertex (when exists) is not used.
195  wxRealPoint seg_start;
196  wxRealPoint poly_start;
197  double bulge = 0.0;
198  int lineWidth = mapWidth( aData.thickness );
199 
200  for( unsigned ii = 0; ii < aData.vertlist.size(); ii++ )
201  {
202  DRW_Vertex2D* vertex = aData.vertlist[ii];
203 
204  if( ii == 0 )
205  {
206  seg_start.x = m_xOffset + vertex->x * m_DXF2mm;
207  seg_start.y = m_yOffset - vertex->y * m_DXF2mm;
208  bulge = vertex->bulge;
209  poly_start = seg_start;
210  continue;
211  }
212 
213  wxRealPoint seg_end( m_xOffset + vertex->x * m_DXF2mm, m_yOffset - vertex->y * m_DXF2mm );
214 
215  if( std::abs( bulge ) < MIN_BULGE )
216  insertLine( seg_start, seg_end, lineWidth );
217  else
218  insertArc( seg_start, seg_end, bulge, lineWidth );
219 
220  bulge = vertex->bulge;
221  seg_start = seg_end;
222  }
223 
224  // LWPolyline flags bit 0 indicates closed (1) or open (0) polyline
225  if( aData.flags & 1 )
226  {
227  if( std::abs( bulge ) < MIN_BULGE )
228  insertLine( seg_start, poly_start, lineWidth );
229  else
230  insertArc( seg_start, poly_start, bulge, lineWidth );
231  }
232 }
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)
void DXF2BRD_CONVERTER::addMText ( const DRW_MText &  aData)
overrideprivatevirtual

Definition at line 402 of file dxf2brd_items.cpp.

References 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().

403 {
404  wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
405  wxString attrib, tmp;
406 
407  /* Some texts start by '\' and have formating chars (font name, font option...)
408  * ending with ';'
409  * Here are some mtext formatting codes:
410  * Format code Purpose
411  * \0...\o Turns overline on and off
412  * \L...\l Turns underline on and off
413  * \~ Inserts a nonbreaking space
414  \\ Inserts a backslash
415  \\\{...\} Inserts an opening and closing brace
416  \\ \File name; Changes to the specified font file
417  \\ \Hvalue; Changes to the text height specified in drawing units
418  \\ \Hvaluex; Changes the text height to a multiple of the current text height
419  \\ \S...^...; Stacks the subsequent text at the \, #, or ^ symbol
420  \\ \Tvalue; Adjusts the space between characters, from.75 to 4 times
421  \\ \Qangle; Changes obliquing angle
422  \\ \Wvalue; Changes width factor to produce wide text
423  \\ \A Sets the alignment value; valid values: 0, 1, 2 (bottom, center, top) while( text.StartsWith( wxT("\\") ) )
424  */
425  while( text.StartsWith( wxT( "\\" ) ) )
426  {
427  attrib << text.BeforeFirst( ';' );
428  tmp = text.AfterFirst( ';' );
429  text = tmp;
430  }
431 
432  BOARD_ITEM* brdItem;
433  EDA_TEXT* textItem;
434 
436  {
437  TEXTE_MODULE* modText = new TEXTE_MODULE( NULL );
438  brdItem = static_cast< BOARD_ITEM* >( modText );
439  textItem = static_cast< EDA_TEXT* >( modText );
440  }
441  else
442  {
443  TEXTE_PCB* pcbText = new TEXTE_PCB( NULL );
444  brdItem = static_cast< BOARD_ITEM* >( pcbText );
445  textItem = static_cast< EDA_TEXT* >( pcbText );
446  }
447 
448  brdItem->SetLayer( ToLAYER_ID( m_brdLayer ) );
449  wxPoint textpos( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
450 
451  textItem->SetTextPos( textpos );
452  textItem->SetTextAngle( aData.angle * 10 );
453 
454  // The 0.8 factor gives a better height/width ratio with our font
455  textItem->SetTextWidth( mapDim( aData.height * 0.8 ) );
456  textItem->SetTextHeight( mapDim( aData.height ) );
457  textItem->SetThickness( mapWidth( aData.thickness ) );
458  textItem->SetText( text );
459 
460  // Initialize text justifications:
461  if( aData.textgen <= 3 )
462  {
464  }
465  else if( aData.textgen <= 6 )
466  {
468  }
469  else
470  {
472  }
473 
474  if( aData.textgen % 3 == 1 )
475  {
477  }
478  else if( aData.textgen % 3 == 2 )
479  {
481  }
482  else
483  {
485  }
486 
487 #if 0 // These setting have no mening in Pcbnew
488  if( data.alignH == 1 )
489  {
490  // Text is left to right;
491  }
492  else if( data.alignH == 3 )
493  {
494  // Text is top to bottom;
495  }
496  else
497  {
498  // use ByStyle;
499  }
500 
501  if( aData.alignV == 1 )
502  {
503  // use AtLeast;
504  }
505  else
506  {
507  // useExact;
508  }
509 #endif
510 
511  m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) );
512 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:154
bool m_importAsfootprintGraphicItems
Definition: dxf2brd_items.h:53
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:221
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:112
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:192
int mapX(double aDxfCoordX)
void SetTextWidth(int aWidth)
Definition: eda_text.h:215
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:191
void SetTextHeight(int aHeight)
Definition: eda_text.h:218
int mapWidth(double aDxfWidth)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:796
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:146
virtual void SetText(const wxString &aText)
Definition: eda_text.h:139
virtual void DXF2BRD_CONVERTER::addPoint ( const DRW_Point &  aData)
inlineoverrideprivatevirtual

Definition at line 142 of file dxf2brd_items.h.

142 {}
void DXF2BRD_CONVERTER::addPolyline ( const DRW_Polyline &  aData)
overrideprivatevirtual

Definition at line 138 of file dxf2brd_items.cpp.

References abs, insertArc(), insertLine(), m_DXF2mm, m_xOffset, m_yOffset, mapWidth(), and MIN_BULGE.

139 {
140  // Convert DXF Polylines into a series of KiCad Lines and Arcs.
141  // A Polyline (as opposed to a LWPolyline) may be a 3D line or
142  // even a 3D Mesh. The only type of Polyline which is guaranteed
143  // to import correctly is a 2D Polyline in X and Y, which is what
144  // we assume of all Polylines. The width used is the width of the
145  // Polyline; per-vertex line widths, if present, are ignored.
146 
147  wxRealPoint seg_start;
148  wxRealPoint poly_start;
149  double bulge = 0.0;
150  int lineWidth = mapWidth( aData.thickness );
151 
152  for( unsigned ii = 0; ii < aData.vertlist.size(); ii++ )
153  {
154  DRW_Vertex* vertex = aData.vertlist[ii];
155 
156  if( ii == 0 )
157  {
158  seg_start.x = m_xOffset + vertex->basePoint.x * m_DXF2mm;
159  seg_start.y = m_yOffset - vertex->basePoint.y * m_DXF2mm;
160  bulge = vertex->bulge;
161  poly_start = seg_start;
162  continue;
163  }
164 
165  wxRealPoint seg_end( m_xOffset + vertex->basePoint.x * m_DXF2mm,
166  m_yOffset - vertex->basePoint.y * m_DXF2mm );
167 
168  if( std::abs( bulge ) < MIN_BULGE )
169  insertLine( seg_start, seg_end, lineWidth );
170  else
171  insertArc( seg_start, seg_end, bulge, lineWidth );
172 
173  bulge = vertex->bulge;
174  seg_start = seg_end;
175  }
176 
177  // LWPolyline flags bit 0 indicates closed (1) or open (0) polyline
178  if( aData.flags & 1 )
179  {
180  if( std::abs( bulge ) < MIN_BULGE )
181  insertLine( seg_start, poly_start, lineWidth );
182  else
183  insertArc( seg_start, poly_start, bulge, lineWidth );
184  }
185 }
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)
virtual void DXF2BRD_CONVERTER::addRay ( const DRW_Ray &  aData)
inlineoverrideprivatevirtual

Definition at line 144 of file dxf2brd_items.h.

144 {}
virtual void DXF2BRD_CONVERTER::addSolid ( const DRW_Solid &  aData)
inlineoverrideprivatevirtual

Definition at line 156 of file dxf2brd_items.h.

156 {}
virtual void DXF2BRD_CONVERTER::addSpline ( const DRW_Spline *  aData)
inlineoverrideprivatevirtual

Definition at line 152 of file dxf2brd_items.h.

152 {}
void DXF2BRD_CONVERTER::addText ( const DRW_Text &  aData)
overrideprivatevirtual

Definition at line 290 of file dxf2brd_items.cpp.

References 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().

291 {
292  BOARD_ITEM* brdItem;
293  EDA_TEXT* textItem;
294 
296  {
297  TEXTE_MODULE* modText = new TEXTE_MODULE( NULL );
298  brdItem = static_cast< BOARD_ITEM* >( modText );
299  textItem = static_cast< EDA_TEXT* >( modText );
300  }
301  else
302  {
303  TEXTE_PCB* pcbText = new TEXTE_PCB( NULL );
304  brdItem = static_cast< BOARD_ITEM* >( pcbText );
305  textItem = static_cast< EDA_TEXT* >( pcbText );
306  }
307 
308  brdItem->SetLayer( ToLAYER_ID( m_brdLayer ) );
309 
310  wxPoint refPoint( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
311  wxPoint secPoint( mapX( aData.secPoint.x ), mapY( aData.secPoint.y ) );
312 
313  if( aData.alignV != 0 || aData.alignH != 0 || aData.alignH == DRW_Text::HMiddle )
314  {
315  if( aData.alignH != DRW_Text::HAligned && aData.alignH != DRW_Text::HFit )
316  {
317  wxPoint tmp = secPoint;
318  secPoint = refPoint;
319  refPoint = tmp;
320  }
321  }
322 
323  switch( aData.alignV )
324  {
325  case DRW_Text::VBaseLine:
327  break;
328 
329  case DRW_Text::VBottom:
331  break;
332 
333  case DRW_Text::VMiddle:
335  break;
336 
337  case DRW_Text::VTop:
339  break;
340  }
341 
342  switch( aData.alignH )
343  {
344  case DRW_Text::HLeft:
346  break;
347 
348  case DRW_Text::HCenter:
350  break;
351 
352  case DRW_Text::HRight:
354  break;
355 
356  case DRW_Text::HAligned:
357  // no equivalent options in text pcb.
359  break;
360 
361  case DRW_Text::HMiddle:
362  // no equivalent options in text pcb.
364  break;
365 
366  case DRW_Text::HFit:
367  // no equivalent options in text pcb.
369  break;
370  }
371 
372 #if 0
373  wxString sty = wxString::FromUTF8( aData.style.c_str() );
374  sty = sty.ToLower();
375 
376  if( aData.textgen == 2 )
377  {
378  // Text dir = left to right;
379  } else if( aData.textgen == 4 )
380  {
381  // Text dir = top to bottom;
382  } else
383  {
384  }
385 #endif
386 
387  wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
388 
389  textItem->SetTextPos( refPoint );
390  textItem->SetTextAngle( aData.angle * 10 );
391 
392  // The 0.8 factor gives a better height/width ratio with our font
393  textItem->SetTextWidth( mapDim( aData.height * 0.8 ) );
394  textItem->SetTextHeight( mapDim( aData.height ) );
395  textItem->SetThickness( mapWidth( aData.thickness ) );
396  textItem->SetText( text );
397 
398  m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) );
399 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:154
bool m_importAsfootprintGraphicItems
Definition: dxf2brd_items.h:53
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:221
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:112
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:192
int mapX(double aDxfCoordX)
void SetTextWidth(int aWidth)
Definition: eda_text.h:215
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:191
void SetTextHeight(int aHeight)
Definition: eda_text.h:218
int mapWidth(double aDxfWidth)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:796
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:146
virtual void SetText(const wxString &aText)
Definition: eda_text.h:139
void DXF2BRD_CONVERTER::addTextStyle ( const DRW_Textstyle &  aData)
overrideprivatevirtual

Definition at line 726 of file dxf2brd_items.cpp.

727 {
728  // TODO
729 }
virtual void DXF2BRD_CONVERTER::addTrace ( const DRW_Trace &  aData)
inlineoverrideprivatevirtual

Definition at line 155 of file dxf2brd_items.h.

155 {}
virtual void DXF2BRD_CONVERTER::addViewport ( const DRW_Viewport &  aData)
inlineoverrideprivatevirtual

Definition at line 177 of file dxf2brd_items.h.

177 {}
virtual void DXF2BRD_CONVERTER::addVport ( const DRW_Vport &  aData)
inlineoverrideprivatevirtual

Definition at line 173 of file dxf2brd_items.h.

173 {}
virtual void DXF2BRD_CONVERTER::addXline ( const DRW_Xline &  aData)
inlineoverrideprivatevirtual

Definition at line 145 of file dxf2brd_items.h.

145 {}
virtual void DXF2BRD_CONVERTER::endBlock ( )
inlineoverrideprivatevirtual

Definition at line 141 of file dxf2brd_items.h.

141 {}
const std::list<BOARD_ITEM*>& DXF2BRD_CONVERTER::GetItemsList ( ) const
inline
Returns
the list of new BOARD_ITEM

Definition at line 113 of file dxf2brd_items.h.

References m_newItemsList.

Referenced by DIALOG_DXF_IMPORT::GetImportedItems().

114  {
115  return m_newItemsList;
116  }
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
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 65 of file dxf2brd_items.h.

Referenced by DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT().

66  {
67  m_importAsfootprintGraphicItems = aImportAsFootprintGraphic;
68  }
bool m_importAsfootprintGraphicItems
Definition: dxf2brd_items.h:53
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.

Referenced by DIALOG_DXF_IMPORT::TransferDataFromWindow().

103 {
104  LOCALE_IO locale;
105  dxfRW* dxf = new dxfRW( aFile.ToUTF8() );
106  bool success = dxf->read( this, true );
107 
108  delete dxf;
109 
110  return success;
111 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
void DXF2BRD_CONVERTER::insertArc ( const wxRealPoint &  aSegStart,
const wxRealPoint &  aSegEnd,
double  aBulge,
int  aWidth 
)
private

Definition at line 750 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 addLWPolyline(), and addPolyline().

752 {
754  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
755 
756  wxPoint segment_startpoint( Millimeter2iu( aSegStart.x ), Millimeter2iu( aSegStart.y ) );
757  wxPoint segment_endpoint( Millimeter2iu( aSegEnd.x ), Millimeter2iu( aSegEnd.y ) );
758 
759  // ensure aBulge represents an angle from +/- ( 0 .. approx 359.8 deg )
760  if( aBulge < -2000.0 )
761  aBulge = -2000.0;
762  else if( aBulge > 2000.0 )
763  aBulge = 2000.0;
764 
765  double ang = 4.0 * atan( aBulge );
766 
767  // reflect the Y values to put everything in a RHCS
768  wxRealPoint sp( aSegStart.x, -aSegStart.y );
769  wxRealPoint ep( aSegEnd.x, -aSegEnd.y );
770  // angle from end->start
771  double offAng = atan2( ep.y - sp.y, ep.x - sp.x );
772  // length of subtended segment = 1/2 distance between the 2 points
773  double d = 0.5 * sqrt( (sp.x - ep.x) * (sp.x - ep.x) + (sp.y - ep.y) * (sp.y - ep.y) );
774  // midpoint of the subtended segment
775  double xm = ( sp.x + ep.x ) * 0.5;
776  double ym = ( sp.y + ep.y ) * 0.5;
777  double radius = d / sin( ang * 0.5 );
778 
779  if( radius < 0.0 )
780  radius = -radius;
781 
782  // calculate the height of the triangle with base d and hypotenuse r
783  double dh2 = radius * radius - d * d;
784 
785  // this should only ever happen due to rounding errors when r == d
786  if( dh2 < 0.0 )
787  dh2 = 0.0;
788 
789  double h = sqrt( dh2 );
790 
791  if( ang < 0.0 )
792  offAng -= M_PI_2;
793  else
794  offAng += M_PI_2;
795 
796  // for angles greater than 180 deg we need to flip the
797  // direction in which the arc center is found relative
798  // to the midpoint of the subtended segment.
799  if( ang < -M_PI )
800  offAng += M_PI;
801  else if( ang > M_PI )
802  offAng -= M_PI;
803 
804  // center point
805  double cx = h * cos( offAng ) + xm;
806  double cy = h * sin( offAng ) + ym;
807 
808  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
809  segm->SetShape( S_ARC );
810  segm->SetCenter( wxPoint( Millimeter2iu( cx ), Millimeter2iu( -cy ) ) );
811 
812  if( ang < 0.0 )
813  {
814  segm->SetArcStart( wxPoint( Millimeter2iu( ep.x ), Millimeter2iu( -ep.y ) ) );
815  segm->SetAngle( RAD2DECIDEG( ang ) );
816  }
817  else
818  {
819  segm->SetArcStart( wxPoint( Millimeter2iu( sp.x ), Millimeter2iu( -sp.y ) ) );
820  segm->SetAngle( RAD2DECIDEG( -ang ) );
821  }
822 
823  segm->SetWidth( aWidth );
824 
825  m_newItemsList.push_back( segm );
826  return;
827 }
bool m_importAsfootprintGraphicItems
Definition: dxf2brd_items.h:53
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
Definition: dxf2brd_items.h:45
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:796
void SetWidth(int aWidth)
void DXF2BRD_CONVERTER::insertLine ( const wxRealPoint &  aSegStart,
const wxRealPoint &  aSegEnd,
int  aWidth 
)
private

Definition at line 732 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 addLWPolyline(), and addPolyline().

734 {
736  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
737  wxPoint segment_startpoint( Millimeter2iu( aSegStart.x ), Millimeter2iu( aSegStart.y ) );
738  wxPoint segment_endpoint( Millimeter2iu( aSegEnd.x ), Millimeter2iu( aSegEnd.y ) );
739 
740  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
741  segm->SetStart( segment_startpoint );
742  segm->SetEnd( segment_endpoint );
743  segm->SetWidth( aWidth );
744 
745  m_newItemsList.push_back( segm );
746  return;
747 }
bool m_importAsfootprintGraphicItems
Definition: dxf2brd_items.h:53
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
void SetStart(const wxPoint &aStart)
void SetEnd(const wxPoint &aEnd)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:796
void SetWidth(int aWidth)
virtual void DXF2BRD_CONVERTER::linkImage ( const DRW_ImageDef *  aData)
inlineoverrideprivatevirtual

Definition at line 168 of file dxf2brd_items.h.

168 {}
int DXF2BRD_CONVERTER::mapDim ( double  aDxfValue)
private

Definition at line 87 of file dxf2brd_items.cpp.

References m_DXF2mm.

Referenced by addMText(), and addText().

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

Definition at line 93 of file dxf2brd_items.cpp.

References m_defaultThickness, and m_DXF2mm.

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

94 {
95  // mapWidth returns the aDxfValue if aDxfWidth > 0 m_defaultThickness
96  if( aDxfWidth > 0.0 )
97  return Millimeter2iu( aDxfWidth * m_DXF2mm );
98 
99  return Millimeter2iu( m_defaultThickness );
100 }
double m_defaultThickness
Definition: dxf2brd_items.h:48
int DXF2BRD_CONVERTER::mapX ( double  aDxfCoordX)
private

Definition at line 75 of file dxf2brd_items.cpp.

References m_DXF2mm, and m_xOffset.

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

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

Definition at line 81 of file dxf2brd_items.cpp.

References m_DXF2mm, and m_yOffset.

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

82 {
83  return Millimeter2iu( m_yOffset - ( aDxfCoordY * m_DXF2mm ) );
84 }
virtual void DXF2BRD_CONVERTER::setBlock ( const int  aHandle)
inlineoverrideprivatevirtual

Definition at line 179 of file dxf2brd_items.h.

179 {}
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 100 of file dxf2brd_items.h.

Referenced by DIALOG_DXF_IMPORT::TransferDataFromWindow().

100 { 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 77 of file dxf2brd_items.h.

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

78  {
79  m_defaultThickness = aWidth;
80  }
double m_defaultThickness
Definition: dxf2brd_items.h:48
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 90 of file dxf2brd_items.h.

Referenced by DIALOG_DXF_IMPORT::TransferDataFromWindow().

91  {
92  m_xOffset = aOffsetX;
93  m_yOffset = aOffsetY;
94  }
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 598 of file dxf2brd_items.cpp.

599 {
600  wxString res;
601  int j = 0;
602 
603  for( unsigned i = 0; i<aStr.length(); ++i )
604  {
605  int c = aStr[i];
606 
607  if( c > 175 || c < 11 )
608  {
609  res.append( aStr.Mid( j, i - j ) );
610  j = i;
611 
612  switch( c )
613  {
614  case 0x0A:
615  res += wxT( "\\P" );
616  break;
617 
618  // diameter:
619 #ifdef __WINDOWS_
620  // windows, as always, is special.
621  case 0x00D8:
622 #else
623  case 0x2205:
624 #endif
625  res += wxT( "%%C" );
626  break;
627 
628  // degree:
629  case 0x00B0:
630  res += wxT( "%%D" );
631  break;
632 
633  // plus/minus
634  case 0x00B1:
635  res += wxT( "%%P" );
636  break;
637 
638  default:
639  j--;
640  break;
641  }
642 
643  j++;
644  }
645  }
646 
647  res.append( aStr.Mid( j ) );
648  return res;
649 }
wxString DXF2BRD_CONVERTER::toNativeString ( const wxString &  aData)
staticprivate

Converts a DXF encoded string into a native Unicode string.

Definition at line 652 of file dxf2brd_items.cpp.

Referenced by addMText(), and addText().

653 {
654  wxString res;
655 
656  // Ignore font tags:
657  int j = 0;
658 
659  for( unsigned i = 0; i < aData.length(); ++i )
660  {
661  if( aData[ i ] == 0x7B ) // is '{' ?
662  {
663  if( aData[ i + 1 ] == 0x5c && aData[ i + 2 ] == 0x66 ) // is "\f" ?
664  {
665  // found font tag, append parsed part
666  res.append( aData.Mid( j, i - j ) );
667 
668  // skip to ';'
669  for( unsigned k = i + 3; k < aData.length(); ++k )
670  {
671  if( aData[ k ] == 0x3B )
672  {
673  i = j = ++k;
674  break;
675  }
676  }
677 
678  // add to '}'
679  for( unsigned k = i; k < aData.length(); ++k )
680  {
681  if( aData[ k ] == 0x7D )
682  {
683  res.append( aData.Mid( i, k - i ) );
684  i = j = ++k;
685  break;
686  }
687  }
688  }
689  }
690  }
691 
692  res.append( aData.Mid( j ) );
693 
694 #if 1
695  wxRegEx regexp;
696  // Line feed:
697  regexp.Compile( wxT( "\\\\P" ) );
698  regexp.Replace( &res, wxT( "\n" ) );
699 
700  // Space:
701  regexp.Compile( wxT( "\\\\~" ) );
702  regexp.Replace( &res, wxT( " " ) );
703 
704  // diameter:
705  regexp.Compile( wxT( "%%[cC]" ) );
706 #ifdef __WINDOWS__
707  // windows, as always, is special.
708  regexp.Replace( &res, wxChar( 0xD8 ) );
709 #else
710  // Empty_set, diameter is 0x2300
711  regexp.Replace( &res, wxChar( 0x2205 ) );
712 #endif
713 
714  // degree:
715  regexp.Compile( wxT( "%%[dD]" ) );
716  regexp.Replace( &res, wxChar( 0x00B0 ) );
717  // plus/minus
718  regexp.Compile( wxT( "%%[pP]" ) );
719  regexp.Replace( &res, wxChar( 0x00B1 ) );
720 #endif
721 
722  return res;
723 }
virtual void DXF2BRD_CONVERTER::writeAppId ( )
inlineoverrideprivatevirtual

Definition at line 212 of file dxf2brd_items.h.

212 {}
virtual void DXF2BRD_CONVERTER::writeBlockRecords ( )
inlineoverrideprivatevirtual

Definition at line 204 of file dxf2brd_items.h.

204 {}
virtual void DXF2BRD_CONVERTER::writeBlocks ( )
inlineoverrideprivatevirtual

Definition at line 205 of file dxf2brd_items.h.

205 {}
virtual void DXF2BRD_CONVERTER::writeDimstyles ( )
inlineoverrideprivatevirtual

Definition at line 206 of file dxf2brd_items.h.

206 {}
virtual void DXF2BRD_CONVERTER::writeEntities ( )
inlineoverrideprivatevirtual

Definition at line 201 of file dxf2brd_items.h.

201 {}
virtual void DXF2BRD_CONVERTER::writeHeader ( DRW_Header &  aData)
inlineoverrideprivatevirtual

Definition at line 200 of file dxf2brd_items.h.

200 {}
virtual void DXF2BRD_CONVERTER::writeLayers ( )
inlineoverrideprivatevirtual

Definition at line 203 of file dxf2brd_items.h.

203 {}
void DXF2BRD_CONVERTER::writeLine ( )
private
virtual void DXF2BRD_CONVERTER::writeLTypes ( )
inlineoverrideprivatevirtual

Definition at line 202 of file dxf2brd_items.h.

202 {}
void DXF2BRD_CONVERTER::writeMtext ( )
private
virtual void DXF2BRD_CONVERTER::writeTextstyles ( )
inlineoverrideprivatevirtual

Definition at line 198 of file dxf2brd_items.h.

198 {}
virtual void DXF2BRD_CONVERTER::writeVports ( )
inlineoverrideprivatevirtual

Definition at line 199 of file dxf2brd_items.h.

199 {}

Member Data Documentation

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

Definition at line 52 of file dxf2brd_items.h.

Referenced by addHeader().

double DXF2BRD_CONVERTER::m_defaultThickness
private

Definition at line 48 of file dxf2brd_items.h.

Referenced by DXF2BRD_CONVERTER(), and mapWidth().

double DXF2BRD_CONVERTER::m_DXF2mm
private
bool DXF2BRD_CONVERTER::m_importAsfootprintGraphicItems
private
std::list<BOARD_ITEM*> DXF2BRD_CONVERTER::m_newItemsList
private
int DXF2BRD_CONVERTER::m_version
private

Definition at line 51 of file dxf2brd_items.h.

Referenced by DXF2BRD_CONVERTER().

double DXF2BRD_CONVERTER::m_xOffset
private

Definition at line 46 of file dxf2brd_items.h.

Referenced by addLWPolyline(), addPolyline(), DXF2BRD_CONVERTER(), and mapX().

double DXF2BRD_CONVERTER::m_yOffset
private

Definition at line 47 of file dxf2brd_items.h.

Referenced by addLWPolyline(), addPolyline(), DXF2BRD_CONVERTER(), and mapY().


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