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

View File

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

View File

@ -116,7 +116,10 @@ bool DRW_Entity::parseCode(int code, dxfReader *reader){
case 1011:
case 1012:
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);
break;
case 1020:
@ -156,28 +159,28 @@ bool DRW_Entity::parseDxfGroups(int code, dxfReader *reader){
int nc;
std::string appName= reader->getString();
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);
while (code !=102 && appName.at(0)== '}'){
reader->readRec(&nc);//RLZ curr.code = code or nc?
// curr.code = code;
//RLZ code == 330 || code == 360 OR nc == 330 || nc == 360 ?
reader->readRec(&nc);
curr.code = code;
if (code == 330 || code == 360)
curr.addInt(code, reader->getHandleString());//RLZ code or nc
curr.addInt(reader->getHandleString());
else {
switch (reader->type) {
case dxfReader::STRING:
curr.addString(code, reader->getString());//RLZ code or nc
curr.addString(reader->getString());
break;
case dxfReader::INT32:
case dxfReader::INT64:
curr.addInt(code, reader->getInt32());//RLZ code or nc
curr.addInt(reader->getInt32());
break;
case dxfReader::DOUBLE:
curr.addDouble(code, reader->getDouble());//RLZ code or nc
curr.addDouble(reader->getDouble());
break;
case dxfReader::BOOL:
curr.addInt(code, reader->getInt32());//RLZ code or nc
curr.addInt(reader->getInt32());
break;
default:
break;
@ -1427,6 +1430,59 @@ void DRW_MText::parseCode(int code, dxfReader *reader){
case 44:
interlin = reader->getDouble();
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:
DRW_Text::parseCode(code, reader);
break;
@ -1906,7 +1962,6 @@ bool DRW_Hatch::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
spline->controllist.reserve(spline->ncontrol);
for (dint32 j = 0; j < spline->ncontrol;++j){
DRW_Coord* crd = new DRW_Coord(buf->get3BitDouble());
spline->controllist.push_back(crd);
if(isRational)
crd->z = buf->getBitDouble(); //RLZ: investigate how store weight
spline->controllist.push_back(crd);
@ -2080,8 +2135,9 @@ void DRW_Spline::parseCode(int code, dxfReader *reader){
case 40:
knotslist.push_back(reader->getDouble());
break;
// case 41:
// break;
case 41:
weightlist.push_back(reader->getDouble());
break;
default:
DRW_Entity::parseCode(code, reader);
break;
@ -2238,14 +2294,14 @@ bool DRW_Image::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
sizev = buf->getRawDouble();
DRW_DBG("\nsize U: "); DRW_DBG(sizeu); DRW_DBG("\nsize V: "); DRW_DBG(sizev);
duint16 displayProps = buf->getBitShort();
DRW_UNUSED(displayProps);//RLZ: temporary, complete API
(void)displayProps;
clip = buf->getBit();
brightness = buf->getRawChar8();
contrast = buf->getRawChar8();
fade = buf->getRawChar8();
if (version > DRW::AC1021){ //2010+
bool clipMode = buf->getBit();
DRW_UNUSED(clipMode);//RLZ: temporary, complete API
(void)clipMode;
}
duint16 clipType = buf->getBitShort();
if (clipType == 1){
@ -2358,6 +2414,10 @@ void DRW_Dimension::parseCode(int code, dxfReader *reader){
case 41:
linefactor = reader->getDouble();
break;
case 42:
actual = reader->getDouble();
hasActual = (actual != 0.0);
break;
case 53:
rot = reader->getDouble();
break;

View File

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

View File

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

View File

@ -28,25 +28,25 @@
*/
class DRW_Interface {
public:
DRW_Interface()
{}
DRW_Interface() {
}
virtual ~DRW_Interface() = default;
/** Called when header is parsed. */
virtual void addHeader(const DRW_Header* data) = 0;
virtual void addHeader(const DRW_Header *) { }
/** Called for every line Type. */
virtual void addLType(const DRW_LType& data) = 0;
virtual void addLType(const DRW_LType &) { }
/** Called for every layer. */
virtual void addLayer(const DRW_Layer& data) = 0;
virtual void addLayer(const DRW_Layer &) { }
/** Called for every dim style. */
virtual void addDimStyle(const DRW_Dimstyle& data) = 0;
virtual void addDimStyle(const DRW_Dimstyle &) { }
/** Called for every VPORT table. */
virtual void addVport(const DRW_Vport& data) = 0;
virtual void addVport(const DRW_Vport &) { }
/** Called for every text style. */
virtual void addTextStyle(const DRW_Textstyle& data) = 0;
virtual void addTextStyle(const DRW_Textstyle &) { }
/** 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
@ -54,146 +54,137 @@ public:
*
* @see endBlock()
*/
virtual void addBlock(const DRW_Block& data) = 0;
/**
* 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;
virtual void addBlock(const DRW_Block &) { }
/** Called to end the current block */
virtual void endBlock() = 0;
virtual void endBlock() { }
/** Called for every point */
virtual void addPoint(const DRW_Point& data) = 0;
virtual void addPoint(const DRW_Point &) { }
/** Called for every line */
virtual void addLine(const DRW_Line& data) = 0;
virtual void addLine(const DRW_Line &) { }
/** Called for every ray */
virtual void addRay(const DRW_Ray& data) = 0;
virtual void addRay(const DRW_Ray &) { }
/** Called for every xline */
virtual void addXline(const DRW_Xline& data) = 0;
virtual void addXline(const DRW_Xline &) { }
/** Called for every arc */
virtual void addArc(const DRW_Arc& data) = 0;
virtual void addArc(const DRW_Arc &) { }
/** Called for every circle */
virtual void addCircle(const DRW_Circle& data) = 0;
virtual void addCircle(const DRW_Circle &) { }
/** Called for every ellipse */
virtual void addEllipse(const DRW_Ellipse& data) = 0;
virtual void addEllipse(const DRW_Ellipse &) { }
/** Called for every lwpolyline */
virtual void addLWPolyline(const DRW_LWPolyline& data) = 0;
virtual void addLWPolyline(const DRW_LWPolyline &) { }
/** Called for every polyline start */
virtual void addPolyline(const DRW_Polyline& data) = 0;
virtual void addPolyline(const DRW_Polyline &) { }
/** Called for every spline */
virtual void addSpline(const DRW_Spline* data) = 0;
virtual void addSpline(const DRW_Spline *) { }
/** Called for every spline knot value */
virtual void addKnot(const DRW_Entity& data) = 0;
virtual void addKnot(const DRW_Entity &) { }
/** Called for every insert. */
virtual void addInsert(const DRW_Insert& data) = 0;
virtual void addInsert(const DRW_Insert &) { }
/** Called for every trace start */
virtual void addTrace(const DRW_Trace& data) = 0;
virtual void addTrace(const DRW_Trace &) { }
/** Called for every 3dface start */
virtual void add3dFace(const DRW_3Dface& data) = 0;
virtual void add3dFace(const DRW_3Dface &) { }
/** 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. */
virtual void addMText(const DRW_MText& data) = 0;
virtual void addMText(const DRW_MText &) { }
/** 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.
*/
virtual void addDimAlign(const DRW_DimAligned *data) = 0;
virtual void addDimAlign(const DRW_DimAligned *) { }
/**
* 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.
*/
virtual void addDimRadial(const DRW_DimRadial *data) = 0;
virtual void addDimRadial(const DRW_DimRadial *) { }
/**
* 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.
*/
virtual void addDimAngular(const DRW_DimAngular *data) = 0;
virtual void addDimAngular(const DRW_DimAngular *) { }
/**
* 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.
*/
virtual void addDimOrdinate(const DRW_DimOrdinate *data) = 0;
virtual void addDimOrdinate(const DRW_DimOrdinate *) { }
/**
* Called for every leader start.
*/
virtual void addLeader(const DRW_Leader *data) = 0;
virtual void addLeader(const DRW_Leader *) { }
/**
* Called for every hatch entity.
*/
virtual void addHatch(const DRW_Hatch *data) = 0;
virtual void addHatch(const DRW_Hatch *) { }
/**
* Called for every viewport entity.
*/
virtual void addViewport(const DRW_Viewport& data) = 0;
virtual void addViewport(const DRW_Viewport &) { }
/**
* Called for every image entity.
*/
virtual void addImage(const DRW_Image *data) = 0;
virtual void addImage(const DRW_Image *) { }
/**
* 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).
*/
virtual void addComment(const char* comment) = 0;
virtual void addComment(const char *) { }
virtual void writeHeader(DRW_Header& data) = 0;
virtual void writeBlocks() = 0;
virtual void writeBlockRecords() = 0;
virtual void writeEntities() = 0;
virtual void writeLTypes() = 0;
virtual void writeLayers() = 0;
virtual void writeTextstyles() = 0;
virtual void writeVports() = 0;
virtual void writeDimstyles() = 0;
virtual void writeAppId() = 0;
virtual void writeHeader(DRW_Header &) { }
virtual void writeBlocks() { }
virtual void writeBlockRecords() { }
virtual void writeEntities() { }
virtual void writeLTypes() { }
virtual void writeLayers() { }
virtual void writeTextstyles() { }
virtual void writeVports() { }
virtual void writeDimstyles() { }
virtual void writeAppId() { }
};
#endif

View File

@ -50,7 +50,10 @@ void DRW_TableEntry::parseCode(int code, dxfReader *reader){
case 1011:
case 1012:
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);
break;
case 1020:
@ -455,7 +458,7 @@ void DRW_LType::parseCode(int code, dxfReader *reader){
/*TODO: control max length permited */
void DRW_LType::update(){
double d =0;
size = path.size();
size = (int)path.size();
for (int i = 0; i< size; 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();
DRW_DBG("class Version: "); DRW_DBG(imgVersion);
DRW_Coord size = buf->get2RawDouble();
DRW_UNUSED(size);//RLZ: temporary, complete API
(void)size;
name = sBuf->getVariableText(version, false);
DRW_DBG("appId name: "); DRW_DBG(name.c_str()); DRW_DBG("\n");
loaded = buf->getBit();

View File

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

View File

@ -2,8 +2,6 @@
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <iconv.h>
#include "../drw_base.h"
#include "drw_cptables.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){
static int min_ver = 10;
min_ver = std::min(min_ver, version);
cp = correctCodePage(*c);
delete conv;
if (version == DRW::AC1009 || version == DRW::AC1015) {
@ -92,13 +87,9 @@ void DRW_TextCodec::setCodePage(std::string *c, bool dxfFormat){
conv = new DRW_ConvTable(DRW_Table1258, CPLENGHTCOMMON);
else if (cp == "UTF-8") { //DXF older than 2007 are write in win codepages
cp = "ANSI_1252";
conv = new DRW_ExtConverter("SJIS");
} else {
conv = new DRW_ExtConverter("SJIS");
}
} else {
if (min_ver <= DRW::AC1018) {
conv = new DRW_ExtConverter("SJIS");
conv = new DRW_Converter(NULL, 0);
} else
conv = new DRW_ConvTable(DRW_Table1252, CPLENGHTCOMMON);
} else {
if (dxfFormat)
conv = new DRW_Converter(NULL, 0);//utf16 to utf8
@ -106,7 +97,6 @@ void DRW_TextCodec::setCodePage(std::string *c, bool dxfFormat){
conv = new DRW_ConvUTF16();//utf16 to utf8
}
}
}
std::string DRW_TextCodec::toUtf8(std::string s) {
return conv->toUtf8(&s);
@ -470,32 +460,6 @@ std::string DRW_ConvUTF16::toUtf8(std::string *s){//RLZ: pending to write
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) {
//stringstream cause crash in OS/X, bug#3597944
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

View File

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

View File

@ -35,7 +35,7 @@ public:
class dwgFileStream: public dwgBasicStream{
public:
dwgFileStream(std::ifstream *s){
dwgFileStream(std::istream *s){
stream =s;
stream->seekg (0, std::ios::end);
sz = stream->tellg();
@ -49,7 +49,7 @@ public:
virtual bool good(){return stream->good();}
virtual dwgBasicStream* clone(){return new dwgFileStream(stream);}
private:
std::ifstream *stream;
std::istream *stream;
duint64 sz;
};
@ -77,7 +77,7 @@ private:
class dwgBuffer {
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( const dwgBuffer& org );
dwgBuffer& operator=( const dwgBuffer& org );

View File

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

View File

@ -120,7 +120,7 @@ public:
class dwgReader {
friend class dwgR;
public:
dwgReader(std::ifstream *stream, dwgR *p){
dwgReader(std::istream *stream, dwgR *p){
fileBuf = new dwgBuffer(stream);
parent = p;
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);
return ret;
}

View File

@ -21,7 +21,7 @@
class dwgReader15 : public dwgReader {
public:
dwgReader15(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ }
dwgReader15(std::istream *stream, dwgR *p):dwgReader(stream, p){ }
virtual ~dwgReader15() {}
bool readMetaData();
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
return ret;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -35,9 +35,8 @@
secObjects
};*/
dwgR::dwgR(const char* name){
dwgR::dwgR(){
DRW_DBGSL(DRW_dbg::NONE);
fileName = name;
reader = NULL;
// writer = NULL;
applyExt = false;
@ -62,11 +61,10 @@ void dwgR::setDebug(DRW::DBG_LEVEL lvl){
}
/*reads metadata and loads image preview*/
bool dwgR::getPreview(){
bool dwgR::getPreview(std::istream &stream){
bool isOk = false;
std::ifstream filestr;
isOk = openFile(&filestr);
isOk = open(&stream);
if (!isOk)
return false;
@ -76,7 +74,6 @@ bool dwgR::getPreview(){
} else
error = DRW::BAD_READ_METADATA;
filestr.close();
if (reader != NULL) {
delete reader;
reader = NULL;
@ -84,70 +81,13 @@ bool dwgR::getPreview(){
return isOk;
}
bool dwgR::testReader(){
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;
bool dwgR::read(std::istream &stream, DRW_Interface *interface_, bool ext){
applyExt = ext;
iface = interface_;
//testReader();return false;
bool isOk = false;
std::ifstream filestr;
isOk = openFile(&filestr);
isOk = open(&stream);
if (!isOk)
return false;
@ -161,7 +101,6 @@ bool dwgR::read(DRW_Interface *interface_, bool ext){
} else
error = DRW::BAD_READ_METADATA;
filestr.close();
if (reader != NULL) {
delete reader;
reader = NULL;
@ -170,23 +109,9 @@ bool dwgR::read(DRW_Interface *interface_, bool ext){
return isOk;
}
/* Open the file and stores it in filestr, install the correct reader version.
* 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;
}
bool dwgR::open(std::istream *stream){
char line[7];
filestr->read (line, 6);
stream->read (line, 6);
line[6]='\0';
DRW_DBG("dwgR::read 2\n");
DRW_DBG("dwgR::read line version: ");
@ -200,35 +125,33 @@ bool dwgR::openFile(std::ifstream *filestr){
// reader = new dwgReader09(&filestr, this);
}else if (strcmp(line, "AC1012") == 0){
version = DRW::AC1012;
reader = new dwgReader15(filestr, this);
reader = new dwgReader15(stream, this);
} else if (strcmp(line, "AC1014") == 0) {
version = DRW::AC1014;
reader = new dwgReader15(filestr, this);
reader = new dwgReader15(stream, this);
} else if (strcmp(line, "AC1015") == 0) {
version = DRW::AC1015;
reader = new dwgReader15(filestr, this);
reader = new dwgReader15(stream, this);
} else if (strcmp(line, "AC1018") == 0){
version = DRW::AC1018;
reader = new dwgReader18(filestr, this);
reader = new dwgReader18(stream, this);
} else if (strcmp(line, "AC1021") == 0) {
version = DRW::AC1021;
reader = new dwgReader21(filestr, this);
reader = new dwgReader21(stream, this);
} else if (strcmp(line, "AC1024") == 0) {
version = DRW::AC1024;
reader = new dwgReader24(filestr, this);
reader = new dwgReader24(stream, this);
} else if (strcmp(line, "AC1027") == 0) {
version = DRW::AC1027;
reader = new dwgReader27(filestr, this);
reader = new dwgReader27(stream, this);
} else
version = DRW::UNKNOWNV;
if (reader == NULL) {
error = DRW::BAD_VERSION;
filestr->close();
} else
isOk = true;
return isOk;
return false;
}
return true;
}
/********* Reader Process *********/

View File

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

View File

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