From 47ea863088e45ff68216e92da7d1caee8a8440a7 Mon Sep 17 00:00:00 2001 From: mbs Date: Wed, 14 Dec 2022 22:36:18 +0000 Subject: [PATCH] fixed non conformance with same feature behavior in GEOM updated the tests --- .../FeaturesPlugin_GlueFaces.cpp | 17 ++- .../Test/TestGlueFaces_Compound.py | 2 +- .../Test/TestGlueFaces_Faces.py | 111 ++++++++++++++++++ .../Test/TestGlueFaces_Shell.py | 4 +- .../Test/TestGlueFaces_Solids.py | 4 +- src/FeaturesPlugin/tests.set | 1 + 6 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 src/FeaturesPlugin/Test/TestGlueFaces_Faces.py diff --git a/src/FeaturesPlugin/FeaturesPlugin_GlueFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_GlueFaces.cpp index 37d9cbcd8..b9e0ad20a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_GlueFaces.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_GlueFaces.cpp @@ -35,6 +35,8 @@ #include #include +#include + //================================================================================================== FeaturesPlugin_GlueFaces::FeaturesPlugin_GlueFaces() @@ -87,6 +89,13 @@ void FeaturesPlugin_GlueFaces::execute() ResultBodyPtr aResultBody = document()->createBody(data(), anIndex); aResultBody->storeModified(aShapes, aResult, aGluingAlgo); + // Ensure the result body is named after this feature + std::wstring aBaseName = feature(aResultBody)->data()->name(); + std::wostringstream aNameStr; + aNameStr << aBaseName << "_" << (anIndex+1); + std::wstring aName = aNameStr.str(); + aResultBody->data()->setName(aName); + setResult(aResultBody, anIndex); } @@ -118,7 +127,7 @@ bool FeaturesPlugin_GlueFaces::isGlued(const ListOfShape& theInputs, // Consider the list of input shapes the same as the result, if // * the total number of faces did NOT change. - int nbInputFaces = 0; + int nbInputFaces = 0, nbInputEdges = 0; for (ListOfShape::const_iterator anIt = theInputs.cbegin(); anIt != theInputs.cend(); ++anIt) @@ -127,12 +136,14 @@ bool FeaturesPlugin_GlueFaces::isGlued(const ListOfShape& theInputs, if (aShape.get()) { nbInputFaces += aShape->subShapes(GeomAPI_Shape::FACE, true).size(); + nbInputEdges += aShape->subShapes(GeomAPI_Shape::EDGE, true).size(); } } - int nbResultFaces = 0; + int nbResultFaces = 0, nbResultEdges = 0; nbResultFaces = theResult->subShapes(GeomAPI_Shape::FACE, true).size(); - return(0 < nbResultFaces && nbResultFaces < nbInputFaces); + nbResultEdges = theResult->subShapes(GeomAPI_Shape::EDGE, true).size(); + return(0 < nbResultFaces && ((nbResultFaces < nbInputFaces) || (nbResultFaces == nbInputFaces && nbResultEdges < nbInputEdges))); } //================================================================================================= diff --git a/src/FeaturesPlugin/Test/TestGlueFaces_Compound.py b/src/FeaturesPlugin/Test/TestGlueFaces_Compound.py index 5202fd31d..47aa16fd3 100644 --- a/src/FeaturesPlugin/Test/TestGlueFaces_Compound.py +++ b/src/FeaturesPlugin/Test/TestGlueFaces_Compound.py @@ -92,7 +92,7 @@ GlueFaces_2 = model.addGlueFaces(Part_1_doc, [model.selection("COMPOUND", "Compo model.end() # no faces glued -testCompound(GlueFaces_2, model, [2], [2], [12], [24], [16]) +testCompound(GlueFaces_2, model, [2], [2], [12], [23], [14]) # ============================================================================= # Test 3. Glue faces for 2 solids with 2 adjacent faces above default tolerance diff --git a/src/FeaturesPlugin/Test/TestGlueFaces_Faces.py b/src/FeaturesPlugin/Test/TestGlueFaces_Faces.py new file mode 100644 index 000000000..d4b7131b5 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestGlueFaces_Faces.py @@ -0,0 +1,111 @@ +# Copyright (C) 2014-2022 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 +from GeomAPI import GeomAPI_Shape + +aShapeTypes = { + GeomAPI_Shape.SOLID: "GeomAPI_Shape.SOLID", + GeomAPI_Shape.FACE: "GeomAPI_Shape.FACE", + GeomAPI_Shape.EDGE: "GeomAPI_Shape.EDGE", + GeomAPI_Shape.VERTEX: "GeomAPI_Shape.VERTEX"} + +def testNbUniqueSubShapes(theFeature, theShapeType, theExpectedNbSubShapes): + """ Tests number of unique feature sub-shapes of passed type for each result. + :param theFeature: feature to test. + :param theShapeType: shape type of sub-shapes to test. + :param theExpectedNbSubShapes: list of sub-shapes numbers. Size of list should be equal to len(theFeature.results()). + """ + aResults = theFeature.feature().results() + aNbResults = len(aResults) + aListSize = len(theExpectedNbSubShapes) + assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize) + for anIndex in range(0, aNbResults): + aNbResultSubShapes = 0 + anExpectedNbSubShapes = theExpectedNbSubShapes[anIndex] + aNbResultSubShapes = aResults[anIndex].shape().subShapes(theShapeType, True).size() + assert (aNbResultSubShapes == anExpectedNbSubShapes), "Number of sub-shapes of type {} for result[{}]: {}. Expected: {}.".format(aShapeTypes[theShapeType], anIndex, aNbResultSubShapes, anExpectedNbSubShapes) + +def testCompound(theFeature,theModel,NbSubRes,NbSolid,NbFace,NbEdge,NbVertex): + """ Tests numbers of unique sub-shapes in compound result + """ + aResults = theFeature.feature().results() + aNbResults = len(aResults) + assert (aNbResults == 1), "Number of results: {} not equal to 1.".format(aNbResults) + assert aResults[0].shape().isCompound(), "Result shape type: {}. Expected: COMPOUND.".format(aResults[0].shape().shapeTypeStr()) + theModel.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) + +# Create document +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() + +# ============================================================================= +# Prepare all input shapes +# ============================================================================= +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Box_2 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_2_1")], axis = model.selection("EDGE", "PartSet/OX"), distance = 10, keepSubResults = True) +Copy_1_objects = [model.selection("FACE", "Box_1_1/Top"), + model.selection("FACE", "Translation_1_1/MF:Translated&Box_2_1/Top"), + model.selection("FACE", "Translation_1_1/MF:Translated&Box_2_1/Left")] +Copy_1 = model.addCopy(Part_1_doc, Copy_1_objects, 1) +Copy_1.result().setName("Box_1_1_1") +Copy_1.results()[1].setName("Translation_1_1_1") +Copy_1.results()[2].setName("Translation_1_1_2") +model.do() + +# ============================================================================= +# Test 1. Glue faces of 2 adjacent solids +# ============================================================================= +GlueFaces_1 = model.addGlueFaces(Part_1_doc, [model.selection("SOLID", "Translation_1_1"), model.selection("SOLID", "Box_1_1")], 1e-07, True) +model.do() + +# gluing successful +testCompound(GlueFaces_1, model, [2], [2], [11], [20], [12]) + +# ============================================================================= +# Test 2. Glue faces for 2 faces with 1 common edge only +# ============================================================================= +GlueFaces_2 = model.addGlueFaces(Part_1_doc, [model.selection("FACE", "Box_1_1_1"), model.selection("FACE", "Translation_1_1_1")], 1e-07, True) +GlueFaces_2.result().setName("GlueFaces_2_1") +GlueFaces_2.result().subResult(0).setName("GlueFaces_2_1_1") +GlueFaces_2.result().subResult(1).setName("GlueFaces_2_1_2") +model.do() + +# gluing successful +testCompound(GlueFaces_2, model, [2], [0], [2], [7], [6]) + +# ============================================================================= +# Test 3. Glue faces for 1 solid and 1 faces with 1 common edge +# ============================================================================= +Recover_1 = model.addRecover(Part_1_doc, GlueFaces_1, [Box_1.result()]) +GlueFaces_3 = model.addGlueFaces(Part_1_doc, [model.selection("FACE", "Translation_1_1_2"), model.selection("SOLID", "Recover_1_1")], 1e-07, True) +GlueFaces_3.result().setName("GlueFaces_3_1") +GlueFaces_3.result().subResult(0).setName("GlueFaces_3_1_1") +GlueFaces_3.result().subResult(1).setName("GlueFaces_3_1_2") +model.end() + +# no faces glued +testCompound(GlueFaces_3, model, [2], [1], [7], [15], [10]) diff --git a/src/FeaturesPlugin/Test/TestGlueFaces_Shell.py b/src/FeaturesPlugin/Test/TestGlueFaces_Shell.py index 95f89ab22..d9688acbd 100644 --- a/src/FeaturesPlugin/Test/TestGlueFaces_Shell.py +++ b/src/FeaturesPlugin/Test/TestGlueFaces_Shell.py @@ -93,8 +93,8 @@ model.do() GlueFaces_2 = model.addGlueFaces(Part_1_doc, [model.selection("SHELL", "Shell_1_1"), model.selection("SHELL", "Shell_2_1")], 1.0e-7, True) model.end() -# no faces glued -testCompound(GlueFaces_2, model, [2], [0], [4], [14], [12]) +# gluing successful +testCompound(GlueFaces_2, model, [2], [0], [4], [13], [10]) # ============================================================================= # Test 3. Glue faces for 2 shells with 2 adjacent faces above default tolerance diff --git a/src/FeaturesPlugin/Test/TestGlueFaces_Solids.py b/src/FeaturesPlugin/Test/TestGlueFaces_Solids.py index 7a6284bcb..424c0270d 100644 --- a/src/FeaturesPlugin/Test/TestGlueFaces_Solids.py +++ b/src/FeaturesPlugin/Test/TestGlueFaces_Solids.py @@ -89,8 +89,8 @@ model.do() GlueFaces_2 = model.addGlueFaces(Part_1_doc, [model.selection("SOLID", "Box_1_1"), model.selection("SOLID", "Rotation_1_1")], 1.0e-7, True) model.end() -# no faces glued -testCompound(GlueFaces_2, model, [2], [2], [12], [24], [16]) +# gluing successful +testCompound(GlueFaces_2, model, [2], [2], [12], [23], [14]) # ============================================================================= # Test 3. Glue faces for 2 solids with 2 adjacent faces above default tolerance diff --git a/src/FeaturesPlugin/tests.set b/src/FeaturesPlugin/tests.set index b07dec3a0..0fc0f16d5 100644 --- a/src/FeaturesPlugin/tests.set +++ b/src/FeaturesPlugin/tests.set @@ -533,6 +533,7 @@ SET(TEST_NAMES_PARA TestSewing_NonManifold.py TestSewing_Groups.py TestGlueFaces_Compound.py + TestGlueFaces_Faces.py TestGlueFaces_Shell.py TestGlueFaces_Solids.py ) -- 2.39.2