diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dd76f3..4891825 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,82 +1,20 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) project(libdxfrw) -if(MSVC) - # Disable some overly strict MSVC warnings. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4244 -wd4800 -wd4805") -endif() - -set(intern_HEADERS - src/intern/drw_cptable932.h - src/intern/drw_cptable936.h - src/intern/drw_cptable949.h - src/intern/drw_cptable950.h - src/intern/drw_cptables.h - src/intern/drw_dbg.h - src/intern/drw_textcodec.h - src/intern/dwgbuffer.h - src/intern/dwgreader15.h - src/intern/dwgreader18.h - src/intern/dwgreader21.h - src/intern/dwgreader24.h - src/intern/dwgreader27.h - src/intern/dwgreader.h - src/intern/dwgutil.h - src/intern/dxfreader.h - src/intern/dxfwriter.h - src/intern/rscodec.h) - -set(intern_SOURCES - src/intern/drw_dbg.cpp - src/intern/drw_textcodec.cpp - src/intern/dwgbuffer.cpp - src/intern/dwgreader15.cpp - src/intern/dwgreader18.cpp - src/intern/dwgreader21.cpp - src/intern/dwgreader24.cpp - src/intern/dwgreader27.cpp - src/intern/dwgreader.cpp - src/intern/dwgutil.cpp - src/intern/dxfreader.cpp - src/intern/dxfwriter.cpp - src/intern/rscodec.cpp) - -set(libdxfrw_HEADERS - src/drw_base.h - src/drw_interface.h - src/drw_header.h - src/drw_classes.h - src/drw_entities.h - src/drw_objects.h - src/libdxfrw.h) - -set(libdxfrw_SOURCES - src/drw_header.cpp - src/drw_classes.cpp - src/drw_entities.cpp - src/drw_objects.cpp - src/libdxfrw.cpp) -set(libdwgr_HEADERS - src/libdwgr.h) +file(GLOB libdxfrw_sources src/*.cpp) +file(GLOB libdxfrw_headers include/*.h) +file(GLOB libdxfrw_intern_sources src/intern/*.cpp) -set(libdwgr_SOURCES - src/libdwgr.cpp) - -add_library(dxfrw STATIC - ${intern_HEADERS} - ${intern_SOURCES} - ${libdxfrw_HEADERS} - ${libdxfrw_SOURCES} - ${libdwgr_HEADERS} - ${libdwgr_SOURCES}) +if(WIN32) -target_include_directories(dxfrw PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/intern/) +include_directories(vs2013/packages/libiconv.1.14.0.11/build/native/include) +link_directories(vs2013/packages/libiconv.1.14.0.11/build/native/lib) +endif() +include_directories(include) -target_include_directories(dxfrw PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/) +add_library(dxfrw STATIC ${libdxfrw_sources} ${libdxfrw_intern_sources}) -install(FILES ${libdxfrw_HEADERS} DESTINATION include) +install(FILES ${libdxfrw_headers} DESTINATION include) if(WIN32) install(TARGETS dxfrw @@ -91,4 +29,4 @@ else() install(TARGETS dxfrw LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) -endif() +endif() \ No newline at end of file diff --git a/src/drw_base.h b/src/drw_base.h index 36f9df7..9e21518 100644 --- a/src/drw_base.h +++ b/src/drw_base.h @@ -103,25 +103,8 @@ enum DBG_LEVEL { //! Special codes for colors enum ColorCodes { - ColorByBlock = 0, - Red = 1, - Yellow = 2, - Green = 3, - Cyan = 4, - Blue = 5, - Magenta = 6, - White = 7, - Gray = 8, - Brown = 15, - LRed = 23, - LGreen = 121, - LCyan = 131, - LBlue = 163, - LMagenta = 221, - Black = 250, - LGray = 252, ColorByLayer = 256, - + ColorByBlock = 0 }; //! Spaces @@ -168,10 +151,14 @@ enum TransparencyCodes { */ class DRW_Coord { public: - DRW_Coord() = default; + DRW_Coord():x(0), y(0),z(0) {} DRW_Coord(double ix, double iy, double iz): x(ix), y(iy),z(iz){} - /*! convert to unitary vector */ + DRW_Coord& operator = (const DRW_Coord& data) { + x = data.x; y = data.y; z = data.z; + return *this; + } +/*!< convert to unitary vector */ void unitize(){ double dist; dist = sqrt(x*x + y*y + z*z); @@ -183,9 +170,9 @@ class DRW_Coord { } public: - double x = 0; - double y = 0; - double z = 0; + double x; + double y; + double z; }; diff --git a/src/drw_entities.cpp b/src/drw_entities.cpp index 316ee0a..c2026a8 100644 --- a/src/drw_entities.cpp +++ b/src/drw_entities.cpp @@ -17,9 +17,9 @@ #include "intern/drw_dbg.h" -//! Calculate arbitrary axis +//! Calculate arbitary axis /*! -* Calculate arbitrary axis for apply extrusions +* Calculate arbitary axis for apply extrusions * @author Rallaz */ void DRW_Entity::calculateAxis(DRW_Coord extPoint){ @@ -50,9 +50,9 @@ void DRW_Entity::calculateAxis(DRW_Coord extPoint){ extAxisY.unitize(); } -//! Extrude a point using arbitrary axis +//! Extrude a point using arbitary axis /*! -* apply extrusion in a point using arbitrary axis (previous calculated) +* apply extrusion in a point using arbitary axis (previous calculated) * @author Rallaz */ void DRW_Entity::extrudePoint(DRW_Coord extPoint, DRW_Coord *point){ @@ -1332,10 +1332,10 @@ bool DRW_Text::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ return ret; DRW_DBG("\n***************************** parsing text *********************************************\n"); - // DataFlags RC Used to determine presence of subsequent data, set to 0xFF for R14- + // DataFlags RC Used to determine presence of subsquent data, set to 0xFF for R14- duint8 data_flags = 0x00; if (version > DRW::AC1014) {//2000+ - data_flags = buf->getRawChar8(); /* DataFlags RC Used to determine presence of subsequent data */ + data_flags = buf->getRawChar8(); /* DataFlags RC Used to determine presence of subsquent data */ DRW_DBG("data_flags: "); DRW_DBG(data_flags); DRW_DBG("\n"); if ( !(data_flags & 0x01) ) { /* Elevation RD --- present if !(DataFlags & 0x01) */ basePoint.z = buf->getRawDouble(); @@ -1427,59 +1427,6 @@ 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; @@ -1517,7 +1464,7 @@ bool DRW_MText::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ DRW_UNUSED(ext_ht); /* Extents wid BD Undocumented and not present in DXF or entget The extents rectangle, when rotated the same as the text, fits the actual text image on - the screen (although we've seen it include an extra row of text in height). */ + the screen (altough we've seen it include an extra row of text in height). */ double ext_wid = buf->getBitDouble(); DRW_UNUSED(ext_wid); /* Text TV 1 All text in one long string (without '\n's 3 for line wrapping). @@ -1965,7 +1912,8 @@ bool DRW_Hatch::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ } for (dint32 j = 0; j < spline->ncontrol;++j){ // pt0 2RD 10 control point - DRW_Coord *crd = new DRW_Coord(buf->get2RawDouble()); + DRW_Coord* crd = new DRW_Coord(buf->get2RawDouble()); + spline->controllist.push_back(crd); if(isRational) crd->z = buf->getBitDouble(); //RLZ: investigate how store weight spline->controllist.push_back(crd); @@ -2023,8 +1971,8 @@ bool DRW_Hatch::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ DRW_DBG("\ndef line: "); DRW_DBG(angleL); DRW_DBG(","); DRW_DBG(ptL.x); DRW_DBG(","); DRW_DBG(ptL.y); DRW_DBG(","); DRW_DBG(offL.x); DRW_DBG(","); DRW_DBG(offL.y); DRW_DBG(","); DRW_DBG(angleL); for (duint16 i = 0 ; i < numDashL; ++i){ - double lengthL = buf->getBitDouble(); - DRW_DBG(","); DRW_DBG(lengthL); + double lenghtL = buf->getBitDouble(); + DRW_DBG(","); DRW_DBG(lenghtL); } }//end deflines } //end not solid @@ -2140,9 +2088,8 @@ void DRW_Spline::parseCode(int code, dxfReader *reader){ case 40: knotslist.push_back(reader->getDouble()); break; - case 41: - weightlist.push_back(reader->getDouble()); - break; +// case 41: +// break; default: DRW_Entity::parseCode(code, reader); break; @@ -2419,10 +2366,6 @@ 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; @@ -2438,15 +2381,6 @@ void DRW_Dimension::parseCode(int code, dxfReader *reader){ case 51: hdir = reader->getDouble(); break; - case 210: - extPoint.x = reader->getDouble(); - break; - case 220: - extPoint.y = reader->getDouble(); - break; - case 230: - extPoint.z = reader->getDouble(); - break; default: DRW_Entity::parseCode(code, reader); break; @@ -3012,7 +2946,7 @@ bool DRW_Viewport::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ frozenLyCount = buf->getBitLong(); DRW_DBG("Frozen Layer count?: "); DRW_DBG(frozenLyCount); DRW_DBG("\n"); DRW_DBG("Status Flags?: "); DRW_DBG(buf->getBitLong()); DRW_DBG("\n"); - //RLZ: Warning needed separate string buffer + //RLZ: Warning needed separate string bufer DRW_DBG("Style sheet?: "); DRW_DBG(sBuf->getVariableText(version, false)); DRW_DBG("\n"); DRW_DBG("Render mode?: "); DRW_DBG(buf->getRawChar8()); DRW_DBG("\n"); DRW_DBG("UCS OMore...: "); DRW_DBG(buf->getBit()); DRW_DBG("\n"); @@ -3027,8 +2961,8 @@ bool DRW_Viewport::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ DRW_DBG("ShadePlot Mode...: "); DRW_DBG(buf->getBitShort()); DRW_DBG("\n"); } if (version > DRW::AC1018) {//2007+ - DRW_DBG("Use def Light...: "); DRW_DBG(buf->getBit()); DRW_DBG("\n"); - DRW_DBG("Def light type?: "); DRW_DBG(buf->getRawChar8()); DRW_DBG("\n"); + DRW_DBG("Use def Ligth...: "); DRW_DBG(buf->getBit()); DRW_DBG("\n"); + DRW_DBG("Def ligth tipe?: "); DRW_DBG(buf->getRawChar8()); DRW_DBG("\n"); DRW_DBG("Brightness: "); DRW_DBG(buf->getBitDouble()); DRW_DBG("\n"); DRW_DBG("Contrast: "); DRW_DBG(buf->getBitDouble()); DRW_DBG("\n"); // DRW_DBG("Ambient Cmc or Enc: "); DRW_DBG(buf->getCmColor(version)); DRW_DBG("\n"); diff --git a/src/drw_entities.h b/src/drw_entities.h index c81a607..b01af09 100644 --- a/src/drw_entities.h +++ b/src/drw_entities.h @@ -155,15 +155,6 @@ class DRW_Entity { 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); @@ -612,7 +603,9 @@ class DRW_LWPolyline : public DRW_Entity { } ~DRW_LWPolyline() { - for(DRW_Vertex2D *item : vertlist) delete item; + while (!vertlist.empty()) { + vertlist.pop_back(); + } } virtual void applyExtrusion(); void addVertex (DRW_Vertex2D v) { @@ -804,7 +797,9 @@ class DRW_Polyline : public DRW_Point { smoothM = smoothN = curvetype = 0; } ~DRW_Polyline() { - for(DRW_Vertex *item : vertlist) delete item; + while (!vertlist.empty()) { + vertlist.pop_back(); + } } void addVertex (DRW_Vertex v) { DRW_Vertex *vert = new DRW_Vertex(); @@ -859,8 +854,12 @@ class DRW_Spline : public DRW_Entity { } ~DRW_Spline() { - for(DRW_Coord *item : controllist) delete item; - for(DRW_Coord *item : fitlist) delete item; + while (!controllist.empty()) { + controllist.pop_back(); + } + while (!fitlist.empty()) { + fitlist.pop_back(); + } } virtual void applyExtrusion(){} @@ -891,7 +890,6 @@ class DRW_Spline : public DRW_Entity { double tolfit; /*!< fit point tolerance, code 44, default 0.0000001 */ std::vector knotslist; /*!< knots list, code 40 */ - std::vector weightlist; /*!< weight list, code 41 */ std::vector controllist; /*!< control points list, code 10, 20 & 30 */ std::vector fitlist; /*!< fit points list, code 11, 21 & 31 */ @@ -913,12 +911,16 @@ class DRW_HatchLoop { } ~DRW_HatchLoop() { - // for(DRW_LWPolyline *item : pollist) delete item; - for(DRW_Entity *item : objlist) delete item; +/* while (!pollist.empty()) { + pollist.pop_back(); + }*/ + while (!objlist.empty()) { + objlist.pop_back(); + } } void update() { - numedges = (int)objlist.size(); + numedges = objlist.size(); } public: @@ -950,7 +952,9 @@ class DRW_Hatch : public DRW_Point { } ~DRW_Hatch() { - for(DRW_HatchLoop *item : looplist) delete item; + while (!looplist.empty()) { + looplist.pop_back(); + } } void appendLoop (DRW_HatchLoop *v) { @@ -1085,9 +1089,6 @@ class DRW_Dimension : public DRW_Entity { 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) { @@ -1111,8 +1112,6 @@ class DRW_Dimension : public DRW_Entity { 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() {} @@ -1143,14 +1142,11 @@ class DRW_Dimension : public DRW_Entity { double getDir() const { return rot;} /*!< rotation angle of the dimension text, code 53 (optional) default 0 */ void setDir(const double d) { rot = d;} - DRW_Coord getExtrusion() const {return extPoint;} /*!< extrusion, code 210, 220 & 230 */ + DRW_Coord getExtrusion(){return extPoint;} /*!< extrusion, code 210, 220 & 230 */ void setExtrusion(const DRW_Coord p) {extPoint =p;} - std::string getName() const {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;} // 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;} @@ -1193,8 +1189,6 @@ class DRW_Dimension : public DRW_Entity { 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; @@ -1212,7 +1206,6 @@ 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; @@ -1241,7 +1234,6 @@ 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; @@ -1263,7 +1255,6 @@ 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; @@ -1290,7 +1281,6 @@ 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; @@ -1298,7 +1288,7 @@ class DRW_DimDiametric : public DRW_Dimension { DRW_Coord getDiameter1Point() const {return getPt5();} /*!< First definition point for diameter, code 15, 25 & 35 */ void setDiameter1Point(const DRW_Coord p){setPt5(p);} - DRW_Coord getDiameter2Point() const {return getDefPoint();} /*!< Opposite point for diameter, code 10, 20 & 30 */ + DRW_Coord getDiameter2Point() const {return getDefPoint();} /*!< Oposite point for diameter, code 10, 20 & 30 */ void setDiameter2Point(const DRW_Coord p){setDefPoint(p);} double getLeaderLength() const {return getRa40();} /*!< Leader length, code 40 */ void setLeaderLength(const double d) {setRa40(d);} @@ -1317,7 +1307,6 @@ 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; @@ -1349,7 +1338,6 @@ 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; @@ -1378,7 +1366,6 @@ 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; @@ -1413,7 +1400,9 @@ class DRW_Leader : public DRW_Entity { extrusionPoint.z = 1.0; } ~DRW_Leader() { - for(DRW_Coord *item : vertexlist) delete item; + while (!vertexlist.empty()) { + vertexlist.pop_back(); + } } virtual void applyExtrusion(){} diff --git a/src/drw_header.cpp b/src/drw_header.cpp index 2829dfc..4812360 100644 --- a/src/drw_header.cpp +++ b/src/drw_header.cpp @@ -303,7 +303,7 @@ void DRW_Header::write(dxfWriter *writer, DRW::Version ver){ if (getDouble("$DIMSCALE", &varDouble)) writer->writeDouble(40, varDouble); else - writer->writeDouble(40, 1.0); + writer->writeDouble(40, 2.5); writer->writeString(9, "$DIMASZ"); if (getDouble("$DIMASZ", &varDouble)) writer->writeDouble(40, varDouble); @@ -473,11 +473,11 @@ void DRW_Header::write(dxfWriter *writer, DRW::Version ver){ writer->writeInt16(70, varInt); else writer->writeInt16(70, 0); - writer->writeString(9, "$DIMSAH"); - if (getInt("$DIMSAH", &varInt)) - writer->writeInt16(70, varInt); - else - writer->writeInt16(70, 0); + writer->writeString(9, "$DIMSAH"); + if (getInt("$DIMSAH", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); writer->writeString(9, "$DIMBLK1"); if (getStr("$DIMBLK1", &varStr)) if (ver == DRW::AC1009) @@ -926,10 +926,6 @@ void DRW_Header::write(dxfWriter *writer, DRW::Version ver){ writer->writeInt16(70, varInt); } else writer->writeInt16(70, 6); - if (getStr("$TDCREATE", &varStr)) { - writer->writeString(9, "$TDCREATE"); - writer->writeString(40, varStr); - } if (ver > DRW::AC1009) { writer->writeString(9, "$UCSBASE"); if (getStr("$UCSBASE", &varStr)) @@ -1530,7 +1526,7 @@ void DRW_Header::write(dxfWriter *writer, DRW::Version ver){ else writer->writeDouble(40, 50.0); writer->writeString(9, "$CAMERAHEIGHT"); - if (getDouble("$CAMERAHEIGHT", &varDouble)) + if (getDouble("$CAMERAHEIGTH", &varDouble)) writer->writeDouble(40, varDouble); else writer->writeDouble(40, 0.0); @@ -1764,8 +1760,8 @@ bool DRW_Header::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *hBbuf DRW_DBG("\nbyte size of data: "); DRW_DBG(size); if (version > DRW::AC1021 && mv > 3) { //2010+ duint32 hSize = buf->getRawLong32(); - endBitPos += 32; //start bit: + 4 height size - DRW_DBG("\n2010+ & MV> 3, height 32b: "); DRW_DBG(hSize); + endBitPos += 32; //start bit: + 4 hight size + DRW_DBG("\n2010+ & MV> 3, higth 32b: "); DRW_DBG(hSize); } //RLZ TODO add $ACADVER var & $DWGCODEPAGE & $MEASUREMENT //RLZ TODO EN 2000 falta $CELWEIGHT, $ENDCAPS, $EXTNAMES $JOINSTYLE $LWDISPLAY $PSTYLEMODE $TDUCREATE $TDUUPDATE $XEDIT @@ -1946,7 +1942,7 @@ bool DRW_Header::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *hBbuf // vars["TDUSRTIMER"]=new DRW_Variant(40, buf->getBitLong());//RLZ: TODO convert to day.msec // vars["TDUSRTIMER"]=new DRW_Variant(40, buf->getBitLong());//RLZ: TODO convert to day.msec vars["CECOLOR"]=new DRW_Variant(62, buf->getCmColor(version));//RLZ: TODO read CMC or EMC color - dwgHandle HANDSEED = buf->getHandle();//always present in data stream + dwgHandle HANDSEED = buf->getHandle();//allways present in data stream DRW_DBG("\nHANDSEED: "); DRW_DBGHL(HANDSEED.code, HANDSEED.size, HANDSEED.ref); dwgHandle CLAYER = hBbuf->getHandle(); DRW_DBG("\nCLAYER: "); DRW_DBGHL(CLAYER.code, CLAYER.size, CLAYER.ref); @@ -2391,7 +2387,7 @@ bool DRW_Header::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *hBbuf } } - buf->setPosition(size+16+4); //read size +16 start sentinel + 4 size + buf->setPosition(size+16+4); //readed size +16 start sentinel + 4 size if (version > DRW::AC1021 && mv > 3) { //2010+ buf->getRawLong32();//advance 4 bytes (hisize) } diff --git a/src/drw_interface.h b/src/drw_interface.h index fa378c2..045b025 100644 --- a/src/drw_interface.h +++ b/src/drw_interface.h @@ -34,20 +34,20 @@ class DRW_Interface { } /** Called when header is parsed. */ - virtual void addHeader(const DRW_Header *) { } + virtual void addHeader(const DRW_Header* data) = 0; /** Called for every line Type. */ - virtual void addLType(const DRW_LType &) { } + virtual void addLType(const DRW_LType& data) = 0; /** Called for every layer. */ - virtual void addLayer(const DRW_Layer &) { } + virtual void addLayer(const DRW_Layer& data) = 0; /** Called for every dim style. */ - virtual void addDimStyle(const DRW_Dimstyle &) { } + virtual void addDimStyle(const DRW_Dimstyle& data) = 0; /** Called for every VPORT table. */ - virtual void addVport(const DRW_Vport &) { } + virtual void addVport(const DRW_Vport& data) = 0; /** Called for every text style. */ - virtual void addTextStyle(const DRW_Textstyle &) { } + virtual void addTextStyle(const DRW_Textstyle& data) = 0; /** Called for every AppId entry. */ - virtual void addAppId(const DRW_AppId &) { } + virtual void addAppId(const DRW_AppId& data) = 0; /** * Called for every block. Note: all entities added after this @@ -55,137 +55,146 @@ class DRW_Interface { * * @see endBlock() */ - virtual void addBlock(const DRW_Block &) { } + 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; /** Called to end the current block */ - virtual void endBlock() { } + virtual void endBlock() = 0; /** Called for every point */ - virtual void addPoint(const DRW_Point &) { } + virtual void addPoint(const DRW_Point& data) = 0; /** Called for every line */ - virtual void addLine(const DRW_Line &) { } + virtual void addLine(const DRW_Line& data) = 0; /** Called for every ray */ - virtual void addRay(const DRW_Ray &) { } + virtual void addRay(const DRW_Ray& data) = 0; /** Called for every xline */ - virtual void addXline(const DRW_Xline &) { } + virtual void addXline(const DRW_Xline& data) = 0; /** Called for every arc */ - virtual void addArc(const DRW_Arc &) { } + virtual void addArc(const DRW_Arc& data) = 0; /** Called for every circle */ - virtual void addCircle(const DRW_Circle &) { } + virtual void addCircle(const DRW_Circle& data) = 0; /** Called for every ellipse */ - virtual void addEllipse(const DRW_Ellipse &) { } + virtual void addEllipse(const DRW_Ellipse& data) = 0; /** Called for every lwpolyline */ - virtual void addLWPolyline(const DRW_LWPolyline &) { } + virtual void addLWPolyline(const DRW_LWPolyline& data) = 0; /** Called for every polyline start */ - virtual void addPolyline(const DRW_Polyline &) { } + virtual void addPolyline(const DRW_Polyline& data) = 0; /** Called for every spline */ - virtual void addSpline(const DRW_Spline *) { } - + virtual void addSpline(const DRW_Spline* data) = 0; + /** Called for every spline knot value */ - virtual void addKnot(const DRW_Entity &) { } + virtual void addKnot(const DRW_Entity& data) = 0; /** Called for every insert. */ - virtual void addInsert(const DRW_Insert &) { } - + virtual void addInsert(const DRW_Insert& data) = 0; + /** Called for every trace start */ - virtual void addTrace(const DRW_Trace &) { } - + virtual void addTrace(const DRW_Trace& data) = 0; + /** Called for every 3dface start */ - virtual void add3dFace(const DRW_3Dface &) { } + virtual void add3dFace(const DRW_3Dface& data) = 0; /** Called for every solid start */ - virtual void addSolid(const DRW_Solid &) { } + virtual void addSolid(const DRW_Solid& data) = 0; /** Called for every Multi Text entity. */ - virtual void addMText(const DRW_MText &) { } + virtual void addMText(const DRW_MText& data) = 0; /** Called for every Text entity. */ - virtual void addText(const DRW_Text &) { } + virtual void addText(const DRW_Text& data) = 0; /** * Called for every aligned dimension entity. */ - virtual void addDimAlign(const DRW_DimAligned *) { } + virtual void addDimAlign(const DRW_DimAligned *data) = 0; /** * Called for every linear or rotated dimension entity. */ - virtual void addDimLinear(const DRW_DimLinear *) { } + virtual void addDimLinear(const DRW_DimLinear *data) = 0; /** * Called for every radial dimension entity. */ - virtual void addDimRadial(const DRW_DimRadial *) { } + virtual void addDimRadial(const DRW_DimRadial *data) = 0; /** * Called for every diametric dimension entity. */ - virtual void addDimDiametric(const DRW_DimDiametric *) { } + virtual void addDimDiametric(const DRW_DimDiametric *data) = 0; /** * Called for every angular dimension (2 lines version) entity. */ - virtual void addDimAngular(const DRW_DimAngular *) { } + virtual void addDimAngular(const DRW_DimAngular *data) = 0; /** * Called for every angular dimension (3 points version) entity. */ - virtual void addDimAngular3P(const DRW_DimAngular3p *) { } - + virtual void addDimAngular3P(const DRW_DimAngular3p *data) = 0; + /** * Called for every ordinate dimension entity. */ - virtual void addDimOrdinate(const DRW_DimOrdinate *) { } - - /** - * Called for every leader start. + virtual void addDimOrdinate(const DRW_DimOrdinate *data) = 0; + + /** + * Called for every leader start. */ - virtual void addLeader(const DRW_Leader *) { } - - /** - * Called for every hatch entity. + virtual void addLeader(const DRW_Leader *data) = 0; + + /** + * Called for every hatch entity. */ - virtual void addHatch(const DRW_Hatch *) { } - + virtual void addHatch(const DRW_Hatch *data) = 0; + /** * Called for every viewport entity. */ - virtual void addViewport(const DRW_Viewport &) { } + virtual void addViewport(const DRW_Viewport& data) = 0; /** * Called for every image entity. */ - virtual void addImage(const DRW_Image *) { } + virtual void addImage(const DRW_Image *data) = 0; /** * Called for every image definition. */ - virtual void linkImage(const DRW_ImageDef *) { } + virtual void linkImage(const DRW_ImageDef *data) = 0; /** * Called for every comment in the DXF file (code 999). */ - virtual void addComment(const char *) { } - - 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() { } + virtual void addComment(const char* comment) = 0; + + 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; }; #endif diff --git a/src/drw_objects.cpp b/src/drw_objects.cpp index 0572316..4d1e0c4 100644 --- a/src/drw_objects.cpp +++ b/src/drw_objects.cpp @@ -448,13 +448,13 @@ void DRW_LType::parseCode(int code, dxfReader *reader){ //! Update line type /*! -* Update the size and length of line type according to the path +* Update the size and length of line type acording to the path * @author Rallaz */ /*TODO: control max length permited */ void DRW_LType::update(){ double d =0; - size = (int)path.size(); + size = path.size(); for (int i = 0; i< size; i++){ d += fabs(path.at(i)); } diff --git a/src/drw_objects.h b/src/drw_objects.h index f19467a..65b0e0e 100644 --- a/src/drw_objects.h +++ b/src/drw_objects.h @@ -128,30 +128,25 @@ class DRW_Dimstyle : public DRW_TableEntry { void reset(){ tType = DRW::DIMSTYLE; - dimasz = dimtxt = dimcen = 2.5; - dimexe = 1.25; - dimexo = dimgap = 0.625; - dimtxsty = ""; + dimasz = dimtxt = dimexe = 0.18; + dimexo = 0.0625; + dimgap = dimcen = 0.09; + dimtxsty = "Standard"; dimscale = dimlfac = dimtfac = dimfxl = 1.0; - dimdli = 3.75; + dimdli = 0.38; dimrnd = dimdle = dimtp = dimtm = dimtsz = dimtvp = 0.0; - 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; + 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; dimclrd = dimclre = dimclrt = dimjust = dimupt = 0; - dimtzin = 8; - dimazin = dimaltz = dimaltttz = dimfrac = 0; + dimazin = dimaltz = dimaltttz = dimtzin = dimfrac = 0; dimtih = dimadec = dimaunit = dimsd1 = dimsd2 = dimtmove = 0; dimaltrnd = 0.0; - dimdec = dimtdec = 2; + dimdec = dimtdec = 4; dimfit = dimatfit = 3; - dimdsep = ','; + dimdsep = '.'; dimlwd = dimlwe = -2; DRW_TableEntry::reset(); } @@ -439,7 +434,7 @@ class DRW_Vport : public DRW_TableEntry { * bit 1 (1) show out of limits * bit 2 (2) adaptive grid * bit 3 (4) allow subdivision - * bit 4 (8) follow dynamic SCP + * bit 4 (8) follow dinamic SCP **/ }; diff --git a/src/intern/drw_cptable932.h b/src/intern/drw_cptable932.h index a85f3ca..0d9be10 100644 --- a/src/intern/drw_cptable932.h +++ b/src/intern/drw_cptable932.h @@ -6,7 +6,7 @@ //first entry in this table are 0xA1 #define CPOFFSET932 0xFEC0 //#define CP1LENGHT932 63 -#define CPLENGTH932 7724 +#define CPLENGHT932 7724 #define NOTFOUND932 0x30FB //Table 932 one byte are diff --git a/src/intern/drw_cptable936.h b/src/intern/drw_cptable936.h index 9f5fb56..4c1c141 100644 --- a/src/intern/drw_cptable936.h +++ b/src/intern/drw_cptable936.h @@ -5,7 +5,7 @@ //first entry in this tables are 0x80 #define CPOFFSET936 0x80 -#define CPLENGTH936 21791 +#define CPLENGHT936 21791 #define NOTFOUND936 0x003F //Table 949 one byte diff --git a/src/intern/drw_cptable949.h b/src/intern/drw_cptable949.h index 5364bea..3276b60 100644 --- a/src/intern/drw_cptable949.h +++ b/src/intern/drw_cptable949.h @@ -5,7 +5,7 @@ //first entry in this table are 0x80 #define CPOFFSET949 0x80 -#define CPLENGTH949 17048 +#define CPLENGHT949 17048 #define NOTFOUND949 0x003F //Table 949 one byte diff --git a/src/intern/drw_cptable950.h b/src/intern/drw_cptable950.h index 3adc1e8..2afb89d 100644 --- a/src/intern/drw_cptable950.h +++ b/src/intern/drw_cptable950.h @@ -5,7 +5,7 @@ //first entry in this table are 0x80 #define CPOFFSET950 0x80 -#define CPLENGTH950 13503 +#define CPLENGHT950 13503 #define NOTFOUND950 0x003F //Table 950 one byte diff --git a/src/intern/drw_cptables.h b/src/intern/drw_cptables.h index 7217743..2f7d758 100644 --- a/src/intern/drw_cptables.h +++ b/src/intern/drw_cptables.h @@ -3,7 +3,7 @@ //first entry in all tables are 0x80 #define CPOFFSET 0x80 -#define CPLENGTHCOMMON 128 +#define CPLENGHTCOMMON 128 //Table 874 static const int DRW_Table874[] = { diff --git a/src/intern/drw_textcodec.cpp b/src/intern/drw_textcodec.cpp index 2541a6a..c9d9180 100644 --- a/src/intern/drw_textcodec.cpp +++ b/src/intern/drw_textcodec.cpp @@ -62,35 +62,35 @@ void DRW_TextCodec::setCodePage(std::string *c, bool dxfFormat){ delete conv; if (version == DRW::AC1009 || version == DRW::AC1015) { if (cp == "ANSI_874") - conv = new DRW_ConvTable(DRW_Table874, CPLENGTHCOMMON); + conv = new DRW_ConvTable(DRW_Table874, CPLENGHTCOMMON); else if (cp == "ANSI_932") conv = new DRW_Conv932Table(DRW_Table932, DRW_LeadTable932, - DRW_DoubleTable932, CPLENGTH932); + DRW_DoubleTable932, CPLENGHT932); else if (cp == "ANSI_936") conv = new DRW_ConvDBCSTable(DRW_Table936, DRW_LeadTable936, - DRW_DoubleTable936, CPLENGTH936); + DRW_DoubleTable936, CPLENGHT936); else if (cp == "ANSI_949") conv = new DRW_ConvDBCSTable(DRW_Table949, DRW_LeadTable949, - DRW_DoubleTable949, CPLENGTH949); + DRW_DoubleTable949, CPLENGHT949); else if (cp == "ANSI_950") conv = new DRW_ConvDBCSTable(DRW_Table950, DRW_LeadTable950, - DRW_DoubleTable950, CPLENGTH950); + DRW_DoubleTable950, CPLENGHT950); else if (cp == "ANSI_1250") - conv = new DRW_ConvTable(DRW_Table1250, CPLENGTHCOMMON); + conv = new DRW_ConvTable(DRW_Table1250, CPLENGHTCOMMON); else if (cp == "ANSI_1251") - conv = new DRW_ConvTable(DRW_Table1251, CPLENGTHCOMMON); + conv = new DRW_ConvTable(DRW_Table1251, CPLENGHTCOMMON); else if (cp == "ANSI_1253") - conv = new DRW_ConvTable(DRW_Table1253, CPLENGTHCOMMON); + conv = new DRW_ConvTable(DRW_Table1253, CPLENGHTCOMMON); else if (cp == "ANSI_1254") - conv = new DRW_ConvTable(DRW_Table1254, CPLENGTHCOMMON); + conv = new DRW_ConvTable(DRW_Table1254, CPLENGHTCOMMON); else if (cp == "ANSI_1255") - conv = new DRW_ConvTable(DRW_Table1255, CPLENGTHCOMMON); + conv = new DRW_ConvTable(DRW_Table1255, CPLENGHTCOMMON); else if (cp == "ANSI_1256") - conv = new DRW_ConvTable(DRW_Table1256, CPLENGTHCOMMON); + conv = new DRW_ConvTable(DRW_Table1256, CPLENGHTCOMMON); else if (cp == "ANSI_1257") - conv = new DRW_ConvTable(DRW_Table1257, CPLENGTHCOMMON); + conv = new DRW_ConvTable(DRW_Table1257, CPLENGHTCOMMON); else if (cp == "ANSI_1258") - conv = new DRW_ConvTable(DRW_Table1258, CPLENGTHCOMMON); + 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"); @@ -159,7 +159,7 @@ std::string DRW_ConvTable::fromUtf8(std::string *s) { j = i+l; i = j - 1; notFound = true; - for (int k=0; k0x390 && code<0x542) || (code>0x200F && code<0x9FA1) || code>0xF928 )) { - for (int k=0; ksize(); @@ -299,7 +299,7 @@ duint8 dwgBuffer::get3Bits(){ /**Reads tree Bits returns a char (3B) for R24 **/ //to be written -/**Reads compressed Short (max. 16 + 2 bits) little-endian order, returns a UNsigned 16 bits (BS) **/ +/**Reads compresed Short (max. 16 + 2 bits) little-endian order, returns a UNsigned 16 bits (BS) **/ duint16 dwgBuffer::getBitShort(){ duint8 b = get2Bits(); if (b == 0) @@ -311,7 +311,7 @@ duint16 dwgBuffer::getBitShort(){ else return 256; } -/**Reads compressed Short (max. 16 + 2 bits) little-endian order, returns a signed 16 bits (BS) **/ +/**Reads compresed Short (max. 16 + 2 bits) little-endian order, returns a signed 16 bits (BS) **/ dint16 dwgBuffer::getSBitShort(){ duint8 b = get2Bits(); if (b == 0) @@ -324,7 +324,7 @@ dint16 dwgBuffer::getSBitShort(){ return 256; } -/**Reads compressed 32 bits Int (max. 32 + 2 bits) little-endian order, returns a signed 32 bits (BL) **/ +/**Reads compresed 32 bits Int (max. 32 + 2 bits) little-endian order, returns a signed 32 bits (BL) **/ //to be written dint32 dwgBuffer::getBitLong(){ dint8 b = get2Bits(); @@ -336,7 +336,7 @@ dint32 dwgBuffer::getBitLong(){ return 0; } -/**Reads compressed 64 bits Int (max. 56 + 3 bits) little-endian order, returns a unsigned 64 bits (BLL) **/ +/**Reads compresed 64 bits Int (max. 56 + 3 bits) little-endian order, returns a unsigned 64 bits (BLL) **/ duint64 dwgBuffer::getBitLongLong(){ dint8 b = get3Bits(); duint64 ret=0; @@ -347,7 +347,7 @@ duint64 dwgBuffer::getBitLongLong(){ return ret; } -/**Reads compressed Double (max. 64 + 2 bits) returns a floating point double of 64 bits (BD) **/ +/**Reads compresed Double (max. 64 + 2 bits) returns a floating point double of 64 bits (BD) **/ double dwgBuffer::getBitDouble(){ dint8 b = get2Bits(); if (b == 1) @@ -367,7 +367,7 @@ double dwgBuffer::getBitDouble(){ return 0.0; } -/**Reads 3 compressed Double (max. 64 + 2 bits) returns a DRW_Coord of floating point double of 64 bits (3BD) **/ +/**Reads 3 compresed Double (max. 64 + 2 bits) returns a DRW_Coord of floating point double of 64 bits (3BD) **/ DRW_Coord dwgBuffer::get3BitDouble(){ DRW_Coord crd; crd.x = getBitDouble(); @@ -452,7 +452,7 @@ duint64 dwgBuffer::getRawLong64(){ return ret; } -/**Reads modular unsigner int, char based, compressed form, little-endian order, returns a unsigned int (U-MC) **/ +/**Reads modular unsigner int, char based, compresed form, little-endian order, returns a unsigned int (U-MC) **/ duint32 dwgBuffer::getUModularChar(){ std::vector buffer; duint32 result =0; @@ -472,7 +472,7 @@ duint32 dwgBuffer::getUModularChar(){ return result; } -/**Reads modular int, char based, compressed form, little-endian order, returns a signed int (MC) **/ +/**Reads modular int, char based, compresed form, little-endian order, returns a signed int (MC) **/ dint32 dwgBuffer::getModularChar(){ bool negative = false; std::vector buffer; @@ -500,7 +500,7 @@ dint32 dwgBuffer::getModularChar(){ return result; } -/**Reads modular int, short based, compressed form, little-endian order, returns a unsigned int (MC) **/ +/**Reads modular int, short based, compresed form, little-endian order, returns a unsigned int (MC) **/ dint32 dwgBuffer::getModularShort(){ // bool negative = false; std::vector buffer; @@ -691,7 +691,7 @@ DRW_Coord dwgBuffer::getExtrusion(bool b_R2000_style) { return ext; } -/**Reads compressed Double with default (max. 64 + 2 bits) returns a floating point double of 64 bits (DD) **/ +/**Reads compresed Double with default (max. 64 + 2 bits) returns a floating point double of 64 bits (DD) **/ double dwgBuffer::getDefaultDouble(double d){ dint8 b = get2Bits(); if (b == 0) diff --git a/src/intern/dwgbuffer.h b/src/intern/dwgbuffer.h index 2dffc23..bfc4fa6 100644 --- a/src/intern/dwgbuffer.h +++ b/src/intern/dwgbuffer.h @@ -35,7 +35,7 @@ class dwgBasicStream{ class dwgFileStream: public dwgBasicStream{ public: - dwgFileStream(std::istream *s){ + dwgFileStream(std::ifstream *s){ stream =s; stream->seekg (0, std::ios::end); sz = stream->tellg(); @@ -49,7 +49,7 @@ class dwgFileStream: public dwgBasicStream{ virtual bool good(){return stream->good();} virtual dwgBasicStream* clone(){return new dwgFileStream(stream);} private: - std::istream *stream; + std::ifstream *stream; duint64 sz; }; @@ -77,7 +77,7 @@ class dwgCharStream: public dwgBasicStream{ class dwgBuffer { public: - dwgBuffer(std::istream *stream, DRW_TextCodec *decoder = NULL); + dwgBuffer(std::ifstream *stream, DRW_TextCodec *decoder = NULL); dwgBuffer(duint8 *buf, int size, DRW_TextCodec *decoder= NULL); dwgBuffer( const dwgBuffer& org ); dwgBuffer& operator=( const dwgBuffer& org ); diff --git a/src/intern/dwgreader.h b/src/intern/dwgreader.h index fa84852..9f34885 100644 --- a/src/intern/dwgreader.h +++ b/src/intern/dwgreader.h @@ -43,14 +43,14 @@ class objHandle{ * address, address in file stream * dataSize, data size for this page * startOffset, start offset for this page - * cSize, compressed size of data - * uSize, uncompressed size of data + * cSize, compresed size of data + * uSize, uncompresed size of data * 2007: page Id, pageCount & pages * size, size in file * dataSize - * startOffset, start position in decompressed data stream - * cSize, compressed size of data - * uSize, uncompressed size of data + * startOffset, start position in decompresed data stream + * cSize, compresed size of data + * uSize, uncompresed size of data * address, address in file stream * */ class dwgPageInfo { @@ -65,25 +65,25 @@ class dwgPageInfo { duint64 size; //in file stream, for rd18, rd21 duint64 dataSize; //for rd18, rd21 duint32 startOffset; //for rd18, rd21 - duint64 cSize; //compressed page size, for rd21 - duint64 uSize; //uncompressed page size, for rd21 + duint64 cSize; //compresed page size, for rd21 + duint64 uSize; //uncompresed page size, for rd21 }; // sections of file /* 2000-: No pages, only section Id, size & address in file * 2004+: Id, Section Id - * size, total size of uncompressed data + * size, total size of uncompresed data * pageCount & pages, number of pages in section * maxSize, max decompressed Size per page - * compressed, (1 = no, 2 = yes, normally 2) + * compresed, (1 = no, 2 = yes, normally 2) * encrypted, (0 = no, 1 = yes, 2 = unknown) * name, read & stored but not used - * 2007: same as 2004+ except encoding, saved in compressed field + * 2007: same as 2004+ except encoding, saved in compresed field * */ class dwgSectionInfo { public: dwgSectionInfo(){ - compressed = 1;//1=no, 2=yes + compresed = 1;//1=no, 2=yes encrypted = 0;//??? pageCount = 0; Id=-1; @@ -91,7 +91,7 @@ class dwgSectionInfo { ~dwgSectionInfo(){} dint32 Id; //section Id, 2000- rd15 rd18 std::string name; //section name rd18 - duint32 compressed;//is compressed? 1=no, 2=yes rd18, rd21(encoding) + duint32 compresed;//is compresed? 1=no, 2=yes rd18, rd21(encoding) duint32 encrypted;//encrypted (doc: 0=no, 1=yes, 2=unkn) on read: objects 0 and encrypted yes rd18 std::mappages;//index, size, offset duint64 size;//size of section, 2000- rd15, rd18, rd21 (data size) @@ -120,7 +120,7 @@ class DRW_ObjControl : public DRW_TableEntry { class dwgReader { friend class dwgR; public: - dwgReader(std::istream *stream, dwgR *p){ + dwgReader(std::ifstream *stream, dwgR *p){ fileBuf = new dwgBuffer(stream); parent = p; decoder.setVersion(DRW::AC1021, false);//default 2007 in utf8(no convert) @@ -164,8 +164,8 @@ class dwgReader { public: std::mapObjectMap; - std::mapobjObjectMap; //stores the objects & entities not read in readDwgEntities - std::mapremainingMap; //stores the objects & entities not read in all processes, for debug only + std::mapobjObjectMap; //stores the ojects & entities not read in readDwgEntities + std::mapremainingMap; //stores the ojects & entities not read in all proces, for debug only std::map ltypemap; std::map layermap; std::map blockmap; diff --git a/src/intern/dwgreader15.h b/src/intern/dwgreader15.h index e3a1f97..8b3dc24 100644 --- a/src/intern/dwgreader15.h +++ b/src/intern/dwgreader15.h @@ -21,7 +21,7 @@ class dwgReader15 : public dwgReader { public: - dwgReader15(std::istream *stream, dwgR *p):dwgReader(stream, p){ } + dwgReader15(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ } virtual ~dwgReader15() {} bool readMetaData(); bool readFileHeader(); diff --git a/src/intern/dwgreader18.cpp b/src/intern/dwgreader18.cpp index 37878e6..a27ff77 100644 --- a/src/intern/dwgreader18.cpp +++ b/src/intern/dwgreader18.cpp @@ -91,7 +91,7 @@ void dwgReader18::parseSysPage(duint8 *decompSec, duint32 decompSize){ } else { DRW_DBG(", "); j++; } } DRW_DBG("\n"); #endif - DRW_DBG("decompressing "); DRW_DBG(compSize); DRW_DBG(" bytes in "); DRW_DBG(decompSize); DRW_DBG(" bytes\n"); + DRW_DBG("decompresing "); DRW_DBG(compSize); DRW_DBG(" bytes in "); DRW_DBG(decompSize); DRW_DBG(" bytes\n"); dwgCompressor comp; comp.decompress18(tmpCompSec, decompSec, compSize, decompSize); #ifdef DRW_DBG_DUMP @@ -146,7 +146,7 @@ bool dwgReader18::parseDataPage(dwgSectionInfo si/*, duint8 *dData*/){ DRW_DBG("\n header checksum= "); DRW_DBGH(bufHdr.getRawLong32()); DRW_DBG("\n data checksum= "); DRW_DBGH(bufHdr.getRawLong32()); DRW_DBG("\n"); - //get compressed data + //get compresed data duint8 *cData = new duint8[pi.cSize]; if (!fileBuf->setPosition(pi.address+32)) return false; @@ -162,7 +162,7 @@ bool dwgReader18::parseDataPage(dwgSectionInfo si/*, duint8 *dData*/){ duint8* oData = objData + pi.startOffset; pi.uSize = si.maxSize; - DRW_DBG("decompressing "); DRW_DBG(pi.cSize); DRW_DBG(" bytes in "); DRW_DBG(pi.uSize); DRW_DBG(" bytes\n"); + DRW_DBG("decompresing "); DRW_DBG(pi.cSize); DRW_DBG(" bytes in "); DRW_DBG(pi.uSize); DRW_DBG(" bytes\n"); dwgCompressor comp; comp.decompress18(cData, oData, pi.cSize, pi.uSize); delete[]cData; @@ -177,7 +177,7 @@ bool dwgReader18::readMetaData() { if (! fileBuf->setPosition(11)) return false; maintenanceVersion = fileBuf->getRawChar8(); - DRW_DBG("maintenance version= "); DRW_DBGH(maintenanceVersion); + DRW_DBG("maintenance verion= "); DRW_DBGH(maintenanceVersion); DRW_DBG("\nbyte at 0x0C= "); DRW_DBGH(fileBuf->getRawChar8()); previewImagePos = fileBuf->getRawLong32(); //+ page header size (0x20). DRW_DBG("\npreviewImagePos (seekerImageData) = "); DRW_DBG(previewImagePos); @@ -304,7 +304,7 @@ bool dwgReader18::readFileHeader() { duint8 *tmpDecompSec = new duint8[decompSize]; parseSysPage(tmpDecompSec, decompSize); -//parses "Section page map" decompressed data +//parses "Section page map" decompresed data dwgBuffer buff2(tmpDecompSec, decompSize, &decoder); duint32 address = 0x100; //stores temporaly info of all pages: @@ -366,8 +366,8 @@ bool dwgReader18::readFileHeader() { secInfo.maxSize = buff3.getRawLong32(); DRW_DBG("\nMax Decompressed Size= "); DRW_DBGH(secInfo.maxSize); DRW_DBG("\nunknown long= "); DRW_DBGH(buff3.getRawLong32()); - secInfo.compressed = buff3.getRawLong32(); - DRW_DBG("\nis Compressed? 1:no, 2:yes= "); DRW_DBGH(secInfo.compressed); + secInfo.compresed = buff3.getRawLong32(); + DRW_DBG("\nis Compressed? 1:no, 2:yes= "); DRW_DBGH(secInfo.compresed); secInfo.Id = buff3.getRawLong32(); DRW_DBG("\nSection Id= "); DRW_DBGH(secInfo.Id); secInfo.encrypted = buff3.getRawLong32(); @@ -451,7 +451,7 @@ bool dwgReader18::readDwgClasses(){ DRW_DBG("\ndata size in bytes "); DRW_DBG(size); if (version > DRW::AC1021 && maintenanceVersion > 3) { //2010+ duint32 hSize = dataBuf.getRawLong32(); - DRW_DBG("\n2010+ & MV> 3, height 32b: "); DRW_DBG(hSize); + DRW_DBG("\n2010+ & MV> 3, higth 32b: "); DRW_DBG(hSize); } duint32 bitSize = 0; if (version > DRW::AC1021) {//2007+ diff --git a/src/intern/dwgreader18.h b/src/intern/dwgreader18.h index f814096..4b66313 100644 --- a/src/intern/dwgreader18.h +++ b/src/intern/dwgreader18.h @@ -43,7 +43,7 @@ static const int DRW_magicNumEnd18[] = { class dwgReader18 : public dwgReader { public: - dwgReader18(std::istream *stream, dwgR *p):dwgReader(stream, p){ + dwgReader18(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ objData = NULL; } virtual ~dwgReader18(){ diff --git a/src/intern/dwgreader21.cpp b/src/intern/dwgreader21.cpp index becea94..6277aa1 100644 --- a/src/intern/dwgreader21.cpp +++ b/src/intern/dwgreader21.cpp @@ -28,7 +28,7 @@ bool dwgReader21::readMetaData() { if (! fileBuf->setPosition(11)) return false; maintenanceVersion = fileBuf->getRawChar8(); - DRW_DBG("maintenance version= "); DRW_DBGH(maintenanceVersion); + DRW_DBG("maintenance verion= "); DRW_DBGH(maintenanceVersion); DRW_DBG("\nbyte at 0x0C= "); DRW_DBG(fileBuf->getRawChar8()); previewImagePos = fileBuf->getRawLong32(); DRW_DBG("previewImagePos (seekerImageData) = "); DRW_DBG(previewImagePos); @@ -110,7 +110,7 @@ bool dwgReader21::parseDataPage(dwgSectionInfo si, duint8 *dData){ dwgCompressor::decompress21(tmpPageRS, pageData, pi.cSize, pi.uSize); #ifdef DRW_DBG_DUMP - DRW_DBG("\n\nSection OBJECTS decompressed data=\n"); + DRW_DBG("\n\nSection OBJECTS decompresed data=\n"); for (unsigned int i=0, j=0; i< pi.uSize;i++) { DRW_DBGH( (unsigned char)pageData[i]); if (j == 7) { DRW_DBG("\n"); j = 0; @@ -161,7 +161,7 @@ bool dwgReader21::readFileHeader() { fileHdrData = new duint8[fileHdrDataLength]; fileHdrBuf.getBytes(fileHdrData, fileHdrDataLength); }else { - DRW_DBG("\ndwgReader21:: file header are compressed:\n"); + DRW_DBG("\ndwgReader21:: file header are compresed:\n"); duint8 *compByteStr = new duint8[fileHdrCompLength]; fileHdrBuf.getBytes(compByteStr, fileHdrCompLength); fileHdrData = new duint8[fileHdrDataLength]; @@ -281,8 +281,8 @@ bool dwgReader21::readFileHeader() { duint64 SectionNameLength = SectionsMapBuf.getRawLong64(); DRW_DBG("\nSectionNameLength = "); DRW_DBG(SectionNameLength); DRW_DBG("\nUnknown = "); DRW_DBGH(SectionsMapBuf.getRawLong64()); - secInfo.compressed = SectionsMapBuf.getRawLong64(); - DRW_DBG("\nEncoding (compressed) = "); DRW_DBGH(secInfo.compressed); + secInfo.compresed = SectionsMapBuf.getRawLong64(); + DRW_DBG("\nEncoding (compresed) = "); DRW_DBGH(secInfo.compresed); secInfo.pageCount = SectionsMapBuf.getRawLong64(); DRW_DBG("\nPage count= "); DRW_DBGH(secInfo.pageCount); secInfo.name = SectionsMapBuf.getUCSStr(SectionNameLength); diff --git a/src/intern/dwgreader21.h b/src/intern/dwgreader21.h index f95c77a..9cecd69 100644 --- a/src/intern/dwgreader21.h +++ b/src/intern/dwgreader21.h @@ -22,7 +22,7 @@ //reader for AC1021 aka v2007, chapter 5 class dwgReader21 : public dwgReader { public: - dwgReader21(std::istream *stream, dwgR *p):dwgReader(stream, p){ + dwgReader21(std::ifstream *stream, dwgR *p):dwgReader(stream, p){ objData = NULL; dataSize = 0; } diff --git a/src/intern/dwgreader24.h b/src/intern/dwgreader24.h index e5fc43a..36ac7fe 100644 --- a/src/intern/dwgreader24.h +++ b/src/intern/dwgreader24.h @@ -21,7 +21,7 @@ class dwgReader24 : public dwgReader18 { public: - dwgReader24(std::istream *stream, dwgR *p):dwgReader18(stream, p){ } + dwgReader24(std::ifstream *stream, dwgR *p):dwgReader18(stream, p){ } virtual ~dwgReader24(){} bool readFileHeader(); bool readDwgHeader(DRW_Header& hdr); diff --git a/src/intern/dwgreader27.h b/src/intern/dwgreader27.h index 32c67f6..676cdc1 100644 --- a/src/intern/dwgreader27.h +++ b/src/intern/dwgreader27.h @@ -21,7 +21,7 @@ class dwgReader27 : public dwgReader18 { public: - dwgReader27(std::istream *stream, dwgR *p):dwgReader18(stream, p){ } + dwgReader27(std::ifstream *stream, dwgR *p):dwgReader18(stream, p){ } virtual ~dwgReader27(){} bool readFileHeader(); bool readDwgHeader(DRW_Header& hdr); diff --git a/src/intern/dwgutil.cpp b/src/intern/dwgutil.cpp index 8fc6eb3..10121cf 100644 --- a/src/intern/dwgutil.cpp +++ b/src/intern/dwgutil.cpp @@ -151,10 +151,10 @@ void dwgCompressor::decompress18(duint8 *cbuf, duint8 *dbuf, duint32 csize, duin duint32 compOffset; duint32 litCount; - pos=0; //current position in compressed buffer - rpos=0; //current position in resulting decompressed buffer + pos=0; //current position in compresed buffer + rpos=0; //current position in resulting decompresed buffer litCount = litLength18(); - //copy first literal length + //copy first lileral lenght for (duint32 i=0; i < litCount; ++i) { bufD[rpos++] = bufC[pos++]; } @@ -199,7 +199,7 @@ void dwgCompressor::decompress18(duint8 *cbuf, duint8 *dbuf, duint32 csize, duin DRW_DBG(pos);DRW_DBG(", Dpos: ");DRW_DBG(rpos);DRW_DBG("\n"); return; //fails, not valid } - //copy "compressed data", TODO Needed verify out of bounds + //copy "compresed data", TODO Needed verify out of bounds duint32 remaining = sizeD - (litCount+rpos); if (remaining < compBytes){ compBytes = remaining; @@ -209,7 +209,7 @@ void dwgCompressor::decompress18(duint8 *cbuf, duint8 *dbuf, duint32 csize, duin for (duint32 i=0, j= rpos - compOffset -1; i < compBytes; i++) { bufD[rpos++] = bufD[j++]; } - //copy "uncompressed data", TODO Needed verify out of bounds + //copy "uncompresed data", TODO Needed verify out of bounds for (duint32 i=0; i < litCount; i++) { bufD[rpos++] = bufC[pos++]; } @@ -274,7 +274,7 @@ void dwgCompressor::decompress21(duint8 *cbuf, duint8 *dbuf, duint32 csize, duin copyCompBytes21(cbuf, dbuf, length, srcIndex, dstIndex); srcIndex += length; dstIndex += length; - if (dstIndex >=dsize) break; //check if last chunk are compressed & terminate + if (dstIndex >=dsize) break; //check if last chunk are compresed & terminate length = 0; opCode = cbuf[srcIndex++]; diff --git a/src/intern/dxfreader.h b/src/intern/dxfreader.h index 71329be..bcb3c1a 100644 --- a/src/intern/dxfreader.h +++ b/src/intern/dxfreader.h @@ -27,7 +27,7 @@ class dxfReader { }; enum TYPE type; public: - dxfReader(std::istream *stream){ + dxfReader(std::ifstream *stream){ filestr = stream; type = INVALID; } @@ -48,7 +48,7 @@ class dxfReader { std::string getCodePage(){ return decoder.getCodePage();} protected: - virtual bool readCode(int *code) = 0; //return true if successful (not EOF) + virtual bool readCode(int *code) = 0; //return true if sucesful (not EOF) virtual bool readString(std::string *text) = 0; virtual bool readString() = 0; virtual bool readInt16() = 0; @@ -58,7 +58,7 @@ class dxfReader { virtual bool readBool() = 0; protected: - std::istream *filestr; + std::ifstream *filestr; std::string strData; double doubleData; signed int intData; //32 bits integer @@ -70,7 +70,7 @@ class dxfReader { class dxfReaderBinary : public dxfReader { public: - dxfReaderBinary(std::istream *stream):dxfReader(stream){skip = false; } + dxfReaderBinary(std::ifstream *stream):dxfReader(stream){skip = false; } virtual ~dxfReaderBinary() {} virtual bool readCode(int *code); virtual bool readString(std::string *text); @@ -84,7 +84,7 @@ class dxfReaderBinary : public dxfReader { class dxfReaderAscii : public dxfReader { public: - dxfReaderAscii(std::istream *stream):dxfReader(stream){skip = true; } + dxfReaderAscii(std::ifstream *stream):dxfReader(stream){skip = true; } virtual ~dxfReaderAscii(){} virtual bool readCode(int *code); virtual bool readString(std::string *text); diff --git a/src/intern/dxfwriter.cpp b/src/intern/dxfwriter.cpp index 2231733..40ca3fc 100644 --- a/src/intern/dxfwriter.cpp +++ b/src/intern/dxfwriter.cpp @@ -214,7 +214,7 @@ bool dxfWriterBinary::writeBool(int code, bool data) { return (filestr->good()); } -dxfWriterAscii::dxfWriterAscii(std::ostream *stream):dxfWriter(stream){ +dxfWriterAscii::dxfWriterAscii(std::ofstream *stream):dxfWriter(stream){ filestr->precision(16); } diff --git a/src/intern/dxfwriter.h b/src/intern/dxfwriter.h index adabe02..2af464b 100644 --- a/src/intern/dxfwriter.h +++ b/src/intern/dxfwriter.h @@ -17,7 +17,7 @@ class dxfWriter { public: - dxfWriter(std::ostream *stream){filestr = stream; /*count =0;*/} + dxfWriter(std::ofstream *stream){filestr = stream; /*count =0;*/} virtual ~dxfWriter(){} virtual bool writeString(int code, std::string text) = 0; bool writeUtf8String(int code, std::string text); @@ -32,14 +32,14 @@ class dxfWriter { void setCodePage(std::string *c){encoder.setCodePage(c, true);} std::string getCodePage(){return encoder.getCodePage();} protected: - std::ostream *filestr; + std::ofstream *filestr; private: DRW_TextCodec encoder; }; class dxfWriterBinary : public dxfWriter { public: - dxfWriterBinary(std::ostream *stream):dxfWriter(stream){} + dxfWriterBinary(std::ofstream *stream):dxfWriter(stream){} virtual ~dxfWriterBinary() {} virtual bool writeString(int code, std::string text); virtual bool writeInt16(int code, int data); @@ -51,7 +51,7 @@ class dxfWriterBinary : public dxfWriter { class dxfWriterAscii : public dxfWriter { public: - dxfWriterAscii(std::ostream *stream); + dxfWriterAscii(std::ofstream *stream); virtual ~dxfWriterAscii(){} virtual bool writeString(int code, std::string text); virtual bool writeInt16(int code, int data); diff --git a/src/libdwgr.cpp b/src/libdwgr.cpp index adca43c..4ba77ff 100644 --- a/src/libdwgr.cpp +++ b/src/libdwgr.cpp @@ -35,8 +35,9 @@ secObjects };*/ -dwgR::dwgR(){ +dwgR::dwgR(const char* name){ DRW_DBGSL(DRW_dbg::NONE); + fileName = name; reader = NULL; // writer = NULL; applyExt = false; @@ -61,10 +62,11 @@ void dwgR::setDebug(DRW::DBG_LEVEL lvl){ } /*reads metadata and loads image preview*/ -bool dwgR::getPreview(std::istream &stream){ +bool dwgR::getPreview(){ bool isOk = false; - isOk = open(&stream); + std::ifstream filestr; + isOk = openFile(&filestr); if (!isOk) return false; @@ -74,6 +76,7 @@ bool dwgR::getPreview(std::istream &stream){ } else error = DRW::BAD_READ_METADATA; + filestr.close(); if (reader != NULL) { delete reader; reader = NULL; @@ -81,13 +84,70 @@ bool dwgR::getPreview(std::istream &stream){ return isOk; } -bool dwgR::read(std::istream &stream, DRW_Interface *interface_, bool ext){ +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; applyExt = ext; iface = interface_; - bool isOk = false; +//testReader();return false; - isOk = open(&stream); + std::ifstream filestr; + isOk = openFile(&filestr); if (!isOk) return false; @@ -101,6 +161,7 @@ bool dwgR::read(std::istream &stream, DRW_Interface *interface_, bool ext){ } else error = DRW::BAD_READ_METADATA; + filestr.close(); if (reader != NULL) { delete reader; reader = NULL; @@ -109,9 +170,23 @@ bool dwgR::read(std::istream &stream, DRW_Interface *interface_, bool ext){ return isOk; } -bool dwgR::open(std::istream *stream){ +/* 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; + } + char line[7]; - stream->read (line, 6); + filestr->read (line, 6); line[6]='\0'; DRW_DBG("dwgR::read 2\n"); DRW_DBG("dwgR::read line version: "); @@ -125,33 +200,35 @@ bool dwgR::open(std::istream *stream){ // reader = new dwgReader09(&filestr, this); }else if (strcmp(line, "AC1012") == 0){ version = DRW::AC1012; - reader = new dwgReader15(stream, this); + reader = new dwgReader15(filestr, this); } else if (strcmp(line, "AC1014") == 0) { version = DRW::AC1014; - reader = new dwgReader15(stream, this); + reader = new dwgReader15(filestr, this); } else if (strcmp(line, "AC1015") == 0) { version = DRW::AC1015; - reader = new dwgReader15(stream, this); + reader = new dwgReader15(filestr, this); } else if (strcmp(line, "AC1018") == 0){ version = DRW::AC1018; - reader = new dwgReader18(stream, this); + reader = new dwgReader18(filestr, this); } else if (strcmp(line, "AC1021") == 0) { version = DRW::AC1021; - reader = new dwgReader21(stream, this); + reader = new dwgReader21(filestr, this); } else if (strcmp(line, "AC1024") == 0) { version = DRW::AC1024; - reader = new dwgReader24(stream, this); + reader = new dwgReader24(filestr, this); } else if (strcmp(line, "AC1027") == 0) { version = DRW::AC1027; - reader = new dwgReader27(stream, this); + reader = new dwgReader27(filestr, this); } else version = DRW::UNKNOWNV; if (reader == NULL) { error = DRW::BAD_VERSION; - return false; - } - return true; + filestr->close(); + } else + isOk = true; + + return isOk; } /********* Reader Process *********/ diff --git a/src/libdwgr.h b/src/libdwgr.h index 0601004..8e035fe 100644 --- a/src/libdwgr.h +++ b/src/libdwgr.h @@ -24,17 +24,18 @@ class dwgReader; class dwgR { public: - dwgR(); + dwgR(const char* name); ~dwgR(); //read: return true if all ok - bool read(std::istream &stream, DRW_Interface *interface_, bool ext); - bool getPreview(std::istream &stream); + bool read(DRW_Interface *interface_, bool ext); + bool getPreview(); DRW::Version getVersion(){return version;} DRW::error getError(){return error;} +bool testReader(); void setDebug(DRW::DBG_LEVEL lvl); private: - bool open(std::istream *stream); + bool openFile(std::ifstream *filestr); bool processDwg(); private: DRW::Version version; diff --git a/src/libdxfrw.cpp b/src/libdxfrw.cpp index bc67c47..3dad7e3 100644 --- a/src/libdxfrw.cpp +++ b/src/libdxfrw.cpp @@ -32,8 +32,9 @@ secObjects };*/ -dxfRW::dxfRW(){ +dxfRW::dxfRW(const char* name){ DRW_DBGSL(DRW_dbg::NONE); + fileName = name; reader = NULL; writer = NULL; applyExt = false; @@ -60,46 +61,63 @@ void dxfRW::setDebug(DRW::DBG_LEVEL lvl){ } } -bool dxfRW::read(std::istream &stream, DRW_Interface *interface_, bool ext){ +bool dxfRW::read(DRW_Interface *interface_, bool ext){ + drw_assert(fileName.empty() == false); + bool isOk = false; applyExt = ext; - - if(interface_ == NULL) - return false; + std::ifstream filestr; + if ( interface_ == NULL ) + return isOk; + DRW_DBG("dxfRW::read 1def\n"); + filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary); + if (!filestr.is_open()) + return isOk; + if (!filestr.good()) + return isOk; char line[22]; char line2[22] = "AutoCAD Binary DXF\r\n"; line2[20] = (char)26; line2[21] = '\0'; - stream.read (line, 22); + filestr.read (line, 22); + filestr.close(); iface = interface_; DRW_DBG("dxfRW::read 2\n"); if (strcmp(line, line2) == 0) { + filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary); binFile = true; - reader = new dxfReaderBinary(&stream); + //skip sentinel + filestr.seekg (22, std::ios::beg); + reader = new dxfReaderBinary(&filestr); DRW_DBG("dxfRW::read binary file\n"); } else { binFile = false; - stream.seekg(0, std::ios::beg); - reader = new dxfReaderAscii(&stream); + filestr.open (fileName.c_str(), std::ios_base::in); + reader = new dxfReaderAscii(&filestr); } - bool isOk = processDxf(); + isOk = processDxf(); + filestr.close(); delete reader; reader = NULL; return isOk; } -bool dxfRW::write(std::ostream &stream, DRW_Interface *interface_, DRW::Version ver, bool bin){ +bool dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin){ + bool isOk = false; + std::ofstream filestr; version = ver; binFile = bin; iface = interface_; if (binFile) { + filestr.open (fileName.c_str(), std::ios_base::out | std::ios::binary | std::ios::trunc); //write sentinel - stream << "AutoCAD Binary DXF\r\n" << (char)26 << '\0'; - writer = new dxfWriterBinary(&stream); + filestr << "AutoCAD Binary DXF\r\n" << (char)26 << '\0'; + writer = new dxfWriterBinary(&filestr); DRW_DBG("dxfRW::read binary file\n"); } else { - writer = new dxfWriterAscii(&stream); + filestr.open (fileName.c_str(), std::ios_base::out | std::ios::trunc); + writer = new dxfWriterAscii(&filestr); std::string comm = std::string("dxfrw ") + std::string(DRW_VERSION); writer->writeString(999, comm); } @@ -135,10 +153,12 @@ bool dxfRW::write(std::ostream &stream, DRW_Interface *interface_, DRW::Version writer->writeString(0, "ENDSEC"); } writer->writeString(0, "EOF"); - stream.flush(); + filestr.flush(); + filestr.close(); + isOk = true; delete writer; writer = NULL; - return true; + return isOk; } bool dxfRW::writeEntity(DRW_Entity *ent) { @@ -384,15 +404,15 @@ bool dxfRW::writeDimstyle(DRW_Dimstyle *ent){ } else writer->writeUtf8Caps(2, ent->name); writer->writeInt16(70, ent->flags); - if ( version <= DRW::AC1009 || !(ent->dimpost.empty()) ) + if ( version == DRW::AC1009 || !(ent->dimpost.empty()) ) writer->writeUtf8String(3, ent->dimpost); - if ( version <= DRW::AC1009 || !(ent->dimapost.empty()) ) + if ( version == DRW::AC1009 || !(ent->dimapost.empty()) ) writer->writeUtf8String(4, ent->dimapost); - if ( version <= DRW::AC1009 || !(ent->dimblk.empty()) ) + if ( version == DRW::AC1009 || !(ent->dimblk.empty()) ) writer->writeUtf8String(5, ent->dimblk); - if ( version <= DRW::AC1009 || !(ent->dimblk1.empty()) ) + if ( version == DRW::AC1009 || !(ent->dimblk1.empty()) ) writer->writeUtf8String(6, ent->dimblk1); - if ( version <= DRW::AC1009 || !(ent->dimblk2.empty()) ) + if ( version == DRW::AC1009 || !(ent->dimblk2.empty()) ) writer->writeUtf8String(7, ent->dimblk2); writer->writeDouble(40, ent->dimscale); writer->writeDouble(41, ent->dimasz); @@ -469,10 +489,9 @@ bool dxfRW::writeDimstyle(DRW_Dimstyle *ent){ if (version > DRW::AC1014) { writer->writeInt16(289, ent->dimatfit); } - if ( version > DRW::AC1018 && ent->dimfxlon !=0 ) { + if ( version > DRW::AC1018 && ent->dimfxlon !=0 ) writer->writeInt16(290, ent->dimfxlon); - } - if (version > DRW::AC1009 && !ent->dimtxsty.empty()) { + if (version > DRW::AC1009) { writer->writeUtf8String(340, ent->dimtxsty); } if (version > DRW::AC1014) { @@ -716,7 +735,7 @@ bool dxfRW::writeLWPolyline(DRW_LWPolyline *ent){ if (version > DRW::AC1009) { writer->writeString(100, "AcDbPolyline"); } - ent->vertexnum = (int)ent->vertlist.size(); + ent->vertexnum = ent->vertlist.size(); writer->writeInt32(90, ent->vertexnum); writer->writeInt16(70, ent->flags); writer->writeDouble(43, ent->width); @@ -744,14 +763,11 @@ 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, "AcDb3dPolyline"); - is3d = true; - } else { + if (ent->flags & 8 || ent->flags & 16) writer->writeString(100, "AcDb2dPolyline"); - } + else + writer->writeString(100, "AcDb3dPolyline"); } else writer->writeInt16(66, 1); writer->writeDouble(10, 0.0); @@ -787,18 +803,13 @@ bool dxfRW::writePolyline(DRW_Polyline *ent) { writer->writeDouble(230, crd.z); } - size_t vertexnum = ent->vertlist.size(); - for (size_t i = 0; i < vertexnum; i++) { + int vertexnum = ent->vertlist.size(); + for (int 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); @@ -864,9 +875,6 @@ 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< 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); @@ -893,7 +901,7 @@ bool dxfRW::writeHatch(DRW_Hatch *ent){ writer->writeString(2, ent->name); writer->writeInt16(70, ent->solid); writer->writeInt16(71, ent->associative); - ent->loopsnum = (int)ent->looplist.size(); + ent->loopsnum = ent->looplist.size(); writer->writeInt16(91, ent->loopsnum); //write paths data for (int i = 0; i< ent->loopsnum; i++){ @@ -1023,8 +1031,6 @@ 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: @@ -1309,7 +1315,7 @@ bool dxfRW::writeBlock(DRW_Block *bk){ } writer->writeString(100, "AcDbEntity"); } - writer->writeString(8, bk->layer); + writer->writeString(8, "0"); if (version > DRW::AC1009) { writer->writeString(100, "AcDbBlockEnd"); } @@ -1324,7 +1330,7 @@ bool dxfRW::writeBlock(DRW_Block *bk){ } writer->writeString(100, "AcDbEntity"); } - writer->writeString(8, bk->layer); + writer->writeString(8, "0"); if (version > DRW::AC1009) { writer->writeString(100, "AcDbBlockBegin"); writer->writeUtf8String(2, bk->name); @@ -1428,7 +1434,7 @@ bool dxfRW::writeTables() { writer->writeInt16(72, 65); writer->writeInt16(73, 0); writer->writeDouble(40, 0.0); -//Application linetypes +//Aplication linetypes iface->writeLTypes(); writer->writeString(0, "ENDTAB"); /*** LAYER ***/ @@ -1444,7 +1450,7 @@ bool dxfRW::writeTables() { writer->writeInt16(70, 1); //end table def wlayer0 =false; iface->writeLayers(); - if (!wlayer0 && version > DRW::AC1009) { + if (!wlayer0) { DRW_Layer lay0; lay0.name = "0"; writeLayer(&lay0); @@ -1579,7 +1585,7 @@ bool dxfRW::writeTables() { writer->writeInt16(281, 0); } } - /* always call writeBlockRecords to iface for prepare unnamed blocks */ + /* allways call writeBlockRecords to iface for prepare unnamed blocks */ iface->writeBlockRecords(); if (version > DRW::AC1009) { writer->writeString(0, "ENDTAB"); diff --git a/src/libdxfrw.h b/src/libdxfrw.h index b3de272..18c2649 100644 --- a/src/libdxfrw.h +++ b/src/libdxfrw.h @@ -25,7 +25,7 @@ class dxfWriter; class dxfRW { public: - dxfRW(); + dxfRW(const char* name); ~dxfRW(); void setDebug(DRW::DBG_LEVEL lvl); /// reads the file specified in constructor @@ -36,10 +36,10 @@ class dxfRW { * @param ext should the extrusion be applied to convert in 2D? * @return true for success */ - bool read(std::istream &stream, DRW_Interface *interface_, bool ext); + bool read(DRW_Interface *interface_, bool ext); void setBinary(bool b) {binFile = b;} - bool write(std::ostream &stream, DRW_Interface *interface_, DRW::Version ver, bool bin); + bool write(DRW_Interface *interface_, DRW::Version ver, bool bin); bool writeLineType(DRW_LType *ent); bool writeLayer(DRW_Layer *ent); bool writeDimstyle(DRW_Dimstyle *ent);