Sketcher: SketchObject adaptation to Sketch Analysis

Apart for the inclusion of the Analysis functionality, SketchObject has been improved to provide:

- A fast painless deleteAllConstraints() function

- A fast painless constraint group deletion, delConstraints(std::vector<int> ConstrIds, bool updategeometry)
This commit is contained in:
Abdullah Tahiri
2018-07-09 14:14:11 +02:00
committed by wmayer
parent e8e1f13e57
commit d91f338a1a
2 changed files with 170 additions and 1 deletions

View File

@@ -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<Part::Geometry *>::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<int> 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<ConstraintIds> & SketchObject::getMissingPointOnPointConstraints(void)
{
return analyser->getMissingPointOnPointConstraints();
}
std::vector<ConstraintIds> & SketchObject::getMissingVerticalHorizontalConstraints(void)
{
return analyser->getMissingVerticalHorizontalConstraints();
}
std::vector<ConstraintIds> & SketchObject::getMissingLineEqualityConstraints(void)
{
return analyser->getMissingLineEqualityConstraints();
}
std::vector<ConstraintIds> & SketchObject::getMissingRadiusConstraints(void)
{
return analyser->getMissingRadiusConstraints();
}
void SketchObject::setMissingRadiusConstraints(std::vector<ConstraintIds> &cl)
{
if(analyser)
analyser->setMissingRadiusConstraints(cl);
}
void SketchObject::setMissingLineEqualityConstraints(std::vector<ConstraintIds>& cl)
{
if(analyser)
analyser->setMissingLineEqualityConstraints(cl);
}
void SketchObject::setMissingVerticalHorizontalConstraints(std::vector<ConstraintIds>& cl)
{
if(analyser)
analyser->setMissingVerticalHorizontalConstraints(cl);
}
void SketchObject::setMissingPointOnPointConstraints(std::vector<ConstraintIds>& 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 ---------------------------------------------------------

View File

@@ -33,6 +33,10 @@
#include <Mod/Part/App/PropertyGeometryList.h>
#include <Mod/Sketcher/App/PropertyConstraintList.h>
#include <Mod/Sketcher/App/SketchAnalysis.h>
#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 @@ public:
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<Constraint *> &ConstraintList);
/// Copy the constraints instead of cloning them and copying the expressions if any
@@ -107,6 +115,7 @@ public:
int addConstraint(const Constraint *constraint);
/// delete constraint
int delConstraint(int ConstrId);
int delConstraints(std::vector<int> 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 @@ public:
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<ConstraintIds> &getMissingPointOnPointConstraints(void);
std::vector<ConstraintIds> &getMissingVerticalHorizontalConstraints(void);
std::vector<ConstraintIds> &getMissingLineEqualityConstraints(void);
std::vector<ConstraintIds> &getMissingRadiusConstraints(void);
void setMissingRadiusConstraints(std::vector<ConstraintIds> &cl);
void setMissingLineEqualityConstraints(std::vector<ConstraintIds>& cl);
void setMissingVerticalHorizontalConstraints(std::vector<ConstraintIds>& cl);
void setMissingPointOnPointConstraints(std::vector<ConstraintIds>& 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 @@ private:
boost::signals::scoped_connection constraintsRemovedConn;
bool AutoLockTangencyAndPerpty(Constraint* cstr, bool bForce = false, bool bLock = true);
SketchAnalysis * analyser;
};
typedef App::FeaturePythonT<SketchObject> SketchObjectPython;