]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
return compsolid, when result is compound of connected solids
authormbs <martin.bernhard@opencascade.com>
Mon, 23 Jan 2023 09:12:17 +0000 (09:12 +0000)
committerGérald NICOLAS <gerald.nicolas@edf.fr>
Wed, 1 Feb 2023 16:32:07 +0000 (17:32 +0100)
src/FeaturesAPI/FeaturesAPI_GlueFaces.cpp
src/FeaturesPlugin/FeaturesPlugin_GlueFaces.cpp
src/FeaturesPlugin/Test/TestGlueFaces_Compound.py
src/FeaturesPlugin/Test/TestGlueFaces_Faces.py
src/FeaturesPlugin/Test/TestGlueFaces_Solids.py
src/PythonAPI/model/tests/tests.py

index 97b7a399d41c9e40ffc5117658935b6c2ca13f79..f3531439986dcec7daadb70c1162f2647a0c1ec8 100644 (file)
@@ -34,7 +34,7 @@ FeaturesAPI_GlueFaces::FeaturesAPI_GlueFaces(const std::shared_ptr<ModelAPI_Feat
 FeaturesAPI_GlueFaces::FeaturesAPI_GlueFaces(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                              const std::list<ModelHighAPI_Selection>& theMainObjects,
                                              const ModelHighAPI_Double& theTolerance,
-                                             bool theIsKeepNonSolids=true)
+                                             bool theIsKeepNonSolids)
 : ModelHighAPI_Interface(theFeature)
 {
   if (initialize()) {
index b9e0ad20afaa6159d9306b9c979e6e854de56bdd..fe2fee8890539a2a77599ffe287d430a2eb1ca09 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_GlueFaces.h>
+#include <GeomAlgoAPI_ShapeTools.h>
 #include <GeomAlgoAPI_Tools.h>
 
 #include <sstream>
@@ -85,6 +86,20 @@ void FeaturesPlugin_GlueFaces::execute()
     return;
   }
 
+  if (aResult->isCompound()) {
+    aResult = GeomAlgoAPI_ShapeTools::groupSharedTopology(aResult);
+
+    // If the subshape of the compound is already a Compound or CompSolid,
+    // use that compound subshape as the result.
+    if (aResult->typeOfCompoundShapes() == GeomAPI_Shape::COMPSOLID) {
+      ListOfShape aResults;
+      aResult = GeomAlgoAPI_ShapeTools::combineShapes(aResult, GeomAPI_Shape::COMPSOLID, aResults);
+    }
+    else if (aResult->typeOfCompoundShapes() == GeomAPI_Shape::COMPOUND) {
+      aResult = aResult->subShapes(GeomAPI_Shape::COMPOUND).front();
+    }
+  }
+
   int anIndex = 0;
   ResultBodyPtr aResultBody = document()->createBody(data(), anIndex);
   aResultBody->storeModified(aShapes, aResult, aGluingAlgo);
index c1af6bb200882379b7478ef95c3e0198d52d9b28..8e270036b10cd05ab20911472fd66829d8050b75 100644 (file)
@@ -43,7 +43,7 @@ GlueFaces_1 = model.addGlueFaces(Part_1_doc, [model.selection("COMPOUND", "Compo
 model.end()
 
 # gluing successful
-model.testCompound(GlueFaces_1, [2], [2], [11], [20], [12])
+model.testCompSolid(GlueFaces_1, [2], [2], [11], [20], [12])
 
 # =============================================================================
 # Test 2. Glue faces for 2 solids with 1 common edge only
@@ -86,7 +86,7 @@ GlueFaces_4 = model.addGlueFaces(Part_1_doc, [model.selection("COMPOUND", "Compo
 model.end()
 
 # gluing successful
-model.testCompound(GlueFaces_4, [2], [2], [11], [20], [12])
+model.testCompSolid(GlueFaces_4, [2], [2], [11], [20], [12])
 
 # =============================================================================
 # Test 5. Check Python dump
index 49305e624d3760b72bf2ff54dbc9da2a97ed4660..a0bb3e7d1b5e55455c1366f26d3fa579c2a4a971 100644 (file)
@@ -48,7 +48,7 @@ GlueFaces_1 = model.addGlueFaces(Part_1_doc, [model.selection("SOLID", "Translat
 model.do()
 
 # gluing successful
-model.testCompound(GlueFaces_1, [2], [2], [11], [20], [12])
+model.testCompSolid(GlueFaces_1, [2], [2], [11], [20], [12])
 
 # =============================================================================
 # Test 2. Glue faces for 2 faces with 1 common edge only
index 97eb0b95b61c5854810cda2b3a39674b4aed027d..6236d2d53ad73fcaba4fd25e7f892b9e073d5a61 100644 (file)
@@ -41,7 +41,7 @@ GlueFaces_1 = model.addGlueFaces(Part_1_doc, [model.selection("SOLID", "Box_1_1"
 model.end()
 
 # gluing successful
-model.testCompound(GlueFaces_1, [2], [2], [11], [20], [12])
+model.testCompSolid(GlueFaces_1, [2], [2], [11], [20], [12])
 
 # =============================================================================
 # Test 2. Glue faces for 2 solids with 1 common edge only
@@ -84,7 +84,7 @@ GlueFaces_4 = model.addGlueFaces(Part_1_doc, [model.selection("SOLID", "Box_1_1"
 model.end()
 
 # gluing successful
-model.testCompound(GlueFaces_4, [2], [2], [11], [20], [12])
+model.testCompSolid(GlueFaces_4, [2], [2], [11], [20], [12])
 
 # =============================================================================
 # Test 5. Check Python dump
index 924ad3405ba97f1f0d1b44b5b23b9ae3cf582c10..23e6844610cc01fe590c56fa1e2d5e371dad0891 100644 (file)
@@ -154,6 +154,20 @@ def testCompound(theFeature, NbSubRes, NbSolid, NbFace, NbEdge, NbVertex):
   testNbUniqueSubShapes(theFeature, GeomAPI_Shape.VERTEX, NbVertex)
 
 
+def testCompSolid(theFeature, NbSubRes, NbSolid, NbFace, NbEdge, NbVertex):
+  """ Tests number of unique sub-shapes in compsolid result
+  """
+  aResults = theFeature.feature().results()
+  aNbResults = len(aResults)
+  assert (aNbResults == 1), "Number of results: {} not equal to 1.".format(aNbResults)
+  assert aResults[0].shape().isCompSolid(), "Result shape type: {}. Expected: COMPSOLID.".format(aResults[0].shape().shapeTypeStr())
+  testNbSubResults(theFeature, NbSubRes)
+  testNbUniqueSubShapes(theFeature, GeomAPI_Shape.SOLID, NbSolid)
+  testNbUniqueSubShapes(theFeature, GeomAPI_Shape.FACE, NbFace)
+  testNbUniqueSubShapes(theFeature, GeomAPI_Shape.EDGE, NbEdge)
+  testNbUniqueSubShapes(theFeature, GeomAPI_Shape.VERTEX, NbVertex)
+
+
 def testResults(theFeature, NbRes, NbSubRes, NbShell, NbFace, NbEdge, NbVertex):
   """ Tests numbers of unique sub-shapes in the results
   """