2019-04-03 15:29:17 +00:00
|
|
|
/*
|
2018-10-13 18:37:28 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-01-24 17:23:57 +00:00
|
|
|
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2021-06-04 17:44:22 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-10-13 18:37:28 +00:00
|
|
|
*
|
|
|
|
* 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
|
2019-04-03 15:29:17 +00:00
|
|
|
*/
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
#ifndef DXF2BRD_ITEMS_H
|
|
|
|
#define DXF2BRD_ITEMS_H
|
|
|
|
|
|
|
|
#include "graphics_import_plugin.h"
|
|
|
|
#include "graphics_importer_buffer.h"
|
|
|
|
|
2019-06-15 03:27:36 +00:00
|
|
|
#include <dl_creationadapter.h>
|
|
|
|
#include <dl_dxf.h>
|
2020-11-23 22:26:52 +00:00
|
|
|
#include <math/vector3.h>
|
2019-06-15 03:27:36 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
class BOARD;
|
|
|
|
class BOARD_ITEM;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper class to store a spline control point (in X,Y plane only)
|
|
|
|
*/
|
|
|
|
struct SPLINE_CTRL_POINT
|
|
|
|
{
|
|
|
|
double m_x;
|
|
|
|
double m_y;
|
|
|
|
double m_weight;
|
|
|
|
|
|
|
|
SPLINE_CTRL_POINT( double a_x, double a_y, double a_weight )
|
|
|
|
: m_x( a_x ), m_y( a_y ), m_weight( a_weight )
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper class to parse a DXF entity (polyline and spline)
|
|
|
|
*/
|
|
|
|
class DXF2BRD_ENTITY_DATA
|
|
|
|
{
|
|
|
|
public:
|
2021-06-04 17:44:22 +00:00
|
|
|
DXF2BRD_ENTITY_DATA() { Clear(); };
|
|
|
|
|
|
|
|
// Reset the entity parameters
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
m_EntityType = DL_UNKNOWN;
|
|
|
|
m_EntityParseStatus = 0;
|
|
|
|
m_EntityFlag = 0;
|
|
|
|
m_SplineDegree = 1;
|
|
|
|
m_SplineKnotsCount = 0;
|
|
|
|
m_SplineControlCount = 0;
|
|
|
|
m_SplineFitCount = 0;
|
|
|
|
m_SplineTangentStartX = 0.0;
|
|
|
|
m_SplineTangentStartY = 0.0;
|
|
|
|
m_SplineTangentEndX = 0.0;
|
|
|
|
m_SplineTangentEndY = 0.0;
|
|
|
|
m_BulgeVertex = 0.0;
|
|
|
|
m_SplineKnotsList.clear();
|
|
|
|
m_SplineControlPointList.clear();
|
|
|
|
m_SplineFitPointList.clear();
|
|
|
|
}
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
int m_EntityType; // the DXF type of entity
|
2019-04-03 15:29:17 +00:00
|
|
|
int m_EntityParseStatus; // Inside a entity: status of parsing:
|
2018-10-13 18:37:28 +00:00
|
|
|
// 0 = no entity
|
|
|
|
// 1 = first item of entity
|
|
|
|
// 2 = entity in progress
|
|
|
|
int m_EntityFlag; // a info flag to parse entities
|
|
|
|
|
2019-01-24 17:23:57 +00:00
|
|
|
VECTOR2D m_LastCoordinate; // the last vertex coordinate read (unit = mm)
|
2019-04-03 15:29:17 +00:00
|
|
|
VECTOR2D m_PolylineStart; // The first point of the polyline entity, when reading a
|
|
|
|
// polyline (unit = mm)
|
2018-10-13 18:37:28 +00:00
|
|
|
double m_BulgeVertex; // the last vertex bulge value read
|
|
|
|
|
|
|
|
// for spline parsing: parameters
|
|
|
|
unsigned int m_SplineDegree;
|
|
|
|
unsigned int m_SplineKnotsCount;
|
|
|
|
unsigned int m_SplineControlCount;
|
|
|
|
unsigned int m_SplineFitCount;
|
2019-04-03 15:29:17 +00:00
|
|
|
double m_SplineTangentStartX; // tangent dir X for the start point
|
|
|
|
double m_SplineTangentStartY; // tangent dir Y for the start point
|
|
|
|
double m_SplineTangentEndX; // tangent dir X for the end point
|
|
|
|
double m_SplineTangentEndY; // tangent dir Y for the end point
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
// for spline parsing: buffers to store control points, fit points and knot
|
|
|
|
std::vector<double> m_SplineKnotsList; // knots list, code 40
|
|
|
|
// control points list coordinates, code 10, 20 & 30 (only X and Y cood and Weight)
|
|
|
|
std::vector<SPLINE_CTRL_POINT> m_SplineControlPointList;
|
|
|
|
// fit points list, code 11, 21 & 31 (only X and Y cood)
|
2018-11-05 16:04:05 +00:00
|
|
|
std::vector<VECTOR2D> m_SplineFitPointList;
|
2018-10-13 18:37:28 +00:00
|
|
|
};
|
|
|
|
|
2020-11-20 12:18:38 +00:00
|
|
|
// Magic constants as defined by dxf specification for line weight
|
|
|
|
#define DXF_IMPORT_LINEWEIGHT_BY_LAYER -1
|
|
|
|
#define DXF_IMPORT_LINEWEIGHT_BY_BLOCK -2
|
|
|
|
#define DXF_IMPORT_LINEWEIGHT_BY_LW_DEFAULT -3
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper class to hold layer settings temporarily during import
|
|
|
|
*/
|
|
|
|
class DXF_IMPORT_LAYER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxString m_layerName;
|
|
|
|
int m_lineWeight;
|
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
DXF_IMPORT_LAYER( const wxString& aName, int aLineWeight )
|
2020-11-20 12:18:38 +00:00
|
|
|
{
|
|
|
|
m_layerName = aName;
|
|
|
|
m_lineWeight = aLineWeight;
|
|
|
|
}
|
|
|
|
};
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2020-11-23 12:47:23 +00:00
|
|
|
/**
|
|
|
|
* A helper class to hold layer settings temporarily during import
|
|
|
|
*/
|
|
|
|
class DXF_IMPORT_BLOCK
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxString m_name;
|
2020-11-26 03:13:12 +00:00
|
|
|
double m_baseX, m_baseY;
|
2020-11-23 12:47:23 +00:00
|
|
|
|
2020-11-23 16:18:02 +00:00
|
|
|
GRAPHICS_IMPORTER_BUFFER m_buffer;
|
2020-11-23 14:59:00 +00:00
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
DXF_IMPORT_BLOCK( const wxString& aName, double aX, double aY )
|
2020-11-23 12:47:23 +00:00
|
|
|
{
|
|
|
|
m_name = aName;
|
2020-11-26 03:13:12 +00:00
|
|
|
m_baseX = aX;
|
|
|
|
m_baseY = aY;
|
2020-11-23 12:47:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-24 05:55:28 +00:00
|
|
|
/**
|
|
|
|
* A helper class to hold style settings temporarily during import
|
|
|
|
*/
|
|
|
|
class DXF_IMPORT_STYLE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxString m_name;
|
|
|
|
double m_textHeight;
|
|
|
|
double m_widthFactor;
|
|
|
|
bool m_bold;
|
|
|
|
bool m_italic;
|
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
DXF_IMPORT_STYLE( const wxString& aName, double aTextHeight, double aWidthFactor, bool aBold,
|
2021-06-04 17:44:22 +00:00
|
|
|
bool aItalic )
|
2020-11-24 05:55:28 +00:00
|
|
|
{
|
|
|
|
m_name = aName;
|
|
|
|
m_textHeight = aTextHeight;
|
|
|
|
m_widthFactor = aWidthFactor;
|
|
|
|
m_bold = aBold;
|
|
|
|
m_italic = aItalic;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-11-22 03:11:24 +00:00
|
|
|
/**
|
|
|
|
* DXF Units enum with values as specified in DXF 2012 Specification
|
|
|
|
*/
|
|
|
|
enum class DXF_IMPORT_UNITS
|
|
|
|
{
|
|
|
|
DEFAULT = 0,
|
|
|
|
INCHES = 1,
|
|
|
|
FEET = 2,
|
|
|
|
MILLIMETERS = 4,
|
|
|
|
CENTIMETERS = 5,
|
|
|
|
METERS = 6,
|
|
|
|
MICROINCHES = 8,
|
|
|
|
MILS = 9,
|
|
|
|
YARDS = 10,
|
|
|
|
ANGSTROMS = 11,
|
|
|
|
NANOMETERS = 12,
|
2020-11-22 20:44:57 +00:00
|
|
|
MICRONS = 13,
|
2020-11-22 03:11:24 +00:00
|
|
|
DECIMETERS = 14,
|
|
|
|
DECAMETERS = 15,
|
|
|
|
HECTOMETERS = 16,
|
|
|
|
GIGAMETERS = 17,
|
|
|
|
ASTRONOMICAL = 18,
|
|
|
|
LIGHTYEARS = 19,
|
|
|
|
PARSECS = 20
|
|
|
|
};
|
|
|
|
|
2020-11-23 22:26:52 +00:00
|
|
|
/**
|
|
|
|
* Helper class representing the DXF specification's "arbitrary axis"
|
|
|
|
*/
|
|
|
|
struct DXF_ARBITRARY_AXIS
|
|
|
|
{
|
|
|
|
VECTOR3D vecX;
|
|
|
|
VECTOR3D vecY;
|
|
|
|
VECTOR3D vecZ;
|
|
|
|
};
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
/**
|
|
|
|
* This class import DXF ASCII files and convert basic entities to board entities.
|
|
|
|
* It depends on the dxflib library.
|
|
|
|
*/
|
2020-04-19 11:41:54 +00:00
|
|
|
#if 0 //defined(DEBUG)
|
|
|
|
// For dxf import debug:
|
|
|
|
#define ON_UNSUPPORTED( error_msg ) wxLogMessage( error_msg )
|
|
|
|
#else
|
|
|
|
#define ON_UNSUPPORTED( error_msg )
|
|
|
|
#endif
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
class DXF_IMPORT_PLUGIN : public GRAPHICS_IMPORT_PLUGIN, public DL_CreationAdapter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DXF_IMPORT_PLUGIN();
|
|
|
|
~DXF_IMPORT_PLUGIN();
|
|
|
|
|
|
|
|
const wxString GetName() const override
|
|
|
|
{
|
|
|
|
return "AutoCAD DXF";
|
|
|
|
}
|
|
|
|
|
2019-09-26 20:09:09 +00:00
|
|
|
const std::vector<std::string> GetFileExtensions() const override
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2019-09-26 20:09:09 +00:00
|
|
|
static std::vector<std::string> exts = { "dxf" };
|
|
|
|
return exts;
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Load( const wxString& aFileName ) override;
|
2018-11-05 16:04:05 +00:00
|
|
|
bool Import() override;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
double GetImageWidth() const override;
|
|
|
|
double GetImageHeight() const override;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-11-01 09:47:41 +00:00
|
|
|
void updateImageLimits( const VECTOR2D& aPoint );
|
|
|
|
|
2019-04-03 15:29:17 +00:00
|
|
|
virtual void SetImporter( GRAPHICS_IMPORTER* aImporter ) override;
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
/**
|
2021-06-04 17:44:22 +00:00
|
|
|
* Allow the import DXF items converted to board graphic items or footprint graphic items.
|
|
|
|
*
|
|
|
|
* @param aImportAsFootprintGraphic use true to import in a footprint or false to import on
|
|
|
|
* a board.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
void ImportAsFootprintGraphic( bool aImportAsFootprintGraphic )
|
|
|
|
{
|
2020-11-14 22:00:12 +00:00
|
|
|
m_importAsFPShapes = aImportAsFootprintGraphic;
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 03:11:24 +00:00
|
|
|
/**
|
2021-06-04 17:44:22 +00:00
|
|
|
* Set the default units when importing DXFs.
|
|
|
|
*
|
|
|
|
* DXFs can lack units by design which requires the importing software to make the decision.
|
|
|
|
*
|
|
|
|
* @param aUnits is the default unit of the DXF to assume.
|
2020-11-22 03:11:24 +00:00
|
|
|
*/
|
|
|
|
void SetUnit( DXF_IMPORT_UNITS aUnit )
|
|
|
|
{
|
|
|
|
m_currentUnit = aUnit;
|
|
|
|
}
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the default line width when importing dxf items like lines to Pcbnew.
|
2021-06-04 17:44:22 +00:00
|
|
|
*
|
|
|
|
* DXF files have no line width explicit parameter, it will be most of time the line width
|
|
|
|
* of imported lines.
|
|
|
|
*f
|
|
|
|
* @param aWidth is the line width in mm.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
void SetDefaultLineWidthMM( double aWidth )
|
|
|
|
{
|
|
|
|
m_defaultThickness = aWidth;
|
|
|
|
}
|
|
|
|
|
2019-04-03 15:29:17 +00:00
|
|
|
void SetLineWidthMM( double aWidth ) override { SetDefaultLineWidthMM( aWidth ); }
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Set the coordinate offset between the imported dxf items and Pcbnew.
|
2021-06-04 17:44:22 +00:00
|
|
|
*
|
|
|
|
* DXF files have the Y axis from bottom to top aOffsetX = 0, and aOffsetY = - vertical
|
|
|
|
* page size to import a full page.
|
|
|
|
*
|
|
|
|
* @param aOffsetX is the X offset in mm.
|
|
|
|
* @param aOffsetY is the Y offset in mm.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
void SetOffset( double aOffsetX, double aOffsetY )
|
|
|
|
{
|
|
|
|
m_xOffset = aOffsetX;
|
|
|
|
m_yOffset = aOffsetY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the layer number to import dxf items.
|
2021-06-04 17:44:22 +00:00
|
|
|
*
|
|
|
|
* The layer should be a technical layer, not a copper layer.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
void SetBrdLayer( int aBrdLayer ) { m_brdLayer = aBrdLayer; }
|
|
|
|
|
|
|
|
/**
|
2021-06-04 17:44:22 +00:00
|
|
|
* Implementation of the method used for communicate with this filter.
|
2018-10-13 18:37:28 +00:00
|
|
|
*
|
2021-06-04 17:44:22 +00:00
|
|
|
* @param aFile is the full filename.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
bool ImportDxfFile( const wxString& aFile );
|
|
|
|
|
|
|
|
/**
|
2018-11-05 16:04:05 +00:00
|
|
|
* @return the list of messages in one string. Each message ends by '\n'
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2021-03-24 04:29:00 +00:00
|
|
|
const wxString& GetMessages() const override
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2018-11-05 16:04:05 +00:00
|
|
|
return m_messages;
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// report message to keep trace of not supported dxf entities:
|
2021-03-24 04:29:00 +00:00
|
|
|
void reportMsg( const wxString& aMessage );
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
// coordinate conversions from dxf file to mm
|
|
|
|
double mapX( double aDxfCoordX );
|
|
|
|
double mapY( double aDxfCoordY );
|
|
|
|
double mapDim( double aDxfValue );
|
2020-11-20 12:18:38 +00:00
|
|
|
double lineWeightToWidth( int lw, DXF_IMPORT_LAYER* aLayer );
|
2020-11-22 03:11:24 +00:00
|
|
|
double getCurrentUnitScale();
|
2020-11-20 12:18:38 +00:00
|
|
|
|
2020-11-23 22:26:52 +00:00
|
|
|
DXF_ARBITRARY_AXIS getArbitraryAxis( DL_Extrusion* aData );
|
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
/**
|
|
|
|
* Converts a given world coordinate point to object coordinate using the given arbitrary
|
|
|
|
* axis vectors.
|
2020-11-23 22:26:52 +00:00
|
|
|
*/
|
|
|
|
VECTOR3D wcsToOcs( const DXF_ARBITRARY_AXIS& arbitraryAxis, VECTOR3D point );
|
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
/**
|
|
|
|
* Converts a given object coordinate point to world coordinate using the given arbitrary
|
|
|
|
* axis vectors.
|
2020-11-23 22:26:52 +00:00
|
|
|
*/
|
|
|
|
VECTOR3D ocsToWcs( const DXF_ARBITRARY_AXIS& arbitraryAxis, VECTOR3D point );
|
|
|
|
|
2020-11-20 12:18:38 +00:00
|
|
|
/**
|
2021-06-04 17:44:22 +00:00
|
|
|
* Return the import layer data.
|
2020-11-20 12:18:38 +00:00
|
|
|
*
|
2021-06-04 17:44:22 +00:00
|
|
|
* @param aLayerName is the raw string from dxflib getLayer().
|
|
|
|
* @returns The given layer by name or the placeholder layer inserted in the constructor.
|
2020-11-20 12:18:38 +00:00
|
|
|
*/
|
|
|
|
DXF_IMPORT_LAYER* getImportLayer( const std::string& aLayerName );
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2020-11-23 14:59:00 +00:00
|
|
|
/**
|
2021-06-04 17:44:22 +00:00
|
|
|
* Return the import layer block.
|
2020-11-23 14:59:00 +00:00
|
|
|
*
|
2021-06-04 17:44:22 +00:00
|
|
|
* @param aBlockName is the raw string from dxflib.
|
|
|
|
* @return The given block by name or nullptr if not found.
|
2020-11-23 14:59:00 +00:00
|
|
|
*/
|
|
|
|
DXF_IMPORT_BLOCK* getImportBlock( const std::string& aBlockName );
|
|
|
|
|
2020-11-24 05:55:28 +00:00
|
|
|
/**
|
2021-06-04 17:44:22 +00:00
|
|
|
* Return the import style.
|
2020-11-24 05:55:28 +00:00
|
|
|
*
|
2021-06-04 17:44:22 +00:00
|
|
|
* @param aStyleName is the raw string from dxflib.
|
|
|
|
* @return The given style by name or nullptr if not found.
|
2020-11-24 05:55:28 +00:00
|
|
|
*/
|
|
|
|
DXF_IMPORT_STYLE* getImportStyle( const std::string& aStyleName );
|
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
// Functions to aid in the creation of a Polyline.
|
2018-11-05 16:04:05 +00:00
|
|
|
void insertLine( const VECTOR2D& aSegStart, const VECTOR2D& aSegEnd, int aWidth );
|
|
|
|
void insertArc( const VECTOR2D& aSegStart, const VECTOR2D& aSegEnd,
|
2018-10-13 18:37:28 +00:00
|
|
|
double aBulge, int aWidth );
|
2021-06-04 17:44:22 +00:00
|
|
|
|
|
|
|
// Add a dxf spline (stored in m_curr_entity) to the board, after conversion to segments.
|
2018-10-13 18:37:28 +00:00
|
|
|
void insertSpline( int aWidth );
|
|
|
|
|
|
|
|
// Methods from DL_CreationAdapter:
|
2019-04-03 15:29:17 +00:00
|
|
|
// They are something like"call back" functions,
|
2018-10-13 18:37:28 +00:00
|
|
|
// called when the corresponding object is read in dxf file
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called for every string variable in the DXF file (e.g. "$ACADVER").
|
|
|
|
*/
|
|
|
|
virtual void setVariableString( const std::string& key, const std::string& value,
|
2021-06-04 17:44:22 +00:00
|
|
|
int code ) override;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called for every int variable in the DXF file (e.g. "$ACADMAINTVER").
|
|
|
|
*/
|
|
|
|
virtual void setVariableInt( const std::string& key, int value, int code ) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called for every double variable in the DXF file (e.g. "$DIMEXO").
|
|
|
|
*/
|
|
|
|
virtual void setVariableDouble( const std::string& key, double value, int code ) override {}
|
|
|
|
|
|
|
|
virtual void addLayer( const DL_LayerData& aData ) override;
|
2020-11-20 12:18:38 +00:00
|
|
|
virtual void addLine( const DL_LineData& aData ) override;
|
|
|
|
virtual void addLinetype( const DL_LinetypeData& data ) override;
|
2019-10-23 10:25:21 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-04 17:44:22 +00:00
|
|
|
* Called for each BLOCK in the DXF file.
|
|
|
|
*
|
2019-10-23 10:25:21 +00:00
|
|
|
* These are re-usable elements that may be placed into the model space. The elements
|
|
|
|
* are dereferenced to the model, so we just need to skip the re-parsing for the block
|
|
|
|
* elements.
|
|
|
|
*/
|
|
|
|
virtual void addBlock( const DL_BlockData& ) override;
|
|
|
|
virtual void endBlock() override;
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addCircle( const DL_CircleData& aData ) override;
|
|
|
|
virtual void addArc( const DL_ArcData& aData ) override;
|
|
|
|
//virtual void addLWPolyline( const DRW_LWPolyline& aData ) override;
|
|
|
|
virtual void addText( const DL_TextData& aData ) override;
|
|
|
|
virtual void addPolyline( const DL_PolylineData& aData ) override;
|
|
|
|
|
2020-11-23 12:47:23 +00:00
|
|
|
/* Inserts blocks where specified by insert data */
|
|
|
|
virtual void addInsert( const DL_InsertData& aData ) override;
|
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
/**
|
|
|
|
* Called for every polyline vertex.
|
|
|
|
*/
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addVertex( const DL_VertexData& aData ) override;
|
|
|
|
virtual void addMText( const DL_MTextData& aData) override;
|
|
|
|
virtual void addTextStyle( const DL_StyleData& aData ) override;
|
|
|
|
|
|
|
|
virtual void endEntity() override;
|
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
/**
|
|
|
|
* Called for every spline.
|
|
|
|
* */
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addSpline( const DL_SplineData& aData ) override;
|
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
/**
|
|
|
|
* Called for every spline control point.
|
|
|
|
*/
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addControlPoint( const DL_ControlPointData& aData ) override;
|
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
/**
|
|
|
|
* Called for every spline fit point.
|
|
|
|
*/
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addFitPoint( const DL_FitPointData& aData ) override;
|
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
/**
|
|
|
|
* Called for every spline knot value.
|
|
|
|
*/
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addKnot( const DL_KnotData& aData ) override;
|
|
|
|
|
|
|
|
// Not yet handled DXF entities:
|
2020-04-19 11:41:54 +00:00
|
|
|
virtual void addXLine( const DL_XLineData& ) override { ON_UNSUPPORTED( "addXLine" ); }
|
|
|
|
|
|
|
|
virtual void addRay( const DL_RayData& ) override { ON_UNSUPPORTED( "addRay" ); }
|
|
|
|
|
|
|
|
virtual void addArcAlignedText( const DL_ArcAlignedTextData& ) override
|
|
|
|
{ ON_UNSUPPORTED( "addArcAlignedText" ); }
|
|
|
|
|
|
|
|
virtual void addAttribute( const DL_AttributeData& ) override
|
|
|
|
{ ON_UNSUPPORTED( "addAttribute" ); }
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addDimAlign( const DL_DimensionData&,
|
2020-04-19 11:41:54 +00:00
|
|
|
const DL_DimAlignedData& ) override { ON_UNSUPPORTED( "addDimAlign" ); }
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addDimLinear( const DL_DimensionData&,
|
2020-04-19 11:41:54 +00:00
|
|
|
const DL_DimLinearData& ) override { ON_UNSUPPORTED( "addDimLinear" ); }
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addDimRadial( const DL_DimensionData&,
|
2020-04-19 11:41:54 +00:00
|
|
|
const DL_DimRadialData& ) override { ON_UNSUPPORTED( "addDimRadial" ); }
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addDimDiametric( const DL_DimensionData&,
|
2020-04-19 11:41:54 +00:00
|
|
|
const DL_DimDiametricData& ) override { ON_UNSUPPORTED( "addDimDiametric" ); }
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addDimAngular( const DL_DimensionData&,
|
2020-11-20 00:04:59 +00:00
|
|
|
const DL_DimAngular2LData& ) override { ON_UNSUPPORTED( "addDimAngular" ); }
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addDimAngular3P( const DL_DimensionData&,
|
2020-04-19 11:41:54 +00:00
|
|
|
const DL_DimAngular3PData& ) override { ON_UNSUPPORTED( "addDimAngular3P" ); }
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void addDimOrdinate( const DL_DimensionData&,
|
2020-04-19 11:41:54 +00:00
|
|
|
const DL_DimOrdinateData& ) override { ON_UNSUPPORTED( "addDimOrdinate" ); }
|
|
|
|
|
|
|
|
virtual void addLeader( const DL_LeaderData& ) override
|
|
|
|
{ ON_UNSUPPORTED( "addLeader" ); }
|
2019-04-03 15:29:17 +00:00
|
|
|
|
2020-04-19 11:41:54 +00:00
|
|
|
virtual void addLeaderVertex( const DL_LeaderVertexData& ) override
|
|
|
|
{ ON_UNSUPPORTED( "addLeaderVertex" ); }
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2020-04-19 11:41:54 +00:00
|
|
|
virtual void addHatch( const DL_HatchData& ) override { ON_UNSUPPORTED( "addHatch" ); }
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2020-04-19 11:41:54 +00:00
|
|
|
virtual void addTrace( const DL_TraceData& ) override { ON_UNSUPPORTED( "addTrace" ); }
|
|
|
|
virtual void add3dFace( const DL_3dFaceData& ) override { ON_UNSUPPORTED( "add3dFace" ); }
|
2019-04-03 15:29:17 +00:00
|
|
|
|
2020-04-19 11:41:54 +00:00
|
|
|
virtual void addSolid( const DL_SolidData& ) override { ON_UNSUPPORTED( "addSolid" ); }
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2020-04-19 11:41:54 +00:00
|
|
|
virtual void addImage( const DL_ImageData& ) override { ON_UNSUPPORTED( "addImage" ); }
|
2019-10-23 10:25:21 +00:00
|
|
|
virtual void linkImage( const DL_ImageDefData& ) override {}
|
2019-04-03 15:29:17 +00:00
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
virtual void addHatchLoop( const DL_HatchLoopData& ) override
|
|
|
|
{
|
|
|
|
ON_UNSUPPORTED( "addHatchLoop" );
|
|
|
|
}
|
2020-04-19 11:41:54 +00:00
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
virtual void addHatchEdge( const DL_HatchEdgeData& ) override
|
|
|
|
{
|
|
|
|
ON_UNSUPPORTED( "addHatchEdge" );
|
|
|
|
}
|
2020-04-19 11:41:54 +00:00
|
|
|
|
|
|
|
virtual void addXRecord( const std::string& ) override { ON_UNSUPPORTED( "addXRecord" ); }
|
2021-06-04 17:44:22 +00:00
|
|
|
|
|
|
|
virtual void addXRecordString( int, const std::string& ) override
|
|
|
|
{
|
|
|
|
ON_UNSUPPORTED( "addXRecordString" );
|
|
|
|
}
|
|
|
|
|
2020-04-19 11:41:54 +00:00
|
|
|
virtual void addXRecordReal( int, double ) override { ON_UNSUPPORTED( "addXRecordReal" ); }
|
|
|
|
virtual void addXRecordInt( int, int ) override { ON_UNSUPPORTED( "addXRecordInt" ); }
|
|
|
|
virtual void addXRecordBool( int, bool ) override { ON_UNSUPPORTED( "addXRecordBool" ); }
|
2019-04-03 15:29:17 +00:00
|
|
|
|
2020-04-19 11:41:54 +00:00
|
|
|
virtual void addXDataApp( const std::string& ) override { ON_UNSUPPORTED( "addXDataApp" ); }
|
2021-06-04 17:44:22 +00:00
|
|
|
virtual void addXDataString( int, const std::string& ) override
|
|
|
|
{
|
|
|
|
ON_UNSUPPORTED( "addXDataString" );
|
|
|
|
}
|
|
|
|
|
2020-04-19 11:41:54 +00:00
|
|
|
virtual void addXDataReal( int, double ) override { ON_UNSUPPORTED( "addXDataReal" ); }
|
|
|
|
virtual void addXDataInt( int, int ) override { ON_UNSUPPORTED( "addXDataInt" ); }
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-04 17:44:22 +00:00
|
|
|
* Convert a native Unicode string into a DXF encoded string.
|
2018-10-13 18:37:28 +00:00
|
|
|
*
|
2019-04-03 15:29:17 +00:00
|
|
|
* DXF encoding includes the following special sequences:
|
2018-10-13 18:37:28 +00:00
|
|
|
* - %%%c for a diameter sign
|
|
|
|
* - %%%d for a degree sign
|
|
|
|
* - %%%p for a plus/minus sign
|
|
|
|
*/
|
|
|
|
static wxString toDxfString( const wxString& aStr );
|
|
|
|
|
|
|
|
/**
|
2021-06-04 17:44:22 +00:00
|
|
|
* Convert a DXF encoded string into a native Unicode string.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
static wxString toNativeString( const wxString& aData );
|
|
|
|
|
|
|
|
void writeLine();
|
|
|
|
void writeMtext();
|
2021-06-04 17:44:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
double m_xOffset; // X coord offset for conversion (in mm)
|
|
|
|
double m_yOffset; // Y coord offset for conversion (in mm)
|
|
|
|
double m_defaultThickness; // default line thickness for conversion (in mm)
|
|
|
|
int m_brdLayer; // The board layer to place imported DXF items
|
|
|
|
int m_version; // the dxf version, not used here
|
|
|
|
std::string m_codePage; // The code page, not used here
|
|
|
|
bool m_importAsFPShapes; // Use footprint items instead of board items when true.
|
|
|
|
// true when the items are imported in the footprint editor
|
|
|
|
wxString m_messages; // messages generated during dxf file parsing.
|
|
|
|
// Each message ends by '\n'
|
|
|
|
DXF2BRD_ENTITY_DATA m_curr_entity; // the current entity parameters when parsing a DXF entity
|
|
|
|
|
|
|
|
double m_minX, m_maxX; // handles image size in mm
|
|
|
|
double m_minY, m_maxY; // handles image size in mm
|
|
|
|
|
2021-06-22 11:34:15 +00:00
|
|
|
DXF_IMPORT_UNITS m_currentUnit; // current unit during import
|
|
|
|
int m_importCoordinatePrecision; // current precision for linear units (points)
|
|
|
|
int m_importAnglePrecision; // current precision for angles
|
2021-06-04 17:44:22 +00:00
|
|
|
|
|
|
|
GRAPHICS_IMPORTER_BUFFER m_internalImporter;
|
|
|
|
|
|
|
|
// List of layers as we import, used just to grab props for objects.
|
|
|
|
std::vector<std::unique_ptr<DXF_IMPORT_LAYER>> m_layers;
|
|
|
|
std::vector<std::unique_ptr<DXF_IMPORT_BLOCK>> m_blocks; // List of blocks as we import
|
|
|
|
std::vector<std::unique_ptr<DXF_IMPORT_STYLE>> m_styles; // List of blocks as we import
|
|
|
|
DXF_IMPORT_BLOCK* m_currentBlock;
|
2018-10-13 18:37:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DXF2BRD_ITEMS_H
|