aConstraint.h = myStorage->addConstraint(aConstraint);
mySlvsConstraints.push_back(aConstraint.h);
+ myPrevValue = 0.0;
+ adjustConstraint();
+}
+
+void SketchSolver_ConstraintDistance::adjustConstraint()
+{
// Adjust point-line distance
if (getType() != SLVS_C_PT_LINE_DISTANCE)
return;
+ // Check the sign of distance is changed
+ Slvs_Constraint aConstraint = myStorage->getConstraint(mySlvsConstraints.front());
+ if (fabs(myPrevValue) == fabs(aConstraint.valA)) {
+ aConstraint.valA = myPrevValue;
+ myStorage->updateConstraint(aConstraint);
+ return;
+ }
+
// Get constraint parameters and check the sign of constraint value
std::vector<Slvs_hConstraint>::iterator aCIter = mySlvsConstraints.begin();
for (; aCIter != mySlvsConstraints.end(); aCIter++) {
- Slvs_Constraint aConstraint = myStorage->getConstraint(*aCIter);
+ aConstraint = myStorage->getConstraint(*aCIter);
Slvs_Entity aLine = myStorage->getEntity(aConstraint.entityA);
// Obtain point and line coordinates
Slvs_hEntity aPointID[3] = {aConstraint.ptA, aLine.point[0], aLine.point[1]};
}
}
}
+
+void SketchSolver_ConstraintDistance::update(ConstraintPtr theConstraint)
+{
+ Slvs_Constraint aConstraint = myStorage->getConstraint(mySlvsConstraints.front());
+ myPrevValue = aConstraint.valA;
+ SketchSolver_Constraint::update(theConstraint);
+}
SketchSolver_Constraint(theConstraint), myType(SLVS_C_UNKNOWN)
{}
+ /// \brief Update constraint
+ virtual void update(ConstraintPtr theConstraint = ConstraintPtr());
+
virtual int getType() const
{return myType; }
/// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
virtual void process();
+ /// \brief This method is used in derived objects to check consistence of constraint.
+ /// E.g. the distance between line and point may be signed.
+ virtual void adjustConstraint();
+
private:
int myType; ///< type of constraint (applicable: SLVS_C_PT_PT_DISTANCE, SLVS_C_PT_LINE_DISTANCE)
+ double myPrevValue; ///< previous value of distance (for correct calculation of a distance sign)
};
#endif