Salome HOME
Debug of "Concealment" behavior in multiple hierarchy case.
authormpv <mpv@opencascade.com>
Wed, 1 Aug 2018 08:04:01 +0000 (11:04 +0300)
committermpv <mpv@opencascade.com>
Wed, 1 Aug 2018 08:04:14 +0000 (11:04 +0300)
src/Model/Model_Objects.cpp
src/Model/Model_ResultBody.cpp

index 199b249c34ce234e396e11a4670ec7960bfe3fa7..f02468717f2b816ba6396c2f185ede3d5af01d4b 100644 (file)
@@ -682,8 +682,8 @@ std::shared_ptr<ModelAPI_Object> Model_Objects::parent(
   if (theChild.get()) {
     std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theChild->data());
     TDF_Label aLab = aData->label();
-    if (!aLab.IsNull() && aLab.Depth() > 1) {
-      ObjectPtr anObj = object(aLab.Father().Father());
+    if (!aLab.IsNull() && aLab.Depth() > 2) {
+      ObjectPtr anObj = object(aLab.Father().Father().Father());
       return anObj;
     }
   }
@@ -1180,7 +1180,8 @@ bool Model_Objects::hasCustomName(DataPtr theFeatureData,
                                   std::string& theParentName) const
 {
   ResultBodyPtr aBodyRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theFeatureData->owner());
-  if(aBodyRes) {
+  if (aBodyRes && std::dynamic_pointer_cast<Model_Data>(theFeatureData)->label().Depth() < 7) {
+    // only for top-results (works for the cases when results are not yet added to the feature)
     FeaturePtr anOwner = ModelAPI_Feature::feature(theResult);
 
     // names of sub-solids in CompSolid should be default (for example,
index 2a82cc445e47b129595ced1a6212f4c6b9b1acd7..e22a0f38e26e62c0c7bb96e078255bed22b150a1 100644 (file)
@@ -136,58 +136,52 @@ void Model_ResultBody::setIsConcealed(const bool theValue)
   }
 }
 
+// recursively check all subs for concealment flag, returns true if everybody have "flag" state,
+// in theAll returns results with "flag" state
+static bool checkAllSubs(ResultBodyPtr theParent, bool theFlag, std::list<ResultBodyPtr>& theAll)
+{
+  if (theParent->isConcealed() != theFlag)
+    theAll.push_back(theParent);
+  bool aResult = theParent->ModelAPI_ResultBody::isConcealed() == theFlag;
+  for(int a = 0; a < theParent->numberOfSubs(); a++) {
+    bool aSubRes = checkAllSubs(theParent->subResult(a), theFlag, theAll);
+    if (theFlag)
+      aResult = aResult || aSubRes; // concealed: one makes concealed everyone
+    else
+      aResult = aResult && aSubRes; // not concealed: all must be not concealed
+  }
+  return aResult;
+}
+
 void Model_ResultBody::updateConcealment()
 {
   if (myLastConcealed != ModelAPI_ResultBody::isConcealed()) {
-    ResultPtr anOwner = std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner());
-    std::shared_ptr<Model_ResultBody> aParent = std::dynamic_pointer_cast<Model_ResultBody>(
-      ModelAPI_Tools::bodyOwner(anOwner));
-
-    myLastConcealed = ModelAPI_ResultBody::isConcealed(); // set new value and check parent
-    if (myLastConcealed) { // this becomes concealed, so, update all: parent and children
-      if (aParent.get())
-        aParent->updateConcealment();
-      static Events_ID EVENT_DISP =
-        Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-      ModelAPI_EventCreator::get()->sendDeleted(document(), groupName());
-      ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), EVENT_DISP);
-      std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
-      for (; aSubIter != mySubs.cend(); aSubIter++) {
-        std::dynamic_pointer_cast<Model_ResultBody>(*aSubIter)->updateConcealment();
-      }
-    } else {
-      // ask parent: if it is still concealed, nothing is changed
-      if (aParent.get()) {
-        aParent->updateConcealment();
-        if (aParent->isConcealed()) {
-          myLastConcealed = true;
-          return;
-        }
-      }
-      // iterate children: if they are concealed, nothing is changed
-      bool aChildConcealed = false;
-      std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
-      for (; aSubIter != mySubs.cend(); aSubIter++) {
-        std::dynamic_pointer_cast<Model_ResultBody>(*aSubIter)->updateConcealment();
-        if ((*aSubIter)->isConcealed()) {
-          aChildConcealed = true;
-          break;
-        }
-      }
-      if (aChildConcealed) { // some child is concealed, so, update back
-        myLastConcealed = true;
-        if (aParent.get())
-          aParent->updateConcealment();
-        std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
-        for (; aSubIter != mySubs.cend(); aSubIter++) {
-          std::dynamic_pointer_cast<Model_ResultBody>(*aSubIter)->updateConcealment();
+    // check the whole tree of results: if one is concealed, everybody are concealed
+    ResultBodyPtr anOwner = std::dynamic_pointer_cast<ModelAPI_ResultBody>(data()->owner());
+    ResultBodyPtr aParent = ModelAPI_Tools::bodyOwner(anOwner);
+    while(aParent.get()) {
+      anOwner = aParent;
+      aParent = ModelAPI_Tools::bodyOwner(anOwner);
+    }
+    // iterate all results and collect all results whose state may be updated
+    std::list<ResultBodyPtr> anUpdated;
+    bool aNewFlag = !myLastConcealed;
+    if (checkAllSubs(anOwner, aNewFlag, anUpdated)) { // state of everyone must be updated
+      std::list<ResultBodyPtr>::iterator aRes = anUpdated.begin();
+      for(; aRes != anUpdated.end(); aRes++) {
+        bool aLastConcealed = (*aRes)->isConcealed();
+        if (aNewFlag != aLastConcealed) {
+          std::dynamic_pointer_cast<Model_ResultBody>(*aRes)->myLastConcealed = aNewFlag;
+          if (aNewFlag) { // become concealed, behaves like removed
+            ModelAPI_EventCreator::get()->sendDeleted(document(), groupName());
+          } else { // become not-concealed, behaves like created
+            static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+            ModelAPI_EventCreator::get()->sendUpdated(*aRes, anEvent);
+          }
+          static Events_ID EVENT_DISP = // must be redisplayed in any case
+            Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+          ModelAPI_EventCreator::get()->sendUpdated(*aRes, EVENT_DISP);
         }
-      } else { // so, it becomes unconcealed
-        static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
-        ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), anEvent);
-        static Events_ID EVENT_DISP =
-          Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-        ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), EVENT_DISP);
       }
     }
   }
@@ -229,8 +223,10 @@ void Model_ResultBody::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisS
     // erase left, unused results
     while(mySubs.size() > aSubIndex) {
       ResultBodyPtr anErased = *(mySubs.rbegin());
-      if (anErased->ModelAPI_ResultBody::isConcealed())
+      if (anErased->ModelAPI_ResultBody::isConcealed()) {
+        anErased->ModelAPI_ResultBody::setIsConcealed(false);
         std::dynamic_pointer_cast<Model_ResultBody>(anErased)->updateConcealment();
+      }
       anErased->setDisabled(anErased, true);
       mySubsMap.erase(anErased);
       mySubs.pop_back();
@@ -242,8 +238,10 @@ void Model_ResultBody::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisS
   } else if (!mySubs.empty()) { // erase all subs
     while(!mySubs.empty()) {
       ResultBodyPtr anErased = *(mySubs.rbegin());
-      if (anErased->ModelAPI_ResultBody::isConcealed())
+      if (anErased->ModelAPI_ResultBody::isConcealed()) {
+        anErased->ModelAPI_ResultBody::setIsConcealed(false);
         std::dynamic_pointer_cast<Model_ResultBody>(anErased)->updateConcealment();
+      }
       anErased->setDisabled(anErased, true); // even if it is invalid (to erase subs on abort/undo)
       mySubs.pop_back();
     }