From 08687859554775951d8d087978299de4bba04a88 Mon Sep 17 00:00:00 2001 From: mbs Date: Mon, 23 Jan 2023 09:12:17 +0000 Subject: [PATCH] return compsolid, when result is compound of connected solids --- src/FeaturesAPI/FeaturesAPI_GlueFaces.cpp | 2 +- src/FeaturesPlugin/FeaturesPlugin_GlueFaces.cpp | 15 +++++++++++++++ src/FeaturesPlugin/Test/TestGlueFaces_Compound.py | 4 ++-- src/FeaturesPlugin/Test/TestGlueFaces_Faces.py | 2 +- src/FeaturesPlugin/Test/TestGlueFaces_Solids.py | 4 ++-- src/PythonAPI/model/tests/tests.py | 14 ++++++++++++++ 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/FeaturesAPI/FeaturesAPI_GlueFaces.cpp b/src/FeaturesAPI/FeaturesAPI_GlueFaces.cpp index 97b7a399d..f35314399 100644 --- a/src/FeaturesAPI/FeaturesAPI_GlueFaces.cpp +++ b/src/FeaturesAPI/FeaturesAPI_GlueFaces.cpp @@ -34,7 +34,7 @@ FeaturesAPI_GlueFaces::FeaturesAPI_GlueFaces(const std::shared_ptr& theFeature, const std::list& theMainObjects, const ModelHighAPI_Double& theTolerance, - bool theIsKeepNonSolids=true) + bool theIsKeepNonSolids) : ModelHighAPI_Interface(theFeature) { if (initialize()) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_GlueFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_GlueFaces.cpp index b9e0ad20a..fe2fee889 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_GlueFaces.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_GlueFaces.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -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); diff --git a/src/FeaturesPlugin/Test/TestGlueFaces_Compound.py b/src/FeaturesPlugin/Test/TestGlueFaces_Compound.py index c1af6bb20..8e270036b 100644 --- a/src/FeaturesPlugin/Test/TestGlueFaces_Compound.py +++ b/src/FeaturesPlugin/Test/TestGlueFaces_Compound.py @@ -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 diff --git a/src/FeaturesPlugin/Test/TestGlueFaces_Faces.py b/src/FeaturesPlugin/Test/TestGlueFaces_Faces.py index 49305e624..a0bb3e7d1 100644 --- a/src/FeaturesPlugin/Test/TestGlueFaces_Faces.py +++ b/src/FeaturesPlugin/Test/TestGlueFaces_Faces.py @@ -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 diff --git a/src/FeaturesPlugin/Test/TestGlueFaces_Solids.py b/src/FeaturesPlugin/Test/TestGlueFaces_Solids.py index 97eb0b95b..6236d2d53 100644 --- a/src/FeaturesPlugin/Test/TestGlueFaces_Solids.py +++ b/src/FeaturesPlugin/Test/TestGlueFaces_Solids.py @@ -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 diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index 924ad3405..23e684461 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -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 """ -- 2.39.2