From: mpv Date: Fri, 25 Jan 2019 17:30:16 +0000 (+0300) Subject: Make concealed and removed objects removed from the Group. X-Git-Tag: HighLevelObjectsHierarchy~13^2~23 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=55ea7e9df2a91ecad9d843e93ea651dcce4aed43;p=modules%2Fshaper.git Make concealed and removed objects removed from the Group. --- diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index ba7ebae63..517ef728d 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -1287,8 +1287,41 @@ bool Model_AttributeSelection::searchNewContext(std::shared_ptr } else aResIter++; } - if (aResults.empty()) + if (aResults.empty()) { + // check the context become concealed by operation which is earlier than this selection + std::list allRes; + ResultPtr aRoot = ModelAPI_Tools::bodyOwner(theContext, true); + if (!aRoot.get()) + aRoot = theContext; + ResultBodyPtr aRootBody = std::dynamic_pointer_cast(aRoot); + if (aRootBody.get()) { + ModelAPI_Tools::allSubs(aRootBody, allRes); + allRes.push_back(aRootBody); + } else + allRes.push_back(aRoot); + + FeaturePtr aThisFeature = std::dynamic_pointer_cast(owner()); + for (std::list::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) { + ResultPtr aResCont = *aSub; + const std::set& aRefs = aResCont->data()->refsToMe(); + std::set::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((*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::iterator aResIter = aResults.begin(); for(; aResIter != aResults.end(); aResIter++) { @@ -1325,7 +1358,7 @@ bool Model_AttributeSelection::searchNewContext(std::shared_ptr 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(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 anEmptyShape; - setValue(anEmptyContext, anEmptyShape); // nullify the selection - return; + if (myParent) { + theRemove = true; + } else { + ResultPtr anEmptyContext; + std::shared_ptr anEmptyShape; + setValue(anEmptyContext, anEmptyShape); // nullify the selection + return; + } } } } diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 741929433..d240a3178 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -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 diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 1f4001e78..835683845 100755 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -1066,19 +1066,27 @@ void Model_Update::updateSelection(const std::set aSel = std::dynamic_pointer_cast(*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 aRemoveSet; std::shared_ptr aSel = std::dynamic_pointer_cast(*aRefsIter); for(int a = aSel->size() - 1; a >= 0; a--) { std::shared_ptr aSelAttr = std::dynamic_pointer_cast(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); } } } diff --git a/src/SketchPlugin/Test/TestMovementComplex.py b/src/SketchPlugin/Test/TestMovementComplex.py index d0db233b2..2b646ca8c 100644 --- a/src/SketchPlugin/Test/TestMovementComplex.py +++ b/src/SketchPlugin/Test/TestMovementComplex.py @@ -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()