From b5464ccf4d180c09da3d6754413899ccfaa1fcff Mon Sep 17 00:00:00 2001 From: wandererfan Date: Mon, 22 Jul 2019 11:48:40 -0400 Subject: [PATCH] [TD]Add uuid tags for cosmetics --- src/Mod/TechDraw/App/CenterLinePy.xml | 6 + src/Mod/TechDraw/App/CenterLinePyImp.cpp | 8 +- src/Mod/TechDraw/App/Cosmetic.cpp | 161 ++++++++++++++++++- src/Mod/TechDraw/App/Cosmetic.h | 35 +++- src/Mod/TechDraw/App/CosmeticEdgePy.xml | 6 + src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp | 6 + src/Mod/TechDraw/App/CosmeticVertexPy.xml | 6 + src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp | 7 + src/Mod/TechDraw/App/GeomFormatPy.xml | 6 + src/Mod/TechDraw/App/GeomFormatPyImp.cpp | 29 +--- src/Mod/TechDraw/App/PreCompiled.h | 1 + 11 files changed, 236 insertions(+), 35 deletions(-) diff --git a/src/Mod/TechDraw/App/CenterLinePy.xml b/src/Mod/TechDraw/App/CenterLinePy.xml index 8361d17f91..fe3f099244 100644 --- a/src/Mod/TechDraw/App/CenterLinePy.xml +++ b/src/Mod/TechDraw/App/CenterLinePy.xml @@ -36,5 +36,11 @@ returns the appearance attributes of this CenterLine. returns tuple(style, color, weight, visible). + + + Gives the tag of the CenterLine as string. + + + diff --git a/src/Mod/TechDraw/App/CenterLinePyImp.cpp b/src/Mod/TechDraw/App/CenterLinePyImp.cpp index 2558b23092..5b546d33b1 100644 --- a/src/Mod/TechDraw/App/CenterLinePyImp.cpp +++ b/src/Mod/TechDraw/App/CenterLinePyImp.cpp @@ -24,7 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -//# include +# include #endif #include "DrawUtil.h" @@ -167,6 +167,12 @@ PyObject* CenterLinePy::getFormat(PyObject *args) return result; } +Py::String CenterLinePy::getTag(void) const +{ + std::string tmp = boost::uuids::to_string(getCenterLinePtr()->getTag()); + return Py::String(tmp); +} + PyObject *CenterLinePy::getCustomAttributes(const char* /*attr*/) const { return 0; diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index c5fd2ee87a..0d89a8c14a 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -145,6 +145,8 @@ CosmeticVertex::CosmeticVertex() : TechDraw::Vertex() size = 3.0; style = 1; visible = true; + + createNewTag(); } CosmeticVertex::CosmeticVertex(const TechDraw::CosmeticVertex* cv) : TechDraw::Vertex(cv) @@ -154,6 +156,8 @@ CosmeticVertex::CosmeticVertex(const TechDraw::CosmeticVertex* cv) : TechDraw::V size = cv->size; style = cv->style; visible = cv->visible; + + createNewTag(); } CosmeticVertex::CosmeticVertex(Base::Vector3d loc) : TechDraw::Vertex(loc) @@ -169,6 +173,9 @@ CosmeticVertex::CosmeticVertex(Base::Vector3d loc) : TechDraw::Vertex(loc) size = 30.0; style = 1; //TODO: implement styled vertexes visible = true; + + createNewTag(); + } std::string CosmeticVertex::toString(void) const @@ -219,6 +226,40 @@ void CosmeticVertex::Restore(Base::XMLReader &reader) visible = (int)reader.getAttributeAsInteger("value")==0?false:true; } +boost::uuids::uuid CosmeticVertex::getTag() const +{ + return tag; +} + +std::string CosmeticVertex::getTagAsString(void) const +{ + std::string tmp = boost::uuids::to_string(getTag()); + return tmp; +} + +void CosmeticVertex::createNewTag() +{ + // Initialize a random number generator, to avoid Valgrind false positives. + static boost::mt19937 ran; + static bool seeded = false; + + if (!seeded) { + ran.seed(static_cast(std::time(0))); + seeded = true; + } + static boost::uuids::basic_random_generator gen(&ran); + + tag = gen(); +} + +void CosmeticVertex::assignTag(const TechDraw::CosmeticVertex * cv) +{ + if(cv->getTypeId() == this->getTypeId()) + this->tag = cv->tag; + else + throw Base::TypeError("CosmeticVertex tag can not be assigned as types do not match."); +} + CosmeticVertex* CosmeticVertex::copy(void) const { // Base::Console().Message("CV::copy()\n"); @@ -230,6 +271,7 @@ CosmeticVertex* CosmeticVertex::clone(void) const { // Base::Console().Message("CV::clone()\n"); CosmeticVertex* cpy = this->copy(); + cpy->tag = this->tag; return cpy; } @@ -304,6 +346,9 @@ void CosmeticEdge::initialize(void) m_geometry->classOfEdge = ecHARD; m_geometry->visible = true; m_geometry->cosmetic = true; + + createNewTag(); + } TechDraw::BaseGeom* CosmeticEdge::scaledGeometry(double scale) @@ -402,6 +447,34 @@ void CosmeticEdge::Restore(Base::XMLReader &reader) } } +boost::uuids::uuid CosmeticEdge::getTag() const +{ + return tag; +} + +void CosmeticEdge::createNewTag() +{ + // Initialize a random number generator, to avoid Valgrind false positives. + static boost::mt19937 ran; + static bool seeded = false; + + if (!seeded) { + ran.seed(static_cast(std::time(0))); + seeded = true; + } + static boost::uuids::basic_random_generator gen(&ran); + + tag = gen(); +} + +void CosmeticEdge::assignTag(const TechDraw::CosmeticEdge * ce) +{ + if(ce->getTypeId() == this->getTypeId()) + this->tag = ce->tag; + else + throw Base::TypeError("CosmeticEdge tag can not be assigned as types do not match."); +} + CosmeticEdge* CosmeticEdge::copy(void) const { // Base::Console().Message("CE::copy()\n"); @@ -416,6 +489,7 @@ CosmeticEdge* CosmeticEdge::clone(void) const { // Base::Console().Message("CE::clone()\n"); CosmeticEdge* cpy = this->copy(); + cpy->tag = this->tag; return cpy; } @@ -440,6 +514,7 @@ CenterLine::CenterLine(void) m_type = CLTYPE::FACE; m_flip2Line = false; + createNewTag(); } CenterLine::CenterLine(CenterLine* cl) @@ -457,6 +532,8 @@ CenterLine::CenterLine(CenterLine* cl) m_flip2Line = cl->m_flip2Line; m_edges = cl->m_edges; m_verts = cl->m_verts; + + createNewTag(); } CenterLine::CenterLine(Base::Vector3d p1, Base::Vector3d p2) @@ -470,6 +547,8 @@ CenterLine::CenterLine(Base::Vector3d p1, Base::Vector3d p2) m_extendBy = 0.0; m_type = CLTYPE::FACE; m_flip2Line = false; + + createNewTag(); } CenterLine::CenterLine(Base::Vector3d p1, Base::Vector3d p2, @@ -488,6 +567,8 @@ CenterLine::CenterLine(Base::Vector3d p1, Base::Vector3d p2, m_extendBy = x; m_type = CLTYPE::FACE; m_flip2Line = false; + + createNewTag(); } CenterLine::~CenterLine() @@ -1102,9 +1183,39 @@ CenterLine* CenterLine::copy(void) const return newCL; } -CenterLine* CenterLine::clone(void) const +boost::uuids::uuid CenterLine::getTag() const +{ + return tag; +} + +void CenterLine::createNewTag() +{ + // Initialize a random number generator, to avoid Valgrind false positives. + static boost::mt19937 ran; + static bool seeded = false; + + if (!seeded) { + ran.seed(static_cast(std::time(0))); + seeded = true; + } + static boost::uuids::basic_random_generator gen(&ran); + + tag = gen(); +} + +void CenterLine::assignTag(const TechDraw::CenterLine * ce) +{ + if(ce->getTypeId() == this->getTypeId()) + this->tag = ce->tag; + else + throw Base::TypeError("CenterLine tag can not be assigned as types do not match."); +} + +CenterLine *CenterLine::clone(void) const { CenterLine* cpy = this->copy(); + cpy->tag = this->tag; + return cpy; } @@ -1169,6 +1280,8 @@ GeomFormat::GeomFormat() : m_format.m_weight = LineFormat::getDefEdgeWidth(); m_format.m_color = LineFormat::getDefEdgeColor(); m_format.m_visible = true; + + createNewTag(); } GeomFormat::GeomFormat(GeomFormat* gf) @@ -1178,6 +1291,8 @@ GeomFormat::GeomFormat(GeomFormat* gf) m_format.m_weight = gf->m_format.m_weight; m_format.m_color = gf->m_format.m_color; m_format.m_visible = gf->m_format.m_visible; + + createNewTag(); } GeomFormat::GeomFormat(int idx, @@ -1189,6 +1304,7 @@ GeomFormat::GeomFormat(int idx, m_format.m_color = fmt.m_color; m_format.m_visible = fmt.m_visible; + createNewTag(); } GeomFormat::~GeomFormat() @@ -1243,6 +1359,42 @@ void GeomFormat::Restore(Base::XMLReader &reader) m_format.m_visible = (int)reader.getAttributeAsInteger("value")==0?false:true; } +boost::uuids::uuid GeomFormat::getTag() const +{ + return tag; +} + +void GeomFormat::createNewTag() +{ + // Initialize a random number generator, to avoid Valgrind false positives. + static boost::mt19937 ran; + static bool seeded = false; + + if (!seeded) { + ran.seed(static_cast(std::time(0))); + seeded = true; + } + static boost::uuids::basic_random_generator gen(&ran); + + tag = gen(); +} + +void GeomFormat::assignTag(const TechDraw::GeomFormat * ce) +{ + if(ce->getTypeId() == this->getTypeId()) + this->tag = ce->tag; + else + throw Base::TypeError("GeomFormat tag can not be assigned as types do not match."); +} + +GeomFormat *GeomFormat::clone(void) const +{ + GeomFormat* cpy = this->copy(); + cpy->tag = this->tag; + + return cpy; +} + GeomFormat* GeomFormat::copy(void) const { GeomFormat* newFmt = new GeomFormat(); @@ -1254,15 +1406,8 @@ GeomFormat* GeomFormat::copy(void) const return newFmt; } -GeomFormat* GeomFormat::clone(void) const -{ - GeomFormat* cpy = this->copy(); - return cpy; -} - PyObject* GeomFormat::getPyObject(void) { return new GeomFormatPy(new GeomFormat(this->copy())); } - diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h index c9df65c008..8e1dc297ab 100644 --- a/src/Mod/TechDraw/App/Cosmetic.h +++ b/src/Mod/TechDraw/App/Cosmetic.h @@ -23,6 +23,11 @@ #ifndef TECHDRAW_COSMETIC_H #define TECHDRAW_COSMETIC_H +# include + +#include +#include + #include #include @@ -57,7 +62,6 @@ public: void dump(char* title); std::string toString() const; -/* bool fromCSV(std::string& lineSpec);*/ }; class TechDrawExport CosmeticVertex: public Base::Persistence, public TechDraw::Vertex @@ -89,7 +93,16 @@ public: int style; bool visible; + boost::uuids::uuid getTag() const; + std::string getTagAsString(void) const; + + protected: + //Uniqueness + void createNewTag(); + void assignTag(const TechDraw::CosmeticVertex* cv); + + boost::uuids::uuid tag; }; @@ -123,8 +136,14 @@ public: TechDraw::BaseGeom* m_geometry; LineFormat m_format; -protected: + boost::uuids::uuid getTag() const; +protected: + //Uniqueness + void createNewTag(); + void assignTag(const TechDraw::CosmeticEdge* ce); + + boost::uuids::uuid tag; }; class TechDrawExport CenterLine: public Base::Persistence @@ -216,7 +235,13 @@ public: LineFormat m_format; bool m_flip2Line; + //Uniqueness + boost::uuids::uuid getTag() const; protected: + void createNewTag(); + void assignTag(const TechDraw::CenterLine* cl); + + boost::uuids::uuid tag; }; @@ -241,14 +266,18 @@ public: GeomFormat* clone(void) const; std::string toString(void) const; -/* bool fromCSV(std::string& lineSpec);*/ void dump(char* title) const; int m_geomIndex; LineFormat m_format; + //Uniqueness + boost::uuids::uuid getTag() const; protected: + void createNewTag(); + void assignTag(const TechDraw::GeomFormat* gf); + boost::uuids::uuid tag; }; } //end namespace TechDraw diff --git a/src/Mod/TechDraw/App/CosmeticEdgePy.xml b/src/Mod/TechDraw/App/CosmeticEdgePy.xml index dad876be13..39a8119d8c 100644 --- a/src/Mod/TechDraw/App/CosmeticEdgePy.xml +++ b/src/Mod/TechDraw/App/CosmeticEdgePy.xml @@ -36,5 +36,11 @@ returns the appearance attributes of this CometicEdge. returns tuple(style, color, weight, visible). + + + Gives the tag of the CosmeticEdge as string. + + + diff --git a/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp b/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp index c5e61c12c7..4ae3061bd3 100644 --- a/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp +++ b/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include #endif #include @@ -169,6 +170,11 @@ PyObject* CosmeticEdgePy::getFormat(PyObject *args) return result; } +Py::String CosmeticEdgePy::getTag(void) const +{ + std::string tmp = boost::uuids::to_string(getCosmeticEdgePtr()->getTag()); + return Py::String(tmp); +} PyObject *CosmeticEdgePy::getCustomAttributes(const char* /*attr*/) const { diff --git a/src/Mod/TechDraw/App/CosmeticVertexPy.xml b/src/Mod/TechDraw/App/CosmeticVertexPy.xml index e2033e5f2b..fb512c3db0 100644 --- a/src/Mod/TechDraw/App/CosmeticVertexPy.xml +++ b/src/Mod/TechDraw/App/CosmeticVertexPy.xml @@ -25,5 +25,11 @@ Create a copy of this CosmeticVertex + + + Gives the tag of the CosmeticVertex as string. + + + diff --git a/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp b/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp index 3e1fb94ece..7bab6e50de 100644 --- a/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp +++ b/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include #endif #include "Cosmetic.h" @@ -108,6 +109,12 @@ PyObject* CosmeticVertexPy::copy(PyObject *args) return cpy; } +Py::String CosmeticVertexPy::getTag(void) const +{ + std::string tmp = boost::uuids::to_string(getCosmeticVertexPtr()->getTag()); + return Py::String(tmp); +} + PyObject *CosmeticVertexPy::getCustomAttributes(const char* /*attr*/) const { return 0; diff --git a/src/Mod/TechDraw/App/GeomFormatPy.xml b/src/Mod/TechDraw/App/GeomFormatPy.xml index f0b971f2ae..2f399d425e 100644 --- a/src/Mod/TechDraw/App/GeomFormatPy.xml +++ b/src/Mod/TechDraw/App/GeomFormatPy.xml @@ -25,5 +25,11 @@ Create a copy of this geomformat + + + Gives the tag of the GeomFormat as string. + + + diff --git a/src/Mod/TechDraw/App/GeomFormatPyImp.cpp b/src/Mod/TechDraw/App/GeomFormatPyImp.cpp index c884d4f9ee..4a0d8f167b 100644 --- a/src/Mod/TechDraw/App/GeomFormatPyImp.cpp +++ b/src/Mod/TechDraw/App/GeomFormatPyImp.cpp @@ -23,37 +23,14 @@ #include "PreCompiled.h" #ifndef _PreComp_ -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include # include #endif -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include - -//#include "OCCError.h" #include "Cosmetic.h" #include "GeomFormatPy.h" #include "GeomFormatPy.cpp" -//#include "TopoShape.h" -//#include "TopoShapePy.h" - using namespace TechDraw; // returns a string which represents the object e.g. when printed in python @@ -130,6 +107,12 @@ PyObject* GeomFormatPy::copy(PyObject *args) return cpy; } +Py::String GeomFormatPy::getTag(void) const +{ + std::string tmp = boost::uuids::to_string(getGeomFormatPtr()->getTag()); + return Py::String(tmp); +} + PyObject *GeomFormatPy::getCustomAttributes(const char* /*attr*/) const { return 0; diff --git a/src/Mod/TechDraw/App/PreCompiled.h b/src/Mod/TechDraw/App/PreCompiled.h index c6bd3b8a20..9b8799a1b2 100644 --- a/src/Mod/TechDraw/App/PreCompiled.h +++ b/src/Mod/TechDraw/App/PreCompiled.h @@ -58,6 +58,7 @@ #include #include +#include // OpenCasCade ===================================================================================== #include