]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Update the SketchSolver to make constraints changeable
authorazv <azv@opencascade.com>
Fri, 10 Apr 2015 14:02:23 +0000 (17:02 +0300)
committerazv <azv@opencascade.com>
Fri, 10 Apr 2015 14:02:43 +0000 (17:02 +0300)
src/SketchSolver/SketchSolver_Constraint.cpp
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Storage.cpp

index 2a2c85f383839a78c2844797a789d5f8edf6dd41..737809a985e0cf79be25c1cd1bd01eab79359f18 100644 (file)
@@ -116,12 +116,53 @@ void SketchSolver_Constraint::process()
 void SketchSolver_Constraint::update(ConstraintPtr theConstraint)
 {
   cleanErrorMsg();
-  if (theConstraint && theConstraint != myBaseConstraint) {
-    if (theConstraint->getKind() != myBaseConstraint->getKind())
+  bool needToRebuild = (theConstraint && theConstraint != myBaseConstraint);
+  if (!needToRebuild) {
+    // Check the attrbutes of constraint are changed
+    ConstraintPtr aConstraint = theConstraint ? theConstraint : myBaseConstraint;
+    std::list<AttributePtr> anAttrList = aConstraint->data()->attributes(std::string());
+    std::list<AttributePtr>::iterator anAttrIter = anAttrList.begin();
+    for (; anAttrIter != anAttrList.end(); anAttrIter++) {
+      AttributeRefAttrPtr aRefAttr =
+          std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
+      if (aRefAttr) {
+        if (aRefAttr->isObject()) {
+          FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+          if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end()) {
+            needToRebuild = true;
+            break;
+          }
+        } else if (aRefAttr->attr() &&
+                    myAttributeMap.find(aRefAttr->attr()) == myAttributeMap.end()) {
+          needToRebuild = true;
+          break;
+        }
+      }
+      AttributeRefListPtr aRefList =
+          std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrIter);
+      if (aRefList) {
+        std::list<ObjectPtr> anItems = aRefList->list();
+        std::list<ObjectPtr>::iterator anIt = anItems.begin();
+        for (; anIt != anItems.end(); anIt++) {
+          FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+          if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end()) {
+            needToRebuild = true;
+            break;
+          }
+        }
+        if (needToRebuild)
+          break;
+      }
+    }
+  }
+  if (needToRebuild) {
+    if (theConstraint && theConstraint->getKind() != myBaseConstraint->getKind())
       return;
     remove(myBaseConstraint);
-    myBaseConstraint = theConstraint;
+    if (theConstraint)
+      myBaseConstraint = theConstraint;
     process();
+    return;
   }
 
   // Update all attributes
@@ -564,7 +605,15 @@ Slvs_hEntity SketchSolver_Constraint::getId(FeaturePtr theFeature) const
   std::map<FeaturePtr, Slvs_hEntity>::const_iterator aFIter = myFeatureMap.find(theFeature);
   if (aFIter == myFeatureMap.end())
     return SLVS_E_UNKNOWN;
-  return aFIter->second;
+  // check the Feature is really in the storage
+  Slvs_Entity anEntity = myStorage->getEntity(aFIter->second);
+  if (anEntity.h == SLVS_E_UNKNOWN) {
+    // rebuild feature
+    int aType;
+    anEntity.h = const_cast<SketchSolver_Constraint*>(this)->changeEntity(aFIter->first, aType);
+    const_cast<SketchSolver_Constraint*>(this)->myFeatureMap[theFeature] = anEntity.h;
+  }
+  return anEntity.h;
 }
 
 Slvs_hEntity SketchSolver_Constraint::getId(AttributePtr theAttribute) const
index 9ccf3fa73d003b22f7743c08506a2cd0e11bd2d6..58d822786f807d1b4b92446b4e8be22be41dde35 100644 (file)
@@ -235,12 +235,12 @@ bool SketchSolver_Group::changeConstraint(
       setTemporary(aConstraint);
     }
   }
-  // Fix base features for mirror
-  if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
-    AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
-        theConstraint->attribute(SketchPlugin_ConstraintMirror::ENTITY_B()));
-    fixFeaturesList(aRefList);
-  }
+  //// Fix base features for mirror
+  //if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
+  //  AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+  //      theConstraint->attribute(SketchPlugin_ConstraintMirror::ENTITY_B()));
+  //  fixFeaturesList(aRefList);
+  //}
 
   if (!myFeatureStorage)
     myFeatureStorage = FeatureStoragePtr(new SketchSolver_FeatureStorage);
index eddd630c94aa4f9365e79673b170c13436306d5e..421696c175f8828c00fcf99c5f777c4b43162fcd 100644 (file)
@@ -142,13 +142,19 @@ bool SketchSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID)
   bool aResult = true;
   int aPos = Search(theEntityID, myEntities);
   if (aPos >= 0 && aPos < (int)myEntities.size()) {
-    // Firstly, check the entity is not used elsewhere
+    // Firstly, check the entity and its attributes is not used elsewhere
+    std::set<Slvs_hEntity> anEntAndSubs;
+    anEntAndSubs.insert(theEntityID);
+    for (int i = 0; i < 4; i++)
+      if (myEntities[aPos].point[i] != SLVS_E_UNKNOWN)
+        anEntAndSubs.insert(myEntities[aPos].point[i]);
+
     std::vector<Slvs_Entity>::const_iterator anEntIter = myEntities.begin();
     for (; anEntIter != myEntities.end(); anEntIter++) {
       for (int i = 0; i < 4; i++)
-        if (anEntIter->point[i] == theEntityID)
+        if (anEntAndSubs.find(anEntIter->point[i]) != anEntAndSubs.end())
           return false;
-      if (anEntIter->distance == theEntityID)
+      if (anEntAndSubs.find(anEntIter->distance) != anEntAndSubs.end())
         return false;
     }
     std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
@@ -157,7 +163,7 @@ bool SketchSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID)
           aConstrIter->entityA, aConstrIter->entityB,
           aConstrIter->entityC, aConstrIter->entityD};
       for (int i = 0; i < 6; i++)
-        if (anEntIDs[i] == theEntityID)
+        if (anEntAndSubs.find(anEntIDs[i]) != anEntAndSubs.end())
           return false;
     }
     // The entity is not used, remove it and its parameters
@@ -188,7 +194,7 @@ const Slvs_Entity& SketchSolver_Storage::getEntity(const Slvs_hEntity& theEntity
 
   // Entity is not found, return empty object
   static Slvs_Entity aDummy;
-  aDummy.h = 0;
+  aDummy.h = SLVS_E_UNKNOWN;
   return aDummy;
 }
 
@@ -639,7 +645,7 @@ int Search(const uint32_t& theEntityID, const std::vector<T>& theEntities)
     aResIndex--;
   while (aResIndex < aVecSize && aResIndex >= 0 && theEntities[aResIndex].h < theEntityID)
     aResIndex++;
-  if (aResIndex == -1)
+  if (aResIndex == -1 || (aResIndex < aVecSize && theEntities[aResIndex].h != theEntityID))
     aResIndex = aVecSize;
   return aResIndex;
 }