]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Task 3.2. To keep compounds’ sub-shapes for all operations (issue #3139)
authorazv <azv@opencascade.com>
Tue, 25 Feb 2020 07:05:13 +0000 (10:05 +0300)
committerazv <azv@opencascade.com>
Tue, 25 Feb 2020 07:05:13 +0000 (10:05 +0300)
Refactor the Intersection feature.

src/FeaturesAPI/FeaturesAPI.i
src/FeaturesAPI/FeaturesAPI_Intersection.cpp
src/FeaturesAPI/FeaturesAPI_Intersection.h
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp
src/FeaturesPlugin/FeaturesPlugin_Intersection.h
src/FeaturesPlugin/Test/TestIntersection_MultiLevelCompound_v0_1.py [new file with mode: 0644]
src/FeaturesPlugin/Test/TestIntersection_MultiLevelCompound_v0_2.py [new file with mode: 0644]
src/FeaturesPlugin/Test/TestIntersection_MultiLevelCompound_v95_1.py [new file with mode: 0644]
src/FeaturesPlugin/Test/TestIntersection_MultiLevelCompound_v95_2.py [new file with mode: 0644]

index 7d1505907d76bc7a72b0ba18bf2f61e93081c679..c084ba96ca3d5667bdbb6735fd25133ed9d31780 100644 (file)
@@ -41,6 +41,7 @@
 %feature("kwargs") addCommon;
 %feature("kwargs") addCut;
 %feature("kwargs") addFuse;
+%feature("kwargs") addIntersection;
 %feature("kwargs") addMultiRotation;
 %feature("kwargs") addMultiTranslation;
 %feature("kwargs") addPartition;
index 5e85db2d38e5cdd0269c9c070f21049f0161545d..ee3b995836b1c5fc6f7ac110120241f312e3b143 100644 (file)
@@ -66,14 +66,21 @@ void FeaturesAPI_Intersection::dump(ModelHighAPI_Dumper& theDumper) const
   AttributeSelectionListPtr anAttrObjects =
     aBase->selectionList(FeaturesPlugin_Intersection::OBJECT_LIST_ID());
 
-  theDumper << aBase << " = model.addIntersection(" << aDocName << ", "
-            << anAttrObjects << ")" << std::endl;
+  theDumper << aBase << " = model.addIntersection(" << aDocName << ", " << anAttrObjects;
+
+  if (!aBase->data()->version().empty())
+    theDumper << ", keepSubResults = True";
+
+  theDumper << ")" << std::endl;
 }
 
 //==================================================================================================
 IntersectionPtr addIntersection(const std::shared_ptr<ModelAPI_Document>& thePart,
-                                const std::list<ModelHighAPI_Selection>& theObjects)
+                                const std::list<ModelHighAPI_Selection>& theObjects,
+                                const bool keepSubResults)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Intersection::ID());
+  if (!keepSubResults)
+    aFeature->data()->setVersion("");
   return IntersectionPtr(new FeaturesAPI_Intersection(aFeature, theObjects));
 }
index 4135816c8ca2dcce44447381da615d4f734b7f6d..400c520dfaba377ada75c377eb61dfc89a7585ee 100644 (file)
@@ -68,7 +68,8 @@ typedef std::shared_ptr<FeaturesAPI_Intersection> IntersectionPtr;
 /// \ingroup CPPHighAPI
 /// \brief Create Intersection feature.
 FEATURESAPI_EXPORT
-IntersectionPtr addIntersection(const std::shared_ptr<ModelAPI_Document>& thePart,
-                                const std::list<ModelHighAPI_Selection>& theObjects);
+IntersectionPtr addIntersection(const std::shared_ptr<ModelAPI_Document>& part,
+                                const std::list<ModelHighAPI_Selection>& objects,
+                                const bool keepSubResults = false);
 
 #endif // FeaturesAPI_Intersection_H_
index 4aff68961120763743b3d9bd5c8de73793972f71..af203545b98fcd4b51390325fabef4f95545265c 100644 (file)
@@ -633,4 +633,8 @@ ADD_UNIT_TESTS(TestExtrusion.py
                TestMultiRotation_MultiLevelCompound_v95_2.py
                TestMultiRotation_MultiLevelCompound_v95_3.py
                TestMultiRotation_MultiLevelCompound_v95_4.py
+               TestIntersection_MultiLevelCompound_v0_1.py
+               TestIntersection_MultiLevelCompound_v0_2.py
+               TestIntersection_MultiLevelCompound_v95_1.py
+               TestIntersection_MultiLevelCompound_v95_2.py
 )
index 1fa9079247f632a9cf86732de0a28b271bfada7e..23830042e857f9a6fa53d8ba827329fb3f4a05f2 100644 (file)
 #include <ModelAPI_AttributeSelectionList.h>
 
 #include <GeomAlgoAPI_Intersection.h>
+#include <GeomAlgoAPI_MakeShapeList.h>
 #include <GeomAlgoAPI_Tools.h>
 #include <GeomAPI_ShapeExplorer.h>
 
 #include <sstream>
 
+static const std::string INTERSECTION_VERSION_1("v9.5");
+
 //=================================================================================================
 FeaturesPlugin_Intersection::FeaturesPlugin_Intersection()
 {
@@ -39,28 +42,19 @@ FeaturesPlugin_Intersection::FeaturesPlugin_Intersection()
 //=================================================================================================
 void FeaturesPlugin_Intersection::initAttributes()
 {
-  data()->addAttribute(OBJECT_LIST_ID(),
+  AttributePtr anObjectsAttr = data()->addAttribute(OBJECT_LIST_ID(),
                        ModelAPI_AttributeSelectionList::typeId());
+
+  initVersion(INTERSECTION_VERSION_1, anObjectsAttr, AttributePtr());
 }
 
 //=================================================================================================
 void FeaturesPlugin_Intersection::execute()
 {
-  ListOfShape anObjects;
-
+  GeomAPI_ShapeHierarchy anObjectsHierarchy;
+  ListOfShape aPlanes;
   // Getting objects.
-  AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECT_LIST_ID());
-  for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
-    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
-      anObjectsSelList->value(anObjectsIndex);
-    std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
-    if (!anObject.get()) {
-      return;
-    }
-    anObjects.push_back(anObject);
-  }
-
-  if(anObjects.empty()) {
+  if (!processAttribute(OBJECT_LIST_ID(), anObjectsHierarchy, aPlanes)) {
     setError("Error: Objects or tools are empty.");
     return;
   }
@@ -68,6 +62,7 @@ void FeaturesPlugin_Intersection::execute()
   int aResultIndex = 0;
 
   // Create result.
+  const ListOfShape& anObjects = anObjectsHierarchy.objects();
   GeomMakeShapePtr anIntersectionAlgo(new GeomAlgoAPI_Intersection(anObjects));
 
   // Checking that the algorithm worked properly.
@@ -77,38 +72,32 @@ void FeaturesPlugin_Intersection::execute()
     return;
   }
 
+  std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList);
+  aMakeShapeList->appendAlgo(anIntersectionAlgo);
+
+  GeomShapePtr aResShape = anIntersectionAlgo->shape();
+  if (data()->version() == INTERSECTION_VERSION_1) {
+    // merge hierarchies of compounds containing objects and tools
+    // and append the result of the FUSE operation
+    aResShape = keepUnusedSubsOfCompound(aResShape, anObjectsHierarchy,
+                                         GeomAPI_ShapeHierarchy(), aMakeShapeList);
+  }
+
   std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
-  loadNamingDS(aResultBody, anObjects, anIntersectionAlgo);
+  FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
+                                           anObjects,
+                                           ListOfShape(),
+                                           aMakeShapeList,
+                                           aResShape);
   setResult(aResultBody, aResultIndex);
   aResultIndex++;
 
+  FeaturesPlugin_Tools::loadDeletedShapes(aResultBody,
+                                          GeomShapePtr(),
+                                          anObjects,
+                                          aMakeShapeList,
+                                          aResShape);
+
   // remove the rest results if there were produced in the previous pass
   removeResults(aResultIndex);
 }
-
-//=================================================================================================
-void FeaturesPlugin_Intersection::loadNamingDS(ResultBodyPtr theResultBody,
-                                               const ListOfShape& theObjects,
-                                               const GeomMakeShapePtr& theMakeShape)
-{
-  std::shared_ptr<GeomAPI_Shape> aResultShape = theMakeShape->shape();
-
-  if(theObjects.front()->isEqual(aResultShape)) {
-    theResultBody->store(aResultShape, false);
-    return;
-  }
-
-  theResultBody->storeModified(theObjects, aResultShape, theMakeShape);
-
-  const int aShapeTypesNb = 3;
-  const GeomAPI_Shape::ShapeType aShapeTypes[aShapeTypesNb] = {GeomAPI_Shape::VERTEX,
-                                                               GeomAPI_Shape::EDGE,
-                                                               GeomAPI_Shape::FACE };
-  for (ListOfShape::const_iterator anIt = theObjects.cbegin(); anIt != theObjects.cend(); ++anIt) {
-    const GeomShapePtr aShape = *anIt;
-    for(int anIndex = 0; anIndex < aShapeTypesNb; ++anIndex) {
-      theResultBody->loadModifiedShapes(theMakeShape, aShape, aShapeTypes[anIndex]);
-      theResultBody->loadGeneratedShapes(theMakeShape, aShape, aShapeTypes[anIndex]);
-    }
-  }
-}
index 6d4d99cdfeba75b18a5c8c983b7533e894488d4d..af7181753f1d2ec3d61015e505dea01853377e0e 100644 (file)
 #ifndef FeaturesPlugin_Intersection_H_
 #define FeaturesPlugin_Intersection_H_
 
-#include "FeaturesPlugin.h"
-
-#include <ModelAPI_Feature.h>
-
-#include <GeomAPI_Shape.h>
+#include "FeaturesPlugin_VersionedBoolean.h"
 
 class GeomAlgoAPI_MakeShape;
 
@@ -35,7 +31,7 @@ class GeomAlgoAPI_MakeShape;
 /// whole objects, compsoilds, solids, shells, faces or edges.
 /// The result is less than the minimal dimension from pair of intersection:
 /// for two solids or two faces it is wire, for the edge and face it is vertex, etc.
-class FeaturesPlugin_Intersection : public ModelAPI_Feature
+class FeaturesPlugin_Intersection : public FeaturesPlugin_VersionedBoolean
 {
 public:
   /// Feature kind.
@@ -67,12 +63,6 @@ public:
 
   /// Use plugin manager for features creation.
   FeaturesPlugin_Intersection();
-
-private:
-  /// Load Naming data structure of the feature to the document.
-  void loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-                    const ListOfShape& theObjects,
-                    const std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape);
 };
 
 #endif
diff --git a/src/FeaturesPlugin/Test/TestIntersection_MultiLevelCompound_v0_1.py b/src/FeaturesPlugin/Test/TestIntersection_MultiLevelCompound_v0_1.py
new file mode 100644 (file)
index 0000000..d3c0269
--- /dev/null
@@ -0,0 +1,44 @@
+# Copyright (C) 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
+#
+
+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)
+LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 20, 2)
+Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 5)
+Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOY"), model.selection("EDGE", "PartSet/OX"), 30)
+Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1"), model.selection("FACE", "Plane_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "LinearCopy_1_1_1"), model.selection("SOLID", "Partition_1_1_1")])
+model.end()
+
+from GeomAPI import *
+
+model.testNbResults(Intersection_1, 1)
+model.testNbSubResults(Intersection_1, [6])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.FACE, [0])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.EDGE, [6])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.VERTEX, [12])
+model.testResultsVolumes(Intersection_1, [0])
+
+assert(model.checkPythonDump())
diff --git a/src/FeaturesPlugin/Test/TestIntersection_MultiLevelCompound_v0_2.py b/src/FeaturesPlugin/Test/TestIntersection_MultiLevelCompound_v0_2.py
new file mode 100644 (file)
index 0000000..7c7384e
--- /dev/null
@@ -0,0 +1,43 @@
+# Copyright (C) 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
+#
+
+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)
+LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 20, 2)
+Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
+LinearCopy_2 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], model.selection("EDGE", "PartSet/OY"), 20, 3)
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "LinearCopy_1_1_1"), model.selection("SOLID", "LinearCopy_2_1_1")])
+model.end()
+
+from GeomAPI import *
+
+model.testNbResults(Intersection_1, 1)
+model.testNbSubResults(Intersection_1, [8])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.FACE, [0])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.EDGE, [8])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.VERTEX, [16])
+model.testResultsVolumes(Intersection_1, [0])
+
+assert(model.checkPythonDump())
diff --git a/src/FeaturesPlugin/Test/TestIntersection_MultiLevelCompound_v95_1.py b/src/FeaturesPlugin/Test/TestIntersection_MultiLevelCompound_v95_1.py
new file mode 100644 (file)
index 0000000..e2a5d63
--- /dev/null
@@ -0,0 +1,44 @@
+# Copyright (C) 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
+#
+
+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)
+LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 20, 2, keepSubResults = True)
+Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 5)
+Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOY"), model.selection("EDGE", "PartSet/OX"), 30)
+Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1"), model.selection("FACE", "Plane_1")], keepSubResults = True)
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "LinearCopy_1_1_1"), model.selection("SOLID", "Partition_1_1_1")], keepSubResults = True)
+model.end()
+
+from GeomAPI import *
+
+model.testNbResults(Intersection_1, 1)
+model.testNbSubResults(Intersection_1, [2])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.FACE, [6])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.EDGE, [30])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.VERTEX, [60])
+model.testResultsVolumes(Intersection_1, [1000])
+
+assert(model.checkPythonDump())
diff --git a/src/FeaturesPlugin/Test/TestIntersection_MultiLevelCompound_v95_2.py b/src/FeaturesPlugin/Test/TestIntersection_MultiLevelCompound_v95_2.py
new file mode 100644 (file)
index 0000000..9b1cc3b
--- /dev/null
@@ -0,0 +1,43 @@
+# Copyright (C) 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
+#
+
+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)
+LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 20, 2, keepSubResults = True)
+Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
+LinearCopy_2 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], model.selection("EDGE", "PartSet/OY"), 20, 3, keepSubResults = True)
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "LinearCopy_1_1_1"), model.selection("SOLID", "LinearCopy_2_1_1")], keepSubResults = True)
+model.end()
+
+from GeomAPI import *
+
+model.testNbResults(Intersection_1, 1)
+model.testNbSubResults(Intersection_1, [3])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.SOLID, [3])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.FACE, [12])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.EDGE, [44])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.VERTEX, [88])
+model.testResultsVolumes(Intersection_1, [2570.79632679489714])
+
+assert(model.checkPythonDump())