Salome HOME
add new shape creation from groups
authorrraphael <raphael.raphael@c-s.fr>
Thu, 10 Dec 2020 16:48:16 +0000 (17:48 +0100)
committerrraphael <raphael.raphael@c-s.fr>
Fri, 15 Jan 2021 11:10:10 +0000 (12:10 +0100)
17 files changed:
src/CollectionAPI/CMakeLists.txt
src/CollectionAPI/CollectionAPI.i
src/CollectionAPI/CollectionAPI_GroupShape.cpp [new file with mode: 0644]
src/CollectionAPI/CollectionAPI_GroupShape.h [new file with mode: 0644]
src/CollectionPlugin/CMakeLists.txt
src/CollectionPlugin/CollectionPlugin_GroupAddition.cpp
src/CollectionPlugin/CollectionPlugin_GroupAddition.h
src/CollectionPlugin/CollectionPlugin_GroupMerge.cpp [new file with mode: 0644]
src/CollectionPlugin/CollectionPlugin_GroupMerge.h [new file with mode: 0644]
src/CollectionPlugin/CollectionPlugin_GroupShape.cpp [new file with mode: 0644]
src/CollectionPlugin/CollectionPlugin_GroupShape.h [new file with mode: 0644]
src/CollectionPlugin/CollectionPlugin_Plugin.cpp
src/CollectionPlugin/doc/CollectionPlugin.rst
src/CollectionPlugin/doc/TUI_groupShapeFeature.rst [new file with mode: 0644]
src/CollectionPlugin/doc/examples/group_shape.py [new file with mode: 0644]
src/CollectionPlugin/doc/groupShapeFeature.rst [new file with mode: 0644]
src/CollectionPlugin/plugin-Collection.xml

index 5e1a416db9539f8eb6013941df241f0f5d8fe853..ea0383b90e578ef8e9a675aa090dc10341703dad 100644 (file)
@@ -23,6 +23,7 @@ SET(PROJECT_HEADERS
   CollectionAPI.h
   CollectionAPI_Group.h
   CollectionAPI_GroupAddition.h
+  CollectionAPI_GroupShape.h
   CollectionAPI_GroupIntersection.h
   CollectionAPI_GroupSubstraction.h
   CollectionAPI_Field.h
@@ -31,6 +32,7 @@ SET(PROJECT_HEADERS
 SET(PROJECT_SOURCES
   CollectionAPI_Group.cpp
   CollectionAPI_GroupAddition.cpp
+  CollectionAPI_GroupShape.cpp
   CollectionAPI_GroupIntersection.cpp
   CollectionAPI_GroupSubstraction.cpp
   CollectionAPI_Field.cpp
index 055cc22aa0f15433c1a06022c8e873dd6ded0b3c..6d19f650fb1cc8d801389b66a6c99e6d3523b3a7 100644 (file)
@@ -30,6 +30,7 @@
   #include "CollectionAPI.h"
   #include "CollectionAPI_Group.h"
   #include "CollectionAPI_GroupAddition.h"
+  #include "CollectionAPI_GroupShape.h"
   #include "CollectionAPI_GroupIntersection.h"
   #include "CollectionAPI_GroupSubstraction.h"
   #include "CollectionAPI_Field.h"
@@ -66,6 +67,7 @@
 // shared pointers
 %shared_ptr(CollectionAPI_Group)
 %shared_ptr(CollectionAPI_GroupAddition)
+%shared_ptr(CollectionAPI_GroupShape)
 %shared_ptr(CollectionAPI_GroupIntersection)
 %shared_ptr(CollectionAPI_GroupSubstraction)
 %shared_ptr(CollectionAPI_Field)
@@ -73,6 +75,7 @@
 // all supported interfaces
 %include "CollectionAPI_Group.h"
 %include "CollectionAPI_GroupAddition.h"
+%include "CollectionAPI_GroupShape.h"
 %include "CollectionAPI_GroupIntersection.h"
 %include "CollectionAPI_GroupSubstraction.h"
 %include "CollectionAPI_Field.h"
diff --git a/src/CollectionAPI/CollectionAPI_GroupShape.cpp b/src/CollectionAPI/CollectionAPI_GroupShape.cpp
new file mode 100644 (file)
index 0000000..ba561f3
--- /dev/null
@@ -0,0 +1,71 @@
+// Copyright (C) 2014-2020  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
+//
+
+#include "CollectionAPI_GroupShape.h"
+
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Tools.h>
+
+CollectionAPI_GroupShape::CollectionAPI_GroupShape(
+    const std::shared_ptr<ModelAPI_Feature>& theFeature)
+  : ModelHighAPI_Interface(theFeature)
+{
+  initialize();
+}
+
+CollectionAPI_GroupShape::CollectionAPI_GroupShape(
+    const std::shared_ptr<ModelAPI_Feature>& theFeature,
+    const std::list<ModelHighAPI_Selection>& theGroupList)
+  : ModelHighAPI_Interface(theFeature)
+{
+  if(initialize()) {
+    setGroupList(theGroupList);
+  }
+}
+
+CollectionAPI_GroupShape::~CollectionAPI_GroupShape()
+{
+}
+
+void CollectionAPI_GroupShape::setGroupList(
+    const std::list<ModelHighAPI_Selection>& theGroupList)
+{
+  fillAttribute(theGroupList, mygroupList);
+  execute();
+}
+
+void CollectionAPI_GroupShape::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aDocName = theDumper.name(aBase->document());
+
+  AttributeSelectionListPtr anAttrList =
+      aBase->selectionList(CollectionPlugin_GroupShape::LIST_ID());
+
+  theDumper << aBase << " = model.addGroupShape(" << aDocName << ", "
+            << anAttrList << ")" << std::endl;
+}
+
+GroupShapePtr addGroupShape(const std::shared_ptr<ModelAPI_Document>& thePart,
+                                  const std::list<ModelHighAPI_Selection>& theGroupList)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      thePart->addFeature(CollectionAPI_GroupShape::ID());
+  return GroupShapePtr(new CollectionAPI_GroupShape(aFeature, theGroupList));
+}
diff --git a/src/CollectionAPI/CollectionAPI_GroupShape.h b/src/CollectionAPI/CollectionAPI_GroupShape.h
new file mode 100644 (file)
index 0000000..f2d32a0
--- /dev/null
@@ -0,0 +1,74 @@
+// Copyright (C) 2014-2020  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
+//
+
+#ifndef CollectionAPI_GroupShape_H_
+#define CollectionAPI_GroupShape_H_
+
+#include "CollectionAPI.h"
+
+#include <CollectionPlugin_GroupShape.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+class ModelHighAPI_Dumper;
+class ModelHighAPI_Selection;
+
+/// \class CollectionAPI_GroupShape
+/// \ingroup CPPHighAPI
+/// \brief Interface for Group Shape feature.
+class CollectionAPI_GroupShape : public ModelHighAPI_Interface
+{
+public:
+  /// Constructor without values.
+  COLLECTIONAPI_EXPORT
+  explicit CollectionAPI_GroupShape(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+  /// Constructor with values.
+  COLLECTIONAPI_EXPORT
+  CollectionAPI_GroupShape(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                              const std::list<ModelHighAPI_Selection>& theGroupList);
+
+  /// Destructor.
+  COLLECTIONAPI_EXPORT
+  virtual ~CollectionAPI_GroupShape();
+
+  INTERFACE_1(CollectionPlugin_GroupShape::ID(),
+              groupList, CollectionPlugin_GroupShape::LIST_ID(),
+              ModelAPI_AttributeSelectionList, /** Group list*/)
+
+  /// Set main objects.
+  COLLECTIONAPI_EXPORT
+  void setGroupList(const std::list<ModelHighAPI_Selection>& theGroupList);
+
+  /// Dump wrapped feature
+  COLLECTIONAPI_EXPORT
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+};
+
+/// Pointer on Group Shape object.
+typedef std::shared_ptr<CollectionAPI_GroupShape> GroupShapePtr;
+
+/// \ingroup CPPHighAPI
+/// \brief Create Group Shape feature.
+COLLECTIONAPI_EXPORT
+GroupShapePtr addGroupShape(const std::shared_ptr<ModelAPI_Document>& thePart,
+                                  const std::list<ModelHighAPI_Selection>& theGroupsList);
+
+#endif // CollectionAPI_GroupShape_H_
index bd65ca86ae3b8596ee3c4de3091d10eec88268eb..21b3fbe075b445e27af08c97f9f8f09c5c1852a6 100644 (file)
@@ -32,6 +32,8 @@ SET(PROJECT_HEADERS
     CollectionPlugin_Plugin.h
     CollectionPlugin_Group.h
     CollectionPlugin_GroupAddition.h
+    CollectionPlugin_GroupMerge.h
+    CollectionPlugin_GroupShape.h
     CollectionPlugin_GroupIntersection.h
     CollectionPlugin_GroupOperation.h
     CollectionPlugin_GroupSubstraction.h
@@ -49,6 +51,8 @@ SET(PROJECT_SOURCES
     CollectionPlugin_Plugin.cpp
     CollectionPlugin_Group.cpp
     CollectionPlugin_GroupAddition.cpp
+    CollectionPlugin_GroupMerge.cpp
+    CollectionPlugin_GroupShape.cpp
     CollectionPlugin_GroupIntersection.cpp
     CollectionPlugin_GroupOperation.cpp
     CollectionPlugin_GroupSubstraction.cpp
index 4fb6cab7f7c1219116f6d42b64f5f1430b11b4f1..4799bd3b032905fbef941f8fcaa5e0a9af5ac69a 100644 (file)
 
 #include "CollectionPlugin_GroupAddition.h"
 
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Document.h>
-#include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_AttributeString.h>
-#include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_ResultGroup.h>
-
-#include <GeomAPI_ShapeIterator.h>
-#include <GeomAlgoAPI_CompoundBuilder.h>
-
-CollectionPlugin_GroupAddition::CollectionPlugin_GroupAddition()
-{
-}
-
-void CollectionPlugin_GroupAddition::initAttributes()
-{
-  data()->addAttribute(CollectionPlugin_GroupAddition::LIST_ID(),
-                       ModelAPI_AttributeSelectionList::typeId());
-}
-
-static void explodeCompound(const GeomShapePtr& theCompound, ListOfShape& theSubs)
-{
-  if (theCompound->isCompound()) {
-    GeomAPI_ShapeIterator anIt(theCompound);
-    for (; anIt.more(); anIt.next())
-      explodeCompound(anIt.current(), theSubs);
-  }
-  else
-    theSubs.push_back(theCompound);
-}
-
-static void keepUniqueShapes(ListOfShape& theShapes)
-{
-  ListOfShape::iterator anIt = theShapes.begin();
-  while (anIt != theShapes.end()) {
-    GeomShapePtr aCurrent = *anIt;
-    ListOfShape::iterator anIt2 = theShapes.begin();
-    for (; anIt2 != anIt; ++anIt2)
-      if (aCurrent->isEqual(*anIt2))
-        break;
-    if (anIt2 != anIt) {
-      // the same shape is found
-      ListOfShape::iterator aRemoveIt = anIt++;
-      theShapes.erase(aRemoveIt);
-    }
-    else
-      ++anIt;
-  }
-}
 
 void CollectionPlugin_GroupAddition::execute()
 {
-  ResultGroupPtr aGroup = document()->createGroup(data());
-  // clean the result of the operation
-  aGroup->store(GeomShapePtr());
-
-  // collect all unique sub-shapes
-  GeomShapePtr aCompound = aGroup->shape();
-  ListOfShape aSubs;
-  explodeCompound(aCompound, aSubs);
-  keepUniqueShapes(aSubs);
-  aCompound = aSubs.empty() ? GeomShapePtr() : GeomAlgoAPI_CompoundBuilder::compound(aSubs);
-  aGroup->store(aCompound);
-
-  // update the type of selection
-  updateGroupType(LIST_ID());
-
+  ResultGroupPtr aGroup;
+  CollectionPlugin_GroupMerge::execute(aGroup);
   setResult(aGroup);
 }
index 74f1be90f3c63c543e06acb940b9583bd13c3ae7..d52da423bf1dd571ae9c474571d50ffa28a04fa9 100644 (file)
 
 #include "CollectionPlugin.h"
 #include "CollectionPlugin_GroupOperation.h"
+#include "CollectionPlugin_GroupMerge.h"
 
 /**\class CollectionPlugin_GroupAddition
  * \ingroup Plugins
  * \brief Merge several groups of same shape type into single group.
  */
-class CollectionPlugin_GroupAddition : public CollectionPlugin_GroupOperation
+class CollectionPlugin_GroupAddition : public CollectionPlugin_GroupMerge
 {
 public:
   /// Extrusion kind
@@ -35,13 +36,7 @@ public:
   {
     static const std::string MY_GROUP_ID("GroupAddition");
     return MY_GROUP_ID;
-  }
-  /// attribute name of selected entities list
-  inline static const std::string& LIST_ID()
-  {
-    static const std::string MY_GROUP_LIST_ID("group_list");
-    return MY_GROUP_LIST_ID;
-  }
+  }  
 
   /// Returns the kind of a feature
   COLLECTIONPLUGIN_EXPORT virtual const std::string& getKind()
@@ -51,13 +46,10 @@ public:
   }
 
   /// Creates a new group result if needed
-  COLLECTIONPLUGIN_EXPORT virtual void execute();
-
-  /// Request for initialization of data model of the feature: adding all attributes
-  COLLECTIONPLUGIN_EXPORT virtual void initAttributes();
+  COLLECTIONPLUGIN_EXPORT void execute();
 
   /// Use plugin manager for features creation
-  CollectionPlugin_GroupAddition();
+  CollectionPlugin_GroupAddition() = default;
 
 };
 
diff --git a/src/CollectionPlugin/CollectionPlugin_GroupMerge.cpp b/src/CollectionPlugin/CollectionPlugin_GroupMerge.cpp
new file mode 100644 (file)
index 0000000..cfef811
--- /dev/null
@@ -0,0 +1,84 @@
+// Copyright (C) 2014-2020  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
+//
+
+#include "CollectionPlugin_GroupMerge.h"
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_ResultGroup.h>
+
+#include <GeomAPI_ShapeIterator.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+void CollectionPlugin_GroupMerge::initAttributes()
+{
+  data()->addAttribute(CollectionPlugin_GroupMerge::LIST_ID(),
+                       ModelAPI_AttributeSelectionList::typeId());
+}
+
+static void explodeCompound(const GeomShapePtr& theCompound, ListOfShape& theSubs)
+{
+  if (theCompound->isCompound()) {
+    GeomAPI_ShapeIterator anIt(theCompound);
+    for (; anIt.more(); anIt.next())
+      explodeCompound(anIt.current(), theSubs);
+  }
+  else
+    theSubs.push_back(theCompound);
+}
+
+static void keepUniqueShapes(ListOfShape& theShapes)
+{
+  ListOfShape::iterator anIt = theShapes.begin();
+  while (anIt != theShapes.end()) {
+    GeomShapePtr aCurrent = *anIt;
+    ListOfShape::iterator anIt2 = theShapes.begin();
+    for (; anIt2 != anIt; ++anIt2)
+      if (aCurrent->isEqual(*anIt2))
+        break;
+    if (anIt2 != anIt) {
+      // the same shape is found
+      ListOfShape::iterator aRemoveIt = anIt++;
+      theShapes.erase(aRemoveIt);
+    }
+    else
+      ++anIt;
+  }
+}
+
+void CollectionPlugin_GroupMerge::execute(ResultGroupPtr & aGroup)
+{
+  aGroup = document()->createGroup(data());
+  // clean the result of the operation
+  aGroup->store(GeomShapePtr());
+
+  // collect all unique sub-shapes
+  GeomShapePtr aCompound = aGroup->shape();
+  ListOfShape aSubs;
+  explodeCompound(aCompound, aSubs);
+  keepUniqueShapes(aSubs);
+  aCompound = aSubs.empty() ? GeomShapePtr() : GeomAlgoAPI_CompoundBuilder::compound(aSubs);
+  aGroup->store(aCompound);
+
+  // update the type of selection
+  updateGroupType(LIST_ID());  
+}
diff --git a/src/CollectionPlugin/CollectionPlugin_GroupMerge.h b/src/CollectionPlugin/CollectionPlugin_GroupMerge.h
new file mode 100644 (file)
index 0000000..e56f40f
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright (C) 2014-2020  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
+//
+
+#ifndef COLLECTIONPLUGIN_GROUPMERGE_H_
+#define COLLECTIONPLUGIN_GROUPMERGE_H_
+
+#include "CollectionPlugin.h"
+#include "CollectionPlugin_GroupOperation.h"
+#include "ModelAPI_ResultGroup.h"
+
+/**\class CollectionPlugin_GroupMerge
+ * \ingroup Plugins
+ * \brief Merge several groups of same or different shape type,
+ * \the validator being used for the shape type.
+ */
+class CollectionPlugin_GroupMerge: public CollectionPlugin_GroupOperation
+{
+public:  
+  /// attribute name of selected entities list
+  inline static const std::string& LIST_ID()
+  {
+    static const std::string MY_GROUP_LIST_ID("group_list");
+    return MY_GROUP_LIST_ID;
+  }
+
+
+  /// Creates a new group result if needed
+  COLLECTIONPLUGIN_EXPORT void execute(ResultGroupPtr & aGroup);
+
+  /// Request for initialization of data model of the feature: adding all attributes
+  COLLECTIONPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Use plugin manager for features creation
+  CollectionPlugin_GroupMerge() = default;
+
+};
+
+#endif
diff --git a/src/CollectionPlugin/CollectionPlugin_GroupShape.cpp b/src/CollectionPlugin/CollectionPlugin_GroupShape.cpp
new file mode 100644 (file)
index 0000000..a44ecdb
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (C) 2014-2020  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
+//
+
+#include "CollectionPlugin_GroupShape.h"
+#include "ModelAPI_ResultBody.h"
+
+void CollectionPlugin_GroupShape::execute()
+{  
+  ResultGroupPtr aGroup;
+  CollectionPlugin_GroupMerge::execute(aGroup);
+  GeomShapePtr aCompound = aGroup->shape();
+  std::shared_ptr<ModelAPI_ResultBody> theResultBody = document()->createBody(data());
+  theResultBody->store(GeomShapePtr());
+  if(!aCompound->empty())
+    theResultBody->store(aCompound);
+  setResult(theResultBody);
+}
diff --git a/src/CollectionPlugin/CollectionPlugin_GroupShape.h b/src/CollectionPlugin/CollectionPlugin_GroupShape.h
new file mode 100644 (file)
index 0000000..a69a7a2
--- /dev/null
@@ -0,0 +1,56 @@
+// Copyright (C) 2014-2020  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
+//
+
+#ifndef COLLECTIONPLUGIN_GROUPSHAPE_H_
+#define COLLECTIONPLUGIN_GROUPSHAPE_H_
+
+#include "CollectionPlugin.h"
+#include "CollectionPlugin_GroupOperation.h"
+#include "CollectionPlugin_GroupMerge.h"
+
+/**\class CollectionPlugin_GroupShape
+ * \ingroup Plugins
+ * \brief Merge several groups of different shape type into a single shape.
+ */
+class CollectionPlugin_GroupShape: public CollectionPlugin_GroupMerge
+{
+public:
+  /// Extrusion kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_GROUP_ID("GroupShape");
+    return MY_GROUP_ID;
+  }  
+
+  /// Returns the kind of a feature
+  COLLECTIONPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = CollectionPlugin_GroupShape::ID();
+    return MY_KIND;
+  }
+
+  /// Creates a new group result if needed
+  COLLECTIONPLUGIN_EXPORT void execute();
+
+  /// Use plugin manager for features creation
+  CollectionPlugin_GroupShape() = default;
+
+};
+
+#endif
index c1da4073945d47311911dcdd56d5d960e47d13fb..aea358c62c5198b552fcd82c3d44bf8dcf6eb169 100644 (file)
@@ -23,6 +23,7 @@
 #include <CollectionPlugin_GroupAddition.h>
 #include <CollectionPlugin_GroupIntersection.h>
 #include <CollectionPlugin_GroupSubstraction.h>
+#include <CollectionPlugin_GroupShape.h>
 #include <CollectionPlugin_Field.h>
 #include <CollectionPlugin_Validators.h>
 #include <ModelAPI_Session.h>
@@ -67,7 +68,9 @@ FeaturePtr CollectionPlugin_Plugin::createFeature(std::string theFeatureID)
     return FeaturePtr(new CollectionPlugin_GroupIntersection);
   } else if (theFeatureID == CollectionPlugin_GroupSubstraction::ID()) {
     return FeaturePtr(new CollectionPlugin_GroupSubstraction);
-  }
+  } else if (theFeatureID == CollectionPlugin_GroupShape::ID()) {
+     return FeaturePtr(new CollectionPlugin_GroupShape);
+   }
 
   // feature of such kind is not found
   return FeaturePtr();
index 2b83ddd8cfc0ba857884478d711d43ad92ba32be..f47b202f52944ef5784f75d0491f636a5b51241d 100644 (file)
@@ -16,3 +16,4 @@ Collection plug-in deals with groups of geometrical entities created by selectio
    groupAdditionFeature.rst
    groupIntersectionFeature.rst
    groupSubstractionFeature.rst
+   groupShapeFeature.rst
diff --git a/src/CollectionPlugin/doc/TUI_groupShapeFeature.rst b/src/CollectionPlugin/doc/TUI_groupShapeFeature.rst
new file mode 100644 (file)
index 0000000..d6f9ea6
--- /dev/null
@@ -0,0 +1,11 @@
+
+  .. _tui_create_group_shape:
+
+Create Group Shape
+=====================
+
+.. literalinclude:: examples/group_shape.py
+    :linenos:
+    :language: python
+
+:download:`Download this script <examples/group_shape.py>`
diff --git a/src/CollectionPlugin/doc/examples/group_shape.py b/src/CollectionPlugin/doc/examples/group_shape.py
new file mode 100644 (file)
index 0000000..20e4bde
--- /dev/null
@@ -0,0 +1,14 @@
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Top"),
+                                      model.selection("FACE", "Box_1_1/Left")])
+Group_2 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Front"),
+                                      model.selection("FACE", "Box_1_1/Top")])
+GroupShape_1 = model.addGroupShape(Part_1_doc, [model.selection("COMPOUND", "Group_1"),
+                                                      model.selection("COMPOUND", "Group_2")])
+model.end()
diff --git a/src/CollectionPlugin/doc/groupShapeFeature.rst b/src/CollectionPlugin/doc/groupShapeFeature.rst
new file mode 100644 (file)
index 0000000..33a84a3
--- /dev/null
@@ -0,0 +1,36 @@
+.. |group_shape.icon|    image:: images/group_shape.png
+
+Group Shape
+==============
+
+Group shape produces a new shape from union of all the elements of the selected groups.
+To create a Group Shape in the active part:
+
+#. select in the Main Menu *Features - > Group Shape* item  or
+#. click |group_shape.icon| **Group Shape** button in the toolbar:
+
+The following property panel appears. 
+
+.. figure:: images/group_shape_property_panel.png
+  :align: center
+
+  Create a group shape operation
+
+Input fields:
+
+- **Name** defines the name of the group, by default, it is **GroupShape_n**.
+- The list of selected groups of the same type.  Multiple selection can be done manually in OCC 3D Viewer by mouse click with Shift button pressed or by rectangle selection. To delete entities from the list, select them and call pop-up menu *Delete* item.
+
+Note, that operation is valid only for the groups of the same type.
+
+**TUI Command**:
+
+.. py:function:: model.addGroupShape(Part_1_doc,
+                                       [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2")])
+
+    :param part: The current part object
+    :param list: A list of selected groups
+    :return: Created shape.
+
+
+**See Also** a sample TUI Script of :ref:`tui_create_group_shape` operation.
index ea913123b87290bd257e49b2f009961753ef997d..c20a2b9b6c910cd077702d8f92ddc63a20b76cd3 100644 (file)
@@ -31,6 +31,7 @@
         <source path="group_addition_widget.xml"/>
       </feature>
 
+
       <feature id="GroupIntersection"
         title="Group Intersection"
         tooltip="Get elements existing in all groups"
         helpfile="groupSubstractionFeature.html">
         <source path="group_substraction_widget.xml"/>
       </feature>
+
+      <feature id="GroupShape"
+        title="Group Shape"
+        tooltip="Join several groups to single shape"
+        icon="icons/Collection/group_shape.png"
+        helpfile="groupShapeFeature.html">
+        <source path="group_addition_widget.xml"/>
+      </feature>
+
     </group>
   </workbench>
 </plugin>