diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index c6a356cd2b..9c89d0aac3 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -174,6 +174,8 @@ SET(TechDraw_SRCS MattingPropEnum.h Preferences.cpp Preferences.h + Tag.cpp + Tag.h TechDrawExport.cpp TechDrawExport.h ProjectionAlgos.cpp diff --git a/src/Mod/TechDraw/App/CenterLine.cpp b/src/Mod/TechDraw/App/CenterLine.cpp index 71501f7070..640b7dc577 100644 --- a/src/Mod/TechDraw/App/CenterLine.cpp +++ b/src/Mod/TechDraw/App/CenterLine.cpp @@ -23,9 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ - #include - #include - #include #include #include #include @@ -35,8 +32,6 @@ #include #include -#include -#include #include "CenterLine.h" #include "DrawUtil.h" @@ -140,8 +135,6 @@ void CenterLine::initialize() m_geometry->setHlrVisible( true); m_geometry->setCosmetic(true); m_geometry->source(SourceType::CENTERLINE); - - createNewTag(); m_geometry->setCosmeticTag(getTagAsString()); } @@ -1062,41 +1055,10 @@ CenterLine* CenterLine::copy() const return newCL; } -boost::uuids::uuid CenterLine::getTag() const -{ - return tag; -} - -std::string CenterLine::getTagAsString() const -{ - return boost::uuids::to_string(getTag()); -} - -void CenterLine::createNewTag() -{ - // Initialize a random number generator, to avoid Valgrind false positives. - // The random number generator is not threadsafe so we guard it. See - // https://www.boost.org/doc/libs/1_62_0/libs/uuid/uuid.html#Design%20notes - static boost::mt19937 ran; - static bool seeded = false; - static boost::mutex random_number_mutex; - - boost::lock_guard guard(random_number_mutex); - - if (!seeded) { - ran.seed(static_cast(std::time(nullptr))); - seeded = true; - } - static boost::uuids::basic_random_generator gen(&ran); - - - tag = gen(); -} - CenterLine *CenterLine::clone() const { CenterLine* cpy = this->copy(); - cpy->tag = this->tag; + cpy->setTag(this->getTag()); return cpy; } diff --git a/src/Mod/TechDraw/App/CenterLine.h b/src/Mod/TechDraw/App/CenterLine.h index 8c87a32342..efdd9b6e0f 100644 --- a/src/Mod/TechDraw/App/CenterLine.h +++ b/src/Mod/TechDraw/App/CenterLine.h @@ -28,6 +28,7 @@ #include #include +#include "Tag.h" #include "Cosmetic.h" #include "Geometry.h" @@ -35,7 +36,7 @@ namespace TechDraw { class DrawViewPart; -class TechDrawExport CenterLine: public Base::Persistence +class TechDrawExport CenterLine: public Base::Persistence, public TechDraw::Tag { TYPESYSTEM_HEADER_WITH_OVERRIDE(); @@ -175,19 +176,10 @@ public: TechDraw::BaseGeomPtr m_geometry; - //Uniqueness - boost::uuids::uuid getTag() const; - virtual std::string getTagAsString() const; - protected: void initialize(); - void createNewTag(); - - boost::uuids::uuid tag; - Py::Object PythonObject; - }; } // namespace TechDraw diff --git a/src/Mod/TechDraw/App/CenterLinePyImp.cpp b/src/Mod/TechDraw/App/CenterLinePyImp.cpp index 6904e77c5e..9dda832c46 100644 --- a/src/Mod/TechDraw/App/CenterLinePyImp.cpp +++ b/src/Mod/TechDraw/App/CenterLinePyImp.cpp @@ -21,9 +21,6 @@ ***************************************************************************/ #include "PreCompiled.h" -#ifndef _PreComp_ -# include -#endif #include #include @@ -146,7 +143,7 @@ void CenterLinePy::setFormat(Py::Dict arg) Py::String CenterLinePy::getTag() const { - std::string tmp = boost::uuids::to_string(getCenterLinePtr()->getTag()); + std::string tmp = getCenterLinePtr()->getTagAsString(); return Py::String(tmp); } diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index fc9d2511ac..5a8d073200 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -24,12 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include -# include -# include -# include #endif -#include -#include #include #include @@ -115,8 +110,6 @@ void CosmeticEdge::initialize() m_geometry->setHlrVisible( true); m_geometry->setCosmetic(true); m_geometry->source(SourceType::COSMETICEDGE); - - createNewTag(); m_geometry->setCosmeticTag(getTagAsString()); } @@ -298,43 +291,13 @@ void CosmeticEdge::Restore(Base::XMLReader &reader) } } -boost::uuids::uuid CosmeticEdge::getTag() const -{ - return tag; -} - -std::string CosmeticEdge::getTagAsString() const -{ - return boost::uuids::to_string(getTag()); -} - -void CosmeticEdge::createNewTag() -{ - // Initialize a random number generator, to avoid Valgrind false positives. - // The random number generator is not threadsafe so we guard it. See - // https://www.boost.org/doc/libs/1_62_0/libs/uuid/uuid.html#Design%20notes - static boost::mt19937 ran; - static bool seeded = false; - static boost::mutex random_number_mutex; - - boost::lock_guard guard(random_number_mutex); - - if (!seeded) { - ran.seed(static_cast(std::time(nullptr))); - seeded = true; - } - static boost::uuids::basic_random_generator gen(&ran); - - tag = gen(); -} - CosmeticEdge* CosmeticEdge::clone() const { Base::Console().Message("CE::clone()\n"); CosmeticEdge* cpy = new CosmeticEdge(); cpy->m_geometry = m_geometry->copy(); cpy->m_format = m_format; - cpy->tag = this->tag; + cpy->setTag(this->getTag()); return cpy; } @@ -359,8 +322,6 @@ GeomFormat::GeomFormat() : m_format.setColor(LineFormat::getDefEdgeColor()); m_format.setVisible(true); m_format.setLineNumber(LineFormat::InvalidLine); - - createNewTag(); } GeomFormat::GeomFormat(const GeomFormat* gf) @@ -371,8 +332,6 @@ GeomFormat::GeomFormat(const GeomFormat* gf) m_format.setColor(gf->m_format.getColor()); m_format.setVisible(gf->m_format.getVisible()); m_format.setLineNumber(gf->m_format.getLineNumber()); - - createNewTag(); } GeomFormat::GeomFormat(const int idx, @@ -384,8 +343,6 @@ GeomFormat::GeomFormat(const int idx, m_format.setColor(fmt.getColor()); m_format.setVisible(fmt.getVisible()); m_format.setLineNumber(fmt.getLineNumber()); - - createNewTag(); } GeomFormat::~GeomFormat() @@ -466,40 +423,10 @@ void GeomFormat::Restore(Base::XMLReader &reader) } } -boost::uuids::uuid GeomFormat::getTag() const -{ - return tag; -} - -std::string GeomFormat::getTagAsString() const -{ - return boost::uuids::to_string(getTag()); -} - -void GeomFormat::createNewTag() -{ - // Initialize a random number generator, to avoid Valgrind false positives. - // The random number generator is not threadsafe so we guard it. See - // https://www.boost.org/doc/libs/1_62_0/libs/uuid/uuid.html#Design%20notes - static boost::mt19937 ran; - static bool seeded = false; - static boost::mutex random_number_mutex; - - boost::lock_guard guard(random_number_mutex); - - if (!seeded) { - ran.seed(static_cast(std::time(nullptr))); - seeded = true; - } - static boost::uuids::basic_random_generator gen(&ran); - - tag = gen(); -} - GeomFormat *GeomFormat::clone() const { GeomFormat* cpy = this->copy(); - cpy->tag = this->tag; + cpy->setTag(this->getTag()); return cpy; } diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h index c1ac1c0431..f86b8b9b22 100644 --- a/src/Mod/TechDraw/App/Cosmetic.h +++ b/src/Mod/TechDraw/App/Cosmetic.h @@ -81,22 +81,14 @@ public: TechDraw::BaseGeomPtr m_geometry; LineFormat m_format; - boost::uuids::uuid getTag() const; - std::string getTagAsString() const override; - protected: - //Uniqueness - void createNewTag(); - boost::uuids::uuid tag; - Py::Object PythonObject; - }; //********** GeomFormat ******************************************************** // format specifier for geometric edges (Edge5) -class TechDrawExport GeomFormat: public Base::Persistence +class TechDrawExport GeomFormat: public Base::Persistence, public TechDraw::Tag { TYPESYSTEM_HEADER_WITH_OVERRIDE(); @@ -123,14 +115,7 @@ public: int m_geomIndex; //connection to edgeGeom LineFormat m_format; - //Uniqueness - boost::uuids::uuid getTag() const; - virtual std::string getTagAsString() const; - protected: - void createNewTag(); - - boost::uuids::uuid tag; Py::Object PythonObject; }; diff --git a/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp b/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp index 5cab4be262..c989ec3881 100644 --- a/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp +++ b/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp @@ -24,7 +24,6 @@ #ifndef _PreComp_ # include -# include #endif #include @@ -152,7 +151,7 @@ Py::Dict CosmeticEdgePy::getFormat() const Py::String CosmeticEdgePy::getTag() const { - std::string tmp = boost::uuids::to_string(getCosmeticEdgePtr()->getTag()); + std::string tmp = getCosmeticEdgePtr()->getTagAsString(); return Py::String(tmp); } diff --git a/src/Mod/TechDraw/App/CosmeticVertex.cpp b/src/Mod/TechDraw/App/CosmeticVertex.cpp index 893405557a..a33e6c2dd8 100644 --- a/src/Mod/TechDraw/App/CosmeticVertex.cpp +++ b/src/Mod/TechDraw/App/CosmeticVertex.cpp @@ -24,17 +24,10 @@ //! CosmeticVertex point is stored in unscaled, unrotated form #include "PreCompiled.h" -#ifndef _PreComp_ - #include - #include - #include -#endif // _PreComp_ #include #include #include -#include -#include #include "CosmeticVertex.h" #include "CosmeticVertexPy.h" @@ -56,8 +49,6 @@ CosmeticVertex::CosmeticVertex() : TechDraw::Vertex() LineGroup::getDefaultWidth("Thin"); hlrVisible = true; cosmetic = true; - - createNewTag(); } CosmeticVertex::CosmeticVertex(const TechDraw::CosmeticVertex* cv) : TechDraw::Vertex(cv) @@ -70,8 +61,6 @@ CosmeticVertex::CosmeticVertex(const TechDraw::CosmeticVertex* cv) : TechDraw::V visible = cv->visible; hlrVisible = true; cosmetic = true; - - createNewTag(); } CosmeticVertex::CosmeticVertex(const Base::Vector3d& loc) : TechDraw::Vertex(loc) @@ -85,9 +74,6 @@ CosmeticVertex::CosmeticVertex(const Base::Vector3d& loc) : TechDraw::Vertex(loc visible = true; hlrVisible = true; cosmetic = true; - - createNewTag(); - } void CosmeticVertex::move(const Base::Vector3d& newPos) @@ -140,7 +126,7 @@ void CosmeticVertex::Save(Base::Writer &writer) const writer.Stream() << writer.ind() << "