Salome HOME
Add tutorial help page.
[modules/shaper.git] / src / XGUI / XGUI_Tools.cpp
index cd310eef0b4351b893282063740d80f47618ed6e..e5bc7a30829b394cd07d8a7159c7a814285b77b0 100644 (file)
@@ -1,4 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "XGUI_Tools.h"
 
@@ -21,6 +39,9 @@
 #include <Events_InfoMessage.h>
 
 #include <GeomAPI_Shape.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+#include <TopoDS_Shape.hxx>
 
 #include <QDir>
 #include <QMessageBox>
@@ -151,7 +172,66 @@ bool canRename(const ObjectPtr& theObject, const QString& theName)
 XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop)
 {
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
-  return aConnector->workshop();
+  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;
 }
 
 }