From: azv Date: Mon, 1 Oct 2018 07:02:04 +0000 (+0300) Subject: Compose a compsolid as a result of RemoveSubShapes feature. X-Git-Tag: CEA_2018-2~41 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9442bdbd29ae22f8881cc578478db6ae4ee11612;p=modules%2Fshaper.git Compose a compsolid as a result of RemoveSubShapes feature. --- diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index fdad01eaa..d1e619820 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -191,6 +191,7 @@ ADD_UNIT_TESTS(TestExtrusion.py TestRemoveSubShapes.py TestRemoveSubShapes2.py TestRemoveSubShapes3.py + TestRemoveSubShapes4.py TestPipe.py TestRecover.py TestRecover1798.py diff --git a/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp b/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp index b7fe7b8e8..e4d61f163 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp @@ -269,6 +269,18 @@ void FeaturesPlugin_RemoveSubShapes::execute() aResultShape = aCopy->shape(); aMakeShapeList.appendAlgo(aCopy); + if (aResultShape->shapeType() == GeomAPI_Shape::COMPOUND) { + aResultShape = GeomAlgoAPI_ShapeTools::groupSharedTopology(aResultShape); + if (aResultShape->shapeType() == GeomAPI_Shape::COMPOUND) { + // if the result has only one sub-shape, discard the compound + GeomAPI_ShapeIterator aSubIt(aResultShape); + GeomShapePtr aSub = aSubIt.current(); + aSubIt.next(); + if (!aSubIt.more()) + aResultShape = aSub; + } + } + // Store result. ResultBodyPtr aResultBody = document()->createBody(data()); aResultBody->storeModified(aBaseShape, aResultShape, 1); @@ -276,10 +288,10 @@ void FeaturesPlugin_RemoveSubShapes::execute() for(; aTypeIter != aTypes.end(); aTypeIter++) aResultBody->loadDeletedShapes(&aMakeShapeList, aBaseShape, *aTypeIter, 1); aResultBody->loadAndOrientModifiedShapes(&aMakeShapeList, aBaseShape, GeomAPI_Shape::FACE, - 2, "Modified_Face", *aMakeShapeList.mapOfSubShapes().get(), true, false, true); + 2, "Modified_Face", *aMakeShapeList.mapOfSubShapes().get(), true, false, true); aResultBody->loadAndOrientModifiedShapes(&aMakeShapeList, aBaseShape, GeomAPI_Shape::EDGE, - 3, "Modified_Edge", *aMakeShapeList.mapOfSubShapes().get(), false, false, true); + 3, "Modified_Edge", *aMakeShapeList.mapOfSubShapes().get(), false, false, true); aResultBody->loadAndOrientModifiedShapes(&aMakeShapeList, aBaseShape, GeomAPI_Shape::VERTEX, - 4, "Modified_Vertex", *aMakeShapeList.mapOfSubShapes().get()); + 4, "Modified_Vertex", *aMakeShapeList.mapOfSubShapes().get()); setResult(aResultBody); } diff --git a/src/FeaturesPlugin/Test/TestRemoveSubShapes4.py b/src/FeaturesPlugin/Test/TestRemoveSubShapes4.py new file mode 100644 index 000000000..e594d3371 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRemoveSubShapes4.py @@ -0,0 +1,76 @@ +## Copyright (C) 2018-20xx 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 * + +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) +Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Bottom"), model.selection("FACE", "Box_1_1/Top")) +Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Plane_1")) +SketchLine_1 = Sketch_1.addLine(20, 0, 0, 0) +SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False) +SketchPoint_1 = SketchProjection_1.createdFeature() +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchPoint_1.result()) +SketchLine_2 = Sketch_1.addLine(0, 0, 0, -20) +SketchLine_3 = Sketch_1.addLine(0, -20, 20, -20) +SketchLine_4 = Sketch_1.addLine(20, -20, 20, 0) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result()) +SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_1.result(), SketchLine_4.result()) +SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 20) +model.do() +Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1f-SketchLine_2f-SketchLine_3f-SketchLine_4f")]) +LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("FACE", "Face_1_1")], model.selection("EDGE", "PartSet/OZ"), 2, 2) +Partition_1_objects = [model.selection("SOLID", "Box_1_1"), model.selection("FACE", "LinearCopy_1_1_1"), model.selection("FACE", "LinearCopy_1_1_2")] +Partition_1 = model.addPartition(Part_1_doc, Partition_1_objects) +Remove_SubShapes_1 = model.addRemoveSubShapes(Part_1_doc, model.selection("COMPOUND", "Partition_1_1")) +Remove_SubShapes_1.setSubShapesToRemove([model.selection("FACE", "Partition_1_1_2"), model.selection("FACE", "Partition_1_1_3")]) +Recover_1 = model.addRecover(Part_1_doc, Remove_SubShapes_1, [Partition_1.result()]) +model.do() + +# check number of sub-shapes +model.testNbResults(Remove_SubShapes_1, 1) +model.testNbSubResults(Remove_SubShapes_1, [3]) +model.testNbSubShapes(Remove_SubShapes_1, GeomAPI_Shape.COMPOUND, [0]) +model.testNbSubShapes(Remove_SubShapes_1, GeomAPI_Shape.COMPSOLID, [1]) +model.testNbSubShapes(Remove_SubShapes_1, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Remove_SubShapes_1, GeomAPI_Shape.FACE, [18]) + +model.testNbResults(Recover_1, 1) +model.testNbSubResults(Recover_1, [3]) +model.testNbSubShapes(Recover_1, GeomAPI_Shape.COMPOUND, [1]) +model.testNbSubShapes(Recover_1, GeomAPI_Shape.COMPSOLID, [1]) +model.testNbSubShapes(Recover_1, GeomAPI_Shape.SOLID, [3]) +model.testNbSubShapes(Recover_1, GeomAPI_Shape.FACE, [20]) + +model.end() + +assert(model.checkPythonDump())