Salome HOME
Issue #447: Show message, if the constraint on the same objects is created twice
authorazv <azv@opencascade.com>
Thu, 16 Apr 2015 05:02:11 +0000 (08:02 +0300)
committerazv <azv@opencascade.com>
Thu, 16 Apr 2015 05:02:11 +0000 (08:02 +0300)
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Storage.cpp
src/SketchSolver/SketchSolver_Storage.h

index d7049b111884fe2ea710f69a77675d045308db56..5479601f9f74e45b9e6b3307a20a2b2ffc37034a 100644 (file)
@@ -408,7 +408,10 @@ bool SketchSolver_Group::resolveConstraints()
 
     int aResult = SLVS_RESULT_OKAY;
     try {
-      aResult = myConstrSolver.solve();
+      if (myStorage->hasDuplicatedConstraint())
+        aResult = SLVS_RESULT_INCONSISTENT;
+      else
+        aResult = myConstrSolver.solve();
     } catch (...) {
       Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this);
       return false;
index 421696c175f8828c00fcf99c5f777c4b43162fcd..857c634d4e72bc23a216696fd391c166d2f5b9f7 100644 (file)
@@ -29,7 +29,8 @@ SketchSolver_Storage::SketchSolver_Storage()
     myEntityMaxID(SLVS_E_UNKNOWN),
     myConstrMaxID(SLVS_C_UNKNOWN),
     myFixed(SLVS_E_UNKNOWN),
-    myNeedToResolve(false)
+    myNeedToResolve(false),
+    myDuplicatedConstraint(false)
 {
 }
 
@@ -420,17 +421,15 @@ Slvs_hConstraint SketchSolver_Storage::addConstraint(const Slvs_Constraint& theC
 
   Slvs_Constraint aConstraint = theConstraint;
 
-  // Find a constraint with same type uses same arguments
+  // Find a constraint with same type uses same arguments to show user overconstraint situation
   std::vector<Slvs_Constraint>::iterator aCIt = myConstraints.begin();
   for (; aCIt != myConstraints.end(); aCIt++) {
     if (aConstraint.type != aCIt->type)
       continue;
     if (aConstraint.ptA == aCIt->ptA && aConstraint.ptB == aCIt->ptB &&
         aConstraint.entityA == aCIt->entityA && aConstraint.entityB == aCIt->entityB &&
-        aConstraint.entityC == aCIt->entityC && aConstraint.entityD == aCIt->entityD) {
-      aConstraint.h = aCIt->h;
-      return updateConstraint(aConstraint);
-    }
+        aConstraint.entityC == aCIt->entityC && aConstraint.entityD == aCIt->entityD)
+      myDuplicatedConstraint = true;
   }
 
   if (aConstraint.h > myConstrMaxID)
@@ -484,6 +483,21 @@ bool SketchSolver_Storage::removeConstraint(const Slvs_hConstraint& theConstrain
     // remove temporary fixed point, if available
     if (myFixed == theConstraintID)
       myFixed = SLVS_E_UNKNOWN;
+    if (myDuplicatedConstraint) {
+      // Check the duplicated constraints are still available
+      myDuplicatedConstraint = false;
+      std::vector<Slvs_Constraint>::const_iterator anIt1 = myConstraints.begin();
+      std::vector<Slvs_Constraint>::const_iterator anIt2 = myConstraints.begin();
+      for (; anIt1 != myConstraints.end() && !myDuplicatedConstraint; anIt1++)
+        for (anIt2 = anIt1+1; anIt2 != myConstraints.end() && !myDuplicatedConstraint; anIt2++) {
+          if (anIt1->type != anIt2->type)
+            continue;
+          if (anIt1->ptA == anIt2->ptA && anIt1->ptB == anIt2->ptB &&
+              anIt1->entityA == anIt2->entityA && anIt1->entityB == anIt2->entityB &&
+              anIt1->entityC == anIt2->entityC && anIt1->entityD == anIt2->entityD)
+            myDuplicatedConstraint = true;
+        }
+    }
   }
   return aResult;
 }
index 80fce4563c8911e1d6370ed1c25a1fe5cd2c4b4c..fbd9acf6412592b1382e64ac107e60c142edc8fe 100644 (file)
@@ -115,6 +115,10 @@ public:
   bool isNeedToResolve() const
   { return myNeedToResolve; }
 
+  /// \brief Shows the storage has the same constraint twice
+  bool hasDuplicatedConstraint() const
+  { return myDuplicatedConstraint; }
+
   /// \brief Changes the flag of group to be resolved
   void setNeedToResolve(bool theFlag)
   { myNeedToResolve = theFlag; }
@@ -149,6 +153,7 @@ private:
   Slvs_hConstraint myFixed; ///< identifier of one of temporary constraints to fix separate point
 
   bool myNeedToResolve; ///< parameters are changed and group needs to be resolved
+  bool myDuplicatedConstraint; ///< shows the storage has same constraint twice
 
   std::set<Slvs_hConstraint> myTemporaryConstraints; ///< list of transient constraints
   std::set<Slvs_hParam> myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant)