diff -urp libdxfrw-0.5.7/src/drw_base.h libdxfrw-0.5.7.new/src/drw_base.h --- libdxfrw-0.5.7/src/drw_base.h 2012-09-03 11:01:23.000000000 -0400 +++ libdxfrw-0.5.7.new/src/drw_base.h 2013-04-14 16:37:18.000000000 -0400 @@ -13,6 +13,7 @@ #ifndef DRW_BASE_H #define DRW_BASE_H +#define DRW_VERSION "0.5.7" #include <string> #include <cmath> @@ -20,6 +21,7 @@ using std::string; #define UTF8STRING std::string +#define DRW_UNUSED(x) (void)x #if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) # define DRW_WIN @@ -31,9 +33,19 @@ using std::string; # define DRW_POSIX #endif +#ifndef M_PI + #define M_PI 3.141592653589793238462643 +#endif +#ifndef M_PI_2 + #define M_PI_2 1.57079632679489661923 +#endif +#define M_PIx2 6.283185307179586 // 2*PI +#define ARAD 57.29577951308232 + namespace DRW { //! Version numbers for the DXF Format. enum Version { + UNKNOWNV, /*!< UNKNOWN VERSION. */ AC1006, /*!< R10. */ AC1009, /*!< R11 & R12. */ AC1012, /*!< R13. */ @@ -44,6 +56,19 @@ enum Version { AC1024 /*!< ACAD 2010. */ }; +enum error { +BAD_NONE, /*!< No error. */ +BAD_UNKNOWN, /*!< UNKNOWN. */ +BAD_OPEN, /*!< error opening file. */ +BAD_VERSION, /*!< unsupported version. */ +BAD_READ_FILE_HEADER, /*!< error in file header read process. */ +BAD_READ_HEADER, /*!< error in header vars read process. */ +BAD_READ_OFFSETS, /*!< error in object map read process. */ +BAD_READ_CLASSES, /*!< error in classes read process. */ +BAD_READ_TABLES, /*!< error in tables read process. */ +BAD_READ_ENTITIES /*!< error in entities read process. */ +}; + } //! Class to handle 3D coordinate point @@ -161,6 +186,118 @@ private: }; +//! Class to convert between line width and integer +/*! +* Class to convert between line width and integer +* verifing valid values, if value is not valid +* returns widthDefault. +* @author Rallaz +*/ +class DRW_LW_Conv{ +public: + enum lineWidth { + width00 = 0, /*!< 0.00mm */ + width01 = 1, /*!< 0.05mm */ + width02 = 2, /*!< 0.09mm */ + width03 = 3, /*!< 0.13mm */ + width04 = 4, /*!< 0.15mm */ + width05 = 5, /*!< 0.18mm */ + width06 = 6, /*!< 0.20mm */ + width07 = 7, /*!< 0.25mm */ + width08 = 8, /*!< 0.30mm */ + width09 = 9, /*!< 0.35mm */ + width10 = 10, /*!< 0.40mm */ + width11 = 11, /*!< 0.50mm */ + width12 = 12, /*!< 0.53mm */ + width13 = 13, /*!< 0.60mm */ + width14 = 14, /*!< 0.70mm */ + width15 = 15, /*!< 0.80mm */ + width16 = 16, /*!< 0.90mm */ + width17 = 17, /*!< 1.00mm */ + width18 = 18, /*!< 1.06mm */ + width19 = 19, /*!< 1.20mm */ + width20 = 20, /*!< 1.40mm */ + width21 = 21, /*!< 1.58mm */ + width22 = 22, /*!< 2.00mm */ + width23 = 23, /*!< 2.11mm */ + widthByLayer = 29, /*!< by layer (dxf -1) */ + widthByBlock = 30, /*!< by block (dxf -2) */ + widthDefault = 31 /*!< by default (dxf -3) */ + }; + + static int lineWidth2int(enum lineWidth lw){ + return static_cast<int> (lw); + } + + static enum lineWidth dxfInt2lineWidth(int i){ + if (i<0) { + if (i==-1) + return widthByLayer; + else if (i==-2) + return widthByBlock; + else if (i==-3) + return widthDefault; + } else if (i<3) { + return width00; + } else if (i<7) { + return width01; + } else if (i<11) { + return width02; + } else if (i<14) { + return width03; + } else if (i<16) { + return width04; + } else if (i<19) { + return width05; + } else if (i<22) { + return width06; + } else if (i<27) { + return width07; + } else if (i<32) { + return width08; + } else if (i<37) { + return width09; + } else if (i<45) { + return width10; + } else if (i<52) { + return width11; + } else if (i<57) { + return width12; + } else if (i<65) { + return width13; + } else if (i<75) { + return width14; + } else if (i<85) { + return width15; + } else if (i<95) { + return width16; + } else if (i<103) { + return width17; + } else if (i<112) { + return width18; + } else if (i<130) { + return width19; + } else if (i<149) { + return width20; + } else if (i<180) { + return width21; + } else if (i<205) { + return width22; + } else { + return width23; + } + //default by default + return widthDefault; + } + + static enum lineWidth dwgInt2lineWidth(int i){ + if ( (i>-1 && i<24) || (i>28 && i<32) ) { + return static_cast<lineWidth> (i); + } + //default by default + return widthDefault; + } +}; #endif diff -urp libdxfrw-0.5.7/src/drw_entities.cpp libdxfrw-0.5.7.new/src/drw_entities.cpp --- libdxfrw-0.5.7/src/drw_entities.cpp 2013-02-19 10:36:29.000000000 -0500 +++ libdxfrw-0.5.7.new/src/drw_entities.cpp 2013-04-14 16:37:18.000000000 -0400 @@ -17,7 +17,7 @@ //! Calculate arbitary axis /*! -* Calculate arbitary axis for aplly extrusions +* Calculate arbitary axis for apply extrusions * @author Rallaz */ void DRW_Entity::calculateAxis(DRW_Coord extPoint){ @@ -70,9 +70,7 @@ void DRW_Entity::parseCode(int code, dxf color = reader->getInt32(); break; case 370: -// lWeight = (DRW::LWEIGHT)reader->getInt32(); -//RLZ: TODO as integer or enum?? - lWeight = reader->getInt32(); + lWeight = DRW_LW_Conv::dxfInt2lineWidth(reader->getInt32()); break; case 48: ltypeScale = reader->getDouble(); @@ -162,10 +160,10 @@ void DRW_Circle::parseCode(int code, dxf void DRW_Arc::parseCode(int code, dxfReader *reader){ switch (code) { case 50: - staangle = reader->getDouble(); + staangle = reader->getDouble()/ ARAD; break; case 51: - endangle = reader->getDouble(); + endangle = reader->getDouble()/ ARAD; break; default: DRW_Circle::parseCode(code, reader); @@ -190,6 +188,32 @@ void DRW_Ellipse::parseCode(int code, dx } } +//if ratio > 1 minor axis are greather than major axis, correct it +void DRW_Ellipse::correctAxis(){ + bool complete = false; + if (staparam == endparam) { + staparam = 0.0; + endparam = M_PIx2; //2*M_PI; + complete = true; + } + if (ratio > 1){ + if ( fabs(endparam - staparam - M_PIx2) < 1.0e-10) + complete = true; + double incX = secPoint.x; + secPoint.x = -(secPoint.y * ratio); + secPoint.y = incX*ratio; + ratio = 1/ratio; + if (!complete){ + if (staparam < M_PI_2) + staparam += M_PI *2; + if (endparam < M_PI_2) + endparam += M_PI *2; + endparam -= M_PI_2; + staparam -= M_PI_2; + } + } +} + void DRW_Ellipse::toPolyline(DRW_Polyline *pol){ double radMajor, radMinor, cosRot, sinRot, incAngle, curAngle; double cosCurr, sinCurr; @@ -213,7 +237,7 @@ void DRW_Ellipse::toPolyline(DRW_Polylin pol->addVertex( DRW_Vertex(x, y, 0.0, 0.0)); curAngle = (++i)*incAngle; } while (i<128); - if ( fabs(endparam - 6.28318530718) < 1.0e-10){ + if ( fabs(endparam - staparam - M_PIx2) < 1.0e-10){ pol->flags = 1; } pol->layer = this->layer; @@ -361,6 +385,9 @@ void DRW_LWPolyline::parseCode(int code, case 38: elevation = reader->getDouble(); break; + case 39: + thickness = reader->getDouble(); + break; case 43: width = reader->getDouble(); break; @@ -574,12 +601,12 @@ void DRW_Hatch::parseCode(int code, dxfR if (plvert) plvert ->bulge = reader->getDouble(); break; case 50: - if (arc) arc->staangle = reader->getDouble(); - else if (ellipse) ellipse->staparam = reader->getDouble(); + if (arc) arc->staangle = reader->getDouble()/ARAD; + else if (ellipse) ellipse->staparam = reader->getDouble()/ARAD; break; case 51: - if (arc) arc->endangle = reader->getDouble(); - else if (ellipse) ellipse->endparam = reader->getDouble(); + if (arc) arc->endangle = reader->getDouble()/ARAD; + else if (ellipse) ellipse->endparam = reader->getDouble()/ARAD; break; case 52: angle = reader->getDouble(); diff -urp libdxfrw-0.5.7/src/drw_entities.h libdxfrw-0.5.7.new/src/drw_entities.h --- libdxfrw-0.5.7/src/drw_entities.h 2013-02-19 10:36:29.000000000 -0500 +++ libdxfrw-0.5.7.new/src/drw_entities.h 2013-04-14 16:37:18.000000000 -0400 @@ -62,17 +62,6 @@ namespace DRW { UNKNOWN }; - enum LWEIGHT { - L0=0, - L1, - L2, - L3, - L4, - L5, - L6, - L7 - }; - } //! Base class for entities @@ -90,10 +79,12 @@ public: ltypeScale = 1.0; visible = true; layer = "0"; - lWeight = -1; // default BYLAYER (-1) - space = 0; // default ModelSpace (0) + lWeight = DRW_LW_Conv::widthByLayer; // default BYLAYER (dxf -1, dwg 29) + handleBlock = space = 0; // default ModelSpace (0) & handleBlock = no handle (0) haveExtrusion = false; + color24 = -1; //default -1 not set } + virtual~DRW_Entity() {} DRW_Entity(const DRW_Entity& d) { eType = d.eType; @@ -124,14 +115,12 @@ public: UTF8STRING layer; /*!< layer name, code 8 */ UTF8STRING lineType; /*!< line type, code 6 */ int color; /*!< entity color, code 62 */ - //RLZ: TODO as integer or enum?? - int lWeight; /*!< entity lineweight, code 370 */ -// enum DRW::LWEIGHT lWeight; /*!< entity lineweight, code 370 */ + enum DRW_LW_Conv::lineWidth lWeight; /*!< entity lineweight, code 370 */ double ltypeScale; /*!< linetype scale, code 48 */ bool visible; /*!< entity visibility, code 60 */ int color24; /*!< 24-bit color, code 420 */ string colorName; /*!< color name, code 430 */ - int space; /*!< space indicator 0 = model, 1 paper , code 67*/ + int space; /*!< space indicator 0 = model, 1 paper, code 67*/ bool haveExtrusion; /*!< set to true if the entity have extrusion*/ private: DRW_Coord extAxisX; @@ -240,8 +229,8 @@ public: void parseCode(int code, dxfReader *reader); public: - double staangle; /*!< x coordinate, code 50 */ - double endangle; /*!< x coordinate, code 51 */ + double staangle; /*!< start angle, code 50 in radians*/ + double endangle; /*!< end angle, code 51 in radians */ int isccw; /*!< is counter clockwise arc?, only used in hatch, code 73 */ }; @@ -261,6 +250,7 @@ public: void parseCode(int code, dxfReader *reader); void toPolyline(DRW_Polyline *pol); + void correctAxis(); public: double ratio; /*!< ratio, code 40 */ double staparam; /*!< start parameter, code 41, 0.0 for full ellipse*/ @@ -369,7 +359,7 @@ public: void parseCode(int code, dxfReader *reader); public: - UTF8STRING name; /*!< block name, code 2 */ + UTF8STRING name; /*!< block name, code 2 */ double xscale; /*!< x scale factor, code 41 */ double yscale; /*!< y scale factor, code 42 */ double zscale; /*!< z scale factor, code 43 */ @@ -389,8 +379,8 @@ class DRW_LWPolyline : public DRW_Entity public: DRW_LWPolyline() { eType = DRW::LWPOLYLINE; - width = 0; - elevation = flags = 0; + elevation = thickness = width = 0.0; + flags = 0; extPoint.x = extPoint.y = 0; extPoint.z = 1; vertex = NULL; @@ -426,6 +416,7 @@ public: int flags; /*!< polyline flag, code 70, default 0 */ double width; /*!< constant width, code 43 */ double elevation; /*!< elevation, code 38 */ + double thickness; /*!< thickness, code 39 */ DRW_Coord extPoint; /*!< Dir extrusion normal vector, code 210, 220 & 230 */ DRW_Vertex2D *vertex; /*!< current vertex to add data */ std::vector<DRW_Vertex2D *> vertlist; /*!< vertex list */ @@ -476,7 +467,7 @@ public: double angle; /*!< rotation angle in degrees (360), code 50 */ double widthscale; /*!< width factor, code 41 */ double oblique; /*!< oblique angle, code 51 */ - UTF8STRING style; /*!< stile name, code 7 */ + UTF8STRING style; /*!< style name, code 7 */ int textgen; /*!< text generation, code 71 */ enum HAlign alignH; /*!< horizontal align, code 72 */ enum VAlign alignV; /*!< vertical align, code 73 */ diff -urp libdxfrw-0.5.7/src/drw_interface.h libdxfrw-0.5.7.new/src/drw_interface.h --- libdxfrw-0.5.7/src/drw_interface.h 2012-09-03 11:01:23.000000000 -0400 +++ libdxfrw-0.5.7.new/src/drw_interface.h 2013-04-14 16:37:18.000000000 -0400 @@ -52,11 +52,20 @@ public: /** * Called for every block. Note: all entities added after this * command go into this block until endBlock() is called. - * + * * @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; + /** Called to end the current block */ virtual void endBlock() = 0; diff -urp libdxfrw-0.5.7/src/drw_objects.cpp libdxfrw-0.5.7.new/src/drw_objects.cpp --- libdxfrw-0.5.7/src/drw_objects.cpp 2013-02-19 10:36:29.000000000 -0500 +++ libdxfrw-0.5.7.new/src/drw_objects.cpp 2013-04-14 16:37:18.000000000 -0400 @@ -319,7 +319,7 @@ void DRW_Layer::parseCode(int code, dxfR plotF = reader->getBool(); break; case 370: - lWeight = reader->getInt32(); + lWeight = DRW_LW_Conv::dxfInt2lineWidth(reader->getInt32()); break; case 390: handlePlotS = reader->getString(); @@ -327,6 +327,9 @@ void DRW_Layer::parseCode(int code, dxfR case 347: handlePlotM = reader->getString(); break; + case 420: + color24 = reader->getInt32(); + break; default: DRW_TableEntry::parseCode(code, reader); break; diff -urp libdxfrw-0.5.7/src/drw_objects.h libdxfrw-0.5.7.new/src/drw_objects.h --- libdxfrw-0.5.7/src/drw_objects.h 2013-02-19 10:36:29.000000000 -0500 +++ libdxfrw-0.5.7.new/src/drw_objects.h 2013-04-14 16:37:18.000000000 -0400 @@ -52,6 +52,7 @@ public: tType = DRW::UNKNOWNT; flags = 0; } + virtual~DRW_TableEntry() {} protected: void parseCode(int code, dxfReader *reader); @@ -223,7 +224,8 @@ public: lineType = "CONTINUOUS"; color = 7; // default BYLAYER (256) plotF = true; // default TRUE (plot yes) - lWeight = -3; // default BYDEFAULT (-3) + lWeight = DRW_LW_Conv::widthDefault; // default BYDEFAULT (dxf -3, dwg 31) + color24 = -1; //default -1 not set } void parseCode(int code, dxfReader *reader); @@ -231,8 +233,9 @@ public: public: UTF8STRING lineType; /*!< line type, code 6 */ int color; /*!< layer color, code 62 */ + int color24; /*!< 24-bit color, code 420 */ bool plotF; /*!< Plot flag, code 290 */ - int lWeight; /*!< layer lineweight, code 370 */ + enum DRW_LW_Conv::lineWidth lWeight; /*!< layer lineweight, code 370 */ string handlePlotS; /*!< Hard-pointer ID/handle of plotstyle, code 390 */ string handlePlotM; /*!< Hard-pointer ID/handle of materialstyle, code 347 */ }; @@ -396,264 +399,265 @@ namespace DRW { // Extended color palette: // The first entry is only for direct indexing starting with [1] // Color 1 is red (1,0,0) -const double dxfColors[][3] = { - {0,0,0}, // unused - {1,0,0}, // 1 red - {1,1,0}, // 2 yellow - {0,1,0}, // 3 green - {0,1,1}, - {0,0,1}, - {1,0,1}, - {1,1,1}, // black or white - {0.5,0.5,0.5}, - {0.75,0.75,0.75}, - {1,0,0}, // 10 - {1,0.5,0.5}, - {0.65,0,0}, - {0.65,0.325,0.325}, - {0.5,0,0}, - {0.5,0.25,0.25}, - {0.3,0,0}, - {0.3,0.15,0.15}, - {0.15,0,0}, - {0.15,0.075,0.075}, - {1,0.25,0}, // 20 - {1,0.625,0.5}, - {0.65,0.1625,0}, - {0.65,0.4063,0.325}, - {0.5,0.125,0}, - {0.5,0.3125,0.25}, - {0.3,0.075,0}, - {0.3,0.1875,0.15}, - {0.15,0.0375,0}, - {0.15,0.0938,0.075}, - {1,0.5,0}, // 30 - {1,0.75,0.5}, - {0.65,0.325,0}, - {0.65,0.4875,0.325}, - {0.5,0.25,0}, - {0.5,0.375,0.25}, - {0.3,0.15,0}, - {0.3,0.225,0.15}, - {0.15,0.075,0}, - {0.15,0.1125,0.075}, - {1,0.75,0}, // 40 - {1,0.875,0.5}, - {0.65,0.4875,0}, - {0.65,0.5688,0.325}, - {0.5,0.375,0}, - {0.5,0.4375,0.25}, - {0.3,0.225,0}, - {0.3,0.2625,0.15}, - {0.15,0.1125,0}, - {0.15,0.1313,0.075}, - {1,1,0}, // 50 - {1,1,0.5}, - {0.65,0.65,0}, - {0.65,0.65,0.325}, - {0.5,0.5,0}, - {0.5,0.5,0.25}, - {0.3,0.3,0}, - {0.3,0.3,0.15}, - {0.15,0.15,0}, - {0.15,0.15,0.075}, - {0.75,1,0}, // 60 - {0.875,1,0.5}, - {0.4875,0.65,0}, - {0.5688,0.65,0.325}, - {0.375,0.5,0}, - {0.4375,0.5,0.25}, - {0.225,0.3,0}, - {0.2625,0.3,0.15}, - {0.1125,0.15,0}, - {0.1313,0.15,0.075}, - {0.5,1,0}, // 70 - {0.75,1,0.5}, - {0.325,0.65,0}, - {0.4875,0.65,0.325}, - {0.25,0.5,0}, - {0.375,0.5,0.25}, - {0.15,0.3,0}, - {0.225,0.3,0.15}, - {0.075,0.15,0}, - {0.1125,0.15,0.075}, - {0.25,1,0}, // 80 - {0.625,1,0.5}, - {0.1625,0.65,0}, - {0.4063,0.65,0.325}, - {0.125,0.5,0}, - {0.3125,0.5,0.25}, - {0.075,0.3,0}, - {0.1875,0.3,0.15}, - {0.0375,0.15,0}, - {0.0938,0.15,0.075}, - {0,1,0}, // 90 - {0.5,1,0.5}, - {0,0.65,0}, - {0.325,0.65,0.325}, - {0,0.5,0}, - {0.25,0.5,0.25}, - {0,0.3,0}, - {0.15,0.3,0.15}, - {0,0.15,0}, - {0.075,0.15,0.075}, - {0,1,0.25}, // 100 - {0.5,1,0.625}, - {0,0.65,0.1625}, - {0.325,0.65,0.4063}, - {0,0.5,0.125}, - {0.25,0.5,0.3125}, - {0,0.3,0.075}, - {0.15,0.3,0.1875}, - {0,0.15,0.0375}, - {0.075,0.15,0.0938}, - {0,1,0.5}, // 110 - {0.5,1,0.75}, - {0,0.65,0.325}, - {0.325,0.65,0.4875}, - {0,0.5,0.25}, - {0.25,0.5,0.375}, - {0,0.3,0.15}, - {0.15,0.3,0.225}, - {0,0.15,0.075}, - {0.075,0.15,0.1125}, - {0,1,0.75}, // 120 - {0.5,1,0.875}, - {0,0.65,0.4875}, - {0.325,0.65,0.5688}, - {0,0.5,0.375}, - {0.25,0.5,0.4375}, - {0,0.3,0.225}, - {0.15,0.3,0.2625}, - {0,0.15,0.1125}, - {0.075,0.15,0.1313}, - {0,1,1}, // 130 - {0.5,1,1}, - {0,0.65,0.65}, - {0.325,0.65,0.65}, - {0,0.5,0.5}, - {0.25,0.5,0.5}, - {0,0.3,0.3}, - {0.15,0.3,0.3}, - {0,0.15,0.15}, - {0.075,0.15,0.15}, - {0,0.75,1}, // 140 - {0.5,0.875,1}, - {0,0.4875,0.65}, - {0.325,0.5688,0.65}, - {0,0.375,0.5}, - {0.25,0.4375,0.5}, - {0,0.225,0.3}, - {0.15,0.2625,0.3}, - {0,0.1125,0.15}, - {0.075,0.1313,0.15}, - {0,0.5,1}, // 150 - {0.5,0.75,1}, - {0,0.325,0.65}, - {0.325,0.4875,0.65}, - {0,0.25,0.5}, - {0.25,0.375,0.5}, - {0,0.15,0.3}, - {0.15,0.225,0.3}, - {0,0.075,0.15}, - {0.075,0.1125,0.15}, - {0,0.25,1}, // 160 - {0.5,0.625,1}, - {0,0.1625,0.65}, - {0.325,0.4063,0.65}, - {0,0.125,0.5}, - {0.25,0.3125,0.5}, - {0,0.075,0.3}, - {0.15,0.1875,0.3}, - {0,0.0375,0.15}, - {0.075,0.0938,0.15}, - {0,0,1}, // 170 - {0.5,0.5,1}, - {0,0,0.65}, - {0.325,0.325,0.65}, - {0,0,0.5}, - {0.25,0.25,0.5}, - {0,0,0.3}, - {0.15,0.15,0.3}, - {0,0,0.15}, - {0.075,0.075,0.15}, - {0.25,0,1}, // 180 - {0.625,0.5,1}, - {0.1625,0,0.65}, - {0.4063,0.325,0.65}, - {0.125,0,0.5}, - {0.3125,0.25,0.5}, - {0.075,0,0.3}, - {0.1875,0.15,0.3}, - {0.0375,0,0.15}, - {0.0938,0.075,0.15}, - {0.5,0,1}, // 190 - {0.75,0.5,1}, - {0.325,0,0.65}, - {0.4875,0.325,0.65}, - {0.25,0,0.5}, - {0.375,0.25,0.5}, - {0.15,0,0.3}, - {0.225,0.15,0.3}, - {0.075,0,0.15}, - {0.1125,0.075,0.15}, - {0.75,0,1}, // 200 - {0.875,0.5,1}, - {0.4875,0,0.65}, - {0.5688,0.325,0.65}, - {0.375,0,0.5}, - {0.4375,0.25,0.5}, - {0.225,0,0.3}, - {0.2625,0.15,0.3}, - {0.1125,0,0.15}, - {0.1313,0.075,0.15}, - {1,0,1}, // 210 - {1,0.5,1}, - {0.65,0,0.65}, - {0.65,0.325,0.65}, - {0.5,0,0.5}, - {0.5,0.25,0.5}, - {0.3,0,0.3}, - {0.3,0.15,0.3}, - {0.15,0,0.15}, - {0.15,0.075,0.15}, - {1,0,0.75}, // 220 - {1,0.5,0.875}, - {0.65,0,0.4875}, - {0.65,0.325,0.5688}, - {0.5,0,0.375}, - {0.5,0.25,0.4375}, - {0.3,0,0.225}, - {0.3,0.15,0.2625}, - {0.15,0,0.1125}, - {0.15,0.075,0.1313}, - {1,0,0.5}, // 230 - {1,0.5,0.75}, - {0.65,0,0.325}, - {0.65,0.325,0.4875}, - {0.5,0,0.25}, - {0.5,0.25,0.375}, - {0.3,0,0.15}, - {0.3,0.15,0.225}, - {0.15,0,0.075}, - {0.15,0.075,0.1125}, - {1,0,0.25}, // 240 - {1,0.5,0.625}, - {0.65,0,0.1625}, - {0.65,0.325,0.4063}, - {0.5,0,0.125}, - {0.5,0.25,0.3125}, - {0.3,0,0.075}, - {0.3,0.15,0.1875}, - {0.15,0,0.0375}, - {0.15,0.075,0.0938}, - {0.33,0.33,0.33}, // 250 - {0.464,0.464,0.464}, - {0.598,0.598,0.598}, - {0.732,0.732,0.732}, - {0.866,0.866,0.866}, - {1,1,1} // 255 - } ; +const unsigned char dxfColors[][3] = { + { 0, 0, 0}, // unused + {255, 0, 0}, // 1 red + {255,255, 0}, // 2 yellow + { 0,255, 0}, // 3 green + { 0,255,255}, // 4 cyan + { 0, 0,255}, // 5 blue + {255, 0,255}, // 6 magenta + { 0, 0, 0}, // 7 black or white + {128,128,128}, // 8 50% gray + {192,192,192}, // 9 75% gray + {255, 0, 0}, // 10 + {255,127,127}, + {204, 0, 0}, + {204,102,102}, + {153, 0, 0}, + {153, 76, 76}, // 15 + {127, 0, 0}, + {127, 63, 63}, + { 76, 0, 0}, + { 76, 38, 38}, + {255, 63, 0}, // 20 + {255,159,127}, + {204, 51, 0}, + {204,127,102}, + {153, 38, 0}, + {153, 95, 76}, // 25 + {127, 31, 0}, + {127, 79, 63}, + { 76, 19, 0}, + { 76, 47, 38}, + {255,127, 0}, // 30 + {255,191,127}, + {204,102, 0}, + {204,153,102}, + {153, 76, 0}, + {153,114, 76}, // 35 + {127, 63, 0}, + {127, 95, 63}, + { 76, 38, 0}, + { 76, 57, 38}, + {255,191, 0}, // 40 + {255,223,127}, + {204,153, 0}, + {204,178,102}, + {153,114, 0}, + {153,133, 76}, // 45 + {127, 95, 0}, + {127,111, 63}, + { 76, 57, 0}, + { 76, 66, 38}, + {255,255, 0}, // 50 + {255,255,127}, + {204,204, 0}, + {204,204,102}, + {153,153, 0}, + {153,153, 76}, // 55 + {127,127, 0}, + {127,127, 63}, + { 76, 76, 0}, + { 76, 76, 38}, + {191,255, 0}, // 60 + {223,255,127}, + {153,204, 0}, + {178,204,102}, + {114,153, 0}, + {133,153, 76}, // 65 + { 95,127, 0}, + {111,127, 63}, + { 57, 76, 0}, + { 66, 76, 38}, + {127,255, 0}, // 70 + {191,255,127}, + {102,204, 0}, + {153,204,102}, + { 76,153, 0}, + {114,153, 76}, // 75 + { 63,127, 0}, + { 95,127, 63}, + { 38, 76, 0}, + { 57, 76, 38}, + { 63,255, 0}, // 80 + {159,255,127}, + { 51,204, 0}, + {127,204,102}, + { 38,153, 0}, + { 95,153, 76}, // 85 + { 31,127, 0}, + { 79,127, 63}, + { 19, 76, 0}, + { 47, 76, 38}, + { 0,255, 0}, // 90 + {127,255,127}, + { 0,204, 0}, + {102,204,102}, + { 0,153, 0}, + { 76,153, 76}, // 95 + { 0,127, 0}, + { 63,127, 63}, + { 0, 76, 0}, + { 38, 76, 38}, + { 0,255, 63}, // 100 + {127,255,159}, + { 0,204, 51}, + {102,204,127}, + { 0,153, 38}, + { 76,153, 95}, // 105 + { 0,127, 31}, + { 63,127, 79}, + { 0, 76, 19}, + { 38, 76, 47}, + { 0,255,127}, // 110 + {127,255,191}, + { 0,204,102}, + {102,204,153}, + { 0,153, 76}, + { 76,153,114}, // 115 + { 0,127, 63}, + { 63,127, 95}, + { 0, 76, 38}, + { 38, 76, 57}, + { 0,255,191}, // 120 + {127,255,223}, + { 0,204,153}, + {102,204,178}, + { 0,153,114}, + { 76,153,133}, // 125 + { 0,127, 95}, + { 63,127,111}, + { 0, 76, 57}, + { 38, 76, 66}, + { 0,255,255}, // 130 + {127,255,255}, + { 0,204,204}, + {102,204,204}, + { 0,153,153}, + { 76,153,153}, // 135 + { 0,127,127}, + { 63,127,127}, + { 0, 76, 76}, + { 38, 76, 76}, + { 0,191,255}, // 140 + {127,223,255}, + { 0,153,204}, + {102,178,204}, + { 0,114,153}, + { 76,133,153}, // 145 + { 0, 95,127}, + { 63,111,127}, + { 0, 57, 76}, + { 38, 66, 76}, + { 0,127,255}, // 150 + {127,191,255}, + { 0,102,204}, + {102,153,204}, + { 0, 76,153}, + { 76,114,153}, // 155 + { 0, 63,127}, + { 63, 95,127}, + { 0, 38, 76}, + { 38, 57, 76}, + { 0, 66,255}, // 160 + {127,159,255}, + { 0, 51,204}, + {102,127,204}, + { 0, 38,153}, + { 76, 95,153}, // 165 + { 0, 31,127}, + { 63, 79,127}, + { 0, 19, 76}, + { 38, 47, 76}, + { 0, 0,255}, // 170 + {127,127,255}, + { 0, 0,204}, + {102,102,204}, + { 0, 0,153}, + { 76, 76,153}, // 175 + { 0, 0,127}, + { 63, 63,127}, + { 0, 0, 76}, + { 38, 38, 76}, + { 63, 0,255}, // 180 + {159,127,255}, + { 50, 0,204}, + {127,102,204}, + { 38, 0,153}, + { 95, 76,153}, // 185 + { 31, 0,127}, + { 79, 63,127}, + { 19, 0, 76}, + { 47, 38, 76}, + {127, 0,255}, // 190 + {191,127,255}, + {102, 0,204}, + {153,102,204}, + { 76, 0,153}, + {114, 76,153}, // 195 + { 63, 0,127}, + { 95, 63,127}, + { 38, 0, 76}, + { 57, 38, 76}, + {191, 0,255}, // 200 + {223,127,255}, + {153, 0,204}, + {178,102,204}, + {114, 0,153}, + {133, 76,153}, // 205 + { 95, 0,127}, + {111, 63,127}, + { 57, 0, 76}, + { 66, 38, 76}, + {255, 0,255}, // 210 + {255,127,255}, + {204, 0,204}, + {204,102,204}, + {153, 0,153}, + {153, 76,153}, // 215 + {127, 0,127}, + {127, 63,127}, + { 76, 0, 76}, + { 76, 38, 76}, + {255, 0,191}, // 220 + {255,127,223}, + {204, 0,153}, + {204,102,178}, + {153, 0,114}, + {153, 76,133}, // 225 + {127, 0, 95}, + {127, 63, 11}, + { 76, 0, 57}, + { 76, 38, 66}, + {255, 0,127}, // 230 + {255,127,191}, + {204, 0,102}, + {204,102,153}, + {153, 0, 76}, + {153, 76,114}, // 235 + {127, 0, 63}, + {127, 63, 95}, + { 76, 0, 38}, + { 76, 38, 57}, + {255, 0, 63}, // 240 + {255,127,159}, + {204, 0, 51}, + {204,102,127}, + {153, 0, 38}, + {153, 76, 95}, // 245 + {127, 0, 31}, + {127, 63, 79}, + { 76, 0, 19}, + { 76, 38, 47}, + { 51, 51, 51}, // 250 + { 91, 91, 91}, + {132,132,132}, + {173,173,173}, + {214,214,214}, + {255,255,255} // 255 +}; + } #endif diff -urp libdxfrw-0.5.7/src/drw_textcodec.cpp libdxfrw-0.5.7.new/src/drw_textcodec.cpp --- libdxfrw-0.5.7/src/drw_textcodec.cpp 2013-02-18 14:51:41.000000000 -0500 +++ libdxfrw-0.5.7.new/src/drw_textcodec.cpp 2013-04-14 16:37:18.000000000 -0400 @@ -181,9 +181,15 @@ std::string DRW_Converter::encodeText(st std::string DRW_Converter::decodeText(int c){ std::string res = "\\U+"; std::string num; +#if defined(__APPLE__) + char str [16]; + sprintf ( str, "%04X", c ); + num = str; +#else std::stringstream ss; ss << std::uppercase << std::setfill('0') << std::setw(4) << std::hex << c; ss >> num; +#endif res += num; return res; } diff -urp libdxfrw-0.5.7/src/drw_textcodec.h libdxfrw-0.5.7.new/src/drw_textcodec.h --- libdxfrw-0.5.7/src/drw_textcodec.h 2013-02-18 14:51:41.000000000 -0500 +++ libdxfrw-0.5.7.new/src/drw_textcodec.h 2013-04-14 16:37:18.000000000 -0400 @@ -14,7 +14,9 @@ public: std::string toUtf8(std::string s); int getVersion(){return version;} void setVersion(std::string *v); + void setVersion(int v){version = v;} void setCodePage(std::string *c); + void setCodePage(std::string c){setCodePage(&c);} std::string getCodePage(){return cp;} private: diff -urp libdxfrw-0.5.7/src/libdxfrw.cpp libdxfrw-0.5.7.new/src/libdxfrw.cpp --- libdxfrw-0.5.7/src/libdxfrw.cpp 2013-02-19 10:36:29.000000000 -0500 +++ libdxfrw-0.5.7.new/src/libdxfrw.cpp 2013-04-14 16:37:18.000000000 -0400 @@ -18,9 +18,7 @@ #include "drw_textcodec.h" #include "dxfreader.h" #include "dxfwriter.h" - - -using namespace std; +#include <assert.h> #ifdef DRW_DBG #include <iostream> //for debug @@ -53,11 +51,14 @@ dxfRW::~dxfRW(){ } bool dxfRW::read(DRW_Interface *interface_, bool ext){ + assert(fileName.empty() == false); bool isOk = false; applyExt = ext; - ifstream filestr; + std::ifstream filestr; + if ( interface_ == NULL ) + return isOk; DBG("dxfRW::read 1def\n"); - filestr.open (fileName.c_str(), ios_base::in | ios::binary); + filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary); if (!filestr.is_open()) return isOk; if (!filestr.good()) @@ -72,15 +73,15 @@ bool dxfRW::read(DRW_Interface *interfac iface = interface_; DBG("dxfRW::read 2\n"); if (strcmp(line, line2) == 0) { - filestr.open (fileName.c_str(), ios_base::in | ios::binary); + filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary); binary = true; //skip sentinel - filestr.seekg (22, ios::beg); + filestr.seekg (22, std::ios::beg); reader = new dxfReaderBinary(&filestr); DBG("dxfRW::read binary file\n"); } else { binary = false; - filestr.open (fileName.c_str(), ios_base::in); + filestr.open (fileName.c_str(), std::ios_base::in); reader = new dxfReaderAscii(&filestr); } @@ -93,18 +94,18 @@ bool dxfRW::read(DRW_Interface *interfac bool dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin){ bool isOk = false; - ofstream filestr; + std::ofstream filestr; version = ver; binary = bin; iface = interface_; if (binary) { - filestr.open (fileName.c_str(), ios_base::out | ios::binary | ios::trunc); + filestr.open (fileName.c_str(), std::ios_base::out | std::ios::binary | std::ios::trunc); //write sentinel filestr << "AutoCAD Binary DXF\r\n" << (char)26 << '\0'; writer = new dxfWriterBinary(&filestr); DBG("dxfRW::read binary file\n"); } else { - filestr.open (fileName.c_str(), ios_base::out | ios::trunc); + 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); @@ -163,6 +164,9 @@ bool dxfRW::writeEntity(DRW_Entity *ent) writer->writeUtf8Caps(6, ent->lineType); } writer->writeInt16(62, ent->color); + if (version > DRW::AC1015 && ent->color24 >= 0) { + writer->writeInt32(420, ent->color24); + } if (version > DRW::AC1014) { writer->writeInt16(370, ent->lWeight); } @@ -228,6 +232,9 @@ bool dxfRW::writeLayer(DRW_Layer *ent){ } writer->writeInt16(70, ent->flags); writer->writeInt16(62, ent->color); + if (version > DRW::AC1015 && ent->color24 >= 0) { + writer->writeInt32(420, ent->color24); + } if (version > DRW::AC1009) { writer->writeUtf8String(6, ent->lineType); if (! ent->plotF) @@ -243,10 +250,9 @@ bool dxfRW::writeLayer(DRW_Layer *ent){ bool dxfRW::writeTextstyle(DRW_Textstyle *ent){ writer->writeString(0, "STYLE"); if (!dimstyleStd) { - std::string name; - std::stringstream ss; - ss << std::uppercase << ent->name; - ss >> name; + //stringstream cause crash in OS/X, bug#3597944 + std::string name=ent->name; + transform(name.begin(), name.end(), name.begin(), toupper); if (name == "STANDARD") dimstyleStd = true; } @@ -584,14 +590,14 @@ bool dxfRW::writeArc(DRW_Arc *ent) { if (version > DRW::AC1009) { writer->writeString(100, "AcDbArc"); } - writer->writeDouble(50, ent->staangle); - writer->writeDouble(51, ent->endangle); + writer->writeDouble(50, ent->staangle*ARAD); + writer->writeDouble(51, ent->endangle*ARAD); return true; } bool dxfRW::writeEllipse(DRW_Ellipse *ent){ - if (ent->staparam == ent->endparam) - ent->endparam = 6.28318530718; //2*M_PI; + //verify axis/ratio and params for full ellipse + ent->correctAxis(); if (version > DRW::AC1009) { writer->writeString(0, "ELLIPSE"); writeEntity(ent); @@ -691,6 +697,10 @@ bool dxfRW::writeLWPolyline(DRW_LWPolyli writer->writeInt32(90, ent->vertexnum); writer->writeInt16(70, ent->flags); writer->writeDouble(43, ent->width); + if (ent->elevation != 0) + writer->writeDouble(38, ent->elevation); + if (ent->thickness != 0) + writer->writeDouble(39, ent->thickness); for (int i = 0; i< ent->vertexnum; i++){ DRW_Vertex2D *v = ent->vertlist.at(i); writer->writeDouble(10, v->x); @@ -877,20 +887,21 @@ bool dxfRW::writeHatch(DRW_Hatch *ent){ writer->writeDouble(10, a->basePoint.x); writer->writeDouble(20, a->basePoint.y); writer->writeDouble(40, a->radious); - writer->writeDouble(50, a->staangle); - writer->writeDouble(51, a->endangle); + writer->writeDouble(50, a->staangle*ARAD); + writer->writeDouble(51, a->endangle*ARAD); writer->writeInt16(73, a->isccw); break; } case DRW::ELLIPSE: { writer->writeInt16(72, 3); DRW_Ellipse* a = (DRW_Ellipse*)loop->objlist.at(j); + a->correctAxis(); writer->writeDouble(10, a->basePoint.x); writer->writeDouble(20, a->basePoint.y); writer->writeDouble(11, a->secPoint.x); writer->writeDouble(21, a->secPoint.y); writer->writeDouble(40, a->ratio); - writer->writeDouble(50, a->staparam); - writer->writeDouble(51, a->endparam); + writer->writeDouble(50, a->staparam*ARAD); + writer->writeDouble(51, a->endparam*ARAD); writer->writeInt16(73, a->isccw); break; } case DRW::SPLINE: @@ -1646,7 +1657,7 @@ bool dxfRW::writeObjects() { //write IMAGEDEF_REACTOR for (unsigned int i=0; i<imageDef.size(); i++) { DRW_ImageDef *id = imageDef.at(i); - map<string, string>::iterator it; + std::map<string, string>::iterator it; for ( it=id->reactors.begin() ; it != id->reactors.end(); it++ ) { writer->writeString(0, "IMAGEDEF_REACTOR"); writer->writeString(5, (*it).first); @@ -1679,7 +1690,7 @@ bool dxfRW::writeObjects() { // writer->writeString(330, "0"); handle to DICTIONARY } writer->writeString(102, "{ACAD_REACTORS"); - map<string, string>::iterator it; + std::map<string, string>::iterator it; for ( it=id->reactors.begin() ; it != id->reactors.end(); it++ ) { writer->writeString(330, (*it).first); } @@ -2644,8 +2655,8 @@ std::string dxfRW::toHexStr(int n){ sprintf(buffer, "%X", n); return std::string(buffer); #else - ostringstream Convert; - Convert << uppercase << hex << n; + std::ostringstream Convert; + Convert << std::uppercase << std::hex << n; return Convert.str(); #endif } diff -urp libdxfrw-0.5.7/src/libdxfrw.h libdxfrw-0.5.7.new/src/libdxfrw.h --- libdxfrw-0.5.7/src/libdxfrw.h 2013-02-19 10:36:29.000000000 -0500 +++ libdxfrw-0.5.7.new/src/libdxfrw.h 2013-04-14 16:37:18.000000000 -0400 @@ -18,7 +18,6 @@ #include "drw_objects.h" #include "drw_interface.h" -#define DRW_VERSION "0.5.7" class dxfReader; class dxfWriter; @@ -27,7 +26,14 @@ class dxfRW { public: dxfRW(const char* name); ~dxfRW(); - //read: return 0 if all ok + /// reads the file specified in constructor + /*! + * An interface must be provided. It is used by the class to signal various + * components being added. + * @param interface_ the interface to use + * @param ext should the extrusion be applied to convert in 2D? + * @return true for success + */ bool read(DRW_Interface *interface_, bool ext); void setBinary(bool b) {binary = b;} @@ -62,6 +68,7 @@ public: bool writeDimension(DRW_Dimension *ent); private: + /// used by read() to parse the content of the file bool processDxf(); bool processHeader(); bool processTables();