Salome HOME
group shape: remove COMPOUND on single shape result, activate python plugin
authorrraphael <raphael.raphael@c-s.fr>
Thu, 17 Dec 2020 09:53:12 +0000 (10:53 +0100)
committerrraphael <raphael.raphael@c-s.fr>
Fri, 15 Jan 2021 11:10:10 +0000 (12:10 +0100)
src/CollectionPlugin/CollectionPlugin_GroupShape.cpp
src/PythonAPI/model/collection/__init__.py

index a44ecdba7d19159cb0193d0fd1b648e9081820ea..0a0f90d25ea9b9872287ee6c28e46b0e92ef5f17 100644 (file)
 
 #include "CollectionPlugin_GroupShape.h"
 #include "ModelAPI_ResultBody.h"
+#include <TopoDS.hxx>
+#include <TopoDS_Iterator.hxx>
 
 void CollectionPlugin_GroupShape::execute()
 {  
   ResultGroupPtr aGroup;
   CollectionPlugin_GroupMerge::execute(aGroup);
   GeomShapePtr aCompound = aGroup->shape();
+
+  const TopoDS_Shape & aShape = aCompound->impl<TopoDS_Shape>();
+
+  if(aShape.NbChildren() == 1)
+  {
+    /// unique shape, remove compound on type
+
+    TopoDS_Iterator anIt(aShape);
+    TopoDS_Shape aShape = anIt.Value();
+    std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+    aRes->setImpl(new TopoDS_Shape(aShape));
+    aGroup->store(GeomShapePtr());
+    aGroup->store(aRes);
+    aCompound = aGroup->shape();
+  }
+
   std::shared_ptr<ModelAPI_ResultBody> theResultBody = document()->createBody(data());
   theResultBody->store(GeomShapePtr());
   if(!aCompound->empty())
index 9b71ec825bb557fee2c75162616c9c11ff2f8d5b..b6f4ed15362dd825b2d7c959ca34ea2917a1874d 100644 (file)
@@ -20,4 +20,4 @@
 """
 
 from CollectionAPI import addGroup, addField
-from CollectionAPI import addGroupAddition, addGroupIntersection, addGroupSubstraction
+from CollectionAPI import addGroupAddition, addGroupIntersection, addGroupSubstraction, addGroupShape