]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix the SketchSolver problems on Undo-Redo operations
authorazv <azv@opencascade.com>
Thu, 16 Apr 2015 08:49:49 +0000 (11:49 +0300)
committerazv <azv@opencascade.com>
Thu, 16 Apr 2015 08:50:00 +0000 (11:50 +0300)
src/SketchSolver/SketchSolver_ConstraintManager.cpp
src/SketchSolver/SketchSolver_FeatureStorage.cpp

index 79616858f5a292c628dc9dbe717d8fad6785bc96..8e2aa58b67ccc529e56207188e713c0939a4c254 100644 (file)
@@ -82,6 +82,9 @@ void SketchSolver_ConstraintManager::processEvent(
         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
     std::set<ObjectPtr> aFeatures = anUpdateMsg->objects();
 
+    // Shows the message has at least one feature applicable for solver
+    bool hasProperFeature = false;
+
     bool isMovedEvt = theMessage->eventID()
         == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED);
     if (isMovedEvt) {
@@ -89,8 +92,10 @@ void SketchSolver_ConstraintManager::processEvent(
       for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
         std::shared_ptr<SketchPlugin_Feature> aSFeature = 
             std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
-        if (aSFeature)
+        if (aSFeature) {
           moveEntity(aSFeature);
+          hasProperFeature = true;
+        }
       }
     } else {
       std::set<ObjectPtr>::iterator aFeatIter;
@@ -103,7 +108,7 @@ void SketchSolver_ConstraintManager::processEvent(
         if (aFeatureKind.compare(SketchPlugin_Sketch::ID()) == 0) {
           std::shared_ptr<ModelAPI_CompositeFeature> aSketch = std::dynamic_pointer_cast<
               ModelAPI_CompositeFeature>(aFeature);
-          changeWorkplane(aSketch);
+          hasProperFeature = changeWorkplane(aSketch) || hasProperFeature;
         }
       }
       // then get anything but not the sketch
@@ -118,7 +123,7 @@ void SketchSolver_ConstraintManager::processEvent(
           aComplexConstraints.insert(aFeature);
           continue;
         }
-        changeConstraintOrEntity(aFeature);
+        hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature;
       }
       // processing remain constraints
       aFeatIter = aComplexConstraints.begin();
@@ -127,12 +132,13 @@ void SketchSolver_ConstraintManager::processEvent(
           std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
         if (!aFeature)
           continue;
-        changeConstraintOrEntity(aFeature);
+        hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature;
       }
     }
 
     // Solve the set of constraints
-    resolveConstraints(isMovedEvt); // send update for movement in any case
+    if (hasProperFeature)
+      resolveConstraints(isMovedEvt); // send update for movement in any case
   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
     std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleteMsg =
         std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
index e274244fb3dba6eb56dfbf4f24a371e28021c09c..34d07b2bfe01066f3c8ad9ad76a3ae1d5271b771 100644 (file)
@@ -9,6 +9,7 @@
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <GeomDataAPI_Point2D.h>
 
 void SketchSolver_FeatureStorage::changeConstraint(ConstraintPtr theConstraint)
 {
@@ -305,6 +306,24 @@ void SketchSolver_FeatureStorage::removeAttribute(AttributePtr theAttribute, Fea
     return; // no such attribute
 
   anAttrIter->second.erase(theFeature);
+  if (!anAttrIter->second.empty())
+    return;
+
+  // Check there is no features containing such attribute
+  MapFeatureConstraint::iterator aFeatIter = myFeatures.begin();
+  for (; aFeatIter != myFeatures.end(); aFeatIter++) {
+    DataPtr aData = aFeatIter->first->data();
+    if (!aData || !aData->isValid())
+      continue;
+    std::list<AttributePtr> anAttrList = aData->attributes(GeomDataAPI_Point2D::typeId());
+    std::list<AttributePtr>::iterator anAtIt = anAttrList.begin();
+    for (; anAtIt != anAttrList.end(); anAtIt++) {
+      std::shared_ptr<GeomDataAPI_Point2D> aPoint =
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anAtIt);
+      if (aPoint == theAttribute)
+        anAttrIter->second.insert(aFeatIter->first);
+    }
+  }
   if (anAttrIter->second.empty())
     myAttributes.erase(anAttrIter);
 }