diff --git a/src/drw_entities.cpp b/src/drw_entities.cpp index 00f113a..05469ad 100644 --- a/src/drw_entities.cpp +++ b/src/drw_entities.cpp @@ -16,10 +16,9 @@ #include "intern/dwgbuffer.h" #include "intern/drw_dbg.h" - -//! Calculate arbitary axis +//! Calculate arbitrary axis /*! -* Calculate arbitary axis for apply extrusions +* Calculate arbitrary axis for apply extrusions * @author Rallaz */ void DRW_Entity::calculateAxis(DRW_Coord extPoint){ @@ -50,9 +49,9 @@ void DRW_Entity::calculateAxis(DRW_Coord extPoint){ extAxisY.unitize(); } -//! Extrude a point using arbitary axis +//! Extrude a point using arbitrary axis /*! -* apply extrusion in a point using arbitary axis (previous calculated) +* apply extrusion in a point using arbitrary axis (previous calculated) * @author Rallaz */ void DRW_Entity::extrudePoint(DRW_Coord extPoint, DRW_Coord *point){ @@ -110,13 +109,13 @@ bool DRW_Entity::parseCode(int code, dxfReader *reader){ case 1003: case 1004: case 1005: - extData.push_back(new DRW_Variant(code, reader->getString())); + extData.push_back(std::make_shared(code, reader->getString())); break; case 1010: case 1011: case 1012: case 1013: - curr = new DRW_Variant(code, DRW_Coord(reader->getDouble(), 0.0, 0.0)); + curr =std::make_shared(code, DRW_Coord(reader->getDouble(), 0.0, 0.0)); extData.push_back(curr); break; case 1020: @@ -132,16 +131,17 @@ bool DRW_Entity::parseCode(int code, dxfReader *reader){ case 1033: if (curr) curr->setCoordZ(reader->getDouble()); - curr=NULL; + //FIXME, why do we discard curr right after setting the its Z +// curr=NULL; break; case 1040: case 1041: case 1042: - extData.push_back(new DRW_Variant(code, reader->getDouble() )); + extData.push_back(std::make_shared(code, reader->getDouble() )); break; case 1070: case 1071: - extData.push_back(new DRW_Variant(code, reader->getInt32() )); + extData.push_back(std::make_shared(code, reader->getInt32() )); break; default: break; @@ -155,33 +155,29 @@ bool DRW_Entity::parseDxfGroups(int code, dxfReader *reader){ DRW_Variant curr; int nc; std::string appName= reader->getString(); - if (!appName.empty() && appName.at(0)== '{'){ curr.addString(code, appName.substr(1, (int) appName.size()-1)); ls.push_back(curr); - - while (reader->readRec(&nc)) { - if(nc == 102 || reader->getString() == "}") { - break; - } - - if (nc == 330 || nc == 360) { - curr.addInt(nc, reader->getHandleString()); - } + while (code !=102 && appName.at(0)== '}'){ + reader->readRec(&nc);//RLZ curr.code = code or nc? +// curr.code = code; + //RLZ code == 330 || code == 360 OR nc == 330 || nc == 360 ? + if (code == 330 || code == 360) + curr.addInt(code, reader->getHandleString());//RLZ code or nc else { switch (reader->type) { case dxfReader::STRING: - curr.addString(nc, reader->getString()); + curr.addString(code, reader->getString());//RLZ code or nc break; case dxfReader::INT32: case dxfReader::INT64: - curr.addInt(nc, reader->getInt32()); + curr.addInt(code, reader->getInt32());//RLZ code or nc break; case dxfReader::DOUBLE: - curr.addDouble(nc, reader->getDouble()); + curr.addDouble(code, reader->getDouble());//RLZ code or nc break; case dxfReader::BOOL: - curr.addInt(nc, reader->getInt32()); + curr.addInt(code, reader->getInt32());//RLZ code or nc break; default: break; @@ -784,7 +780,7 @@ bool DRW_Ellipse::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ void DRW_Ellipse::toPolyline(DRW_Polyline *pol, int parts){ double radMajor, radMinor, cosRot, sinRot, incAngle, curAngle; double cosCurr, sinCurr; - radMajor = sqrt(secPoint.x*secPoint.x + secPoint.y*secPoint.y); + radMajor = hypot(secPoint.x, secPoint.y); radMinor = radMajor*ratio; //calculate sin & cos of included angle incAngle = atan2(secPoint.y, secPoint.x); @@ -1123,7 +1119,7 @@ void DRW_LWPolyline::applyExtrusion(){ if (haveExtrusion) { calculateAxis(extPoint); for (unsigned int i=0; ix, vert->y, elevation); extrudePoint(extPoint, &v); vert->x = v.x; @@ -1135,24 +1131,24 @@ void DRW_LWPolyline::applyExtrusion(){ void DRW_LWPolyline::parseCode(int code, dxfReader *reader){ switch (code) { case 10: { - vertex = new DRW_Vertex2D(); + vertex = std::make_shared(); vertlist.push_back(vertex); vertex->x = reader->getDouble(); break; } case 20: - if(vertex != NULL) + if(vertex) vertex->y = reader->getDouble(); break; case 40: - if(vertex != NULL) + if(vertex) vertex->stawidth = reader->getDouble(); break; case 41: - if(vertex != NULL) + if(vertex) vertex->endwidth = reader->getDouble(); break; case 42: - if(vertex != NULL) + if(vertex) vertex->bulge = reader->getDouble(); break; case 38: @@ -1227,14 +1223,14 @@ bool DRW_LWPolyline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ if (vertexnum > 0) { //verify if is lwpol without vertex (empty) // add vertexs - vertex = new DRW_Vertex2D(); + vertex = std::make_shared(); vertex->x = buf->getRawDouble(); vertex->y = buf->getRawDouble(); vertlist.push_back(vertex); - DRW_Vertex2D* pv = vertex; + auto pv = vertex; for (int i = 1; i< vertexnum; i++){ - vertex = new DRW_Vertex2D(); - if (version < DRW::AC1015) {//14- + vertex = std::make_shared(); + if (version < DRW::AC1015) {//14- vertex->x = buf->getRawDouble(); vertex->y = buf->getRawDouble(); } else { @@ -1273,8 +1269,7 @@ bool DRW_LWPolyline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ } if (DRW_DBGGL == DRW_dbg::DEBUG){ DRW_DBG("\nVertex list: "); - for (std::vector::iterator it = vertlist.begin() ; it != vertlist.end(); ++it){ - DRW_Vertex2D* pv = *it; + for (auto& pv: vertlist) { DRW_DBG("\n x: "); DRW_DBG(pv->x); DRW_DBG(" y: "); DRW_DBG(pv->y); DRW_DBG(" bulge: "); DRW_DBG(pv->bulge); DRW_DBG(" stawidth: "); DRW_DBG(pv->stawidth); DRW_DBG(" endwidth: "); DRW_DBG(pv->endwidth); } @@ -1384,6 +1379,7 @@ bool DRW_Text::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ height = buf->getBitDouble(); /* Height BD 40 */ widthscale = buf->getBitDouble(); /* Width factor BD 41 */ } + angle *= ARAD; DRW_DBG("thickness: "); DRW_DBG(thickness); DRW_DBG(", Oblique ang: "); DRW_DBG(oblique); DRW_DBG(", Width: "); DRW_DBG(widthscale); DRW_DBG(", Rotation: "); DRW_DBG(angle); DRW_DBG(", height: "); DRW_DBG(height); DRW_DBG("\n"); text = sBuf->getVariableText(version, false); /* Text value TV 1 */ @@ -1422,7 +1418,7 @@ void DRW_MText::parseCode(int code, dxfReader *reader){ text = reader->toUtf8String(text); break; case 11: - haveXAxis = true; + hasXAxisVec = true; DRW_Text::parseCode(code, reader); break; case 3: @@ -1431,6 +1427,10 @@ void DRW_MText::parseCode(int code, dxfReader *reader){ case 44: interlin = reader->getDouble(); break; + case 50: // djm: per dxf docs, last of code 11 or code 50 prevails + hasXAxisVec = false; + angle = reader->getDouble(); + break; default: DRW_Text::parseCode(code, reader); break; @@ -1452,6 +1452,7 @@ bool DRW_MText::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ DRW_DBG("Insertion: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); DRW_DBG("\n"); extPoint = buf->get3BitDouble(); /* Extrusion 3BD 210 Undocumented; */ secPoint = buf->get3BitDouble(); /* X-axis dir 3BD 11 */ + hasXAxisVec = true; updateAngle(); widthscale = buf->getBitDouble(); /* Rect width BD 41 */ if (version > DRW::AC1018) {//2007+ @@ -1512,9 +1513,9 @@ bool DRW_MText::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ return buf->isGood(); } -void DRW_MText::updateAngle(){ - if (haveXAxis) { - angle = atan2(secPoint.y, secPoint.x)*180/M_PI; +void DRW_MText::updateAngle() { + if (hasXAxisVec) { + angle = atan2(secPoint.y, secPoint.x) * ARAD; } } @@ -1793,12 +1794,12 @@ void DRW_Hatch::parseCode(int code, dxfReader *reader){ looplist.reserve(loopsnum); break; case 92: - loop = new DRW_HatchLoop(reader->getInt32()); + loop = std::make_shared(reader->getInt32()); looplist.push_back(loop); if (reader->getInt32() & 2) { ispol = true; clearEntities(); - pline = new DRW_LWPolyline; + pline = std::make_shared(); loop->objlist.push_back(pline); } else ispol = false; break; @@ -1870,7 +1871,7 @@ bool DRW_Hatch::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ //read loops for (dint32 i = 0 ; i < loopsnum; ++i){ - loop = new DRW_HatchLoop(buf->getBitLong()); + loop = std::make_shared(buf->getBitLong()); havePixelSize |= loop->type & 4; if (!(loop->type & 2)){ //Not polyline dint32 numPathSeg = buf->getBitLong(); @@ -1909,7 +1910,7 @@ bool DRW_Hatch::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ spline->ncontrol = buf->getBitLong(); spline->controllist.reserve(spline->ncontrol); for (dint32 j = 0; j < spline->ncontrol;++j){ - DRW_Coord* crd = new DRW_Coord(buf->get3BitDouble()); + std::shared_ptr crd = std::make_shared(buf->get3BitDouble()); spline->controllist.push_back(crd); if(isRational) crd->z = buf->getBitDouble(); //RLZ: investigate how store weight @@ -1919,8 +1920,8 @@ bool DRW_Hatch::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ spline->nfit = buf->getBitLong(); spline->fitlist.reserve(spline->nfit); for (dint32 j = 0; j < spline->nfit;++j){ - DRW_Coord* crd = new DRW_Coord(buf->get3BitDouble()); - spline->fitlist.push_back (crd); + std::shared_ptr crd = std::make_shared(buf->get3BitDouble()); + spline->fitlist.push_back(crd); } spline->tgStart = buf->get2RawDouble(); spline->tgEnd = buf->get2RawDouble(); @@ -1928,7 +1929,7 @@ bool DRW_Hatch::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ } } } else { //end not pline, start polyline - pline = new DRW_LWPolyline; + pline = std::make_shared(); bool asBulge = buf->getBit(); pline->flags = buf->getBit();//closed bit dint32 numVert = buf->getBitLong(); @@ -2056,29 +2057,29 @@ void DRW_Spline::parseCode(int code, dxfReader *reader){ tolfit = reader->getDouble(); break; case 10: { - controlpoint = new DRW_Coord(); + controlpoint = std::make_shared(); controllist.push_back(controlpoint); controlpoint->x = reader->getDouble(); break; } case 20: - if(controlpoint != NULL) + if(controlpoint) controlpoint->y = reader->getDouble(); break; case 30: - if(controlpoint != NULL) + if(controlpoint) controlpoint->z = reader->getDouble(); break; case 11: { - fitpoint = new DRW_Coord(); + fitpoint = std::make_shared(); fitlist.push_back(fitpoint); fitpoint->x = reader->getDouble(); break; } case 21: - if(fitpoint != NULL) + if(fitpoint) fitpoint->y = reader->getDouble(); break; case 31: - if(fitpoint != NULL) + if(fitpoint) fitpoint->z = reader->getDouble(); break; case 40: @@ -2146,31 +2147,29 @@ bool DRW_Spline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ knotslist.push_back (buf->getBitDouble()); } controllist.reserve(ncontrol); - for (dint32 i= 0; iget3BitDouble()); - controllist.push_back(crd); - if (weight){ + for (dint32 i= 0; i(buf->get3BitDouble())); + if (weight) DRW_DBG("\n w: "); DRW_DBG(buf->getBitDouble()); //RLZ Warning: D (BD or RD) - } } fitlist.reserve(nfit); - for (dint32 i= 0; iget3BitDouble()); - fitlist.push_back (crd); - } + for (dint32 i= 0; i(buf->get3BitDouble())); + if (DRW_DBGGL == DRW_dbg::DEBUG){ - DRW_DBG("\nknots list: "); - for (std::vector::iterator it = knotslist.begin() ; it != knotslist.end(); ++it){ - DRW_DBG("\n"); DRW_DBG(*it); - } + DRW_DBG("\nknots list: "); + for (auto const& v: knotslist) { + DRW_DBG("\n"); DRW_DBG(v); + } DRW_DBG("\ncontrol point list: "); - for (std::vector::iterator it = controllist.begin() ; it != controllist.end(); ++it){ - DRW_DBG("\n"); DRW_DBGPT((*it)->x,(*it)->y,(*it)->z); - } + for (auto const& v: controllist) { + DRW_DBG("\n"); DRW_DBGPT(v->x, v->y, v->z); + } DRW_DBG("\nfit point list: "); - for (std::vector::iterator it = fitlist.begin() ; it != fitlist.end(); ++it){ - DRW_DBG("\n"); DRW_DBGPT((*it)->x,(*it)->y,(*it)->z); - } + for (auto const& v: fitlist) { + DRW_DBG("\n"); DRW_DBGPT(v->x, v->y, v->z); + } + } /* Common Entity Handle Data */ @@ -2720,17 +2719,17 @@ void DRW_Leader::parseCode(int code, dxfReader *reader){ case 41: textwidth = reader->getDouble(); break; - case 10: { - vertexpoint = new DRW_Coord(); + case 10: + vertexpoint= std::make_shared(); vertexlist.push_back(vertexpoint); vertexpoint->x = reader->getDouble(); - break; } + break; case 20: - if(vertexpoint != NULL) + if(vertexpoint) vertexpoint->y = reader->getDouble(); break; case 30: - if(vertexpoint != NULL) + if(vertexpoint) vertexpoint->z = reader->getDouble(); break; case 340: @@ -2796,9 +2795,9 @@ bool DRW_Leader::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ // add vertexs for (int i = 0; i< nPt; i++){ - DRW_Coord* vertex = new DRW_Coord(buf->get3BitDouble()); - vertexlist.push_back(vertex); - DRW_DBG("\nvertex "); DRW_DBGPT(vertex->x, vertex->y, vertex->z); + DRW_Coord vertex = buf->get3BitDouble(); + vertexlist.push_back(std::make_shared(vertex)); + DRW_DBG("\nvertex "); DRW_DBGPT(vertex.x, vertex.y, vertex.z); } DRW_Coord Endptproj = buf->get3BitDouble(); DRW_DBG("\nEndptproj "); DRW_DBGPT(Endptproj.x, Endptproj.y, Endptproj.z); diff --git a/src/drw_entities.h b/src/drw_entities.h index b01af09..d6d5f61 100644 --- a/src/drw_entities.h +++ b/src/drw_entities.h @@ -17,6 +17,7 @@ #include #include #include +#include #include "drw_base.h" class dxfReader; @@ -28,13 +29,13 @@ namespace DRW { //! Entity's type. enum ETYPE { E3DFACE, -// E3DSOLID, //encripted propietry data +// E3DSOLID, //encrypted proprietary data // ACAD_PROXY_ENTITY, ARC, // ATTDEF, // ATTRIB, BLOCK,// and ENDBLK -// BODY, //encripted propietry data +// BODY, //encrypted proprietary data CIRCLE, DIMENSION, DIMALIGNED, @@ -63,14 +64,14 @@ namespace DRW { POINT, POLYLINE, RAY, -// REGION, //encripted propietry data +// REGION, //encrypted proprietary data // SECTION, // SEQEND,//not needed?? used in polyline and insert/attrib and dwg // SHAPE, SOLID, SPLINE, // SUN, -// SURFACE, //encripted propietry data can be four types +// SURFACE, //encrypted proprietary data can be four types // TABLE, TEXT, // TOLERANCE, @@ -99,59 +100,17 @@ class DRW_Entity { SETENTFRIENDS public: //initializes default values - //handles: default no handle (0), color: default BYLAYER (256), 24 bits color: default -1 (not set) - //line weight: default BYLAYER (dxf -1, dwg 29), space: default ModelSpace (0) - DRW_Entity(): eType(DRW::UNKNOWN), handle(DRW::NoHandle), parentHandle(DRW::NoHandle), appData(0), - space(DRW::ModelSpace), layer("0"), lineType("BYLAYER"), material(DRW::MaterialByLayer), - color(DRW::ColorByLayer), lWeight(DRW_LW_Conv::widthByLayer), ltypeScale(1.0), visible(true), - numProxyGraph(0), proxyGraphics(std::string()), color24(-1), colorName(std::string()), - transparency(DRW::Opaque), plotStyle(DRW::DefaultPlotStyle), shadow(DRW::CastAndReceieveShadows), - haveExtrusion(false), extData(), haveNextLinks(0),plotFlags(0), ltFlags(0),materialFlag(0), - shadowFlag(0), lTypeH(dwgHandle()), layerH(dwgHandle()), nextEntLink(0), prevEntLink(0), - ownerHandle(false), xDictFlag(0), numReactors(0), objSize(0), oType(0), extAxisX(DRW_Coord()), - extAxisY(DRW_Coord()), curr(NULL) {} - - DRW_Entity(const DRW_Entity& e) { - eType = e.eType; - handle = e.handle; - parentHandle = e.parentHandle; //no handle (0) - lineType = e.lineType; - color = e.color; // default BYLAYER (256) - ltypeScale = e.ltypeScale; - visible = e.visible; - layer = e.layer; - lWeight = e.lWeight; - space = e.space; - haveExtrusion = e.haveExtrusion; - color24 = e.color24; //default -1 not set - numProxyGraph = e.numProxyGraph; - shadow = e.shadow; - material = e.material; - plotStyle = e.plotStyle; - transparency = e.transparency; - nextEntLink = e.nextEntLink; - prevEntLink = e.prevEntLink; - numReactors = e.numReactors; - xDictFlag = e.xDictFlag; - curr = NULL; - ownerHandle= false; - for (std::vector::const_iterator it=e.extData.begin(); it!=e.extData.end(); ++it){ - extData.push_back(new DRW_Variant(*(*it))); - } - } + DRW_Entity() = default; + virtual ~DRW_Entity() = default; - virtual ~DRW_Entity() { - for (std::vector::iterator it=extData.begin(); it!=extData.end(); ++it) - delete *it; + //removed copy/move ctors + // looks like the potential issue is the "curr" pointer is reset in previous + // versions during copy ctor - extData.clear(); - } - - void reset(){ - for (std::vector::iterator it=extData.begin(); it!=extData.end(); ++it) - delete *it; - extData.clear(); - } + void reset() { + extData.clear(); + curr.reset(); + } virtual void applyExtrusion() = 0; @@ -172,27 +131,27 @@ class DRW_Entity { bool parseDxfGroups(int code, dxfReader *reader); public: - enum DRW::ETYPE eType; /*!< enum: entity type, code 0 */ - duint32 handle; /*!< entity identifier, code 5 */ - duint32 parentHandle; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */ + enum DRW::ETYPE eType = DRW::UNKNOWN; /*!< enum: entity type, code 0 */ + duint32 handle = DRW::NoHandle; /*!< entity identifier, code 5 */ std::list > appData; /*!< list of application data, code 102 */ - DRW::Space space; /*!< space indicator, code 67*/ - UTF8STRING layer; /*!< layer name, code 8 */ - UTF8STRING lineType; /*!< line type, code 6 */ - duint32 material; /*!< hard pointer id to material object, code 347 */ - int color; /*!< entity color, code 62 */ - enum DRW_LW_Conv::lineWidth lWeight; /*!< entity lineweight, code 370 */ - double ltypeScale; /*!< linetype scale, code 48 */ - bool visible; /*!< entity visibility, code 60 */ - int numProxyGraph; /*!< Number of bytes in proxy graphics, code 92 */ + duint32 parentHandle = DRW::NoHandle; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */ + DRW::Space space = DRW::ModelSpace; /*!< space indicator, code 67*/ + UTF8STRING layer = "0"; /*!< layer name, code 8 */ + UTF8STRING lineType = "BYLAYER"; /*!< line type, code 6 */ + duint32 material = DRW::MaterialByLayer; /*!< hard pointer id to material object, code 347 */ + int color = DRW::ColorByLayer; /*!< entity color, code 62 */ + enum DRW_LW_Conv::lineWidth lWeight = DRW_LW_Conv::widthByLayer; /*!< entity lineweight, code 370 */ + double ltypeScale = 1.0; /*!< linetype scale, code 48 */ + bool visible = true; /*!< entity visibility, code 60 */ + int numProxyGraph = 0; /*!< Number of bytes in proxy graphics, code 92 */ std::string proxyGraphics; /*!< proxy graphics bytes, code 310 */ - int color24; /*!< 24-bit color, code 420 */ + int color24 = -1; /*!< 24-bit color, code 420 */ std::string colorName; /*!< color name, code 430 */ - int transparency; /*!< transparency, code 440 */ - int plotStyle; /*!< hard pointer id to plot style object, code 390 */ - DRW::ShadowMode shadow; /*!< shadow mode, code 284 */ - bool haveExtrusion; /*!< set to true if the entity have extrusion*/ - std::vector extData; /*!< FIFO list of extended data, codes 1000 to 1071*/ + int transparency = DRW::Opaque; /*!< transparency, code 440 */ + int plotStyle = DRW::DefaultPlotStyle; /*!< hard pointer id to plot style object, code 390 */ + DRW::ShadowMode shadow = DRW::CastAndReceieveShadows; /*!< shadow mode, code 284 */ + bool haveExtrusion = false; /*!< set to true if the entity have extrusion*/ + std::vector> extData; /*!< FIFO list of extended data, codes 1000 to 1071*/ protected: //only for read dwg duint8 haveNextLinks; //aka nolinks //B @@ -202,19 +161,20 @@ class DRW_Entity { duint8 shadowFlag; //presence of shadow handle ?? (in dwg may be plotflag)//RC dwgHandle lTypeH; dwgHandle layerH; - duint32 nextEntLink; - duint32 prevEntLink; - bool ownerHandle; + duint32 nextEntLink = 0; + duint32 prevEntLink = 0; + bool ownerHandle = false; - duint8 xDictFlag; - dint32 numReactors; // + duint8 xDictFlag = 0; + dint32 numReactors = 0; // duint32 objSize; //RL 32bits object data size in bits dint16 oType; private: - DRW_Coord extAxisX; + void init(DRW_Entity const& rhs); + DRW_Coord extAxisX; DRW_Coord extAxisY; - DRW_Variant* curr; + std::shared_ptr curr; }; @@ -233,7 +193,7 @@ class DRW_Point : public DRW_Entity { thickness = 0; } - virtual void applyExtrusion(){} + virtual void applyExtrusion(){} protected: void parseCode(int code, dxfReader *reader); @@ -260,8 +220,6 @@ class DRW_Line : public DRW_Point { secPoint.z = 0; } - virtual void applyExtrusion(){} - protected: void parseCode(int code, dxfReader *reader); virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); @@ -584,8 +542,7 @@ class DRW_LWPolyline : public DRW_Entity { elevation = thickness = width = 0.0; flags = 0; extPoint.x = extPoint.y = 0; - extPoint.z = 1; - vertex = NULL; + extPoint.z = 1; } DRW_LWPolyline(const DRW_LWPolyline& p):DRW_Entity(p){ @@ -594,31 +551,21 @@ class DRW_LWPolyline : public DRW_Entity { this->thickness = p.thickness; this->width = p.width; this->flags = p.flags; - this->extPoint = p.extPoint; - this->vertex = NULL; + this->extPoint = p.extPoint; for (unsigned i=0; ivertlist.push_back( new DRW_Vertex2D( *(p.vertlist.at(i)) ) ); - - this->vertex = NULL; + this->vertlist.push_back( + std::make_shared(*p.vertlist.at(i)) + ); } + // TODO rule of 5 - ~DRW_LWPolyline() { - while (!vertlist.empty()) { - vertlist.pop_back(); - } - } virtual void applyExtrusion(); void addVertex (DRW_Vertex2D v) { - DRW_Vertex2D *vert = new DRW_Vertex2D(); - vert->x = v.x; - vert->y = v.y; - vert->stawidth = v.stawidth; - vert->endwidth = v.endwidth; - vert->bulge = v.bulge; + std::shared_ptr vert = std::make_shared(v); vertlist.push_back(vert); } - DRW_Vertex2D *addVertex () { - DRW_Vertex2D *vert = new DRW_Vertex2D(); + std::shared_ptr addVertex () { + std::shared_ptr vert = std::make_shared(); vert->stawidth = 0; vert->endwidth = 0; vert->bulge = 0; @@ -637,8 +584,8 @@ class DRW_LWPolyline : public DRW_Entity { 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 vertlist; /*!< vertex list */ + std::shared_ptr vertex; /*!< current vertex to add data */ + std::vector> vertlist; /*!< vertex list */ }; //! Class to handle insert entries @@ -723,18 +670,19 @@ class DRW_MText : public DRW_Text { interlin = 1; alignV = (VAlign)TopLeft; textgen = 1; - haveXAxis = false; //if true needed to recalculate angle + hasXAxisVec = false; // if true need to calculate angle from secPoint vector } protected: void parseCode(int code, dxfReader *reader); - void updateAngle(); //recalculate angle if 'haveXAxis' is true + void updateAngle(); // recalculate angle if 'hasXAxisVec' is true virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); public: double interlin; /*!< width factor, code 44 */ private: - bool haveXAxis; +// bool haveXAxis; + bool hasXAxisVec; /* renamed by djm for better description */ }; //! Class to handle vertex @@ -795,14 +743,9 @@ class DRW_Polyline : public DRW_Point { basePoint.x = basePoint.y = 0.0; flags = vertexcount = facecount = 0; smoothM = smoothN = curvetype = 0; - } - ~DRW_Polyline() { - while (!vertlist.empty()) { - vertlist.pop_back(); - } - } + } void addVertex (DRW_Vertex v) { - DRW_Vertex *vert = new DRW_Vertex(); + std::shared_ptr vert = std::make_shared(); vert->basePoint.x = v.basePoint.x; vert->basePoint.y = v.basePoint.y; vert->basePoint.z = v.basePoint.z; @@ -811,7 +754,7 @@ class DRW_Polyline : public DRW_Point { vert->bulge = v.bulge; vertlist.push_back(vert); } - void appendVertex (DRW_Vertex *v) { + void appendVertex (std::shared_ptr const& v) { vertlist.push_back(v); } @@ -829,7 +772,7 @@ class DRW_Polyline : public DRW_Point { int smoothN; /*!< smooth surface M density, code 74, default 0 */ int curvetype; /*!< curves & smooth surface type, code 75, default 0 */ - std::vector vertlist; /*!< vertex list */ + std::vector> vertlist; /*!< vertex list */ private: std::listhadlesList; //list of handles, only in 2004+ @@ -852,15 +795,7 @@ class DRW_Spline : public DRW_Entity { flags = nknots = ncontrol = nfit = 0; tolknot = tolcontrol = tolfit = 0.0000001; - } - ~DRW_Spline() { - while (!controllist.empty()) { - controllist.pop_back(); - } - while (!fitlist.empty()) { - fitlist.pop_back(); - } - } + } virtual void applyExtrusion(){} protected: @@ -890,12 +825,12 @@ 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 controllist; /*!< control points list, code 10, 20 & 30 */ - std::vector fitlist; /*!< fit points list, code 11, 21 & 31 */ + std::vector> controllist; /*!< control points list, code 10, 20 & 30 */ + std::vector> fitlist; /*!< fit points list, code 11, 21 & 31 */ private: - DRW_Coord *controlpoint; /*!< current control point to add data */ - DRW_Coord *fitpoint; /*!< current fit point to add data */ + std::shared_ptr controlpoint; /*!< current control point to add data */ + std::shared_ptr fitpoint; /*!< current fit point to add data */ }; //! Class to handle hatch loop @@ -910,15 +845,6 @@ class DRW_HatchLoop { numedges = 0; } - ~DRW_HatchLoop() { -/* while (!pollist.empty()) { - pollist.pop_back(); - }*/ - while (!objlist.empty()) { - objlist.pop_back(); - } - } - void update() { numedges = objlist.size(); } @@ -928,7 +854,7 @@ class DRW_HatchLoop { int numedges; /*!< number of edges (if not a polyline), code 93 */ //TODO: store lwpolylines as entities // std::vector pollist; /*!< polyline list */ - std::vector objlist; /*!< entities list */ + std::vector> objlist; /*!< entities list */ }; //! Class to handle hatch entity @@ -947,17 +873,10 @@ class DRW_Hatch : public DRW_Point { loopsnum = hstyle = associative = 0; solid = hpattern = 1; deflines = doubleflag = 0; - loop = NULL; clearEntities(); } - ~DRW_Hatch() { - while (!looplist.empty()) { - looplist.pop_back(); - } - } - - void appendLoop (DRW_HatchLoop *v) { + void appendLoop (std::shared_ptr const& v) { looplist.push_back(v); } @@ -979,22 +898,23 @@ class DRW_Hatch : public DRW_Point { double scale; /*!< hatch pattern scale, code 41 */ int deflines; /*!< number of pattern definition lines, code 78 */ - std::vector looplist; /*!< polyline list */ + std::vector> looplist; /*!< polyline list */ private: void clearEntities(){ - pt = line = NULL; - pline = NULL; - arc = NULL; - ellipse = NULL; - spline = NULL; - plvert = NULL; + pt.reset(); + line.reset(); + pline.reset(); + arc.reset(); + ellipse.reset(); + spline.reset(); + plvert.reset(); } void addLine() { clearEntities(); if (loop) { - pt = line = new DRW_Line; + pt = line = std::make_shared(); loop->objlist.push_back(line); } } @@ -1002,7 +922,7 @@ class DRW_Hatch : public DRW_Point { void addArc() { clearEntities(); if (loop) { - pt = arc = new DRW_Arc; + pt = arc = std::make_shared(); loop->objlist.push_back(arc); } } @@ -1010,7 +930,7 @@ class DRW_Hatch : public DRW_Point { void addEllipse() { clearEntities(); if (loop) { - pt = ellipse = new DRW_Ellipse; + pt = ellipse = std::make_shared(); loop->objlist.push_back(ellipse); } } @@ -1018,20 +938,20 @@ class DRW_Hatch : public DRW_Point { void addSpline() { clearEntities(); if (loop) { - pt = NULL; - spline = new DRW_Spline; + pt.reset(); + spline = std::make_shared(); loop->objlist.push_back(spline); } } - DRW_HatchLoop *loop; /*!< current loop to add data */ - DRW_Line *line; - DRW_Arc *arc; - DRW_Ellipse *ellipse; - DRW_Spline *spline; - DRW_LWPolyline *pline; - DRW_Point *pt; - DRW_Vertex2D *plvert; + std::shared_ptr loop; /*!< current loop to add data */ + std::shared_ptr line; + std::shared_ptr arc; + std::shared_ptr ellipse; + std::shared_ptr spline; + std::shared_ptr pline; + std::shared_ptr pt; + std::shared_ptr plvert; bool ispol; }; @@ -1398,12 +1318,7 @@ class DRW_Leader : public DRW_Entity { extrusionPoint.x = extrusionPoint.y = 0.0; arrow = 1; extrusionPoint.z = 1.0; - } - ~DRW_Leader() { - while (!vertexlist.empty()) { - vertexlist.pop_back(); - } - } + } virtual void applyExtrusion(){} @@ -1428,10 +1343,10 @@ class DRW_Leader : public DRW_Entity { DRW_Coord offsetblock; /*!< Offset of last leader vertex from block, code 212, 222 & 232 */ DRW_Coord offsettext; /*!< Offset of last leader vertex from annotation, code 213, 223 & 233 */ - std::vector vertexlist; /*!< vertex points list, code 10, 20 & 30 */ + std::vector> vertexlist; /*!< vertex points list, code 10, 20 & 30 */ private: - DRW_Coord *vertexpoint; /*!< current control point to add data */ + std::shared_ptr vertexpoint; /*!< current control point to add data */ dwgHandle dimStyleH; dwgHandle AnnotH; };