From 994bd9d92b81ae213d5fa965d16401f2a0972539 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 1 Dec 2020 18:04:26 +0100 Subject: [PATCH] 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. --- src/Mod/Part/App/Geometry.cpp | 48 ++++---- src/Mod/Part/App/Geometry.h | 8 -- src/Mod/Part/App/GeometryPy.xml | 7 -- src/Mod/Part/App/GeometryPyImp.cpp | 11 -- src/Mod/Sketcher/App/Sketch.cpp | 6 +- src/Mod/Sketcher/App/SketchAnalysis.cpp | 45 ++++---- src/Mod/Sketcher/App/SketchObject.cpp | 107 ++++++++++-------- src/Mod/Sketcher/App/SketchObject.h | 5 + src/Mod/Sketcher/Gui/CommandConstraints.cpp | 14 +-- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 6 +- src/Mod/Sketcher/Gui/TaskSketcherElements.cpp | 3 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 4 +- 12 files changed, 130 insertions(+), 134 deletions(-) diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index c9ce273258..5f764ad0c4 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -140,8 +140,11 @@ #include #include +#include "GeometryMigrationExtension.h" + #include "Geometry.h" + using namespace Part; @@ -187,7 +190,6 @@ const char* gce_ErrorStatusText(gce_ErrorType et) TYPESYSTEM_SOURCE_ABSTRACT(Part::Geometry,Base::Persistence) Geometry::Geometry() - : Construction(false) { createNewTag(); } @@ -205,29 +207,26 @@ unsigned int Geometry::getMemSize (void) const void Geometry::Save(Base::Writer &writer) const { - if( extensions.size()>0 ) { + // We always store an extension array even if empty, so that restoring is consistent. + writer.Stream() << writer.ind() << "" << std::endl; - writer.incInd(); + writer.incInd(); - writer.Stream() << writer.ind() << "" << std::endl; - - for(auto att:extensions) { - att->Save(writer); - } - - writer.decInd(); - writer.Stream() << writer.ind() << "" << std::endl; + for(auto att:extensions) { + att->Save(writer); } - const char c = Construction?'1':'0'; - writer.Stream() << writer.ind() << "" << std::endl; + writer.decInd(); + writer.Stream() << writer.ind() << "" << std::endl; } void Geometry::Restore(Base::XMLReader &reader) { + // In legacy file format, there are no extensions and there is a construction XML tag + // In the new format, this is migrated into extensions, and we get an array with extensions reader.readElement(); - if(strcmp(reader.localName(),"GeoExtensions") == 0) { + if(strcmp(reader.localName(),"GeoExtensions") == 0) { // new format int count = reader.getAttributeAsInteger("count"); @@ -242,14 +241,21 @@ void Geometry::Restore(Base::XMLReader &reader) } reader.readEndElement("GeoExtensions"); - - reader.readElement("Construction"); // prepare for reading construction attribute - } - else if(strcmp(reader.localName(),"Construction") != 0) { // ignore anything not known - reader.readElement("Construction"); } + else if(strcmp(reader.localName(),"Construction") == 0) { // legacy - Construction = (int)reader.getAttributeAsInteger("value")==0?false:true; + bool construction = (int)reader.getAttributeAsInteger("value")==0?false:true; + + // prepare migration + if(!this->hasExtension(GeometryMigrationExtension::getClassTypeId())) + this->setExtension(std::make_unique()); + + auto ext = std::static_pointer_cast(this->getExtension(GeometryMigrationExtension::getClassTypeId()).lock()); + + ext->setMigrationType(GeometryMigrationExtension::Construction); + ext->setConstruction(construction); + + } } @@ -385,8 +391,6 @@ void Geometry::assignTag(const Part::Geometry * geo) void Geometry::copyNonTag(const Part::Geometry * src) { - this->Construction = src->Construction; - for(auto & ext: src->extensions) this->extensions.push_back(ext->copy()); } diff --git a/src/Mod/Part/App/Geometry.h b/src/Mod/Part/App/Geometry.h index f05f554cf9..e594ce5f47 100644 --- a/src/Mod/Part/App/Geometry.h +++ b/src/Mod/Part/App/Geometry.h @@ -93,11 +93,6 @@ public: /// If you do not desire to have the same tag, then a copy can be performed by using a constructor (which will generate another tag) /// and then, if necessary (e.g. if the constructor did not take a handle as a parameter), set a new handle. Geometry *clone(void) const; - /// construction geometry (means no impact on a later built topo) - /// Note: In the Sketcher and only for the specific case of a point, it has a special meaning: - /// a construction point has fixed coordinates for the solver (it has fixed parameters) - inline bool getConstruction(void) const {return Construction;}; - inline void setConstruction(bool construction) {Construction = construction;}; /// returns the tag of the geometry object boost::uuids::uuid getTag() const; @@ -138,9 +133,6 @@ protected: private: Geometry(const Geometry&); Geometry& operator = (const Geometry&); - -protected: - bool Construction; }; class PartExport GeomPoint : public Geometry diff --git a/src/Mod/Part/App/GeometryPy.xml b/src/Mod/Part/App/GeometryPy.xml index 87d69de4bb..b8d5cc425f 100644 --- a/src/Mod/Part/App/GeometryPy.xml +++ b/src/Mod/Part/App/GeometryPy.xml @@ -93,13 +93,6 @@ It describes the common behavior of these objects when: Returns a list with information about the geometry extensions. - - - Defines this geometry as a construction one which -means that it is not part of a later built shape. - - - Gives the tag of the geometry as string. diff --git a/src/Mod/Part/App/GeometryPyImp.cpp b/src/Mod/Part/App/GeometryPyImp.cpp index fe5755d2ed..7d89f9a13b 100644 --- a/src/Mod/Part/App/GeometryPyImp.cpp +++ b/src/Mod/Part/App/GeometryPyImp.cpp @@ -433,17 +433,6 @@ PyObject* GeometryPy::getExtensions(PyObject *args) } -Py::Boolean GeometryPy::getConstruction(void) const -{ - return Py::Boolean(getGeometryPtr()->getConstruction()); -} - -void GeometryPy::setConstruction(Py::Boolean arg) -{ - if (getGeometryPtr()->getTypeId() != Part::GeomPoint::getClassTypeId()) - getGeometryPtr()->setConstruction(arg); -} - Py::String GeometryPy::getTag(void) const { std::string tmp = boost::uuids::to_string(getGeometryPtr()->getTag()); diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index e6f0ae3388..108ff572cc 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -1055,7 +1055,8 @@ std::vector Sketch::extractGeometry(bool withConstructionEleme std::vector temp; temp.reserve(Geoms.size()); for (std::vector::const_iterator it=Geoms.begin(); it != Geoms.end(); ++it) { - if ((!it->external || withExternalElements) && (!it->geo->getConstruction() || withConstructionElements)) + auto gf = GeometryFacade::getFacade(it->geo); + if ((!it->external || withExternalElements) && (!gf->getConstruction() || withConstructionElements)) temp.push_back(it->geo->clone()); } @@ -3827,7 +3828,8 @@ TopoShape Sketch::toShape(void) const // collecting all (non constructive and non external) edges out of the sketch for (;it!=Geoms.end();++it) { - if (!it->external && !it->geo->getConstruction() && (it->type != Point)) { + auto gf = GeometryFacade::getFacade(it->geo); + if (!it->external && !gf->getConstruction() && (it->type != Point)) { edge_list.push_back(TopoDS::Edge(it->geo->toShape())); } } diff --git a/src/Mod/Sketcher/App/SketchAnalysis.cpp b/src/Mod/Sketcher/App/SketchAnalysis.cpp index 2849196cca..0f5d3f8070 100644 --- a/src/Mod/Sketcher/App/SketchAnalysis.cpp +++ b/src/Mod/Sketcher/App/SketchAnalysis.cpp @@ -45,6 +45,7 @@ #include #include +#include #include #include "SketchAnalysis.h" @@ -144,13 +145,13 @@ int SketchAnalysis::detectMissingPointOnPointConstraints(double precision, bool std::vector vertexIds; const std::vector& geom = sketch->getInternalGeometry(); for (std::size_t i=0; igetConstruction() && !includeconstruction) + if(gf->getConstruction() && !includeconstruction) continue; - if (g->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *segm = static_cast(g); + if (gf->getGeometry()->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + const Part::GeomLineSegment *segm = static_cast(gf->getGeometry()); VertexIds id; id.GeoId = (int)i; id.PosId = Sketcher::start; @@ -161,8 +162,8 @@ int SketchAnalysis::detectMissingPointOnPointConstraints(double precision, bool id.v = segm->getEndPoint(); vertexIds.push_back(id); } - else if (g->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *segm = static_cast(g); + else if (gf->getGeometry()->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { + const Part::GeomArcOfCircle *segm = static_cast(gf->getGeometry()); VertexIds id; id.GeoId = (int)i; id.PosId = Sketcher::start; @@ -173,8 +174,8 @@ int SketchAnalysis::detectMissingPointOnPointConstraints(double precision, bool id.v = segm->getEndPoint(/*emulateCCW=*/true); vertexIds.push_back(id); } - else if (g->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { - const Part::GeomArcOfEllipse *segm = static_cast(g); + else if (gf->getGeometry()->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { + const Part::GeomArcOfEllipse *segm = static_cast(gf->getGeometry()); VertexIds id; id.GeoId = (int)i; id.PosId = Sketcher::start; @@ -185,8 +186,8 @@ int SketchAnalysis::detectMissingPointOnPointConstraints(double precision, bool id.v = segm->getEndPoint(/*emulateCCW=*/true); vertexIds.push_back(id); } - else if (g->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { - const Part::GeomArcOfHyperbola *segm = static_cast(g); + else if (gf->getGeometry()->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { + const Part::GeomArcOfHyperbola *segm = static_cast(gf->getGeometry()); VertexIds id; id.GeoId = (int)i; id.PosId = Sketcher::start; @@ -197,8 +198,8 @@ int SketchAnalysis::detectMissingPointOnPointConstraints(double precision, bool id.v = segm->getEndPoint(); vertexIds.push_back(id); } - else if (g->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { - const Part::GeomArcOfParabola *segm = static_cast(g); + else if (gf->getGeometry()->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { + const Part::GeomArcOfParabola *segm = static_cast(gf->getGeometry()); VertexIds id; id.GeoId = (int)i; id.PosId = Sketcher::start; @@ -209,8 +210,8 @@ int SketchAnalysis::detectMissingPointOnPointConstraints(double precision, bool id.v = segm->getEndPoint(); vertexIds.push_back(id); } - else if (g->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { - const Part::GeomBSplineCurve *segm = static_cast(g); + else if (gf->getGeometry()->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { + const Part::GeomBSplineCurve *segm = static_cast(gf->getGeometry()); VertexIds id; id.GeoId = (int)i; id.PosId = Sketcher::start; @@ -828,13 +829,13 @@ int SketchAnalysis::detectDegeneratedGeometries(double tolerance) int countDegenerated = 0; const std::vector& geom = sketch->getInternalGeometry(); for (std::size_t i=0; igetConstruction()) + if (gf->getConstruction()) continue; - if (g->getTypeId().isDerivedFrom(Part::GeomCurve::getClassTypeId())) { - Part::GeomCurve* curve = static_cast(g); + if (gf->getGeometry()->getTypeId().isDerivedFrom(Part::GeomCurve::getClassTypeId())) { + Part::GeomCurve* curve = static_cast(gf->getGeometry()); double len = curve->length(curve->getFirstParameter(), curve->getLastParameter()); if (len < tolerance) countDegenerated++; @@ -849,13 +850,13 @@ int SketchAnalysis::removeDegeneratedGeometries(double tolerance) std::set delInternalGeometries; const std::vector& geom = sketch->getInternalGeometry(); for (std::size_t i=0; igetConstruction()) + if (gf->getConstruction()) continue; - if (g->getTypeId().isDerivedFrom(Part::GeomCurve::getClassTypeId())) { - Part::GeomCurve* curve = static_cast(g); + if (gf->getGeometry()->getTypeId().isDerivedFrom(Part::GeomCurve::getClassTypeId())) { + Part::GeomCurve* curve = static_cast(gf->getGeometry()); double len = curve->length(curve->getFirstParameter(), curve->getLastParameter()); if (len < tolerance) delInternalGeometries.insert(static_cast(i)); diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 33e18229ac..a160c19b76 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -78,8 +78,6 @@ #include #include -#include "GeometryFacade.h" - #include "SketchObject.h" #include "Sketch.h" #include @@ -118,14 +116,14 @@ SketchObject::SketchObject() for (std::vector::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::getTypedFacade(); + auto VLine = GeometryTypedFacade::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::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::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(*geo); @@ -894,7 +898,7 @@ int SketchObject::addGeometry(const std::vector &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 &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::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 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; diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 9e624447d1..9d0611839e 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -34,6 +34,8 @@ #include +#include "GeometryFacade.h" + #include "Analyse.h" #include "Sketch.h" @@ -146,6 +148,9 @@ public: * id<=-3 for user defined projected external geometries, */ const Part::Geometry* getGeometry(int GeoId) const; + + std::unique_ptr getGeometryFacade(int GeoId) const; + /// returns a list of all internal geometries const std::vector &getInternalGeometry(void) const { return Geometry.getValues(); } /// returns a list of projected external geometries diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 202b1d6068..970341f1ea 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -238,7 +238,7 @@ bool SketcherGui::isSimpleVertex(const Sketcher::SketchObject* Obj, int GeoId, P bool SketcherGui::isConstructionPoint(const Sketcher::SketchObject* Obj, int GeoId) { const Part::Geometry * geo = Obj->getGeometry(GeoId); - return (geo && geo->getTypeId() == Part::GeomPoint::getClassTypeId() && geo->getConstruction() == true); + return (geo && geo->getTypeId() == Part::GeomPoint::getClassTypeId() && GeometryFacade::getConstruction(geo)); } bool SketcherGui::IsPointAlreadyOnCurve(int GeoIdCurve, int GeoIdPoint, Sketcher::PointPos PosIdPoint, Sketcher::SketchObject* Obj) @@ -7229,7 +7229,7 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) const Part::GeomLineSegment *geo = static_cast(Obj->getGeometry(lineids[0])); - if(!geo->getConstruction()) + if(!Sketcher::GeometryFacade::getConstruction(geo)) Gui::cmdAppObjectArgs(selection[0].getObject(),"toggleConstruction(%d) ",lineids[0]); } @@ -7240,7 +7240,7 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) const Part::GeomLineSegment *geo = static_cast(Obj->getGeometry(lineids[0])); - if(!geo->getConstruction()) + if(!Sketcher::GeometryFacade::getConstruction(geo)) Gui::cmdAppObjectArgs(selection[0].getObject(),"toggleConstruction(%d) ",lineids[0]); minor=true; @@ -7257,7 +7257,7 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) const Part::GeomLineSegment *geo = static_cast(Obj->getGeometry(lineids[1])); - if(!geo->getConstruction()) + if(!Sketcher::GeometryFacade::getConstruction(geo)) Gui::cmdAppObjectArgs(selection[0].getObject(),"toggleConstruction(%d) ",lineids[1]); } else @@ -7407,7 +7407,7 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) const Part::GeomLineSegment *geo = static_cast(Obj->getGeometry(lineids[0])); - if(!geo->getConstruction()) + if(!Sketcher::GeometryFacade::getConstruction(geo)) Gui::cmdAppObjectArgs(selection[0].getObject(),"toggleConstruction(%d) ",lineids[0]); } @@ -7418,7 +7418,7 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) const Part::GeomLineSegment *geo = static_cast(Obj->getGeometry(lineids[0])); - if(!geo->getConstruction()) + if(!Sketcher::GeometryFacade::getConstruction(geo)) Gui::cmdAppObjectArgs(selection[0].getObject(),"toggleConstruction(%d) ",lineids[0]); minor=true; @@ -7435,7 +7435,7 @@ void CmdSketcherConstrainInternalAlignment::activated(int iMsg) const Part::GeomLineSegment *geo = static_cast(Obj->getGeometry(lineids[1])); - if (!geo->getConstruction()) + if (!Sketcher::GeometryFacade::getConstruction(geo)) Gui::cmdAppObjectArgs(selection[0].getObject(),"toggleConstruction(%d) ",lineids[1]); } else diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 0a2939e7d8..d53caf646a 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -5112,7 +5112,7 @@ public: if (GeoIdList.size() == 2 && GeoIdList[0] >= 0 && GeoIdList[1] >= 0) { const Part::Geometry *geom1 = sketchgui->getSketchObject()->getGeometry(GeoIdList[0]); const Part::Geometry *geom2 = sketchgui->getSketchObject()->getGeometry(GeoIdList[1]); - construction=geom1->getConstruction() && geom2->getConstruction(); + construction=Sketcher::GeometryFacade::getConstruction(geom1) && Sketcher::GeometryFacade::getConstruction(geom2); if (geom1->getTypeId() == Part::GeomLineSegment::getClassTypeId() && geom2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { const Part::GeomLineSegment *lineSeg1 = static_cast(geom1); @@ -5195,7 +5195,7 @@ public: if (radius < 0) return false; - construction=lineSeg1->getConstruction() && lineSeg2->getConstruction(); + construction=Sketcher::GeometryFacade::getConstruction(lineSeg1) && Sketcher::GeometryFacade::getConstruction(lineSeg2); } else { // other supported curves const Part::Geometry *geo1 = static_cast @@ -5203,7 +5203,7 @@ public: const Part::Geometry *geo2 = static_cast (sketchgui->getSketchObject()->getGeometry(secondCurve)); - construction=geo1->getConstruction() && geo2->getConstruction(); + construction=Sketcher::GeometryFacade::getConstruction(geo1) && Sketcher::GeometryFacade::getConstruction(geo2); } diff --git a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp index 8a5a8f718a..d833fba3e6 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp @@ -40,6 +40,7 @@ #include "ViewProviderSketch.h" #include +#include #include #include @@ -712,7 +713,7 @@ void TaskSketcherElements::slotElementsChanged(void) int i=1; for(std::vector< Part::Geometry * >::const_iterator it= vals.begin();it!=vals.end();++it,++i){ Base::Type type = (*it)->getTypeId(); - bool construction = (*it)->getConstruction(); + bool construction = Sketcher::GeometryFacade::getConstruction(*it); ui->listWidgetElements->addItem(new ElementItem( (type == Part::GeomPoint::getClassTypeId() && element==1) ? Sketcher_Element_Point_StartingPoint.getIcon(construction, false) : diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 51a3e15bc6..a973353252 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -2726,7 +2726,7 @@ void ViewProviderSketch::updateColor(void) auto isConstructionGeom = [](Sketcher::SketchObject* obj, int GeoId) -> bool { const Part::Geometry* geom = obj->getGeometry(GeoId); if (geom) - return geom->getConstruction(); + return Sketcher::GeometryFacade::getConstruction(geom); return false; }; @@ -2759,7 +2759,7 @@ void ViewProviderSketch::updateColor(void) pverts[i].getValue(x,y,z); const Part::Geometry * tmp = getSketchObject()->getGeometry(edit->PointIdToGeoId[i]); if(tmp && z < zHighlight) { - if(tmp->getConstruction()) + if(Sketcher::GeometryFacade::getConstruction(tmp)) pverts[i].setValue(x,y,zConstrPoint); else pverts[i].setValue(x,y,zNormPoint);