Salome HOME
Issue #2593: CEA 2018-2 Geometrical Naming
[modules/shaper.git] / src / Model / Model_AttributeSelection.cpp
index af1020ab5a9463bf89f95b52b181196c57fe907b..90cbe4322e7b0af7ff02ed65c703cd4f3b4fc3eb 100644 (file)
@@ -40,6 +40,7 @@
 #include <Events_InfoMessage.h>
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_ShapeIterator.h>
 #include <GeomAPI_Vertex.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_NExplode.h>
@@ -451,6 +452,10 @@ void Model_AttributeSelection::setID(const std::string theID)
 {
   myRef.setID(theID);
   ModelAPI_AttributeSelection::setID(theID);
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
+  // TODO: check if parent list have geometrical selection flag.
+  myIsGeometricalSelection =
+    ModelAPI_Session::get()->validators()->isGeometricalSelection(aFeature->getKind(), id());
 }
 
 ResultPtr Model_AttributeSelection::context()
@@ -774,7 +779,7 @@ void Model_AttributeSelection::selectBody(
       if (aEraseResults) // erase results without flash deleted and redisplay: do it after Select
         aFeatureOwner->removeResults(0, false, false);
     }
-    aSel.Select(aNewSub, aNewContext);
+    aSel.Select(aNewSub, aNewContext, myIsGeometricalSelection);
     // face may become divided after the model update, so, new labels may be added to the scope
     myScope.Clear();
 
@@ -864,6 +869,14 @@ std::string Model_AttributeSelection::namingName(const std::string& theDefaultNa
     return "";
   }
 
+  if (myIsGeometricalSelection
+      && aSubSh.get()
+      && aSubSh->isCompound())
+  {
+    GeomAPI_ShapeIterator anIt(aSubSh);
+    aSubSh = anIt.current();
+  }
+
   Model_SelectionNaming aSelNaming(selectionLabel());
   std::string aResult = aSelNaming.namingName(
     aCont, aSubSh, theDefaultName, owner()->document() != aCont->document());