From 0edf17245c98da1257fd881b7ba44ae148c49628 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sat, 28 Jan 2017 23:05:29 +0100 Subject: [PATCH 1/2] Sketcher: Fix deletion of geometry having internal geometry inserted before the geometry --- src/Mod/Sketcher/App/SketchObject.cpp | 35 +++++++++++++++++++++------ src/Mod/Sketcher/App/SketchObject.h | 4 +-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 1b5d93b15..221a9059d 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -644,13 +644,25 @@ int SketchObject::addGeometry(const Part::Geometry *geo, bool construction/*=fal return Geometry.getSize()-1; } -int SketchObject::delGeometry(int GeoId) +int SketchObject::delGeometry(int GeoId, bool deleteinternalgeo) { const std::vector< Part::Geometry * > &vals = getInternalGeometry(); if (GeoId < 0 || GeoId >= int(vals.size())) return -1; - this->DeleteUnusedInternalGeometry(GeoId); + const Part::Geometry *geo = getGeometry(GeoId); + // Only for supported types + if ((geo->getTypeId() == Part::GeomEllipse::getClassTypeId() || + geo->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId() || + geo->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId() || + geo->getTypeId() == Part::GeomArcOfParabola::getClassTypeId() || + geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId())) { + + if(deleteinternalgeo) { + this->DeleteUnusedInternalGeometry(GeoId, true); + return 0; + } + } std::vector< Part::Geometry * > newVals(vals); newVals.erase(newVals.begin()+GeoId); @@ -3474,7 +3486,7 @@ int SketchObject::ExposeInternalGeometry(int GeoId) return -1; // not supported type } -int SketchObject::DeleteUnusedInternalGeometry(int GeoId) +int SketchObject::DeleteUnusedInternalGeometry(int GeoId, bool delgeoid) { if (GeoId < 0 || GeoId > getHighestCurveIndex()) return -1; @@ -3552,11 +3564,14 @@ int SketchObject::DeleteUnusedInternalGeometry(int GeoId) if (majorconstraints<2) delgeometries.push_back(majorelementindex); + if(delgeoid) + delgeometries.push_back(GeoId); + std::sort(delgeometries.begin(), delgeometries.end()); // indices over an erased element get automatically updated!! if (delgeometries.size()>0) { for (std::vector::reverse_iterator it=delgeometries.rbegin(); it!=delgeometries.rend(); ++it) { - delGeometry(*it); + delGeometry(*it,false); } } @@ -3637,11 +3652,14 @@ int SketchObject::DeleteUnusedInternalGeometry(int GeoId) if (majorelementindex == -1 && focus1elementindex !=-1 && focus1constraints<3) // focus has one coincident and one internal align delgeometries.push_back(focus1elementindex); + if(delgeoid) + delgeometries.push_back(GeoId); + std::sort(delgeometries.begin(), delgeometries.end()); // indices over an erased element get automatically updated!! if (delgeometries.size()>0) { for (std::vector::reverse_iterator it=delgeometries.rbegin(); it!=delgeometries.rend(); ++it) { - delGeometry(*it); + delGeometry(*it,false); } } @@ -3700,11 +3718,14 @@ int SketchObject::DeleteUnusedInternalGeometry(int GeoId) } } + if(delgeoid) + delgeometries.push_back(GeoId); + std::sort(delgeometries.begin(), delgeometries.end()); // indices over an erased element get automatically updated!! if (delgeometries.size()>0) { for (std::vector::reverse_iterator it=delgeometries.rbegin(); it!=delgeometries.rend(); ++it) { - delGeometry(*it); + delGeometry(*it,false); } } @@ -3727,7 +3748,7 @@ int SketchObject::DeleteUnusedInternalGeometry(int GeoId) if (delgeometries.size()>0) { for (std::vector::reverse_iterator it=delgeometries.rbegin(); it!=delgeometries.rend(); ++it) { - delGeometry(*it); + delGeometry(*it,false); } } diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index ccd9931fb..a9ef75e7d 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -91,7 +91,7 @@ public: /// add unspecified geometry int addGeometry(const std::vector &geoList, bool construction=false); /// delete geometry - int delGeometry(int GeoId); + int delGeometry(int GeoId, bool deleteinternalgeo = true); /// add all constraints in the list int addConstraints(const std::vector &ConstraintList); /// add constraint @@ -188,7 +188,7 @@ public: /*! * \return -1 on error */ - int DeleteUnusedInternalGeometry(int GeoId); + int DeleteUnusedInternalGeometry(int GeoId, bool delgeoid=false); /// retrieves for a Vertex number the corresponding GeoId and PosId void getGeoVertexIndex(int VertexId, int &GeoId, PointPos &PosId) const; From 9725be86867b393ab5d69db1f458049a5878eff9 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 29 Jan 2017 00:25:34 +0100 Subject: [PATCH 2/2] Sketcher: Documentation of delete functions --- src/Mod/Sketcher/App/SketchObject.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index a9ef75e7d..224c4800d 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -90,7 +90,12 @@ public: int addGeometry(const Part::Geometry *geo, bool construction=false); /// add unspecified geometry int addGeometry(const std::vector &geoList, bool construction=false); - /// delete geometry + /*! + \brief Deletes indicated geometry (by geoid). + \param GeoId - the geometry to delete + \param deleteinternalgeo - if true deletes the associated and unconstraint internal geometry, otherwise deletes only the GeoId + \retval int - 0 if successful + */ int delGeometry(int GeoId, bool deleteinternalgeo = true); /// add all constraints in the list int addConstraints(const std::vector &ConstraintList); @@ -184,9 +189,11 @@ public: * \return -1 on error */ int ExposeInternalGeometry(int GeoId); - /// Deletes all unused (not further constrained) internal geometry /*! - * \return -1 on error + \brief Deletes all unused (not further constrained) internal geometry + \param GeoId - the geometry having the internal geometry to delete + \param delgeoid - if true in addition to the unused internal geometry also deletes the GeoId geometry + \retval int - returns -1 on error */ int DeleteUnusedInternalGeometry(int GeoId, bool delgeoid=false);