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

References Dwgs_User, m_brdLayer, m_defaultThickness, m_DXF2mm, m_useModuleItems, 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;
63  m_defaultThickness = 0.1;
65  m_useModuleItems = true;
66 }
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 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 249 of file dxf2brd_items.cpp.

References PNS::angle(), m_brdLayer, m_defaultThickness, m_DXF2mm, 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().

250 {
251  DRAWSEGMENT* segm = ( m_useModuleItems ) ?
252  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
253 
254  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
255  segm->SetShape( S_ARC );
256 
257  // Init arc centre:
258  wxPoint center( mapX( data.basePoint.x ), mapY( data.basePoint.y ) );
259  segm->SetCenter( center );
260 
261  // Init arc start point
262  double arcStartx = data.radious;
263  double arcStarty = 0;
264  double startangle = data.staangle;
265  double endangle = data.endangle;
266 
267  RotatePoint( &arcStartx, &arcStarty, -RAD2DECIDEG( startangle ) );
268  wxPoint arcStart( mapX( arcStartx + data.basePoint.x ),
269  mapY( arcStarty + data.basePoint.y ) );
270  segm->SetArcStart( arcStart );
271 
272  // calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew)
273  double angle = -RAD2DECIDEG( endangle - startangle );
274 
275  if( angle > 0.0 )
276  angle -= 3600.0;
277 
278  segm->SetAngle( angle );
279 
280  segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness / m_DXF2mm
281  : data.thickness ) );
282  m_newItemsList.push_back( segm );
283 }
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 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)
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...
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:774
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 229 of file dxf2brd_items.cpp.

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

230 {
231  DRAWSEGMENT* segm = ( m_useModuleItems ) ?
232  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
233 
234  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
235  segm->SetShape( S_CIRCLE );
236  wxPoint center( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
237  segm->SetCenter( center );
238  wxPoint circle_start( mapX( aData.basePoint.x + aData.radious ), mapY( aData.basePoint.y ) );
239  segm->SetArcStart( circle_start );
240  segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm
241  : aData.thickness ) );
242  m_newItemsList.push_back( segm );
243 }
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 mapDim(double aDxfValue)
int mapY(double aDxfCoordY)
std::list< BOARD_ITEM * > m_newItemsList
Definition: dxf2brd_items.h:45
int mapX(double aDxfCoordX)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:774
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 513 of file dxf2brd_items.cpp.

References m_codePage, and m_DXF2mm.

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

References name.

106 {
107  // Not yet useful in Pcbnew.
108 #if 0
109  wxString name = wxString::FromUTF8( aData.name.c_str() );
110  wxLogMessage( name );
111 #endif
112 }
const char * name
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 115 of file dxf2brd_items.cpp.

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

116 {
117  DRAWSEGMENT* segm = ( m_useModuleItems ) ?
118  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
119 
120  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
121  wxPoint start( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
122  segm->SetStart( start );
123  wxPoint end( mapX( aData.secPoint.x ), mapY( aData.secPoint.y ) );
124  segm->SetEnd( end );
125  segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm
126  : aData.thickness ) );
127  m_newItemsList.push_back( segm );
128 }
virtual void SetLayer(PCB_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)
void SetEnd(const wxPoint &aEnd)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:774
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 181 of file dxf2brd_items.cpp.

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

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

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

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

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

287 {
288  BOARD_ITEM* brdItem;
289  EDA_TEXT* textItem;
290 
291  if( m_useModuleItems )
292  {
293  TEXTE_MODULE* modText = new TEXTE_MODULE( NULL );
294  brdItem = static_cast< BOARD_ITEM* >( modText );
295  textItem = static_cast< EDA_TEXT* >( modText );
296  }
297  else
298  {
299  TEXTE_PCB* pcbText = new TEXTE_PCB( NULL );
300  brdItem = static_cast< BOARD_ITEM* >( pcbText );
301  textItem = static_cast< EDA_TEXT* >( pcbText );
302  }
303 
304  brdItem->SetLayer( ToLAYER_ID( m_brdLayer ) );
305 
306  wxPoint refPoint( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
307  wxPoint secPoint( mapX( aData.secPoint.x ), mapY( aData.secPoint.y ) );
308 
309  if( aData.alignV != 0 || aData.alignH != 0 || aData.alignH == DRW_Text::HMiddle )
310  {
311  if( aData.alignH != DRW_Text::HAligned && aData.alignH != DRW_Text::HFit )
312  {
313  wxPoint tmp = secPoint;
314  secPoint = refPoint;
315  refPoint = tmp;
316  }
317  }
318 
319  switch( aData.alignV )
320  {
321  case DRW_Text::VBaseLine:
323  break;
324 
325  case DRW_Text::VBottom:
327  break;
328 
329  case DRW_Text::VMiddle:
331  break;
332 
333  case DRW_Text::VTop:
335  break;
336  }
337 
338  switch( aData.alignH )
339  {
340  case DRW_Text::HLeft:
342  break;
343 
344  case DRW_Text::HCenter:
346  break;
347 
348  case DRW_Text::HRight:
350  break;
351 
352  case DRW_Text::HAligned:
353  // no equivalent options in text pcb.
355  break;
356 
357  case DRW_Text::HMiddle:
358  // no equivalent options in text pcb.
360  break;
361 
362  case DRW_Text::HFit:
363  // no equivalent options in text pcb.
365  break;
366  }
367 
368 #if 0
369  wxString sty = wxString::FromUTF8( aData.style.c_str() );
370  sty = sty.ToLower();
371 
372  if( aData.textgen == 2 )
373  {
374  // Text dir = left to right;
375  } else if( aData.textgen == 4 )
376  {
377  // Text dir = top to bottom;
378  } else
379  {
380  }
381 #endif
382 
383  wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
384 
385  textItem->SetTextPos( refPoint );
386  textItem->SetTextAngle( aData.angle * 10 );
387 
388  // The 0.8 factor gives a better height/width ratio with our font
389  textItem->SetTextWidth( mapDim( aData.height * 0.8 ) );
390  textItem->SetTextHeight( mapDim( aData.height ) );
391  textItem->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm
392  : aData.thickness ) );
393  textItem->SetText( text );
394 
395  m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) );
396 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:156
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: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
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:193
void SetTextHeight(int aHeight)
Definition: eda_text.h:220
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:774
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 724 of file dxf2brd_items.cpp.

725 {
726  // TODO
727 }
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 93 of file dxf2brd_items.cpp.

Referenced by DIALOG_DXF_IMPORT::OnOKClick().

94 {
95  LOCALE_IO locale;
96  dxfRW* dxf = new dxfRW( aFile.ToUTF8() );
97  bool success = dxf->read( this, true );
98 
99  delete dxf;
100 
101  return success;
102 }
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 748 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(), and addPolyline().

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

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

732 {
733  DRAWSEGMENT* segm = ( m_useModuleItems ) ?
734  static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
735  wxPoint segment_startpoint( Millimeter2iu( aSegStart.x ), Millimeter2iu( aSegStart.y ) );
736  wxPoint segment_endpoint( Millimeter2iu( aSegEnd.x ), Millimeter2iu( aSegEnd.y ) );
737 
738  segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
739  segm->SetStart( segment_startpoint );
740  segm->SetEnd( segment_endpoint );
741  segm->SetWidth( aWidth );
742 
743  m_newItemsList.push_back( segm );
744  return;
745 }
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:774
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 87 of file dxf2brd_items.cpp.

References m_DXF2mm.

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

88 {
89  return Millimeter2iu( aDxfValue * m_DXF2mm );
90 }
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 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 596 of file dxf2brd_items.cpp.

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

Converts a DXF encoded string into a native Unicode string.

Definition at line 650 of file dxf2brd_items.cpp.

Referenced by addMText(), and addText().

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