From: azv Date: Mon, 1 Oct 2018 10:33:37 +0000 (+0300) Subject: Fix issue related to selection of compsolid in the RemoveSubShapes feature X-Git-Tag: CEA_2018-2~39 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0f48244314c2a9563ae4401235d910879b709fd3;p=modules%2Fshaper.git Fix issue related to selection of compsolid in the RemoveSubShapes feature --- diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index d1e619820..e2ede78a6 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -192,6 +192,8 @@ ADD_UNIT_TESTS(TestExtrusion.py TestRemoveSubShapes2.py TestRemoveSubShapes3.py TestRemoveSubShapes4.py + TestRemoveSubShapes5.py + TestRemoveSubShapes6.py TestPipe.py TestRecover.py TestRecover1798.py diff --git a/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp b/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp index e4d61f163..75b335b61 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_RemoveSubShapes.cpp @@ -133,7 +133,8 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID) for(anIndex = 0; anIndex < aSubsToKeepNb; ++anIndex) { AttributeSelectionPtr anAttrSelectionInList = aSubShapesToKeepAttrList->value(anIndex); GeomShapePtr aSubShapeToKeep = anAttrSelectionInList->value(); - if (aSubShapeToKeep.get() && aSubShapeToKeep->isEqual(aSubShape)) { + if (aSubShapeToKeep.get() && + (aSubShapeToKeep->isEqual(aSubShape) || aSubShapeToKeep->isSubShape(aSubShape))) { break; } } @@ -173,7 +174,8 @@ void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID) for(anIndex = 0; anIndex < aSubsToRemoveNb; ++anIndex) { AttributeSelectionPtr anAttrSelectionInList = aSubShapesToRemoveAttrList->value(anIndex); GeomShapePtr aSubShapeToRemove = anAttrSelectionInList->value(); - if (aSubShapeToRemove.get() && aSubShapeToRemove->isEqual(aSubShape)) { + if (aSubShapeToRemove.get() && + (aSubShapeToRemove->isEqual(aSubShape) || aSubShapeToRemove->isSubShape(aSubShape))) { break; } } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 8d785e658..1b8c4d13e 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -906,7 +906,10 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePt return false; } - std::list aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape); + ListOfShape aSubShapes = GeomAlgoAPI_ShapeTools::getLowLevelSubShapes(aBaseShape); + // add to the list all sub-shapes of the compound due to they can be selected as a shapes to keep + for (GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) + aSubShapes.push_back(anIt.current()); for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) { bool isSameFound = false; AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex); diff --git a/src/FeaturesPlugin/Test/TestRemoveSubShapes5.py b/src/FeaturesPlugin/Test/TestRemoveSubShapes5.py new file mode 100644 index 000000000..310a650ff --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRemoveSubShapes5.py @@ -0,0 +1,68 @@ +## 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("COMPSOLID", "Partition_1_1_1/Partition_1_1_1")]) +model.do() + +# check number of sub-shapes +model.testNbResults(Remove_SubShapes_1, 1) +model.testNbSubResults(Remove_SubShapes_1, [2]) +model.testNbSubShapes(Remove_SubShapes_1, GeomAPI_Shape.COMPOUND, [1]) +model.testNbSubShapes(Remove_SubShapes_1, GeomAPI_Shape.COMPSOLID, [0]) +model.testNbSubShapes(Remove_SubShapes_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Remove_SubShapes_1, GeomAPI_Shape.FACE, [2]) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/TestRemoveSubShapes6.py b/src/FeaturesPlugin/Test/TestRemoveSubShapes6.py new file mode 100644 index 000000000..61955a4bd --- /dev/null +++ b/src/FeaturesPlugin/Test/TestRemoveSubShapes6.py @@ -0,0 +1,68 @@ +## 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.setSubShapesToKeep([model.selection("COMPSOLID", "Partition_1_1_1")]) +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.end() + +assert(model.checkPythonDump()) diff --git a/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp b/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp index 73266b8cf..887c64476 100644 --- a/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp +++ b/src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp @@ -161,7 +161,8 @@ namespace ModelGeomAlgo_Shape // process subs of compsolid ResultBodyPtr aSubCompSolid = std::dynamic_pointer_cast(aSubResult); - if (aSubCompSolid && aSubCompSolid->numberOfSubs() > 0) { + if (theShapeType != GeomAPI_Shape::COMPSOLID && + aSubCompSolid && aSubCompSolid->numberOfSubs() > 0) { isSubshapeFound = findSubshapeInCompsolid(aSubCompSolid, thePoint, theShapeType, theTolerance, theSelected); }