Salome HOME
Fix for the problem of update of the selection attribute value after it becomes inval...
[modules/shaper.git] / src / Model / Model_AttributeSelection.cpp
index 787cc116f1e5157935113c841030387f421f56da..7a06523911063668e287262f956f9f49f1791dd1 100644 (file)
@@ -774,6 +774,8 @@ void Model_AttributeSelection::selectBody(
         aFeatureOwner->removeResults(0, false, false);
     }
     aSel.Select(aNewSub, aNewContext);
+    // face may become divided after the model update, so, new labels may be added to the scope
+    myScope.Clear();
 
     if (aEraseResults) { // flash after Select : in Groups it makes selection with shift working
       static Events_Loop* aLoop = Events_Loop::loop();
@@ -1073,6 +1075,10 @@ void Model_AttributeSelection::selectSubShape(const std::string& theType,
   if (theType.empty() || !thePoint)
     return;
 
+  // list of parent features
+  FeaturePtr anOwner = ModelAPI_Feature::feature(owner());
+  std::set<FeaturePtr> aParents = ModelAPI_Tools::getParents(anOwner);
+
   int aSelectionIndex = 0;
   GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(theType);
   if (aType == GeomAPI_Shape::SHAPE) {
@@ -1095,8 +1101,8 @@ void Model_AttributeSelection::selectSubShape(const std::string& theType,
       aSelectionIndex -= 1;
     }
   }
-  ResultPtr aFoundResult;
-  GeomShapePtr aFoundSubShape;
+
+  std::list<ModelGeomAlgo_Shape::SubshapeOfResult> anAppropriate;
 
   // collect features from PartSet and the current part
   SessionPtr aSession = ModelAPI_Session::get();
@@ -1109,6 +1115,9 @@ void Model_AttributeSelection::selectSubShape(const std::string& theType,
   // to find appropriate sub-shape
   for (std::list<FeaturePtr>::const_reverse_iterator anIt = aFeatures.rbegin();
        anIt != aFeatures.rend(); ++anIt) {
+    // selection cannot be linked to the parent features
+    if (aParents.find(*anIt) != aParents.end())
+      continue;
     // check the feature is a part of composite feature (like sketch elements),
     // then do not process it, it will be processed in scope of composite feature
     bool isSubOfComposite = false;
@@ -1124,12 +1133,17 @@ void Model_AttributeSelection::selectSubShape(const std::string& theType,
       continue;
 
     // process results of the current feature to find appropriate sub-shape
-    if (ModelGeomAlgo_Shape::findSubshapeByPoint(*anIt, thePoint, aType,
-                                                 aFoundResult, aFoundSubShape)) {
-      if (aSelectionIndex > 0)
-        --aSelectionIndex; // skip this shape, because one of the previous is selected
-      else {
-        setValue(aFoundResult, aFoundSubShape);
+    if (ModelGeomAlgo_Shape::findSubshapeByPoint(*anIt, thePoint, aType, anAppropriate)) {
+      std::list<ModelGeomAlgo_Shape::SubshapeOfResult>::iterator anApIt = anAppropriate.begin();
+      for (; aSelectionIndex > 0 && anApIt != anAppropriate.end(); --aSelectionIndex)
+        ++anApIt; // skip this shape, because one of the previous is selected
+
+      if (anApIt != anAppropriate.end()) {
+        if (anApIt->myCenterType == (int)ModelAPI_AttributeSelection::NOT_CENTER)
+          setValue(anApIt->myResult, anApIt->mySubshape);
+        else
+          setValueCenter(anApIt->myResult, anApIt->mySubshape->edge(),
+                         (ModelAPI_AttributeSelection::CenterType)anApIt->myCenterType);
         return;
       }
     }