Skip to content

Commit

Permalink
Sketcher: SketchObject adaptation to Sketch Analysis
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed Jul 29, 2018
1 parent 3dfb202 commit 527c814
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 1 deletion.
133 changes: 133 additions & 0 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -129,13 +129,17 @@ 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()
{
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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ---------------------------------------------------------

Expand Down
38 changes: 37 additions & 1 deletion src/Mod/Sketcher/App/SketchObject.h
Expand Up @@ -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
Expand All @@ -46,6 +50,8 @@ struct SketcherExport GeoEnum
static const int RefExt;
};

class SketchAnalysis;

class SketcherExport SketchObject : public Part::Part2DObject
{
PROPERTY_HEADER(Sketcher::SketchObject);
Expand Down Expand Up @@ -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<Constraint *> &ConstraintList);
/// Copy the constraints instead of cloning them and copying the expressions if any
Expand All @@ -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<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
Expand Down Expand Up @@ -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<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*/);
Expand Down Expand Up @@ -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<SketchObject> SketchObjectPython;
Expand Down

0 comments on commit 527c814

Please sign in to comment.