Salome HOME
Issue #3172: Valid partition is invalid after save/open saved document
authorazv <azv@opencascade.com>
Fri, 28 Feb 2020 13:34:56 +0000 (16:34 +0300)
committerazv <azv@opencascade.com>
Fri, 28 Feb 2020 13:36:21 +0000 (16:36 +0300)
* Improve AttributeSelectionList to cash whole selected features as well as the results.
* Avoid sending EVENT_UPDATE_SELECTION until all the features will obtain their "disabled" flag.

src/GeomAPI/GeomAPI_Shape.cpp
src/Model/Model_AttributeSelectionList.cpp
src/Model/Model_Document.cpp
src/ModelAPI/ModelAPI_Feature.cpp
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp

index 78a10ac3c5ffb0bb6940a29828e1a07dca6c034d..6d5649a75cf3b9bfc367e3e982634ee3ad82b8cd 100644 (file)
@@ -93,11 +93,10 @@ bool GeomAPI_Shape::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
 
 bool GeomAPI_Shape::isSame(const std::shared_ptr<GeomAPI_Shape> theShape) const
 {
-  if (!theShape.get())
-    return false;
+  bool isNullShape = !theShape.get() || theShape->isNull();;
   if (isNull())
-    return theShape->isNull();
-  if (theShape->isNull())
+    return isNullShape;
+  if (isNullShape)
     return false;
 
   return MY_SHAPE->IsSame(theShape->impl<TopoDS_Shape>()) == Standard_True;
index 9e7b0b6ff1144cf9957a4cf6599808398844e791..77fb5185364b0c76ddfa450e62645e0a1c884d9b 100644 (file)
@@ -65,9 +65,7 @@ void Model_AttributeSelectionList::append(
   }
 
   if (myIsCashed && !theTemporarily) {
-    ResultPtr aResContext = std::dynamic_pointer_cast<ModelAPI_Result>(theContext);
-    if (aResContext.get())
-      myCash[aResContext].push_back(theSubShape);
+    myCash[theContext].push_back(theSubShape);
   }
 
   int aNewTag = mySize->Get() + 1;
@@ -315,7 +313,8 @@ bool Model_AttributeSelectionList::isInList(const ObjectPtr& theContext,
             if (!aShapes->get())
               return true;
             ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aContext->first);
-            if (aRes.get() && (*aShapes)->isSame(aRes->shape()))
+            FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(aContext->first);
+            if ((aRes.get() && (*aShapes)->isSame(aRes->shape())) || aFeat.get())
               return true;
           } else {
             // we need to call here isSame instead of isEqual to do not check shapes orientation
@@ -442,7 +441,7 @@ void Model_AttributeSelectionList::cashValues(const bool theEnabled)
     for(int anIndex = size() - 1; anIndex >= 0; anIndex--) {
       AttributeSelectionPtr anAttr = value(anIndex);
       if (anAttr.get()) {
-        myCash[anAttr->context()].push_back(anAttr->value());
+        myCash[anAttr->contextObject()].push_back(anAttr->value());
       }
     }
   }
index 1efd395afc2519c15626f4bd9d77bdc561af615c..cff3d18404df54506d96644a395866659535a9b7 100644 (file)
@@ -1505,6 +1505,9 @@ void Model_Document::setCurrentFeature(
   myIsSetCurrentFeature = false;
   // unblock  the flush signals and up them after this
   aLoop->activateFlushes(isActive);
+
+  static Events_ID kUpdatedSel = aLoop->eventByName(EVENT_UPDATE_SELECTION);
+  aLoop->flush(kUpdatedSel);
 }
 
 void Model_Document::setCurrentFeatureUp()
index 6eacd88767ff741bde1d1766ab8487f852cb14ac..14ce7f46c574cc69834dbd374f5422f6975b4000 100644 (file)
@@ -208,11 +208,13 @@ bool ModelAPI_Feature::setDisabled(const bool theFlag)
         (*aResIter)->setDisabled(*aResIter, false);
       }
       // update selection for the case something was updated higher in the history
-      // while this feature was disabled
+      // while this feature was disabled, but avoid flushing it immediately and
+      // wait while all the previous features update myIsDisabled flag
+      // (flush will be called by the document)
       static Events_Loop* aLoop = Events_Loop::loop();
       static Events_ID kUpdatedSel = aLoop->eventByName(EVENT_UPDATE_SELECTION);
       static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
-      aECreator->sendUpdated(data()->owner(), kUpdatedSel, false);
+      aECreator->sendUpdated(data()->owner(), kUpdatedSel, true);
     }
     return true;
   }
index bae232f486e72a37e9ea4b87b7f53d1e63f12935..0132131b91fe6662e393d44157116cd73b859b56 100644 (file)
@@ -627,8 +627,7 @@ bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
     AttributeSelectionListPtr aSelectionListAttr =
                          std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
-    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-    aHasObject = aSelectionListAttr->isInList(aResult, theShape, theTemporarily);
+    aHasObject = aSelectionListAttr->isInList(theObject, theShape, theTemporarily);
   }
   else if (aType == ModelAPI_AttributeRefList::typeId()) {
     AttributeRefListPtr aRefListAttr =
index fae06823576e8d7bac17d965705f6761dfea4a49..bab6ca0029ab230033e73bc315756249009c52b9 100644 (file)
@@ -937,13 +937,15 @@ bool ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
     for (int i = 0; i < aSelectionListAttr->size(); i++) {
       AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
-      //aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->contextObject());
-      //if (!aFeature.get()) { // Feature can not be found as geometry selection
-        bool aFound = findInSelection(
-          anAttr->contextObject(), anAttr->value(), aGeomSelection, myWorkshop);
-        if (!aFound)
-          anIndicesToBeRemoved.insert(i);
-//      }
+      ObjectPtr aContextObject = anAttr->contextObject();
+      GeomShapePtr aShape;
+      aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aContextObject);
+      if (!aFeature.get())
+        aShape = anAttr->value();
+
+      bool aFound = findInSelection(aContextObject, aShape, aGeomSelection, myWorkshop);
+      if (!aFound)
+        anIndicesToBeRemoved.insert(i);
     }
     isDone = anIndicesToBeRemoved.size() > 0;
     if (isDone)