Salome HOME
Fix for #2579, note 7:
[modules/shaper.git] / src / Model / Model_AttributeSelection.cpp
index 787cc116f1e5157935113c841030387f421f56da..2337fb0b58d2bed9e4d3027814fb3e809048f7eb 100644 (file)
@@ -1073,6 +1073,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 +1099,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 +1113,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 +1131,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;
       }
     }