Port changes from libdxfrw mainstream.

This commit is contained in:
Roman Telezhynskyi 2023-08-21 17:24:10 +03:00
parent df888f2f5d
commit c2fea54864
3 changed files with 1018 additions and 914 deletions

View File

@ -14,21 +14,22 @@
#ifndef DRW_ENTITIES_H #ifndef DRW_ENTITIES_H
#define DRW_ENTITIES_H #define DRW_ENTITIES_H
#include "drw_base.h"
#include <QtGlobal>
#include <algorithm>
#include <list>
#include <string> #include <string>
#include <vector> #include <vector>
#include <list>
#include <QtGlobal>
#include "drw_base.h"
#include <algorithm>
class dxfReader; class dxfReader;
class DRW_Polyline; class DRW_Polyline;
namespace DRW { namespace DRW
{
//! Entity's type. //! Entity's type.
enum ETYPE { enum ETYPE
{
E3DFACE, E3DFACE,
// E3DSOLID, //encripted propietry data // E3DSOLID, //encripted propietry data
// ACAD_PROXY_ENTITY, // ACAD_PROXY_ENTITY,
@ -86,7 +87,7 @@ namespace DRW {
UNKNOWN UNKNOWN
}; };
} } // namespace DRW
// only in DWG: MINSERT, 5 types of vertex, 4 types of polylines: 2d, 3d, pface & mesh // only in DWG: MINSERT, 5 types of vertex, 4 types of polylines: 2d, 3d, pface & mesh
// shape, dictionary, MLEADER, MLEADERSTYLE // shape, dictionary, MLEADER, MLEADERSTYLE
@ -97,8 +98,10 @@ namespace DRW {
* Base class for entities * Base class for entities
* @author Rallaz * @author Rallaz
*/ */
class DRW_Entity { class DRW_Entity
{
SETENTFRIENDS SETENTFRIENDS
public: public:
// initializes default values // initializes default values
DRW_Entity() DRW_Entity()
@ -126,7 +129,8 @@ public:
extAxisX(), extAxisX(),
extAxisY(), extAxisY(),
curr(nullptr) curr(nullptr)
{} {
}
DRW_Entity(const DRW_Entity &e) DRW_Entity(const DRW_Entity &e)
: eType(e.eType), : eType(e.eType),
@ -154,19 +158,22 @@ public:
extAxisY(), extAxisY(),
curr(nullptr /*e.curr*/) curr(nullptr /*e.curr*/)
{ {
for (std::vector<DRW_Variant*>::const_iterator it=e.extData.begin(); it!=e.extData.end(); ++it){ for (std::vector<DRW_Variant *>::const_iterator it = e.extData.begin(); it != e.extData.end(); ++it)
{
extData.push_back(new DRW_Variant(*(*it))); extData.push_back(new DRW_Variant(*(*it)));
} }
} }
virtual ~DRW_Entity() { virtual ~DRW_Entity()
{
for (std::vector<DRW_Variant *>::iterator it = extData.begin(); it != extData.end(); ++it) for (std::vector<DRW_Variant *>::iterator it = extData.begin(); it != extData.end(); ++it)
delete *it; delete *it;
extData.clear(); extData.clear();
} }
void reset(){ void reset()
{
for (std::vector<DRW_Variant *>::iterator it = extData.begin(); it != extData.end(); ++it) for (std::vector<DRW_Variant *>::iterator it = extData.begin(); it != extData.end(); ++it)
delete *it; delete *it;
extData.clear(); extData.clear();
@ -174,12 +181,15 @@ public:
virtual void applyExtrusion() = 0; virtual void applyExtrusion() = 0;
void setWidthMm(double millimeters) { void setWidthMm(double millimeters)
if(millimeters < 0.0) { {
if (millimeters < 0.0)
{
lWeight = DRW_LW_Conv::widthByLayer; lWeight = DRW_LW_Conv::widthByLayer;
return; return;
} }
if(millimeters > 2.11) millimeters = 2.11; if (millimeters > 2.11)
millimeters = 2.11;
lWeight = DRW_LW_Conv::dxfInt2lineWidth(int(floor(millimeters * 100.0))); lWeight = DRW_LW_Conv::dxfInt2lineWidth(int(floor(millimeters * 100.0)));
} }
@ -224,19 +234,17 @@ private:
DRW_Variant *curr; DRW_Variant *curr;
}; };
//! Class to handle point entity //! Class to handle point entity
/*! /*!
* Class to handle point entity * Class to handle point entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Point : public DRW_Entity { class DRW_Point : public DRW_Entity
SETENTFRIENDS
public:
DRW_Point()
{ {
eType = DRW::POINT; SETENTFRIENDS
}
public:
DRW_Point() { eType = DRW::POINT; }
void applyExtrusion() override {} void applyExtrusion() override {}
@ -251,14 +259,12 @@ public:
// the UCS in effect when the point was drawn // the UCS in effect when the point was drawn
}; };
class DRW_ASTMNotch : public DRW_Point
class DRW_ASTMNotch : public DRW_Point {
SETENTFRIENDS
public:
DRW_ASTMNotch()
{ {
eType = DRW::ASTMNOTCH; SETENTFRIENDS
}
public:
DRW_ASTMNotch() { eType = DRW::ASTMNOTCH; }
protected: protected:
auto parseCode(int code, dxfReader *reader) -> bool override; auto parseCode(int code, dxfReader *reader) -> bool override;
@ -272,8 +278,10 @@ public:
* Class to handle line entity * Class to handle line entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Line : public DRW_Point { class DRW_Line : public DRW_Point
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Line() DRW_Line()
: secPoint() : secPoint()
@ -295,12 +303,12 @@ public:
* Class to handle ray entity * Class to handle ray entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Ray : public DRW_Line { class DRW_Ray : public DRW_Line
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Ray() { DRW_Ray() { eType = DRW::RAY; }
eType = DRW::RAY;
}
}; };
//! Class to handle xline entity //! Class to handle xline entity
@ -308,11 +316,10 @@ public:
* Class to handle xline entity * Class to handle xline entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Xline : public DRW_Ray { class DRW_Xline : public DRW_Ray
{
public: public:
DRW_Xline() { DRW_Xline() { eType = DRW::XLINE; }
eType = DRW::XLINE;
}
}; };
//! Class to handle circle entity //! Class to handle circle entity
@ -320,8 +327,10 @@ public:
* Class to handle circle entity * Class to handle circle entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Circle : public DRW_Point { class DRW_Circle : public DRW_Point
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Circle() DRW_Circle()
: radious() : radious()
@ -343,8 +352,10 @@ public:
* Class to handle arc entity * Class to handle arc entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Arc : public DRW_Circle { class DRW_Arc : public DRW_Circle
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Arc() DRW_Arc()
: staangle(), : staangle(),
@ -386,8 +397,10 @@ public:
* for hatch boundary are in degrees * for hatch boundary are in degrees
* @author Rallaz * @author Rallaz
*/ */
class DRW_Ellipse : public DRW_Line { class DRW_Ellipse : public DRW_Line
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Ellipse() DRW_Ellipse()
: ratio(), : ratio(),
@ -420,8 +433,10 @@ public:
* Class to handle trace entity * Class to handle trace entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Trace : public DRW_Line { class DRW_Trace : public DRW_Line
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Trace() DRW_Trace()
: thirdPoint(), : thirdPoint(),
@ -445,12 +460,12 @@ public:
* Class to handle solid entity * Class to handle solid entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Solid : public DRW_Trace { class DRW_Solid : public DRW_Trace
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Solid() { DRW_Solid() { eType = DRW::SOLID; }
eType = DRW::SOLID;
}
public: public:
//! first corner (2D) //! first corner (2D)
@ -460,7 +475,7 @@ public:
//! third corner (2D) //! third corner (2D)
auto thirdCorner() const -> const DRW_Coord & { return thirdPoint; } auto thirdCorner() const -> const DRW_Coord & { return thirdPoint; }
//! fourth corner (2D) //! fourth corner (2D)
auto fourthCorner() const -> const DRW_Coord & { return thirdPoint; } auto fourthCorner() const -> const DRW_Coord & { return fourPoint; }
//! thickness //! thickness
auto thick() const -> double { return thickness; } auto thick() const -> double { return thickness; }
//! elevation //! elevation
@ -474,10 +489,13 @@ public:
* Class to handle 3dface entity * Class to handle 3dface entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_3Dface : public DRW_Trace { class DRW_3Dface : public DRW_Trace
{
SETENTFRIENDS SETENTFRIENDS
public: public:
enum InvisibleEdgeFlags { enum InvisibleEdgeFlags
{
NoEdge = 0x00, NoEdge = 0x00,
FirstEdge = 0x01, FirstEdge = 0x01,
SecodEdge = 0x02, SecodEdge = 0x02,
@ -511,7 +529,6 @@ protected:
public: public:
int invisibleflag; /*!< invisible edge flag, code 70 */ int invisibleflag; /*!< invisible edge flag, code 70 */
}; };
//! Class to handle block entries //! Class to handle block entries
@ -519,8 +536,10 @@ public:
* Class to handle block entries * Class to handle block entries
* @author Rallaz * @author Rallaz
*/ */
class DRW_Block : public DRW_Point { class DRW_Block : public DRW_Point
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Block() DRW_Block()
: name("*U0"), : name("*U0"),
@ -540,14 +559,15 @@ public:
int flags; /*!< block type, code 70 */ int flags; /*!< block type, code 70 */
}; };
//! Class to handle insert entries //! Class to handle insert entries
/*! /*!
* Class to handle insert entries * Class to handle insert entries
* @author Rallaz * @author Rallaz
*/ */
class DRW_Insert : public DRW_Point { class DRW_Insert : public DRW_Point
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Insert() DRW_Insert()
: name(), : name(),
@ -583,8 +603,10 @@ public:
* Class to handle lwpolyline entity * Class to handle lwpolyline entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_LWPolyline : public DRW_Entity { class DRW_LWPolyline : public DRW_Entity
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_LWPolyline() DRW_LWPolyline()
: vertexnum(), : vertexnum(),
@ -615,11 +637,14 @@ public:
this->vertlist.push_back(new DRW_Vertex2D(*(p.vertlist.at(i)))); this->vertlist.push_back(new DRW_Vertex2D(*(p.vertlist.at(i))));
} }
~DRW_LWPolyline() { ~DRW_LWPolyline()
for(DRW_Vertex2D *item : vertlist) delete item; {
for (DRW_Vertex2D *item : vertlist)
delete item;
} }
void applyExtrusion() override; void applyExtrusion() override;
void addVertex (DRW_Vertex2D v) { void addVertex(DRW_Vertex2D v)
{
DRW_Vertex2D *vert = new DRW_Vertex2D(); DRW_Vertex2D *vert = new DRW_Vertex2D();
vert->x = v.x; vert->x = v.x;
vert->y = v.y; vert->y = v.y;
@ -650,6 +675,7 @@ public:
DRW_Coord extPoint; /*!< Dir extrusion normal vector, code 210, 220 & 230 */ DRW_Coord extPoint; /*!< Dir extrusion normal vector, code 210, 220 & 230 */
DRW_Vertex2D *vertex; /*!< current vertex to add data */ DRW_Vertex2D *vertex; /*!< current vertex to add data */
std::vector<DRW_Vertex2D *> vertlist; /*!< vertex list */ std::vector<DRW_Vertex2D *> vertlist; /*!< vertex list */
private: private:
auto operator=(const DRW_LWPolyline &) -> DRW_LWPolyline &Q_DECL_EQ_DELETE; auto operator=(const DRW_LWPolyline &) -> DRW_LWPolyline &Q_DECL_EQ_DELETE;
}; };
@ -659,11 +685,14 @@ private:
* Class to handle insert entries * Class to handle insert entries
* @author Rallaz * @author Rallaz
*/ */
class DRW_Text : public DRW_Line { class DRW_Text : public DRW_Line
{
SETENTFRIENDS SETENTFRIENDS
public: public:
//! Vertical alignments. //! Vertical alignments.
enum VAlign { enum VAlign
{
VBaseLine = 0, /*!< Top = 0 */ VBaseLine = 0, /*!< Top = 0 */
VBottom, /*!< Bottom = 1 */ VBottom, /*!< Bottom = 1 */
VMiddle, /*!< Middle = 2 */ VMiddle, /*!< Middle = 2 */
@ -671,7 +700,8 @@ public:
}; };
//! Horizontal alignments. //! Horizontal alignments.
enum HAlign { enum HAlign
{
HLeft = 0, /*!< Left = 0 */ HLeft = 0, /*!< Left = 0 */
HCenter, /*!< Centered = 1 */ HCenter, /*!< Centered = 1 */
HRight, /*!< Right = 2 */ HRight, /*!< Right = 2 */
@ -716,11 +746,14 @@ public:
* Class to handle insert entries * Class to handle insert entries
* @author Rallaz * @author Rallaz
*/ */
class DRW_MText : public DRW_Text { class DRW_MText : public DRW_Text
{
SETENTFRIENDS SETENTFRIENDS
public: public:
//! Attachments. //! Attachments.
enum Attach { enum Attach
{
TopLeft = 1, TopLeft = 1,
TopCenter, TopCenter,
TopRight, TopRight,
@ -747,6 +780,7 @@ protected:
public: public:
double interlin; /*!< width factor, code 44 */ double interlin; /*!< width factor, code 44 */
private: private:
bool hasXAxisVec; bool hasXAxisVec;
}; };
@ -756,8 +790,10 @@ private:
* Class to handle vertex for polyline entity * Class to handle vertex for polyline entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Vertex final : public DRW_Point { class DRW_Vertex final : public DRW_Point
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Vertex() DRW_Vertex()
: stawidth(0), : stawidth(0),
@ -813,8 +849,10 @@ public:
* Class to handle polyline entity * Class to handle polyline entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Polyline : public DRW_Point { class DRW_Polyline : public DRW_Point
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Polyline() DRW_Polyline()
: flags(0), : flags(0),
@ -853,10 +891,13 @@ public:
this->vertlist.push_back(new DRW_Vertex(*(p.vertlist.at(i)))); this->vertlist.push_back(new DRW_Vertex(*(p.vertlist.at(i))));
} }
~DRW_Polyline() { ~DRW_Polyline()
for(DRW_Vertex *item : vertlist) delete item; {
for (DRW_Vertex *item : vertlist)
delete item;
} }
void addVertex (DRW_Vertex v) { void addVertex(DRW_Vertex v)
{
DRW_Vertex *vert = new DRW_Vertex(); DRW_Vertex *vert = new DRW_Vertex();
vert->basePoint.x = v.basePoint.x; vert->basePoint.x = v.basePoint.x;
vert->basePoint.y = v.basePoint.y; vert->basePoint.y = v.basePoint.y;
@ -866,9 +907,7 @@ public:
vert->bulge = v.bulge; vert->bulge = v.bulge;
vertlist.push_back(vert); vertlist.push_back(vert);
} }
void appendVertex (DRW_Vertex *v) { void appendVertex(DRW_Vertex *v) { vertlist.push_back(v); }
vertlist.push_back(v);
}
protected: protected:
auto parseCode(int code, dxfReader *reader) -> bool override; auto parseCode(int code, dxfReader *reader) -> bool override;
@ -892,14 +931,15 @@ private:
duint32 lastEH; // handle of last entity, only in pre-2004 duint32 lastEH; // handle of last entity, only in pre-2004
}; };
//! Class to handle spline entity //! Class to handle spline entity
/*! /*!
* Class to handle spline entity * Class to handle spline entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Spline : public DRW_Entity { class DRW_Spline : public DRW_Entity
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Spline() DRW_Spline()
: normalVec(), : normalVec(),
@ -953,9 +993,12 @@ public:
[](DRW_Coord *v) { return new DRW_Coord(*v); }); [](DRW_Coord *v) { return new DRW_Coord(*v); });
} }
~DRW_Spline() { ~DRW_Spline()
for(DRW_Coord *item : controllist) delete item; {
for(DRW_Coord *item : fitlist) delete item; for (DRW_Coord *item : controllist)
delete item;
for (DRW_Coord *item : fitlist)
delete item;
} }
void applyExtrusion() override {} void applyExtrusion() override {}
@ -1000,22 +1043,24 @@ private:
* Class to handle hatch loop * Class to handle hatch loop
* @author Rallaz * @author Rallaz
*/ */
class DRW_HatchLoop { class DRW_HatchLoop
{
public: public:
explicit DRW_HatchLoop(int t) explicit DRW_HatchLoop(int t)
: type(t), : type(t),
numedges(0), numedges(0),
objlist() objlist()
{} {
}
~DRW_HatchLoop() { ~DRW_HatchLoop()
{
// for(DRW_LWPolyline *item : pollist) delete item; // for(DRW_LWPolyline *item : pollist) delete item;
for(DRW_Entity *item : objlist) delete item; for (DRW_Entity *item : objlist)
delete item;
} }
void update() { void update() { numedges = static_cast<int>(objlist.size()); }
numedges = static_cast<int>(objlist.size());
}
public: public:
int type; /*!< boundary path type, code 92, polyline=2, default=0 */ int type; /*!< boundary path type, code 92, polyline=2, default=0 */
@ -1031,8 +1076,10 @@ public:
* @author Rallaz * @author Rallaz
*/ */
// TODO: handle lwpolylines, splines and ellipses // TODO: handle lwpolylines, splines and ellipses
class DRW_Hatch : public DRW_Point { class DRW_Hatch : public DRW_Point
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Hatch() DRW_Hatch()
: name(), : name(),
@ -1061,13 +1108,13 @@ public:
clearEntities(); clearEntities();
} }
~DRW_Hatch() { ~DRW_Hatch()
for(DRW_HatchLoop *item : looplist) delete item; {
for (DRW_HatchLoop *item : looplist)
delete item;
} }
void appendLoop (DRW_HatchLoop *v) { void appendLoop(DRW_HatchLoop *v) { looplist.push_back(v); }
looplist.push_back(v);
}
void applyExtrusion() override {} void applyExtrusion() override {}
@ -1091,7 +1138,8 @@ public:
private: private:
// cppcheck-suppress unknownMacro // cppcheck-suppress unknownMacro
Q_DISABLE_COPY_MOVE(DRW_Hatch) // NOLINT Q_DISABLE_COPY_MOVE(DRW_Hatch) // NOLINT
void clearEntities(){ void clearEntities()
{
pt = line = nullptr; pt = line = nullptr;
pline = nullptr; pline = nullptr;
arc = nullptr; arc = nullptr;
@ -1100,33 +1148,41 @@ private:
plvert = nullptr; plvert = nullptr;
} }
void addLine() { void addLine()
{
clearEntities(); clearEntities();
if (loop) { if (loop)
{
pt = line = new DRW_Line; pt = line = new DRW_Line;
loop->objlist.push_back(line); loop->objlist.push_back(line);
} }
} }
void addArc() { void addArc()
{
clearEntities(); clearEntities();
if (loop) { if (loop)
{
pt = arc = new DRW_Arc; pt = arc = new DRW_Arc;
loop->objlist.push_back(arc); loop->objlist.push_back(arc);
} }
} }
void addEllipse() { void addEllipse()
{
clearEntities(); clearEntities();
if (loop) { if (loop)
{
pt = ellipse = new DRW_Ellipse; pt = ellipse = new DRW_Ellipse;
loop->objlist.push_back(ellipse); loop->objlist.push_back(ellipse);
} }
} }
void addSpline() { void addSpline()
{
clearEntities(); clearEntities();
if (loop) { if (loop)
{
pt = nullptr; pt = nullptr;
spline = new DRW_Spline; spline = new DRW_Spline;
loop->objlist.push_back(spline); loop->objlist.push_back(spline);
@ -1149,8 +1205,10 @@ private:
* Class to handle image entity * Class to handle image entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Image : public DRW_Line { class DRW_Image : public DRW_Line
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Image() DRW_Image()
: ref(), : ref(),
@ -1182,17 +1240,17 @@ public:
int brightness; /*!< Brightness value, code 281, (0-100) default 50 */ int brightness; /*!< Brightness value, code 281, (0-100) default 50 */
int contrast; /*!< Brightness value, code 282, (0-100) default 50 */ int contrast; /*!< Brightness value, code 282, (0-100) default 50 */
int fade; /*!< Brightness value, code 283, (0-100) default 0 */ int fade; /*!< Brightness value, code 283, (0-100) default 0 */
}; };
//! Base class for dimension entity //! Base class for dimension entity
/*! /*!
* Base class for dimension entity * Base class for dimension entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Dimension : public DRW_Entity { class DRW_Dimension : public DRW_Entity
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Dimension() DRW_Dimension()
: type(0), : type(0),
@ -1289,7 +1347,11 @@ public:
void setName(const std::string &s) { name = s; } void setName(const std::string &s) { name = s; }
// int getType(){ return type;} /*!< Dimension type, code 70 */ // int getType(){ return type;} /*!< Dimension type, code 70 */
auto hasActualMeasurement() const -> bool { return hasActual; } auto hasActualMeasurement() const -> bool { return hasActual; }
void setActualMeasurement(double value) { hasActual = true; actual = value; } void setActualMeasurement(double value)
{
hasActual = true;
actual = value;
}
auto getActualMeasurement() const -> double { return actual; } auto getActualMeasurement() const -> double { return actual; }
protected: protected:
@ -1312,8 +1374,10 @@ protected:
void setOb52(const double d) { oblique = d; } void setOb52(const double d) { oblique = d; }
auto getRa40() const -> double { return length; } /*!< Leader length, code 40 */ auto getRa40() const -> double { return length; } /*!< Leader length, code 40 */
void setRa40(const double d) { length = d; } void setRa40(const double d) { length = d; }
public: public:
int type; /*!< Dimension type, code 70 */ int type; /*!< Dimension type, code 70 */
private: private:
auto operator=(const DRW_Dimension &) -> DRW_Dimension &Q_DECL_EQ_DELETE; auto operator=(const DRW_Dimension &) -> DRW_Dimension &Q_DECL_EQ_DELETE;
std::string name; /*!< Name of the block that contains the entities, code 2 */ std::string name; /*!< Name of the block that contains the entities, code 2 */
@ -1341,16 +1405,18 @@ private:
double actual; /*!< Actual measurement (optional; read-only value), code 42 */ double actual; /*!< Actual measurement (optional; read-only value), code 42 */
}; };
//! Class to handle aligned dimension entity //! Class to handle aligned dimension entity
/*! /*!
* Class to handle aligned dimension entity * Class to handle aligned dimension entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_DimAligned : public DRW_Dimension { class DRW_DimAligned : public DRW_Dimension
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_DimAligned(){ DRW_DimAligned()
{
eType = DRW::DIMALIGNED; eType = DRW::DIMALIGNED;
type = 1; type = 1;
} }
@ -1372,7 +1438,6 @@ public:
void setDef1Point(const DRW_Coord &p) { setPt3(p); } void setDef1Point(const DRW_Coord &p) { setPt3(p); }
auto getDef2Point() const -> DRW_Coord { return getPt4(); } /*!< Definition point 2, code 14, 24 & 34 */ auto getDef2Point() const -> DRW_Coord { return getPt4(); } /*!< Definition point 2, code 14, 24 & 34 */
void setDef2Point(const DRW_Coord &p) { setPt4(p); } void setDef2Point(const DRW_Coord &p) { setPt4(p); }
}; };
//! Class to handle linear or rotated dimension entity //! Class to handle linear or rotated dimension entity
@ -1380,9 +1445,11 @@ public:
* Class to handle linear or rotated dimension entity * Class to handle linear or rotated dimension entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_DimLinear : public DRW_DimAligned { class DRW_DimLinear : public DRW_DimAligned
{
public: public:
DRW_DimLinear() { DRW_DimLinear()
{
eType = DRW::DIMLINEAR; eType = DRW::DIMLINEAR;
type = 0; type = 0;
} }
@ -1406,10 +1473,13 @@ public:
* Class to handle aligned, linear or rotated dimension entity * Class to handle aligned, linear or rotated dimension entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_DimRadial : public DRW_Dimension { class DRW_DimRadial : public DRW_Dimension
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_DimRadial() { DRW_DimRadial()
{
eType = DRW::DIMRADIAL; eType = DRW::DIMRADIAL;
type = 4; type = 4;
} }
@ -1428,7 +1498,6 @@ public:
void setDiameterPoint(const DRW_Coord &p) { setPt5(p); } void setDiameterPoint(const DRW_Coord &p) { setPt5(p); }
auto getLeaderLength() const -> double { return getRa40(); } /*!< Leader length, code 40 */ auto getLeaderLength() const -> double { return getRa40(); } /*!< Leader length, code 40 */
void setLeaderLength(const double d) { setRa40(d); } void setLeaderLength(const double d) { setRa40(d); }
}; };
//! Class to handle radial dimension entity //! Class to handle radial dimension entity
@ -1436,10 +1505,13 @@ public:
* Class to handle aligned, linear or rotated dimension entity * Class to handle aligned, linear or rotated dimension entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_DimDiametric : public DRW_Dimension { class DRW_DimDiametric : public DRW_Dimension
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_DimDiametric() { DRW_DimDiametric()
{
eType = DRW::DIMDIAMETRIC; eType = DRW::DIMDIAMETRIC;
type = 3; type = 3;
} }
@ -1461,7 +1533,6 @@ public:
void setDiameter2Point(const DRW_Coord &p) { setDefPoint(p); } void setDiameter2Point(const DRW_Coord &p) { setDefPoint(p); }
auto getLeaderLength() const -> double { return getRa40(); } /*!< Leader length, code 40 */ auto getLeaderLength() const -> double { return getRa40(); } /*!< Leader length, code 40 */
void setLeaderLength(const double d) { setRa40(d); } void setLeaderLength(const double d) { setRa40(d); }
}; };
//! Class to handle angular dimension entity //! Class to handle angular dimension entity
@ -1469,14 +1540,18 @@ public:
* Class to handle angular dimension entity * Class to handle angular dimension entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_DimAngular : public DRW_Dimension { class DRW_DimAngular : public DRW_Dimension
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_DimAngular() { DRW_DimAngular()
{
eType = DRW::DIMANGULAR; eType = DRW::DIMANGULAR;
type = 2; type = 2;
} }
explicit DRW_DimAngular(const DRW_Dimension& d): DRW_Dimension(d) explicit DRW_DimAngular(const DRW_Dimension &d)
: DRW_Dimension(d)
{ {
eType = DRW::DIMANGULAR; eType = DRW::DIMANGULAR;
} }
@ -1494,23 +1569,25 @@ public:
void setSecondLine2(const DRW_Coord &p) { setDefPoint(p); } void setSecondLine2(const DRW_Coord &p) { setDefPoint(p); }
auto getDimPoint() const -> DRW_Coord { return getPt6(); } /*!< Dimension definition point, code 16, 26 & 36 */ auto getDimPoint() const -> DRW_Coord { return getPt6(); } /*!< Dimension definition point, code 16, 26 & 36 */
void setDimPoint(const DRW_Coord &p) { setPt6(p); } void setDimPoint(const DRW_Coord &p) { setPt6(p); }
}; };
//! Class to handle angular 3p dimension entity //! Class to handle angular 3p dimension entity
/*! /*!
* Class to handle angular 3p dimension entity * Class to handle angular 3p dimension entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_DimAngular3p : public DRW_Dimension { class DRW_DimAngular3p : public DRW_Dimension
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_DimAngular3p() { DRW_DimAngular3p()
{
eType = DRW::DIMANGULAR3P; eType = DRW::DIMANGULAR3P;
type = 5; type = 5;
} }
explicit DRW_DimAngular3p(const DRW_Dimension& d): DRW_Dimension(d) explicit DRW_DimAngular3p(const DRW_Dimension &d)
: DRW_Dimension(d)
{ {
eType = DRW::DIMANGULAR3P; eType = DRW::DIMANGULAR3P;
} }
@ -1523,7 +1600,6 @@ public:
void SetVertexPoint(const DRW_Coord &p) { setPt5(p); } void SetVertexPoint(const DRW_Coord &p) { setPt5(p); }
auto getDimPoint() const -> DRW_Coord { return getDefPoint(); } /*!< Dimension definition point, code 10, 20 & 30 */ auto getDimPoint() const -> DRW_Coord { return getDefPoint(); } /*!< Dimension definition point, code 10, 20 & 30 */
void setDimPoint(const DRW_Coord &p) { setDefPoint(p); } void setDimPoint(const DRW_Coord &p) { setDefPoint(p); }
}; };
//! Class to handle ordinate dimension entity //! Class to handle ordinate dimension entity
@ -1531,10 +1607,13 @@ public:
* Class to handle ordinate dimension entity * Class to handle ordinate dimension entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_DimOrdinate : public DRW_Dimension { class DRW_DimOrdinate : public DRW_Dimension
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_DimOrdinate() { DRW_DimOrdinate()
{
eType = DRW::DIMORDINATE; eType = DRW::DIMORDINATE;
type = 6; type = 6;
} }
@ -1550,17 +1629,17 @@ public:
void setFirstLine(const DRW_Coord &p) { setPt3(p); } void setFirstLine(const DRW_Coord &p) { setPt3(p); }
auto getSecondLine() const -> DRW_Coord { return getPt4(); } /*!< Leader end point, code 14, 24 & 34 */ auto getSecondLine() const -> DRW_Coord { return getPt4(); } /*!< Leader end point, code 14, 24 & 34 */
void setSecondLine(const DRW_Coord &p) { setPt4(p); } void setSecondLine(const DRW_Coord &p) { setPt4(p); }
}; };
//! Class to handle leader entity //! Class to handle leader entity
/*! /*!
* Class to handle leader entity * Class to handle leader entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Leader : public DRW_Entity { class DRW_Leader : public DRW_Entity
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Leader() DRW_Leader()
: style(), : style(),
@ -1583,8 +1662,10 @@ public:
{ {
eType = DRW::LEADER; eType = DRW::LEADER;
} }
~DRW_Leader() { ~DRW_Leader()
for(DRW_Coord *item : vertexlist) delete item; {
for (DRW_Coord *item : vertexlist)
delete item;
} }
void applyExtrusion() override {} void applyExtrusion() override {}
@ -1621,8 +1702,10 @@ private:
* Class to handle viewport entity * Class to handle viewport entity
* @author Rallaz * @author Rallaz
*/ */
class DRW_Viewport : public DRW_Point { class DRW_Viewport : public DRW_Point
{
SETENTFRIENDS SETENTFRIENDS
public: public:
DRW_Viewport() DRW_Viewport()
: pswidth(205), : pswidth(205),
@ -1676,7 +1759,8 @@ public:
private: private:
duint32 frozenLyCount; duint32 frozenLyCount;
};//RLZ: missing 15,25, 72, 331, 90, 340, 1, 281, 71, 74, 110, 120, 130, 111, 121,131, 112,122, 132, 345,346, and more... }; // RLZ: missing 15,25, 72, 331, 90, 340, 1, 281, 71, 74, 110, 120, 130, 111, 121,131, 112,122, 132, 345,346, and
// more...
// used //DRW_Coord basePoint; /*!< base point, code 10, 20 & 30 */ // used //DRW_Coord basePoint; /*!< base point, code 10, 20 & 30 */

View File

@ -411,7 +411,12 @@ auto dxfRW::writeLayer(DRW_Layer *ent) -> bool
auto dxfRW::writeTextstyle(DRW_Textstyle *ent) -> bool auto dxfRW::writeTextstyle(DRW_Textstyle *ent) -> bool
{ {
writer->writeString(0, "STYLE"); writer->writeString(0, "STYLE");
// stringstream cause crash in OS/X, bug#3597944
std::string name = ent->name;
transform(name.begin(), name.end(), name.begin(), toupper);
if (!dimstyleStd) if (!dimstyleStd)
{
if (name == "STANDARD")
{ {
// stringstream cause crash in OS/X, bug#3597944 // stringstream cause crash in OS/X, bug#3597944
std::string name = ent->name; std::string name = ent->name;
@ -419,9 +424,11 @@ auto dxfRW::writeTextstyle(DRW_Textstyle *ent) -> bool
if (name == "STANDARD") if (name == "STANDARD")
dimstyleStd = true; dimstyleStd = true;
} }
}
if (version > DRW::AC1009) if (version > DRW::AC1009)
{ {
writer->writeString(5, toHexStr(++entCount)); writer->writeString(5, toHexStr(++entCount));
textStyleMap[name] = entCount;
} }
if (version > DRW::AC1012) if (version > DRW::AC1012)
@ -555,12 +562,10 @@ auto dxfRW::writeDimstyle(DRW_Dimstyle *ent) -> bool
if (name == "STANDARD") if (name == "STANDARD")
dimstyleStd = true; dimstyleStd = true;
} }
if (version > DRW::AC1009) if (version > DRW::AC1009)
{ {
writer->writeString(105, toHexStr(++entCount)); writer->writeString(105, toHexStr(++entCount));
} }
if (version > DRW::AC1012) if (version > DRW::AC1012)
{ {
writer->writeString(330, "A"); writer->writeString(330, "A");
@ -574,15 +579,15 @@ auto dxfRW::writeDimstyle(DRW_Dimstyle *ent) -> bool
else else
writer->writeUtf8Caps(2, ent->name); writer->writeUtf8Caps(2, ent->name);
writer->writeInt16(70, ent->flags); writer->writeInt16(70, ent->flags);
if (version <= DRW::AC1009 || !(ent->dimpost.empty())) if (version == DRW::AC1009 || !(ent->dimpost.empty()))
writer->writeUtf8String(3, ent->dimpost); writer->writeUtf8String(3, ent->dimpost);
if (version <= DRW::AC1009 || !(ent->dimapost.empty())) if (version == DRW::AC1009 || !(ent->dimapost.empty()))
writer->writeUtf8String(4, ent->dimapost); writer->writeUtf8String(4, ent->dimapost);
if (version <= DRW::AC1009 || !(ent->dimblk.empty())) if (version == DRW::AC1009 || !(ent->dimblk.empty()))
writer->writeUtf8String(5, ent->dimblk); writer->writeUtf8String(5, ent->dimblk);
if (version <= DRW::AC1009 || !(ent->dimblk1.empty())) if (version == DRW::AC1009 || !(ent->dimblk1.empty()))
writer->writeUtf8String(6, ent->dimblk1); writer->writeUtf8String(6, ent->dimblk1);
if (version <= DRW::AC1009 || !(ent->dimblk2.empty())) if (version == DRW::AC1009 || !(ent->dimblk2.empty()))
writer->writeUtf8String(7, ent->dimblk2); writer->writeUtf8String(7, ent->dimblk2);
writer->writeDouble(40, ent->dimscale); writer->writeDouble(40, ent->dimscale);
writer->writeDouble(41, ent->dimasz); writer->writeDouble(41, ent->dimasz);
@ -593,6 +598,8 @@ auto dxfRW::writeDimstyle(DRW_Dimstyle *ent) -> bool
writer->writeDouble(46, ent->dimdle); writer->writeDouble(46, ent->dimdle);
writer->writeDouble(47, ent->dimtp); writer->writeDouble(47, ent->dimtp);
writer->writeDouble(48, ent->dimtm); writer->writeDouble(48, ent->dimtm);
if (version > DRW::AC1018 || !qFuzzyIsNull(ent->dimfxl))
writer->writeDouble(49, ent->dimfxl);
writer->writeDouble(140, ent->dimtxt); writer->writeDouble(140, ent->dimtxt);
writer->writeDouble(141, ent->dimcen); writer->writeDouble(141, ent->dimcen);
writer->writeDouble(142, ent->dimtsz); writer->writeDouble(142, ent->dimtsz);
@ -664,16 +671,28 @@ auto dxfRW::writeDimstyle(DRW_Dimstyle *ent) -> bool
{ {
writer->writeInt16(289, ent->dimatfit); writer->writeInt16(289, ent->dimatfit);
} }
if (version > DRW::AC1009 && !ent->dimtxsty.empty()) if (version > DRW::AC1018 && ent->dimfxlon != 0)
writer->writeInt16(290, ent->dimfxlon);
if (version > DRW::AC1009)
{ {
writer->writeUtf8String(340, ent->dimtxsty); std::string txstyname = ent->dimtxsty;
std::transform(txstyname.begin(), txstyname.end(), txstyname.begin(), ::toupper);
if (textStyleMap.count(txstyname) > 0)
{
int txstyHandle = (*(textStyleMap.find(txstyname))).second;
writer->writeUtf8String(340, toHexStr(txstyHandle));
}
} }
if (version > DRW::AC1014) if (version > DRW::AC1014)
{ {
writer->writeUtf8String(341, ent->dimldrblk); if (blockMap.count(ent->dimldrblk) > 0)
{
int blkHandle = (*(blockMap.find(ent->dimldrblk))).second;
writer->writeUtf8String(341, toHexStr(blkHandle));
writer->writeInt16(371, ent->dimlwd); writer->writeInt16(371, ent->dimlwd);
writer->writeInt16(372, ent->dimlwe); writer->writeInt16(372, ent->dimlwe);
} }
}
return true; return true;
} }

View File

@ -158,6 +158,7 @@ private:
bool writingBlock; bool writingBlock;
int elParts; /*!< parts number when convert ellipse to polyline */ int elParts; /*!< parts number when convert ellipse to polyline */
std::unordered_map<std::string, int> blockMap; std::unordered_map<std::string, int> blockMap;
std::unordered_map<std::string, int> textStyleMap;
std::vector<DRW_ImageDef *> imageDef; /*!< imageDef list */ std::vector<DRW_ImageDef *> imageDef; /*!< imageDef list */
int currHandle; int currHandle;