Sync libdxf code with last from QCAD project.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-02-22 12:08:58 +02:00
parent 146c936ccf
commit 2921276cad
4 changed files with 103 additions and 26 deletions

View File

@ -91,8 +91,8 @@ public:
* @param layer Layer name for this entity or NULL for no layer * @param layer Layer name for this entity or NULL for no layer
* (every entity should be on a named layer!). * (every entity should be on a named layer!).
* @param color Color number (0..256). 0 = BYBLOCK, 256 = BYLAYER. * @param color Color number (0..256). 0 = BYBLOCK, 256 = BYLAYER.
* @param color24 24 bit color (see DXF reference). * @param color24 24 bit color (0x00RRGGBB, see DXF reference).
* @param width Line thickness. Defaults to zero. -1 = BYLAYER, * @param width Line thickness. Defaults to zero. -1 = BYLAYER,
* -2 = BYBLOCK, -3 = default width * -2 = BYBLOCK, -3 = default width
* @param linetype Line type name or "BYLAYER" or "BYBLOCK". Defaults * @param linetype Line type name or "BYLAYER" or "BYBLOCK". Defaults
* to "BYLAYER" * to "BYLAYER"

View File

@ -417,7 +417,7 @@ bool DL_Dxf::processDXFGroup(DL_CreationInterface* creationInterface,
int color24; int color24;
color24 = getIntValue(420, -1); color24 = getIntValue(420, -1);
int handle; int handle;
handle = getIntValue(5, -1); handle = getInt16Value(5, -1);
std::string linetype = getStringValue(6, "BYLAYER"); std::string linetype = getStringValue(6, "BYLAYER");
@ -1151,7 +1151,7 @@ void DL_Dxf::addRay(DL_CreationInterface* creationInterface)
*/ */
void DL_Dxf::addPolyline(DL_CreationInterface* creationInterface) void DL_Dxf::addPolyline(DL_CreationInterface* creationInterface)
{ {
DL_PolylineData pd(maxVertices, getIntValue(71, 0), getIntValue(72, 0), getIntValue(70, 0)); DL_PolylineData pd(maxVertices, getIntValue(71, 0), getIntValue(72, 0), getIntValue(70, 0), getRealValue(38, 0));
creationInterface->addPolyline(pd); creationInterface->addPolyline(pd);
maxVertices = std::min(maxVertices, vertexIndex+1); maxVertices = std::min(maxVertices, vertexIndex+1);
@ -1406,7 +1406,7 @@ void DL_Dxf::addMText(DL_CreationInterface* creationInterface)
{ {
if (libVersion<=0x02000200) if (libVersion<=0x02000200)
{ {
// wrong but compatible with dxflib <=2.0.2.0: // wrong but compatible with dxflib <=2.0.2.0 (angle stored in rad):
angle = getRealValue(50, 0.0); angle = getRealValue(50, 0.0);
} }
else else
@ -1578,7 +1578,12 @@ bool DL_Dxf::handleXData(DL_CreationInterface* creationInterface)
creationInterface->addXDataReal(static_cast<int>(groupCode), toReal(groupValue)); creationInterface->addXDataReal(static_cast<int>(groupCode), toReal(groupValue));
return true; return true;
} }
else if (groupCode>=1060 && groupCode<=1071) else if (groupCode>=1060 && groupCode<=1070)
{
creationInterface->addXDataInt(static_cast<int>(groupCode), toInt(groupValue));
return true;
}
else if (groupCode==1071)
{ {
creationInterface->addXDataInt(static_cast<int>(groupCode), toInt(groupValue)); creationInterface->addXDataInt(static_cast<int>(groupCode), toInt(groupValue));
return true; return true;
@ -2629,9 +2634,12 @@ void DL_Dxf::writePoint(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.dxfString(100, "AcDbPoint");
} }
dw.entityAttributes(attrib); dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbPoint");
}
dw.coord(DL_POINT_COORD_CODE, data.x, data.y, data.z); dw.coord(DL_POINT_COORD_CODE, data.x, data.y, data.z);
} }
@ -2652,9 +2660,12 @@ void DL_Dxf::writeLine(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.dxfString(100, "AcDbLine");
} }
dw.entityAttributes(attrib); dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbLine");
}
dw.coord(DL_LINE_START_CODE, data.x1, data.y1, data.z1); dw.coord(DL_LINE_START_CODE, data.x1, data.y1, data.z1);
dw.coord(DL_LINE_END_CODE, data.x2, data.y2, data.z2); dw.coord(DL_LINE_END_CODE, data.x2, data.y2, data.z2);
} }
@ -2676,9 +2687,12 @@ void DL_Dxf::writeXLine(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.dxfString(100, "AcDbLine");
} }
dw.entityAttributes(attrib); dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbLine");
}
dw.coord(DL_LINE_START_CODE, data.bx, data.by, data.bz); dw.coord(DL_LINE_START_CODE, data.bx, data.by, data.bz);
dw.coord(DL_LINE_END_CODE, data.dx, data.dy, data.dz); dw.coord(DL_LINE_END_CODE, data.dx, data.dy, data.dz);
} }
@ -2700,9 +2714,12 @@ void DL_Dxf::writeRay(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.dxfString(100, "AcDbLine");
} }
dw.entityAttributes(attrib); dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbLine");
}
dw.coord(DL_LINE_START_CODE, data.bx, data.by, data.bz); dw.coord(DL_LINE_START_CODE, data.bx, data.by, data.bz);
dw.coord(DL_LINE_END_CODE, data.dx, data.dy, data.dz); dw.coord(DL_LINE_END_CODE, data.dx, data.dy, data.dz);
} }
@ -2724,8 +2741,8 @@ void DL_Dxf::writePolyline(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.entity("LWPOLYLINE"); dw.entity("LWPOLYLINE");
dw.entityAttributes(attrib);
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.entityAttributes(attrib);
dw.dxfString(100, "AcDbPolyline"); dw.dxfString(100, "AcDbPolyline");
dw.dxfInt(90, static_cast<int>(data.number)); dw.dxfInt(90, static_cast<int>(data.number));
dw.dxfInt(70, data.flags); dw.dxfInt(70, data.flags);
@ -2808,10 +2825,13 @@ void DL_Dxf::writeSpline(DL_WriterA& dw,
{ {
dw.entity("SPLINE"); dw.entity("SPLINE");
dw.entityAttributes(attrib);
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
}
dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbSpline"); dw.dxfString(100, "AcDbSpline");
} }
dw.dxfInt(70, data.flags); dw.dxfInt(70, data.flags);
@ -2887,9 +2907,12 @@ void DL_Dxf::writeCircle(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.dxfString(100, "AcDbCircle");
} }
dw.entityAttributes(attrib); dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbCircle");
}
dw.coord(10, data.cx, data.cy, data.cz); dw.coord(10, data.cx, data.cy, data.cz);
dw.dxfReal(40, data.radius); dw.dxfReal(40, data.radius);
} }
@ -2947,9 +2970,12 @@ void DL_Dxf::writeEllipse(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.dxfString(100, "AcDbEllipse");
} }
dw.entityAttributes(attrib); dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbEllipse");
}
dw.coord(10, data.cx, data.cy, data.cz); dw.coord(10, data.cx, data.cy, data.cz);
dw.coord(11, data.mx, data.my, data.mz); dw.coord(11, data.mx, data.my, data.mz);
dw.dxfReal(40, data.ratio); dw.dxfReal(40, data.ratio);
@ -2975,9 +3001,12 @@ void DL_Dxf::writeSolid(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.dxfString(100, "AcDbTrace");
} }
dw.entityAttributes(attrib); dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbTrace");
}
dw.coord(10, data.x[0], data.y[0], data.z[0]); dw.coord(10, data.x[0], data.y[0], data.z[0]);
dw.coord(11, data.x[1], data.y[1], data.z[1]); dw.coord(11, data.x[1], data.y[1], data.z[1]);
dw.coord(12, data.x[2], data.y[2], data.z[2]); dw.coord(12, data.x[2], data.y[2], data.z[2]);
@ -3000,9 +3029,12 @@ void DL_Dxf::writeTrace(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.dxfString(100, "AcDbTrace");
} }
dw.entityAttributes(attrib); dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbTrace");
}
dw.coord(10, data.x[0], data.y[0], data.z[0]); dw.coord(10, data.x[0], data.y[0], data.z[0]);
dw.coord(11, data.x[1], data.y[1], data.z[1]); dw.coord(11, data.x[1], data.y[1], data.z[1]);
dw.coord(12, data.x[2], data.y[2], data.z[2]); dw.coord(12, data.x[2], data.y[2], data.z[2]);
@ -3027,9 +3059,12 @@ void DL_Dxf::write3dFace(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.dxfString(100, "AcDbFace");
} }
dw.entityAttributes(attrib); dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbFace");
}
dw.coord(10, data.x[0], data.y[0], data.z[0]); dw.coord(10, data.x[0], data.y[0], data.z[0]);
dw.coord(11, data.x[1], data.y[1], data.z[1]); dw.coord(11, data.x[1], data.y[1], data.z[1]);
dw.coord(12, data.x[2], data.y[2], data.z[2]); dw.coord(12, data.x[2], data.y[2], data.z[2]);
@ -3061,6 +3096,10 @@ void DL_Dxf::writeInsert(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
}
dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
if (data.cols!=1 || data.rows!=1) if (data.cols!=1 || data.rows!=1)
{ {
dw.dxfString(100, "AcDbMInsertBlock"); dw.dxfString(100, "AcDbMInsertBlock");
@ -3070,7 +3109,6 @@ void DL_Dxf::writeInsert(DL_WriterA& dw,
dw.dxfString(100, "AcDbBlockReference"); dw.dxfString(100, "AcDbBlockReference");
} }
} }
dw.entityAttributes(attrib);
dw.dxfString(2, data.name); dw.dxfString(2, data.name);
dw.dxfReal(10, data.ipx); dw.dxfReal(10, data.ipx);
dw.dxfReal(20, data.ipy); dw.dxfReal(20, data.ipy);
@ -3115,9 +3153,12 @@ void DL_Dxf::writeMText(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.dxfString(100, "AcDbMText");
} }
dw.entityAttributes(attrib); dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbMText");
}
dw.dxfReal(10, data.ipx); dw.dxfReal(10, data.ipx);
dw.dxfReal(20, data.ipy); dw.dxfReal(20, data.ipy);
dw.dxfReal(30, data.ipz); dw.dxfReal(30, data.ipz);
@ -3176,9 +3217,12 @@ void DL_Dxf::writeText(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.dxfString(100, "AcDbText");
} }
dw.entityAttributes(attrib); dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbText");
}
dw.dxfReal(10, data.ipx); dw.dxfReal(10, data.ipx);
dw.dxfReal(20, data.ipy); dw.dxfReal(20, data.ipy);
dw.dxfReal(30, data.ipz); dw.dxfReal(30, data.ipz);
@ -3197,6 +3241,7 @@ void DL_Dxf::writeText(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
// required twice for some reason:
dw.dxfString(100, "AcDbText"); dw.dxfString(100, "AcDbText");
} }
@ -3212,9 +3257,12 @@ void DL_Dxf::writeAttribute(DL_WriterA& dw,
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
dw.dxfString(100, "AcDbText");
} }
dw.entityAttributes(attrib); dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbText");
}
dw.dxfReal(10, data.ipx); dw.dxfReal(10, data.ipx);
dw.dxfReal(20, data.ipy); dw.dxfReal(20, data.ipy);
dw.dxfReal(30, data.ipz); dw.dxfReal(30, data.ipz);
@ -3749,10 +3797,13 @@ void DL_Dxf::writeLeader(DL_WriterA& dw,
if (version>DL_VERSION_R12) if (version>DL_VERSION_R12)
{ {
dw.entity("LEADER"); dw.entity("LEADER");
dw.entityAttributes(attrib);
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
}
dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbLeader"); dw.dxfString(100, "AcDbLeader");
} }
dw.dxfString(3, "Standard"); dw.dxfString(3, "Standard");
@ -3802,10 +3853,13 @@ void DL_Dxf::writeHatch1(DL_WriterA& dw,
{ {
dw.entity("HATCH"); dw.entity("HATCH");
dw.entityAttributes(attrib);
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
}
dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbHatch"); dw.dxfString(100, "AcDbHatch");
} }
dw.dxfReal(10, 0.0); // elevation dw.dxfReal(10, 0.0); // elevation
@ -4020,10 +4074,13 @@ int DL_Dxf::writeImage(DL_WriterA& dw,
dw.entity("IMAGE"); dw.entity("IMAGE");
dw.entityAttributes(attrib);
if (version==DL_VERSION_2000) if (version==DL_VERSION_2000)
{ {
dw.dxfString(100, "AcDbEntity"); dw.dxfString(100, "AcDbEntity");
}
dw.entityAttributes(attrib);
if (version==DL_VERSION_2000)
{
dw.dxfString(100, "AcDbRasterImage"); dw.dxfString(100, "AcDbRasterImage");
dw.dxfInt(90, 0); dw.dxfInt(90, 0);
} }

View File

@ -414,6 +414,21 @@ public:
return static_cast<int>(strtol(str.c_str(), &p, 10)); return static_cast<int>(strtol(str.c_str(), &p, 10));
} }
int getInt16Value(int code, int def)
{
if (!hasValue(code))
{
return def;
}
return toInt16(values[code]);
}
static int toInt16(const std::string& str)
{
char* p;
return static_cast<int>(strtol(str.c_str(), &p, 16));
}
static bool toBool(const std::string& str) static bool toBool(const std::string& str)
{ {
char* p; char* p;

View File

@ -390,10 +390,12 @@ struct DXFLIB_EXPORT DL_PolylineData
* Constructor. * Constructor.
* Parameters: see member variables. * Parameters: see member variables.
*/ */
DL_PolylineData(int pNumber, int pMVerteces, int pNVerteces, int pFlags) DL_PolylineData(int pNumber, int pMVerteces, int pNVerteces, int pFlags, double pElevation = 0.0)
: number(static_cast<quint32>(pNumber)), : number(static_cast<quint32>(pNumber)),
m(static_cast<quint32>(pMVerteces)), m(static_cast<quint32>(pMVerteces)),
n(static_cast<quint32>(pNVerteces)), flags(pFlags) n(static_cast<quint32>(pNVerteces)),
elevation(pElevation),
flags(pFlags)
{ {
} }
@ -406,6 +408,9 @@ struct DXFLIB_EXPORT DL_PolylineData
/*! Number of vertices in n direction if polyline is a polygon mesh. */ /*! Number of vertices in n direction if polyline is a polygon mesh. */
quint32 n; quint32 n;
/*! elevation of the polyline. */
double elevation;
/*! Flags */ /*! Flags */
int flags; int flags;
}; };