Added dxflib

--HG--
branch : feature
This commit is contained in:
val177 2015-09-07 17:39:04 +03:00
parent d053d51cba
commit c9eb629e8c
19 changed files with 10976 additions and 0 deletions

View file

@ -2066,6 +2066,15 @@ DEPENDPATH += $$PWD/../../libs/vobj
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vobj/$${DESTDIR}/vobj.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vobj/$${DESTDIR}/libvobj.a
# VDxf static library
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vdxf/$${DESTDIR}/ -lvdxf
INCLUDEPATH += $$PWD/../../libs/vdxf
DEPENDPATH += $$PWD/../../libs/vdxf
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vdxf/$${DESTDIR}/vdxf.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vdxf/$${DESTDIR}/libvdxf.a
# VLayout static library
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR}/ -lvlayout

View file

@ -4,6 +4,7 @@ SUBDIRS = \
vpropertyexplorer \
ifc \
vobj \
vdxf \
vlayout \
vgeometry \
vpatterndb \

View file

@ -0,0 +1,260 @@
/****************************************************************************
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
**
** This file is part of the dxflib project.
**
** This file 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.
**
** Licensees holding valid dxflib Professional Edition licenses may use
** this file in accordance with the dxflib Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.ribbonsoft.com for further details.
**
** Contact info@ribbonsoft.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef DL_ATTRIBUTES_H
#define DL_ATTRIBUTES_H
#include "dl_global.h"
#include <string>
#include <vector>
#include "dl_codes.h"
/**
* Storing and passing around attributes. Attributes
* are the layer name, color, width and line type.
*
* @author Andrew Mustun
*/
class DXFLIB_EXPORT DL_Attributes
{
public:
/**
* Default constructor.
*/
DL_Attributes() :
layer(""),
color(0),
color24(-1),
width(0),
linetype("BYLAYER"),
linetypeScale(1.0),
handle(-1),
inPaperSpace(false)
{
}
/**
* Constructor for DXF attributes.
*
* @param layer Layer name for this entity or NULL for no layer
* (every entity should be on a named layer!).
* @param color Color number (0..256). 0 = BYBLOCK, 256 = BYLAYER.
* @param width Line thickness. Defaults to zero. -1 = BYLAYER,
* -2 = BYBLOCK, -3 = default width
* @param linetype Line type name or "BYLAYER" or "BYBLOCK". Defaults
* to "BYLAYER"
*/
DL_Attributes(const std::string& layer,
int color, int width,
const std::string& linetype,
double linetypeScale) :
layer(layer),
color(color),
color24(-1),
width(width),
linetype(linetype),
linetypeScale(linetypeScale),
handle(-1),
inPaperSpace(false)
{
}
/**
* Constructor for DXF attributes.
*
* @param layer Layer name for this entity or NULL for no layer
* (every entity should be on a named layer!).
* @param color Color number (0..256). 0 = BYBLOCK, 256 = BYLAYER.
* @param color24 24 bit color (see DXF reference).
* @param width Line thickness. Defaults to zero. -1 = BYLAYER,
* -2 = BYBLOCK, -3 = default width
* @param linetype Line type name or "BYLAYER" or "BYBLOCK". Defaults
* to "BYLAYER"
*/
DL_Attributes(const std::string& layer,
int color, int color24, int width,
const std::string& linetype,
int handle=-1) :
layer(layer),
color(color),
color24(color24),
width(width),
linetype(linetype),
linetypeScale(1.0),
handle(handle),
inPaperSpace(false)
{
}
/**
* Sets the layer. If the given pointer points to NULL, the
* new layer name will be an empty but valid string.
*/
void setLayer(const std::string& layer)
{
this->layer = layer;
}
/**
* @return Layer name.
*/
std::string getLayer() const
{
return layer;
}
/**
* Sets the color.
*
* @see DL_Codes, dxfColors
*/
void setColor(int color)
{
this->color = color;
}
/**
* Sets the 24bit color.
*
* @see DL_Codes, dxfColors
*/
void setColor24(int color)
{
this->color24 = color;
}
/**
* @return Color.
*
* @see DL_Codes, dxfColors
*/
int getColor() const
{
return color;
}
/**
* @return 24 bit color or -1 if no 24bit color is defined.
*
* @see DL_Codes, dxfColors
*/
int getColor24() const
{
return color24;
}
/**
* Sets the width.
*/
void setWidth(int width)
{
this->width = width;
}
/**
* @return Width.
*/
int getWidth() const
{
return width;
}
/**
* Sets the line type. This can be any string and is not
* checked to be a valid line type.
*/
void setLinetype(const std::string& linetype)
{
this->linetype = linetype;
}
/**
* Sets the entity specific line type scale.
*/
void setLinetypeScale(double linetypeScale)
{
this->linetypeScale = linetypeScale;
}
double getLinetypeScale() const
{
return linetypeScale;
}
/**
* @return Line type.
*/
std::string getLinetype() const
{
if (linetype.length()==0)
{
return "BYLAYER";
}
else
{
return linetype;
}
}
void setHandle(int h)
{
handle = h;
}
int getHandle() const
{
return handle;
}
void setInPaperSpace(bool on)
{
inPaperSpace = on;
}
bool isInPaperSpace()
{
return inPaperSpace;
}
private:
std::string layer;
int color;
int color24;
int width;
std::string linetype;
double linetypeScale;
int handle;
// DXF code 67 (true: entity in paper space, false: entity in model space (default):
bool inPaperSpace;
};
#endif
// EOF

View file

@ -0,0 +1,549 @@
/****************************************************************************
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
** Copyright (C) 2001 Robert J. Campbell Jr.
**
** This file is part of the dxflib project.
**
** This file 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.
**
** Licensees holding valid dxflib Professional Edition licenses may use
** this file in accordance with the dxflib Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.ribbonsoft.com for further details.
**
** Contact info@ribbonsoft.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
/**
* Defines common DXF codes and constants.
*/
#ifndef DXF_CODES_H
#define DXF_CODES_H
#include "dl_global.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#if defined(__OS2__)||defined(__EMX__)
#define strcasecmp(s,t) stricmp(s,t)
#endif
#if defined(_WIN32)
#define strcasecmp(s,t) _stricmp(s,t)
#endif
#ifdef _WIN32
#undef M_PI
#define M_PI 3.14159265358979323846
#pragma warning(disable : 4800)
#endif
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
#define DL_DXF_MAXLINE 1024
#define DL_DXF_MAXGROUPCODE 1100
// used to mark invalid vectors:
//#define DL_DXF_MAXDOUBLE 1.0E+10
/**
* Codes for colors and DXF versions.
*/
class DXFLIB_EXPORT DL_Codes
{
public:
/**
* Standard DXF colors.
*/
enum color
{
black = 250,
green = 3,
red = 1,
brown = 15,
yellow = 2,
cyan = 4,
magenta = 6,
gray = 8,
blue = 5,
l_blue = 163,
l_green = 121,
l_cyan = 131,
l_red = 23,
l_magenta = 221,
l_gray = 252,
white = 7,
bylayer = 256,
byblock = 0
};
/**
* Version numbers for the DXF Format.
*/
enum version
{
AC1009, // R12
AC1012,
AC1014,
AC1015 // R2000
};
};
// Extended color palette:
// The first entry is only for direct indexing starting with [1]
// Color 1 is red (1,0,0)
const double dxfColors[][3] =
{
{0,0,0}, // unused
{1,0,0}, // 1
{1,1,0},
{0,1,0},
{0,1,1},
{0,0,1},
{1,0,1},
{1,1,1}, // black or white
{0.5,0.5,0.5},
{0.75,0.75,0.75},
{1,0,0}, // 10
{1,0.5,0.5},
{0.65,0,0},
{0.65,0.325,0.325},
{0.5,0,0},
{0.5,0.25,0.25},
{0.3,0,0},
{0.3,0.15,0.15},
{0.15,0,0},
{0.15,0.075,0.075},
{1,0.25,0}, // 20
{1,0.625,0.5},
{0.65,0.1625,0},
{0.65,0.4063,0.325},
{0.5,0.125,0},
{0.5,0.3125,0.25},
{0.3,0.075,0},
{0.3,0.1875,0.15},
{0.15,0.0375,0},
{0.15,0.0938,0.075},
{1,0.5,0}, // 30
{1,0.75,0.5},
{0.65,0.325,0},
{0.65,0.4875,0.325},
{0.5,0.25,0},
{0.5,0.375,0.25},
{0.3,0.15,0},
{0.3,0.225,0.15},
{0.15,0.075,0},
{0.15,0.1125,0.075},
{1,0.75,0}, // 40
{1,0.875,0.5},
{0.65,0.4875,0},
{0.65,0.5688,0.325},
{0.5,0.375,0},
{0.5,0.4375,0.25},
{0.3,0.225,0},
{0.3,0.2625,0.15},
{0.15,0.1125,0},
{0.15,0.1313,0.075},
{1,1,0}, // 50
{1,1,0.5},
{0.65,0.65,0},
{0.65,0.65,0.325},
{0.5,0.5,0},
{0.5,0.5,0.25},
{0.3,0.3,0},
{0.3,0.3,0.15},
{0.15,0.15,0},
{0.15,0.15,0.075},
{0.75,1,0}, // 60
{0.875,1,0.5},
{0.4875,0.65,0},
{0.5688,0.65,0.325},
{0.375,0.5,0},
{0.4375,0.5,0.25},
{0.225,0.3,0},
{0.2625,0.3,0.15},
{0.1125,0.15,0},
{0.1313,0.15,0.075},
{0.5,1,0}, // 70
{0.75,1,0.5},
{0.325,0.65,0},
{0.4875,0.65,0.325},
{0.25,0.5,0},
{0.375,0.5,0.25},
{0.15,0.3,0},
{0.225,0.3,0.15},
{0.075,0.15,0},
{0.1125,0.15,0.075},
{0.25,1,0}, // 80
{0.625,1,0.5},
{0.1625,0.65,0},
{0.4063,0.65,0.325},
{0.125,0.5,0},
{0.3125,0.5,0.25},
{0.075,0.3,0},
{0.1875,0.3,0.15},
{0.0375,0.15,0},
{0.0938,0.15,0.075},
{0,1,0}, // 90
{0.5,1,0.5},
{0,0.65,0},
{0.325,0.65,0.325},
{0,0.5,0},
{0.25,0.5,0.25},
{0,0.3,0},
{0.15,0.3,0.15},
{0,0.15,0},
{0.075,0.15,0.075},
{0,1,0.25}, // 100
{0.5,1,0.625},
{0,0.65,0.1625},
{0.325,0.65,0.4063},
{0,0.5,0.125},
{0.25,0.5,0.3125},
{0,0.3,0.075},
{0.15,0.3,0.1875},
{0,0.15,0.0375},
{0.075,0.15,0.0938},
{0,1,0.5}, // 110
{0.5,1,0.75},
{0,0.65,0.325},
{0.325,0.65,0.4875},
{0,0.5,0.25},
{0.25,0.5,0.375},
{0,0.3,0.15},
{0.15,0.3,0.225},
{0,0.15,0.075},
{0.075,0.15,0.1125},
{0,1,0.75}, // 120
{0.5,1,0.875},
{0,0.65,0.4875},
{0.325,0.65,0.5688},
{0,0.5,0.375},
{0.25,0.5,0.4375},
{0,0.3,0.225},
{0.15,0.3,0.2625},
{0,0.15,0.1125},
{0.075,0.15,0.1313},
{0,1,1}, // 130
{0.5,1,1},
{0,0.65,0.65},
{0.325,0.65,0.65},
{0,0.5,0.5},
{0.25,0.5,0.5},
{0,0.3,0.3},
{0.15,0.3,0.3},
{0,0.15,0.15},
{0.075,0.15,0.15},
{0,0.75,1}, // 140
{0.5,0.875,1},
{0,0.4875,0.65},
{0.325,0.5688,0.65},
{0,0.375,0.5},
{0.25,0.4375,0.5},
{0,0.225,0.3},
{0.15,0.2625,0.3},
{0,0.1125,0.15},
{0.075,0.1313,0.15},
{0,0.5,1}, // 150
{0.5,0.75,1},
{0,0.325,0.65},
{0.325,0.4875,0.65},
{0,0.25,0.5},
{0.25,0.375,0.5},
{0,0.15,0.3},
{0.15,0.225,0.3},
{0,0.075,0.15},
{0.075,0.1125,0.15},
{0,0.25,1}, // 160
{0.5,0.625,1},
{0,0.1625,0.65},
{0.325,0.4063,0.65},
{0,0.125,0.5},
{0.25,0.3125,0.5},
{0,0.075,0.3},
{0.15,0.1875,0.3},
{0,0.0375,0.15},
{0.075,0.0938,0.15},
{0,0,1}, // 170
{0.5,0.5,1},
{0,0,0.65},
{0.325,0.325,0.65},
{0,0,0.5},
{0.25,0.25,0.5},
{0,0,0.3},
{0.15,0.15,0.3},
{0,0,0.15},
{0.075,0.075,0.15},
{0.25,0,1}, // 180
{0.625,0.5,1},
{0.1625,0,0.65},
{0.4063,0.325,0.65},
{0.125,0,0.5},
{0.3125,0.25,0.5},
{0.075,0,0.3},
{0.1875,0.15,0.3},
{0.0375,0,0.15},
{0.0938,0.075,0.15},
{0.5,0,1}, // 190
{0.75,0.5,1},
{0.325,0,0.65},
{0.4875,0.325,0.65},
{0.25,0,0.5},
{0.375,0.25,0.5},
{0.15,0,0.3},
{0.225,0.15,0.3},
{0.075,0,0.15},
{0.1125,0.075,0.15},
{0.75,0,1}, // 200
{0.875,0.5,1},
{0.4875,0,0.65},
{0.5688,0.325,0.65},
{0.375,0,0.5},
{0.4375,0.25,0.5},
{0.225,0,0.3},
{0.2625,0.15,0.3},
{0.1125,0,0.15},
{0.1313,0.075,0.15},
{1,0,1}, // 210
{1,0.5,1},
{0.65,0,0.65},
{0.65,0.325,0.65},
{0.5,0,0.5},
{0.5,0.25,0.5},
{0.3,0,0.3},
{0.3,0.15,0.3},
{0.15,0,0.15},
{0.15,0.075,0.15},
{1,0,0.75}, // 220
{1,0.5,0.875},
{0.65,0,0.4875},
{0.65,0.325,0.5688},
{0.5,0,0.375},
{0.5,0.25,0.4375},
{0.3,0,0.225},
{0.3,0.15,0.2625},
{0.15,0,0.1125},
{0.15,0.075,0.1313},
{1,0,0.5}, // 230
{1,0.5,0.75},
{0.65,0,0.325},
{0.65,0.325,0.4875},
{0.5,0,0.25},
{0.5,0.25,0.375},
{0.3,0,0.15},
{0.3,0.15,0.225},
{0.15,0,0.075},
{0.15,0.075,0.1125},
{1,0,0.25}, // 240
{1,0.5,0.625},
{0.65,0,0.1625},
{0.65,0.325,0.4063},
{0.5,0,0.125},
{0.5,0.25,0.3125},
{0.3,0,0.075},
{0.3,0.15,0.1875},
{0.15,0,0.0375},
{0.15,0.075,0.0938},
{0.33,0.33,0.33}, // 250
{0.464,0.464,0.464},
{0.598,0.598,0.598},
{0.732,0.732,0.732},
{0.866,0.866,0.866},
{1,1,1} // 255
}
;
// AutoCAD VERSION aliases
#define DL_VERSION_R12 DL_Codes::AC1009
#define DL_VERSION_LT2 DL_Codes::AC1009
#define DL_VERSION_R13 DL_Codes::AC1012 // not supported yet
#define DL_VERSION_LT95 DL_Codes::AC1012 // not supported yet
#define DL_VERSION_R14 DL_Codes::AC1014 // not supported yet
#define DL_VERSION_LT97 DL_Codes::AC1014 // not supported yet
#define DL_VERSION_LT98 DL_Codes::AC1014 // not supported yet
#define DL_VERSION_2000 DL_Codes::AC1015
#define DL_VERSION_2002 DL_Codes::AC1015
// DXF Group Codes:
// Strings
#define DL_STRGRP_START 0
#define DL_STRGRP_END 9
// Coordinates
#define DL_CRDGRP_START 10
#define DL_CRDGRP_END 19
// Real values
#define DL_RLGRP_START 38
#define DL_RLGRP_END 59
// Short integer values
#define DL_SHOGRP_START 60
#define DL_SHOGRP_END 79
// New in Release 13,
#define DL_SUBCLASS 100
// More coordinates
#define DL_CRD2GRP_START 210
#define DL_CRD2GRP_END 239
// Extended data strings
#define DL_ESTRGRP_START 1000
#define DL_ESTRGRP_END 1009
// Extended data reals
#define DL_ERLGRP_START 1010
#define DL_ERLGRP_END 1059
#define DL_Y8_COORD_CODE 28
#define DL_Z0_COORD_CODE 30
#define DL_Z8_COORD_CODE 38
#define DL_POINT_COORD_CODE 10
#define DL_INSERT_COORD_CODE 10
#define DL_CRD2GRP_START 210
#define DL_CRD2GRP_END 239
#define DL_THICKNESS 39
#define DL_FIRST_REAL_CODE THICKNESS
#define DL_LAST_REAL_CODE 59
#define DL_FIRST_INT_CODE 60
#define DL_ATTFLAGS_CODE 70
#define DL_PLINE_FLAGS_CODE 70
#define DL_LAYER_FLAGS_CODE 70
#define DL_FLD_LEN_CODE 73 // Inside ATTRIB resbuf
#define DL_LAST_INT_CODE 79
#define DL_X_EXTRU_CODE 210
#define DL_Y_EXTRU_CODE 220
#define DL_Z_EXTRU_CODE 230
#define DL_COMMENT_CODE 999
// Start and endpoints of a line
#define DL_LINE_START_CODE 10 // Followed by x coord
#define DL_LINE_END_CODE 11 // Followed by x coord
// Some codes used by blocks
#define DL_BLOCK_FLAGS_CODE 70 // An int containing flags
#define DL_BLOCK_BASE_CODE 10 // Origin of block definition
#define DL_XREF_DEPENDENT 16 // If a block contains an XREF
#define DL_XREF_RESOLVED 32 // If a XREF resolved ok
#define DL_REFERENCED 64 // If a block is ref'd in DWG
#define DL_XSCALE_CODE 41
#define DL_YSCALE_CODE 42
#define DL_ANGLE_CODE 50
#define DL_INS_POINT_CODE 10 // Followed by x of ins pnt
#define DL_NAME2_CODE 3 // Second appearance of name
// Some codes used by circle entities
#define DL_CENTER_CODE 10 // Followed by x of center
#define DL_RADIUS_CODE 40 // Followd by radius of circle
#define DL_COND_OP_CODE -4 // Conditional op,ads_ssget
// When using ads_buildlist you MUST use RTDXF0 instead of these
#define DL_ENTITY_TYPE_CODE 0 // Then there is LINE, 3DFACE..
#define DL_SES_CODE 0 // Start End String Code
#define DL_FILE_SEP_CODE 0 // File separator
#define DL_SOT_CODE 0 // Start Of Table
#define DL_TEXTVAL_CODE 1
#define DL_NAME_CODE 2
#define DL_BLOCK_NAME_CODE 2
#define DL_SECTION_NAME_CODE 2
#define DL_ENT_HAND_CODE 5 // What follows is hexa string
#define DL_TXT_STYLE_CODE 7 // Inside attributes
#define DL_LAYER_NAME_CODE 8 // What follows is layer name
#define DL_FIRST_XCOORD_CODE 10 // Group code x of 1st coord
#define DL_FIRST_YCOORD_CODE 20 // Group code y of 1st coord
#define DL_FIRST_ZCOORD_CODE 30 // Group code z of 1st coord
#define DL_L_START_CODE 10
#define DL_L_END_CODE 11
#define DL_TXTHI_CODE 40
#define DL_SCALE_X_CODE 41
#define DL_SCALE_Y_CODE 42
#define DL_SCALE_Z_CODE 43
#define DL_BULGE_CODE 42 // Used in PLINE verts for arcs
#define DL_ROTATION_CODE 50
#define DL_COLOUR_CODE 62 // What follows is a color int
#define DL_LTYPE_CODE 6 // What follows is a linetype
// Attribute flags
#define DL_ATTS_FOLLOW_CODE 66
#define DL_ATT_TAG_CODE 2
#define DL_ATT_VAL_CODE 1
#define DL_ATT_FLAGS_CODE 70 // 4 1 bit flags as follows...
#define DL_ATT_INVIS_FLAG 1
#define DL_ATT_CONST_FLAG 2
#define DL_ATT_VERIFY_FLAG 4 // Prompt and verify
#define DL_ATT_PRESET_FLAG 8 // No prompt and no verify
// PLINE defines
// Flags
#define DL_OPEN_PLINE 0x00
#define DL_CLOSED_PLINE 0x01
#define DL_POLYLINE3D 0x80
#define DL_PFACE_MESH 0x40
#define DL_PGON_MESH 0x10
// Vertices follow entity, required in POLYLINES
#define DL_VERTS_FOLLOW_CODE 66 // Value should always be 1
#define DL_VERTEX_COORD_CODE 10
// LAYER flags
#define DL_FROZEN 1
#define DL_FROZEN_BY_DEF 2
#define DL_LOCKED 4
#define DL_OBJECT_USED 64 // Object is ref'd in the dwg
#define DL_BLOCK_EN_CODE -2 // Block entity definition
#define DL_E_NAME -1 // Entity name
// Extended data codes
#define DL_EXTD_SENTINEL (-3)
#define DL_EXTD_STR 1000
#define DL_EXTD_APP_NAME 1001
#define DL_EXTD_CTL_STR 1002
#define DL_EXTD_LYR_STR 1003
#define DL_EXTD_CHUNK 1004
#define DL_EXTD_HANDLE 1005
#define DL_EXTD_POINT 1010
#define DL_EXTD_POS 1011
#define DL_EXTD_DISP 1012
#define DL_EXTD_DIR 1013
#define DL_EXTD_FLOAT 1040
#define DL_EXTD_DIST 1041
#define DL_EXTD_SCALE 1042
#define DL_EXTD_INT16 1070
#define DL_EXTD_INT32 1071
// UCS codes for use in ads_trans
#define DL_WCS_TRANS_CODE 0
#define DL_UCS_TRANS_CODE 1
#define DL_DCS_TRANS_CODE 2
#define DL_PCS_TRANS_CODE 3
#endif

View file

@ -0,0 +1,138 @@
/****************************************************************************
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
**
** This file is part of the dxflib project.
**
** This file 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.
**
** Licensees holding valid dxflib Professional Edition licenses may use
** this file in accordance with the dxflib Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.ribbonsoft.com for further details.
**
** Contact info@ribbonsoft.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef DL_CREATIONADAPTER_H
#define DL_CREATIONADAPTER_H
#include "dl_global.h"
#include "dl_creationinterface.h"
/**
* An abstract adapter class for receiving DXF events when a DXF file is being read.
* The methods in this class are empty. This class exists as convenience for creating
* listener objects.
*
* @author Andrew Mustun
*/
class DXFLIB_EXPORT DL_CreationAdapter : public DL_CreationInterface
{
public:
DL_CreationAdapter() {}
virtual ~DL_CreationAdapter() {}
virtual void processCodeValuePair(unsigned int, const std::string&) {}
virtual void endSection() {}
virtual void addLayer(const DL_LayerData&) {}
virtual void addLinetype(const DL_LinetypeData&) {}
virtual void addLinetypeDash(double) {}
virtual void addBlock(const DL_BlockData&) {}
virtual void endBlock() {}
virtual void addTextStyle(const DL_StyleData&) {}
virtual void addPoint(const DL_PointData&) {}
virtual void addLine(const DL_LineData&) {}
virtual void addXLine(const DL_XLineData&) {}
virtual void addRay(const DL_RayData&) {}
virtual void addArc(const DL_ArcData&) {}
virtual void addCircle(const DL_CircleData&) {}
virtual void addEllipse(const DL_EllipseData&) {}
virtual void addPolyline(const DL_PolylineData&) {}
virtual void addVertex(const DL_VertexData&) {}
virtual void addSpline(const DL_SplineData&) {}
virtual void addControlPoint(const DL_ControlPointData&) {}
virtual void addFitPoint(const DL_FitPointData&) {}
virtual void addKnot(const DL_KnotData&) {}
virtual void addInsert(const DL_InsertData&) {}
virtual void addMText(const DL_MTextData&) {}
virtual void addMTextChunk(const std::string&) {}
virtual void addText(const DL_TextData&) {}
virtual void addAttribute(const DL_AttributeData&) {}
virtual void addDimAlign(const DL_DimensionData&,
const DL_DimAlignedData&) {}
virtual void addDimLinear(const DL_DimensionData&,
const DL_DimLinearData&) {}
virtual void addDimRadial(const DL_DimensionData&,
const DL_DimRadialData&) {}
virtual void addDimDiametric(const DL_DimensionData&,
const DL_DimDiametricData&) {}
virtual void addDimAngular(const DL_DimensionData&,
const DL_DimAngularData&) {}
virtual void addDimAngular3P(const DL_DimensionData&,
const DL_DimAngular3PData&) {}
virtual void addDimOrdinate(const DL_DimensionData&,
const DL_DimOrdinateData&) {}
virtual void addLeader(const DL_LeaderData&) {}
virtual void addLeaderVertex(const DL_LeaderVertexData&) {}
virtual void addHatch(const DL_HatchData&) {}
virtual void addTrace(const DL_TraceData&) {}
virtual void add3dFace(const DL_3dFaceData&) {}
virtual void addSolid(const DL_SolidData&) {}
virtual void addImage(const DL_ImageData&) {}
virtual void linkImage(const DL_ImageDefData&) {}
virtual void addHatchLoop(const DL_HatchLoopData&) {}
virtual void addHatchEdge(const DL_HatchEdgeData&) {}
virtual void addXRecord(const std::string&) {}
virtual void addXRecordString(int, const std::string&) {}
virtual void addXRecordReal(int, double) {}
virtual void addXRecordInt(int, int) {}
virtual void addXRecordBool(int, bool) {}
virtual void addXDataApp(const std::string&) {}
virtual void addXDataString(int, const std::string&) {}
virtual void addXDataReal(int, double) {}
virtual void addXDataInt(int, int) {}
virtual void addDictionary(const DL_DictionaryData&) {}
virtual void addDictionaryEntry(const DL_DictionaryEntryData&) {}
virtual void endEntity() {}
virtual void addComment(const std::string&) {}
virtual void setVariableVector(const std::string&, double, double, double, int) {}
virtual void setVariableString(const std::string&, const std::string&, int) {}
virtual void setVariableInt(const std::string&, int, int) {}
virtual void setVariableDouble(const std::string&, double, int) {}
#ifdef DL_COMPAT
virtual void setVariableVector(const char*, double, double, double, int) {}
virtual void setVariableString(const char*, const char*, int) {}
virtual void setVariableInt(const char*, int, int) {}
virtual void setVariableDouble(const char*, double, int) {}
virtual void processCodeValuePair(unsigned int, char*) {}
virtual void addComment(const char*) {}
virtual void addMTextChunk(const char*) {}
#endif
virtual void endSequence() {}
};
#endif

View file

@ -0,0 +1,373 @@
/****************************************************************************
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
**
** This file is part of the dxflib project.
**
** This file 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.
**
** Licensees holding valid dxflib Professional Edition licenses may use
** this file in accordance with the dxflib Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.ribbonsoft.com for further details.
**
** Contact info@ribbonsoft.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef DL_CREATIONINTERFACE_H
#define DL_CREATIONINTERFACE_H
#include "dl_global.h"
#include <string.h>
#include "dl_attributes.h"
#include "dl_codes.h"
#include "dl_entities.h"
#include "dl_extrusion.h"
/**
* Abstract class (interface) for the creation of new entities.
* Inherit your class which takes care of the entities in the
* processed DXF file from this interface.
*
* Double arrays passed to your implementation contain 3 double
* values for x, y, z coordinates unless stated differently.
*
* @author Andrew Mustun
*/
class DXFLIB_EXPORT DL_CreationInterface
{
public:
DL_CreationInterface()
{
extrusion = new DL_Extrusion;
}
virtual ~DL_CreationInterface()
{
delete extrusion;
}
/**
* Called for every code / value tuple of the DXF file. The complete DXF file
* contents can be handled by the implemetation of this function.
*/
virtual void processCodeValuePair(unsigned int groupCode, const std::string& groupValue) = 0;
/**
* Called when a section (entity, table entry, etc.) is finished.
*/
virtual void endSection() = 0;
/**
* Called for every layer.
*/
virtual void addLayer(const DL_LayerData& data) = 0;
/**
* Called for every linetype.
*/
virtual void addLinetype(const DL_LinetypeData& data) = 0;
/**
* Called for every dash in linetype pattern
*/
virtual void addLinetypeDash(double length) = 0;
/**
* Called for every block. Note: all entities added after this
* command go into this block until endBlock() is called.
*
* @see endBlock()
*/
virtual void addBlock(const DL_BlockData& data) = 0;
/** Called to end the current block */
virtual void endBlock() = 0;
/** Called for every text style */
virtual void addTextStyle(const DL_StyleData& data) = 0;
/** Called for every point */
virtual void addPoint(const DL_PointData& data) = 0;
/** Called for every line */
virtual void addLine(const DL_LineData& data) = 0;
/** Called for every xline */
virtual void addXLine(const DL_XLineData& data) = 0;
/** Called for every ray */
virtual void addRay(const DL_RayData& data) = 0;
/** Called for every arc */
virtual void addArc(const DL_ArcData& data) = 0;
/** Called for every circle */
virtual void addCircle(const DL_CircleData& data) = 0;
/** Called for every ellipse */
virtual void addEllipse(const DL_EllipseData& data) = 0;
/** Called for every polyline start */
virtual void addPolyline(const DL_PolylineData& data) = 0;
/** Called for every polyline vertex */
virtual void addVertex(const DL_VertexData& data) = 0;
/** Called for every spline */
virtual void addSpline(const DL_SplineData& data) = 0;
/** Called for every spline control point */
virtual void addControlPoint(const DL_ControlPointData& data) = 0;
/** Called for every spline fit point */
virtual void addFitPoint(const DL_FitPointData& data) = 0;
/** Called for every spline knot value */
virtual void addKnot(const DL_KnotData& data) = 0;
/** Called for every insert. */
virtual void addInsert(const DL_InsertData& data) = 0;
/** Called for every trace start */
virtual void addTrace(const DL_TraceData& data) = 0;
/** Called for every 3dface start */
virtual void add3dFace(const DL_3dFaceData& data) = 0;
/** Called for every solid start */
virtual void addSolid(const DL_SolidData& data) = 0;
/** Called for every Multi Text entity. */
virtual void addMText(const DL_MTextData& data) = 0;
/**
* Called for additional text chunks for MTEXT entities.
* The chunks come at 250 character in size each. Note that
* those chunks come <b>before</b> the actual MTEXT entity.
*/
virtual void addMTextChunk(const std::string& text) = 0;
/** Called for every Text entity. */
virtual void addText(const DL_TextData& data) = 0;
/** Called for every Block Attribute entity. */
virtual void addAttribute(const DL_AttributeData& data) = 0;
/**
* Called for every aligned dimension entity.
*/
virtual void addDimAlign(const DL_DimensionData& data,
const DL_DimAlignedData& edata) = 0;
/**
* Called for every linear or rotated dimension entity.
*/
virtual void addDimLinear(const DL_DimensionData& data,
const DL_DimLinearData& edata) = 0;
/**
* Called for every radial dimension entity.
*/
virtual void addDimRadial(const DL_DimensionData& data,
const DL_DimRadialData& edata) = 0;
/**
* Called for every diametric dimension entity.
*/
virtual void addDimDiametric(const DL_DimensionData& data,
const DL_DimDiametricData& edata) = 0;
/**
* Called for every angular dimension (2 lines version) entity.
*/
virtual void addDimAngular(const DL_DimensionData& data,
const DL_DimAngularData& edata) = 0;
/**
* Called for every angular dimension (3 points version) entity.
*/
virtual void addDimAngular3P(const DL_DimensionData& data,
const DL_DimAngular3PData& edata) = 0;
/**
* Called for every ordinate dimension entity.
*/
virtual void addDimOrdinate(const DL_DimensionData& data,
const DL_DimOrdinateData& edata) = 0;
/**
* Called for every leader start.
*/
virtual void addLeader(const DL_LeaderData& data) = 0;
/**
* Called for every leader vertex
*/
virtual void addLeaderVertex(const DL_LeaderVertexData& data) = 0;
/**
* Called for every hatch entity.
*/
virtual void addHatch(const DL_HatchData& data) = 0;
/**
* Called for every image entity.
*/
virtual void addImage(const DL_ImageData& data) = 0;
/**
* Called for every image definition.
*/
virtual void linkImage(const DL_ImageDefData& data) = 0;
/**
* Called for every hatch loop.
*/
virtual void addHatchLoop(const DL_HatchLoopData& data) = 0;
/**
* Called for every hatch edge entity.
*/
virtual void addHatchEdge(const DL_HatchEdgeData& data) = 0;
/**
* Called for every XRecord with the given handle.
*/
virtual void addXRecord(const std::string& handle) = 0;
/**
* Called for XRecords of type string.
*/
virtual void addXRecordString(int code, const std::string& value) = 0;
/**
* Called for XRecords of type double.
*/
virtual void addXRecordReal(int code, double value) = 0;
/**
* Called for XRecords of type int.
*/
virtual void addXRecordInt(int code, int value) = 0;
/**
* Called for XRecords of type bool.
*/
virtual void addXRecordBool(int code, bool value) = 0;
/**
* Called for every beginning of an XData section of the given application.
*/
virtual void addXDataApp(const std::string& appId) = 0;
/**
* Called for XData tuples.
*/
virtual void addXDataString(int code, const std::string& value) = 0;
/**
* Called for XData tuples.
*/
virtual void addXDataReal(int code, double value) = 0;
/**
* Called for XData tuples.
*/
virtual void addXDataInt(int code, int value) = 0;
/**
* Called for dictionary objects.
*/
virtual void addDictionary(const DL_DictionaryData& data) = 0;
/**
* Called for dictionary entries.
*/
virtual void addDictionaryEntry(const DL_DictionaryEntryData& data) = 0;
/**
* Called after an entity has been completed.
*/
virtual void endEntity() = 0;
/**
* Called for every comment in the DXF file (code 999).
*/
virtual void addComment(const std::string& comment) = 0;
/**
* Called for every vector variable in the DXF file (e.g. "$EXTMIN").
*/
virtual void setVariableVector(const std::string& key, double v1, double v2, double v3, int code) = 0;
/**
* Called for every string variable in the DXF file (e.g. "$ACADVER").
*/
virtual void setVariableString(const std::string& key, const std::string& value, int code) = 0;
/**
* Called for every int variable in the DXF file (e.g. "$ACADMAINTVER").
*/
virtual void setVariableInt(const std::string& key, int value, int code) = 0;
/**
* Called for every double variable in the DXF file (e.g. "$DIMEXO").
*/
virtual void setVariableDouble(const std::string& key, double value, int code) = 0;
#ifdef DL_COMPAT
virtual void setVariableVector(const char* key, double v1, double v2, double v3, int code) = 0;
virtual void setVariableString(const char* key, const char* value, int code) = 0;
virtual void setVariableInt(const char* key, int value, int code) = 0;
virtual void setVariableDouble(const char* key, double value, int code) = 0;
virtual void processCodeValuePair(unsigned int groupCode, char* groupValue) = 0;
virtual void addComment(const char* comment) = 0;
virtual void addMTextChunk(const char* text) = 0;
#endif
/**
* Called when a SEQEND occurs (when a POLYLINE or ATTRIB is done)
*/
virtual void endSequence() = 0;
/** Sets the current attributes for entities. */
void setAttributes(const DL_Attributes& attrib)
{
attributes = attrib;
}
/** @return the current attributes used for new entities. */
DL_Attributes getAttributes()
{
return attributes;
}
/** Sets the current attributes for entities. */
void setExtrusion(double dx, double dy, double dz, double elevation)
{
extrusion->setDirection(dx, dy, dz);
extrusion->setElevation(elevation);
}
/** @return the current attributes used for new entities. */
DL_Extrusion* getExtrusion()
{
return extrusion;
}
protected:
DL_Attributes attributes;
DL_Extrusion *extrusion;
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,522 @@
/****************************************************************************
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
**
** This file is part of the dxflib project.
**
** This file 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.
**
** Licensees holding valid dxflib Professional Edition licenses may use
** this file in accordance with the dxflib Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.ribbonsoft.com for further details.
**
** Contact info@ribbonsoft.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef DL_DXF_H
#define DL_DXF_H
#include "dl_global.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <map>
#include "dl_attributes.h"
#include "dl_codes.h"
#include "dl_entities.h"
#include "dl_writer_ascii.h"
#ifdef _WIN32
#undef M_PI
#define M_PI 3.14159265358979323846
#pragma warning(disable : 4800)
#endif
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
class DL_CreationInterface;
class DL_WriterA;
#define DL_VERSION "3.7.5.0"
#define DL_VERSION_MAJOR 3
#define DL_VERSION_MINOR 7
#define DL_VERSION_REV 5
#define DL_VERSION_BUILD 0
#define DL_UNKNOWN 0
#define DL_LAYER 10
#define DL_BLOCK 11
#define DL_ENDBLK 12
#define DL_LINETYPE 13
#define DL_STYLE 20
#define DL_SETTING 50
#define DL_ENTITY_POINT 100
#define DL_ENTITY_LINE 101
#define DL_ENTITY_POLYLINE 102
#define DL_ENTITY_LWPOLYLINE 103
#define DL_ENTITY_VERTEX 104
#define DL_ENTITY_SPLINE 105
#define DL_ENTITY_KNOT 106
#define DL_ENTITY_CONTROLPOINT 107
#define DL_ENTITY_ARC 108
#define DL_ENTITY_CIRCLE 109
#define DL_ENTITY_ELLIPSE 110
#define DL_ENTITY_INSERT 111
#define DL_ENTITY_TEXT 112
#define DL_ENTITY_MTEXT 113
#define DL_ENTITY_DIMENSION 114
#define DL_ENTITY_LEADER 115
#define DL_ENTITY_HATCH 116
#define DL_ENTITY_ATTRIB 117
#define DL_ENTITY_IMAGE 118
#define DL_ENTITY_IMAGEDEF 119
#define DL_ENTITY_TRACE 120
#define DL_ENTITY_SOLID 121
#define DL_ENTITY_3DFACE 122
#define DL_ENTITY_XLINE 123
#define DL_ENTITY_RAY 124
#define DL_ENTITY_SEQEND 125
#define DL_XRECORD 200
#define DL_DICTIONARY 210
/**
* Reading and writing of DXF files.
*
* This class can read in a DXF file and calls methods from the
* interface DL_EntityContainer to add the entities to the
* contianer provided by the user of the library.
*
* It can also be used to write DXF files to a certain extent.
*
* When saving entities, special values for colors and linetypes
* can be used:
*
* Special colors are 0 (=BYBLOCK) and 256 (=BYLAYER).
* Special linetypes are "BYLAYER" and "BYBLOCK".
*
* @author Andrew Mustun
*/
class DXFLIB_EXPORT DL_Dxf
{
public:
DL_Dxf();
~DL_Dxf();
bool in(const std::string& file,
DL_CreationInterface* creationInterface);
bool readDxfGroups(FILE* fp,
DL_CreationInterface* creationInterface);
static bool getStrippedLine(std::string& s, unsigned int size,
FILE* stream);
bool readDxfGroups(std::stringstream& stream,
DL_CreationInterface* creationInterface);
bool in(std::stringstream &stream,
DL_CreationInterface* creationInterface);
static bool getStrippedLine(std::string& s, unsigned int size,
std::stringstream& stream);
static bool stripWhiteSpace(char** s);
bool processDXFGroup(DL_CreationInterface* creationInterface,
int groupCode, const std::string& groupValue);
void addSetting(DL_CreationInterface* creationInterface);
void addLayer(DL_CreationInterface* creationInterface);
void addLinetype(DL_CreationInterface *creationInterface);
void addBlock(DL_CreationInterface* creationInterface);
void endBlock(DL_CreationInterface* creationInterface);
void addTextStyle(DL_CreationInterface* creationInterface);
void addPoint(DL_CreationInterface* creationInterface);
void addLine(DL_CreationInterface* creationInterface);
void addXLine(DL_CreationInterface* creationInterface);
void addRay(DL_CreationInterface* creationInterface);
void addPolyline(DL_CreationInterface* creationInterface);
void addVertex(DL_CreationInterface* creationInterface);
void addSpline(DL_CreationInterface* creationInterface);
void addArc(DL_CreationInterface* creationInterface);
void addCircle(DL_CreationInterface* creationInterface);
void addEllipse(DL_CreationInterface* creationInterface);
void addInsert(DL_CreationInterface* creationInterface);
void addTrace(DL_CreationInterface* creationInterface);
void add3dFace(DL_CreationInterface* creationInterface);
void addSolid(DL_CreationInterface* creationInterface);
void addMText(DL_CreationInterface* creationInterface);
void addText(DL_CreationInterface* creationInterface);
void addAttribute(DL_CreationInterface* creationInterface);
DL_DimensionData getDimData();
void addDimLinear(DL_CreationInterface* creationInterface);
void addDimAligned(DL_CreationInterface* creationInterface);
void addDimRadial(DL_CreationInterface* creationInterface);
void addDimDiametric(DL_CreationInterface* creationInterface);
void addDimAngular(DL_CreationInterface* creationInterface);
void addDimAngular3P(DL_CreationInterface* creationInterface);
void addDimOrdinate(DL_CreationInterface* creationInterface);
void addLeader(DL_CreationInterface* creationInterface);
void addHatch(DL_CreationInterface* creationInterface);
void addHatchLoop();
void addHatchEdge();
bool handleHatchData(DL_CreationInterface* creationInterface);
void addImage(DL_CreationInterface* creationInterface);
void addImageDef(DL_CreationInterface* creationInterface);
void addComment(DL_CreationInterface* creationInterface, const std::string& comment);
void addDictionary(DL_CreationInterface* creationInterface);
void addDictionaryEntry(DL_CreationInterface* creationInterface);
bool handleXRecordData(DL_CreationInterface* creationInterface);
bool handleDictionaryData(DL_CreationInterface* creationInterface);
bool handleXData(DL_CreationInterface *creationInterface);
bool handleMTextData(DL_CreationInterface* creationInterface);
bool handleLWPolylineData(DL_CreationInterface* creationInterface);
bool handleSplineData(DL_CreationInterface* creationInterface);
bool handleLeaderData(DL_CreationInterface* creationInterface);
bool handleLinetypeData(DL_CreationInterface* creationInterface);
void endEntity(DL_CreationInterface* creationInterface);
void endSequence(DL_CreationInterface* creationInterface);
//int stringToInt(const char* s, bool* ok=NULL);
DL_WriterA* out(const char* file,
DL_Codes::version version=DL_VERSION_2000);
void writeHeader(DL_WriterA& dw);
void writePoint(DL_WriterA& dw,
const DL_PointData& data,
const DL_Attributes& attrib);
void writeLine(DL_WriterA& dw,
const DL_LineData& data,
const DL_Attributes& attrib);
void writeXLine(DL_WriterA& dw,
const DL_XLineData& data,
const DL_Attributes& attrib);
void writeRay(DL_WriterA& dw,
const DL_RayData& data,
const DL_Attributes& attrib);
void writePolyline(DL_WriterA& dw,
const DL_PolylineData& data,
const DL_Attributes& attrib);
void writeVertex(DL_WriterA& dw,
const DL_VertexData& data);
void writePolylineEnd(DL_WriterA& dw);
void writeSpline(DL_WriterA& dw,
const DL_SplineData& data,
const DL_Attributes& attrib);
void writeControlPoint(DL_WriterA& dw,
const DL_ControlPointData& data);
void writeFitPoint(DL_WriterA& dw,
const DL_FitPointData& data);
void writeKnot(DL_WriterA& dw,
const DL_KnotData& data);
void writeCircle(DL_WriterA& dw,
const DL_CircleData& data,
const DL_Attributes& attrib);
void writeArc(DL_WriterA& dw,
const DL_ArcData& data,
const DL_Attributes& attrib);
void writeEllipse(DL_WriterA& dw,
const DL_EllipseData& data,
const DL_Attributes& attrib);
void writeSolid(DL_WriterA& dw,
const DL_SolidData& data,
const DL_Attributes& attrib);
void writeTrace(DL_WriterA& dw,
const DL_TraceData& data,
const DL_Attributes& attrib);
void write3dFace(DL_WriterA& dw,
const DL_3dFaceData& data,
const DL_Attributes& attrib);
void writeInsert(DL_WriterA& dw,
const DL_InsertData& data,
const DL_Attributes& attrib);
void writeMText(DL_WriterA& dw,
const DL_MTextData& data,
const DL_Attributes& attrib);
void writeText(DL_WriterA& dw,
const DL_TextData& data,
const DL_Attributes& attrib);
void writeAttribute(DL_WriterA& dw,
const DL_AttributeData& data,
const DL_Attributes& attrib);
void writeDimStyleOverrides(DL_WriterA& dw,
const DL_DimensionData& data);
void writeDimAligned(DL_WriterA& dw,
const DL_DimensionData& data,
const DL_DimAlignedData& edata,
const DL_Attributes& attrib);
void writeDimLinear(DL_WriterA& dw,
const DL_DimensionData& data,
const DL_DimLinearData& edata,
const DL_Attributes& attrib);
void writeDimRadial(DL_WriterA& dw,
const DL_DimensionData& data,
const DL_DimRadialData& edata,
const DL_Attributes& attrib);
void writeDimDiametric(DL_WriterA& dw,
const DL_DimensionData& data,
const DL_DimDiametricData& edata,
const DL_Attributes& attrib);
void writeDimAngular(DL_WriterA& dw,
const DL_DimensionData& data,
const DL_DimAngularData& edata,
const DL_Attributes& attrib);
void writeDimAngular3P(DL_WriterA& dw,
const DL_DimensionData& data,
const DL_DimAngular3PData& edata,
const DL_Attributes& attrib);
void writeDimOrdinate(DL_WriterA& dw,
const DL_DimensionData& data,
const DL_DimOrdinateData& edata,
const DL_Attributes& attrib);
void writeLeader(DL_WriterA& dw,
const DL_LeaderData& data,
const DL_Attributes& attrib);
void writeLeaderVertex(DL_WriterA& dw,
const DL_LeaderVertexData& data);
void writeHatch1(DL_WriterA& dw,
const DL_HatchData& data,
const DL_Attributes& attrib);
void writeHatch2(DL_WriterA& dw,
const DL_HatchData& data,
const DL_Attributes& attrib);
void writeHatchLoop1(DL_WriterA& dw,
const DL_HatchLoopData& data);
void writeHatchLoop2(DL_WriterA& dw,
const DL_HatchLoopData& data);
void writeHatchEdge(DL_WriterA& dw,
const DL_HatchEdgeData& data);
int writeImage(DL_WriterA& dw,
const DL_ImageData& data,
const DL_Attributes& attrib);
void writeImageDef(DL_WriterA& dw, int handle,
const DL_ImageData& data);
void writeLayer(DL_WriterA& dw,
const DL_LayerData& data,
const DL_Attributes& attrib);
void writeLinetype(DL_WriterA& dw,
const DL_LinetypeData& data);
void writeAppid(DL_WriterA& dw, const std::string& name);
void writeBlock(DL_WriterA& dw,
const DL_BlockData& data);
void writeEndBlock(DL_WriterA& dw, const std::string& name);
void writeVPort(DL_WriterA& dw);
void writeStyle(DL_WriterA& dw, const DL_StyleData& style);
void writeView(DL_WriterA& dw);
void writeUcs(DL_WriterA& dw);
void writeDimStyle(DL_WriterA& dw,
double dimasz, double dimexe, double dimexo,
double dimgap, double dimtxt);
void writeBlockRecord(DL_WriterA& dw);
void writeBlockRecord(DL_WriterA& dw, const std::string& name);
void writeObjects(DL_WriterA& dw, const std::string& appDictionaryName = "");
void writeAppDictionary(DL_WriterA& dw);
int writeDictionaryEntry(DL_WriterA& dw, const std::string& name);
void writeXRecord(DL_WriterA& dw, int handle, int value);
void writeXRecord(DL_WriterA& dw, int handle, double value);
void writeXRecord(DL_WriterA& dw, int handle, bool value);
void writeXRecord(DL_WriterA& dw, int handle, const std::string& value);
void writeObjectsEnd(DL_WriterA& dw);
void writeComment(DL_WriterA& dw, const std::string& comment);
/**
* Converts the given string into a double or returns the given
* default valud (def) if value is NULL or empty.
*/
//static double toReal(const char* value, double def=0.0);
/**
* Converts the given string into an int or returns the given
* default valud (def) if value is NULL or empty.
*/
// static int toInt(const char* value, int def=0) {
// if (value!=NULL && value[0] != '\0') {
// return atoi(value);
// }
// return def;
// }
/**
* Converts the given string into a string or returns the given
* default valud (def) if value is NULL or empty.
*/
// static const char* toString(const char* value, const char* def="") {
// if (value!=NULL && value[0] != '\0') {
// return value;
// } else {
// return def;
// }
// }
static bool checkVariable(const char* var, DL_Codes::version version);
DL_Codes::version getVersion()
{
return version;
}
int getLibVersion(const std::string &str);
static void test();
bool hasValue(int code)
{
return values.count(code)==1;
}
int getIntValue(int code, int def)
{
if (!hasValue(code))
{
return def;
}
return toInt(values[code]);
}
int toInt(const std::string& str)
{
char* p;
return strtol(str.c_str(), &p, 10);
}
bool toBool(const std::string& str)
{
char* p;
return (bool)strtol(str.c_str(), &p, 10);
}
std::string getStringValue(int code, const std::string& def)
{
if (!hasValue(code))
{
return def;
}
return values[code];
}
double getRealValue(int code, double def)
{
if (!hasValue(code))
{
return def;
}
return toReal(values[code]);
}
double toReal(const std::string& str)
{
double ret;
// make sure the real value uses '.' not ',':
std::string str2 = str;
std::replace(str2.begin(), str2.end(), ',', '.');
// make sure c++ expects '.' not ',':
std::istringstream istr(str2);
istr.imbue(std::locale("C"));
istr >> ret;
return ret;
}
private:
DL_Codes::version version;
std::string polylineLayer;
double* vertices;
int maxVertices;
int vertexIndex;
double* knots;
int maxKnots;
int knotIndex;
double* weights;
int weightIndex;
double* controlPoints;
int maxControlPoints;
int controlPointIndex;
double* fitPoints;
int maxFitPoints;
int fitPointIndex;
double* leaderVertices;
int maxLeaderVertices;
int leaderVertexIndex;
bool firstHatchLoop;
DL_HatchEdgeData hatchEdge;
std::vector<std::vector<DL_HatchEdgeData> > hatchEdges;
std::string xRecordHandle;
bool xRecordValues;
// Only the useful part of the group code
std::string groupCodeTmp;
// ...same as integer
unsigned int groupCode;
// Only the useful part of the group value
std::string groupValue;
// Current entity type
int currentObjectType;
// Value of the current setting
char settingValue[DL_DXF_MAXLINE+1];
// Key of the current setting (e.g. "$ACADVER")
std::string settingKey;
// Stores the group codes
std::map<int, std::string> values;
// First call of this method. We initialize all group values in
// the first call.
bool firstCall;
// Attributes of the current entity (layer, color, width, line type)
DL_Attributes attrib;
// library version. hex: 0x20003001 = 2.0.3.1
int libVersion;
// app specific dictionary handle:
unsigned long appDictionaryHandle;
// handle of standard text style, referenced by dimstyle:
unsigned long styleHandleStd;
};
#endif
// EOF

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,56 @@
/****************************************************************************
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
** Copyright (C) 2001 Robert J. Campbell Jr.
**
** This file is part of the dxflib project.
**
** This file 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.
**
** Licensees holding valid dxflib Professional Edition licenses may use
** this file in accordance with the dxflib Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.ribbonsoft.com for further details.
**
** Contact info@ribbonsoft.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef DL_EXCEPTION_H
#define DL_EXCEPTION_H
#include "dl_global.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/**
* Used for exception handling.
*/
class DXFLIB_EXPORT DL_Exception {}
;
/**
* Used for exception handling.
*/
class DXFLIB_EXPORT DL_NullStrExc : public DL_Exception {}
;
/**
* Used for exception handling.
*/
class DXFLIB_EXPORT DL_GroupCodeExc : public DL_Exception
{
DL_GroupCodeExc(int gc=0) : groupCode(gc) {}
int groupCode;
};
#endif

View file

@ -0,0 +1,154 @@
/****************************************************************************
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
**
** This file is part of the dxflib project.
**
** This file 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.
**
** Licensees holding valid dxflib Professional Edition licenses may use
** this file in accordance with the dxflib Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.ribbonsoft.com for further details.
**
** Contact info@ribbonsoft.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef DL_EXTRUSION_H
#define DL_EXTRUSION_H
#include "dl_global.h"
#include <math.h>
/**
* Storing and passing around attributes. Attributes
* are the layer name, color, width and line type.
*
* @author Andrew Mustun
*/
class DXFLIB_EXPORT DL_Extrusion
{
public:
/**
* Default constructor.
*/
DL_Extrusion()
{
direction = new double[3];
setDirection(0.0, 0.0, 1.0);
setElevation(0.0);
}
/**
* Destructor.
*/
~DL_Extrusion()
{
delete[] direction ;
}
/**
* Constructor for DXF extrusion.
*
* @param direction Vector of axis along which the entity shall be extruded
* this is also the Z axis of the Entity coordinate system
* @param elevation Distance of the entities XY plane from the origin of the
* world coordinate system
*/
DL_Extrusion(double dx, double dy, double dz, double elevation)
{
direction = new double[3];
setDirection(dx, dy, dz);
setElevation(elevation);
}
/**
* Sets the direction vector.
*/
void setDirection(double dx, double dy, double dz)
{
direction[0]=dx;
direction[1]=dy;
direction[2]=dz;
}
/**
* @return direction vector.
*/
double* getDirection() const
{
return direction;
}
/**
* @return direction vector.
*/
void getDirection(double dir[]) const
{
dir[0]=direction[0];
dir[1]=direction[1];
dir[2]=direction[2];
}
/**
* Sets the elevation.
*/
void setElevation(double elevation)
{
this->elevation = elevation;
}
/**
* @return Elevation.
*/
double getElevation() const
{
return elevation;
}
/**
* Copies extrusion (deep copies) from another extrusion object.
*/
DL_Extrusion operator = (const DL_Extrusion& extru)
{
setDirection(extru.direction[0], extru.direction[1], extru.direction[2]);
setElevation(extru.elevation);
return *this;
}
private:
double *direction;
double elevation;
};
#endif

View file

@ -0,0 +1,13 @@
#if defined(DXFLIB_DLL)
# ifdef _WIN32
# if defined(DXFLIB_LIBRARY)
# define DXFLIB_EXPORT __declspec(dllexport)
# else
# define DXFLIB_EXPORT __declspec(dllimport)
# endif
# else
# define DXFLIB_EXPORT
# endif
#else
# define DXFLIB_EXPORT
#endif

View file

@ -0,0 +1,729 @@
/****************************************************************************
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
** Copyright (C) 2001 Robert J. Campbell Jr.
**
** This file is part of the dxflib project.
**
** This file 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.
**
** Licensees holding valid dxflib Professional Edition licenses may use
** this file in accordance with the dxflib Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.ribbonsoft.com for further details.
**
** Contact info@ribbonsoft.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef DL_WRITER_H
#define DL_WRITER_H
#include "dl_global.h"
#ifndef _WIN32
#include <strings.h>
#endif
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <iostream>
#include <algorithm>
#include "dl_attributes.h"
#include "dl_codes.h"
/**
* Defines interface for writing low level DXF constructs to
* a file. Implementation is defined in derived classes that write
* to binary or ASCII files.
*
* Implements functions that write higher level constructs in terms of
* the low level ones.
*
* @todo Add error checking for string/entry length.
*/
class DXFLIB_EXPORT DL_Writer
{
public:
/**
* @param version DXF version. Defaults to DL_VERSION_2002.
*/
DL_Writer(DL_Codes::version version) : m_handle(0x30)
{
this->version = version;
modelSpaceHandle = 0;
paperSpaceHandle = 0;
paperSpace0Handle = 0;
}
virtual ~DL_Writer() {}
;
/** Generic section for section 'name'.
*
* <pre>
* 0
* SECTION
* 2
* name
* </pre>
*/
void section(const char* name) const
{
dxfString(0, "SECTION");
dxfString(2, name);
}
/**
* Section HEADER
*
* <pre>
* 0
* SECTION
* 2
* HEADER
* </pre>
*/
void sectionHeader() const
{
section("HEADER");
}
/**
* Section TABLES
*
* <pre>
* 0
* SECTION
* 2
* TABLES
* </pre>
*/
void sectionTables() const
{
section("TABLES");
}
/**
* Section BLOCKS
*
* <pre>
* 0
* SECTION
* 2
* BLOCKS
* </pre>
*/
void sectionBlocks() const
{
section("BLOCKS");
}
/**
* Section ENTITIES
*
* <pre>
* 0
* SECTION
* 2
* ENTITIES
* </pre>
*/
void sectionEntities() const
{
section("ENTITIES");
}
/**
* Section CLASSES
*
* <pre>
* 0
* SECTION
* 2
* CLASSES
* </pre>
*/
void sectionClasses() const
{
section("CLASSES");
}
/**
* Section OBJECTS
*
* <pre>
* 0
* SECTION
* 2
* OBJECTS
* </pre>
*/
void sectionObjects() const
{
section("OBJECTS");
}
/**
* End of a section.
*
* <pre>
* 0
* ENDSEC
* </pre>
*/
void sectionEnd() const
{
dxfString(0, "ENDSEC");
}
/**
* Generic table for table 'name' with 'num' entries:
*
* <pre>
* 0
* TABLE
* 2
* name
* 70
* num
* </pre>
*/
void table(const char* name, int num, int h=0) const
{
dxfString(0, "TABLE");
dxfString(2, name);
if (version>=DL_VERSION_2000)
{
if (h==0)
{
handle();
}
else
{
dxfHex(5, h);
}
dxfString(100, "AcDbSymbolTable");
}
dxfInt(70, num);
}
/** Table for layers.
*
* @param num Number of layers in total.
*
* <pre>
* 0
* TABLE
* 2
* LAYER
* 70
* num
* </pre>
*/
void tableLayers(int num) const
{
table("LAYER", num, 2);
}
/** Table for line types.
*
* @param num Number of line types in total.
*
* <pre>
* 0
* TABLE
* 2
* LTYPE
* 70
* num
* </pre>
*/
void tableLinetypes(int num) const
{
//linetypeHandle = 5;
table("LTYPE", num, 5);
}
/** Table for application id.
*
* @param num Number of registered applications in total.
*
* <pre>
* 0
* TABLE
* 2
* APPID
* 70
* num
* </pre>
*/
void tableAppid(int num) const
{
table("APPID", num, 9);
}
/** Table for text style.
*
* @param num Number of text styles.
*
* <pre>
* 0
* TABLE
* 2
* STYLE
* 70
* num
* </pre>
*/
void tableStyle(int num) const
{
table("STYLE", num, 3);
}
/**
* End of a table.
*
* <pre>
* 0
* ENDTAB
* </pre>
*/
void tableEnd() const
{
dxfString(0, "ENDTAB");
}
/**
* End of the DXF file.
*
* <pre>
* 0
* EOF
* </pre>
*/
void dxfEOF() const
{
dxfString(0, "EOF");
}
/**
* Comment.
*
* <pre>
* 999
* text
* </pre>
*/
void comment(const char* text) const
{
dxfString(999, text);
}
/**
* Entity.
*
* <pre>
* 0
* entTypeName
* </pre>
*
* @return Unique handle or 0.
*/
void entity(const char* entTypeName) const
{
dxfString(0, entTypeName);
if (version>=DL_VERSION_2000)
{
handle();
}
}
/**
* Attributes of an entity.
*
* <pre>
* 8
* layer
* 62
* color
* 39
* width
* 6
* linetype
* </pre>
*/
void entityAttributes(const DL_Attributes& attrib) const
{
// layer name:
dxfString(8, attrib.getLayer());
// R12 doesn't accept BYLAYER values. The value has to be missing
// in that case.
if (version>=DL_VERSION_2000 || attrib.getColor()!=256)
{
dxfInt(62, attrib.getColor());
}
if (version>=DL_VERSION_2000 && attrib.getColor24()!=-1)
{
dxfInt(420, attrib.getColor24());
}
if (version>=DL_VERSION_2000)
{
dxfInt(370, attrib.getWidth());
}
if (version>=DL_VERSION_2000)
{
dxfReal(48, attrib.getLinetypeScale());
}
std::string linetype = attrib.getLinetype();
std::transform(linetype.begin(), linetype.end(), linetype.begin(), ::toupper);
if (version>=DL_VERSION_2000 || linetype=="BYLAYER")
{
dxfString(6, attrib.getLinetype());
}
}
/**
* Subclass.
*/
void subClass(const char* sub) const
{
dxfString(100, sub);
}
/**
* Layer (must be in the TABLES section LAYER).
*
* <pre>
* 0
* LAYER
* </pre>
*/
void tableLayerEntry(unsigned long int h=0) const
{
dxfString(0, "LAYER");
if (version>=DL_VERSION_2000)
{
if (h==0)
{
handle();
}
else
{
dxfHex(5, h);
}
dxfString(100, "AcDbSymbolTableRecord");
dxfString(100, "AcDbLayerTableRecord");
}
}
/**
* Line type (must be in the TABLES section LTYPE).
*
* <pre>
* 0
* LTYPE
* </pre>
*/
void tableLinetypeEntry(unsigned long int h=0) const
{
dxfString(0, "LTYPE");
if (version>=DL_VERSION_2000)
{
if (h==0)
{
handle();
}
else
{
dxfHex(5, h);
}
//dxfHex(330, 0x5);
dxfString(100, "AcDbSymbolTableRecord");
dxfString(100, "AcDbLinetypeTableRecord");
}
}
/**
* Appid (must be in the TABLES section APPID).
*
* <pre>
* 0
* APPID
* </pre>
*/
void tableAppidEntry(unsigned long int h=0) const
{
dxfString(0, "APPID");
if (version>=DL_VERSION_2000)
{
if (h==0)
{
handle();
}
else
{
dxfHex(5, h);
}
//dxfHex(330, 0x9);
dxfString(100, "AcDbSymbolTableRecord");
dxfString(100, "AcDbRegAppTableRecord");
}
}
/**
* Block (must be in the section BLOCKS).
*
* <pre>
* 0
* BLOCK
* </pre>
*/
void sectionBlockEntry(unsigned long int h=0) const
{
dxfString(0, "BLOCK");
if (version>=DL_VERSION_2000)
{
if (h==0)
{
handle();
}
else
{
dxfHex(5, h);
}
//dxfHex(330, blockHandle);
dxfString(100, "AcDbEntity");
if (h==0x1C)
{
dxfInt(67, 1);
}
dxfString(8, "0"); // TODO: Layer for block
dxfString(100, "AcDbBlockBegin");
}
}
/**
* End of Block (must be in the section BLOCKS).
*
* <pre>
* 0
* ENDBLK
* </pre>
*/
void sectionBlockEntryEnd(unsigned long int h=0) const
{
dxfString(0, "ENDBLK");
if (version>=DL_VERSION_2000)
{
if (h==0)
{
handle();
}
else
{
dxfHex(5, h);
}
//dxfHex(330, blockHandle);
dxfString(100, "AcDbEntity");
if (h==0x1D)
{
dxfInt(67, 1);
}
dxfString(8, "0"); // TODO: Layer for block
dxfString(100, "AcDbBlockEnd");
}
}
void color(int col=256) const
{
dxfInt(62, col);
}
void linetype(const char *lt) const
{
dxfString(6, lt);
}
void linetypeScale(double scale) const
{
dxfReal(48, scale);
}
void lineWeight(int lw) const
{
dxfInt(370, lw);
}
void coord(int gc, double x, double y, double z=0) const
{
dxfReal(gc, x);
dxfReal(gc+10, y);
dxfReal(gc+20, z);
}
void coordTriplet(int gc, const double* value) const
{
if (value)
{
dxfReal(gc, *value++);
dxfReal(gc+10, *value++);
dxfReal(gc+20, *value++);
}
}
void resetHandle() const
{
m_handle = 1;
}
/**
* Writes a unique handle and returns it.
*/
unsigned long handle(int gc=5) const
{
// handle has to be hex
dxfHex(gc, m_handle);
return m_handle++;
}
/**
* @return Next handle that will be written.
*/
unsigned long getNextHandle() const
{
return m_handle;
}
/**
* Increases handle, so that the handle returned remains available.
*/
unsigned long incHandle() const
{
return m_handle++;
}
/**
* Sets the handle of the model space. Entities refer to
* this handle.
*/
void setModelSpaceHandle(unsigned long h)
{
modelSpaceHandle = h;
}
unsigned long getModelSpaceHandle()
{
return modelSpaceHandle;
}
/**
* Sets the handle of the paper space. Some special blocks refer to
* this handle.
*/
void setPaperSpaceHandle(unsigned long h)
{
paperSpaceHandle = h;
}
unsigned long getPaperSpaceHandle()
{
return paperSpaceHandle;
}
/**
* Sets the handle of the paper space 0. Some special blocks refer to
* this handle.
*/
void setPaperSpace0Handle(unsigned long h)
{
paperSpace0Handle = h;
}
unsigned long getPaperSpace0Handle()
{
return paperSpace0Handle;
}
/**
* Must be overwritten by the implementing class to write a
* real value to the file.
*
* @param gc Group code.
* @param value The real value.
*/
virtual void dxfReal(int gc, double value) const = 0;
/**
* Must be overwritten by the implementing class to write an
* int value to the file.
*
* @param gc Group code.
* @param value The int value.
*/
virtual void dxfInt(int gc, int value) const = 0;
/**
* Can be overwritten by the implementing class to write a
* bool value to the file.
*
* @param gc Group code.
* @param value The bool value.
*/
virtual void dxfBool(int gc, bool value) const
{
dxfInt(gc, (int)value);
}
/**
* Must be overwritten by the implementing class to write an
* int value (hex) to the file.
*
* @param gc Group code.
* @param value The int value.
*/
virtual void dxfHex(int gc, int value) const = 0;
/**
* Must be overwritten by the implementing class to write a
* string to the file.
*
* @param gc Group code.
* @param value The string.
*/
virtual void dxfString(int gc, const char* value) const = 0;
/**
* Must be overwritten by the implementing class to write a
* string to the file.
*
* @param gc Group code.
* @param value The string.
*/
virtual void dxfString(int gc, const std::string& value) const = 0;
protected:
mutable unsigned long m_handle;
mutable unsigned long modelSpaceHandle;
mutable unsigned long paperSpaceHandle;
mutable unsigned long paperSpace0Handle;
/**
* DXF version to be created.
*/
DL_Codes::version version;
private:
};
#endif

View file

@ -0,0 +1,167 @@
/****************************************************************************
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
** Copyright (C) 2001 Robert J. Campbell Jr.
**
** This file is part of the dxflib project.
**
** This file 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.
**
** Licensees holding valid dxflib Professional Edition licenses may use
** this file in accordance with the dxflib Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.ribbonsoft.com for further details.
**
** Contact info@ribbonsoft.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <stdio.h>
#include <string.h>
#include "dl_writer_ascii.h"
#include "dl_exception.h"
/**
* Closes the output file.
*/
void DL_WriterA::close() const
{
m_ofile.close();
}
/**
* @retval true Opening file has failed.
* @retval false Otherwise.
*/
bool DL_WriterA::openFailed() const
{
return m_ofile.fail();
}
/**
* Writes a real (double) variable to the DXF file.
*
* @param gc Group code.
* @param value Double value
*/
void DL_WriterA::dxfReal(int gc, double value) const
{
char str[256];
sprintf(str, "%.16lf", value);
// fix for german locale:
strReplace(str, ',', '.');
// Cut away those zeros at the end:
bool dot = false;
int end = -1;
for (unsigned int i=0; i<strlen(str); ++i)
{
if (str[i]=='.')
{
dot = true;
end = i+2;
continue;
}
else if (dot && str[i]!='0')
{
end = i+1;
}
}
if (end>0 && end<(int)strlen(str))
{
str[end] = '\0';
}
dxfString(gc, str);
m_ofile.flush();
}
/**
* Writes an int variable to the DXF file.
*
* @param gc Group code.
* @param value Int value
*/
void DL_WriterA::dxfInt(int gc, int value) const
{
m_ofile << (gc<10 ? " " : (gc<100 ? " " : "")) << gc << "\n" << value << "\n";
}
/**
* Writes a hex int variable to the DXF file.
*
* @param gc Group code.
* @param value Int value
*/
void DL_WriterA::dxfHex(int gc, int value) const
{
char str[12];
sprintf(str, "%0X", value);
dxfString(gc, str);
}
/**
* Writes a string variable to the DXF file.
*
* @param gc Group code.
* @param value String
*/
void DL_WriterA::dxfString(int gc, const char* value) const
{
if (value==NULL)
{
#ifndef __GCC2x__
//throw DL_NullStrExc();
#endif
}
m_ofile << (gc<10 ? " " : (gc<100 ? " " : "")) << gc << "\n"
<< value << "\n";
}
void DL_WriterA::dxfString(int gc, const std::string& value) const
{
m_ofile << (gc<10 ? " " : (gc<100 ? " " : "")) << gc << "\n"
<< value << "\n";
}
/**
* Replaces every occurence of src with dest in the null terminated str.
*/
void DL_WriterA::strReplace(char* str, char src, char dest)
{
size_t i;
for (i=0; i<strlen(str); i++)
{
if (str[i]==src)
{
str[i] = dest;
}
}
}

View file

@ -0,0 +1,75 @@
/****************************************************************************
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
** Copyright (C) 2001 Robert J. Campbell Jr.
**
** This file is part of the dxflib project.
**
** This file 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.
**
** Licensees holding valid dxflib Professional Edition licenses may use
** this file in accordance with the dxflib Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.ribbonsoft.com for further details.
**
** Contact info@ribbonsoft.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef DL_WRITER_ASCII_H
#define DL_WRITER_ASCII_H
#include "dl_global.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "dl_writer.h"
#include <fstream>
#include <string>
/**
* Implements functions defined in DL_Writer for writing low
* level DXF constructs to an ASCII format DXF file.
*
* @para fname File name of the file to be created.
* @para version DXF version. Defaults to DL_VERSION_2002.
*
* @todo What if \c fname is NULL? Or \c fname can't be opened for
* another reason?
*/
class DXFLIB_EXPORT DL_WriterA : public DL_Writer
{
public:
DL_WriterA(const char* fname, DL_Codes::version version=DL_VERSION_2000)
: DL_Writer(version), m_ofile(fname) {}
virtual ~DL_WriterA() {}
bool openFailed() const;
void close() const;
void dxfReal(int gc, double value) const;
void dxfInt(int gc, int value) const;
void dxfHex(int gc, int value) const;
void dxfString(int gc, const char* value) const;
void dxfString(int gc, const std::string& value) const;
static void strReplace(char* str, char src, char dest);
private:
/**
* DXF file to be created.
*/
mutable std::ofstream m_ofile;
};
#endif

30
src/libs/vdxf/stable.cpp Normal file
View file

@ -0,0 +1,30 @@
/************************************************************************
**
** @file stable.cpp
** @author Valentina Zhuravska <zhuravska19(at)gmail.com>
** @date 12 8, 2015
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013-2015 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina 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 3 of the License, or
** (at your option) any later version.
**
** Valentina 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 Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
// Build the precompiled headers.
#include "stable.h"

52
src/libs/vdxf/stable.h Normal file
View file

@ -0,0 +1,52 @@
/************************************************************************
**
** @file stable.h
** @author Valentina Zhuravska <zhuravska19(at)gmail.com>
** @date 12 8, 2015
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013-2015 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina 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 3 of the License, or
** (at your option) any later version.
**
** Valentina 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 Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef STABLE_H
#define STABLE_H
/* I like to include this pragma too, so the build log indicates if pre-compiled headers were in use. */
#ifndef __clang__
#pragma message("Compiling precompiled headers for VDxf library.\n")
#endif
/* Add C includes here */
#if defined __cplusplus
/* Add C++ includes here */
#ifdef QT_CORE_LIB
#include <QtCore>
#endif
#ifdef QT_GUI_LIB
# include <QtGui>
#endif
#endif/*__cplusplus*/
#endif // STABLE_H

21
src/libs/vdxf/vdxf.pri Normal file
View file

@ -0,0 +1,21 @@
# ADD TO EACH PATH $$PWD VARIABLE!!!!!!
# This need for corect working file translations.pro
SOURCES += \
$$PWD/stable.cpp \
$$PWD/dxflib/dl_dxf.cpp \
$$PWD/dxflib/dl_writer_ascii.cpp
HEADERS += \
$$PWD/stable.h \
$$PWD/dxflib/dl_attributes.h \
$$PWD/dxflib/dl_codes.h \
$$PWD/dxflib/dl_creationadapter.h \
$$PWD/dxflib/dl_creationinterface.h \
$$PWD/dxflib/dl_dxf.h \
$$PWD/dxflib/dl_entities.h \
$$PWD/dxflib/dl_exception.h \
$$PWD/dxflib/dl_extrusion.h \
$$PWD/dxflib/dl_global.h \
$$PWD/dxflib/dl_writer.h \
$$PWD/dxflib/dl_writer_ascii.h

96
src/libs/vdxf/vdxf.pro Normal file
View file

@ -0,0 +1,96 @@
#-------------------------------------------------
#
# Project created by QtCreator 2014-12-12T14:55:06
#
#-------------------------------------------------
# File with common stuff for whole project
include(../../../common.pri)
# Name of library
TARGET = vdxf
# We want create a library
TEMPLATE = lib
CONFIG += \
staticlib \# Making static library
c++11 # We use C++11 standard
# Use out-of-source builds (shadow builds)
CONFIG -= debug_and_release debug_and_release_target
# Since Qt 5.4.0 the source code location is recorded only in debug builds.
# We need this information also in release builds. For this need define QT_MESSAGELOGCONTEXT.
DEFINES += QT_MESSAGELOGCONTEXT
include(vdxf.pri)
# This is static library so no need in "make install"
# directory for executable file
DESTDIR = bin
# files created moc
MOC_DIR = moc
# objecs files
OBJECTS_DIR = obj
# Set using ccache. Function enable_ccache() defined in common.pri.
$$enable_ccache()
# Set precompiled headers. Function set_PCH() defined in common.pri.
$$set_PCH()
CONFIG(debug, debug|release){
# Debug mode
unix {
#Turn on compilers warnings.
*-g++{
QMAKE_CXXFLAGS += \
# Key -isystem disable checking errors in system headers.
-isystem "$${OUT_PWD}/$${MOC_DIR}" \
$$GCC_DEBUG_CXXFLAGS # See common.pri for more details.
noAddressSanitizer{ # For enable run qmake with CONFIG+=noAddressSanitizer
# do nothing
} else {
#gccs 4.8.0 Address Sanitizer
#http://blog.qt.digia.com/blog/2013/04/17/using-gccs-4-8-0-address-sanitizer-with-qt/
QMAKE_CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer
QMAKE_CFLAGS += -fsanitize=address -fno-omit-frame-pointer
QMAKE_LFLAGS += -fsanitize=address
}
}
clang*{
QMAKE_CXXFLAGS += \
# Key -isystem disable checking errors in system headers.
-isystem "$${OUT_PWD}/$${MOC_DIR}" \
$$CLANG_DEBUG_CXXFLAGS # See common.pri for more details.
}
} else {
*-g++{
QMAKE_CXXFLAGS += $$GCC_DEBUG_CXXFLAGS # See common.pri for more details.
}
}
}else{
# Release mode
!unix:*-g++{
QMAKE_CXXFLAGS += -fno-omit-frame-pointer # Need for exchndl.dll
}
noDebugSymbols{ # For enable run qmake with CONFIG+=noDebugSymbols
# do nothing
} else {
!macx:!win32-msvc*{
# Turn on debug symbols in release mode on Unix systems.
# On Mac OS X temporarily disabled. TODO: find way how to strip binary file.
QMAKE_CXXFLAGS_RELEASE += -g -gdwarf-3
QMAKE_CFLAGS_RELEASE += -g -gdwarf-3
QMAKE_LFLAGS_RELEASE =
}
}
}