]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Distance constraint for equal points (issue #1061)
authorazv <azv@opencascade.com>
Thu, 21 Jan 2016 13:37:22 +0000 (16:37 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:04:27 +0000 (17:04 +0300)
src/SketchSolver/SketchSolver_ConstraintDistance.cpp
src/SketchSolver/SketchSolver_Storage.h
src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp

index e82568d3ef089f60cd569a3c5895a3bc565dab25..2a75e1293f85b4e1c4d69331fb2af61c4e5c6891 100644 (file)
@@ -32,13 +32,23 @@ 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<EntityWrapperPtr>& 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;
index ae0ac3602d4a01bf748e8c9ee5ab373124317bc4..7cd073f70f13dc59bf47eff3d805c976dcfb0d08 100644 (file)
@@ -18,7 +18,7 @@
 #include <ModelAPI_Feature.h>
 #include <SketchPlugin_Constraint.h>
 
-
+class SketchSolver_ConstraintDistance;
 typedef std::map<EntityWrapperPtr, std::set<EntityWrapperPtr> > CoincidentPointsMap;
 
 
@@ -213,6 +213,9 @@ protected:
   std::map<AttributePtr, EntityWrapperPtr>                  myAttributeMap;
 
   CoincidentPointsMap myCoincidentPoints; ///< lists of coincident points (first is a master point, second is a set of slaves)
+
+  // to be able to update entities from constraints
+  friend class SketchSolver_ConstraintDistance;
 };
 
 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;
index fcd53d0e62361d13dd037a35b77bd543c7bb8b4d..1f0632b7186fd06096335ea21ca53db7aec36d12 100644 (file)
@@ -974,12 +974,10 @@ bool SolveSpaceSolver_Storage::remove(ConstraintWrapperPtr theConstraint)
     return true;
 
   bool isFullyRemoved = removeConstraint((Slvs_hConstraint)aConstraint->id());
-  isFullyRemoved = SketchSolver_Storage::remove(theConstraint) && isFullyRemoved;
-
   // remove point-point coincidence
   if (aConstraint->type() == CONSTRAINT_PT_PT_COINCIDENT)
     isFullyRemoved = removeCoincidence(theConstraint) && isFullyRemoved;
-  return isFullyRemoved;
+  return SketchSolver_Storage::remove(theConstraint) && isFullyRemoved;
 }
 
 bool SolveSpaceSolver_Storage::remove(EntityWrapperPtr theEntity)
@@ -1013,7 +1011,7 @@ bool SolveSpaceSolver_Storage::remove(EntityWrapperPtr theEntity)
   std::shared_ptr<SolveSpaceSolver_EntityWrapper> anEntity = 
         std::dynamic_pointer_cast<SolveSpaceSolver_EntityWrapper>(theEntity);
   bool isFullyRemoved = isCoincide ? true : removeEntity((Slvs_hEntity)anEntity->id());
-  return SketchSolver_Storage::remove(theEntity) && isFullyRemoved;
+  return (SketchSolver_Storage::remove(theEntity) || isCoincide) && isFullyRemoved;
 }
 
 bool SolveSpaceSolver_Storage::remove(ParameterWrapperPtr theParameter)