2013-10-24 16:44:38 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
// The DXF reader lib (libdxfrw) comes from LibreCAD project, a 2D CAD program
|
|
|
|
// libdxfrw can be found on http://sourceforge.net/projects/libdxfrw/
|
|
|
|
// or (latest sources) on
|
|
|
|
// https://github.com/LibreCAD/LibreCAD/tree/master/libraries/libdxfrw/src
|
|
|
|
//
|
|
|
|
// There is no doc to use it, but have a look to
|
|
|
|
// https://github.com/LibreCAD/LibreCAD/blob/master/librecad/src/lib/filters/rs_filterdxf.cpp
|
|
|
|
// and https://github.com/LibreCAD/LibreCAD/blob/master/librecad/src/lib/filters/rs_filterdxf.h
|
|
|
|
// Each time a dxf entity is read, a "call back" fuction is called
|
|
|
|
// like void DXF2BRD_CONVERTER::addLine( const DRW_Line& data ) when a line is read.
|
|
|
|
// this function just add the BOARD entity from dxf parameters (start and end point ...)
|
|
|
|
|
|
|
|
|
|
|
|
#include "libdxfrw.h"
|
|
|
|
#include "dxf2brd_items.h"
|
|
|
|
#include <wx/arrstr.h>
|
|
|
|
#include <wx/regex.h>
|
|
|
|
|
|
|
|
#include <trigo.h>
|
2013-12-19 11:33:57 +00:00
|
|
|
#include <macros.h>
|
2013-10-24 16:44:38 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_drawsegment.h>
|
|
|
|
#include <class_pcb_text.h>
|
2013-12-19 11:33:57 +00:00
|
|
|
#include <convert_from_iu.h>
|
2013-10-24 16:44:38 +00:00
|
|
|
|
|
|
|
DXF2BRD_CONVERTER::DXF2BRD_CONVERTER() : DRW_Interface()
|
|
|
|
{
|
|
|
|
m_xOffset = 0.0; // X coord offset for conversion (in mm)
|
|
|
|
m_yOffset = 0.0; // Y coord offset for conversion (in mm)
|
|
|
|
m_Dfx2mm = 1.0; // The scale factor to convert DXF units to mm
|
|
|
|
m_version = 0;
|
|
|
|
m_defaultThickness = 0.1;
|
2014-06-24 16:17:18 +00:00
|
|
|
m_brdLayer = Dwgs_User;
|
2013-10-24 16:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DXF2BRD_CONVERTER::~DXF2BRD_CONVERTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// coordinate conversions from dxf to internal units
|
|
|
|
int DXF2BRD_CONVERTER::mapX( double aDxfCoordX )
|
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
return Millimeter2iu( m_xOffset + ( aDxfCoordX * m_Dfx2mm ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DXF2BRD_CONVERTER::mapY( double aDxfCoordY )
|
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
return Millimeter2iu( m_yOffset - ( aDxfCoordY * m_Dfx2mm ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DXF2BRD_CONVERTER::mapDim( double aDxfValue )
|
|
|
|
{
|
|
|
|
return Millimeter2iu( aDxfValue * m_Dfx2mm );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
bool DXF2BRD_CONVERTER::ImportDxfFile( const wxString& aFile )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-02-02 09:07:02 +00:00
|
|
|
dxfRW* dxf = new dxfRW( aFile.ToUTF8() );
|
|
|
|
bool success = dxf->read( this, true );
|
2013-10-24 16:44:38 +00:00
|
|
|
|
2014-02-02 09:07:02 +00:00
|
|
|
delete dxf;
|
2013-10-24 16:44:38 +00:00
|
|
|
|
2014-02-02 09:07:02 +00:00
|
|
|
return success;
|
2013-10-24 16:44:38 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
|
2013-10-30 12:14:45 +00:00
|
|
|
/*
|
2013-10-24 16:44:38 +00:00
|
|
|
* Implementation of the method which handles layers.
|
|
|
|
*/
|
2014-07-09 12:41:52 +00:00
|
|
|
void DXF2BRD_CONVERTER::addLayer( const DRW_Layer& aData )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2013-10-25 12:16:18 +00:00
|
|
|
// Not yet useful in Pcbnew.
|
2013-10-24 16:44:38 +00:00
|
|
|
#if 0
|
2014-07-09 12:41:52 +00:00
|
|
|
wxString name = wxString::FromUTF8( aData.name.c_str() );
|
2013-10-24 16:44:38 +00:00
|
|
|
wxLogMessage( name );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Import line entities.
|
|
|
|
*/
|
2014-07-09 12:41:52 +00:00
|
|
|
void DXF2BRD_CONVERTER::addLine( const DRW_Line& aData )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-07-09 13:02:56 +00:00
|
|
|
DRAWSEGMENT* segm = new DRAWSEGMENT;
|
2013-10-24 16:44:38 +00:00
|
|
|
|
2014-06-29 13:05:51 +00:00
|
|
|
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
2014-07-09 12:41:52 +00:00
|
|
|
wxPoint start( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
segm->SetStart( start );
|
2014-07-09 12:41:52 +00:00
|
|
|
wxPoint end( mapX( aData.secPoint.x ), mapY( aData.secPoint.y ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
segm->SetEnd( end );
|
2014-07-09 12:41:52 +00:00
|
|
|
segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_newItemsList.push_back( segm );
|
2013-10-24 16:44:38 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
void DXF2BRD_CONVERTER::addPolyline(const DRW_Polyline& aData )
|
2014-06-24 18:04:16 +00:00
|
|
|
{
|
|
|
|
// Currently, Pcbnew does not know polylines, for boards.
|
|
|
|
// So we have to convert a polyline to a set of segments.
|
|
|
|
// Obviously, the z coordinate is ignored
|
|
|
|
|
|
|
|
wxPoint startpoint;
|
2014-06-30 06:44:46 +00:00
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
for( unsigned ii = 0; ii < aData.vertlist.size(); ii++ )
|
2014-06-24 18:04:16 +00:00
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
DRW_Vertex* vertex = aData.vertlist[ii];
|
2014-06-24 18:04:16 +00:00
|
|
|
|
|
|
|
if( ii == 0 )
|
|
|
|
{
|
|
|
|
startpoint.x = mapX( vertex->basePoint.x );
|
|
|
|
startpoint.y = mapY( vertex->basePoint.y );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
DRAWSEGMENT* segm = new DRAWSEGMENT( NULL );
|
2014-06-30 06:44:46 +00:00
|
|
|
|
|
|
|
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
2014-06-24 18:04:16 +00:00
|
|
|
segm->SetStart( startpoint );
|
|
|
|
wxPoint endpoint( mapX( vertex->basePoint.x ), mapY( vertex->basePoint.y ) );
|
|
|
|
segm->SetEnd( endpoint );
|
2014-07-09 12:41:52 +00:00
|
|
|
segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness
|
|
|
|
: aData.thickness ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_newItemsList.push_back( segm );
|
2014-06-24 18:04:16 +00:00
|
|
|
startpoint = endpoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
void DXF2BRD_CONVERTER::addLWPolyline(const DRW_LWPolyline& aData )
|
2014-06-24 18:04:16 +00:00
|
|
|
{
|
|
|
|
// Currently, Pcbnew does not know polylines, for boards.
|
|
|
|
// So we have to convert a polyline to a set of segments.
|
|
|
|
// The import is a simplified import: the width of segment is
|
|
|
|
// (obviously contant and is the width of the DRW_LWPolyline.
|
|
|
|
// the variable width of each vertex (when exists) is not used.
|
|
|
|
wxPoint startpoint;
|
2014-06-30 06:44:46 +00:00
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
for( unsigned ii = 0; ii < aData.vertlist.size(); ii++ )
|
2014-06-24 18:04:16 +00:00
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
DRW_Vertex2D* vertex = aData.vertlist[ii];
|
2014-06-24 18:04:16 +00:00
|
|
|
|
|
|
|
if( ii == 0 )
|
|
|
|
{
|
|
|
|
startpoint.x = mapX( vertex->x );
|
|
|
|
startpoint.y = mapY( vertex->y );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
DRAWSEGMENT* segm = new DRAWSEGMENT( NULL );
|
2014-06-30 06:44:46 +00:00
|
|
|
|
|
|
|
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
2014-06-24 18:04:16 +00:00
|
|
|
segm->SetStart( startpoint );
|
|
|
|
wxPoint endpoint( mapX( vertex->x ), mapY( vertex->y ) );
|
|
|
|
segm->SetEnd( endpoint );
|
2014-07-09 12:41:52 +00:00
|
|
|
segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness
|
|
|
|
: aData.thickness ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_newItemsList.push_back( segm );
|
2014-06-24 18:04:16 +00:00
|
|
|
startpoint = endpoint;
|
|
|
|
}
|
|
|
|
}
|
2013-10-24 16:44:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Import Circle entities.
|
|
|
|
*/
|
2014-07-09 12:41:52 +00:00
|
|
|
void DXF2BRD_CONVERTER::addCircle( const DRW_Circle& aData )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-07-09 13:02:56 +00:00
|
|
|
DRAWSEGMENT* segm = new DRAWSEGMENT;
|
2013-10-24 16:44:38 +00:00
|
|
|
|
2014-06-29 13:05:51 +00:00
|
|
|
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
segm->SetShape( S_CIRCLE );
|
2014-07-09 12:41:52 +00:00
|
|
|
wxPoint center( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
|
2013-12-19 11:33:57 +00:00
|
|
|
segm->SetCenter( center );
|
2014-07-09 12:41:52 +00:00
|
|
|
wxPoint circle_start( mapX( aData.basePoint.x + aData.radious ), mapY( aData.basePoint.y ) );
|
2013-12-19 11:33:57 +00:00
|
|
|
segm->SetArcStart( circle_start );
|
2014-07-09 12:41:52 +00:00
|
|
|
segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_newItemsList.push_back( segm );
|
2013-10-24 16:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Import Arc entities.
|
|
|
|
*/
|
|
|
|
void DXF2BRD_CONVERTER::addArc( const DRW_Arc& data )
|
|
|
|
{
|
2014-07-09 13:02:56 +00:00
|
|
|
DRAWSEGMENT* segm = new DRAWSEGMENT;
|
2013-10-24 16:44:38 +00:00
|
|
|
|
2014-06-29 13:05:51 +00:00
|
|
|
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
segm->SetShape( S_ARC );
|
|
|
|
|
|
|
|
// Init arc centre:
|
|
|
|
wxPoint center( mapX( data.basePoint.x ), mapY( data.basePoint.y ) );
|
2013-12-19 11:33:57 +00:00
|
|
|
segm->SetCenter( center );
|
2013-10-24 16:44:38 +00:00
|
|
|
|
|
|
|
// Init arc start point
|
|
|
|
double arcStartx = data.radious;
|
|
|
|
double arcStarty = 0;
|
2013-12-19 11:33:57 +00:00
|
|
|
double startangle = data.staangle;
|
|
|
|
double endangle = data.endangle;
|
|
|
|
|
|
|
|
RotatePoint( &arcStartx, &arcStarty, -RAD2DECIDEG( startangle ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
wxPoint arcStart( mapX( arcStartx + data.basePoint.x ),
|
|
|
|
mapY( arcStarty + data.basePoint.y ) );
|
2013-12-19 11:33:57 +00:00
|
|
|
segm->SetArcStart( arcStart );
|
2013-10-24 16:44:38 +00:00
|
|
|
|
|
|
|
// calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew)
|
2013-12-19 11:33:57 +00:00
|
|
|
double angle = -RAD2DECIDEG( endangle - startangle );
|
2013-10-24 16:44:38 +00:00
|
|
|
|
|
|
|
if( angle > 0.0 )
|
|
|
|
angle -= 3600.0;
|
|
|
|
|
|
|
|
segm->SetAngle( angle );
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness : data.thickness ) );
|
2014-07-09 13:02:56 +00:00
|
|
|
m_newItemsList.push_back( segm );
|
2013-10-24 16:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Import texts (TEXT).
|
|
|
|
*/
|
2014-07-09 12:41:52 +00:00
|
|
|
void DXF2BRD_CONVERTER::addText( const DRW_Text& aData )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-07-09 13:02:56 +00:00
|
|
|
TEXTE_PCB* pcb_text = new TEXTE_PCB( NULL );
|
2014-06-29 13:05:51 +00:00
|
|
|
pcb_text->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
wxPoint refPoint( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
|
|
|
|
wxPoint secPoint( mapX( aData.secPoint.x ), mapY( aData.secPoint.y ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
if( aData.alignV != 0 || aData.alignH != 0 || aData.alignH == DRW_Text::HMiddle )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
if( aData.alignH != DRW_Text::HAligned && aData.alignH != DRW_Text::HFit )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
wxPoint tmp = secPoint;
|
|
|
|
secPoint = refPoint;
|
|
|
|
refPoint = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
switch( aData.alignV )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2013-10-25 12:16:18 +00:00
|
|
|
case DRW_Text::VBaseLine:
|
|
|
|
pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
2013-10-24 16:44:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRW_Text::VBottom:
|
|
|
|
pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRW_Text::VMiddle:
|
|
|
|
pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRW_Text::VTop:
|
|
|
|
pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
switch( aData.alignH )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
case DRW_Text::HLeft:
|
|
|
|
pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRW_Text::HCenter:
|
|
|
|
pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRW_Text::HRight:
|
|
|
|
pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRW_Text::HAligned:
|
|
|
|
// no equivalent options in text pcb.
|
2013-10-25 12:16:18 +00:00
|
|
|
pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
2013-10-24 16:44:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRW_Text::HMiddle:
|
|
|
|
// no equivalent options in text pcb.
|
|
|
|
pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRW_Text::HFit:
|
|
|
|
// no equivalent options in text pcb.
|
2013-10-25 12:16:18 +00:00
|
|
|
pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
2013-10-24 16:44:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2014-07-09 12:41:52 +00:00
|
|
|
wxString sty = wxString::FromUTF8(aData.style.c_str());
|
2013-10-24 16:44:38 +00:00
|
|
|
sty=sty.ToLower();
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
if (aData.textgen==2)
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
// Text dir = left to right;
|
2014-07-09 12:41:52 +00:00
|
|
|
} else if (aData.textgen==4)
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
/ Text dir = top to bottom;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
|
|
|
|
pcb_text->SetTextPosition( refPoint );
|
2014-07-09 12:41:52 +00:00
|
|
|
pcb_text->SetOrientation( aData.angle * 10 );
|
2013-10-24 16:44:38 +00:00
|
|
|
// The 0.8 factor gives a better height/width ratio with our font
|
2014-07-09 12:41:52 +00:00
|
|
|
pcb_text->SetWidth( mapDim( aData.height * 0.8 ) );
|
|
|
|
pcb_text->SetHeight( mapDim( aData.height ) );
|
|
|
|
pcb_text->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
pcb_text->SetText( text );
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
m_newItemsList.push_back( pcb_text );
|
2013-10-24 16:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Import multi line texts (MTEXT).
|
|
|
|
*/
|
2014-07-09 12:41:52 +00:00
|
|
|
void DXF2BRD_CONVERTER::addMText( const DRW_MText& aData )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
wxString attrib, tmp;
|
|
|
|
|
|
|
|
/* Some texts start by '\' and have formating chars (font name, font option...)
|
|
|
|
* ending with ';'
|
|
|
|
* Here are some mtext formatting codes:
|
|
|
|
* Format code Purpose
|
|
|
|
* \0...\o Turns overline on and off
|
|
|
|
* \L...\l Turns underline on and off
|
|
|
|
* \~ Inserts a nonbreaking space
|
|
|
|
\\ Inserts a backslash
|
|
|
|
\\\{...\} Inserts an opening and closing brace
|
|
|
|
\\ \File name; Changes to the specified font file
|
|
|
|
\\ \Hvalue; Changes to the text height specified in drawing units
|
|
|
|
\\ \Hvaluex; Changes the text height to a multiple of the current text height
|
|
|
|
\\ \S...^...; Stacks the subsequent text at the \, #, or ^ symbol
|
|
|
|
\\ \Tvalue; Adjusts the space between characters, from.75 to 4 times
|
|
|
|
\\ \Qangle; Changes obliquing angle
|
|
|
|
\\ \Wvalue; Changes width factor to produce wide text
|
|
|
|
\\ \A Sets the alignment value; valid values: 0, 1, 2 (bottom, center, top) while( text.StartsWith( wxT("\\") ) )
|
|
|
|
*/
|
|
|
|
while( text.StartsWith( wxT( "\\" ) ) )
|
|
|
|
{
|
|
|
|
attrib << text.BeforeFirst( ';' );
|
|
|
|
tmp = text.AfterFirst( ';' );
|
|
|
|
text = tmp;
|
|
|
|
}
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
TEXTE_PCB* pcb_text = new TEXTE_PCB( NULL );
|
2014-06-29 13:05:51 +00:00
|
|
|
pcb_text->SetLayer( ToLAYER_ID( m_brdLayer ) );
|
2014-07-09 12:41:52 +00:00
|
|
|
wxPoint textpos( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
pcb_text->SetTextPosition( textpos );
|
2014-07-09 12:41:52 +00:00
|
|
|
pcb_text->SetOrientation( aData.angle * 10 );
|
2013-10-24 16:44:38 +00:00
|
|
|
// The 0.8 factor gives a better height/width ratio with our font
|
2014-07-09 12:41:52 +00:00
|
|
|
pcb_text->SetWidth( mapDim( aData.height * 0.8 ) );
|
|
|
|
pcb_text->SetHeight( mapDim( aData.height ) );
|
|
|
|
pcb_text->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
pcb_text->SetText( text );
|
|
|
|
|
|
|
|
// Initialize text justifications:
|
2014-07-09 12:41:52 +00:00
|
|
|
if( aData.textgen <= 3 )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
}
|
2014-07-09 12:41:52 +00:00
|
|
|
else if( aData.textgen <= 6 )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
}
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
if( aData.textgen % 3 == 1 )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
}
|
2014-07-09 12:41:52 +00:00
|
|
|
else if( aData.textgen % 3 == 2 )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 // These setting have no mening in Pcbnew
|
|
|
|
if( data.alignH==1 )
|
|
|
|
{
|
|
|
|
// Text is left to right;
|
|
|
|
}
|
|
|
|
else if( data.alignH == 3 )
|
|
|
|
{
|
|
|
|
// Text is top to bottom;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// use ByStyle;
|
|
|
|
}
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
if( aData.alignV==1 )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
// use AtLeast;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// useExact;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
m_newItemsList.push_back( pcb_text );
|
2013-10-24 16:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the header variables from the DXF file.
|
|
|
|
*/
|
|
|
|
void DXF2BRD_CONVERTER::addHeader( const DRW_Header* data )
|
|
|
|
{
|
|
|
|
std::map<std::string, DRW_Variant*>::const_iterator it;
|
|
|
|
|
|
|
|
for( it = data->vars.begin(); it != data->vars.end(); it++ )
|
|
|
|
{
|
|
|
|
std::string key = ( (*it).first ).c_str();
|
|
|
|
|
|
|
|
if( key == "$DWGCODEPAGE" )
|
|
|
|
{
|
|
|
|
DRW_Variant* var = (*it).second;
|
|
|
|
m_codePage = ( *var->content.s );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2014-07-09 12:41:52 +00:00
|
|
|
wxString DXF2BRD_CONVERTER::toDxfString( const wxString& aStr )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
wxString res;
|
|
|
|
int j = 0;
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
for( unsigned i = 0; i<aStr.length(); ++i )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
int c = aStr[i];
|
2013-10-24 16:44:38 +00:00
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
if( c > 175 || c < 11 )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
res.append( aStr.Mid( j, i - j ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
j = i;
|
|
|
|
|
|
|
|
switch( c )
|
|
|
|
{
|
|
|
|
case 0x0A:
|
2014-07-09 12:41:52 +00:00
|
|
|
res += wxT( "\\P" );
|
2013-10-24 16:44:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// diameter:
|
|
|
|
#ifdef __WINDOWS_
|
|
|
|
// windows, as always, is special.
|
|
|
|
case 0x00D8:
|
|
|
|
#else
|
|
|
|
case 0x2205:
|
|
|
|
#endif
|
2014-07-09 12:41:52 +00:00
|
|
|
res += wxT( "%%C" );
|
2013-10-24 16:44:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// degree:
|
|
|
|
case 0x00B0:
|
2014-07-09 12:41:52 +00:00
|
|
|
res += wxT( "%%D" );
|
2013-10-24 16:44:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// plus/minus
|
|
|
|
case 0x00B1:
|
2014-07-09 12:41:52 +00:00
|
|
|
res += wxT( "%%P" );
|
2013-10-24 16:44:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
j--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
res.append( aStr.Mid( j ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a DXF encoded string into a native Unicode string.
|
|
|
|
*/
|
2014-07-09 12:41:52 +00:00
|
|
|
wxString DXF2BRD_CONVERTER::toNativeString( const wxString& aData )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
wxString res;
|
|
|
|
|
|
|
|
// Ignore font tags:
|
|
|
|
int j = 0;
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
for( unsigned i = 0; i < aData.length(); ++i )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
if( aData[ i ] == 0x7B ) // is '{' ?
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
if( aData[ i + 1 ] == 0x5c && aData[ i + 2 ] == 0x66 ) // is "\f" ?
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
// found font tag, append parsed part
|
2014-07-09 12:41:52 +00:00
|
|
|
res.append( aData.Mid( j, i - j ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
|
|
|
|
// skip to ';'
|
2014-07-09 12:41:52 +00:00
|
|
|
for( unsigned k = i + 3; k < aData.length(); ++k )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
if( aData[ k ] == 0x3B )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
i = j = ++k;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add to '}'
|
2014-07-09 12:41:52 +00:00
|
|
|
for( unsigned k = i; k < aData.length(); ++k )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
if( aData[ k ] == 0x7D )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
2014-07-09 12:41:52 +00:00
|
|
|
res.append( aData.Mid( i, k - i ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
i = j = ++k;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
res.append( aData.Mid( j ) );
|
2013-10-24 16:44:38 +00:00
|
|
|
|
|
|
|
#if 1
|
|
|
|
wxRegEx regexp;
|
|
|
|
// Line feed:
|
|
|
|
regexp.Compile( wxT( "\\\\P" ) );
|
|
|
|
regexp.Replace( &res, wxT( "\n" ) );
|
|
|
|
|
|
|
|
// Space:
|
|
|
|
regexp.Compile( wxT( "\\\\~" ) );
|
|
|
|
regexp.Replace( &res, wxT( " " ) );
|
|
|
|
|
|
|
|
// diameter:
|
|
|
|
regexp.Compile( wxT( "%%[cC]" ) );
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
// windows, as always, is special.
|
|
|
|
regexp.Replace( &res, wxChar( 0xD8 ) );
|
|
|
|
#else
|
|
|
|
// Empty_set, diameter is 0x2300
|
|
|
|
regexp.Replace( &res, wxChar( 0x2205 ) );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// degree:
|
|
|
|
regexp.Compile( wxT( "%%[dD]" ) );
|
|
|
|
regexp.Replace( &res, wxChar( 0x00B0 ) );
|
|
|
|
// plus/minus
|
|
|
|
regexp.Compile( wxT( "%%[pP]" ) );
|
|
|
|
regexp.Replace( &res, wxChar( 0x00B1 ) );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-09 12:41:52 +00:00
|
|
|
void DXF2BRD_CONVERTER::addTextStyle( const DRW_Textstyle& aData )
|
2013-10-24 16:44:38 +00:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|