Part/Sketcher - Construction Migration - step 3: Removal of Geometry construction data member

=============================================================================================

This commits removes the Geometry construction data member and adapts sketcher code to use
GeometryFacade to access construction information via the SketchGeometryExtension.
This commit is contained in:
Abdullah Tahiri
2020-12-01 18:04:26 +01:00
committed by abdullahtahiriyo
parent 850a71d3c7
commit 994bd9d92b
12 changed files with 130 additions and 134 deletions

View File

@@ -78,8 +78,6 @@
#include <Mod/Part/App/DatumFeature.h>
#include <Mod/Part/App/BodyBase.h>
#include "GeometryFacade.h"
#include "SketchObject.h"
#include "Sketch.h"
#include <Mod/Sketcher/App/SketchObjectPy.h>
@@ -118,14 +116,14 @@ SketchObject::SketchObject()
for (std::vector<Part::Geometry *>::iterator it=ExternalGeo.begin(); it != ExternalGeo.end(); ++it)
if (*it) delete *it;
ExternalGeo.clear();
Part::GeomLineSegment *HLine = new Part::GeomLineSegment();
Part::GeomLineSegment *VLine = new Part::GeomLineSegment();
HLine->setPoints(Base::Vector3d(0,0,0),Base::Vector3d(1,0,0));
VLine->setPoints(Base::Vector3d(0,0,0),Base::Vector3d(0,1,0));
auto HLine = GeometryTypedFacade<Part::GeomLineSegment>::getTypedFacade();
auto VLine = GeometryTypedFacade<Part::GeomLineSegment>::getTypedFacade();
HLine->getTypedGeometry()->setPoints(Base::Vector3d(0,0,0),Base::Vector3d(1,0,0));
VLine->getTypedGeometry()->setPoints(Base::Vector3d(0,0,0),Base::Vector3d(0,1,0));
HLine->setConstruction(true);
VLine->setConstruction(true);
ExternalGeo.push_back(HLine);
ExternalGeo.push_back(VLine);
ExternalGeo.push_back(HLine->getGeometry());
ExternalGeo.push_back(VLine->getGeometry());
rebuildVertexIndex();
lastDoF=0;
@@ -410,13 +408,19 @@ int SketchObject::toggleDriving(int ConstrId)
if(ret<0)
return ret;
const Part::Geometry * geo1 = getGeometry(vals[ConstrId]->First);
const Part::Geometry * geo2 = getGeometry(vals[ConstrId]->Second);
const Part::Geometry * geo3 = getGeometry(vals[ConstrId]->Third);
const auto geof1 = getGeometryFacade(vals[ConstrId]->First);
const auto geof2 = getGeometryFacade(vals[ConstrId]->Second);
const auto geof3 = getGeometryFacade(vals[ConstrId]->Third);
bool extorconstructionpoint1 = (vals[ConstrId]->First == Constraint::GeoUndef) || (vals[ConstrId]->First < 0) || (geo1 && geo1->getTypeId() == Part::GeomPoint::getClassTypeId() && geo1->getConstruction() == true);
bool extorconstructionpoint2 = (vals[ConstrId]->Second == Constraint::GeoUndef) || (vals[ConstrId]->Second < 0) || (geo2 && geo2->getTypeId() == Part::GeomPoint::getClassTypeId() && geo2->getConstruction() == true);
bool extorconstructionpoint3 = (vals[ConstrId]->Third == Constraint::GeoUndef) || (vals[ConstrId]->Third < 0) || (geo3 && geo3->getTypeId() == Part::GeomPoint::getClassTypeId() && geo3->getConstruction() == true);
bool extorconstructionpoint1 = (vals[ConstrId]->First == Constraint::GeoUndef) ||
(vals[ConstrId]->First < 0) ||
(geof1 && geof1->isGeoType(Part::GeomPoint::getClassTypeId()) && geof1->getConstruction() == true);
bool extorconstructionpoint2 = (vals[ConstrId]->Second == Constraint::GeoUndef)||
(vals[ConstrId]->Second < 0) ||
(geof2 && geof2->isGeoType(Part::GeomPoint::getClassTypeId()) && geof2->getConstruction() == true);
bool extorconstructionpoint3 = (vals[ConstrId]->Third == Constraint::GeoUndef) ||
(vals[ConstrId]->Third < 0) ||
(geof3 && geof3->isGeoType(Part::GeomPoint::getClassTypeId()) && geof3->getConstruction() == true);
if (extorconstructionpoint1 && extorconstructionpoint2 && extorconstructionpoint3 && vals[ConstrId]->isDriving==false)
return -4;
@@ -803,7 +807,7 @@ int SketchObject::getAxisCount(void) const
int count=0;
for (std::vector<Part::Geometry *>::const_iterator geo=vals.begin();
geo != vals.end(); geo++)
if ((*geo) && (*geo)->getConstruction() &&
if ((*geo) && GeometryFacade::getConstruction(*geo) &&
(*geo)->getTypeId() == Part::GeomLineSegment::getClassTypeId())
count++;
@@ -819,7 +823,7 @@ Base::Axis SketchObject::getAxis(int axId) const
int count=0;
for (std::vector<Part::Geometry *>::const_iterator geo=vals.begin();
geo != vals.end(); geo++)
if ((*geo) && (*geo)->getConstruction() &&
if ((*geo) && GeometryFacade::getConstruction(*geo) &&
(*geo)->getTypeId() == Part::GeomLineSegment::getClassTypeId()) {
if (count == axId) {
Part::GeomLineSegment *lineSeg = static_cast<Part::GeomLineSegment*>(*geo);
@@ -894,7 +898,7 @@ int SketchObject::addGeometry(const std::vector<Part::Geometry *> &geoList, bool
Part::Geometry* copy = v->copy();
if(construction && copy->getTypeId() != Part::GeomPoint::getClassTypeId()) {
copy->setConstruction(construction);
GeometryFacade::setConstruction(copy, construction);
}
newVals.push_back(copy);
@@ -922,7 +926,7 @@ int SketchObject::addGeometry(const Part::Geometry *geo, bool construction/*=fal
Part::Geometry *geoNew = geo->copy();
if(geoNew->getTypeId() != Part::GeomPoint::getClassTypeId())
geoNew->setConstruction(construction);
GeometryFacade::setConstruction(geoNew, construction);
newVals.push_back(geoNew);
@@ -1130,7 +1134,7 @@ int SketchObject::toggleConstruction(int GeoId)
newVals[i] = newVals[i]->clone();
if((int)i == GeoId) {
newVals[i]->setConstruction(!newVals[i]->getConstruction());
GeometryFacade::setConstruction(newVals[i], !GeometryFacade::getConstruction(newVals[i]));
}
}
@@ -1163,7 +1167,7 @@ int SketchObject::setConstruction(int GeoId, bool on)
newVals[i] = newVals[i]->clone();
if((int)i == GeoId) {
newVals[i]->setConstruction(on);
GeometryFacade::setConstruction(newVals[i], on);
}
}
@@ -4217,7 +4221,7 @@ int SketchObject::addCopy(const std::vector<int> &geoIdList, const Base::Vector3
(double(x-1)*displacement+double(y)*perpendicularDisplacement)); // position of the reference point
Base::Vector3d ep = iterfirstpoint; // position of the current instance corresponding point
constrline->setPoints(sp,ep);
constrline->setConstruction(true);
GeometryFacade::setConstruction(constrline,true);
newgeoVals.push_back(constrline);
@@ -4911,7 +4915,7 @@ int SketchObject::exposeInternalGeometry(int GeoId)
// a construction point, for now on, is a point that is not handled by the solver and does not contribute to the dofs
// This is done so as to avoid having to add another data member to GeomPoint that is specific for the sketcher.
kp->setConstruction(true);
GeometryFacade::setConstruction(kp, true);
igeo.push_back(kp);
@@ -5718,7 +5722,7 @@ int SketchObject::carbonCopy(App::DocumentObject * pObj, bool construction)
for (std::vector<Part::Geometry *>::const_iterator it=svals.begin(); it != svals.end(); ++it){
Part::Geometry *geoNew = (*it)->copy();
if(construction && geoNew->getTypeId() != Part::GeomPoint::getClassTypeId()) {
geoNew->setConstruction(true);
GeometryFacade::setConstruction(geoNew, true);
}
newVals.push_back(geoNew);
}
@@ -5973,7 +5977,12 @@ const Part::Geometry* SketchObject::getGeometry(int GeoId) const
else if (-GeoId <= int(ExternalGeo.size()))
return ExternalGeo[-GeoId-1];
return 0;
return nullptr;
}
std::unique_ptr<const GeometryFacade> SketchObject::getGeometryFacade(int GeoId) const
{
return GeometryFacade::getFacade(getGeometry(GeoId));
}
// Auxiliary Method: returns vector projection in UV space of plane
@@ -6053,13 +6062,13 @@ Part::Geometry* projectLine(const BRepAdaptor_Curve& curve, const Handle(Geom_Pl
if (Base::Distance(p1,p2) < Precision::Confusion()) {
Base::Vector3d p = (p1 + p2) / 2;
Part::GeomPoint* point = new Part::GeomPoint(p);
point->setConstruction(true);
GeometryFacade::setConstruction(point, true);
return point;
}
else {
Part::GeomLineSegment* line = new Part::GeomLineSegment();
line->setPoints(p1,p2);
line->setConstruction(true);
GeometryFacade::setConstruction(line, true);
return line;
}
}
@@ -6179,8 +6188,8 @@ void SketchObject::rebuildExternalGeometry(void)
Part::GeomLineSegment *VLine = new Part::GeomLineSegment();
HLine->setPoints(Base::Vector3d(0,0,0),Base::Vector3d(1,0,0));
VLine->setPoints(Base::Vector3d(0,0,0),Base::Vector3d(0,1,0));
HLine->setConstruction(true);
VLine->setConstruction(true);
GeometryFacade::setConstruction(HLine, true);
GeometryFacade::setConstruction(VLine, true);
ExternalGeo.push_back(HLine);
ExternalGeo.push_back(VLine);
for (int i=0; i < int(Objects.size()); i++) {
@@ -6278,7 +6287,7 @@ void SketchObject::rebuildExternalGeometry(void)
gCircle->setRadius(circle.Radius());
gCircle->setCenter(Base::Vector3d(cnt.X(),cnt.Y(),cnt.Z()));
gCircle->setConstruction(true);
GeometryFacade::setConstruction(gCircle, true);
ExternalGeo.push_back(gCircle);
}
else {
@@ -6287,7 +6296,7 @@ void SketchObject::rebuildExternalGeometry(void)
Handle(Geom_TrimmedCurve) tCurve = new Geom_TrimmedCurve(hCircle, curve.FirstParameter(),
curve.LastParameter());
gArc->setHandle(tCurve);
gArc->setConstruction(true);
GeometryFacade::setConstruction(gArc, true);
ExternalGeo.push_back(gArc);
}
}
@@ -6389,7 +6398,7 @@ void SketchObject::rebuildExternalGeometry(void)
invPlm.multVec(p2,p2);
projectedSegment->setPoints(p1, p2);
projectedSegment->setConstruction(true);
GeometryFacade::setConstruction(projectedSegment, true);
ExternalGeo.push_back(projectedSegment);
}
else { // general case, full circle
@@ -6415,7 +6424,7 @@ void SketchObject::rebuildExternalGeometry(void)
Handle(Geom_Ellipse) curve = new Geom_Ellipse(refFrameEllipse, origCircle.Radius(), minorRadius);
Part::GeomEllipse* ellipse = new Part::GeomEllipse();
ellipse->setHandle(curve);
ellipse->setConstruction(true);
GeometryFacade::setConstruction(ellipse, true);
ExternalGeo.push_back(ellipse);
}
@@ -6438,7 +6447,7 @@ void SketchObject::rebuildExternalGeometry(void)
Handle(Geom_Ellipse) curve = new Geom_Ellipse(elipsDest);
Part::GeomEllipse* ellipse = new Part::GeomEllipse();
ellipse->setHandle(curve);
ellipse->setConstruction(true);
GeometryFacade::setConstruction(ellipse, true);
ExternalGeo.push_back(ellipse);
}
@@ -6484,7 +6493,7 @@ void SketchObject::rebuildExternalGeometry(void)
Handle(Geom_Circle) curve = new Geom_Circle(destCurveAx2, 0.5 * (rDest + RDest));
Part::GeomCircle* circle = new Part::GeomCircle();
circle->setHandle(curve);
circle->setConstruction(true);
GeometryFacade::setConstruction(circle, true);
ExternalGeo.push_back(circle);
}
@@ -6496,7 +6505,7 @@ void SketchObject::rebuildExternalGeometry(void)
Part::GeomLineSegment * projectedSegment = new Part::GeomLineSegment();
projectedSegment->setPoints(Base::Vector3d(start.X(), start.Y(), start.Z()),
Base::Vector3d(end.X(), end.Y(), end.Z()));
projectedSegment->setConstruction(true);
GeometryFacade::setConstruction(projectedSegment, true);
ExternalGeo.push_back(projectedSegment);
}
else {
@@ -6509,7 +6518,7 @@ void SketchObject::rebuildExternalGeometry(void)
Handle(Geom_Ellipse) curve = new Geom_Ellipse(elipsDest);
Part::GeomEllipse* ellipse = new Part::GeomEllipse();
ellipse->setHandle(curve);
ellipse->setConstruction(true);
GeometryFacade::setConstruction(ellipse, true);
ExternalGeo.push_back(ellipse);
}
@@ -6538,13 +6547,13 @@ void SketchObject::rebuildExternalGeometry(void)
if (Base::Distance(p1,p2) < Precision::Confusion()) {
Base::Vector3d p = (p1 + p2) / 2;
Part::GeomPoint* point = new Part::GeomPoint(p);
point->setConstruction(true);
GeometryFacade::setConstruction(point, true);
ExternalGeo.push_back(point);
}
else {
Part::GeomLineSegment* line = new Part::GeomLineSegment();
line->setPoints(p1,p2);
line->setConstruction(true);
GeometryFacade::setConstruction(line, true);
ExternalGeo.push_back(line);
}
}
@@ -6559,7 +6568,7 @@ void SketchObject::rebuildExternalGeometry(void)
circle->setRadius(c.Radius());
circle->setCenter(Base::Vector3d(p.X(),p.Y(),p.Z()));
circle->setConstruction(true);
GeometryFacade::setConstruction(circle, true);
ExternalGeo.push_back(circle);
}
else {
@@ -6568,7 +6577,7 @@ void SketchObject::rebuildExternalGeometry(void)
Handle(Geom_TrimmedCurve) tCurve = new Geom_TrimmedCurve(curve, projCurve.FirstParameter(),
projCurve.LastParameter());
arc->setHandle(tCurve);
arc->setConstruction(true);
GeometryFacade::setConstruction(arc, true);
ExternalGeo.push_back(arc);
}
} else if (projCurve.GetType() == GeomAbs_BSplineCurve) {
@@ -6590,11 +6599,11 @@ void SketchObject::rebuildExternalGeometry(void)
gp_Pnt center = circ->Axis().Location();
circle->setCenter(Base::Vector3d(center.X(), center.Y(), center.Z()));
circle->setConstruction(true);
GeometryFacade::setConstruction(circle, true);
ExternalGeo.push_back(circle);
} else {
Part::GeomBSplineCurve* bspline = new Part::GeomBSplineCurve(projCurve.BSpline());
bspline->setConstruction(true);
GeometryFacade::setConstruction(bspline, true);
ExternalGeo.push_back(bspline);
}
} else if (projCurve.GetType() == GeomAbs_Hyperbola) {
@@ -6613,7 +6622,7 @@ void SketchObject::rebuildExternalGeometry(void)
hyperbola->setMinorRadius(e.MinorRadius());
hyperbola->setCenter(Base::Vector3d(p.X(),p.Y(),p.Z()));
hyperbola->setAngleXU(-xdir.AngleWithRef(xdirref.XDirection(),normal));
hyperbola->setConstruction(true);
GeometryFacade::setConstruction(hyperbola, true);
ExternalGeo.push_back(hyperbola);
}
else {
@@ -6622,7 +6631,7 @@ void SketchObject::rebuildExternalGeometry(void)
Handle(Geom_TrimmedCurve) tCurve = new Geom_TrimmedCurve(curve, projCurve.FirstParameter(),
projCurve.LastParameter());
aoh->setHandle(tCurve);
aoh->setConstruction(true);
GeometryFacade::setConstruction(aoh, true);
ExternalGeo.push_back(aoh);
}
} else if (projCurve.GetType() == GeomAbs_Parabola) {
@@ -6640,7 +6649,7 @@ void SketchObject::rebuildExternalGeometry(void)
parabola->setFocal(e.Focal());
parabola->setCenter(Base::Vector3d(p.X(),p.Y(),p.Z()));
parabola->setAngleXU(-xdir.AngleWithRef(xdirref.XDirection(),normal));
parabola->setConstruction(true);
GeometryFacade::setConstruction(parabola, true);
ExternalGeo.push_back(parabola);
}
else {
@@ -6649,7 +6658,7 @@ void SketchObject::rebuildExternalGeometry(void)
Handle(Geom_TrimmedCurve) tCurve = new Geom_TrimmedCurve(curve, projCurve.FirstParameter(),
projCurve.LastParameter());
aop->setHandle(tCurve);
aop->setConstruction(true);
GeometryFacade::setConstruction(aop, true);
ExternalGeo.push_back(aop);
}
}
@@ -6667,7 +6676,7 @@ void SketchObject::rebuildExternalGeometry(void)
Part::GeomEllipse* ellipse = new Part::GeomEllipse();
Handle(Geom_Ellipse) curve = new Geom_Ellipse(e);
ellipse->setHandle(curve);
ellipse->setConstruction(true);
GeometryFacade::setConstruction(ellipse, true);
ExternalGeo.push_back(ellipse);
}
else {
@@ -6676,7 +6685,7 @@ void SketchObject::rebuildExternalGeometry(void)
Handle(Geom_TrimmedCurve) tCurve = new Geom_TrimmedCurve(curve, projCurve.FirstParameter(),
projCurve.LastParameter());
aoe->setHandle(tCurve);
aoe->setConstruction(true);
GeometryFacade::setConstruction(aoe, true);
ExternalGeo.push_back(aoe);
}
}
@@ -6701,7 +6710,7 @@ void SketchObject::rebuildExternalGeometry(void)
invPlm.multVec(p,p);
Part::GeomPoint* point = new Part::GeomPoint(p);
point->setConstruction(true);
GeometryFacade::setConstruction(point, true);
ExternalGeo.push_back(point);
}
break;