]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp
Salome HOME
SketchSolver Refactoring: Eliminate SolveSpace as a sketch solver.
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintCoincidence.cpp
index 18594018c4f38fe3c38f00aa468eae76d1d478d2..8501289fd2b475d9532f2d77cc5eba1796d783d6 100644 (file)
@@ -3,9 +3,37 @@
 #include <SketchSolver_ConstraintCoincidence.h>
 #include <SketchSolver_Error.h>
 #include <SketchSolver_Manager.h>
+#include <PlaneGCSSolver_UpdateCoincidence.h>
+
+void SketchSolver_ConstraintCoincidence::process()
+{
+  cleanErrorMsg();
+  if (!myBaseConstraint || !myStorage) {
+    // Not enough parameters are assigned
+    return;
+  }
+
+  EntityWrapperPtr aValue;
+  std::vector<EntityWrapperPtr> anAttributes;
+  getAttributes(aValue, anAttributes);
+  if (!myErrorMsg.empty())
+    return;
+  if (anAttributes.empty()) {
+    myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
+    return;
+  }
+
+  BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
+  mySolverConstraint = aBuilder->createConstraint(
+      myBaseConstraint, getType(),
+      aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]);
+
+  myStorage->subscribeUpdates(this, PlaneGCSSolver_UpdateCoincidence::GROUP());
+  myStorage->notify(myBaseConstraint);
+}
 
 void SketchSolver_ConstraintCoincidence::getAttributes(
-    double& theValue,
+    EntityWrapperPtr& theValue,
     std::vector<EntityWrapperPtr>& theAttributes)
 {
   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
@@ -14,19 +42,8 @@ void SketchSolver_ConstraintCoincidence::getAttributes(
     return;
   }
 
-  if (theAttributes[1]) {
+  if (theAttributes[1])
     myType = CONSTRAINT_PT_PT_COINCIDENT;
-    if (myStorage->isFixed(theAttributes[1]) && !myStorage->isFixed(theAttributes[0])) {
-      // fixed point should go first
-      EntityWrapperPtr aTemp = theAttributes[0];
-      theAttributes[0] = theAttributes[1];
-      theAttributes[1] = aTemp;
-    }
-    // Set the slave (second) point the same as master (first) point.
-    // This will allow to skip adding point-point coincidence to the set of constraints
-    // and give us speed-up in solving the set of equations
-    myStorage->addCoincidentPoints(theAttributes[0], theAttributes[1]);
-  }
   else if (theAttributes[2]) {
     // check the type of entity (line or circle)
     SketchSolver_EntityType anEntType = theAttributes[2]->type();
@@ -39,3 +56,22 @@ void SketchSolver_ConstraintCoincidence::getAttributes(
   } else
     myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
 }
+
+void SketchSolver_ConstraintCoincidence::notify(const FeaturePtr&      theFeature,
+                                                PlaneGCSSolver_Update* theUpdater)
+{
+  PlaneGCSSolver_UpdateCoincidence* anUpdater =
+      static_cast<PlaneGCSSolver_UpdateCoincidence*>(theUpdater);
+  bool isAccepted = anUpdater->checkCoincidence(myAttributes.front(), myAttributes.back());
+  if (isAccepted) {
+    if (!myInSolver) {
+      myInSolver = true;
+      myStorage->addConstraint(myBaseConstraint, mySolverConstraint);
+    }
+  } else {
+    if (myInSolver) {
+      myInSolver = false;
+      myStorage->removeConstraint(myBaseConstraint);
+    }
+  }
+}