Salome HOME
Make concealed and removed objects removed from the Group.
authormpv <mpv@opencascade.com>
Fri, 25 Jan 2019 17:30:16 +0000 (20:30 +0300)
committermpv <mpv@opencascade.com>
Fri, 25 Jan 2019 17:30:16 +0000 (20:30 +0300)
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/Model/Model_Update.cpp
src/SketchPlugin/Test/TestMovementComplex.py

index ba7ebae63a9b39fa71f65155e46476d6daca9821..517ef728dba52c69b1b0b96d3441f5ed1efd5c87 100644 (file)
@@ -1287,8 +1287,41 @@ bool Model_AttributeSelection::searchNewContext(std::shared_ptr<Model_Document>
     } else aResIter++;
   }
 
-  if (aResults.empty())
+  if (aResults.empty()) {
+    // check the context become concealed by operation which is earlier than this selection
+    std::list<ResultPtr> allRes;
+    ResultPtr aRoot = ModelAPI_Tools::bodyOwner(theContext, true);
+    if (!aRoot.get())
+      aRoot = theContext;
+    ResultBodyPtr aRootBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aRoot);
+    if (aRootBody.get()) {
+      ModelAPI_Tools::allSubs(aRootBody, allRes);
+      allRes.push_back(aRootBody);
+    } else
+      allRes.push_back(aRoot);
+
+    FeaturePtr aThisFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
+    for (std::list<ResultPtr>::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) {
+      ResultPtr aResCont = *aSub;
+      const std::set<AttributePtr>& aRefs = aResCont->data()->refsToMe();
+      std::set<AttributePtr>::const_iterator aRef = aRefs.begin();
+      for (; aRef != aRefs.end(); aRef++) {
+        if (!aRef->get() || !(*aRef)->owner().get())
+          continue;
+        // concealed attribute only
+        FeaturePtr aRefFeat = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRef)->owner());
+        if (aRefFeat == aThisFeature)
+          continue;
+        if (!ModelAPI_Session::get()->validators()->isConcealed(
+          aRefFeat->getKind(), (*aRef)->id()))
+          continue;
+        if (!theDoc->isLaterByDep(aRefFeat, aThisFeature)) {
+          return true; // feature conceals result, return true, so the context will be removed
+        }
+      }
+    }
     return false; // no modifications found, must stay the same
+  }
   // iterate all results to find further modifications
   std::set<ResultPtr>::iterator aResIter = aResults.begin();
   for(; aResIter != aResults.end(); aResIter++) {
@@ -1325,7 +1358,7 @@ bool Model_AttributeSelection::searchNewContext(std::shared_ptr<Model_Document>
   return true; // theResults must be empty: everything is deleted
 }
 
-void Model_AttributeSelection::updateInHistory()
+void Model_AttributeSelection::updateInHistory(bool& theRemove)
 {
   ResultPtr aContext = std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
   // only bodies and parts may be modified later in the history, don't do anything otherwise
@@ -1451,10 +1484,14 @@ void Model_AttributeSelection::updateInHistory()
       }
     }
     if (aFirst) { // nothing was added, all results were deleted
-      ResultPtr anEmptyContext;
-      std::shared_ptr<GeomAPI_Shape> anEmptyShape;
-      setValue(anEmptyContext, anEmptyShape); // nullify the selection
-      return;
+      if (myParent) {
+        theRemove = true;
+      } else {
+        ResultPtr anEmptyContext;
+        std::shared_ptr<GeomAPI_Shape> anEmptyShape;
+        setValue(anEmptyContext, anEmptyShape); // nullify the selection
+        return;
+      }
     }
   }
 }
index 741929433d3dc5049cb49535688f7b70f3ff71e5..d240a31782b36124b4ff46435dbb264031e6dcf5 100644 (file)
@@ -122,7 +122,8 @@ public:
 
   /// Updates the arguments of selection if something was affected by creation
   /// or reorder of features upper in the history line (issue #1757)
-  MODEL_EXPORT virtual void updateInHistory();
+  /// Returns theRemove true if this attribute must be removed (become deleted)
+  MODEL_EXPORT virtual void updateInHistory(bool& theRemove);
 
   // Implementation of the name generator method from the Selector package
   // This method returns the context name by the label of the sub-selected shape
index 1f4001e78badf99f6ea304ea9673eb6e96cdf5ad..8356838450635e191e224a07d91c3240c6535660 100755 (executable)
@@ -1066,19 +1066,27 @@ void Model_Update::updateSelection(const std::set<std::shared_ptr<ModelAPI_Objec
     for (; aRefsIter != aRefs.end(); aRefsIter++) {
       std::shared_ptr<Model_AttributeSelection> aSel =
         std::dynamic_pointer_cast<Model_AttributeSelection>(*aRefsIter);
-      aSel->updateInHistory();
+      bool aRemove = false;
+      aSel->updateInHistory(aRemove);
     }
     // update the selection list attributes if any
     aRefs = (*anObj)->data()->attributes(ModelAPI_AttributeSelectionList::typeId());
     for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
+      std::set<int> aRemoveSet;
       std::shared_ptr<ModelAPI_AttributeSelectionList> aSel =
         std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*aRefsIter);
       for(int a = aSel->size() - 1; a >= 0; a--) {
         std::shared_ptr<Model_AttributeSelection> aSelAttr =
           std::dynamic_pointer_cast<Model_AttributeSelection>(aSel->value(a));
-        if (aSelAttr.get())
-          aSelAttr->updateInHistory();
+        if (aSelAttr.get()) {
+          bool theRemove = false;
+          aSelAttr->updateInHistory(theRemove);
+          if (theRemove) {
+            aRemoveSet.insert(a);
+          }
+        }
       }
+      aSel->remove(aRemoveSet);
     }
   }
 }
index d0db233b2b0ac48fb17d2722e5a3cd856379f6b8..2b646ca8c975afeddc11e7965612e4a458b974dc 100644 (file)
@@ -340,9 +340,9 @@ model.do()
 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_9r-SketchLine_8r-SketchLine_7r-SketchLine_6r-SketchLine_14f-SketchLine_16r-SketchArc_3_2r-SketchLine_15f-SketchLine_13r-SketchArc_2_2r-SketchCircle_2_2r")], model.selection(), -165, 155)
 Boolean_1 = model.addFuse(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], [model.selection("SOLID", "Extrusion_2_1")])
 
-Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "(Fuse_1_1/Modified_Face&Extrusion_1_1/To_Face)(Extrusion_1_1/Generated_Face&Sketch_1/SketchArc_1_2)(Fuse_1_1/Modified_Face&Sketch_1/SketchLine_5&Sketch_2/SketchLine_7)"))
+Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "(Fuse_1_1/Modified_Face&Extrusion_1_1/To_Face)(Extrusion_1_1/Generated_Face&Sketch_1/SketchArc_1_2)(Fuse_1_1/Modified_Face&Sketch_2/SketchLine_7&Sketch_1/SketchLine_5)"))
 SketchLine_17 = Sketch_3.addLine(145, 0, 165, 0)
-SketchProjection_2 = Sketch_3.addProjection(model.selection("VERTEX", "[Fuse_1_1/Modified_Face&Extrusion_1_1/From_Face&Sketch_2/SketchLine_6][Fuse_1_1/Modified_Face&Sketch_1/SketchLine_1&Extrusion_2_1/To_Face][Fuse_1_1/Modified_Face&Sketch_1/SketchLine_5&Sketch_2/SketchLine_7]"))
+SketchProjection_2 = Sketch_3.addProjection(model.selection("VERTEX", "[Fuse_1_1/Modified_Face&Sketch_2/SketchLine_6&Extrusion_1_1/From_Face][Fuse_1_1/Modified_Face&Extrusion_2_1/To_Face&Sketch_1/SketchLine_1][Fuse_1_1/Modified_Face&Sketch_2/SketchLine_7&Sketch_1/SketchLine_5]"))
 SketchPoint_2 = SketchProjection_2.createdFeature()
 SketchConstraintCoincidence_23 = Sketch_3.setCoincident(SketchLine_17.endPoint(), SketchAPI_Point(SketchPoint_2).result())
 SketchLine_18 = Sketch_3.addLine(165, 0, 165, -20)
@@ -365,12 +365,12 @@ SketchArc_5 = Sketch_3.addArc(145, -20, 155, -20, 145, -10, False)
 SketchConstraintCoincidence_31 = Sketch_3.setCoincident(SketchLine_19.endPoint(), SketchArc_5.center())
 SketchConstraintCoincidence_32 = Sketch_3.setCoincident(SketchLine_20.result(), SketchArc_5.endPoint())
 SketchConstraintCoincidence_33 = Sketch_3.setCoincident(SketchArc_5.startPoint(), SketchLine_19.result())
-SketchLine_21 = Sketch_3.addLine(model.selection("EDGE", "[Fuse_1_1/Modified_Face&Extrusion_2_1/From_Face][(Fuse_1_1/Modified_Face&Extrusion_2_1/From_Face)(Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_8)(Fuse_1_1/Modified_Face&Sketch_1/SketchLine_5&Sketch_2/SketchLine_7)]"))
+SketchLine_21 = Sketch_3.addLine(model.selection("EDGE", "[Fuse_1_1/Modified_Face&Extrusion_2_1/From_Face][(Fuse_1_1/Modified_Face&Extrusion_2_1/From_Face)(Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_8)(Fuse_1_1/Modified_Face&Sketch_2/SketchLine_7&Sketch_1/SketchLine_5)]"))
 SketchConstraintTangent_5 = Sketch_3.setTangent(SketchArc_5.results()[1], SketchLine_21.result())
 model.do()
 
-ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_3/Face-SketchArc_4_2r-SketchLine_18r-SketchLine_17r")], model.selection(), model.selection("FACE", "Fuse_1_1/Modified_Face&Sketch_1/SketchLine_2&Sketch_2/SketchLine_9"), 0, model.selection(), 0, [model.selection("SOLID", "Fuse_1_1")])
-ExtrusionFuse_1 = model.addExtrusionFuse(Part_1_doc, [model.selection("FACE", "Sketch_3/Face-SketchArc_4_2f-SketchLine_20r-SketchArc_5_2r-SketchLine_19r")], model.selection(), model.selection("FACE", "(Fuse_1_1/Modified_Face&Extrusion_2_1/From_Face)(ExtrusionCut_1_1/Modified_Face&Sketch_1/SketchLine_2&Sketch_2/SketchLine_9)(ExtrusionCut_1_1/Generated_Face&Sketch_3/SketchArc_4_2)(ExtrusionCut_1_1/Modified_Face&Extrusion_2_1/To_Face)(Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_8)"), 0, model.selection(), 0, [model.selection("SOLID", "ExtrusionCut_1_1")])
+ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_3/Face-SketchArc_4_2r-SketchLine_18r-SketchLine_17r")], model.selection(), model.selection("FACE", "Fuse_1_1/Modified_Face&Sketch_2/SketchLine_9&Sketch_1/SketchLine_2"), 0, model.selection(), 0, [model.selection("SOLID", "Fuse_1_1")])
+ExtrusionFuse_1 = model.addExtrusionFuse(Part_1_doc, [model.selection("FACE", "Sketch_3/Face-SketchArc_4_2f-SketchLine_20r-SketchArc_5_2r-SketchLine_19r")], model.selection(), model.selection("FACE", "(Fuse_1_1/Modified_Face&Extrusion_2_1/From_Face)(ExtrusionCut_1_1/Modified_Face&Sketch_2/SketchLine_9&Sketch_1/SketchLine_2)(ExtrusionCut_1_1/Generated_Face&Sketch_3/SketchArc_4_2)(ExtrusionCut_1_1/Modified_Face&Extrusion_2_1/To_Face)(Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_8)"), 0, model.selection(), 0, [model.selection("SOLID", "ExtrusionCut_1_1")])
 model.do()
 
 model.end()