X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintDistance.cpp;h=afe792932bd99f06b85e9d2a49e76bb7b774b388;hb=4f565b2204d3fba046aa8c851abada2a5a17bf6c;hp=e82568d3ef089f60cd569a3c5895a3bc565dab25;hpb=29d446f4dd2969d80087745fe44adb5638d13de7;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintDistance.cpp b/src/SketchSolver/SketchSolver_ConstraintDistance.cpp index e82568d3e..afe792932 100644 --- a/src/SketchSolver/SketchSolver_ConstraintDistance.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintDistance.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + #include #include #include @@ -32,38 +34,32 @@ void SketchSolver_ConstraintDistance::getAttributes( void SketchSolver_ConstraintDistance::adjustConstraint() { - // Adjust point-line distance - if (getType() != CONSTRAINT_PT_LINE_DISTANCE) + ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint).front(); + + // Adjust point-point distance if the points are equal + if (getType() == CONSTRAINT_PT_PT_DISTANCE) { + const std::list& aSubs = aConstraint->entities(); + if (aSubs.front()->isEqual(aSubs.back())) { + // Change X coordinate of second point to eliminate coincidence + ParameterWrapperPtr aX = aSubs.back()->parameters().front(); + aX->setValue(aX->value() + 1.0); + myStorage->update(aX); + } return; + } - // Check the sign of distance is changed - ConstraintWrapperPtr aConstraint = myStorage->constraint(myBaseConstraint).front(); + // Adjust point-line distance if (fabs(myPrevValue) == fabs(aConstraint->value())) { + // sign of distance is not changed aConstraint->setValue(myPrevValue); myStorage->addConstraint(myBaseConstraint, aConstraint); return; } - // Get constraint parameters and check the sign of constraint value + // Adjust the sign of constraint value BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder(); - std::shared_ptr aPoint; - std::shared_ptr aLine; - std::list aSubs = aConstraint->entities(); - std::list::const_iterator aSIt = aSubs.begin(); - for (; aSIt != aSubs.end(); ++aSIt) { - if ((*aSIt)->type() == ENTITY_POINT) - aPoint = aBuilder->point(*aSIt); - else if ((*aSIt)->type() == ENTITY_LINE) - aLine = aBuilder->line(*aSIt); - } - - std::shared_ptr aLineVec = aLine->direction()->xy(); - std::shared_ptr aPtLineVec = aPoint->xy()->decreased(aLine->location()->xy()); - if (aPtLineVec->cross(aLineVec) * aConstraint->value() < 0.0 || myIsNegative) { - aConstraint->setValue(aConstraint->value() * (-1.0)); - myStorage->addConstraint(myBaseConstraint, aConstraint); - myIsNegative = true; - } + aBuilder->adjustConstraint(aConstraint); + myStorage->addConstraint(myBaseConstraint, aConstraint); } void SketchSolver_ConstraintDistance::update()