]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Task 2.5. Combination operations on Groups (issue #2935)
authorazv <azv@opencascade.com>
Thu, 8 Aug 2019 06:43:07 +0000 (09:43 +0300)
committerazv <azv@opencascade.com>
Thu, 8 Aug 2019 06:43:07 +0000 (09:43 +0300)
Python dump and unit tests for Group Addition operation.

src/CollectionAPI/CMakeLists.txt
src/CollectionAPI/CollectionAPI.i
src/CollectionAPI/CollectionAPI_GroupAddition.cpp [new file with mode: 0644]
src/CollectionAPI/CollectionAPI_GroupAddition.h [new file with mode: 0644]
src/CollectionPlugin/CMakeLists.txt
src/CollectionPlugin/Test/TestGroupAddition.py [new file with mode: 0644]
src/CollectionPlugin/Test/TestGroupAddition_Error.py [new file with mode: 0644]
src/Model/Model_AttributeSelection.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/PythonAPI/model/collection/__init__.py

index 0b2815bdd7250efc16593edcce438936a3efd033..f9ca6033bd8e731332821580257816fb001e3127 100644 (file)
@@ -22,11 +22,13 @@ INCLUDE(Common)
 SET(PROJECT_HEADERS
   CollectionAPI.h
   CollectionAPI_Group.h
+  CollectionAPI_GroupAddition.h
   CollectionAPI_Field.h
 )
 
 SET(PROJECT_SOURCES
   CollectionAPI_Group.cpp
+  CollectionAPI_GroupAddition.cpp
   CollectionAPI_Field.cpp
 )
 
index c27d56cb22240e9bc29f2187c5b7deee85e2c28a..2dee7dd08610cd66c0abcf2fc8502cd03b1a318b 100644 (file)
@@ -29,6 +29,7 @@
 
   #include "CollectionAPI.h"
   #include "CollectionAPI_Group.h"
+  #include "CollectionAPI_GroupAddition.h"
   #include "CollectionAPI_Field.h"
 
 #endif // CollectionAPI_swig_H_
 
 // shared pointers
 %shared_ptr(CollectionAPI_Group)
+%shared_ptr(CollectionAPI_GroupAddition)
 %shared_ptr(CollectionAPI_Field)
 
 // all supported interfaces
 %include "CollectionAPI_Group.h"
+%include "CollectionAPI_GroupAddition.h"
 %include "CollectionAPI_Field.h"
diff --git a/src/CollectionAPI/CollectionAPI_GroupAddition.cpp b/src/CollectionAPI/CollectionAPI_GroupAddition.cpp
new file mode 100644 (file)
index 0000000..d0fecad
--- /dev/null
@@ -0,0 +1,70 @@
+// Copyright (C) 2014-2019  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_GroupAddition.h"
+
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Tools.h>
+
+CollectionAPI_GroupAddition::CollectionAPI_GroupAddition(
+    const std::shared_ptr<ModelAPI_Feature>& theFeature)
+  : ModelHighAPI_Interface(theFeature)
+{
+  initialize();
+}
+
+CollectionAPI_GroupAddition::CollectionAPI_GroupAddition(
+    const std::shared_ptr<ModelAPI_Feature>& theFeature,
+    const std::list<ModelHighAPI_Selection>& theGroupList)
+  : ModelHighAPI_Interface(theFeature)
+{
+  if(initialize()) {
+    setGroupList(theGroupList);
+  }
+}
+
+CollectionAPI_GroupAddition::~CollectionAPI_GroupAddition()
+{
+}
+
+void CollectionAPI_GroupAddition::setGroupList(
+    const std::list<ModelHighAPI_Selection>& theGroupList)
+{
+  fillAttribute(theGroupList, mygroupList);
+  execute();
+}
+
+void CollectionAPI_GroupAddition::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aDocName = theDumper.name(aBase->document());
+
+  AttributeSelectionListPtr anAttrList =
+      aBase->selectionList(CollectionPlugin_GroupAddition::LIST_ID());
+
+  theDumper << aBase << " = model.addGroupAddition(" << aDocName << ", "
+            << anAttrList << ")" << std::endl;
+}
+
+GroupAdditionPtr addGroupAddition(const std::shared_ptr<ModelAPI_Document>& thePart,
+                                  const std::list<ModelHighAPI_Selection>& theGroupList)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(CollectionAPI_GroupAddition::ID());
+  return GroupAdditionPtr(new CollectionAPI_GroupAddition(aFeature, theGroupList));
+}
diff --git a/src/CollectionAPI/CollectionAPI_GroupAddition.h b/src/CollectionAPI/CollectionAPI_GroupAddition.h
new file mode 100644 (file)
index 0000000..c639530
--- /dev/null
@@ -0,0 +1,74 @@
+// Copyright (C) 2014-2019  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_GroupAddition_H_
+#define CollectionAPI_GroupAddition_H_
+
+#include "CollectionAPI.h"
+
+#include <CollectionPlugin_GroupAddition.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+class ModelHighAPI_Dumper;
+class ModelHighAPI_Selection;
+
+/// \class CollectionAPI_GroupAddition
+/// \ingroup CPPHighAPI
+/// \brief Interface for Group feature.
+class CollectionAPI_GroupAddition : public ModelHighAPI_Interface
+{
+public:
+  /// Constructor without values.
+  COLLECTIONAPI_EXPORT
+  explicit CollectionAPI_GroupAddition(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+  /// Constructor with values.
+  COLLECTIONAPI_EXPORT
+  CollectionAPI_GroupAddition(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                              const std::list<ModelHighAPI_Selection>& theGroupList);
+
+  /// Destructor.
+  COLLECTIONAPI_EXPORT
+  virtual ~CollectionAPI_GroupAddition();
+
+  INTERFACE_1(CollectionPlugin_GroupAddition::ID(),
+              groupList, CollectionPlugin_GroupAddition::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 Addition object.
+typedef std::shared_ptr<CollectionAPI_GroupAddition> GroupAdditionPtr;
+
+/// \ingroup CPPHighAPI
+/// \brief Create Group Addition feature.
+COLLECTIONAPI_EXPORT
+GroupAdditionPtr addGroupAddition(const std::shared_ptr<ModelAPI_Document>& thePart,
+                                  const std::list<ModelHighAPI_Selection>& theGroupsList);
+
+#endif // CollectionAPI_Group_H_
index 921596cdd3c7c4e41fe3848ba9103fa17139595e..a19513883a395a360fc992cf93eab3bed0bf6bba 100644 (file)
@@ -133,4 +133,6 @@ ADD_UNIT_TESTS(
                TestGroupMove19.py
                TestGroupMove20.py
                TestGroupShareTopology.py
+               TestGroupAddition.py
+               TestGroupAddition_Error.py
 )
diff --git a/src/CollectionPlugin/Test/TestGroupAddition.py b/src/CollectionPlugin/Test/TestGroupAddition.py
new file mode 100644 (file)
index 0000000..de66eb5
--- /dev/null
@@ -0,0 +1,42 @@
+# Copyright (C) 2014-2019  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
+#
+
+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")])
+GroupAddition_1 = model.addGroupAddition(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2")])
+model.end
+
+from GeomAPI import *
+
+model.testNbResults(GroupAddition_1, 1)
+model.testNbSubResults(GroupAddition_1, [0])
+model.testNbSubShapes(GroupAddition_1, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(GroupAddition_1, GeomAPI_Shape.FACE, [3])
+model.testNbSubShapes(GroupAddition_1, GeomAPI_Shape.EDGE, [12])
+model.testNbSubShapes(GroupAddition_1, GeomAPI_Shape.VERTEX, [24])
+model.testResultsVolumes(GroupAddition_1, [300])
+
+assert(model.checkPythonDump())
diff --git a/src/CollectionPlugin/Test/TestGroupAddition_Error.py b/src/CollectionPlugin/Test/TestGroupAddition_Error.py
new file mode 100644 (file)
index 0000000..ad6934d
--- /dev/null
@@ -0,0 +1,33 @@
+# Copyright (C) 2014-2019  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
+#
+
+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("EDGE", "[Box_1_1/Front][Box_1_1/Bottom]"), model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Right]")])
+GroupAddition_1 = model.addGroupAddition(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2")])
+GroupAddition_2 = model.addGroupAddition(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("FACE", "Box_1_1/Front")])
+model.end
+
+assert(GroupAddition_1.feature().error() != "")
index 26b45f7c865a732f41d8577397ca6a54cb805dd1..ff194dac58e821903d20d866074e6cb6efb238ad 100644 (file)
@@ -896,8 +896,11 @@ void Model_AttributeSelection::selectSubShape(
     // the whole result selection check
     if (aSubShapeName.find('/') == std::string::npos) {
       ObjectPtr aRes = aDoc->objectByName(ModelAPI_ResultConstruction::group(), aSubShapeName);
-      if (!aRes.get())
+      if (!aRes.get()) {
         aRes = aDoc->objectByName(ModelAPI_ResultBody::group(), aSubShapeName);
+        if (!aRes.get())
+          aRes = aDoc->objectByName(ModelAPI_ResultGroup::group(), aSubShapeName);
+      }
       if (aRes.get()) {
         setValue(aRes, anEmptyShape);
         return;
index 409f1b4306313f2eb47a89eaae331be86122aa7d..ef6f1ee621e4e62e6e1d8153220b6f7791a9e2a9 100644 (file)
@@ -52,6 +52,7 @@
 #include <ModelAPI_Result.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultGroup.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Tools.h>
@@ -289,7 +290,8 @@ static void getShapeAndContext(const AttributeSelectionPtr& theAttrSelect,
     if (theAttrSelect->isGeometricalSelection() &&
         theShape.get() && theShape->shapeType() == GeomAPI_Shape::COMPOUND &&
         theContext.get() && !theShape->isEqual(theContext->shape()) &&
-        theContext->groupName() != ModelAPI_ResultPart::group()) {
+        theContext->groupName() != ModelAPI_ResultPart::group() &&
+        theContext->groupName() != ModelAPI_ResultGroup::group()) {
       GeomAPI_ShapeIterator anIt(theShape);
       theShape = anIt.current();
     }
index 5718df5f5c99294827b246ce2663786c96da14c6..96b7089cea35993c65872f60f0b84e236e07eb81 100644 (file)
@@ -20,3 +20,4 @@
 """
 
 from CollectionAPI import addGroup, addField
+from CollectionAPI import addGroupAddition