From: azv Date: Fri, 22 Nov 2019 12:35:45 +0000 (+0300) Subject: Task 3.4 Build/Face and Build/Shell on a whole Sketch (issue #3078). X-Git-Tag: V9_5_0a1~167^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d3513754be0a59693b5f0e84ee8b866436887500;p=modules%2Fshaper.git Task 3.4 Build/Face and Build/Shell on a whole Sketch (issue #3078). --- diff --git a/src/BuildPlugin/BuildPlugin_Face.cpp b/src/BuildPlugin/BuildPlugin_Face.cpp index 022865abd..ac88ffe6a 100644 --- a/src/BuildPlugin/BuildPlugin_Face.cpp +++ b/src/BuildPlugin/BuildPlugin_Face.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -71,11 +72,21 @@ void BuildPlugin_Face::execute() if(!aShape.get()) { aShape = aContext; } - // keep selected faces "as is" if (aShape->shapeType() == GeomAPI_Shape::FACE) { + // keep selected faces "as is" anOriginalFaces.push_back(aShape); continue; } + else if (!aSelection->value() && aShape->shapeType() == GeomAPI_Shape::COMPOUND) { + // collect faces from the sketch + ResultConstructionPtr aSketch = + std::dynamic_pointer_cast(aSelection->context()); + if (aSketch && aSketch->facesNum() > 0) { + for (int i = 0; i < aSketch->facesNum(); ++i) + anOriginalFaces.push_back(aSketch->face(i)); + continue; + } + } for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { GeomShapePtr anEdge = anExp.current(); diff --git a/src/BuildPlugin/BuildPlugin_Shell.cpp b/src/BuildPlugin/BuildPlugin_Shell.cpp index 7f1010307..293a63818 100644 --- a/src/BuildPlugin/BuildPlugin_Shell.cpp +++ b/src/BuildPlugin/BuildPlugin_Shell.cpp @@ -48,6 +48,18 @@ void BuildPlugin_Shell::execute() ListOfShape aShapes, aContexts; getOriginalShapesAndContexts(BASE_OBJECTS_ID(), aShapes, aContexts); + // Collect sketch faces. + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + ResultConstructionPtr aContext = + std::dynamic_pointer_cast(aSelection->context()); + if (!aShape && aContext) { + for (int i = 0; i < aContext->facesNum(); ++i) + aShapes.push_back(aContext->face(i)); + } + } + // Sew faces. GeomMakeShapePtr aSewingAlgo(new GeomAlgoAPI_Sewing(aShapes)); diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp index 99ba50ccb..761fc6fa5 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -104,17 +104,6 @@ bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute theError = "Infinite objects not acceptable."; return false; } - - std::shared_ptr anEdges = - std::dynamic_pointer_cast(aContextShape); - if(anEdges.get()) { - if(aShape->isEqual(aContextShape)) { - // It is whole sketch. - return false; - } - - continue; - } } } @@ -198,7 +187,11 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptrcontext()->shape(); } - if (aShape->shapeType() == GeomAPI_Shape::FACE) { + ResultConstructionPtr aSketchRes = + std::dynamic_pointer_cast(aSelection->context()); + + if (aShape->shapeType() == GeomAPI_Shape::FACE || + (!aSelection->value() && aSketchRes && aSketchRes->facesNum() > 0)) { // skip faces exploding hasFaces = true; continue; diff --git a/src/BuildPlugin/CMakeLists.txt b/src/BuildPlugin/CMakeLists.txt index 121f992cf..e8a4e470f 100644 --- a/src/BuildPlugin/CMakeLists.txt +++ b/src/BuildPlugin/CMakeLists.txt @@ -121,7 +121,11 @@ ADD_UNIT_TESTS(TestVertex.py TestInterpolation.py TestFace.py TestFace_ErrorMsg.py + TestFace_WholeSketch_1.py + TestFace_WholeSketch_2.py TestShell.py + TestShell_WholeSketch_1.py + TestShell_WholeSketch_2.py TestSolid.py TestSolid_ErrorMsg.py TestCompSolid.py diff --git a/src/BuildPlugin/Test/TestFace_WholeSketch_1.py b/src/BuildPlugin/Test/TestFace_WholeSketch_1.py new file mode 100644 index 000000000..713ccb287 --- /dev/null +++ b/src/BuildPlugin/Test/TestFace_WholeSketch_1.py @@ -0,0 +1,49 @@ +# Copyright (C) 2019 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() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(0, -20, 45, -15) +SketchLine_2 = Sketch_1.addLine(45, -15, 10, 15) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(10, 15, 25, -40) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +model.do() +Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchCircle_1 = Sketch_2.addCircle(-5, 10, 20) +SketchLine_4 = Sketch_2.addLine(-25, 10, 15, 10) +SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_4.startPoint(), SketchCircle_1.results()[1]) +SketchConstraintCoincidence_4 = Sketch_2.setCoincident(SketchLine_4.endPoint(), SketchCircle_1.results()[1]) +model.do() +Face_1 = model.addFace(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")]) +model.end() + +model.testNbResults(Face_1, 1) +model.testNbSubShapes(Face_1, GeomAPI_Shape.FACE, [1]) +model.testNbSubShapes(Face_1, GeomAPI_Shape.EDGE, [3]) +model.testNbSubShapes(Face_1, GeomAPI_Shape.VERTEX, [6]) +model.testResultsVolumes(Face_1, [441.0539215686274]) + +assert(model.checkPythonDump()) diff --git a/src/BuildPlugin/Test/TestFace_WholeSketch_2.py b/src/BuildPlugin/Test/TestFace_WholeSketch_2.py new file mode 100644 index 000000000..c3a25de6b --- /dev/null +++ b/src/BuildPlugin/Test/TestFace_WholeSketch_2.py @@ -0,0 +1,49 @@ +# Copyright (C) 2019 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() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(0, -20, 45, -15) +SketchLine_2 = Sketch_1.addLine(45, -15, 10, 15) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(10, 15, 25, -40) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +model.do() +Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchCircle_1 = Sketch_2.addCircle(-5, 10, 20) +SketchLine_4 = Sketch_2.addLine(-25, 10, 15, 10) +SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_4.startPoint(), SketchCircle_1.results()[1]) +SketchConstraintCoincidence_4 = Sketch_2.setCoincident(SketchLine_4.endPoint(), SketchCircle_1.results()[1]) +model.do() +Face_1 = model.addFace(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_1"), model.selection("COMPOUND", "Sketch_2")]) +model.end() + +model.testNbResults(Face_1, 3) +model.testNbSubShapes(Face_1, GeomAPI_Shape.FACE, [1, 1, 1]) +model.testNbSubShapes(Face_1, GeomAPI_Shape.EDGE, [3, 2, 2]) +model.testNbSubShapes(Face_1, GeomAPI_Shape.VERTEX, [6, 4, 4]) +model.testResultsVolumes(Face_1, [441.0539215686274, 628.318530717958, 628.318530717958]) + +assert(model.checkPythonDump()) diff --git a/src/BuildPlugin/Test/TestShell_WholeSketch_1.py b/src/BuildPlugin/Test/TestShell_WholeSketch_1.py new file mode 100644 index 000000000..0b11501da --- /dev/null +++ b/src/BuildPlugin/Test/TestShell_WholeSketch_1.py @@ -0,0 +1,49 @@ +# Copyright (C) 2019 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() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(0, -20, 45, -15) +SketchLine_2 = Sketch_1.addLine(45, -15, 10, 15) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(10, 15, 25, -40) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +model.do() +Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchCircle_1 = Sketch_2.addCircle(-5, 10, 20) +SketchLine_4 = Sketch_2.addLine(-25, 10, 15, 10) +SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_4.startPoint(), SketchCircle_1.results()[1]) +SketchConstraintCoincidence_4 = Sketch_2.setCoincident(SketchLine_4.endPoint(), SketchCircle_1.results()[1]) +model.do() +Shell_1 = model.addShell(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")]) +model.end() + +model.testNbResults(Shell_1, 1) +model.testNbSubShapes(Shell_1, GeomAPI_Shape.FACE, [1]) +model.testNbSubShapes(Shell_1, GeomAPI_Shape.EDGE, [3]) +model.testNbSubShapes(Shell_1, GeomAPI_Shape.VERTEX, [6]) +model.testResultsVolumes(Shell_1, [441.0539215686274]) + +assert(model.checkPythonDump()) diff --git a/src/BuildPlugin/Test/TestShell_WholeSketch_2.py b/src/BuildPlugin/Test/TestShell_WholeSketch_2.py new file mode 100644 index 000000000..55a7ad286 --- /dev/null +++ b/src/BuildPlugin/Test/TestShell_WholeSketch_2.py @@ -0,0 +1,49 @@ +# Copyright (C) 2019 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() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(0, -20, 45, -15) +SketchLine_2 = Sketch_1.addLine(45, -15, 10, 15) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(10, 15, 25, -40) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +model.do() +Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchCircle_1 = Sketch_2.addCircle(-5, 10, 20) +SketchLine_4 = Sketch_2.addLine(-25, 10, 15, 10) +SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_4.startPoint(), SketchCircle_1.results()[1]) +SketchConstraintCoincidence_4 = Sketch_2.setCoincident(SketchLine_4.endPoint(), SketchCircle_1.results()[1]) +model.do() +Shell_1 = model.addShell(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_1"), model.selection("COMPOUND", "Sketch_2")]) +model.end() + +model.testNbResults(Shell_1, 2) +model.testNbSubShapes(Shell_1, GeomAPI_Shape.FACE, [1, 2]) +model.testNbSubShapes(Shell_1, GeomAPI_Shape.EDGE, [3, 4]) +model.testNbSubShapes(Shell_1, GeomAPI_Shape.VERTEX, [6, 8]) +model.testResultsVolumes(Shell_1, [441.0539215686274, 1256.637061435917]) + +assert(model.checkPythonDump()) diff --git a/src/BuildPlugin/face_widget.xml b/src/BuildPlugin/face_widget.xml index e61ce59d1..78235132d 100644 --- a/src/BuildPlugin/face_widget.xml +++ b/src/BuildPlugin/face_widget.xml @@ -4,7 +4,7 @@ tooltip="Select edges, wires or faces." shape_types="edges wires faces" concealment="true"> - + diff --git a/src/BuildPlugin/shell_widget.xml b/src/BuildPlugin/shell_widget.xml index 50575ff1e..cb44a7c30 100644 --- a/src/BuildPlugin/shell_widget.xml +++ b/src/BuildPlugin/shell_widget.xml @@ -4,6 +4,6 @@ tooltip="Select faces or shells objects." shape_types="faces shells" concealment="true"> - +