[TD] avoid memory leaks by using shared_ptr
TD geometry objects are sometimes double deleted. This change uses shared_ptr instead of raw pointers to manage deletions.
This commit is contained in:
committed by
WandererFan
parent
4c9191d489
commit
e91cc8e329
@@ -344,14 +344,14 @@ CosmeticEdge::CosmeticEdge()
|
||||
{
|
||||
// Base::Console().Message("CE::CE()\n");
|
||||
permaRadius = 0.0;
|
||||
m_geometry = new TechDraw::BaseGeom();
|
||||
m_geometry = std::make_shared<TechDraw::BaseGeom> ();
|
||||
initialize();
|
||||
}
|
||||
|
||||
CosmeticEdge::CosmeticEdge(CosmeticEdge* ce)
|
||||
{
|
||||
// Base::Console().Message("CE::CE(ce)\n");
|
||||
TechDraw::BaseGeom* newGeom = ce->m_geometry->copy();
|
||||
TechDraw::BaseGeomPtr newGeom = ce->m_geometry->copy();
|
||||
//these endpoints are already YInverted
|
||||
permaStart = ce->permaStart;
|
||||
permaEnd = ce->permaEnd;
|
||||
@@ -384,7 +384,7 @@ CosmeticEdge::CosmeticEdge(TopoDS_Edge e)
|
||||
permaEnd = m_geometry->getEndPoint();
|
||||
if ((m_geometry->geomType == TechDraw::GeomType::CIRCLE) ||
|
||||
(m_geometry->geomType == TechDraw::GeomType::ARCOFCIRCLE) ) {
|
||||
TechDraw::Circle* circ = static_cast<TechDraw::Circle*>(m_geometry);
|
||||
TechDraw::CirclePtr circ = std::static_pointer_cast<TechDraw::Circle>(m_geometry);
|
||||
permaStart = circ->center;
|
||||
permaEnd = circ->center;
|
||||
permaRadius = circ->radius;
|
||||
@@ -392,7 +392,7 @@ CosmeticEdge::CosmeticEdge(TopoDS_Edge e)
|
||||
initialize();
|
||||
}
|
||||
|
||||
CosmeticEdge::CosmeticEdge(TechDraw::BaseGeom* g)
|
||||
CosmeticEdge::CosmeticEdge(TechDraw::BaseGeomPtr g)
|
||||
{
|
||||
// Base::Console().Message("CE::CE(bg)\n");
|
||||
m_geometry = g;
|
||||
@@ -400,7 +400,7 @@ CosmeticEdge::CosmeticEdge(TechDraw::BaseGeom* g)
|
||||
permaEnd = m_geometry->getEndPoint();
|
||||
if ((g->geomType == TechDraw::GeomType::CIRCLE) ||
|
||||
(g->geomType == TechDraw::GeomType::ARCOFCIRCLE)) {
|
||||
TechDraw::Circle* circ = static_cast<TechDraw::Circle*>(g);
|
||||
TechDraw::CirclePtr circ = std::static_pointer_cast<TechDraw::Circle>(g);
|
||||
permaStart = circ->center;
|
||||
permaEnd = circ->center;
|
||||
permaRadius = circ->radius;
|
||||
@@ -410,9 +410,7 @@ CosmeticEdge::CosmeticEdge(TechDraw::BaseGeom* g)
|
||||
|
||||
CosmeticEdge::~CosmeticEdge(void)
|
||||
{
|
||||
if (m_geometry != nullptr) {
|
||||
delete m_geometry;
|
||||
}
|
||||
//shared pointer will delete m_geometry when ref count goes to zero.
|
||||
}
|
||||
|
||||
void CosmeticEdge::initialize(void)
|
||||
@@ -426,9 +424,9 @@ void CosmeticEdge::initialize(void)
|
||||
m_geometry->setCosmeticTag(getTagAsString());
|
||||
}
|
||||
|
||||
TechDraw::BaseGeom* CosmeticEdge::scaledGeometry(double scale)
|
||||
TechDraw::BaseGeomPtr CosmeticEdge::scaledGeometry(double scale)
|
||||
{
|
||||
TechDraw::BaseGeom* newGeom = nullptr;
|
||||
TechDraw::BaseGeomPtr newGeom = nullptr;
|
||||
TopoDS_Edge e = m_geometry->occEdge;
|
||||
TopoDS_Shape s = TechDraw::scaleShape(e, scale);
|
||||
TopoDS_Edge newEdge = TopoDS::Edge(s);
|
||||
@@ -477,13 +475,13 @@ void CosmeticEdge::Save(Base::Writer &writer) const
|
||||
|
||||
writer.Stream() << writer.ind() << "<GeometryType value=\"" << m_geometry->geomType <<"\"/>" << endl;
|
||||
if (m_geometry->geomType == TechDraw::GeomType::GENERIC) {
|
||||
Generic* gen = static_cast<Generic*>(m_geometry);
|
||||
GenericPtr gen = std::static_pointer_cast<Generic>(m_geometry);
|
||||
gen->Save(writer);
|
||||
} else if (m_geometry->geomType == TechDraw::GeomType::CIRCLE) {
|
||||
TechDraw::Circle* circ = static_cast<TechDraw::Circle*>(m_geometry);
|
||||
TechDraw::CirclePtr circ = std::static_pointer_cast<TechDraw::Circle>(m_geometry);
|
||||
circ->Save(writer);
|
||||
} else if (m_geometry->geomType == TechDraw::GeomType::ARCOFCIRCLE) {
|
||||
TechDraw::AOC* aoc = static_cast<TechDraw::AOC*>(m_geometry);
|
||||
TechDraw::AOCPtr aoc = std::static_pointer_cast<TechDraw::AOC>(m_geometry);
|
||||
aoc->Save(writer);
|
||||
} else {
|
||||
Base::Console().Warning("CE::Save - unimplemented geomType: %d\n", m_geometry->geomType);
|
||||
@@ -509,25 +507,25 @@ void CosmeticEdge::Restore(Base::XMLReader &reader)
|
||||
TechDraw::GeomType gType = (TechDraw::GeomType)reader.getAttributeAsInteger("value");
|
||||
|
||||
if (gType == TechDraw::GeomType::GENERIC) {
|
||||
TechDraw::Generic* gen = new TechDraw::Generic();
|
||||
TechDraw::GenericPtr gen = std::make_shared<TechDraw::Generic> ();
|
||||
gen->Restore(reader);
|
||||
gen->occEdge = GeometryUtils::edgeFromGeneric(gen);
|
||||
m_geometry = (TechDraw::BaseGeom*) gen;
|
||||
m_geometry = (TechDraw::BaseGeomPtr) gen;
|
||||
permaStart = gen->getStartPoint();
|
||||
permaEnd = gen->getEndPoint();
|
||||
} else if (gType == TechDraw::GeomType::CIRCLE) {
|
||||
TechDraw::Circle* circ = new TechDraw::Circle();
|
||||
TechDraw::CirclePtr circ = std::make_shared<TechDraw::Circle> ();
|
||||
circ->Restore(reader);
|
||||
circ->occEdge = GeometryUtils::edgeFromCircle(circ);
|
||||
m_geometry = (TechDraw::BaseGeom*) circ;
|
||||
m_geometry = (TechDraw::BaseGeomPtr) circ;
|
||||
permaRadius = circ->radius;
|
||||
permaStart = circ->center;
|
||||
permaEnd = circ->center;
|
||||
} else if (gType == TechDraw::GeomType::ARCOFCIRCLE) {
|
||||
TechDraw::AOC* aoc = new TechDraw::AOC();
|
||||
TechDraw::AOCPtr aoc = std::make_shared<TechDraw::AOC> ();
|
||||
aoc->Restore(reader);
|
||||
aoc->occEdge = GeometryUtils::edgeFromCircleArc(aoc);
|
||||
m_geometry = (TechDraw::BaseGeom*) aoc;
|
||||
m_geometry = (TechDraw::BaseGeomPtr) aoc;
|
||||
permaStart = aoc->startPnt;
|
||||
permaEnd = aoc->endPnt;
|
||||
permaRadius = aoc->radius;
|
||||
@@ -574,7 +572,7 @@ CosmeticEdge* CosmeticEdge::copy(void) const
|
||||
{
|
||||
// Base::Console().Message("CE::copy()\n");
|
||||
CosmeticEdge* newCE = new CosmeticEdge();
|
||||
TechDraw::BaseGeom* newGeom = m_geometry->copy();
|
||||
TechDraw::BaseGeomPtr newGeom = m_geometry->copy();
|
||||
newCE->m_geometry = newGeom;
|
||||
newCE->m_format = m_format;
|
||||
return newCE;
|
||||
@@ -614,7 +612,7 @@ CenterLine::CenterLine(void)
|
||||
m_type = CLTYPE::FACE;
|
||||
m_flip2Line = false;
|
||||
|
||||
m_geometry = new TechDraw::BaseGeom();
|
||||
m_geometry = std::make_shared<TechDraw::BaseGeom> ();
|
||||
|
||||
initialize();
|
||||
}
|
||||
@@ -636,7 +634,7 @@ CenterLine::CenterLine(TechDraw::CenterLine* cl)
|
||||
initialize();
|
||||
}
|
||||
|
||||
CenterLine::CenterLine(TechDraw::BaseGeom* bg)
|
||||
CenterLine::CenterLine(TechDraw::BaseGeomPtr bg)
|
||||
{
|
||||
m_start = bg->getStartPoint();
|
||||
m_end = bg->getEndPoint();
|
||||
@@ -774,7 +772,7 @@ CenterLine* CenterLine::CenterLineBuilder(DrawViewPart* partFeat,
|
||||
return cl;
|
||||
}
|
||||
|
||||
TechDraw::BaseGeom* CenterLine::scaledGeometry(TechDraw::DrawViewPart* partFeat)
|
||||
TechDraw::BaseGeomPtr CenterLine::scaledGeometry(TechDraw::DrawViewPart* partFeat)
|
||||
{
|
||||
// Base::Console().Message("CL::scaledGeometry() - m_type: %d\n", m_type);
|
||||
double scale = partFeat->getScale();
|
||||
@@ -812,7 +810,7 @@ TechDraw::BaseGeom* CenterLine::scaledGeometry(TechDraw::DrawViewPart* partFeat)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TechDraw::BaseGeom* newGeom = nullptr;
|
||||
TechDraw::BaseGeomPtr newGeom = nullptr;
|
||||
Base::Vector3d p1 = ends.first;
|
||||
Base::Vector3d p2 = ends.second;
|
||||
if (!p1.IsEqual(p2, 0.00001)) {
|
||||
@@ -896,7 +894,7 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints(DrawViewPart
|
||||
continue;
|
||||
}
|
||||
int idx = TechDraw::DrawUtil::getIndexFromName(fn);
|
||||
std::vector<TechDraw::BaseGeom*> faceEdges =
|
||||
std::vector<TechDraw::BaseGeomPtr> faceEdges =
|
||||
partFeat->getFaceEdgesByIndex(idx);
|
||||
if (!faceEdges.empty()) {
|
||||
for (auto& fe: faceEdges) {
|
||||
@@ -1013,15 +1011,15 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Lines(DrawVi
|
||||
}
|
||||
|
||||
double scale = partFeat->getScale();
|
||||
const std::vector<TechDraw::BaseGeom*> dbEdges = partFeat->getEdgeGeometry();
|
||||
const std::vector<TechDraw::BaseGeomPtr> dbEdges = partFeat->getEdgeGeometry();
|
||||
|
||||
std::vector<TechDraw::BaseGeom*> edges;
|
||||
std::vector<TechDraw::BaseGeomPtr> edges;
|
||||
for (auto& en: edgeNames) {
|
||||
if (TechDraw::DrawUtil::getGeomTypeFromName(en) != "Edge") {
|
||||
continue;
|
||||
}
|
||||
int idx = TechDraw::DrawUtil::getIndexFromName(en);
|
||||
TechDraw::BaseGeom* bg = partFeat->getGeomByIndex(idx);
|
||||
TechDraw::BaseGeomPtr bg = partFeat->getGeomByIndex(idx);
|
||||
if (bg != nullptr) {
|
||||
edges.push_back(bg);
|
||||
} else {
|
||||
@@ -1287,13 +1285,13 @@ void CenterLine::Save(Base::Writer &writer) const
|
||||
if (m_geometry != nullptr) {
|
||||
writer.Stream() << writer.ind() << "<GeometryType value=\"" << m_geometry->geomType <<"\"/>" << endl;
|
||||
if (m_geometry->geomType == TechDraw::GeomType::GENERIC) {
|
||||
Generic* gen = static_cast<Generic*>(m_geometry);
|
||||
GenericPtr gen = std::static_pointer_cast<Generic>(m_geometry);
|
||||
gen->Save(writer);
|
||||
} else if (m_geometry->geomType == TechDraw::GeomType::CIRCLE) {
|
||||
TechDraw::Circle* circ = static_cast<TechDraw::Circle*>(m_geometry);
|
||||
TechDraw::CirclePtr circ = std::static_pointer_cast<TechDraw::Circle>(m_geometry);
|
||||
circ->Save(writer);
|
||||
} else if (m_geometry->geomType == TechDraw::GeomType::ARCOFCIRCLE) {
|
||||
TechDraw::AOC* aoc = static_cast<TechDraw::AOC*>(m_geometry);
|
||||
TechDraw::AOCPtr aoc = std::static_pointer_cast<TechDraw::AOC>(m_geometry);
|
||||
aoc->Save(writer);
|
||||
} else {
|
||||
Base::Console().Message("CL::Save - unimplemented geomType: %d\n", m_geometry->geomType);
|
||||
@@ -1385,20 +1383,20 @@ void CenterLine::Restore(Base::XMLReader &reader)
|
||||
reader.readElement("GeometryType");
|
||||
TechDraw::GeomType gType = (TechDraw::GeomType)reader.getAttributeAsInteger("value");
|
||||
if (gType == TechDraw::GeomType::GENERIC) {
|
||||
TechDraw::Generic* gen = new TechDraw::Generic();
|
||||
TechDraw::GenericPtr gen = std::make_shared<TechDraw::Generic> ();
|
||||
gen->Restore(reader);
|
||||
gen->occEdge = GeometryUtils::edgeFromGeneric(gen);
|
||||
m_geometry = (TechDraw::BaseGeom*) gen;
|
||||
m_geometry = gen;
|
||||
} else if (gType == TechDraw::GeomType::CIRCLE) {
|
||||
TechDraw::Circle* circ = new TechDraw::Circle();
|
||||
TechDraw::CirclePtr circ = std::make_shared<TechDraw::Circle> ();
|
||||
circ->Restore(reader);
|
||||
circ->occEdge = GeometryUtils::edgeFromCircle(circ);
|
||||
m_geometry = (TechDraw::BaseGeom*) circ;
|
||||
m_geometry = circ;
|
||||
} else if (gType == TechDraw::GeomType::ARCOFCIRCLE) {
|
||||
TechDraw::AOC* aoc = new TechDraw::AOC();
|
||||
TechDraw::AOCPtr aoc = std::make_shared<TechDraw::AOC> ();
|
||||
aoc->Restore(reader);
|
||||
aoc->occEdge = GeometryUtils::edgeFromCircleArc(aoc);
|
||||
m_geometry = (TechDraw::BaseGeom*) aoc;
|
||||
m_geometry = aoc;
|
||||
} else {
|
||||
Base::Console().Warning("CL::Restore - unimplemented geomType: %d\n", gType);
|
||||
}
|
||||
@@ -1421,7 +1419,7 @@ CenterLine* CenterLine::copy(void) const
|
||||
newCL->m_edges = m_edges;
|
||||
newCL->m_verts = m_verts;
|
||||
|
||||
TechDraw::BaseGeom* newGeom = m_geometry->copy();
|
||||
TechDraw::BaseGeomPtr newGeom = m_geometry->copy();
|
||||
newCL->m_geometry = newGeom;
|
||||
|
||||
newCL->m_format = m_format;
|
||||
|
||||
@@ -128,11 +128,11 @@ public:
|
||||
CosmeticEdge(CosmeticEdge* ce);
|
||||
CosmeticEdge(Base::Vector3d p1, Base::Vector3d p2);
|
||||
CosmeticEdge(TopoDS_Edge e);
|
||||
CosmeticEdge(TechDraw::BaseGeom* g);
|
||||
CosmeticEdge(TechDraw::BaseGeomPtr g);
|
||||
virtual ~CosmeticEdge();
|
||||
|
||||
void initialize(void);
|
||||
TechDraw::BaseGeom* scaledGeometry(double scale);
|
||||
TechDraw::BaseGeomPtr scaledGeometry(double scale);
|
||||
|
||||
virtual std::string toString(void) const;
|
||||
void dump(const char* title);
|
||||
@@ -150,7 +150,7 @@ public:
|
||||
Base::Vector3d permaEnd;
|
||||
double permaRadius;
|
||||
// void unscaleEnds(double scale);
|
||||
TechDraw::BaseGeom* m_geometry;
|
||||
TechDraw::BaseGeomPtr m_geometry;
|
||||
LineFormat m_format;
|
||||
|
||||
boost::uuids::uuid getTag() const;
|
||||
@@ -176,7 +176,7 @@ public:
|
||||
CenterLine();
|
||||
CenterLine(CenterLine* cl);
|
||||
//set m_faces after using next 3 ctors
|
||||
CenterLine(TechDraw::BaseGeom* bg);
|
||||
CenterLine(TechDraw::BaseGeomPtr bg);
|
||||
CenterLine(Base::Vector3d p1, Base::Vector3d p2);
|
||||
CenterLine(Base::Vector3d p1, Base::Vector3d p2,
|
||||
int m,
|
||||
@@ -213,7 +213,7 @@ public:
|
||||
std::vector<std::string> subs,
|
||||
int mode = 0,
|
||||
bool flip = false);
|
||||
TechDraw::BaseGeom* scaledGeometry(TechDraw::DrawViewPart* partFeat);
|
||||
TechDraw::BaseGeomPtr scaledGeometry(TechDraw::DrawViewPart* partFeat);
|
||||
static std::pair<Base::Vector3d, Base::Vector3d> calcEndPoints(
|
||||
TechDraw::DrawViewPart* partFeat,
|
||||
std::vector<std::string> faceNames,
|
||||
@@ -260,7 +260,7 @@ public:
|
||||
LineFormat m_format;
|
||||
bool m_flip2Line;
|
||||
|
||||
TechDraw::BaseGeom* m_geometry;
|
||||
TechDraw::BaseGeomPtr m_geometry;
|
||||
|
||||
//Uniqueness
|
||||
boost::uuids::uuid getTag() const;
|
||||
|
||||
@@ -193,7 +193,7 @@ Py::String CosmeticEdgePy::getTag(void) const
|
||||
// py-aware class.
|
||||
//Py::Object CosmeticEdgePy::getGeometry(void) const
|
||||
//{
|
||||
//// TechDraw::BaseGeom* bg = getCosmeticEdgePtr()->m_geometry;
|
||||
//// TechDraw::BaseGeomPtr bg = getCosmeticEdgePtr()->m_geometry;
|
||||
// Base::Console().Message("Not implemented yet");
|
||||
// return Py::asObject(Py_None);
|
||||
//}
|
||||
@@ -239,10 +239,10 @@ void CosmeticEdgePy::setStart(Py::Object arg)
|
||||
gp_Pnt gp1(pNew.x,pNew.y,pNew.z);
|
||||
gp_Pnt gp2(pEnd.x,pEnd.y,pEnd.z);
|
||||
TopoDS_Edge e = BRepBuilderAPI_MakeEdge(gp1, gp2);
|
||||
auto oldGeom = getCosmeticEdgePtr()->m_geometry;
|
||||
// auto oldGeom = getCosmeticEdgePtr()->m_geometry;
|
||||
getCosmeticEdgePtr()->m_geometry = TechDraw::BaseGeom::baseFactory(e);
|
||||
getCosmeticEdgePtr()->permaStart = pNew;
|
||||
delete oldGeom;
|
||||
// delete oldGeom;
|
||||
}
|
||||
|
||||
Py::Object CosmeticEdgePy::getEnd(void) const
|
||||
@@ -273,10 +273,10 @@ void CosmeticEdgePy::setEnd(Py::Object arg)
|
||||
gp_Pnt gp1(pNew.x,pNew.y,pNew.z);
|
||||
gp_Pnt gp2(pStart.x,pStart.y,pStart.z);
|
||||
TopoDS_Edge e = BRepBuilderAPI_MakeEdge(gp2, gp1);
|
||||
auto oldGeom = getCosmeticEdgePtr()->m_geometry;
|
||||
// auto oldGeom = getCosmeticEdgePtr()->m_geometry;
|
||||
getCosmeticEdgePtr()->m_geometry = TechDraw::BaseGeom::baseFactory(e);
|
||||
getCosmeticEdgePtr()->permaEnd = pNew;
|
||||
delete oldGeom;
|
||||
// delete oldGeom;
|
||||
}
|
||||
|
||||
Py::Object CosmeticEdgePy::getRadius(void) const
|
||||
@@ -316,9 +316,10 @@ void CosmeticEdgePy::setRadius(Py::Object arg)
|
||||
}
|
||||
|
||||
getCosmeticEdgePtr()->permaRadius = r;
|
||||
auto oldGeom = getCosmeticEdgePtr()->m_geometry;
|
||||
getCosmeticEdgePtr()->m_geometry = new TechDraw::Circle(getCosmeticEdgePtr()->permaStart, r);
|
||||
delete oldGeom;
|
||||
// auto oldGeom = getCosmeticEdgePtr()->m_geometry;
|
||||
getCosmeticEdgePtr()->m_geometry =
|
||||
std::make_shared<TechDraw::Circle> (getCosmeticEdgePtr()->permaStart, r);
|
||||
// delete oldGeom;
|
||||
}
|
||||
|
||||
Py::Object CosmeticEdgePy::getCenter(void) const
|
||||
@@ -361,7 +362,7 @@ void CosmeticEdgePy::setCenter(Py::Object arg)
|
||||
|
||||
pNew = DrawUtil::invertY(pNew);
|
||||
auto oldGeom = getCosmeticEdgePtr()->m_geometry;
|
||||
TechDraw::Circle* oldCircle = dynamic_cast<TechDraw::Circle*>(oldGeom);
|
||||
TechDraw::CirclePtr oldCircle = std::dynamic_pointer_cast<TechDraw::Circle> (oldGeom);
|
||||
if (oldCircle == nullptr) {
|
||||
throw Py::TypeError("Edge geometry is not a circle");
|
||||
}
|
||||
@@ -369,8 +370,9 @@ void CosmeticEdgePy::setCenter(Py::Object arg)
|
||||
getCosmeticEdgePtr()->permaStart = pNew;
|
||||
getCosmeticEdgePtr()->permaEnd = pNew;
|
||||
getCosmeticEdgePtr()->permaRadius = oldCircle->radius;
|
||||
getCosmeticEdgePtr()->m_geometry = new TechDraw::Circle(getCosmeticEdgePtr()->permaStart, oldCircle->radius);
|
||||
delete oldGeom;
|
||||
getCosmeticEdgePtr()->m_geometry =
|
||||
std::make_shared<TechDraw::Circle> (getCosmeticEdgePtr()->permaStart, oldCircle->radius);
|
||||
// delete oldGeom;
|
||||
}
|
||||
|
||||
PyObject *CosmeticEdgePy::getCustomAttributes(const char* /*attr*/) const
|
||||
|
||||
@@ -179,7 +179,7 @@ std::string CosmeticExtension::addCosmeticEdge(Base::Vector3d start,
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string CosmeticExtension::addCosmeticEdge(TechDraw::BaseGeom* bg)
|
||||
std::string CosmeticExtension::addCosmeticEdge(TechDraw::BaseGeomPtr bg)
|
||||
{
|
||||
// Base::Console().Message("CEx::addCosmeticEdge(bg: %X)\n", bg);
|
||||
std::vector<CosmeticEdge*> edges = CosmeticEdges.getValues();
|
||||
@@ -223,7 +223,7 @@ TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdgeBySelection(std::strin
|
||||
return result;
|
||||
}
|
||||
int idx = DrawUtil::getIndexFromName(name);
|
||||
TechDraw::BaseGeom* base = dvp->getGeomByIndex(idx);
|
||||
TechDraw::BaseGeomPtr base = dvp->getGeomByIndex(idx);
|
||||
if (base == nullptr) {
|
||||
return result;
|
||||
}
|
||||
@@ -301,7 +301,7 @@ std::string CosmeticExtension::addCenterLine(TechDraw::CenterLine* cl)
|
||||
}
|
||||
|
||||
|
||||
std::string CosmeticExtension::addCenterLine(TechDraw::BaseGeom* bg)
|
||||
std::string CosmeticExtension::addCenterLine(TechDraw::BaseGeomPtr bg)
|
||||
{
|
||||
// Base::Console().Message("CEx::addCenterLine(bg: %X)\n", bg);
|
||||
std::vector<CenterLine*> cLines = CenterLines.getValues();
|
||||
@@ -341,7 +341,7 @@ TechDraw::CenterLine* CosmeticExtension::getCenterLineBySelection(std::string na
|
||||
return result;
|
||||
}
|
||||
int idx = DrawUtil::getIndexFromName(name);
|
||||
TechDraw::BaseGeom* base = dvp->getGeomByIndex(idx);
|
||||
TechDraw::BaseGeomPtr base = dvp->getGeomByIndex(idx);
|
||||
if (base == nullptr) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
virtual void removeCosmeticVertex(std::vector<std::string> delTags);
|
||||
|
||||
virtual std::string addCosmeticEdge(Base::Vector3d start, Base::Vector3d end);
|
||||
virtual std::string addCosmeticEdge(TechDraw::BaseGeom* bg);
|
||||
virtual std::string addCosmeticEdge(TechDraw::BaseGeomPtr bg);
|
||||
virtual CosmeticEdge* getCosmeticEdgeBySelection(std::string name) const;
|
||||
virtual CosmeticEdge* getCosmeticEdgeBySelection(int i) const;
|
||||
virtual CosmeticEdge* getCosmeticEdge(std::string id) const;
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
|
||||
virtual std::string addCenterLine(Base::Vector3d start, Base::Vector3d end);
|
||||
virtual std::string addCenterLine(TechDraw::CenterLine* cl);
|
||||
virtual std::string addCenterLine(TechDraw::BaseGeom* bg);
|
||||
virtual std::string addCenterLine(TechDraw::BaseGeomPtr bg);
|
||||
virtual CenterLine* getCenterLineBySelection(std::string name) const;
|
||||
virtual CenterLine* getCenterLineBySelection(int i) const;
|
||||
virtual CenterLine* getCenterLine(std::string tag) const;
|
||||
|
||||
@@ -166,14 +166,14 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawDimHelper::minMax(DrawViewPart* dv
|
||||
gp_Ax3 projAx3(stdOrg, stdZ, stdX);
|
||||
gp_Pln projPlane(projAx3); // OZX
|
||||
|
||||
std::vector<BaseGeom*> bgList;
|
||||
BaseGeomPtrVector bgList;
|
||||
if (!edgeNames.empty()) {
|
||||
for (auto& n: edgeNames) {
|
||||
if (!n.empty()) {
|
||||
std::string geomType = DrawUtil::getGeomTypeFromName(n);
|
||||
if (!n.empty() && (geomType == "Edge")) {
|
||||
int i = DrawUtil::getIndexFromName(n);
|
||||
BaseGeom* bg = dvp->getGeomByIndex(i);
|
||||
BaseGeomPtr bg = dvp->getGeomByIndex(i);
|
||||
if (bg != nullptr) {
|
||||
bgList.push_back(bg);
|
||||
}
|
||||
@@ -182,7 +182,7 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawDimHelper::minMax(DrawViewPart* dv
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<BaseGeom*> selEdges = bgList;
|
||||
BaseGeomPtrVector selEdges = bgList;
|
||||
if (selEdges.empty()) {
|
||||
selEdges = dvp->getEdgeGeometry(); //do the whole View
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class TechDrawExport hTrimCurve {
|
||||
class TechDrawExport DrawDimHelper {
|
||||
public:
|
||||
static void makeExtentDim(DrawViewPart* dvp,
|
||||
// std::vector<TechDraw::BaseGeom*> selEdges,
|
||||
// std::vector<TechDraw::BaseGeomPtr> selEdges,
|
||||
std::vector<std::string> edgeNames,
|
||||
int direction);
|
||||
static gp_Pnt2d findClosestPoint(std::vector<hTrimCurve> hCurve2dList,
|
||||
|
||||
@@ -328,10 +328,10 @@ std::vector<LineSet> DrawGeomHatch::getTrimmedLines(DrawViewPart* source,
|
||||
resultEdges.push_back(edge);
|
||||
}
|
||||
|
||||
std::vector<TechDraw::BaseGeom*> resultGeoms;
|
||||
std::vector<TechDraw::BaseGeomPtr> resultGeoms;
|
||||
int i = 0;
|
||||
for (auto& e: resultEdges) {
|
||||
TechDraw::BaseGeom* base = BaseGeom::baseFactory(e);
|
||||
TechDraw::BaseGeomPtr base = BaseGeom::baseFactory(e);
|
||||
if (base == nullptr) {
|
||||
Base::Console().Log("FAIL - DGH::getTrimmedLines - baseFactory failed for edge: %d\n",i);
|
||||
throw Base::ValueError("DGH::getTrimmedLines - baseFactory failed");
|
||||
@@ -477,10 +477,10 @@ std::vector<LineSet> DrawGeomHatch::getFaceOverlay(int fdx)
|
||||
for (auto& ls: m_lineSets) {
|
||||
PATLineSpec hl = ls.getPATLineSpec();
|
||||
std::vector<TopoDS_Edge> candidates = DrawGeomHatch::makeEdgeOverlay(hl, bBox, ScalePattern.getValue());
|
||||
std::vector<TechDraw::BaseGeom*> resultGeoms;
|
||||
std::vector<TechDraw::BaseGeomPtr> resultGeoms;
|
||||
int i = 0;
|
||||
for (auto& e: candidates) {
|
||||
TechDraw::BaseGeom* base = BaseGeom::baseFactory(e);
|
||||
TechDraw::BaseGeomPtr base = BaseGeom::baseFactory(e);
|
||||
if (base == nullptr) {
|
||||
Base::Console().Log("FAIL - DGH::getFaceOverlay - baseFactory failed for edge: %d\n",i);
|
||||
throw Base::ValueError("DGH::getFaceOverlay - baseFactory failed");
|
||||
|
||||
@@ -117,7 +117,8 @@ App::DocumentObjectExecReturn *DrawParametricTemplate::execute(void)
|
||||
|
||||
int DrawParametricTemplate::drawLine(double x1, double y1, double x2, double y2)
|
||||
{
|
||||
TechDraw::Generic *line = new TechDraw::Generic();
|
||||
// TechDraw::GenericPtr line = new TechDraw::Generic();
|
||||
TechDraw::GenericPtr line(new TechDraw::Generic());
|
||||
|
||||
line->points.emplace_back(x1, y1);
|
||||
line->points.emplace_back(x2, y2);
|
||||
@@ -128,10 +129,7 @@ int DrawParametricTemplate::drawLine(double x1, double y1, double x2, double y2)
|
||||
|
||||
int DrawParametricTemplate::clearGeometry()
|
||||
{
|
||||
for(std::vector<TechDraw::BaseGeom *>::iterator it = geom.begin(); it != geom.end(); ++it) {
|
||||
delete *it;
|
||||
*it = 0;
|
||||
}
|
||||
//smart pointer will delete old geoms when ref count goes to zero?
|
||||
geom.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <App/PropertyFile.h>
|
||||
#include <App/FeaturePython.h>
|
||||
|
||||
#include "Geometry.h"
|
||||
#include "DrawTemplate.h"
|
||||
|
||||
namespace TechDraw
|
||||
@@ -67,7 +68,7 @@ public:
|
||||
virtual unsigned int getMemSize(void) const;
|
||||
|
||||
public:
|
||||
std::vector<TechDraw::BaseGeom *> getGeometry() { return geom; }
|
||||
std::vector<TechDraw::BaseGeomPtr> getGeometry() { return geom; }
|
||||
int clearGeometry();
|
||||
|
||||
// Template Drawing Methods
|
||||
@@ -80,7 +81,7 @@ protected:
|
||||
void onChanged(const App::Property* prop);
|
||||
|
||||
protected:
|
||||
std::vector<TechDraw::BaseGeom *> geom;
|
||||
std::vector<TechDraw::BaseGeomPtr> geom;
|
||||
|
||||
private:
|
||||
static const char* OrientationEnums[];
|
||||
|
||||
@@ -149,8 +149,8 @@ TechDraw::GeometryObject* DrawProjectSplit::buildGeometryObject(TopoDS_Shape sha
|
||||
//! get the projected edges with all their new intersections.
|
||||
std::vector<TopoDS_Edge> DrawProjectSplit::getEdges(TechDraw::GeometryObject* geometryObject)
|
||||
{
|
||||
const std::vector<TechDraw::BaseGeom*>& goEdges = geometryObject->getVisibleFaceEdges(true,true);
|
||||
std::vector<TechDraw::BaseGeom*>::const_iterator itEdge = goEdges.begin();
|
||||
const std::vector<TechDraw::BaseGeomPtr>& goEdges = geometryObject->getVisibleFaceEdges(true,true);
|
||||
std::vector<TechDraw::BaseGeomPtr>::const_iterator itEdge = goEdges.begin();
|
||||
std::vector<TopoDS_Edge> origEdges;
|
||||
for (;itEdge != goEdges.end(); itEdge++) {
|
||||
origEdges.push_back((*itEdge)->occEdge);
|
||||
|
||||
@@ -419,18 +419,19 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
m_hasGeometry = true;
|
||||
} else if (Type.isValue("Radius")){
|
||||
int idx = DrawUtil::getIndexFromName(subElements[0]);
|
||||
TechDraw::BaseGeom* base = getViewPart()->getGeomByIndex(idx);
|
||||
TechDraw::Circle* circle;
|
||||
TechDraw::BaseGeomPtr base = getViewPart()->getGeomByIndex(idx);
|
||||
TechDraw::CirclePtr circle;
|
||||
arcPoints pts;
|
||||
pts.center = Base::Vector3d(0.0,0.0,0.0);
|
||||
pts.radius = 0.0;
|
||||
if ( (base && base->geomType == TechDraw::GeomType::CIRCLE) ||
|
||||
(base && base->geomType == TechDraw::GeomType::ARCOFCIRCLE)) {
|
||||
circle = static_cast<TechDraw::Circle*> (base);
|
||||
circle = std::static_pointer_cast<TechDraw::Circle> (base);
|
||||
pts.center = Base::Vector3d(circle->center.x,circle->center.y,0.0);
|
||||
pts.radius = circle->radius;
|
||||
if (base->geomType == TechDraw::GeomType::ARCOFCIRCLE) {
|
||||
TechDraw::AOC* aoc = static_cast<TechDraw::AOC*> (circle);
|
||||
// TechDraw::AOCPtr aoc = std::static_pointer_cast<TechDraw::AOC> (circle);
|
||||
TechDraw::AOCPtr aoc = std::static_pointer_cast<TechDraw::AOC> (base);
|
||||
pts.isArc = true;
|
||||
pts.onCurve.first = Base::Vector3d(aoc->midPnt.x,aoc->midPnt.y,0.0);
|
||||
pts.midArc = Base::Vector3d(aoc->midPnt.x,aoc->midPnt.y,0.0);
|
||||
@@ -444,7 +445,8 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
}
|
||||
} else if ((base && base->geomType == TechDraw::GeomType::ELLIPSE) ||
|
||||
(base && base->geomType == TechDraw::GeomType::ARCOFELLIPSE)) {
|
||||
TechDraw::Ellipse* ellipse = static_cast<TechDraw::Ellipse*> (base);
|
||||
TechDraw::EllipsePtr ellipse;
|
||||
ellipse = std::static_pointer_cast<TechDraw::Ellipse> (base);
|
||||
if (ellipse->closed()) {
|
||||
double r1 = ellipse->minor;
|
||||
double r2 = ellipse->major;
|
||||
@@ -457,7 +459,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
pts.onCurve.first = pts.center + Base::Vector3d(1,0,0) * rAvg; //arbitrary point on edge
|
||||
pts.onCurve.second = pts.center + Base::Vector3d(-1,0,0) * rAvg; //arbitrary point on edge
|
||||
} else {
|
||||
TechDraw::AOE* aoe = static_cast<TechDraw::AOE*> (base);
|
||||
TechDraw::AOEPtr aoe = std::static_pointer_cast<TechDraw::AOE> (base);
|
||||
double r1 = aoe->minor;
|
||||
double r2 = aoe->major;
|
||||
double rAvg = (r1 + r2) / 2.0;
|
||||
@@ -474,7 +476,8 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
pts.onCurve.second = pts.center + Base::Vector3d(-1,0,0) * rAvg; //arbitrary point on edge
|
||||
}
|
||||
} else if (base && base->geomType == TechDraw::GeomType::BSPLINE) {
|
||||
TechDraw::BSpline* spline = static_cast<TechDraw::BSpline*> (base);
|
||||
TechDraw::BSplinePtr spline;
|
||||
spline = std::static_pointer_cast<TechDraw::BSpline> (base);
|
||||
if (spline->isCircle()) {
|
||||
bool circ,arc;
|
||||
double rad;
|
||||
@@ -506,18 +509,18 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
m_hasGeometry = true;
|
||||
} else if (Type.isValue("Diameter")){
|
||||
int idx = DrawUtil::getIndexFromName(subElements[0]);
|
||||
TechDraw::BaseGeom* base = getViewPart()->getGeomByIndex(idx);
|
||||
TechDraw::Circle* circle;
|
||||
TechDraw::BaseGeomPtr base = getViewPart()->getGeomByIndex(idx);
|
||||
TechDraw::CirclePtr circle;
|
||||
arcPoints pts;
|
||||
pts.center = Base::Vector3d(0.0,0.0,0.0);
|
||||
pts.radius = 0.0;
|
||||
if ((base && base->geomType == TechDraw::GeomType::CIRCLE) ||
|
||||
(base && base->geomType == TechDraw::GeomType::ARCOFCIRCLE)) {
|
||||
circle = static_cast<TechDraw::Circle*> (base);
|
||||
circle = std::static_pointer_cast<TechDraw::Circle> (base);
|
||||
pts.center = Base::Vector3d(circle->center.x,circle->center.y,0.0);
|
||||
pts.radius = circle->radius;
|
||||
if (base->geomType == TechDraw::GeomType::ARCOFCIRCLE) {
|
||||
TechDraw::AOC* aoc = static_cast<TechDraw::AOC*> (circle);
|
||||
TechDraw::AOCPtr aoc = std::static_pointer_cast<TechDraw::AOC> (circle);
|
||||
pts.isArc = true;
|
||||
pts.onCurve.first = Base::Vector3d(aoc->midPnt.x,aoc->midPnt.y,0.0);
|
||||
pts.midArc = Base::Vector3d(aoc->midPnt.x,aoc->midPnt.y,0.0);
|
||||
@@ -531,7 +534,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
}
|
||||
} else if ( (base && base->geomType == TechDraw::GeomType::ELLIPSE) ||
|
||||
(base && base->geomType == TechDraw::GeomType::ARCOFELLIPSE) ) {
|
||||
TechDraw::Ellipse* ellipse = static_cast<TechDraw::Ellipse*> (base);
|
||||
TechDraw::EllipsePtr ellipse = std::static_pointer_cast<TechDraw::Ellipse> (base);
|
||||
if (ellipse->closed()) {
|
||||
double r1 = ellipse->minor;
|
||||
double r2 = ellipse->major;
|
||||
@@ -544,7 +547,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
pts.onCurve.first = pts.center + Base::Vector3d(1,0,0) * rAvg; //arbitrary point on edge
|
||||
pts.onCurve.second = pts.center + Base::Vector3d(-1,0,0) * rAvg; //arbitrary point on edge
|
||||
} else {
|
||||
TechDraw::AOE* aoe = static_cast<TechDraw::AOE*> (base);
|
||||
TechDraw::AOEPtr aoe = std::static_pointer_cast<TechDraw::AOE> (base);
|
||||
double r1 = aoe->minor;
|
||||
double r2 = aoe->major;
|
||||
double rAvg = (r1 + r2) / 2.0;
|
||||
@@ -561,7 +564,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
pts.onCurve.second = pts.center + Base::Vector3d(-1,0,0) * rAvg; //arbitrary point on edge
|
||||
}
|
||||
} else if (base && base->geomType == TechDraw::GeomType::BSPLINE) {
|
||||
TechDraw::BSpline* spline = static_cast<TechDraw::BSpline*> (base);
|
||||
TechDraw::BSplinePtr spline = std::static_pointer_cast<TechDraw::BSpline> (base);
|
||||
if (spline->isCircle()) {
|
||||
bool circ,arc;
|
||||
double rad;
|
||||
@@ -598,18 +601,18 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
||||
}
|
||||
int idx0 = DrawUtil::getIndexFromName(subElements[0]);
|
||||
int idx1 = DrawUtil::getIndexFromName(subElements[1]);
|
||||
TechDraw::BaseGeom* edge0 = getViewPart()->getGeomByIndex(idx0);
|
||||
TechDraw::BaseGeom* edge1 = getViewPart()->getGeomByIndex(idx1);
|
||||
TechDraw::Generic *gen0;
|
||||
TechDraw::Generic *gen1;
|
||||
TechDraw::BaseGeomPtr edge0 = getViewPart()->getGeomByIndex(idx0);
|
||||
TechDraw::BaseGeomPtr edge1 = getViewPart()->getGeomByIndex(idx1);
|
||||
TechDraw::GenericPtr gen0;
|
||||
TechDraw::GenericPtr gen1;
|
||||
if (edge0 && edge0->geomType == TechDraw::GeomType::GENERIC) {
|
||||
gen0 = static_cast<TechDraw::Generic*>(edge0);
|
||||
gen0 = std::static_pointer_cast<TechDraw::Generic>(edge0);
|
||||
} else {
|
||||
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
if (edge1 && edge1->geomType == TechDraw::GeomType::GENERIC) {
|
||||
gen1 = static_cast<TechDraw::Generic*>(edge1);
|
||||
gen1 = std::static_pointer_cast<TechDraw::Generic>(edge1);
|
||||
} else {
|
||||
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
return App::DocumentObject::StdReturn;
|
||||
@@ -1094,10 +1097,10 @@ pointPair DrawViewDimension::getPointsOneEdge()
|
||||
|
||||
//TODO: Check for straight line Edge?
|
||||
int idx = DrawUtil::getIndexFromName(subElements[0]);
|
||||
TechDraw::BaseGeom* geom = getViewPart()->getGeomByIndex(idx);
|
||||
TechDraw::Generic* gen;
|
||||
TechDraw::BaseGeomPtr geom = getViewPart()->getGeomByIndex(idx);
|
||||
TechDraw::GenericPtr gen;
|
||||
if (geom && geom->geomType == TechDraw::GeomType::GENERIC) {
|
||||
gen = static_cast<TechDraw::Generic*>(geom);
|
||||
gen = std::static_pointer_cast<TechDraw::Generic>(geom);
|
||||
} else {
|
||||
Base::Console().Error("Error: DVD - %s - 2D references are corrupt (1)\n",getNameInDocument());
|
||||
return result;
|
||||
@@ -1115,8 +1118,8 @@ pointPair DrawViewDimension::getPointsTwoEdges()
|
||||
|
||||
int idx0 = DrawUtil::getIndexFromName(subElements[0]);
|
||||
int idx1 = DrawUtil::getIndexFromName(subElements[1]);
|
||||
TechDraw::BaseGeom* geom0 = getViewPart()->getGeomByIndex(idx0);
|
||||
TechDraw::BaseGeom* geom1 = getViewPart()->getGeomByIndex(idx1);
|
||||
TechDraw::BaseGeomPtr geom0 = getViewPart()->getGeomByIndex(idx0);
|
||||
TechDraw::BaseGeomPtr geom1 = getViewPart()->getGeomByIndex(idx1);
|
||||
if ((geom0 == nullptr) ||
|
||||
(geom1 == nullptr) ) {
|
||||
Base::Console().Error("Error: DVD - %s - 2D references are corrupt (2)\n",getNameInDocument());
|
||||
@@ -1152,7 +1155,7 @@ pointPair DrawViewDimension::getPointsEdgeVert()
|
||||
const std::vector<std::string> &subElements = References2D.getSubValues();
|
||||
int idx0 = DrawUtil::getIndexFromName(subElements[0]);
|
||||
int idx1 = DrawUtil::getIndexFromName(subElements[1]);
|
||||
TechDraw::BaseGeom* e;
|
||||
TechDraw::BaseGeomPtr e;
|
||||
TechDraw::VertexPtr v;
|
||||
if (DrawUtil::getGeomTypeFromName(subElements[0]) == "Edge") {
|
||||
e = getViewPart()->getGeomByIndex(idx0);
|
||||
@@ -1216,7 +1219,7 @@ bool DrawViewDimension::checkReferences2D() const
|
||||
if (!s.empty()) {
|
||||
int idx = DrawUtil::getIndexFromName(s);
|
||||
if (DrawUtil::getGeomTypeFromName(s) == "Edge") {
|
||||
TechDraw::BaseGeom* geom = getViewPart()->getGeomByIndex(idx);
|
||||
TechDraw::BaseGeomPtr geom = getViewPart()->getGeomByIndex(idx);
|
||||
if (geom == nullptr) {
|
||||
result = false;
|
||||
break;
|
||||
@@ -1331,14 +1334,14 @@ bool DrawViewDimension::leaderIntersectsArc(Base::Vector3d s, Base::Vector3d poi
|
||||
bool result = false;
|
||||
const std::vector<std::string> &subElements = References2D.getSubValues();
|
||||
int idx = DrawUtil::getIndexFromName(subElements[0]);
|
||||
TechDraw::BaseGeom* base = getViewPart()->getGeomByIndex(idx);
|
||||
TechDraw::BaseGeomPtr base = getViewPart()->getGeomByIndex(idx);
|
||||
if ( base && base->geomType == TechDraw::GeomType::ARCOFCIRCLE ) {
|
||||
TechDraw::AOC* aoc = static_cast<TechDraw::AOC*> (base);
|
||||
TechDraw::AOCPtr aoc = std::static_pointer_cast<TechDraw::AOC> (base);
|
||||
if (aoc->intersectsArc(s,pointOnCircle)) {
|
||||
result = true;
|
||||
}
|
||||
} else if ( base && base->geomType == TechDraw::GeomType::BSPLINE ) {
|
||||
TechDraw::BSpline* spline = static_cast<TechDraw::BSpline*> (base);
|
||||
TechDraw::BSplinePtr spline = std::static_pointer_cast<TechDraw::BSpline> (base);
|
||||
if (spline->isCircle()) {
|
||||
if (spline->intersectsArc(s,pointOnCircle)) {
|
||||
result = true;
|
||||
|
||||
@@ -402,7 +402,7 @@ void DrawViewPart::addShapes2d(void)
|
||||
// getScale());
|
||||
// TopoDS_Shape sMirror = TechDraw::mirrorShape(sScale);
|
||||
// TopoDS_Edge edge = TopoDS::Edge(sMirror);
|
||||
// BaseGeom* bg = projectEdge(edge);
|
||||
// BaseGeomPtr bg = projectEdge(edge);
|
||||
|
||||
// geometryObject->addEdge(bg);
|
||||
//save connection between source feat and this edge
|
||||
@@ -494,7 +494,7 @@ TechDraw::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape shape,
|
||||
false);
|
||||
}
|
||||
|
||||
const std::vector<TechDraw::BaseGeom *> & edges = go->getEdgeGeometry();
|
||||
const BaseGeomPtrVector& edges = go->getEdgeGeometry();
|
||||
if (edges.empty()) {
|
||||
Base::Console().Log("DVP::buildGO - NO extracted edges!\n");
|
||||
}
|
||||
@@ -509,9 +509,9 @@ void DrawViewPart::extractFaces()
|
||||
return;
|
||||
}
|
||||
geometryObject->clearFaceGeom();
|
||||
const std::vector<TechDraw::BaseGeom*>& goEdges =
|
||||
const std::vector<TechDraw::BaseGeomPtr>& goEdges =
|
||||
geometryObject->getVisibleFaceEdges(SmoothVisible.getValue(),SeamVisible.getValue());
|
||||
std::vector<TechDraw::BaseGeom*>::const_iterator itEdge = goEdges.begin();
|
||||
std::vector<TechDraw::BaseGeomPtr>::const_iterator itEdge = goEdges.begin();
|
||||
std::vector<TopoDS_Edge> origEdges;
|
||||
for (;itEdge != goEdges.end(); itEdge++) {
|
||||
origEdges.push_back((*itEdge)->occEdge);
|
||||
@@ -706,9 +706,9 @@ const std::vector<TechDraw::FacePtr> DrawViewPart::getFaceGeometry() const
|
||||
return result;
|
||||
}
|
||||
|
||||
const std::vector<TechDraw::BaseGeom*> DrawViewPart::getEdgeGeometry() const
|
||||
const BaseGeomPtrVector DrawViewPart::getEdgeGeometry() const
|
||||
{
|
||||
std::vector<TechDraw::BaseGeom *> result;
|
||||
BaseGeomPtrVector result;
|
||||
if (geometryObject != nullptr) {
|
||||
result = geometryObject->getEdgeGeometry();
|
||||
}
|
||||
@@ -716,9 +716,9 @@ const std::vector<TechDraw::BaseGeom*> DrawViewPart::getEdgeGeometry() const
|
||||
}
|
||||
|
||||
//! returns existing BaseGeom of 2D Edge(idx)
|
||||
TechDraw::BaseGeom* DrawViewPart::getGeomByIndex(int idx) const
|
||||
TechDraw::BaseGeomPtr DrawViewPart::getGeomByIndex(int idx) const
|
||||
{
|
||||
const std::vector<TechDraw::BaseGeom *> &geoms = getEdgeGeometry();
|
||||
const std::vector<TechDraw::BaseGeomPtr> &geoms = getEdgeGeometry();
|
||||
if (geoms.empty()) {
|
||||
Base::Console().Log("INFO - getGeomByIndex(%d) - no Edge Geometry. Probably restoring?\n",idx);
|
||||
return NULL;
|
||||
@@ -765,9 +765,9 @@ TechDraw::VertexPtr DrawViewPart::getProjVertexByCosTag(std::string cosTag)
|
||||
|
||||
|
||||
//! returns existing geometry of 2D Face(idx)
|
||||
std::vector<TechDraw::BaseGeom*> DrawViewPart::getFaceEdgesByIndex(int idx) const
|
||||
std::vector<TechDraw::BaseGeomPtr> DrawViewPart::getFaceEdgesByIndex(int idx) const
|
||||
{
|
||||
std::vector<TechDraw::BaseGeom*> result;
|
||||
std::vector<TechDraw::BaseGeomPtr> result;
|
||||
const std::vector<TechDraw::FacePtr>& faces = getFaceGeometry();
|
||||
if (idx < (int) faces.size()) {
|
||||
TechDraw::FacePtr projFace = faces.at(idx);
|
||||
@@ -851,7 +851,7 @@ Base::Vector3d DrawViewPart::projectPoint(const Base::Vector3d& pt, bool invert)
|
||||
|
||||
//project a loose edge onto the paper plane
|
||||
//TODO:: loose edges not supported yet
|
||||
BaseGeom* DrawViewPart::projectEdge(const TopoDS_Edge& e) const
|
||||
BaseGeomPtr DrawViewPart::projectEdge(const TopoDS_Edge& e) const
|
||||
{
|
||||
Base::Vector3d stdOrg(0.0,0.0,0.0);
|
||||
gp_Ax2 viewAxis = getProjectionCS(stdOrg);
|
||||
@@ -863,8 +863,7 @@ BaseGeom* DrawViewPart::projectEdge(const TopoDS_Edge& e) const
|
||||
projector.Build();
|
||||
TopoDS_Shape s = projector.Projection();
|
||||
// Base::Console().Message("DVP::projectEdge - s.IsNull: %d\n", s.IsNull());
|
||||
// BaseGeom* result = BaseGeom::baseFactory(pe);
|
||||
BaseGeom* result = nullptr;
|
||||
BaseGeomPtr result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -875,7 +874,7 @@ bool DrawViewPart::hasGeometry(void) const
|
||||
return result;
|
||||
}
|
||||
const std::vector<TechDraw::VertexPtr> &verts = getVertexGeometry();
|
||||
const std::vector<TechDraw::BaseGeom*> &edges = getEdgeGeometry();
|
||||
const std::vector<TechDraw::BaseGeomPtr> &edges = getEdgeGeometry();
|
||||
if (verts.empty() &&
|
||||
edges.empty() ) {
|
||||
result = false;
|
||||
@@ -955,7 +954,7 @@ std::vector<DrawViewDetail*> DrawViewPart::getDetailRefs(void) const
|
||||
return result;
|
||||
}
|
||||
|
||||
const std::vector<TechDraw::BaseGeom *> DrawViewPart::getVisibleFaceEdges() const
|
||||
const BaseGeomPtrVector DrawViewPart::getVisibleFaceEdges() const
|
||||
{
|
||||
return geometryObject->getVisibleFaceEdges(SmoothVisible.getValue(),SeamVisible.getValue());
|
||||
}
|
||||
@@ -1268,7 +1267,7 @@ void DrawViewPart::addCosmeticEdgesToGeom(void)
|
||||
// Base::Console().Message("CEx::addCosmeticEdgesToGeom()\n");
|
||||
const std::vector<TechDraw::CosmeticEdge*> cEdges = CosmeticEdges.getValues();
|
||||
for (auto& ce: cEdges) {
|
||||
TechDraw::BaseGeom* scaledGeom = ce->scaledGeometry(getScale());
|
||||
TechDraw::BaseGeomPtr scaledGeom = ce->scaledGeometry(getScale());
|
||||
if (scaledGeom == nullptr) {
|
||||
continue;
|
||||
}
|
||||
@@ -1286,7 +1285,7 @@ int DrawViewPart::add1CEToGE(std::string tag)
|
||||
Base::Console().Message("CEx::add1CEToGE 2 - ce %s not found\n", tag.c_str());
|
||||
return -1;
|
||||
}
|
||||
TechDraw::BaseGeom* scaledGeom = ce->scaledGeometry(getScale());
|
||||
TechDraw::BaseGeomPtr scaledGeom = ce->scaledGeometry(getScale());
|
||||
int iGE = geometryObject->addCosmeticEdge(scaledGeom,
|
||||
tag);
|
||||
|
||||
@@ -1297,8 +1296,8 @@ int DrawViewPart::add1CEToGE(std::string tag)
|
||||
void DrawViewPart::refreshCEGeoms(void)
|
||||
{
|
||||
// Base::Console().Message("DVP::refreshCEGeoms()\n");
|
||||
std::vector<TechDraw::BaseGeom *> gEdges = getEdgeGeometry();
|
||||
std::vector<TechDraw::BaseGeom *> oldGEdges;
|
||||
std::vector<TechDraw::BaseGeomPtr> gEdges = getEdgeGeometry();
|
||||
std::vector<TechDraw::BaseGeomPtr> oldGEdges;
|
||||
for (auto& ge :gEdges) {
|
||||
if (ge->source() != SourceType::COSEDGE) {
|
||||
oldGEdges.push_back(ge);
|
||||
@@ -1324,7 +1323,7 @@ int DrawViewPart::add1CLToGE(std::string tag)
|
||||
Base::Console().Message("CEx::add1CLToGE 2 - cl %s not found\n", tag.c_str());
|
||||
return -1;
|
||||
}
|
||||
TechDraw::BaseGeom* scaledGeom = cl->scaledGeometry(this);
|
||||
TechDraw::BaseGeomPtr scaledGeom = cl->scaledGeometry(this);
|
||||
int iGE = geometryObject->addCenterLine(scaledGeom,
|
||||
tag);
|
||||
|
||||
@@ -1335,8 +1334,8 @@ int DrawViewPart::add1CLToGE(std::string tag)
|
||||
void DrawViewPart::refreshCLGeoms(void)
|
||||
{
|
||||
// Base::Console().Message("DVP::refreshCLGeoms()\n");
|
||||
std::vector<TechDraw::BaseGeom *> gEdges = getEdgeGeometry();
|
||||
std::vector<TechDraw::BaseGeom *> newGEdges;
|
||||
std::vector<TechDraw::BaseGeomPtr> gEdges = getEdgeGeometry();
|
||||
std::vector<TechDraw::BaseGeomPtr> newGEdges;
|
||||
for (auto& ge :gEdges) {
|
||||
if (ge->source() != SourceType::CENTERLINE) {
|
||||
newGEdges.push_back(ge);
|
||||
@@ -1352,7 +1351,7 @@ void DrawViewPart::addCenterLinesToGeom(void)
|
||||
// Base::Console().Message("DVP::addCenterLinesToGeom()\n");
|
||||
const std::vector<TechDraw::CenterLine*> lines = CenterLines.getValues();
|
||||
for (auto& cl: lines) {
|
||||
TechDraw::BaseGeom* scaledGeom = cl->scaledGeometry(this);
|
||||
TechDraw::BaseGeomPtr scaledGeom = cl->scaledGeometry(this);
|
||||
if (scaledGeom == nullptr) {
|
||||
Base::Console().Error("DVP::addCenterLinesToGeom - scaledGeometry is null\n");
|
||||
continue;
|
||||
|
||||
@@ -126,17 +126,17 @@ public:
|
||||
std::vector<TechDraw::DrawViewBalloon*> getBalloons() const;
|
||||
|
||||
const std::vector<TechDraw::VertexPtr> getVertexGeometry() const;
|
||||
const std::vector<TechDraw::BaseGeom*> getEdgeGeometry() const;
|
||||
const std::vector<TechDraw::BaseGeom*> getVisibleFaceEdges() const;
|
||||
const BaseGeomPtrVector getEdgeGeometry() const;
|
||||
const BaseGeomPtrVector getVisibleFaceEdges() const;
|
||||
const std::vector<TechDraw::FacePtr> getFaceGeometry() const;
|
||||
|
||||
bool hasGeometry(void) const;
|
||||
TechDraw::GeometryObject* getGeometryObject(void) const { return geometryObject; }
|
||||
|
||||
TechDraw::BaseGeom* getGeomByIndex(int idx) const; //get existing geom for edge idx in projection
|
||||
TechDraw::BaseGeomPtr getGeomByIndex(int idx) const; //get existing geom for edge idx in projection
|
||||
TechDraw::VertexPtr getProjVertexByIndex(int idx) const; //get existing geom for vertex idx in projection
|
||||
TechDraw::VertexPtr getProjVertexByCosTag(std::string cosTag);
|
||||
std::vector<TechDraw::BaseGeom*> getFaceEdgesByIndex(int idx) const; //get edges for face idx in projection
|
||||
std::vector<TechDraw::BaseGeomPtr> getFaceEdgesByIndex(int idx) const; //get edges for face idx in projection
|
||||
|
||||
virtual Base::BoundBox3d getBoundingBox() const;
|
||||
double getBoxX(void) const;
|
||||
@@ -148,7 +148,7 @@ public:
|
||||
|
||||
virtual Base::Vector3d projectPoint(const Base::Vector3d& pt,
|
||||
bool invert = true) const;
|
||||
virtual BaseGeom* projectEdge(const TopoDS_Edge& e) const;
|
||||
virtual BaseGeomPtr projectEdge(const TopoDS_Edge& e) const;
|
||||
|
||||
virtual gp_Ax2 getViewAxis(const Base::Vector3d& pt,
|
||||
const Base::Vector3d& direction,
|
||||
|
||||
@@ -78,7 +78,7 @@ PyObject* DrawViewPartPy::getVisibleEdges(PyObject *args)
|
||||
(void) args;
|
||||
DrawViewPart* dvp = getDrawViewPartPtr();
|
||||
Py::List pEdgeList;
|
||||
std::vector<TechDraw::BaseGeom*> geoms = dvp->getEdgeGeometry();
|
||||
std::vector<TechDraw::BaseGeomPtr> geoms = dvp->getEdgeGeometry();
|
||||
for (auto& g: geoms) {
|
||||
if (g->hlrVisible) {
|
||||
PyObject* pEdge = new Part::TopoShapeEdgePy(new Part::TopoShape(g->occEdge));
|
||||
@@ -94,7 +94,7 @@ PyObject* DrawViewPartPy::getHiddenEdges(PyObject *args)
|
||||
(void) args;
|
||||
DrawViewPart* dvp = getDrawViewPartPtr();
|
||||
Py::List pEdgeList;
|
||||
std::vector<TechDraw::BaseGeom*> geoms = dvp->getEdgeGeometry();
|
||||
std::vector<TechDraw::BaseGeomPtr> geoms = dvp->getEdgeGeometry();
|
||||
for (auto& g: geoms) {
|
||||
if (!g->hlrVisible) {
|
||||
PyObject* pEdge = new Part::TopoShapeEdgePy(new Part::TopoShape(g->occEdge));
|
||||
@@ -392,7 +392,7 @@ PyObject* DrawViewPartPy::makeCosmeticCircle(PyObject *args)
|
||||
|
||||
DrawViewPart* dvp = getDrawViewPartPtr();
|
||||
Base::Vector3d pnt1 = DrawUtil::invertY(static_cast<Base::VectorPy*>(pPnt1)->value());
|
||||
TechDraw::BaseGeom* bg = new TechDraw::Circle(pnt1, radius);
|
||||
TechDraw::BaseGeomPtr bg = std::make_shared<TechDraw::Circle> (pnt1, radius);
|
||||
std::string newTag = dvp->addCosmeticEdge(bg);
|
||||
TechDraw::CosmeticEdge* ce = dvp->getCosmeticEdge(newTag);
|
||||
if (ce != nullptr) {
|
||||
@@ -435,7 +435,7 @@ PyObject* DrawViewPartPy::makeCosmeticCircleArc(PyObject *args)
|
||||
//from here on is almost duplicate of makeCosmeticCircle
|
||||
DrawViewPart* dvp = getDrawViewPartPtr();
|
||||
Base::Vector3d pnt1 = DrawUtil::invertY(static_cast<Base::VectorPy*>(pPnt1)->value());
|
||||
TechDraw::BaseGeom* bg = new TechDraw::AOC(pnt1, radius, angle1, angle2);
|
||||
TechDraw::BaseGeomPtr bg = std::make_shared<TechDraw::AOC> (pnt1, radius, angle1, angle2);
|
||||
std::string newTag = dvp->addCosmeticEdge(bg);
|
||||
TechDraw::CosmeticEdge* ce = dvp->getCosmeticEdge(newTag);
|
||||
if (ce != nullptr) {
|
||||
@@ -698,7 +698,7 @@ PyObject* DrawViewPartPy::getEdgeByIndex(PyObject *args)
|
||||
|
||||
//this is scaled and +Yup
|
||||
//need unscaled and +Ydown
|
||||
TechDraw::BaseGeom* geom = dvp->getGeomByIndex(edgeIndex);
|
||||
TechDraw::BaseGeomPtr geom = dvp->getGeomByIndex(edgeIndex);
|
||||
if (geom == nullptr) {
|
||||
throw Py::ValueError("wrong edgeIndex");
|
||||
}
|
||||
@@ -746,7 +746,7 @@ PyObject* DrawViewPartPy::getEdgeBySelection(PyObject *args)
|
||||
|
||||
//this is scaled and +Yup
|
||||
//need unscaled and +Ydown
|
||||
TechDraw::BaseGeom* geom = dvp->getGeomByIndex(edgeIndex);
|
||||
TechDraw::BaseGeomPtr geom = dvp->getGeomByIndex(edgeIndex);
|
||||
if (geom == nullptr) {
|
||||
throw Py::ValueError("wrong edgeIndex");
|
||||
}
|
||||
|
||||
@@ -521,7 +521,7 @@ void DrawViewSection::sectionExec(TopoDS_Shape baseShape)
|
||||
for ( ; expWire.More(); expWire.Next()) {
|
||||
iedge++;
|
||||
const TopoDS_Edge& edge = TopoDS::Edge(expWire.Current());
|
||||
TechDraw::BaseGeom* e = BaseGeom::baseFactory(edge);
|
||||
TechDraw::BaseGeomPtr e = BaseGeom::baseFactory(edge);
|
||||
if (e != nullptr) {
|
||||
w->geoms.push_back(e);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ Wire::Wire(const TopoDS_Wire &w)
|
||||
TopExp_Explorer edges(w, TopAbs_EDGE);
|
||||
for (; edges.More(); edges.Next()) {
|
||||
const auto edge( TopoDS::Edge(edges.Current()) );
|
||||
BaseGeom* bg = BaseGeom::baseFactory(edge);
|
||||
BaseGeomPtr bg = BaseGeom::baseFactory(edge);
|
||||
if (bg != nullptr) {
|
||||
geoms.push_back(bg);
|
||||
} else {
|
||||
@@ -117,9 +117,7 @@ Wire::Wire(const TopoDS_Wire &w)
|
||||
|
||||
Wire::~Wire()
|
||||
{
|
||||
for(auto it : geoms) {
|
||||
delete it;
|
||||
}
|
||||
//shared_ptr to geoms should free memory when ref count goes to zero
|
||||
geoms.clear();
|
||||
}
|
||||
|
||||
@@ -186,9 +184,9 @@ BaseGeom::BaseGeom() :
|
||||
cosmeticTag = std::string();
|
||||
}
|
||||
|
||||
BaseGeom* BaseGeom::copy()
|
||||
BaseGeomPtr BaseGeom::copy()
|
||||
{
|
||||
BaseGeom* result = nullptr;
|
||||
BaseGeomPtr result;
|
||||
if (!occEdge.IsNull()) {
|
||||
result = baseFactory(occEdge);
|
||||
if (result != nullptr) {
|
||||
@@ -203,7 +201,7 @@ BaseGeom* BaseGeom::copy()
|
||||
result->cosmeticTag = cosmeticTag;
|
||||
}
|
||||
} else {
|
||||
result = new BaseGeom();
|
||||
result = std::make_shared<BaseGeom>();
|
||||
result->extractType = extractType;
|
||||
result->classOfEdge = classOfEdge;
|
||||
result->hlrVisible = hlrVisible;
|
||||
@@ -388,7 +386,7 @@ double BaseGeom::minDist(Base::Vector3d p)
|
||||
}
|
||||
|
||||
//!find point on me nearest to p
|
||||
Base::Vector3d BaseGeom::nearPoint(const BaseGeom* p)
|
||||
Base::Vector3d BaseGeom::nearPoint(const BaseGeomPtr p)
|
||||
{
|
||||
Base::Vector3d result(0.0, 0.0, 0.0);
|
||||
TopoDS_Edge pEdge = p->occEdge;
|
||||
@@ -449,9 +447,8 @@ bool BaseGeom::closed(void)
|
||||
|
||||
|
||||
//! Convert 1 OCC edge into 1 BaseGeom (static factory method)
|
||||
BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
|
||||
BaseGeomPtr BaseGeom::baseFactory(TopoDS_Edge edge)
|
||||
{
|
||||
std::unique_ptr<BaseGeom> result;
|
||||
if (edge.IsNull()) {
|
||||
Base::Console().Message("BG::baseFactory - input edge is NULL \n");
|
||||
}
|
||||
@@ -460,7 +457,7 @@ BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
result = std::make_unique<Generic>(edge);
|
||||
BaseGeomPtr result = std::make_shared<Generic> (edge);
|
||||
|
||||
BRepAdaptor_Curve adapt(edge);
|
||||
switch(adapt.GetType()) {
|
||||
@@ -474,9 +471,9 @@ BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
|
||||
//if first to last is > 1 radian? are circles parameterize by rotation angle?
|
||||
//if start and end points are close?
|
||||
if (fabs(l-f) > 1.0 && s.SquareDistance(e) < 0.001) {
|
||||
result = std::make_unique<Circle>(edge);
|
||||
result = std::make_shared<Circle>(edge);
|
||||
} else {
|
||||
result = std::make_unique<AOC>(edge);
|
||||
result = std::make_shared<AOC>(edge);
|
||||
}
|
||||
} break;
|
||||
case GeomAbs_Ellipse: {
|
||||
@@ -485,15 +482,15 @@ BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
|
||||
gp_Pnt s = adapt.Value(f);
|
||||
gp_Pnt e = adapt.Value(l);
|
||||
if (fabs(l-f) > 1.0 && s.SquareDistance(e) < 0.001) {
|
||||
result = std::make_unique<Ellipse>(edge);
|
||||
result = std::make_shared<Ellipse>(edge);
|
||||
} else {
|
||||
result = std::make_unique<AOE>(edge);
|
||||
result = std::make_shared<AOE>(edge);
|
||||
}
|
||||
} break;
|
||||
case GeomAbs_BezierCurve: {
|
||||
Handle(Geom_BezierCurve) bez = adapt.Bezier();
|
||||
//if (bez->Degree() < 4) {
|
||||
result = std::make_unique<BezierSegment>(edge);
|
||||
result = std::make_shared<BezierSegment>(edge);
|
||||
if (edge.Orientation() == TopAbs_REVERSED) {
|
||||
result->reversed = true;
|
||||
}
|
||||
@@ -501,25 +498,24 @@ BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
|
||||
// OCC is quite happy with Degree > 3 but QtGui handles only 2,3
|
||||
} break;
|
||||
case GeomAbs_BSplineCurve: {
|
||||
std::unique_ptr<BSpline> bspline;
|
||||
TopoDS_Edge circEdge;
|
||||
|
||||
bool isArc = false;
|
||||
try {
|
||||
bspline = std::make_unique<BSpline>(edge);
|
||||
BSplinePtr bspline = std::make_shared<BSpline>(edge);
|
||||
if (bspline->isLine()) {
|
||||
result = std::make_unique<Generic>(edge);
|
||||
result = std::make_shared<Generic>(edge);
|
||||
} else {
|
||||
circEdge = bspline->asCircle(isArc);
|
||||
if (!circEdge.IsNull()) {
|
||||
if (isArc) {
|
||||
result = std::make_unique<AOC>(circEdge);
|
||||
result = std::make_shared<AOC>(circEdge);
|
||||
} else {
|
||||
result = std::make_unique<Circle>(circEdge);
|
||||
result = std::make_shared<Circle>(circEdge);
|
||||
}
|
||||
} else {
|
||||
// Base::Console().Message("Geom::baseFactory - circEdge is Null\n");
|
||||
result = std::move(bspline);
|
||||
result = bspline;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -538,8 +534,8 @@ BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
|
||||
result = std::make_unique<Generic>(edge);
|
||||
} break;
|
||||
}
|
||||
|
||||
return result.release();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool BaseGeom::validateEdge(TopoDS_Edge edge)
|
||||
@@ -1011,7 +1007,7 @@ double Generic::slope(void)
|
||||
return slope;
|
||||
}
|
||||
|
||||
Base::Vector3d Generic::apparentInter(Generic* g)
|
||||
Base::Vector3d Generic::apparentInter(GenericPtr g)
|
||||
{
|
||||
Base::Vector3d dir0 = asVector();
|
||||
Base::Vector3d dir1 = g->asVector();
|
||||
@@ -1575,7 +1571,7 @@ BaseGeomPtrVector GeometryUtils::chainGeoms(BaseGeomPtrVector geoms)
|
||||
for (unsigned int i = 1; i < geoms.size(); i++) { //do size-1 more edges
|
||||
auto next( nextGeom(atPoint, geoms, used, Precision::Confusion()) );
|
||||
if (next.index) { //found an unused edge with vertex == atPoint
|
||||
BaseGeom* nextEdge = geoms.at(next.index);
|
||||
BaseGeomPtr nextEdge = geoms.at(next.index);
|
||||
used[next.index] = true;
|
||||
nextEdge->reversed = next.reversed;
|
||||
result.push_back(nextEdge);
|
||||
@@ -1621,7 +1617,7 @@ BaseGeomPtrVector GeometryUtils::chainGeoms(BaseGeomPtrVector geoms)
|
||||
return result;
|
||||
}
|
||||
|
||||
TopoDS_Edge GeometryUtils::edgeFromGeneric(TechDraw::Generic* g)
|
||||
TopoDS_Edge GeometryUtils::edgeFromGeneric(TechDraw::GenericPtr g)
|
||||
{
|
||||
// Base::Console().Message("GU::edgeFromGeneric()\n");
|
||||
//TODO: note that this isn't quite right as g can be a polyline!
|
||||
@@ -1635,7 +1631,7 @@ TopoDS_Edge GeometryUtils::edgeFromGeneric(TechDraw::Generic* g)
|
||||
return e;
|
||||
}
|
||||
|
||||
TopoDS_Edge GeometryUtils::edgeFromCircle(TechDraw::Circle* c)
|
||||
TopoDS_Edge GeometryUtils::edgeFromCircle(TechDraw::CirclePtr c)
|
||||
{
|
||||
gp_Pnt loc(c->center.x, c->center.y, c->center.z);
|
||||
gp_Dir dir(0,0,1);
|
||||
@@ -1649,7 +1645,7 @@ TopoDS_Edge GeometryUtils::edgeFromCircle(TechDraw::Circle* c)
|
||||
return e;
|
||||
}
|
||||
|
||||
TopoDS_Edge GeometryUtils::edgeFromCircleArc(TechDraw::AOC* c)
|
||||
TopoDS_Edge GeometryUtils::edgeFromCircleArc(TechDraw::AOCPtr c)
|
||||
{
|
||||
gp_Pnt loc(c->center.x, c->center.y, c->center.z);
|
||||
gp_Dir dir(0,0,1);
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#ifndef TECHDRAW_GEOMETRY_H
|
||||
#define TECHDRAW_GEOMETRY_H
|
||||
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
@@ -74,11 +76,28 @@ enum SourceType {
|
||||
CENTERLINE
|
||||
};
|
||||
|
||||
class BaseGeom;
|
||||
using BaseGeomPtr = std::shared_ptr<BaseGeom>;
|
||||
class Circle;
|
||||
using CirclePtr = std::shared_ptr<Circle>;
|
||||
class AOC;
|
||||
using AOCPtr = std::shared_ptr<AOC>;
|
||||
class Ellipse;
|
||||
using EllipsePtr = std::shared_ptr<Ellipse>;
|
||||
class AOE;
|
||||
using AOEPtr = std::shared_ptr<AOE>;
|
||||
class BezierSegment;
|
||||
using BezierSegmentPtr = std::shared_ptr<BezierSegment>;
|
||||
class BSpline;
|
||||
using BSplinePtr = std::shared_ptr<BSpline>;
|
||||
class Generic;
|
||||
using GenericPtr = std::shared_ptr<Generic>;
|
||||
|
||||
class TechDrawExport BaseGeom
|
||||
{
|
||||
public:
|
||||
BaseGeom();
|
||||
//BaseGeom(BaseGeom* bg); //do we need a copy constructor too?
|
||||
//BaseGeom(BaseGeomPtr bg); //do we need a copy constructor too?
|
||||
virtual ~BaseGeom() = default;
|
||||
|
||||
public:
|
||||
@@ -98,7 +117,6 @@ class TechDrawExport BaseGeom
|
||||
void setCosmeticTag(std::string t) { cosmeticTag = t; }
|
||||
|
||||
virtual std::string toString(void) const;
|
||||
/* virtual bool fromCSV(std::string s);*/
|
||||
virtual void Save(Base::Writer& w) const;
|
||||
virtual void Restore(Base::XMLReader& r);
|
||||
std::vector<Base::Vector3d> findEndPoints();
|
||||
@@ -108,11 +126,11 @@ class TechDrawExport BaseGeom
|
||||
std::vector<Base::Vector3d> getQuads();
|
||||
double minDist(Base::Vector3d p);
|
||||
Base::Vector3d nearPoint(Base::Vector3d p);
|
||||
Base::Vector3d nearPoint(const BaseGeom* p);
|
||||
static BaseGeom* baseFactory(TopoDS_Edge edge);
|
||||
Base::Vector3d nearPoint(const BaseGeomPtr p);
|
||||
static BaseGeomPtr baseFactory(TopoDS_Edge edge);
|
||||
static bool validateEdge(TopoDS_Edge edge);
|
||||
bool closed(void);
|
||||
BaseGeom* copy();
|
||||
BaseGeomPtr copy();
|
||||
std::string dump();
|
||||
|
||||
//Uniqueness
|
||||
@@ -125,12 +143,10 @@ protected:
|
||||
std::string cosmeticTag;
|
||||
|
||||
void createNewTag();
|
||||
/* void assignTag(const TechDraw::BaseGeom* bg);*/
|
||||
|
||||
boost::uuids::uuid tag;
|
||||
};
|
||||
|
||||
typedef std::vector<BaseGeom *> BaseGeomPtrVector; //obs?
|
||||
using BaseGeomPtrVector = std::vector<BaseGeomPtr>; //new style
|
||||
|
||||
class TechDrawExport Circle: public BaseGeom
|
||||
{
|
||||
@@ -138,11 +154,10 @@ class TechDrawExport Circle: public BaseGeom
|
||||
Circle(void);
|
||||
Circle(const TopoDS_Edge &e);
|
||||
Circle(Base::Vector3d center, double radius);
|
||||
~Circle() = default;
|
||||
virtual ~Circle() = default;
|
||||
|
||||
public:
|
||||
virtual std::string toString(void) const override;
|
||||
/* virtual bool fromCSV(std::string s) override;*/
|
||||
virtual void Save(Base::Writer& w) const override;
|
||||
virtual void Restore(Base::XMLReader& r) override;
|
||||
|
||||
@@ -155,7 +170,7 @@ class TechDrawExport Ellipse: public BaseGeom
|
||||
public:
|
||||
Ellipse(const TopoDS_Edge &e);
|
||||
Ellipse(Base::Vector3d c, double mnr, double mjr);
|
||||
~Ellipse() = default;
|
||||
virtual ~Ellipse() = default;
|
||||
|
||||
public:
|
||||
Base::Vector3d center;
|
||||
@@ -198,7 +213,6 @@ class TechDrawExport AOC: public Circle
|
||||
|
||||
public:
|
||||
virtual std::string toString(void) const override;
|
||||
/* virtual bool fromCSV(std::string s) override;*/
|
||||
virtual void Save(Base::Writer& w) const override;
|
||||
virtual void Restore(Base::XMLReader& r) override;
|
||||
|
||||
@@ -231,7 +245,6 @@ public:
|
||||
int poles;
|
||||
int degree;
|
||||
|
||||
//Base::Vector3d pnts[4];
|
||||
std::vector<Base::Vector3d> pnts;
|
||||
};
|
||||
|
||||
@@ -267,12 +280,11 @@ class TechDrawExport Generic: public BaseGeom
|
||||
~Generic() = default;
|
||||
|
||||
virtual std::string toString(void) const override;
|
||||
/* virtual bool fromCSV(std::string s) override;*/
|
||||
virtual void Save(Base::Writer& w) const override;
|
||||
virtual void Restore(Base::XMLReader& r) override;
|
||||
Base::Vector3d asVector(void);
|
||||
double slope(void);
|
||||
Base::Vector3d apparentInter(Generic* g);
|
||||
Base::Vector3d apparentInter(GenericPtr g);
|
||||
std::vector<Base::Vector3d> points;
|
||||
};
|
||||
|
||||
@@ -287,7 +299,7 @@ class TechDrawExport Wire
|
||||
|
||||
TopoDS_Wire toOccWire(void) const;
|
||||
void dump(std::string s);
|
||||
std::vector<BaseGeom *> geoms;
|
||||
BaseGeomPtrVector geoms;
|
||||
};
|
||||
|
||||
/// Simple Collection of geometric features based on BaseGeom inherited classes in order
|
||||
@@ -362,15 +374,15 @@ class TechDrawExport GeometryUtils
|
||||
* returns index[1:geoms.size()),reversed [true,false]
|
||||
*/
|
||||
static ReturnType nextGeom( Base::Vector3d atPoint,
|
||||
std::vector<TechDraw::BaseGeom*> geoms,
|
||||
std::vector<TechDraw::BaseGeomPtr> geoms,
|
||||
std::vector<bool> used,
|
||||
double tolerance );
|
||||
|
||||
//! return a vector of BaseGeom*'s in tail to nose order
|
||||
static std::vector<BaseGeom*> chainGeoms(std::vector<BaseGeom*> geoms);
|
||||
static TopoDS_Edge edgeFromGeneric(TechDraw::Generic* g);
|
||||
static TopoDS_Edge edgeFromCircle(TechDraw::Circle* c);
|
||||
static TopoDS_Edge edgeFromCircleArc(TechDraw::AOC* c);
|
||||
//! return a vector of BaseGeomPtr's in tail to nose order
|
||||
static BaseGeomPtrVector chainGeoms(BaseGeomPtrVector geoms);
|
||||
static TopoDS_Edge edgeFromGeneric(TechDraw::GenericPtr g);
|
||||
static TopoDS_Edge edgeFromCircle(TechDraw::CirclePtr c);
|
||||
static TopoDS_Edge edgeFromCircleArc(TechDraw::AOCPtr c);
|
||||
};
|
||||
|
||||
} //end namespace TechDraw
|
||||
|
||||
@@ -105,9 +105,9 @@ GeometryObject::~GeometryObject()
|
||||
clear();
|
||||
}
|
||||
|
||||
const std::vector<BaseGeom *> GeometryObject::getVisibleFaceEdges(const bool smooth, const bool seam) const
|
||||
const BaseGeomPtrVector GeometryObject::getVisibleFaceEdges(const bool smooth, const bool seam) const
|
||||
{
|
||||
std::vector<BaseGeom *> result;
|
||||
BaseGeomPtrVector result;
|
||||
bool smoothOK = smooth;
|
||||
bool seamOK = seam;
|
||||
|
||||
@@ -150,10 +150,7 @@ const std::vector<BaseGeom *> GeometryObject::getVisibleFaceEdges(const bool smo
|
||||
|
||||
void GeometryObject::clear()
|
||||
{
|
||||
for(std::vector<BaseGeom *>::iterator it = edgeGeom.begin(); it != edgeGeom.end(); ++it) {
|
||||
delete *it;
|
||||
*it = 0;
|
||||
}
|
||||
//shared pointers will delete v/e/f when reference counts go to zero.
|
||||
|
||||
vertexGeom.clear();
|
||||
faceGeom.clear();
|
||||
@@ -477,7 +474,7 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca
|
||||
return; // There is no OpenCascade Geometry to be calculated
|
||||
}
|
||||
|
||||
BaseGeom* base;
|
||||
BaseGeomPtr base;
|
||||
TopExp_Explorer edges(edgeCompound, TopAbs_EDGE);
|
||||
int i = 1;
|
||||
for ( ; edges.More(); edges.Next(),i++) {
|
||||
@@ -510,12 +507,12 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca
|
||||
|
||||
//add vertices of new edge if not already in list
|
||||
if (hlrVisible) {
|
||||
BaseGeom* lastAdded = edgeGeom.back();
|
||||
BaseGeomPtr lastAdded = edgeGeom.back();
|
||||
bool v1Add = true, v2Add = true;
|
||||
bool c1Add = true;
|
||||
TechDraw::VertexPtr v1 = std::make_shared<TechDraw::Vertex>(lastAdded->getStartPoint());
|
||||
TechDraw::VertexPtr v2 = std::make_shared<TechDraw::Vertex>(lastAdded->getEndPoint());
|
||||
TechDraw::Circle* circle = dynamic_cast<TechDraw::Circle*>(lastAdded);
|
||||
TechDraw::CirclePtr circle = std::dynamic_pointer_cast<TechDraw::Circle>(lastAdded);
|
||||
TechDraw::VertexPtr c1;
|
||||
if (circle) {
|
||||
c1 = std::make_shared<TechDraw::Vertex>(circle->center);
|
||||
@@ -568,7 +565,7 @@ void GeometryObject::addVertex(TechDraw::VertexPtr v)
|
||||
vertexGeom.push_back(v);
|
||||
}
|
||||
|
||||
void GeometryObject::addEdge(TechDraw::BaseGeom* bg)
|
||||
void GeometryObject::addEdge(TechDraw::BaseGeomPtr bg)
|
||||
{
|
||||
edgeGeom.push_back(bg);
|
||||
}
|
||||
@@ -628,7 +625,7 @@ int GeometryObject::addCosmeticEdge(CosmeticEdge* ce)
|
||||
{
|
||||
// Base::Console().Message("GO::addCosmeticEdge(%X) 0\n", ce);
|
||||
double scale = m_parent->getScale();
|
||||
TechDraw::BaseGeom* e = ce->scaledGeometry(scale);
|
||||
TechDraw::BaseGeomPtr e = ce->scaledGeometry(scale);
|
||||
e->cosmetic = true;
|
||||
e->setCosmeticTag(ce->getTagAsString());
|
||||
e->hlrVisible = true;
|
||||
@@ -646,7 +643,7 @@ int GeometryObject::addCosmeticEdge(Base::Vector3d start,
|
||||
gp_Pnt gp1(start.x, start.y, start.z);
|
||||
gp_Pnt gp2(end.x, end.y, end.z);
|
||||
TopoDS_Edge occEdge = BRepBuilderAPI_MakeEdge(gp1, gp2);
|
||||
TechDraw::BaseGeom* e = BaseGeom::baseFactory(occEdge);
|
||||
TechDraw::BaseGeomPtr e = BaseGeom::baseFactory(occEdge);
|
||||
e->cosmetic = true;
|
||||
// e->cosmeticLink = link;
|
||||
e->setCosmeticTag("tbi");
|
||||
@@ -664,7 +661,7 @@ int GeometryObject::addCosmeticEdge(Base::Vector3d start,
|
||||
gp_Pnt gp1(start.x, start.y, start.z);
|
||||
gp_Pnt gp2(end.x, end.y, end.z);
|
||||
TopoDS_Edge occEdge = BRepBuilderAPI_MakeEdge(gp1, gp2);
|
||||
TechDraw::BaseGeom* base = BaseGeom::baseFactory(occEdge);
|
||||
TechDraw::BaseGeomPtr base = BaseGeom::baseFactory(occEdge);
|
||||
base->cosmetic = true;
|
||||
base->setCosmeticTag(tagString);
|
||||
base->source(1); //1-CosmeticEdge, 2-CenterLine
|
||||
@@ -674,7 +671,7 @@ int GeometryObject::addCosmeticEdge(Base::Vector3d start,
|
||||
return idx;
|
||||
}
|
||||
|
||||
int GeometryObject::addCosmeticEdge(TechDraw::BaseGeom* base,
|
||||
int GeometryObject::addCosmeticEdge(TechDraw::BaseGeomPtr base,
|
||||
std::string tagString)
|
||||
{
|
||||
// Base::Console().Message("GO::addCosmeticEdge(%X, %s) 3\n", base, tagString.c_str());
|
||||
@@ -688,7 +685,7 @@ int GeometryObject::addCosmeticEdge(TechDraw::BaseGeom* base,
|
||||
return idx;
|
||||
}
|
||||
|
||||
int GeometryObject::addCenterLine(TechDraw::BaseGeom* base,
|
||||
int GeometryObject::addCenterLine(TechDraw::BaseGeomPtr base,
|
||||
std::string tag)
|
||||
// int s, int si)
|
||||
{
|
||||
@@ -773,7 +770,7 @@ Base::BoundBox3d GeometryObject::calcBoundingBox() const
|
||||
Bnd_Box testBox;
|
||||
testBox.SetGap(0.0);
|
||||
if (!edgeGeom.empty()) {
|
||||
for (std::vector<BaseGeom *>::const_iterator it( edgeGeom.begin() );
|
||||
for (BaseGeomPtrVector::const_iterator it( edgeGeom.begin() );
|
||||
it != edgeGeom.end(); ++it) {
|
||||
BRepBndLib::Add((*it)->occEdge, testBox);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#ifndef _TECHDRAW_GEOMETRYOBJECT_H
|
||||
#define _TECHDRAW_GEOMETRYOBJECT_H
|
||||
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <TopoDS_Compound.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
@@ -105,12 +107,12 @@ public:
|
||||
Base::BoundBox3d calcBoundingBox() const;
|
||||
|
||||
const std::vector<VertexPtr> & getVertexGeometry() const { return vertexGeom; }
|
||||
const std::vector<BaseGeom *> & getEdgeGeometry() const { return edgeGeom; }
|
||||
const std::vector<BaseGeom *> getVisibleFaceEdges(bool smooth, bool seam) const;
|
||||
const BaseGeomPtrVector & getEdgeGeometry() const { return edgeGeom; }
|
||||
const BaseGeomPtrVector getVisibleFaceEdges(bool smooth, bool seam) const;
|
||||
const std::vector<FacePtr> & getFaceGeometry() const { return faceGeom; }
|
||||
|
||||
void setVertexGeometry(std::vector<VertexPtr> newVerts) {vertexGeom = newVerts; }
|
||||
void setEdgeGeometry(std::vector<BaseGeom*> newGeoms) {edgeGeom = newGeoms; }
|
||||
void setEdgeGeometry(BaseGeomPtrVector newGeoms) {edgeGeom = newGeoms; }
|
||||
|
||||
void projectShape(const TopoDS_Shape &input,
|
||||
const gp_Ax2 &viewAxis);
|
||||
@@ -147,7 +149,7 @@ public:
|
||||
TopoDS_Shape getHidIso(void) { return hidIso; }
|
||||
|
||||
void addVertex(TechDraw::VertexPtr v);
|
||||
void addEdge(TechDraw::BaseGeom* bg);
|
||||
void addEdge(TechDraw::BaseGeomPtr bg);
|
||||
|
||||
|
||||
int addCosmeticVertex(CosmeticVertex* cv);
|
||||
@@ -161,10 +163,10 @@ public:
|
||||
int addCosmeticEdge(Base::Vector3d start,
|
||||
Base::Vector3d end,
|
||||
std::string tagString);
|
||||
int addCosmeticEdge(TechDraw::BaseGeom* base,
|
||||
int addCosmeticEdge(TechDraw::BaseGeomPtr base,
|
||||
std::string tagString);
|
||||
|
||||
int addCenterLine(TechDraw::BaseGeom* bg,
|
||||
int addCenterLine(TechDraw::BaseGeomPtr bg,
|
||||
std::string tag);
|
||||
/* int s = 0, int si = -1);*/
|
||||
|
||||
@@ -192,7 +194,7 @@ protected:
|
||||
bool isWithinArc(double theta, double first, double last, bool cw) const;
|
||||
|
||||
// Geometry
|
||||
std::vector<BaseGeom *> edgeGeom;
|
||||
BaseGeomPtrVector edgeGeom;
|
||||
std::vector<VertexPtr> vertexGeom;
|
||||
std::vector<FacePtr> faceGeom;
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ bool LineSet::isDashed(void)
|
||||
}
|
||||
|
||||
//! calculates the apparent start point (ie start of overlay line) for dashed lines
|
||||
Base::Vector3d LineSet::calcApparentStart(TechDraw::BaseGeom* g)
|
||||
Base::Vector3d LineSet::calcApparentStart(TechDraw::BaseGeomPtr g)
|
||||
{
|
||||
Base::Vector3d result;
|
||||
Base::Vector3d start(g->getStartPoint().x,g->getStartPoint().y,0.0);
|
||||
@@ -151,7 +151,7 @@ Base::Vector3d LineSet::findAtomStart(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
Base::Vector3d LineSet::getPatternStartPoint(TechDraw::BaseGeom* g, double &offset, double scale)
|
||||
Base::Vector3d LineSet::getPatternStartPoint(TechDraw::BaseGeomPtr g, double &offset, double scale)
|
||||
{
|
||||
Base::Vector3d result = getOrigin();
|
||||
Base::Vector3d atomStart = findAtomStart();
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#ifndef _TechDraw_HATCHLINE_H_
|
||||
#define _TechDraw_HATCHLINE_H_
|
||||
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
@@ -35,6 +37,8 @@
|
||||
//class TopoDS_Edge;
|
||||
//class Bnd_Box;
|
||||
|
||||
#include "Geometry.h"
|
||||
|
||||
namespace TechDraw
|
||||
{
|
||||
class BaseGeom;
|
||||
@@ -114,12 +118,12 @@ public:
|
||||
|
||||
void setPATLineSpec(const PATLineSpec& s) { m_hatchLine = s; }
|
||||
void setEdges(std::vector<TopoDS_Edge> e) {m_edges = e;}
|
||||
void setGeoms(std::vector<TechDraw::BaseGeom*> g) {m_geoms = g;}
|
||||
void setGeoms(std::vector<TechDraw::BaseGeomPtr> g) {m_geoms = g;}
|
||||
void setBBox(const Bnd_Box& bb) {m_box = bb;}
|
||||
|
||||
std::vector<TopoDS_Edge> getEdges(void) { return m_edges; }
|
||||
TopoDS_Edge getEdge(int i) {return m_edges.at(i);}
|
||||
std::vector<TechDraw::BaseGeom*> getGeoms(void) { return m_geoms; }
|
||||
std::vector<TechDraw::BaseGeomPtr> getGeoms(void) { return m_geoms; }
|
||||
|
||||
PATLineSpec getPATLineSpec(void) { return m_hatchLine; }
|
||||
double getOffset(void) { return m_hatchLine.getOffset(); } //delta X offset
|
||||
@@ -133,10 +137,10 @@ public:
|
||||
Base::Vector3d getUnitDir(void);
|
||||
Base::Vector3d getUnitOrtho(void);
|
||||
DashSpec getDashSpec(void) { return m_hatchLine.getDashParms();}
|
||||
Base::Vector3d calcApparentStart(TechDraw::BaseGeom* g);
|
||||
Base::Vector3d calcApparentStart(TechDraw::BaseGeomPtr g);
|
||||
Base::Vector3d findAtomStart(void);
|
||||
Base::Vector3d getLineOrigin(void); //point corresponding to pattern origin for this line (O + n*intervalX)
|
||||
Base::Vector3d getPatternStartPoint(TechDraw::BaseGeom* g, double &offset, double scale = 1.0);
|
||||
Base::Vector3d getPatternStartPoint(TechDraw::BaseGeomPtr g, double &offset, double scale = 1.0);
|
||||
|
||||
Bnd_Box getBBox(void) {return m_box;}
|
||||
double getMinX(void);
|
||||
@@ -148,7 +152,7 @@ public:
|
||||
|
||||
private:
|
||||
std::vector<TopoDS_Edge> m_edges;
|
||||
std::vector<TechDraw::BaseGeom*> m_geoms;
|
||||
std::vector<TechDraw::BaseGeomPtr> m_geoms;
|
||||
PATLineSpec m_hatchLine;
|
||||
Bnd_Box m_box;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user