Move Tag to separate translation unit
- Avoid code duplication - Reduces compile time
This commit is contained in:
@@ -174,6 +174,8 @@ SET(TechDraw_SRCS
|
||||
MattingPropEnum.h
|
||||
Preferences.cpp
|
||||
Preferences.h
|
||||
Tag.cpp
|
||||
Tag.h
|
||||
TechDrawExport.cpp
|
||||
TechDrawExport.h
|
||||
ProjectionAlgos.cpp
|
||||
|
||||
@@ -23,9 +23,6 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <boost/random.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <BRepBndLib.hxx>
|
||||
#include <Bnd_Box.hxx>
|
||||
@@ -35,8 +32,6 @@
|
||||
#include <BRepTools.hxx>
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
#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<boost::mutex> guard(random_number_mutex);
|
||||
|
||||
if (!seeded) {
|
||||
ran.seed(static_cast<unsigned int>(std::time(nullptr)));
|
||||
seeded = true;
|
||||
}
|
||||
static boost::uuids::basic_random_generator<boost::mt19937> gen(&ran);
|
||||
|
||||
|
||||
tag = gen();
|
||||
}
|
||||
|
||||
CenterLine *CenterLine::clone() const
|
||||
{
|
||||
CenterLine* cpy = this->copy();
|
||||
cpy->tag = this->tag;
|
||||
cpy->setTag(this->getTag());
|
||||
|
||||
return cpy;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <Base/Vector3D.h>
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
#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
|
||||
|
||||
@@ -21,9 +21,6 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <boost/uuid/uuid_io.hpp>
|
||||
#endif
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/PyWrapParseTupleAndKeywords.h>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,12 +24,7 @@
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
# include <boost/random.hpp>
|
||||
# include <boost/uuid/uuid_generators.hpp>
|
||||
# include <boost/uuid/uuid_io.hpp>
|
||||
#endif
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Vector3D.h>
|
||||
@@ -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<boost::mutex> guard(random_number_mutex);
|
||||
|
||||
if (!seeded) {
|
||||
ran.seed(static_cast<unsigned int>(std::time(nullptr)));
|
||||
seeded = true;
|
||||
}
|
||||
static boost::uuids::basic_random_generator<boost::mt19937> 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<boost::mutex> guard(random_number_mutex);
|
||||
|
||||
if (!seeded) {
|
||||
ran.seed(static_cast<unsigned int>(std::time(nullptr)));
|
||||
seeded = true;
|
||||
}
|
||||
static boost::uuids::basic_random_generator<boost::mt19937> gen(&ran);
|
||||
|
||||
tag = gen();
|
||||
}
|
||||
|
||||
GeomFormat *GeomFormat::clone() const
|
||||
{
|
||||
GeomFormat* cpy = this->copy();
|
||||
cpy->tag = this->tag;
|
||||
cpy->setTag(this->getTag());
|
||||
return cpy;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
# include <boost/uuid/uuid_io.hpp>
|
||||
#endif
|
||||
|
||||
#include <Base/PyWrapParseTupleAndKeywords.h>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,17 +24,10 @@
|
||||
//! CosmeticVertex point is stored in unscaled, unrotated form
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <boost/random.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#endif // _PreComp_
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Persistence.h>
|
||||
#include <Base/Vector3D.h>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
#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() << "<Style value=\"" << style << "\"/>" << endl;
|
||||
const char v = visible?'1':'0';
|
||||
writer.Stream() << writer.ind() << "<Visible value=\"" << v << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<Tag value=\"" << getTagAsString() << "\"/>" << endl;
|
||||
Tag::Save(writer);
|
||||
}
|
||||
|
||||
void CosmeticVertex::Restore(Base::XMLReader &reader)
|
||||
@@ -164,11 +150,7 @@ void CosmeticVertex::Restore(Base::XMLReader &reader)
|
||||
style = reader.getAttributeAsInteger("value");
|
||||
reader.readElement("Visible");
|
||||
visible = (int)reader.getAttributeAsInteger("value")==0?false:true;
|
||||
reader.readElement("Tag");
|
||||
temp = reader.getAttribute("value");
|
||||
boost::uuids::string_generator gen;
|
||||
boost::uuids::uuid u1 = gen(temp);
|
||||
tag = u1;
|
||||
Tag::Restore(reader);
|
||||
}
|
||||
|
||||
Base::Vector3d CosmeticVertex::scaled(const double factor)
|
||||
@@ -224,37 +206,6 @@ Base::Vector3d CosmeticVertex::makeCanonicalPointInverted(DrawViewPart* dvp, Bas
|
||||
return DU::invertY(result);
|
||||
}
|
||||
|
||||
|
||||
boost::uuids::uuid CosmeticVertex::getTag() const
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
std::string CosmeticVertex::getTagAsString() const
|
||||
{
|
||||
return boost::uuids::to_string(getTag());
|
||||
}
|
||||
|
||||
void CosmeticVertex::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<boost::mutex> guard(random_number_mutex);
|
||||
|
||||
if (!seeded) {
|
||||
ran.seed(static_cast<unsigned int>(std::time(nullptr)));
|
||||
seeded = true;
|
||||
}
|
||||
static boost::uuids::basic_random_generator<boost::mt19937> gen(&ran);
|
||||
|
||||
tag = gen();
|
||||
}
|
||||
|
||||
CosmeticVertex* CosmeticVertex::copy() const
|
||||
{
|
||||
// Base::Console().Message("CV::copy()\n");
|
||||
@@ -265,7 +216,7 @@ CosmeticVertex* CosmeticVertex::clone() const
|
||||
{
|
||||
// Base::Console().Message("CV::clone()\n");
|
||||
CosmeticVertex* cpy = this->copy();
|
||||
cpy->tag = this->tag;
|
||||
cpy->setTag(this->getTag());
|
||||
return cpy;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,18 +78,8 @@ public:
|
||||
int style{1};
|
||||
bool visible{true}; //base class vertex also has visible property
|
||||
|
||||
boost::uuids::uuid getTag() const;
|
||||
std::string getTagAsString() const override;
|
||||
|
||||
protected:
|
||||
//Uniqueness
|
||||
void createNewTag();
|
||||
|
||||
boost::uuids::uuid tag;
|
||||
|
||||
Py::Object PythonObject;
|
||||
|
||||
|
||||
};
|
||||
|
||||
} //end namespace TechDraw
|
||||
|
||||
@@ -22,10 +22,6 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <boost/uuid/uuid_io.hpp>
|
||||
#endif
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/Vector3D.h>
|
||||
@@ -118,7 +114,7 @@ PyObject* CosmeticVertexPy::copy(PyObject *args)
|
||||
|
||||
Py::String CosmeticVertexPy::getTag() const
|
||||
{
|
||||
std::string tmp = boost::uuids::to_string(getCosmeticVertexPtr()->getTag());
|
||||
std::string tmp = getCosmeticVertexPtr()->getTagAsString();
|
||||
return Py::String(tmp);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,6 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <boost/uuid/uuid_io.hpp>
|
||||
#endif
|
||||
|
||||
#include "GeomFormatPy.h"
|
||||
#include "GeomFormatPy.cpp"
|
||||
@@ -107,7 +104,7 @@ PyObject* GeomFormatPy::copy(PyObject *args)
|
||||
|
||||
Py::String GeomFormatPy::getTag(void) const
|
||||
{
|
||||
std::string tmp = boost::uuids::to_string(getGeomFormatPtr()->getTag());
|
||||
std::string tmp = getGeomFormatPtr()->getTagAsString();
|
||||
return Py::String(tmp);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,6 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <boost/uuid/uuid_generators.hpp>
|
||||
# include <boost/uuid/uuid_io.hpp>
|
||||
# include <boost/random.hpp>
|
||||
# include <Approx_Curve3d.hxx>
|
||||
# include <BRep_Tool.hxx>
|
||||
# include <BRepAdaptor_Curve.hxx>
|
||||
@@ -79,8 +76,6 @@
|
||||
#include <Base/Reader.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Writer.h>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
#include <Mod/Part/App/FaceMakerCheese.h>
|
||||
#include <Mod/Part/App/Geometry.h>
|
||||
@@ -203,7 +198,6 @@ BaseGeom::BaseGeom() :
|
||||
{
|
||||
occEdge = TopoDS_Edge();
|
||||
cosmeticTag = std::string();
|
||||
tag = boost::uuids::nil_uuid();
|
||||
}
|
||||
|
||||
BaseGeomPtr BaseGeom::copy()
|
||||
@@ -244,16 +238,6 @@ std::string BaseGeom::toString() const
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
boost::uuids::uuid BaseGeom::getTag() const
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
std::string BaseGeom::getTagAsString() const
|
||||
{
|
||||
return boost::uuids::to_string(getTag());
|
||||
}
|
||||
|
||||
void BaseGeom::Save(Base::Writer &writer) const
|
||||
{
|
||||
writer.Stream() << writer.ind() << "<GeomType value=\"" << geomType << "\"/>" << endl;
|
||||
@@ -269,7 +253,6 @@ void BaseGeom::Save(Base::Writer &writer) const
|
||||
writer.Stream() << writer.ind() << "<Source value=\"" << m_source << "\"/>" << endl; // Should this save as text and not number?
|
||||
writer.Stream() << writer.ind() << "<SourceIndex value=\"" << m_sourceIndex << "\"/>" << endl;
|
||||
writer.Stream() << writer.ind() << "<CosmeticTag value=\"" << cosmeticTag << "\"/>" << endl;
|
||||
// writer.Stream() << writer.ind() << "<Tag value=\"" << getTagAsString() << "\"/>" << endl;
|
||||
}
|
||||
|
||||
void BaseGeom::Restore(Base::XMLReader &reader)
|
||||
@@ -1282,7 +1265,6 @@ Vertex::Vertex()
|
||||
cosmeticLink = -1;
|
||||
cosmeticTag = std::string();
|
||||
m_reference = false;
|
||||
createNewTag();
|
||||
}
|
||||
|
||||
Vertex::Vertex(const Vertex* v)
|
||||
@@ -1297,7 +1279,6 @@ Vertex::Vertex(const Vertex* v)
|
||||
cosmeticLink = v->cosmeticLink;
|
||||
cosmeticTag = v->cosmeticTag;
|
||||
m_reference = false;
|
||||
createNewTag();
|
||||
}
|
||||
|
||||
Vertex::Vertex(double x, double y)
|
||||
@@ -1313,7 +1294,6 @@ Vertex::Vertex(double x, double y)
|
||||
cosmeticLink = -1;
|
||||
cosmeticTag = std::string();
|
||||
m_reference = false;
|
||||
createNewTag();
|
||||
}
|
||||
|
||||
Vertex::Vertex(Base::Vector3d v) : Vertex(v.x, v.y)
|
||||
@@ -1355,7 +1335,7 @@ void Vertex::Save(Base::Writer &writer) const
|
||||
// const char r = reference?'1':'0';
|
||||
// writer.Stream() << writer.ind() << "<Reference value=\"" << r << "\"/>" << endl;
|
||||
|
||||
writer.Stream() << writer.ind() << "<VertexTag value=\"" << getTagAsString() << "\"/>" << endl;
|
||||
Tag::Save(writer);
|
||||
}
|
||||
|
||||
void Vertex::Restore(Base::XMLReader &reader)
|
||||
@@ -1384,46 +1364,12 @@ void Vertex::Restore(Base::XMLReader &reader)
|
||||
// reader.readElement("Reference");
|
||||
// m_reference = (bool)reader.getAttributeAsInteger("value")==0?false:true;
|
||||
|
||||
reader.readElement("VertexTag");
|
||||
std::string temp = reader.getAttribute("value");
|
||||
boost::uuids::string_generator gen;
|
||||
boost::uuids::uuid u1 = gen(temp);
|
||||
tag = u1;
|
||||
Tag::Restore(reader, "VertexTag");
|
||||
|
||||
BRepBuilderAPI_MakeVertex mkVert(gp_Pnt(pnt.x, pnt.y, pnt.z));
|
||||
occVertex = mkVert.Vertex();
|
||||
}
|
||||
|
||||
void Vertex::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<boost::mutex> guard(random_number_mutex);
|
||||
if (!seeded) {
|
||||
ran.seed(static_cast<unsigned int>(std::time(nullptr)));
|
||||
seeded = true;
|
||||
}
|
||||
static boost::uuids::basic_random_generator<boost::mt19937> gen(&ran);
|
||||
|
||||
tag = gen();
|
||||
}
|
||||
|
||||
|
||||
boost::uuids::uuid Vertex::getTag() const
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
std::string Vertex::getTagAsString() const
|
||||
{
|
||||
return boost::uuids::to_string(getTag());
|
||||
}
|
||||
|
||||
void Vertex::dump(const char* title)
|
||||
{
|
||||
Base::Console().Message("TD::Vertex - %s - point: %s vis: %d cosmetic: %d cosLink: %d cosTag: %s\n",
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#include <TopoDS_Vertex.hxx>
|
||||
#include <TopoDS_Wire.hxx>
|
||||
|
||||
#include "Tag.h"
|
||||
|
||||
namespace Part {
|
||||
class TopoShape;
|
||||
}
|
||||
@@ -106,7 +108,7 @@ using BSplinePtr = std::shared_ptr<BSpline>;
|
||||
class Generic;
|
||||
using GenericPtr = std::shared_ptr<Generic>;
|
||||
|
||||
class TechDrawExport BaseGeom : public std::enable_shared_from_this<BaseGeom>
|
||||
class TechDrawExport BaseGeom : public std::enable_shared_from_this<BaseGeom>, public TechDraw::Tag
|
||||
{
|
||||
public:
|
||||
BaseGeom();
|
||||
@@ -133,10 +135,6 @@ class TechDrawExport BaseGeom : public std::enable_shared_from_this<BaseGeom>
|
||||
virtual std::string toString() const;
|
||||
std::vector<Base::Vector3d> intersection(TechDraw::BaseGeomPtr geom2);
|
||||
|
||||
//Uniqueness
|
||||
boost::uuids::uuid getTag() const;
|
||||
virtual std::string getTagAsString() const;
|
||||
|
||||
std::string geomTypeName();
|
||||
BaseGeomPtr inverted();
|
||||
|
||||
@@ -169,8 +167,6 @@ class TechDrawExport BaseGeom : public std::enable_shared_from_this<BaseGeom>
|
||||
virtual void clockwiseAngle(bool direction) { (void) direction; }
|
||||
|
||||
protected:
|
||||
void createNewTag();
|
||||
|
||||
GeomType geomType;
|
||||
ExtractionType extractType; //obs
|
||||
EdgeClass classOfEdge;
|
||||
@@ -183,7 +179,6 @@ protected:
|
||||
SourceType m_source;
|
||||
int m_sourceIndex;
|
||||
std::string cosmeticTag;
|
||||
boost::uuids::uuid tag;
|
||||
|
||||
};
|
||||
using BaseGeomPtrVector = std::vector<BaseGeomPtr>; //new style
|
||||
@@ -370,7 +365,7 @@ class TechDrawExport Face
|
||||
};
|
||||
using FacePtr = std::shared_ptr<Face>;
|
||||
|
||||
class TechDrawExport Vertex
|
||||
class TechDrawExport Vertex : public TechDraw::Tag
|
||||
{
|
||||
public:
|
||||
Vertex();
|
||||
@@ -390,9 +385,6 @@ class TechDrawExport Vertex
|
||||
double x() {return pnt.x;}
|
||||
double y() {return pnt.y;}
|
||||
|
||||
boost::uuids::uuid getTag() const;
|
||||
virtual std::string getTagAsString() const;
|
||||
|
||||
// attribute setters and getters
|
||||
bool getHlrVisible() { return hlrVisible; }
|
||||
void setHlrVisible(bool state) { hlrVisible = state; }
|
||||
@@ -412,9 +404,6 @@ class TechDrawExport Vertex
|
||||
Part::TopoShape asTopoShape(double scale = 1.0);
|
||||
|
||||
protected:
|
||||
//Uniqueness
|
||||
void createNewTag();
|
||||
|
||||
Base::Vector3d pnt;
|
||||
ExtractionType extractType; //obs?
|
||||
bool hlrVisible; //visible according to HLR
|
||||
@@ -425,8 +414,6 @@ class TechDrawExport Vertex
|
||||
int cosmeticLink; //deprec. use cosmeticTag
|
||||
std::string cosmeticTag;
|
||||
bool m_reference; //reference vertex (ex robust dimension)
|
||||
|
||||
boost::uuids::uuid tag;
|
||||
};
|
||||
using VertexPtr = std::shared_ptr<Vertex>;
|
||||
|
||||
|
||||
@@ -49,9 +49,6 @@
|
||||
#include <boost/graph/is_kuratowski_subgraph.hpp>
|
||||
#include <boost/random.hpp>
|
||||
#include <boost_regex.hpp>
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
|
||||
// Qt
|
||||
#include <QApplication>
|
||||
|
||||
93
src/Mod/TechDraw/App/Tag.cpp
Normal file
93
src/Mod/TechDraw/App/Tag.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2025 WandererFan <wandererfan@gmail.com> *
|
||||
* Copyright (c) 2025 Benjamin Bræstrup Sayoc <benj5378@outlook.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <boost/random.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/lock_guard.hpp>
|
||||
#endif
|
||||
|
||||
#include <Base/Reader.h>
|
||||
#include <Base/Writer.h>
|
||||
|
||||
#include "Tag.h"
|
||||
|
||||
using namespace TechDraw;
|
||||
|
||||
Tag::Tag()
|
||||
{
|
||||
createNewTag();
|
||||
}
|
||||
|
||||
boost::uuids::uuid Tag::getTag() const
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
std::string Tag::getTagAsString() const
|
||||
{
|
||||
return boost::uuids::to_string(getTag());
|
||||
}
|
||||
|
||||
void Tag::setTag(const boost::uuids::uuid& newTag)
|
||||
{
|
||||
tag = newTag;
|
||||
}
|
||||
|
||||
void Tag::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<boost::mutex> guard(random_number_mutex);
|
||||
|
||||
if (!seeded) {
|
||||
ran.seed(static_cast<unsigned int>(std::time(nullptr)));
|
||||
seeded = true;
|
||||
}
|
||||
static boost::uuids::basic_random_generator<boost::mt19937> gen(&ran);
|
||||
|
||||
tag = gen();
|
||||
}
|
||||
|
||||
void Tag::Save(Base::Writer& writer) const
|
||||
{
|
||||
writer.Stream() << writer.ind() << "<Tag value=\"" << getTagAsString() << "\"/>" << std::endl;
|
||||
}
|
||||
|
||||
void Tag::Restore(Base::XMLReader& reader, std::string_view elementName)
|
||||
{
|
||||
// Setting elementName is only for backwards compatibility!
|
||||
reader.readElement(elementName.data());
|
||||
std::string temp = reader.getAttribute("value");
|
||||
boost::uuids::string_generator gen;
|
||||
boost::uuids::uuid u1 = gen(temp);
|
||||
tag = u1;
|
||||
}
|
||||
56
src/Mod/TechDraw/App/Tag.h
Normal file
56
src/Mod/TechDraw/App/Tag.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2025 WandererFan <wandererfan@gmail.com> *
|
||||
* Copyright (c) 2025 Benjamin Bræstrup Sayoc <benj5378@outlook.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TECHDRAW_TAG_H
|
||||
#define TECHDRAW_TAG_H
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
namespace Base {
|
||||
class XMLReader;
|
||||
class Writer;
|
||||
}
|
||||
|
||||
namespace TechDraw {
|
||||
class TechDrawExport Tag {
|
||||
public:
|
||||
//Uniqueness
|
||||
boost::uuids::uuid getTag() const;
|
||||
virtual std::string getTagAsString() const;
|
||||
|
||||
protected:
|
||||
Tag();
|
||||
void setTag(const boost::uuids::uuid& newTag);
|
||||
void Save(Base::Writer& writer) const;
|
||||
// Setting elementName is only for backwards compatibility!
|
||||
void Restore(Base::XMLReader& reader, std::string_view elementName="Tag");
|
||||
|
||||
private:
|
||||
void createNewTag();
|
||||
boost::uuids::uuid tag;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user