std::vector<Slvs_hConstraint>::iterator aCIter = mySlvsConstraints.begin();
for (; aCIter != mySlvsConstraints.end(); aCIter++) {
Slvs_Constraint aConstraint = myStorage->getConstraint(*aCIter);
- aConstraint.valA = aValue;
+ if (aValueAttr)
+ aConstraint.valA = aValue;
Slvs_hEntity* aCoeffs[6] = {
&aConstraint.ptA, &aConstraint.ptB,
&aConstraint.entityA, &aConstraint.entityB,
#include <GeomDataAPI_Point2D.h>
#include <ModelAPI_AttributeDouble.h>
+#include <math.h>
+
SketchSolver_ConstraintRigid::SketchSolver_ConstraintRigid(FeaturePtr theFeature)
: SketchSolver_Constraint(),
myBaseFeature(theFeature)
void SketchSolver_ConstraintRigid::fixLine(const Slvs_Entity& theLine)
{
Slvs_Constraint anEqual;
- if (isUsedInEqual(theLine, anEqual)) {
+ if (isAxisParallel(theLine)) {
+ // Fix one point and a line length
+ Slvs_hConstraint aFixed;
+ if (!myStorage->isPointFixed(theLine.point[0], aFixed, true) &&
+ !myStorage->isPointFixed(theLine.point[1], aFixed, true))
+ fixPoint(theLine.point[0]);
+ if (!isUsedInEqual(theLine, anEqual)) {
+ // Calculate distance between points on the line
+ double aCoords[4];
+ for (int i = 0; i < 2; i++) {
+ Slvs_Entity aPnt = myStorage->getEntity(theLine.point[i]);
+ for (int j = 0; j < 2; j++) {
+ Slvs_Param aParam = myStorage->getParameter(aPnt.param[j]);
+ aCoords[2*i+j] = aParam.val;
+ }
+ }
+ double aLength = sqrt((aCoords[2] - aCoords[0]) * (aCoords[2] - aCoords[0]) +
+ (aCoords[3] - aCoords[1]) * (aCoords[3] - aCoords[1]));
+ // fix line length
+ Slvs_Constraint aDistance = Slvs_MakeConstraint(SLVS_E_UNKNOWN, myGroup->getId(),
+ SLVS_C_PT_PT_DISTANCE, myGroup->getWorkplaneId(), aLength,
+ theLine.point[0], theLine.point[1], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
+ aDistance.h = myStorage->addConstraint(aDistance);
+ mySlvsConstraints.push_back(aDistance.h);
+ }
+ return;
+ }
+ else if (isUsedInEqual(theLine, anEqual)) {
// Check another entity of Equal is already fixed
Slvs_hEntity anOtherEntID = anEqual.entityA == theLine.h ? anEqual.entityB : anEqual.entityA;
if (myStorage->isEntityFixed(anOtherEntID, true)) {
return false;
}
+bool SketchSolver_ConstraintRigid::isAxisParallel(const Slvs_Entity& theEntity) const
+{
+ std::list<Slvs_Constraint> aConstr = myStorage->getConstraintsByType(SLVS_C_HORIZONTAL);
+ std::list<Slvs_Constraint> aVert = myStorage->getConstraintsByType(SLVS_C_VERTICAL);
+ aConstr.insert(aConstr.end(), aVert.begin(), aVert.end());
+
+ std::list<Slvs_Constraint>::const_iterator anIter = aConstr.begin();
+ for (; anIter != aConstr.end(); anIter++)
+ if (anIter->entityA == theEntity.h)
+ return true;
+ return false;
+}
if (!theConstraint)
return false;
- if (myConstraints.find(theConstraint) == myConstraints.end()) {
+ bool isNewConstraint = myConstraints.find(theConstraint) == myConstraints.end();
+ if (isNewConstraint) {
// Add constraint to the current group
SolverConstraintPtr aConstraint =
SketchSolver_Builder::getInstance()->createConstraint(theConstraint);
myConstraints[theConstraint]->update();
// Fix base features for fillet
- if (theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID()) {
+ if (isNewConstraint && theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID()) {
std::list<AttributePtr> anAttrList =
theConstraint->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
std::list<AttributePtr>::iterator anAttrIter = anAttrList.begin();
return true;
}
}
- // 2. The line is used in Parallel/Perpendicular and Length constraints
+ // 2. The line is used in Parallel/Perpendicular/Vertical/Horizontal and Length constraints
aList = getConstraintsByType(SLVS_C_PARALLEL);
aList.splice(aList.end(), getConstraintsByType(SLVS_C_PERPENDICULAR));
+ aList.splice(aList.end(), getConstraintsByType(SLVS_C_VERTICAL));
+ aList.splice(aList.end(), getConstraintsByType(SLVS_C_HORIZONTAL));
for (anIt = aList.begin(); anIt != aList.end(); anIt++)
if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) {
Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA;