Merged changed from SolveSpace's independent fork of libdxfrw.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-06-21 14:54:17 +03:00
parent 3f570fc52e
commit 388bad3535
29 changed files with 403 additions and 400 deletions

View File

@ -165,10 +165,12 @@ enum TransparencyCodes {
*/ */
class DRW_Coord { class DRW_Coord {
public: public:
DRW_Coord():x(0), y(0),z(0) {} DRW_Coord() { x = 0; y = 0; z = 0; }
DRW_Coord(double ix, double iy, double iz): x(ix), y(iy),z(iz){} DRW_Coord(double ix, double iy, double iz) {
x = ix; y = iy; z = iz;
}
DRW_Coord& operator = (const DRW_Coord& data) { DRW_Coord operator = (const DRW_Coord& data) {
x = data.x; y = data.y; z = data.z; x = data.x; y = data.y; z = data.z;
return *this; return *this;
} }
@ -197,9 +199,16 @@ public:
*/ */
class DRW_Vertex2D { class DRW_Vertex2D {
public: public:
DRW_Vertex2D(): x(0), y(0), stawidth(0), endwidth(0), bulge(0){} DRW_Vertex2D() {
// eType = DRW::LWPOLYLINE;
DRW_Vertex2D(double sx, double sy, double b): x(sx), y(sy), stawidth(0), endwidth(0), bulge(b) {} stawidth = endwidth = bulge = 0;
}
DRW_Vertex2D(double sx, double sy, double b) {
stawidth = endwidth = 0;
x = sx;
y =sy;
bulge = b;
}
public: public:
double x; /*!< x coordinate, code 10 */ double x; /*!< x coordinate, code 10 */
@ -225,61 +234,68 @@ public:
INVALID INVALID
}; };
//TODO: add INT64 support //TODO: add INT64 support
DRW_Variant(): sdata(std::string()), vdata(), content(0), vType(INVALID), vCode(0) {} DRW_Variant() {
type = INVALID;
}
DRW_Variant(int c, dint32 i): sdata(std::string()), vdata(), content(i), vType(INTEGER), vCode(c){} DRW_Variant(int c, dint32 i) {
code = c; addInt(i);
DRW_Variant(int c, duint32 i): sdata(std::string()), vdata(), content(static_cast<dint32>(i)), vType(INTEGER), vCode(c) {} }
DRW_Variant(int c, duint32 i) {
DRW_Variant(int c, double d): sdata(std::string()), vdata(), content(d), vType(DOUBLE), vCode(c) {} code = c; addInt(static_cast<dint32>(i));//RLZ: verify if worrk with big numbers
}
DRW_Variant(int c, UTF8STRING s): sdata(s), vdata(), content(&sdata), vType(STRING), vCode(c) {} DRW_Variant(int c, double d) {
code = c; addDouble(d);
DRW_Variant(int c, DRW_Coord crd): sdata(std::string()), vdata(crd), content(&vdata), vType(COORD), vCode(c) {} }
DRW_Variant(int c, UTF8STRING s) {
DRW_Variant(const DRW_Variant& d): sdata(d.sdata), vdata(d.vdata), content(d.content), vType(d.vType), vCode(d.vCode) { code = c; addString(s);
if (d.vType == COORD) }
DRW_Variant(int c, DRW_Coord crd) {
code = c; addCoord(crd);
}
DRW_Variant(const DRW_Variant& d) {
code = d.code;
type = d.type;
content = d.content;
if (d.type == COORD) {
vdata = d.vdata;
content.v = &vdata; content.v = &vdata;
if (d.vType == STRING) }
if (d.type == STRING) {
sdata = d.sdata;
content.s = &sdata; content.s = &sdata;
} }
}
~DRW_Variant() { ~DRW_Variant() {
} }
void addString(int c, UTF8STRING s) {vType = STRING; sdata = s; content.s = &sdata; vCode=c;} void addString(UTF8STRING s) {setType(STRING); sdata = s; content.s = &sdata;}
void addInt(int c, int i) {vType = INTEGER; content.i = i; vCode=c;} void addInt(int i) {setType(INTEGER); content.i = i;}
void addDouble(int c, double d) {vType = DOUBLE; content.d = d; vCode=c;} void addDouble(double d) {setType(DOUBLE); content.d = d;}
void addCoord(int c, DRW_Coord v) {vType = COORD; vdata = v; content.v = &vdata; vCode=c;} void addCoord() {setType(COORD); vdata.x=0.0; vdata.y=0.0; vdata.z=0.0; content.v = &vdata;}
void setCoordX(double d) { if (vType == COORD) vdata.x = d;} void addCoord(DRW_Coord v) {setType(COORD); vdata = v; content.v = &vdata;}
void setCoordY(double d) { if (vType == COORD) vdata.y = d;} void setType(enum TYPE t) { type = t;}
void setCoordZ(double d) { if (vType == COORD) vdata.z = d;} void setCoordX(double d) { if (type == COORD) vdata.x = d;}
enum TYPE type() { return vType;} void setCoordY(double d) { if (type == COORD) vdata.y = d;}
int code() { return vCode;} /*!< returns dxf code of this value*/ void setCoordZ(double d) { if (type == COORD) vdata.z = d;}
private: private:
std::string sdata; typedef union {
DRW_Coord vdata;
private:
union DRW_VarContent{
UTF8STRING *s; UTF8STRING *s;
dint32 i; dint32 i;
double d; double d;
DRW_Coord *v; DRW_Coord *v;
} DRW_VarContent;
DRW_VarContent(UTF8STRING *sd):s(sd){}
DRW_VarContent(dint32 id):i(id){}
DRW_VarContent(double dd):d(dd){}
DRW_VarContent(DRW_Coord *vd):v(vd){}
};
public: public:
DRW_VarContent content; DRW_VarContent content;
private: enum TYPE type;
enum TYPE vType; int code; /*!< dxf code of this value*/
int vCode; /*!< dxf code of this value*/
private:
std::string sdata;
DRW_Coord vdata;
}; };
//! Class to handle dwg handles //! Class to handle dwg handles
@ -289,8 +305,11 @@ private:
*/ */
class dwgHandle{ class dwgHandle{
public: public:
dwgHandle(): code(0), size(0), ref(0){} dwgHandle(){
code=0;
size=0;
ref=0;
}
~dwgHandle(){} ~dwgHandle(){}
duint8 code; duint8 code;
duint8 size; duint8 size;
@ -475,4 +494,3 @@ public:
#endif #endif
// EOF // EOF

View File

@ -56,4 +56,3 @@ public: //only for read dwg
#endif #endif
// EOF // EOF

View File

@ -116,7 +116,10 @@ bool DRW_Entity::parseCode(int code, dxfReader *reader){
case 1011: case 1011:
case 1012: case 1012:
case 1013: case 1013:
curr = new DRW_Variant(code, DRW_Coord(reader->getDouble(), 0.0, 0.0)); curr = new DRW_Variant();
curr->addCoord();
curr->setCoordX(reader->getDouble());
curr->code = code;
extData.push_back(curr); extData.push_back(curr);
break; break;
case 1020: case 1020:
@ -156,28 +159,28 @@ bool DRW_Entity::parseDxfGroups(int code, dxfReader *reader){
int nc; int nc;
std::string appName= reader->getString(); std::string appName= reader->getString();
if (!appName.empty() && appName.at(0)== '{'){ if (!appName.empty() && appName.at(0)== '{'){
curr.addString(code, appName.substr(1, (int) appName.size()-1)); curr.addString(appName.substr(1, (int) appName.size()-1));
curr.code = code;
ls.push_back(curr); ls.push_back(curr);
while (code !=102 && appName.at(0)== '}'){ while (code !=102 && appName.at(0)== '}'){
reader->readRec(&nc);//RLZ curr.code = code or nc? reader->readRec(&nc);
// curr.code = code; curr.code = code;
//RLZ code == 330 || code == 360 OR nc == 330 || nc == 360 ?
if (code == 330 || code == 360) if (code == 330 || code == 360)
curr.addInt(code, reader->getHandleString());//RLZ code or nc curr.addInt(reader->getHandleString());
else { else {
switch (reader->type) { switch (reader->type) {
case dxfReader::STRING: case dxfReader::STRING:
curr.addString(code, reader->getString());//RLZ code or nc curr.addString(reader->getString());
break; break;
case dxfReader::INT32: case dxfReader::INT32:
case dxfReader::INT64: case dxfReader::INT64:
curr.addInt(code, reader->getInt32());//RLZ code or nc curr.addInt(reader->getInt32());
break; break;
case dxfReader::DOUBLE: case dxfReader::DOUBLE:
curr.addDouble(code, reader->getDouble());//RLZ code or nc curr.addDouble(reader->getDouble());
break; break;
case dxfReader::BOOL: case dxfReader::BOOL:
curr.addInt(code, reader->getInt32());//RLZ code or nc curr.addInt(reader->getInt32());
break; break;
default: default:
break; break;
@ -1427,6 +1430,59 @@ void DRW_MText::parseCode(int code, dxfReader *reader){
case 44: case 44:
interlin = reader->getDouble(); interlin = reader->getDouble();
break; break;
case 71: {
// Attachment point
Attach a = (Attach)reader->getInt32();
switch(a) {
case TopLeft:
alignV = VTop;
alignH = HLeft;
break;
case TopCenter:
alignV = VTop;
alignH = HCenter;
break;
case TopRight:
alignV = VTop;
alignH = HRight;
break;
case MiddleLeft:
alignV = VMiddle;
alignH = HLeft;
break;
case MiddleCenter:
alignV = VMiddle;
alignH = HCenter;
break;
case MiddleRight:
alignV = VMiddle;
alignH = HRight;
break;
case BottomLeft:
alignV = VBottom;
alignH = HLeft;
break;
case BottomCenter:
alignV = VBottom;
alignH = HCenter;
break;
case BottomRight:
alignV = VBottom;
alignH = HRight;
break;
}
} break;
case 72:
// To prevent redirection to DRW_Text::parseCode.
// This code meaning is different for MTEXT.
// Actually: Drawing direction
break;
case 73:
// To prevent redirection to DRW_Text::parseCode.
// This code meaning is different for MTEXT.
// Actually: Mtext line spacing style
break;
default: default:
DRW_Text::parseCode(code, reader); DRW_Text::parseCode(code, reader);
break; break;
@ -1906,7 +1962,6 @@ bool DRW_Hatch::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
spline->controllist.reserve(spline->ncontrol); spline->controllist.reserve(spline->ncontrol);
for (dint32 j = 0; j < spline->ncontrol;++j){ for (dint32 j = 0; j < spline->ncontrol;++j){
DRW_Coord* crd = new DRW_Coord(buf->get3BitDouble()); DRW_Coord* crd = new DRW_Coord(buf->get3BitDouble());
spline->controllist.push_back(crd);
if(isRational) if(isRational)
crd->z = buf->getBitDouble(); //RLZ: investigate how store weight crd->z = buf->getBitDouble(); //RLZ: investigate how store weight
spline->controllist.push_back(crd); spline->controllist.push_back(crd);
@ -2080,8 +2135,9 @@ void DRW_Spline::parseCode(int code, dxfReader *reader){
case 40: case 40:
knotslist.push_back(reader->getDouble()); knotslist.push_back(reader->getDouble());
break; break;
// case 41: case 41:
// break; weightlist.push_back(reader->getDouble());
break;
default: default:
DRW_Entity::parseCode(code, reader); DRW_Entity::parseCode(code, reader);
break; break;
@ -2238,14 +2294,14 @@ bool DRW_Image::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
sizev = buf->getRawDouble(); sizev = buf->getRawDouble();
DRW_DBG("\nsize U: "); DRW_DBG(sizeu); DRW_DBG("\nsize V: "); DRW_DBG(sizev); DRW_DBG("\nsize U: "); DRW_DBG(sizeu); DRW_DBG("\nsize V: "); DRW_DBG(sizev);
duint16 displayProps = buf->getBitShort(); duint16 displayProps = buf->getBitShort();
DRW_UNUSED(displayProps);//RLZ: temporary, complete API (void)displayProps;
clip = buf->getBit(); clip = buf->getBit();
brightness = buf->getRawChar8(); brightness = buf->getRawChar8();
contrast = buf->getRawChar8(); contrast = buf->getRawChar8();
fade = buf->getRawChar8(); fade = buf->getRawChar8();
if (version > DRW::AC1021){ //2010+ if (version > DRW::AC1021){ //2010+
bool clipMode = buf->getBit(); bool clipMode = buf->getBit();
DRW_UNUSED(clipMode);//RLZ: temporary, complete API (void)clipMode;
} }
duint16 clipType = buf->getBitShort(); duint16 clipType = buf->getBitShort();
if (clipType == 1){ if (clipType == 1){
@ -2358,6 +2414,10 @@ void DRW_Dimension::parseCode(int code, dxfReader *reader){
case 41: case 41:
linefactor = reader->getDouble(); linefactor = reader->getDouble();
break; break;
case 42:
actual = reader->getDouble();
hasActual = (actual != 0.0);
break;
case 53: case 53:
rot = reader->getDouble(); rot = reader->getDouble();
break; break;

View File

@ -99,17 +99,28 @@ class DRW_Entity {
SETENTFRIENDS SETENTFRIENDS
public: public:
//initializes default values //initializes default values
//handles: default no handle (0), color: default BYLAYER (256), 24 bits color: default -1 (not set) DRW_Entity() {
//line weight: default BYLAYER (dxf -1, dwg 29), space: default ModelSpace (0) eType = DRW::UNKNOWN;
DRW_Entity(): eType(DRW::UNKNOWN), handle(DRW::NoHandle), parentHandle(DRW::NoHandle), appData(0), handle = parentHandle = DRW::NoHandle; //no handle (0)
space(DRW::ModelSpace), layer("0"), lineType("BYLAYER"), material(DRW::MaterialByLayer), lineType = "BYLAYER";
color(DRW::ColorByLayer), lWeight(DRW_LW_Conv::widthByLayer), ltypeScale(1.0), visible(true), color = DRW::ColorByLayer; // default BYLAYER (256)
numProxyGraph(0), proxyGraphics(std::string()), color24(-1), colorName(std::string()), ltypeScale = 1.0;
transparency(DRW::Opaque), plotStyle(DRW::DefaultPlotStyle), shadow(DRW::CastAndReceieveShadows), visible = true;
haveExtrusion(false), extData(), haveNextLinks(0),plotFlags(0), ltFlags(0),materialFlag(0), layer = "0";
shadowFlag(0), lTypeH(dwgHandle()), layerH(dwgHandle()), nextEntLink(0), prevEntLink(0), lWeight = DRW_LW_Conv::widthByLayer; // default BYLAYER (dxf -1, dwg 29)
ownerHandle(false), xDictFlag(0), numReactors(0), objSize(0), oType(0), extAxisX(DRW_Coord()), space = DRW::ModelSpace; // default ModelSpace (0)
extAxisY(DRW_Coord()), curr(NULL) {} haveExtrusion = false;
color24 = -1; //default -1 not set
numProxyGraph = 0;
shadow = DRW::CastAndReceieveShadows;
material = DRW::MaterialByLayer;
plotStyle = DRW::DefaultPlotStyle;
transparency = DRW::Opaque;
nextEntLink = prevEntLink = 0;
numReactors = xDictFlag = 0;
curr = NULL;
ownerHandle= false;
}
DRW_Entity(const DRW_Entity& e) { DRW_Entity(const DRW_Entity& e) {
eType = e.eType; eType = e.eType;
@ -135,6 +146,7 @@ public:
xDictFlag = e.xDictFlag; xDictFlag = e.xDictFlag;
curr = NULL; curr = NULL;
ownerHandle= false; ownerHandle= false;
// curr = 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)));
} }
@ -155,6 +167,15 @@ public:
virtual void applyExtrusion() = 0; virtual void applyExtrusion() = 0;
void setWidthMm(double millimeters) {
if(millimeters < 0.0) {
lWeight = DRW_LW_Conv::widthByLayer;
return;
}
if(millimeters > 2.11) millimeters = 2.11;
lWeight = DRW_LW_Conv::dxfInt2lineWidth(int(floor(millimeters * 100.0)));
}
protected: protected:
//parses dxf pair to read entity //parses dxf pair to read entity
bool parseCode(int code, dxfReader *reader); bool parseCode(int code, dxfReader *reader);
@ -174,8 +195,8 @@ protected:
public: public:
enum DRW::ETYPE eType; /*!< enum: entity type, code 0 */ enum DRW::ETYPE eType; /*!< enum: entity type, code 0 */
duint32 handle; /*!< entity identifier, code 5 */ duint32 handle; /*!< entity identifier, code 5 */
duint32 parentHandle; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */
std::list<std::list<DRW_Variant> > appData; /*!< list of application data, code 102 */ std::list<std::list<DRW_Variant> > appData; /*!< list of application data, code 102 */
duint32 parentHandle; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */
DRW::Space space; /*!< space indicator, code 67*/ DRW::Space space; /*!< space indicator, code 67*/
UTF8STRING layer; /*!< layer name, code 8 */ UTF8STRING layer; /*!< layer name, code 8 */
UTF8STRING lineType; /*!< line type, code 6 */ UTF8STRING lineType; /*!< line type, code 6 */
@ -603,9 +624,7 @@ public:
} }
~DRW_LWPolyline() { ~DRW_LWPolyline() {
while (!vertlist.empty()) { for(DRW_Vertex2D *item : vertlist) delete item;
vertlist.pop_back();
}
} }
virtual void applyExtrusion(); virtual void applyExtrusion();
void addVertex (DRW_Vertex2D v) { void addVertex (DRW_Vertex2D v) {
@ -796,10 +815,22 @@ public:
flags = vertexcount = facecount = 0; flags = vertexcount = facecount = 0;
smoothM = smoothN = curvetype = 0; smoothM = smoothN = curvetype = 0;
} }
~DRW_Polyline() {
while (!vertlist.empty()) { DRW_Polyline(const DRW_Polyline& p) : DRW_Point(p) {
vertlist.pop_back(); flags = p.flags ;
defstawidth = p.defstawidth;
defendwidth = p.defendwidth;
vertexcount = p.vertexcount;
facecount = p.facecount ;
smoothM = p.smoothM ;
smoothN = p.smoothN ;
curvetype = p.curvetype ;
for (unsigned i=0; i<p.vertlist.size(); i++)// RLZ ok or new
this->vertlist.push_back( new DRW_Vertex( *(p.vertlist.at(i)) ) );
} }
~DRW_Polyline() {
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();
@ -853,13 +884,30 @@ public:
tolknot = tolcontrol = tolfit = 0.0000001; tolknot = tolcontrol = tolfit = 0.0000001;
} }
DRW_Spline(const DRW_Spline& p):DRW_Entity(p){
eType = DRW::SPLINE;
normalVec = p.normalVec ;
tgStart = p.tgStart ;
tgEnd = p.tgEnd ;
flags = p.flags ;
degree = p.degree ;
nknots = p.nknots ;
ncontrol = p.ncontrol ;
nfit = p.nfit ;
tolknot = p.tolknot ;
tolcontrol = p.tolcontrol;
tolfit = p.tolfit ;
for(double v : p.knotslist) knotslist.push_back(v);
for(double v : p.weightlist) weightlist.push_back(v);
for(DRW_Coord *v : p.controllist) controllist.push_back(new DRW_Coord(*v));
for(DRW_Coord *v : p.fitlist) fitlist.push_back(new DRW_Coord(*v));
}
~DRW_Spline() { ~DRW_Spline() {
while (!controllist.empty()) { for(DRW_Coord *item : controllist) delete item;
controllist.pop_back(); for(DRW_Coord *item : fitlist) delete item;
}
while (!fitlist.empty()) {
fitlist.pop_back();
}
} }
virtual void applyExtrusion(){} virtual void applyExtrusion(){}
@ -890,6 +938,7 @@ public:
double tolfit; /*!< fit point tolerance, code 44, default 0.0000001 */ double tolfit; /*!< fit point tolerance, code 44, default 0.0000001 */
std::vector<double> knotslist; /*!< knots list, code 40 */ std::vector<double> knotslist; /*!< knots list, code 40 */
std::vector<double> weightlist; /*!< weight list, code 41 */
std::vector<DRW_Coord *> controllist; /*!< control points list, code 10, 20 & 30 */ std::vector<DRW_Coord *> controllist; /*!< control points list, code 10, 20 & 30 */
std::vector<DRW_Coord *> fitlist; /*!< fit points list, code 11, 21 & 31 */ std::vector<DRW_Coord *> fitlist; /*!< fit points list, code 11, 21 & 31 */
@ -911,16 +960,12 @@ public:
} }
~DRW_HatchLoop() { ~DRW_HatchLoop() {
/* while (!pollist.empty()) { // for(DRW_LWPolyline *item : pollist) delete item;
pollist.pop_back(); for(DRW_Entity *item : objlist) delete item;
}*/
while (!objlist.empty()) {
objlist.pop_back();
}
} }
void update() { void update() {
numedges = objlist.size(); numedges = (int)objlist.size();
} }
public: public:
@ -952,9 +997,7 @@ public:
} }
~DRW_Hatch() { ~DRW_Hatch() {
while (!looplist.empty()) { for(DRW_HatchLoop *item : looplist) delete item;
looplist.pop_back();
}
} }
void appendLoop (DRW_HatchLoop *v) { void appendLoop (DRW_HatchLoop *v) {
@ -1089,6 +1132,9 @@ public:
defPoint.z = extPoint.x = extPoint.y = 0; defPoint.z = extPoint.x = extPoint.y = 0;
textPoint.z = rot = 0; textPoint.z = rot = 0;
clonePoint.x = clonePoint.y = clonePoint.z = 0; clonePoint.x = clonePoint.y = clonePoint.z = 0;
length = 0.0;
hasActual = false;
actual = 0.0;
} }
DRW_Dimension(const DRW_Dimension& d): DRW_Entity(d) { DRW_Dimension(const DRW_Dimension& d): DRW_Entity(d) {
@ -1112,6 +1158,8 @@ public:
arcPoint = d.arcPoint; arcPoint = d.arcPoint;
circlePoint = d.circlePoint; circlePoint = d.circlePoint;
length = d.length; length = d.length;
hasActual = d.hasActual;
actual = d.actual;
//RLZ needed a def value for this: hdir = ??? //RLZ needed a def value for this: hdir = ???
} }
virtual ~DRW_Dimension() {} virtual ~DRW_Dimension() {}
@ -1147,6 +1195,9 @@ public:
std::string getName(){return name;} /*!< Name of the block that contains the entities, code 2 */ std::string getName(){return name;} /*!< Name of the block that contains the entities, code 2 */
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 */
bool hasActualMeasurement() const { return hasActual; }
void setActualMeasurement(double value) { hasActual = true; actual = value; }
double getActualMeasurement() const { return actual; }
protected: protected:
DRW_Coord getPt2() const {return clonePoint;} DRW_Coord getPt2() const {return clonePoint;}
@ -1189,6 +1240,8 @@ private:
DRW_Coord circlePoint; /*!< Definition point for diameter, radius & angular dims code 15, 25 & 35 (WCS) */ DRW_Coord circlePoint; /*!< Definition point for diameter, radius & angular dims code 15, 25 & 35 (WCS) */
DRW_Coord arcPoint; /*!< Point defining dimension arc, x coordinate, code 16, 26 & 36 (OCS) */ DRW_Coord arcPoint; /*!< Point defining dimension arc, x coordinate, code 16, 26 & 36 (OCS) */
double length; /*!< Leader length, code 40 */ double length; /*!< Leader length, code 40 */
bool hasActual; /*!< Actual measurement has been read, code 42 */
double actual; /*!< Actual measurement (optional; read-only value), code 42 */
protected: protected:
dwgHandle dimStyleH; dwgHandle dimStyleH;
@ -1206,6 +1259,7 @@ class DRW_DimAligned : public DRW_Dimension {
public: public:
DRW_DimAligned(){ DRW_DimAligned(){
eType = DRW::DIMALIGNED; eType = DRW::DIMALIGNED;
type = 1;
} }
DRW_DimAligned(const DRW_Dimension& d): DRW_Dimension(d) { DRW_DimAligned(const DRW_Dimension& d): DRW_Dimension(d) {
eType = DRW::DIMALIGNED; eType = DRW::DIMALIGNED;
@ -1234,6 +1288,7 @@ class DRW_DimLinear : public DRW_DimAligned {
public: public:
DRW_DimLinear() { DRW_DimLinear() {
eType = DRW::DIMLINEAR; eType = DRW::DIMLINEAR;
type = 0;
} }
DRW_DimLinear(const DRW_Dimension& d): DRW_DimAligned(d) { DRW_DimLinear(const DRW_Dimension& d): DRW_DimAligned(d) {
eType = DRW::DIMLINEAR; eType = DRW::DIMLINEAR;
@ -1255,6 +1310,7 @@ class DRW_DimRadial : public DRW_Dimension {
public: public:
DRW_DimRadial() { DRW_DimRadial() {
eType = DRW::DIMRADIAL; eType = DRW::DIMRADIAL;
type = 4;
} }
DRW_DimRadial(const DRW_Dimension& d): DRW_Dimension(d) { DRW_DimRadial(const DRW_Dimension& d): DRW_Dimension(d) {
eType = DRW::DIMRADIAL; eType = DRW::DIMRADIAL;
@ -1281,6 +1337,7 @@ class DRW_DimDiametric : public DRW_Dimension {
public: public:
DRW_DimDiametric() { DRW_DimDiametric() {
eType = DRW::DIMDIAMETRIC; eType = DRW::DIMDIAMETRIC;
type = 3;
} }
DRW_DimDiametric(const DRW_Dimension& d): DRW_Dimension(d) { DRW_DimDiametric(const DRW_Dimension& d): DRW_Dimension(d) {
eType = DRW::DIMDIAMETRIC; eType = DRW::DIMDIAMETRIC;
@ -1307,6 +1364,7 @@ class DRW_DimAngular : public DRW_Dimension {
public: public:
DRW_DimAngular() { DRW_DimAngular() {
eType = DRW::DIMANGULAR; eType = DRW::DIMANGULAR;
type = 2;
} }
DRW_DimAngular(const DRW_Dimension& d): DRW_Dimension(d) { DRW_DimAngular(const DRW_Dimension& d): DRW_Dimension(d) {
eType = DRW::DIMANGULAR; eType = DRW::DIMANGULAR;
@ -1338,6 +1396,7 @@ class DRW_DimAngular3p : public DRW_Dimension {
public: public:
DRW_DimAngular3p() { DRW_DimAngular3p() {
eType = DRW::DIMANGULAR3P; eType = DRW::DIMANGULAR3P;
type = 5;
} }
DRW_DimAngular3p(const DRW_Dimension& d): DRW_Dimension(d) { DRW_DimAngular3p(const DRW_Dimension& d): DRW_Dimension(d) {
eType = DRW::DIMANGULAR3P; eType = DRW::DIMANGULAR3P;
@ -1366,6 +1425,7 @@ class DRW_DimOrdinate : public DRW_Dimension {
public: public:
DRW_DimOrdinate() { DRW_DimOrdinate() {
eType = DRW::DIMORDINATE; eType = DRW::DIMORDINATE;
type = 6;
} }
DRW_DimOrdinate(const DRW_Dimension& d): DRW_Dimension(d) { DRW_DimOrdinate(const DRW_Dimension& d): DRW_Dimension(d) {
eType = DRW::DIMORDINATE; eType = DRW::DIMORDINATE;
@ -1400,9 +1460,7 @@ public:
extrusionPoint.z = 1.0; extrusionPoint.z = 1.0;
} }
~DRW_Leader() { ~DRW_Leader() {
while (!vertexlist.empty()) { for(DRW_Coord *item : vertexlist) delete item;
vertexlist.pop_back();
}
} }
virtual void applyExtrusion(){} virtual void applyExtrusion(){}
@ -1512,4 +1570,3 @@ private:
#endif #endif
// EOF // EOF

View File

@ -105,4 +105,3 @@ private:
#endif #endif
// EOF // EOF

View File

@ -28,25 +28,25 @@
*/ */
class DRW_Interface { class DRW_Interface {
public: public:
DRW_Interface() DRW_Interface() {
{} }
virtual ~DRW_Interface() = default; virtual ~DRW_Interface() = default;
/** Called when header is parsed. */ /** Called when header is parsed. */
virtual void addHeader(const DRW_Header* data) = 0; virtual void addHeader(const DRW_Header *) { }
/** Called for every line Type. */ /** Called for every line Type. */
virtual void addLType(const DRW_LType& data) = 0; virtual void addLType(const DRW_LType &) { }
/** Called for every layer. */ /** Called for every layer. */
virtual void addLayer(const DRW_Layer& data) = 0; virtual void addLayer(const DRW_Layer &) { }
/** Called for every dim style. */ /** Called for every dim style. */
virtual void addDimStyle(const DRW_Dimstyle& data) = 0; virtual void addDimStyle(const DRW_Dimstyle &) { }
/** Called for every VPORT table. */ /** Called for every VPORT table. */
virtual void addVport(const DRW_Vport& data) = 0; virtual void addVport(const DRW_Vport &) { }
/** Called for every text style. */ /** Called for every text style. */
virtual void addTextStyle(const DRW_Textstyle& data) = 0; virtual void addTextStyle(const DRW_Textstyle &) { }
/** Called for every AppId entry. */ /** Called for every AppId entry. */
virtual void addAppId(const DRW_AppId& data) = 0; virtual void addAppId(const DRW_AppId &) { }
/** /**
* Called for every block. Note: all entities added after this * Called for every block. Note: all entities added after this
@ -54,146 +54,137 @@ public:
* *
* @see endBlock() * @see endBlock()
*/ */
virtual void addBlock(const DRW_Block& data) = 0; virtual void addBlock(const DRW_Block &) { }
/**
* In DWG called when the following entities corresponding to a
* block different from the current. Note: all entities added after this
* command go into this block until setBlock() is called already.
*
* int handle are the value of DRW_Block::handleBlock added with addBlock()
*/
virtual void setBlock(const int handle) = 0;
/** Called to end the current block */ /** Called to end the current block */
virtual void endBlock() = 0; virtual void endBlock() { }
/** Called for every point */ /** Called for every point */
virtual void addPoint(const DRW_Point& data) = 0; virtual void addPoint(const DRW_Point &) { }
/** Called for every line */ /** Called for every line */
virtual void addLine(const DRW_Line& data) = 0; virtual void addLine(const DRW_Line &) { }
/** Called for every ray */ /** Called for every ray */
virtual void addRay(const DRW_Ray& data) = 0; virtual void addRay(const DRW_Ray &) { }
/** Called for every xline */ /** Called for every xline */
virtual void addXline(const DRW_Xline& data) = 0; virtual void addXline(const DRW_Xline &) { }
/** Called for every arc */ /** Called for every arc */
virtual void addArc(const DRW_Arc& data) = 0; virtual void addArc(const DRW_Arc &) { }
/** Called for every circle */ /** Called for every circle */
virtual void addCircle(const DRW_Circle& data) = 0; virtual void addCircle(const DRW_Circle &) { }
/** Called for every ellipse */ /** Called for every ellipse */
virtual void addEllipse(const DRW_Ellipse& data) = 0; virtual void addEllipse(const DRW_Ellipse &) { }
/** Called for every lwpolyline */ /** Called for every lwpolyline */
virtual void addLWPolyline(const DRW_LWPolyline& data) = 0; virtual void addLWPolyline(const DRW_LWPolyline &) { }
/** Called for every polyline start */ /** Called for every polyline start */
virtual void addPolyline(const DRW_Polyline& data) = 0; virtual void addPolyline(const DRW_Polyline &) { }
/** Called for every spline */ /** Called for every spline */
virtual void addSpline(const DRW_Spline* data) = 0; virtual void addSpline(const DRW_Spline *) { }
/** Called for every spline knot value */ /** Called for every spline knot value */
virtual void addKnot(const DRW_Entity& data) = 0; virtual void addKnot(const DRW_Entity &) { }
/** Called for every insert. */ /** Called for every insert. */
virtual void addInsert(const DRW_Insert& data) = 0; virtual void addInsert(const DRW_Insert &) { }
/** Called for every trace start */ /** Called for every trace start */
virtual void addTrace(const DRW_Trace& data) = 0; virtual void addTrace(const DRW_Trace &) { }
/** Called for every 3dface start */ /** Called for every 3dface start */
virtual void add3dFace(const DRW_3Dface& data) = 0; virtual void add3dFace(const DRW_3Dface &) { }
/** Called for every solid start */ /** Called for every solid start */
virtual void addSolid(const DRW_Solid& data) = 0; virtual void addSolid(const DRW_Solid &) { }
/** Called for every Multi Text entity. */ /** Called for every Multi Text entity. */
virtual void addMText(const DRW_MText& data) = 0; virtual void addMText(const DRW_MText &) { }
/** Called for every Text entity. */ /** Called for every Text entity. */
virtual void addText(const DRW_Text& data) = 0; virtual void addText(const DRW_Text &) { }
/** /**
* Called for every aligned dimension entity. * Called for every aligned dimension entity.
*/ */
virtual void addDimAlign(const DRW_DimAligned *data) = 0; virtual void addDimAlign(const DRW_DimAligned *) { }
/** /**
* Called for every linear or rotated dimension entity. * Called for every linear or rotated dimension entity.
*/ */
virtual void addDimLinear(const DRW_DimLinear *data) = 0; virtual void addDimLinear(const DRW_DimLinear *) { }
/** /**
* Called for every radial dimension entity. * Called for every radial dimension entity.
*/ */
virtual void addDimRadial(const DRW_DimRadial *data) = 0; virtual void addDimRadial(const DRW_DimRadial *) { }
/** /**
* Called for every diametric dimension entity. * Called for every diametric dimension entity.
*/ */
virtual void addDimDiametric(const DRW_DimDiametric *data) = 0; virtual void addDimDiametric(const DRW_DimDiametric *) { }
/** /**
* Called for every angular dimension (2 lines version) entity. * Called for every angular dimension (2 lines version) entity.
*/ */
virtual void addDimAngular(const DRW_DimAngular *data) = 0; virtual void addDimAngular(const DRW_DimAngular *) { }
/** /**
* Called for every angular dimension (3 points version) entity. * Called for every angular dimension (3 points version) entity.
*/ */
virtual void addDimAngular3P(const DRW_DimAngular3p *data) = 0; virtual void addDimAngular3P(const DRW_DimAngular3p *) { }
/** /**
* Called for every ordinate dimension entity. * Called for every ordinate dimension entity.
*/ */
virtual void addDimOrdinate(const DRW_DimOrdinate *data) = 0; virtual void addDimOrdinate(const DRW_DimOrdinate *) { }
/** /**
* Called for every leader start. * Called for every leader start.
*/ */
virtual void addLeader(const DRW_Leader *data) = 0; virtual void addLeader(const DRW_Leader *) { }
/** /**
* Called for every hatch entity. * Called for every hatch entity.
*/ */
virtual void addHatch(const DRW_Hatch *data) = 0; virtual void addHatch(const DRW_Hatch *) { }
/** /**
* Called for every viewport entity. * Called for every viewport entity.
*/ */
virtual void addViewport(const DRW_Viewport& data) = 0; virtual void addViewport(const DRW_Viewport &) { }
/** /**
* Called for every image entity. * Called for every image entity.
*/ */
virtual void addImage(const DRW_Image *data) = 0; virtual void addImage(const DRW_Image *) { }
/** /**
* Called for every image definition. * Called for every image definition.
*/ */
virtual void linkImage(const DRW_ImageDef *data) = 0; virtual void linkImage(const DRW_ImageDef *) { }
/** /**
* Called for every comment in the DXF file (code 999). * Called for every comment in the DXF file (code 999).
*/ */
virtual void addComment(const char* comment) = 0; virtual void addComment(const char *) { }
virtual void writeHeader(DRW_Header& data) = 0; virtual void writeHeader(DRW_Header &) { }
virtual void writeBlocks() = 0; virtual void writeBlocks() { }
virtual void writeBlockRecords() = 0; virtual void writeBlockRecords() { }
virtual void writeEntities() = 0; virtual void writeEntities() { }
virtual void writeLTypes() = 0; virtual void writeLTypes() { }
virtual void writeLayers() = 0; virtual void writeLayers() { }
virtual void writeTextstyles() = 0; virtual void writeTextstyles() { }
virtual void writeVports() = 0; virtual void writeVports() { }
virtual void writeDimstyles() = 0; virtual void writeDimstyles() { }
virtual void writeAppId() = 0; virtual void writeAppId() { }
}; };
#endif #endif

View File

@ -50,7 +50,10 @@ void DRW_TableEntry::parseCode(int code, dxfReader *reader){
case 1011: case 1011:
case 1012: case 1012:
case 1013: case 1013:
curr = new DRW_Variant(code, DRW_Coord(reader->getDouble(), 0.0, 0.0)); curr = new DRW_Variant();
curr->addCoord();
curr->setCoordX(reader->getDouble());
curr->code = code;
extData.push_back(curr); extData.push_back(curr);
break; break;
case 1020: case 1020:
@ -455,7 +458,7 @@ void DRW_LType::parseCode(int code, dxfReader *reader){
/*TODO: control max length permited */ /*TODO: control max length permited */
void DRW_LType::update(){ void DRW_LType::update(){
double d =0; double d =0;
size = path.size(); size = (int)path.size();
for (int i = 0; i< size; i++){ for (int i = 0; i< size; i++){
d += fabs(path.at(i)); d += fabs(path.at(i));
} }
@ -1168,7 +1171,7 @@ bool DRW_ImageDef::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
dint32 imgVersion = buf->getBitLong(); dint32 imgVersion = buf->getBitLong();
DRW_DBG("class Version: "); DRW_DBG(imgVersion); DRW_DBG("class Version: "); DRW_DBG(imgVersion);
DRW_Coord size = buf->get2RawDouble(); DRW_Coord size = buf->get2RawDouble();
DRW_UNUSED(size);//RLZ: temporary, complete API (void)size;
name = sBuf->getVariableText(version, false); name = sBuf->getVariableText(version, false);
DRW_DBG("appId name: "); DRW_DBG(name.c_str()); DRW_DBG("\n"); DRW_DBG("appId name: "); DRW_DBG(name.c_str()); DRW_DBG("\n");
loaded = buf->getBit(); loaded = buf->getBit();

View File

@ -128,25 +128,30 @@ public:
void reset(){ void reset(){
tType = DRW::DIMSTYLE; tType = DRW::DIMSTYLE;
dimasz = dimtxt = dimexe = 0.18; dimasz = dimtxt = dimcen = 2.5;
dimexo = 0.0625; dimexe = 1.25;
dimgap = dimcen = 0.09; dimexo = dimgap = 0.625;
dimtxsty = "Standard"; dimtxsty = "";
dimscale = dimlfac = dimtfac = dimfxl = 1.0; dimscale = dimlfac = dimtfac = dimfxl = 1.0;
dimdli = 0.38; dimdli = 3.75;
dimrnd = dimdle = dimtp = dimtm = dimtsz = dimtvp = 0.0; dimrnd = dimdle = dimtp = dimtm = dimtsz = dimtvp = 0.0;
dimaltf = 25.4; dimaltf = 1.0 / 25.4;
dimtol = dimlim = dimse1 = dimse2 = dimtad = dimzin = 0; dimtol = dimlim = dimse1 = dimse2 = 0;
dimtoh = dimtolj = 1; dimtad = 1;
dimalt = dimtofl = dimsah = dimtix = dimsoxd = dimfxlon = 0; dimzin = 8;
dimaltd = dimunit = dimaltu = dimalttd = dimlunit = 2; dimtoh = dimtolj = 0;
dimalt = dimsah = dimtix = dimsoxd = dimfxlon = 0;
dimtofl = 1;
dimunit = dimaltu = dimlunit = 2;
dimaltd = dimalttd = 3;
dimclrd = dimclre = dimclrt = dimjust = dimupt = 0; dimclrd = dimclre = dimclrt = dimjust = dimupt = 0;
dimazin = dimaltz = dimaltttz = dimtzin = dimfrac = 0; dimtzin = 8;
dimazin = dimaltz = dimaltttz = dimfrac = 0;
dimtih = dimadec = dimaunit = dimsd1 = dimsd2 = dimtmove = 0; dimtih = dimadec = dimaunit = dimsd1 = dimsd2 = dimtmove = 0;
dimaltrnd = 0.0; dimaltrnd = 0.0;
dimdec = dimtdec = 4; dimdec = dimtdec = 2;
dimfit = dimatfit = 3; dimfit = dimatfit = 3;
dimdsep = '.'; dimdsep = ',';
dimlwd = dimlwe = -2; dimlwd = dimlwe = -2;
DRW_TableEntry::reset(); DRW_TableEntry::reset();
} }
@ -771,4 +776,3 @@ const unsigned char dxfColors[][3] = {
#endif #endif
// EOF // EOF

View File

@ -2,8 +2,6 @@
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <algorithm> #include <algorithm>
#include <cstring>
#include <iconv.h>
#include "../drw_base.h" #include "../drw_base.h"
#include "drw_cptables.h" #include "drw_cptables.h"
#include "drw_cptable932.h" #include "drw_cptable932.h"
@ -54,9 +52,6 @@ void DRW_TextCodec::setVersion(std::string *v, bool dxfFormat){
} }
void DRW_TextCodec::setCodePage(std::string *c, bool dxfFormat){ void DRW_TextCodec::setCodePage(std::string *c, bool dxfFormat){
static int min_ver = 10;
min_ver = std::min(min_ver, version);
cp = correctCodePage(*c); cp = correctCodePage(*c);
delete conv; delete conv;
if (version == DRW::AC1009 || version == DRW::AC1015) { if (version == DRW::AC1009 || version == DRW::AC1015) {
@ -92,20 +87,15 @@ void DRW_TextCodec::setCodePage(std::string *c, bool dxfFormat){
conv = new DRW_ConvTable(DRW_Table1258, CPLENGHTCOMMON); conv = new DRW_ConvTable(DRW_Table1258, CPLENGHTCOMMON);
else if (cp == "UTF-8") { //DXF older than 2007 are write in win codepages else if (cp == "UTF-8") { //DXF older than 2007 are write in win codepages
cp = "ANSI_1252"; cp = "ANSI_1252";
conv = new DRW_ExtConverter("SJIS"); conv = new DRW_Converter(NULL, 0);
} else { } else
conv = new DRW_ExtConverter("SJIS"); conv = new DRW_ConvTable(DRW_Table1252, CPLENGHTCOMMON);
}
} else {
if (min_ver <= DRW::AC1018) {
conv = new DRW_ExtConverter("SJIS");
} else { } else {
if (dxfFormat) if (dxfFormat)
conv = new DRW_Converter(NULL, 0);//utf16 to utf8 conv = new DRW_Converter(NULL, 0);//utf16 to utf8
else else
conv = new DRW_ConvUTF16();//utf16 to utf8 conv = new DRW_ConvUTF16();//utf16 to utf8
} }
}
} }
std::string DRW_TextCodec::toUtf8(std::string s) { std::string DRW_TextCodec::toUtf8(std::string s) {
@ -470,32 +460,6 @@ std::string DRW_ConvUTF16::toUtf8(std::string *s){//RLZ: pending to write
return res; return res;
} }
std::string DRW_ExtConverter::convertByiconv(const char *in_encode,
const char *out_encode,
const std::string *s) {
const int BUF_SIZE = 1000;
static char in_buf[BUF_SIZE], out_buf[BUF_SIZE];
char *in_ptr = in_buf, *out_ptr = out_buf;
strncpy(in_buf, s->c_str(), BUF_SIZE);
iconv_t ic;
ic = iconv_open(out_encode, in_encode);
size_t il = BUF_SIZE-1, ol = BUF_SIZE-1;
iconv(ic , &in_ptr, &il, &out_ptr, &ol);
iconv_close(ic);
return std::string(out_buf);
}
std::string DRW_ExtConverter::fromUtf8(std::string *s){
return convertByiconv("UTF8", this->encoding, s);
}
std::string DRW_ExtConverter::toUtf8(std::string *s){
return convertByiconv(this->encoding, "UTF8", s);
}
std::string DRW_TextCodec::correctCodePage(const std::string& s) { std::string DRW_TextCodec::correctCodePage(const std::string& s) {
//stringstream cause crash in OS/X, bug#3597944 //stringstream cause crash in OS/X, bug#3597944
std::string cp=s; std::string cp=s;

View File

@ -88,18 +88,4 @@ private:
}; };
class DRW_ExtConverter : public DRW_Converter {
public:
DRW_ExtConverter(const char *enc):DRW_Converter(NULL, 0) {
encoding = enc;
}
virtual std::string fromUtf8(std::string *s);
virtual std::string toUtf8(std::string *s);
private:
const char *encoding;
std::string convertByiconv(const char *in_encode,
const char *out_encode,
const std::string *s);
};
#endif // DRW_TEXTCODEC_H #endif // DRW_TEXTCODEC_H

View File

@ -151,7 +151,7 @@ dwgBuffer::dwgBuffer(duint8 *buf, int size, DRW_TextCodec *dc){
bitPos = 0; bitPos = 0;
} }
dwgBuffer::dwgBuffer(std::ifstream *stream, DRW_TextCodec *dc){ dwgBuffer::dwgBuffer(std::istream *stream, DRW_TextCodec *dc){
filestr = new dwgFileStream(stream); filestr = new dwgFileStream(stream);
decoder = dc; decoder = dc;
maxSize = filestr->size(); maxSize = filestr->size();
@ -921,4 +921,3 @@ duint32 dwgBuffer::crc32(duint32 seed,dint32 start,dint32 end){
return st; return st;
// return std::string(buffer); // return std::string(buffer);
}*/ }*/

View File

@ -35,7 +35,7 @@ public:
class dwgFileStream: public dwgBasicStream{ class dwgFileStream: public dwgBasicStream{
public: public:
dwgFileStream(std::ifstream *s){ dwgFileStream(std::istream *s){
stream =s; stream =s;
stream->seekg (0, std::ios::end); stream->seekg (0, std::ios::end);
sz = stream->tellg(); sz = stream->tellg();
@ -49,7 +49,7 @@ public:
virtual bool good(){return stream->good();} virtual bool good(){return stream->good();}
virtual dwgBasicStream* clone(){return new dwgFileStream(stream);} virtual dwgBasicStream* clone(){return new dwgFileStream(stream);}
private: private:
std::ifstream *stream; std::istream *stream;
duint64 sz; duint64 sz;
}; };
@ -77,7 +77,7 @@ private:
class dwgBuffer { class dwgBuffer {
public: public:
dwgBuffer(std::ifstream *stream, DRW_TextCodec *decoder = NULL); dwgBuffer(std::istream *stream, DRW_TextCodec *decoder = NULL);
dwgBuffer(duint8 *buf, int size, DRW_TextCodec *decoder= NULL); dwgBuffer(duint8 *buf, int size, DRW_TextCodec *decoder= NULL);
dwgBuffer( const dwgBuffer& org ); dwgBuffer( const dwgBuffer& org );
dwgBuffer& operator=( const dwgBuffer& org ); dwgBuffer& operator=( const dwgBuffer& org );

View File

@ -1292,4 +1292,3 @@ int unkData=0;
} }
return buf->isGood(); return buf->isGood();
} }

View File

@ -120,7 +120,7 @@ public:
class dwgReader { class dwgReader {
friend class dwgR; friend class dwgR;
public: public:
dwgReader(std::ifstream *stream, dwgR *p){ dwgReader(std::istream *stream, dwgR *p){
fileBuf = new dwgBuffer(stream); fileBuf = new dwgBuffer(stream);
parent = p; parent = p;
decoder.setVersion(DRW::AC1021, false);//default 2007 in utf8(no convert) decoder.setVersion(DRW::AC1021, false);//default 2007 in utf8(no convert)

View File

@ -196,4 +196,3 @@ bool dwgReader15::readDwgBlocks(DRW_Interface& intfa) {
ret = dwgReader::readDwgBlocks(intfa, fileBuf); ret = dwgReader::readDwgBlocks(intfa, fileBuf);
return ret; return ret;
} }

View File

@ -21,7 +21,7 @@
class dwgReader15 : public dwgReader { class dwgReader15 : public dwgReader {
public: public:
dwgReader15(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ } dwgReader15(std::istream *stream, dwgR *p):dwgReader(stream, p){ }
virtual ~dwgReader15() {} virtual ~dwgReader15() {}
bool readMetaData(); bool readMetaData();
bool readFileHeader(); bool readFileHeader();

View File

@ -592,5 +592,3 @@ bool dwgReader18::readDwgTables(DRW_Header& hdr) {
//Do not delete objData in this point, needed in the remaining code //Do not delete objData in this point, needed in the remaining code
return ret; return ret;
} }

View File

@ -43,7 +43,7 @@ static const int DRW_magicNumEnd18[] = {
class dwgReader18 : public dwgReader { class dwgReader18 : public dwgReader {
public: public:
dwgReader18(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ dwgReader18(std::istream *stream, dwgR *p):dwgReader(stream, p){
objData = NULL; objData = NULL;
} }
virtual ~dwgReader18(){ virtual ~dwgReader18(){

View File

@ -485,5 +485,3 @@ bool dwgReader21::readDwgBlocks(DRW_Interface& intfa){
return false; return false;
} }

View File

@ -22,7 +22,7 @@
//reader for AC1021 aka v2007, chapter 5 //reader for AC1021 aka v2007, chapter 5
class dwgReader21 : public dwgReader { class dwgReader21 : public dwgReader {
public: public:
dwgReader21(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ dwgReader21(std::istream *stream, dwgR *p):dwgReader(stream, p){
objData = NULL; objData = NULL;
dataSize = 0; dataSize = 0;
} }

View File

@ -21,7 +21,7 @@
class dwgReader24 : public dwgReader18 { class dwgReader24 : public dwgReader18 {
public: public:
dwgReader24(std::ifstream *stream, dwgR *p):dwgReader18(stream, p){ } dwgReader24(std::istream *stream, dwgR *p):dwgReader18(stream, p){ }
virtual ~dwgReader24(){} virtual ~dwgReader24(){}
bool readFileHeader(); bool readFileHeader();
bool readDwgHeader(DRW_Header& hdr); bool readDwgHeader(DRW_Header& hdr);

View File

@ -41,4 +41,3 @@ bool dwgReader27::readDwgClasses(){
DRW_DBG("\ndwgReader27::readDwgClasses END\n"); DRW_DBG("\ndwgReader27::readDwgClasses END\n");
return ret; return ret;
} }

View File

@ -21,7 +21,7 @@
class dwgReader27 : public dwgReader18 { class dwgReader27 : public dwgReader18 {
public: public:
dwgReader27(std::ifstream *stream, dwgR *p):dwgReader18(stream, p){ } dwgReader27(std::istream *stream, dwgR *p):dwgReader18(stream, p){ }
virtual ~dwgReader27(){} virtual ~dwgReader27(){}
bool readFileHeader(); bool readFileHeader();
bool readDwgHeader(DRW_Header& hdr); bool readDwgHeader(DRW_Header& hdr);

View File

@ -261,4 +261,3 @@ bool dxfReaderAscii::readBool() {
} else } else
return false; return false;
} }

View File

@ -27,7 +27,7 @@ public:
}; };
enum TYPE type; enum TYPE type;
public: public:
dxfReader(std::ifstream *stream){ dxfReader(std::istream *stream){
filestr = stream; filestr = stream;
type = INVALID; type = INVALID;
} }
@ -58,7 +58,7 @@ protected:
virtual bool readBool() = 0; virtual bool readBool() = 0;
protected: protected:
std::ifstream *filestr; std::istream *filestr;
std::string strData; std::string strData;
double doubleData; double doubleData;
signed int intData; //32 bits integer signed int intData; //32 bits integer
@ -70,7 +70,7 @@ private:
class dxfReaderBinary : public dxfReader { class dxfReaderBinary : public dxfReader {
public: public:
dxfReaderBinary(std::ifstream *stream):dxfReader(stream){skip = false; } dxfReaderBinary(std::istream *stream):dxfReader(stream){skip = false; }
virtual ~dxfReaderBinary() {} virtual ~dxfReaderBinary() {}
virtual bool readCode(int *code); virtual bool readCode(int *code);
virtual bool readString(std::string *text); virtual bool readString(std::string *text);
@ -84,7 +84,7 @@ public:
class dxfReaderAscii : public dxfReader { class dxfReaderAscii : public dxfReader {
public: public:
dxfReaderAscii(std::ifstream *stream):dxfReader(stream){skip = true; } dxfReaderAscii(std::istream *stream):dxfReader(stream){skip = true; }
virtual ~dxfReaderAscii(){} virtual ~dxfReaderAscii(){}
virtual bool readCode(int *code); virtual bool readCode(int *code);
virtual bool readString(std::string *text); virtual bool readString(std::string *text);

View File

@ -35,9 +35,8 @@
secObjects secObjects
};*/ };*/
dwgR::dwgR(const char* name){ dwgR::dwgR(){
DRW_DBGSL(DRW_dbg::NONE); DRW_DBGSL(DRW_dbg::NONE);
fileName = name;
reader = NULL; reader = NULL;
// writer = NULL; // writer = NULL;
applyExt = false; applyExt = false;
@ -62,11 +61,10 @@ void dwgR::setDebug(DRW::DBG_LEVEL lvl){
} }
/*reads metadata and loads image preview*/ /*reads metadata and loads image preview*/
bool dwgR::getPreview(){ bool dwgR::getPreview(std::istream &stream){
bool isOk = false; bool isOk = false;
std::ifstream filestr; isOk = open(&stream);
isOk = openFile(&filestr);
if (!isOk) if (!isOk)
return false; return false;
@ -76,7 +74,6 @@ bool dwgR::getPreview(){
} else } else
error = DRW::BAD_READ_METADATA; error = DRW::BAD_READ_METADATA;
filestr.close();
if (reader != NULL) { if (reader != NULL) {
delete reader; delete reader;
reader = NULL; reader = NULL;
@ -84,70 +81,13 @@ bool dwgR::getPreview(){
return isOk; return isOk;
} }
bool dwgR::testReader(){ bool dwgR::read(std::istream &stream, DRW_Interface *interface_, bool ext){
bool isOk = false;
std::ifstream filestr;
filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary);
if (!filestr.is_open() || !filestr.good() ){
error = DRW::BAD_OPEN;
return isOk;
}
dwgBuffer fileBuf(&filestr);
duint8 *tmpStrData = new duint8[fileBuf.size()];
fileBuf.getBytes(tmpStrData, fileBuf.size());
dwgBuffer dataBuf(tmpStrData, fileBuf.size());
fileBuf.setPosition(0);
DRW_DBG("\ndwgR::testReader filebuf size: ");DRW_DBG(fileBuf.size());
DRW_DBG("\ndwgR::testReader dataBuf size: ");DRW_DBG(dataBuf.size());
DRW_DBG("\n filebuf pos: ");DRW_DBG(fileBuf.getPosition());
DRW_DBG("\n dataBuf pos: ");DRW_DBG(dataBuf.getPosition());
DRW_DBG("\n filebuf bitpos: ");DRW_DBG(fileBuf.getBitPos());
DRW_DBG("\n dataBuf bitpos: ");DRW_DBG(dataBuf.getBitPos());
DRW_DBG("\n filebuf first byte : ");DRW_DBGH(fileBuf.getRawChar8());
DRW_DBG("\n dataBuf first byte : ");DRW_DBGH(dataBuf.getRawChar8());
fileBuf.setBitPos(4);
dataBuf.setBitPos(4);
DRW_DBG("\n filebuf first byte : ");DRW_DBGH(fileBuf.getRawChar8());
DRW_DBG("\n dataBuf first byte : ");DRW_DBGH(dataBuf.getRawChar8());
DRW_DBG("\n filebuf pos: ");DRW_DBG(fileBuf.getPosition());
DRW_DBG("\n dataBuf pos: ");DRW_DBG(dataBuf.getPosition());
DRW_DBG("\n filebuf bitpos: ");DRW_DBG(fileBuf.getBitPos());
DRW_DBG("\n dataBuf bitpos: ");DRW_DBG(dataBuf.getBitPos());
fileBuf.setBitPos(6);
dataBuf.setBitPos(6);
DRW_DBG("\n filebuf pos: ");DRW_DBG(fileBuf.getPosition());
DRW_DBG("\n dataBuf pos: ");DRW_DBG(dataBuf.getPosition());
DRW_DBG("\n filebuf bitpos: ");DRW_DBG(fileBuf.getBitPos());
DRW_DBG("\n dataBuf bitpos: ");DRW_DBG(dataBuf.getBitPos());
DRW_DBG("\n filebuf first byte : ");DRW_DBGH(fileBuf.getRawChar8());
DRW_DBG("\n dataBuf first byte : ");DRW_DBGH(dataBuf.getRawChar8());
fileBuf.setBitPos(0);
dataBuf.setBitPos(0);
DRW_DBG("\n filebuf first byte : ");DRW_DBGH(fileBuf.getRawChar8());
DRW_DBG("\n dataBuf first byte : ");DRW_DBGH(dataBuf.getRawChar8());
DRW_DBG("\n filebuf pos: ");DRW_DBG(fileBuf.getPosition());
DRW_DBG("\n dataBuf pos: ");DRW_DBG(dataBuf.getPosition());
DRW_DBG("\n filebuf bitpos: ");DRW_DBG(fileBuf.getBitPos());
DRW_DBG("\n dataBuf bitpos: ");DRW_DBG(dataBuf.getBitPos());
delete[]tmpStrData;
filestr.close();
DRW_DBG("\n\n");
return isOk;
}
/*start reading dwg file header and, if can read it, continue reading all*/
bool dwgR::read(DRW_Interface *interface_, bool ext){
bool isOk = false;
applyExt = ext; applyExt = ext;
iface = interface_; iface = interface_;
//testReader();return false; bool isOk = false;
std::ifstream filestr; isOk = open(&stream);
isOk = openFile(&filestr);
if (!isOk) if (!isOk)
return false; return false;
@ -161,7 +101,6 @@ bool dwgR::read(DRW_Interface *interface_, bool ext){
} else } else
error = DRW::BAD_READ_METADATA; error = DRW::BAD_READ_METADATA;
filestr.close();
if (reader != NULL) { if (reader != NULL) {
delete reader; delete reader;
reader = NULL; reader = NULL;
@ -170,23 +109,9 @@ bool dwgR::read(DRW_Interface *interface_, bool ext){
return isOk; return isOk;
} }
/* Open the file and stores it in filestr, install the correct reader version. bool dwgR::open(std::istream *stream){
* If fail opening file, error are set as DRW::BAD_OPEN
* If not are DWG or are unsupported version, error are set as DRW::BAD_VERSION
* and closes filestr.
* Return true on succeed or false on fail
*/
bool dwgR::openFile(std::ifstream *filestr){
bool isOk = false;
DRW_DBG("dwgR::read 1\n");
filestr->open (fileName.c_str(), std::ios_base::in | std::ios::binary);
if (!filestr->is_open() || !filestr->good() ){
error = DRW::BAD_OPEN;
return isOk;
}
char line[7]; char line[7];
filestr->read (line, 6); stream->read (line, 6);
line[6]='\0'; line[6]='\0';
DRW_DBG("dwgR::read 2\n"); DRW_DBG("dwgR::read 2\n");
DRW_DBG("dwgR::read line version: "); DRW_DBG("dwgR::read line version: ");
@ -200,35 +125,33 @@ bool dwgR::openFile(std::ifstream *filestr){
// reader = new dwgReader09(&filestr, this); // reader = new dwgReader09(&filestr, this);
}else if (strcmp(line, "AC1012") == 0){ }else if (strcmp(line, "AC1012") == 0){
version = DRW::AC1012; version = DRW::AC1012;
reader = new dwgReader15(filestr, this); reader = new dwgReader15(stream, this);
} else if (strcmp(line, "AC1014") == 0) { } else if (strcmp(line, "AC1014") == 0) {
version = DRW::AC1014; version = DRW::AC1014;
reader = new dwgReader15(filestr, this); reader = new dwgReader15(stream, this);
} else if (strcmp(line, "AC1015") == 0) { } else if (strcmp(line, "AC1015") == 0) {
version = DRW::AC1015; version = DRW::AC1015;
reader = new dwgReader15(filestr, this); reader = new dwgReader15(stream, this);
} else if (strcmp(line, "AC1018") == 0){ } else if (strcmp(line, "AC1018") == 0){
version = DRW::AC1018; version = DRW::AC1018;
reader = new dwgReader18(filestr, this); reader = new dwgReader18(stream, this);
} else if (strcmp(line, "AC1021") == 0) { } else if (strcmp(line, "AC1021") == 0) {
version = DRW::AC1021; version = DRW::AC1021;
reader = new dwgReader21(filestr, this); reader = new dwgReader21(stream, this);
} else if (strcmp(line, "AC1024") == 0) { } else if (strcmp(line, "AC1024") == 0) {
version = DRW::AC1024; version = DRW::AC1024;
reader = new dwgReader24(filestr, this); reader = new dwgReader24(stream, this);
} else if (strcmp(line, "AC1027") == 0) { } else if (strcmp(line, "AC1027") == 0) {
version = DRW::AC1027; version = DRW::AC1027;
reader = new dwgReader27(filestr, this); reader = new dwgReader27(stream, this);
} else } else
version = DRW::UNKNOWNV; version = DRW::UNKNOWNV;
if (reader == NULL) { if (reader == NULL) {
error = DRW::BAD_VERSION; error = DRW::BAD_VERSION;
filestr->close(); return false;
} else }
isOk = true; return true;
return isOk;
} }
/********* Reader Process *********/ /********* Reader Process *********/

View File

@ -24,18 +24,17 @@ class dwgReader;
class dwgR { class dwgR {
public: public:
dwgR(const char* name); dwgR();
~dwgR(); ~dwgR();
//read: return true if all ok //read: return true if all ok
bool read(DRW_Interface *interface_, bool ext); bool read(std::istream &stream, DRW_Interface *interface_, bool ext);
bool getPreview(); bool getPreview(std::istream &stream);
DRW::Version getVersion(){return version;} DRW::Version getVersion(){return version;}
DRW::error getError(){return error;} DRW::error getError(){return error;}
bool testReader();
void setDebug(DRW::DBG_LEVEL lvl); void setDebug(DRW::DBG_LEVEL lvl);
private: private:
bool openFile(std::ifstream *filestr); bool open(std::istream *stream);
bool processDwg(); bool processDwg();
private: private:
DRW::Version version; DRW::Version version;

View File

@ -423,8 +423,6 @@ bool dxfRW::writeDimstyle(DRW_Dimstyle *ent){
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 || ent->dimfxl !=0 )
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);
@ -489,9 +487,7 @@ bool dxfRW::writeDimstyle(DRW_Dimstyle *ent){
if (version > DRW::AC1014) { if (version > DRW::AC1014) {
writer->writeInt16(289, ent->dimatfit); writer->writeInt16(289, ent->dimatfit);
} }
if ( version > DRW::AC1018 && ent->dimfxlon !=0 ) if (version > DRW::AC1009 && !ent->dimtxsty.empty()) {
writer->writeInt16(290, ent->dimfxlon);
if (version > DRW::AC1009) {
writer->writeUtf8String(340, ent->dimtxsty); writer->writeUtf8String(340, ent->dimtxsty);
} }
if (version > DRW::AC1014) { if (version > DRW::AC1014) {
@ -735,7 +731,7 @@ bool dxfRW::writeLWPolyline(DRW_LWPolyline *ent){
if (version > DRW::AC1009) { if (version > DRW::AC1009) {
writer->writeString(100, "AcDbPolyline"); writer->writeString(100, "AcDbPolyline");
} }
ent->vertexnum = ent->vertlist.size(); ent->vertexnum = (int)ent->vertlist.size();
writer->writeInt32(90, ent->vertexnum); writer->writeInt32(90, ent->vertexnum);
writer->writeInt16(70, ent->flags); writer->writeInt16(70, ent->flags);
writer->writeDouble(43, ent->width); writer->writeDouble(43, ent->width);
@ -763,11 +759,14 @@ bool dxfRW::writeLWPolyline(DRW_LWPolyline *ent){
bool dxfRW::writePolyline(DRW_Polyline *ent) { bool dxfRW::writePolyline(DRW_Polyline *ent) {
writer->writeString(0, "POLYLINE"); writer->writeString(0, "POLYLINE");
writeEntity(ent); writeEntity(ent);
bool is3d = false;
if (version > DRW::AC1009) { if (version > DRW::AC1009) {
if (ent->flags & 8 || ent->flags & 16) if (ent->flags & 8 || ent->flags & 16) {
writer->writeString(100, "AcDb2dPolyline");
else
writer->writeString(100, "AcDb3dPolyline"); writer->writeString(100, "AcDb3dPolyline");
is3d = true;
} else {
writer->writeString(100, "AcDb2dPolyline");
}
} else } else
writer->writeInt16(66, 1); writer->writeInt16(66, 1);
writer->writeDouble(10, 0.0); writer->writeDouble(10, 0.0);
@ -803,13 +802,18 @@ bool dxfRW::writePolyline(DRW_Polyline *ent) {
writer->writeDouble(230, crd.z); writer->writeDouble(230, crd.z);
} }
int vertexnum = ent->vertlist.size(); size_t vertexnum = ent->vertlist.size();
for (int i = 0; i< vertexnum; i++){ for (size_t i = 0; i < vertexnum; i++) {
DRW_Vertex *v = ent->vertlist.at(i); DRW_Vertex *v = ent->vertlist.at(i);
writer->writeString(0, "VERTEX"); writer->writeString(0, "VERTEX");
writeEntity(ent); writeEntity(ent);
if (version > DRW::AC1009) if (version > DRW::AC1009)
writer->writeString(100, "AcDbVertex"); writer->writeString(100, "AcDbVertex");
if(is3d) {
writer->writeString(100, "AcDb3dPolylineVertex");
} else {
writer->writeString(100, "AcDb2dVertex");
}
if ( (v->flags & 128) && !(v->flags & 64) ) { if ( (v->flags & 128) && !(v->flags & 64) ) {
writer->writeDouble(10, 0); writer->writeDouble(10, 0);
writer->writeDouble(20, 0); writer->writeDouble(20, 0);
@ -875,6 +879,9 @@ bool dxfRW::writeSpline(DRW_Spline *ent){
for (int i = 0; i< ent->nknots; i++){ for (int i = 0; i< ent->nknots; i++){
writer->writeDouble(40, ent->knotslist.at(i)); writer->writeDouble(40, ent->knotslist.at(i));
} }
for (int i = 0; i< (int)ent->weightlist.size(); i++) {
writer->writeDouble(41, ent->weightlist.at(i));
}
for (int i = 0; i< ent->ncontrol; i++){ for (int i = 0; i< ent->ncontrol; i++){
DRW_Coord *crd = ent->controllist.at(i); DRW_Coord *crd = ent->controllist.at(i);
writer->writeDouble(10, crd->x); writer->writeDouble(10, crd->x);
@ -901,7 +908,7 @@ bool dxfRW::writeHatch(DRW_Hatch *ent){
writer->writeString(2, ent->name); writer->writeString(2, ent->name);
writer->writeInt16(70, ent->solid); writer->writeInt16(70, ent->solid);
writer->writeInt16(71, ent->associative); writer->writeInt16(71, ent->associative);
ent->loopsnum = ent->looplist.size(); ent->loopsnum = (int)ent->looplist.size();
writer->writeInt16(91, ent->loopsnum); writer->writeInt16(91, ent->loopsnum);
//write paths data //write paths data
for (int i = 0; i< ent->loopsnum; i++){ for (int i = 0; i< ent->loopsnum; i++){
@ -1031,6 +1038,8 @@ bool dxfRW::writeDimension(DRW_Dimension *ent) {
writer->writeDouble(210, ent->getExtrusion().x); writer->writeDouble(210, ent->getExtrusion().x);
writer->writeDouble(220, ent->getExtrusion().y); writer->writeDouble(220, ent->getExtrusion().y);
writer->writeDouble(230, ent->getExtrusion().z); writer->writeDouble(230, ent->getExtrusion().z);
if ( ent->hasActualMeasurement())
writer->writeDouble(42, ent->getActualMeasurement());
switch (ent->eType) { switch (ent->eType) {
case DRW::DIMALIGNED: case DRW::DIMALIGNED:
@ -1765,15 +1774,15 @@ bool dxfRW::writeObjects() {
bool dxfRW::writeExtData(const std::vector<DRW_Variant*> &ed){ bool dxfRW::writeExtData(const std::vector<DRW_Variant*> &ed){
for (std::vector<DRW_Variant*>::const_iterator it=ed.begin(); it!=ed.end(); ++it){ for (std::vector<DRW_Variant*>::const_iterator it=ed.begin(); it!=ed.end(); ++it){
switch ((*it)->code()) { switch ((*it)->code) {
case 1000: case 1000:
case 1001: case 1001:
case 1002: case 1002:
case 1003: case 1003:
case 1004: case 1004:
case 1005: case 1005:
{int cc = (*it)->code(); {int cc = (*it)->code;
if ((*it)->type() == DRW_Variant::STRING) if ((*it)->type == DRW_Variant::STRING)
writer->writeUtf8String(cc, *(*it)->content.s); writer->writeUtf8String(cc, *(*it)->content.s);
// writer->writeUtf8String((*it)->code, (*it)->content.s); // writer->writeUtf8String((*it)->code, (*it)->content.s);
break;} break;}
@ -1781,25 +1790,25 @@ bool dxfRW::writeExtData(const std::vector<DRW_Variant*> &ed){
case 1011: case 1011:
case 1012: case 1012:
case 1013: case 1013:
if ((*it)->type() == DRW_Variant::COORD) { if ((*it)->type == DRW_Variant::COORD) {
writer->writeDouble((*it)->code(), (*it)->content.v->x); writer->writeDouble((*it)->code, (*it)->content.v->x);
writer->writeDouble((*it)->code()+10 , (*it)->content.v->y); writer->writeDouble((*it)->code+10 , (*it)->content.v->y);
writer->writeDouble((*it)->code()+20 , (*it)->content.v->z); writer->writeDouble((*it)->code+20 , (*it)->content.v->z);
} }
break; break;
case 1040: case 1040:
case 1041: case 1041:
case 1042: case 1042:
if ((*it)->type() == DRW_Variant::DOUBLE) if ((*it)->type == DRW_Variant::DOUBLE)
writer->writeDouble((*it)->code(), (*it)->content.d); writer->writeDouble((*it)->code, (*it)->content.d);
break; break;
case 1070: case 1070:
if ((*it)->type() == DRW_Variant::INTEGER) if ((*it)->type == DRW_Variant::INTEGER)
writer->writeInt16((*it)->code(), (*it)->content.i); writer->writeInt16((*it)->code, (*it)->content.i);
break; break;
case 1071: case 1071:
if ((*it)->type() == DRW_Variant::INTEGER) if ((*it)->type == DRW_Variant::INTEGER)
writer->writeInt32((*it)->code(), (*it)->content.i); writer->writeInt32((*it)->code, (*it)->content.i);
break; break;
default: default:
break; break;