Salome HOME
Issue #2556: "What is" window
[modules/shaper.git] / src / XGUI / XGUI_Tools.cpp
index b52be827ea67d9ce23d0112942fb36c1b75eeab2..e5bc7a30829b394cd07d8a7159c7a814285b77b0 100644 (file)
@@ -39,6 +39,9 @@
 #include <Events_InfoMessage.h>
 
 #include <GeomAPI_Shape.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+#include <TopoDS_Shape.hxx>
 
 #include <QDir>
 #include <QMessageBox>
@@ -172,4 +175,63 @@ XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop)
   return aConnector ? aConnector->workshop() : 0;
 }
 
+
+//********************************************************************
+QString generateName(const ModuleBase_ViewerPrsPtr& thePrs)
+{
+  if (!thePrs.get() || !thePrs->object().get())
+    return "Undefined";
+
+  GeomShapePtr aContext;
+  ObjectPtr anObject = thePrs->object();
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+  if (aResult.get())
+    aContext = aResult->shape();
+  else {
+    // TODO if there is this case
+  }
+
+  QString aName = anObject->data()->name().c_str();
+  if (aContext.get()) {
+    GeomShapePtr aSubShape(new GeomAPI_Shape());
+    TopoDS_Shape aShape = ModuleBase_Tools::getSelectedShape(thePrs);
+    aSubShape->setImpl(new TopoDS_Shape(aShape));
+    if (!aSubShape->isEqual(aContext)) {
+      QString aTypeName;
+      switch (aShape.ShapeType()) {
+      case TopAbs_COMPOUND:
+        aTypeName = "compound";
+        break;
+      case TopAbs_COMPSOLID:
+        aTypeName = "compsolid";
+        break;
+      case TopAbs_SOLID:
+        aTypeName = "solid";
+        break;
+      case TopAbs_SHELL:
+        aTypeName = "shell";
+        break;
+      case TopAbs_FACE:
+        aTypeName = "face";
+        break;
+      case TopAbs_WIRE:
+        aTypeName = "wire";
+        break;
+      case TopAbs_EDGE:
+        aTypeName = "edge";
+        break;
+      case TopAbs_VERTEX:
+        aTypeName = "vertex";
+        break;
+      case TopAbs_SHAPE:
+        aTypeName = "shape";
+        break;
+      }
+      int aId = GeomAlgoAPI_CompoundBuilder::id(aContext, aSubShape);
+      aName += QString("/%1_%2").arg(aTypeName).arg(aId);
+    }
+  }
+  return aName;
+}
+
 }