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 ()
 
bool IsUsingModuleItems () const
 
void UseModuleItems (bool aUseModuleItems=true)
 
void SetOffset (double aOffsetX, double aOffsetY)
 Set the coordinate offset between the importede 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)
 
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_useModuleItems
 

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 56 of file dxf2brd_items.cpp.

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

56  : DRW_Interface()
57 {
58  m_xOffset = 0.0; // X coord offset for conversion (in mm)
59  m_yOffset = 0.0; // Y coord offset for conversion (in mm)
60  m_DXF2mm = 1.0; // The scale factor to convert DXF units to mm
61  m_version = 0;
62  m_defaultThickness = 0.1;
64  m_useModuleItems = true;
65 }
double m_defaultThickness
Definition: dxf2brd_items.h:48
DXF2BRD_CONVERTER::~DXF2BRD_CONVERTER ( )

Definition at line 68 of file dxf2brd_items.cpp.

69 {
70 }

Member Function Documentation

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

Definition at line 147 of file dxf2brd_items.h.

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

Definition at line 188 of file dxf2brd_items.h.

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

Definition at line 246 of file dxf2brd_items.cpp.

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

247 {
248  DRAWSEGMENT* segm = ( m_useModuleItems ) ?
249  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
250 
251  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
252  segm->SetShape( S_ARC );
253 
254  // Init arc centre:
255  wxPoint center( mapX( data.basePoint.x ), mapY( data.basePoint.y ) );
256  segm->SetCenter( center );
257 
258  // Init arc start point
259  double arcStartx = data.radious;
260  double arcStarty = 0;
261  double startangle = data.staangle;
262  double endangle = data.endangle;
263 
264  RotatePoint( &arcStartx, &arcStarty, -RAD2DECIDEG( startangle ) );
265  wxPoint arcStart( mapX( arcStartx + data.basePoint.x ),
266  mapY( arcStarty + data.basePoint.y ) );
267  segm->SetArcStart( arcStart );
268 
269  // calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew)
270  double angle = -RAD2DECIDEG( endangle - startangle );
271 
272  if( angle > 0.0 )
273  angle -= 3600.0;
274 
275  segm->SetAngle( angle );
276 
277  segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness : data.thickness ) );
278  m_newItemsList.push_back( segm );
279 }
void SetShape(STROKE_T aShape)
void SetArcStart(const wxPoint &aArcStartPoint)
Initialize the start arc point.
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
double RAD2DECIDEG(double rad)
Definition: trigo.h:196
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
int mapDim(double aDxfValue)
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
Arcs (with rounded ends)
int mapX(double aDxfCoordX)
LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:766
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...
double m_defaultThickness
Definition: dxf2brd_items.h:48
void SetWidth(int aWidth)
virtual void DXF2BRD_CONVERTER::addBlock ( const DRW_Block &  aData)
inlineoverrideprivatevirtual

Definition at line 117 of file dxf2brd_items.h.

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

Definition at line 227 of file dxf2brd_items.cpp.

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

228 {
229  DRAWSEGMENT* segm = ( m_useModuleItems ) ?
230  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
231 
232  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
233  segm->SetShape( S_CIRCLE );
234  wxPoint center( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
235  segm->SetCenter( center );
236  wxPoint circle_start( mapX( aData.basePoint.x + aData.radious ), mapY( aData.basePoint.y ) );
237  segm->SetArcStart( circle_start );
238  segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) );
239  m_newItemsList.push_back( segm );
240 }
void SetShape(STROKE_T aShape)
void SetArcStart(const wxPoint &aArcStartPoint)
Initialize the start arc point.
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
int mapDim(double aDxfValue)
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
int mapX(double aDxfCoordX)
LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:766
double m_defaultThickness
Definition: dxf2brd_items.h:48
void SetWidth(int aWidth)
virtual void DXF2BRD_CONVERTER::addComment ( const char *  )
inlineoverrideprivatevirtual

Definition at line 148 of file dxf2brd_items.h.

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

Definition at line 135 of file dxf2brd_items.h.

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

Definition at line 139 of file dxf2brd_items.h.

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

Definition at line 140 of file dxf2brd_items.h.

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

Definition at line 138 of file dxf2brd_items.h.

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

Definition at line 136 of file dxf2brd_items.h.

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

Definition at line 141 of file dxf2brd_items.h.

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

Definition at line 137 of file dxf2brd_items.h.

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

Definition at line 116 of file dxf2brd_items.h.

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

Definition at line 125 of file dxf2brd_items.h.

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

Definition at line 143 of file dxf2brd_items.h.

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

Definition at line 507 of file dxf2brd_items.cpp.

References m_codePage, and m_DXF2mm.

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

Definition at line 144 of file dxf2brd_items.h.

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

Definition at line 131 of file dxf2brd_items.h.

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

Definition at line 130 of file dxf2brd_items.h.

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

Definition at line 103 of file dxf2brd_items.cpp.

104 {
105  // Not yet useful in Pcbnew.
106 #if 0
107  wxString name = wxString::FromUTF8( aData.name.c_str() );
108  wxLogMessage( name );
109 #endif
110 }
virtual void DXF2BRD_CONVERTER::addLeader ( const DRW_Leader *  aData)
inlineoverrideprivatevirtual

Definition at line 142 of file dxf2brd_items.h.

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

Definition at line 113 of file dxf2brd_items.cpp.

References m_brdLayer, m_defaultThickness, m_newItemsList, m_useModuleItems, mapDim(), mapX(), mapY(), DRAWSEGMENT::SetEnd(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetStart(), DRAWSEGMENT::SetWidth(), and ToLAYER_ID().

114 {
115  DRAWSEGMENT* segm = ( m_useModuleItems ) ?
116  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
117 
118  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
119  wxPoint start( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
120  segm->SetStart( start );
121  wxPoint end( mapX( aData.secPoint.x ), mapY( aData.secPoint.y ) );
122  segm->SetEnd( end );
123  segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) );
124  m_newItemsList.push_back( segm );
125 }
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
int mapDim(double aDxfValue)
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
int mapX(double aDxfCoordX)
void SetStart(const wxPoint &aStart)
LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:766
void SetEnd(const wxPoint &aEnd)
double m_defaultThickness
Definition: dxf2brd_items.h:48
void SetWidth(int aWidth)
virtual void DXF2BRD_CONVERTER::addLType ( const DRW_LType &  aData)
inlineoverrideprivatevirtual

Definition at line 114 of file dxf2brd_items.h.

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

Definition at line 179 of file dxf2brd_items.cpp.

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

180 {
181  // Currently, Pcbnew does not know polylines, for boards.
182  // So we have to convert a polyline to a set of segments.
183  // The import is a simplified import: the width of segment is
184  // (obviously constant and is the width of the DRW_LWPolyline.
185  // the variable width of each vertex (when exists) is not used.
186  wxRealPoint seg_start;
187  wxRealPoint poly_start;
188  double bulge = 0.0;
189  int lineWidth = mapDim( aData.thickness == 0 ? m_defaultThickness
190  : aData.thickness );
191 
192  for( unsigned ii = 0; ii < aData.vertlist.size(); ii++ )
193  {
194  DRW_Vertex2D* vertex = aData.vertlist[ii];
195 
196  if( ii == 0 )
197  {
198  seg_start.x = m_xOffset + vertex->x * m_DXF2mm;
199  seg_start.y = m_yOffset - vertex->y * m_DXF2mm;
200  bulge = vertex->bulge;
201  poly_start = seg_start;
202  continue;
203  }
204 
205  wxRealPoint seg_end( m_xOffset + vertex->x * m_DXF2mm, m_yOffset - vertex->y * m_DXF2mm );
206 
207  if( std::abs( bulge ) < MIN_BULGE )
208  insertLine( seg_start, seg_end, lineWidth );
209  else
210  insertArc( seg_start, seg_end, bulge, lineWidth );
211 
212  bulge = vertex->bulge;
213  seg_start = seg_end;
214  }
215 
216  // LWPolyline flags bit 0 indicates closed (1) or open (0) polyline
217  if( aData.flags & 1 )
218  {
219  if( std::abs( bulge ) < MIN_BULGE )
220  insertLine( seg_start, poly_start, lineWidth );
221  else
222  insertArc( seg_start, poly_start, bulge, lineWidth );
223  }
224 }
void insertArc(const wxRealPoint &aSegStart, const wxRealPoint &aSegEnd, double aBulge, int aWidth)
#define abs(a)
Definition: auxiliary.h:84
int mapDim(double aDxfValue)
#define MIN_BULGE
void insertLine(const wxRealPoint &aSegStart, const wxRealPoint &aSegEnd, int aWidth)
double m_defaultThickness
Definition: dxf2brd_items.h:48
void DXF2BRD_CONVERTER::addMText ( const DRW_MText &  aData)
overrideprivatevirtual

Definition at line 394 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_defaultThickness, m_newItemsList, m_useModuleItems, mapDim(), 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().

395 {
396  wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
397  wxString attrib, tmp;
398 
399  /* Some texts start by '\' and have formating chars (font name, font option...)
400  * ending with ';'
401  * Here are some mtext formatting codes:
402  * Format code Purpose
403  * \0...\o Turns overline on and off
404  * \L...\l Turns underline on and off
405  * \~ Inserts a nonbreaking space
406  \\ Inserts a backslash
407  \\\{...\} Inserts an opening and closing brace
408  \\ \File name; Changes to the specified font file
409  \\ \Hvalue; Changes to the text height specified in drawing units
410  \\ \Hvaluex; Changes the text height to a multiple of the current text height
411  \\ \S...^...; Stacks the subsequent text at the \, #, or ^ symbol
412  \\ \Tvalue; Adjusts the space between characters, from.75 to 4 times
413  \\ \Qangle; Changes obliquing angle
414  \\ \Wvalue; Changes width factor to produce wide text
415  \\ \A Sets the alignment value; valid values: 0, 1, 2 (bottom, center, top) while( text.StartsWith( wxT("\\") ) )
416  */
417  while( text.StartsWith( wxT( "\\" ) ) )
418  {
419  attrib << text.BeforeFirst( ';' );
420  tmp = text.AfterFirst( ';' );
421  text = tmp;
422  }
423 
424  BOARD_ITEM* brdItem;
425  EDA_TEXT* textItem;
426 
427  if( m_useModuleItems )
428  {
429  TEXTE_MODULE* modText = new TEXTE_MODULE( NULL );
430  brdItem = static_cast< BOARD_ITEM* >( modText );
431  textItem = static_cast< EDA_TEXT* >( modText );
432  }
433  else
434  {
435  TEXTE_PCB* pcbText = new TEXTE_PCB( NULL );
436  brdItem = static_cast< BOARD_ITEM* >( pcbText );
437  textItem = static_cast< EDA_TEXT* >( pcbText );
438  }
439 
440  brdItem->SetLayer( ToLAYER_ID( m_brdLayer ) );
441  wxPoint textpos( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
442 
443  textItem->SetTextPos( textpos );
444  textItem->SetTextAngle( aData.angle * 10 );
445 
446  // The 0.8 factor gives a better height/width ratio with our font
447  textItem->SetTextWidth( mapDim( aData.height * 0.8 ) );
448  textItem->SetTextHeight( mapDim( aData.height ) );
449  textItem->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) );
450  textItem->SetText( text );
451 
452  // Initialize text justifications:
453  if( aData.textgen <= 3 )
454  {
456  }
457  else if( aData.textgen <= 6 )
458  {
460  }
461  else
462  {
464  }
465 
466  if( aData.textgen % 3 == 1 )
467  {
469  }
470  else if( aData.textgen % 3 == 2 )
471  {
473  }
474  else
475  {
477  }
478 
479 #if 0 // These setting have no mening in Pcbnew
480  if( data.alignH == 1 )
481  {
482  // Text is left to right;
483  }
484  else if( data.alignH == 3 )
485  {
486  // Text is top to bottom;
487  }
488  else
489  {
490  // use ByStyle;
491  }
492 
493  if( aData.alignV == 1 )
494  {
495  // use AtLeast;
496  }
497  else
498  {
499  // useExact;
500  }
501 #endif
502 
503  m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) );
504 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:156
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
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:114
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:194
int mapX(double aDxfCoordX)
void SetTextWidth(int aWidth)
Definition: eda_text.h:217
LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:766
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
void SetTextHeight(int aHeight)
Definition: eda_text.h:220
double m_defaultThickness
Definition: dxf2brd_items.h:48
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
virtual void DXF2BRD_CONVERTER::addPoint ( const DRW_Point &  aData)
inlineoverrideprivatevirtual

Definition at line 119 of file dxf2brd_items.h.

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

Definition at line 127 of file dxf2brd_items.cpp.

References m_brdLayer, m_defaultThickness, m_newItemsList, m_useModuleItems, mapDim(), mapX(), mapY(), DRAWSEGMENT::SetEnd(), BOARD_ITEM::SetLayer(), DRAWSEGMENT::SetStart(), DRAWSEGMENT::SetWidth(), ToLAYER_ID(), wxPoint::x, and wxPoint::y.

128 {
129  // Currently, Pcbnew does not know polylines, for boards.
130  // So we have to convert a polyline to a set of segments.
131  // Obviously, the z coordinate is ignored
132 
133  wxPoint polyline_startpoint;
134  wxPoint segment_startpoint;
135 
136  for( unsigned ii = 0; ii < aData.vertlist.size(); ii++ )
137  {
138  DRW_Vertex* vertex = aData.vertlist[ii];
139 
140  if( ii == 0 )
141  {
142  segment_startpoint.x = mapX( vertex->basePoint.x );
143  segment_startpoint.y = mapY( vertex->basePoint.y );
144  polyline_startpoint = segment_startpoint;
145  continue;
146  }
147 
148  DRAWSEGMENT* segm = ( m_useModuleItems ) ?
149  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) :
150  new DRAWSEGMENT;
151 
152  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
153  segm->SetStart( segment_startpoint );
154  wxPoint segment_endpoint( mapX( vertex->basePoint.x ), mapY( vertex->basePoint.y ) );
155  segm->SetEnd( segment_endpoint );
156  segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness
157  : aData.thickness ) );
158  m_newItemsList.push_back( segm );
159  segment_startpoint = segment_endpoint;
160  }
161 
162  // Polyline flags bit 0 indicates closed (1) or open (0) polyline
163  if( aData.flags & 1 )
164  {
165  DRAWSEGMENT* closing_segm = ( m_useModuleItems ) ?
166  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) :
167  new DRAWSEGMENT;
168 
169  closing_segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
170  closing_segm->SetStart( segment_startpoint );
171  closing_segm->SetEnd( polyline_startpoint );
172  closing_segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness
173  : aData.thickness ) );
174  m_newItemsList.push_back( closing_segm );
175  }
176 }
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
int mapDim(double aDxfValue)
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
int mapX(double aDxfCoordX)
void SetStart(const wxPoint &aStart)
LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:766
void SetEnd(const wxPoint &aEnd)
double m_defaultThickness
Definition: dxf2brd_items.h:48
void SetWidth(int aWidth)
virtual void DXF2BRD_CONVERTER::addRay ( const DRW_Ray &  aData)
inlineoverrideprivatevirtual

Definition at line 121 of file dxf2brd_items.h.

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

Definition at line 133 of file dxf2brd_items.h.

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

Definition at line 129 of file dxf2brd_items.h.

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

Definition at line 282 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_defaultThickness, m_newItemsList, m_useModuleItems, mapDim(), 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().

283 {
284  BOARD_ITEM* brdItem;
285  EDA_TEXT* textItem;
286 
287  if( m_useModuleItems )
288  {
289  TEXTE_MODULE* modText = new TEXTE_MODULE( NULL );
290  brdItem = static_cast< BOARD_ITEM* >( modText );
291  textItem = static_cast< EDA_TEXT* >( modText );
292  }
293  else
294  {
295  TEXTE_PCB* pcbText = new TEXTE_PCB( NULL );
296  brdItem = static_cast< BOARD_ITEM* >( pcbText );
297  textItem = static_cast< EDA_TEXT* >( pcbText );
298  }
299 
300  brdItem->SetLayer( ToLAYER_ID( m_brdLayer ) );
301 
302  wxPoint refPoint( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
303  wxPoint secPoint( mapX( aData.secPoint.x ), mapY( aData.secPoint.y ) );
304 
305  if( aData.alignV != 0 || aData.alignH != 0 || aData.alignH == DRW_Text::HMiddle )
306  {
307  if( aData.alignH != DRW_Text::HAligned && aData.alignH != DRW_Text::HFit )
308  {
309  wxPoint tmp = secPoint;
310  secPoint = refPoint;
311  refPoint = tmp;
312  }
313  }
314 
315  switch( aData.alignV )
316  {
317  case DRW_Text::VBaseLine:
319  break;
320 
321  case DRW_Text::VBottom:
323  break;
324 
325  case DRW_Text::VMiddle:
327  break;
328 
329  case DRW_Text::VTop:
331  break;
332  }
333 
334  switch( aData.alignH )
335  {
336  case DRW_Text::HLeft:
338  break;
339 
340  case DRW_Text::HCenter:
342  break;
343 
344  case DRW_Text::HRight:
346  break;
347 
348  case DRW_Text::HAligned:
349  // no equivalent options in text pcb.
351  break;
352 
353  case DRW_Text::HMiddle:
354  // no equivalent options in text pcb.
356  break;
357 
358  case DRW_Text::HFit:
359  // no equivalent options in text pcb.
361  break;
362  }
363 
364 #if 0
365  wxString sty = wxString::FromUTF8( aData.style.c_str() );
366  sty = sty.ToLower();
367 
368  if( aData.textgen == 2 )
369  {
370  // Text dir = left to right;
371  } else if( aData.textgen == 4 )
372  {
373  // Text dir = top to bottom;
374  } else
375  {
376  }
377 #endif
378 
379  wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
380 
381  textItem->SetTextPos( refPoint );
382  textItem->SetTextAngle( aData.angle * 10 );
383 
384  // The 0.8 factor gives a better height/width ratio with our font
385  textItem->SetTextWidth( mapDim( aData.height * 0.8 ) );
386  textItem->SetTextHeight( mapDim( aData.height ) );
387  textItem->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) );
388  textItem->SetText( text );
389 
390  m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) );
391 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:156
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
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:114
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:194
int mapX(double aDxfCoordX)
void SetTextWidth(int aWidth)
Definition: eda_text.h:217
LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:766
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
void SetTextHeight(int aHeight)
Definition: eda_text.h:220
double m_defaultThickness
Definition: dxf2brd_items.h:48
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:148
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
void DXF2BRD_CONVERTER::addTextStyle ( const DRW_Textstyle &  aData)
overrideprivatevirtual

Definition at line 718 of file dxf2brd_items.cpp.

719 {
720  // TODO
721 }
virtual void DXF2BRD_CONVERTER::addTrace ( const DRW_Trace &  aData)
inlineoverrideprivatevirtual

Definition at line 132 of file dxf2brd_items.h.

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

Definition at line 154 of file dxf2brd_items.h.

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

Definition at line 150 of file dxf2brd_items.h.

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

Definition at line 122 of file dxf2brd_items.h.

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

Definition at line 118 of file dxf2brd_items.h.

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

Definition at line 93 of file dxf2brd_items.h.

References m_newItemsList.

Referenced by DIALOG_DXF_IMPORT::GetImportedItems().

94  {
95  return m_newItemsList;
96  }
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
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 92 of file dxf2brd_items.cpp.

Referenced by DIALOG_DXF_IMPORT::OnOKClick().

93 {
94  dxfRW* dxf = new dxfRW( aFile.ToUTF8() );
95  bool success = dxf->read( this, true );
96 
97  delete dxf;
98 
99  return success;
100 }
void DXF2BRD_CONVERTER::insertArc ( const wxRealPoint &  aSegStart,
const wxRealPoint &  aSegEnd,
double  aBulge,
int  aWidth 
)
private

Definition at line 742 of file dxf2brd_items.cpp.

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

Referenced by addLWPolyline().

744 {
745  DRAWSEGMENT* segm = ( m_useModuleItems ) ?
746  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
747 
748  wxPoint segment_startpoint( Millimeter2iu( aSegStart.x ), Millimeter2iu( aSegStart.y ) );
749  wxPoint segment_endpoint( Millimeter2iu( aSegEnd.x ), Millimeter2iu( aSegEnd.y ) );
750 
751  // ensure aBulge represents an angle from +/- ( 0 .. approx 359.8 deg )
752  if( aBulge < -2000.0 )
753  aBulge = -2000.0;
754  else if( aBulge > 2000.0 )
755  aBulge = 2000.0;
756 
757  double ang = 4.0 * atan( aBulge );
758 
759  // reflect the Y values to put everything in a RHCS
760  wxRealPoint sp( aSegStart.x, -aSegStart.y );
761  wxRealPoint ep( aSegEnd.x, -aSegEnd.y );
762  // angle from end->start
763  double offAng = atan2( ep.y - sp.y, ep.x - sp.x );
764  // length of subtended segment = 1/2 distance between the 2 points
765  double d = 0.5 * sqrt( (sp.x - ep.x) * (sp.x - ep.x) + (sp.y - ep.y) * (sp.y - ep.y) );
766  // midpoint of the subtended segment
767  double xm = ( sp.x + ep.x ) * 0.5;
768  double ym = ( sp.y + ep.y ) * 0.5;
769  double radius = d / sin( ang * 0.5 );
770 
771  if( radius < 0.0 )
772  radius = -radius;
773 
774  // calculate the height of the triangle with base d and hypotenuse r
775  double dh2 = radius * radius - d * d;
776 
777  // this should only ever happen due to rounding errors when r == d
778  if( dh2 < 0.0 )
779  dh2 = 0.0;
780 
781  double h = sqrt( dh2 );
782 
783  if( ang < 0.0 )
784  offAng -= M_PI_2;
785  else
786  offAng += M_PI_2;
787 
788  // for angles greater than 180 deg we need to flip the
789  // direction in which the arc center is found relative
790  // to the midpoint of the subtended segment.
791  if( ang < -M_PI )
792  offAng += M_PI;
793  else if( ang > M_PI )
794  offAng -= M_PI;
795 
796  // center point
797  double cx = h * cos( offAng ) + xm;
798  double cy = h * sin( offAng ) + ym;
799 
800  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
801  segm->SetShape( S_ARC );
802  segm->SetCenter( wxPoint( Millimeter2iu( cx ), Millimeter2iu( -cy ) ) );
803 
804  if( ang < 0.0 )
805  {
806  segm->SetArcStart( wxPoint( Millimeter2iu( ep.x ), Millimeter2iu( -ep.y ) ) );
807  segm->SetAngle( RAD2DECIDEG( ang ) );
808  }
809  else
810  {
811  segm->SetArcStart( wxPoint( Millimeter2iu( sp.x ), Millimeter2iu( -sp.y ) ) );
812  segm->SetAngle( RAD2DECIDEG( -ang ) );
813  }
814 
815  segm->SetWidth( aWidth );
816 
817  m_newItemsList.push_back( segm );
818  return;
819 }
void SetShape(STROKE_T aShape)
void SetArcStart(const wxPoint &aArcStartPoint)
Initialize the start arc point.
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
double RAD2DECIDEG(double rad)
Definition: trigo.h:196
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
Arcs (with rounded ends)
LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:766
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
void SetWidth(int aWidth)
void DXF2BRD_CONVERTER::insertLine ( const wxRealPoint &  aSegStart,
const wxRealPoint &  aSegEnd,
int  aWidth 
)
private

Definition at line 724 of file dxf2brd_items.cpp.

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

Referenced by addLWPolyline().

726 {
727  DRAWSEGMENT* segm = ( m_useModuleItems ) ?
728  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
729  wxPoint segment_startpoint( Millimeter2iu( aSegStart.x ), Millimeter2iu( aSegStart.y ) );
730  wxPoint segment_endpoint( Millimeter2iu( aSegEnd.x ), Millimeter2iu( aSegEnd.y ) );
731 
732  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
733  segm->SetStart( segment_startpoint );
734  segm->SetEnd( segment_endpoint );
735  segm->SetWidth( aWidth );
736 
737  m_newItemsList.push_back( segm );
738  return;
739 }
virtual void SetLayer(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)
LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:766
void SetEnd(const wxPoint &aEnd)
void SetWidth(int aWidth)
bool DXF2BRD_CONVERTER::IsUsingModuleItems ( ) const
inline

Definition at line 59 of file dxf2brd_items.h.

References m_useModuleItems.

59 { return m_useModuleItems; }
virtual void DXF2BRD_CONVERTER::linkImage ( const DRW_ImageDef *  aData)
inlineoverrideprivatevirtual

Definition at line 145 of file dxf2brd_items.h.

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

Definition at line 86 of file dxf2brd_items.cpp.

References m_DXF2mm.

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

87 {
88  return Millimeter2iu( aDxfValue * m_DXF2mm );
89 }
int DXF2BRD_CONVERTER::mapX ( double  aDxfCoordX)
private

Definition at line 74 of file dxf2brd_items.cpp.

References m_DXF2mm, and m_xOffset.

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

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

Definition at line 80 of file dxf2brd_items.cpp.

References m_DXF2mm, and m_yOffset.

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

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

Definition at line 156 of file dxf2brd_items.h.

156 {}
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 80 of file dxf2brd_items.h.

Referenced by DIALOG_DXF_IMPORT::OnOKClick().

80 { m_brdLayer = aBrdLayer; }
void DXF2BRD_CONVERTER::SetOffset ( double  aOffsetX,
double  aOffsetY 
)
inline

Set the coordinate offset between the importede 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 70 of file dxf2brd_items.h.

Referenced by DIALOG_DXF_IMPORT::OnOKClick().

71  {
72  m_xOffset = aOffsetX;
73  m_yOffset = aOffsetY;
74  }
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 590 of file dxf2brd_items.cpp.

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

Converts a DXF encoded string into a native Unicode string.

Definition at line 644 of file dxf2brd_items.cpp.

Referenced by addMText(), and addText().

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

Definition at line 60 of file dxf2brd_items.h.

Referenced by DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT().

60 { m_useModuleItems = aUseModuleItems; }
virtual void DXF2BRD_CONVERTER::writeAppId ( )
inlineoverrideprivatevirtual

Definition at line 189 of file dxf2brd_items.h.

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

Definition at line 181 of file dxf2brd_items.h.

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

Definition at line 182 of file dxf2brd_items.h.

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

Definition at line 183 of file dxf2brd_items.h.

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

Definition at line 178 of file dxf2brd_items.h.

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

Definition at line 177 of file dxf2brd_items.h.

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

Definition at line 180 of file dxf2brd_items.h.

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

Definition at line 179 of file dxf2brd_items.h.

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

Definition at line 175 of file dxf2brd_items.h.

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

Definition at line 176 of file dxf2brd_items.h.

176 {}

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
double DXF2BRD_CONVERTER::m_DXF2mm
private

Definition at line 49 of file dxf2brd_items.h.

Referenced by addHeader(), addLWPolyline(), DXF2BRD_CONVERTER(), mapDim(), mapX(), and mapY().

std::list<BOARD_ITEM*> DXF2BRD_CONVERTER::m_newItemsList
private
bool DXF2BRD_CONVERTER::m_useModuleItems
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(), DXF2BRD_CONVERTER(), and mapX().

double DXF2BRD_CONVERTER::m_yOffset
private

Definition at line 47 of file dxf2brd_items.h.

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


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