diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 1a412555e635..4e67532e66b2 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -129,6 +129,8 @@ SketchObject::SketchObject() constraintsRemovedConn = Constraints.signalConstraintsRemoved.connect(boost::bind(&Sketcher::SketchObject::constraintsRemoved, this, _1)); constraintsRenamedConn = Constraints.signalConstraintsRenamed.connect(boost::bind(&Sketcher::SketchObject::constraintsRenamed, this, _1)); + + analyser = new SketchAnalysis(this); } SketchObject::~SketchObject() @@ -136,6 +138,8 @@ SketchObject::~SketchObject() for (std::vector::iterator it=ExternalGeo.begin(); it != ExternalGeo.end(); ++it) if (*it) delete *it; ExternalGeo.clear(); + + delete analyser; } App::DocumentObjectExecReturn *SketchObject::execute(void) @@ -811,6 +815,21 @@ int SketchObject::deleteAllGeometry() return 0; } +int SketchObject::deleteAllConstraints() +{ + std::vector< Constraint * > newConstraints(0); + + this->Constraints.setValues(newConstraints); + + this->Constraints.acceptGeometry(getCompleteGeometry()); + rebuildVertexIndex(); + + if(noRecomputes) // if we do not have a recompute, the sketch must be solved to update the DoF of the solver + solve(); + + return 0; +} + int SketchObject::toggleConstruction(int GeoId) { const std::vector< Part::Geometry * > &vals = getInternalGeometry(); @@ -953,6 +972,28 @@ int SketchObject::delConstraint(int ConstrId) return 0; } +int SketchObject::delConstraints(std::vector ConstrIds, bool updategeometry) +{ + const std::vector< Constraint * > &vals = this->Constraints.getValues(); + + std::vector< Constraint * > newVals(vals); + + std::sort(ConstrIds.begin(),ConstrIds.end()); + + if (*ConstrIds.begin() < 0 || *std::prev(ConstrIds.end()) >= int(vals.size())) + return -1; + + for(auto rit = ConstrIds.rbegin(); rit!=ConstrIds.rend(); rit++) + newVals.erase(newVals.begin()+*rit); + + this->Constraints.setValues(newVals); + + if(noRecomputes) // if we do not have a recompute, the sketch must be solved to update the DoF of the solver + solve(updategeometry); + + return 0; +} + int SketchObject::delConstraintOnPoint(int VertexId, bool onlyCoincident) { int GeoId; @@ -6212,6 +6253,98 @@ void SketchObject::setExpression(const App::ObjectIdentifier &path, boost::share solve(); } +int SketchObject::autoConstraint(double precision, double angleprecision, bool includeconstruction) +{ + return analyser->autoconstraint(precision, angleprecision, includeconstruction); +} + +int SketchObject::detectMissingPointOnPointConstraints(double precision, bool includeconstruction) +{ + return analyser->detectMissingPointOnPointConstraints(precision, includeconstruction); +} + +void SketchObject::analyseMissingPointOnPointCoincident(double angleprecision) +{ + analyser->analyseMissingPointOnPointCoincident(angleprecision); +} + +int SketchObject::detectMissingVerticalHorizontalConstraints(double angleprecision) +{ + return analyser->detectMissingVerticalHorizontalConstraints(angleprecision); +} + +int SketchObject::detectMissingEqualityConstraints(double precision) +{ + return analyser->detectMissingEqualityConstraints(precision); +} + +std::vector & SketchObject::getMissingPointOnPointConstraints(void) +{ + return analyser->getMissingPointOnPointConstraints(); +} + +std::vector & SketchObject::getMissingVerticalHorizontalConstraints(void) +{ + return analyser->getMissingVerticalHorizontalConstraints(); +} + +std::vector & SketchObject::getMissingLineEqualityConstraints(void) +{ + return analyser->getMissingLineEqualityConstraints(); +} + +std::vector & SketchObject::getMissingRadiusConstraints(void) +{ + return analyser->getMissingRadiusConstraints(); +} + +void SketchObject::setMissingRadiusConstraints(std::vector &cl) +{ + if(analyser) + analyser->setMissingRadiusConstraints(cl); +} + +void SketchObject::setMissingLineEqualityConstraints(std::vector& cl) +{ + if(analyser) + analyser->setMissingLineEqualityConstraints(cl); +} + +void SketchObject::setMissingVerticalHorizontalConstraints(std::vector& cl) +{ + if(analyser) + analyser->setMissingVerticalHorizontalConstraints(cl); +} + +void SketchObject::setMissingPointOnPointConstraints(std::vector& cl) +{ + if(analyser) + analyser->setMissingPointOnPointConstraints(cl); +} + +void SketchObject::makeMissingPointOnPointCoincident(bool onebyone) +{ + if(analyser) + analyser->makeMissingPointOnPointCoincident(onebyone); +} + +void SketchObject::makeMissingVerticalHorizontal(bool onebyone) +{ + if(analyser) + analyser->makeMissingVerticalHorizontal(onebyone); +} + +void SketchObject::makeMissingEquality(bool onebyone) +{ + if(analyser) + analyser->makeMissingEquality(onebyone); +} + +void SketchObject::autoRemoveRedundants(bool updategeo) +{ + if(analyser) + analyser->autoRemoveRedundants(updategeo); +} // Python Sketcher feature --------------------------------------------------------- diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 2496c82f693f..9f0f24aa201b 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -33,6 +33,10 @@ #include #include +#include + +#include "Analyse.h" + #include "Sketch.h" namespace Sketcher @@ -46,6 +50,8 @@ struct SketcherExport GeoEnum static const int RefExt; }; +class SketchAnalysis; + class SketcherExport SketchObject : public Part::Part2DObject { PROPERTY_HEADER(Sketcher::SketchObject); @@ -99,6 +105,8 @@ class SketcherExport SketchObject : public Part::Part2DObject int delGeometry(int GeoId, bool deleteinternalgeo = true); /// deletes all the elements/constraints of the sketch except for external geometry int deleteAllGeometry(); + /// deletes all the constraints of the sketch + int deleteAllConstraints(); /// add all constraints in the list int addConstraints(const std::vector &ConstraintList); /// Copy the constraints instead of cloning them and copying the expressions if any @@ -107,6 +115,7 @@ class SketcherExport SketchObject : public Part::Part2DObject int addConstraint(const Constraint *constraint); /// delete constraint int delConstraint(int ConstrId); + int delConstraints(std::vector ConstrIds, bool updategeometry=true); int delConstraintOnPoint(int GeoId, PointPos PosId, bool onlyCoincident=true); int delConstraintOnPoint(int VertexId, bool onlyCoincident=true); /// Deletes all constraints referencing an external geometry @@ -354,7 +363,32 @@ class SketcherExport SketchObject : public Part::Part2DObject bool isExternalAllowed(App::Document *pDoc, App::DocumentObject *pObj, eReasonList* rsn = 0) const; bool isCarbonCopyAllowed(App::Document *pDoc, App::DocumentObject *pObj, bool & xinv, bool & yinv, eReasonList* rsn = 0) const; - +public: + // Analyser functions + int autoConstraint(double precision = Precision::Confusion() * 1000, double angleprecision = M_PI/20, bool includeconstruction = true); + + int detectMissingPointOnPointConstraints(double precision = Precision::Confusion() * 1000, bool includeconstruction = true); + void analyseMissingPointOnPointCoincident(double angleprecision = M_PI/8); + int detectMissingVerticalHorizontalConstraints(double angleprecision = M_PI/8); + int detectMissingEqualityConstraints(double precision); + + std::vector &getMissingPointOnPointConstraints(void); + std::vector &getMissingVerticalHorizontalConstraints(void); + std::vector &getMissingLineEqualityConstraints(void); + std::vector &getMissingRadiusConstraints(void); + + void setMissingRadiusConstraints(std::vector &cl); + void setMissingLineEqualityConstraints(std::vector& cl); + void setMissingVerticalHorizontalConstraints(std::vector& cl); + void setMissingPointOnPointConstraints(std::vector& cl); + + void makeMissingPointOnPointCoincident(bool onebyone = false); + void makeMissingVerticalHorizontal(bool onebyone = false); + void makeMissingEquality(bool onebyone = true); + + // helper + void autoRemoveRedundants(bool updategeo); + protected: /// get called by the container when a property has changed virtual void onChanged(const App::Property* /*prop*/); @@ -405,6 +439,8 @@ class SketcherExport SketchObject : public Part::Part2DObject boost::signals::scoped_connection constraintsRemovedConn; bool AutoLockTangencyAndPerpty(Constraint* cstr, bool bForce = false, bool bLock = true); + + SketchAnalysis * analyser; }; typedef App::FeaturePythonT SketchObjectPython;