From: mpv Date: Tue, 13 Nov 2018 13:25:12 +0000 (+0300) Subject: Fixes and unit-tests basing on the manual tests X-Git-Tag: End2018~178 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6a9eb86984ff6892c0dd95700ee6f37e5235c10e;p=modules%2Fshaper.git Fixes and unit-tests basing on the manual tests --- diff --git a/doc/gui/tutorial.py b/doc/gui/tutorial.py index 64e0c404e..0af565892 100644 --- a/doc/gui/tutorial.py +++ b/doc/gui/tutorial.py @@ -64,9 +64,9 @@ Face_1 = model.addFace(Part_1_doc, [model.selection("WIRE", "Polyline_1_1")]) Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Face_1_1")], model.selection("EDGE", "PartSet/OZ"), 360, 0) # Step5. Extrusion. -Wire = model.selection("WIRE", "Sketch_1/Wire-SketchLine_1r-SketchLine_5r-SketchLine_6r-SketchLine_7r-SketchLine_8r-SketchLine_9r") -To = model.selection("FACE", "Revolution_1_1/Generated_Face_6") -From = model.selection("FACE", "Revolution_1_1/Generated_Face_1") +Wire = model.selection("WIRE", "Sketch_1/Face-SketchLine_5r-SketchLine_6r-SketchLine_7r-SketchLine_8r-SketchLine_9r-SketchLine_1r_wire") +To = model.selection("FACE", "Revolution_1_1/Generated_Face&Face_1_1/Edge_2") +From = model.selection("FACE", "Revolution_1_1/Generated_Face&Face_1_1/Edge_7") Extrusion_1 = model.addExtrusion(Part_1_doc, [Wire], model.selection("EDGE", "PartSet/OZ"), To, 0, From, 0) @@ -74,7 +74,7 @@ Extrusion_1 = model.addExtrusion(Part_1_doc, [Wire], model.selection("EDGE", "Pa Common_1 = model.addCommon(Part_1_doc, [model.selection("SOLID", "Revolution_1_1"), model.selection("SOLID", "Extrusion_1_1")]) # Step7. Fillet. -Fillet_1 = model.addFillet(Part_1_doc, [model.selection("EDGE", "Revolution_1_1/Generated_Face_5&Common_1_1/Modified_Face_11")], 10) +Fillet_1 = model.addFillet(Part_1_doc, [model.selection("EDGE", "[Revolution_1_1/Generated_Face&Face_1_1/Edge_3][Common_1_1/Modified_Face&Face_1_1/Edge_4]")], 10) # Step8. Box. Box_1 = model.addBox(Part_1_doc, 20, 120, 20) diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index da074e70d..1744fde64 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -226,4 +226,6 @@ ADD_UNIT_TESTS(TestConstants.py Test2685.py TestGeomNamingPlacement.py TestGeomNamingRevolution.py + TestGeomNamingEdgeByFilter.py + TestGeomNamingSketchPlane.py ) diff --git a/src/ModelAPI/Test/TestGeomNamingEdgeByFilter.py b/src/ModelAPI/Test/TestGeomNamingEdgeByFilter.py new file mode 100644 index 000000000..c4a12d89f --- /dev/null +++ b/src/ModelAPI/Test/TestGeomNamingEdgeByFilter.py @@ -0,0 +1,50 @@ +## Copyright (C) 2014-2017 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 +## + +# -*- coding: utf-8 -*- + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 15, 15, 15) +Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Bottom"), 5, True) +Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Bottom"), 10, True) +Plane_6 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Back"), 5, True) +Plane_7 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Back"), 10, True) +Plane_8 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Left"), 5, True) +Plane_9 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Left"), 10, True) +Partition_1_objects = [model.selection("SOLID", "Box_1_1"), model.selection("FACE", "Plane_1"), model.selection("FACE", "Plane_2"), model.selection("FACE", "Plane_5"), model.selection("FACE", "Plane_6"), model.selection("FACE", "Plane_3"), model.selection("FACE", "Plane_4")] +Partition_1 = model.addPartition(Part_1_doc, Partition_1_objects) +Box_2 = model.addBox(Part_1_doc, 2, 2, 10) +Placement_1 = model.addPlacement(Part_1_doc, [model.selection("SOLID", "Box_2_1")], model.selection("FACE", "Box_2_1/Bottom"), model.selection("FACE", "_weak_name_4_Partition_1_1_14"), False, True) +model.do() +# update the selection of the placement +Placement_1.setEndShape(model.selection("EDGE", "[_weak_name_4_Partition_1_1_5][(Partition_1_1_5/Modified_Face&Box_1_1/Back)2]")) +model.end() + +# check that placement is valid +from ModelAPI import * +aFactory = ModelAPI_Session.get().validators() +assert(aFactory.validate(Placement_1.feature())) + +assert(model.checkPythonDump(model.ModelHighAPI.CHECK_NAMING)) diff --git a/src/ModelAPI/Test/TestGeomNamingSketchPlane.py b/src/ModelAPI/Test/TestGeomNamingSketchPlane.py new file mode 100644 index 000000000..57cb642a6 --- /dev/null +++ b/src/ModelAPI/Test/TestGeomNamingSketchPlane.py @@ -0,0 +1,107 @@ +## Copyright (C) 2014-2017 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 +## + +# -*- coding: utf-8 -*- + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +lenParam = model.addParameter(Part_1_doc, "len", "500") +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(-302.4220649391276, 58.25973730731688, -52.42206493912754, 58.25973730731688) +SketchLine_2 = Sketch_1.addLine(-52.42206493912754, 58.25973730731688, -52.42206493912754, -61.38418346467283) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(-52.42206493912754, -61.38418346467283, 147.5779350608725, -61.38418346467283) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchLine_4 = Sketch_1.addLine(147.5779350608725, -61.38418346467283, 147.5779350608725, 58.25973730731685) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchLine_5 = Sketch_1.addLine(147.5779350608725, 58.25973730731685, 297.5779350608724, 58.25973730731685) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchLine_6 = Sketch_1.addLine(297.5779350608724, 58.25973730731685, 297.5779350608724, -192.2459441196271) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchLine_7 = Sketch_1.addLine(297.5779350608724, -192.2459441196271, -302.4220649391276, -192.2459441196271) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint()) +SketchLine_8 = Sketch_1.addLine(-302.4220649391276, -192.2459441196271, -302.4220649391276, 58.25973730731688) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_8.endPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_7.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_8.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_2.result()) +SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_4.result()) +SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_6.result()) +SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_7.result(), 600) +SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchConstraintCollinear_1 = Sketch_1.setCollinear(SketchLine_5.result(), SketchLine_1.result()) +SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_1.result(), 250) +SketchConstraintLength_3 = Sketch_1.setLength(SketchLine_3.result(), 200) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_8r-SketchLine_7r-SketchLine_6r-SketchLine_5r-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r")], model.selection(), 600, 0) +Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1")) +SketchLine_9 = Sketch_2.addLine(236.9930310780426, -200, -144.601680073095, -200) +SketchLine_10 = Sketch_2.addLine(-144.601680073095, -200, -144.601680073095, -500) +SketchLine_11 = Sketch_2.addLine(-144.601680073095, -500, 236.9930310780426, -500) +SketchLine_12 = Sketch_2.addLine(236.9930310780426, -500, 236.9930310780426, -200) +SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchLine_12.endPoint(), SketchLine_9.startPoint()) +SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint()) +SketchConstraintCoincidence_11 = Sketch_2.setCoincident(SketchLine_10.endPoint(), SketchLine_11.startPoint()) +SketchConstraintCoincidence_12 = Sketch_2.setCoincident(SketchLine_11.endPoint(), SketchLine_12.startPoint()) +SketchConstraintHorizontal_4 = Sketch_2.setHorizontal(SketchLine_9.result()) +SketchConstraintVertical_5 = Sketch_2.setVertical(SketchLine_10.result()) +SketchConstraintHorizontal_5 = Sketch_2.setHorizontal(SketchLine_11.result()) +SketchConstraintVertical_6 = Sketch_2.setVertical(SketchLine_12.result()) +SketchProjection_1 = Sketch_2.addProjection(model.selection("EDGE", "Sketch_1/SketchLine_1"), False) +SketchLine_13 = SketchProjection_1.createdFeature() +SketchConstraintDistance_1 = Sketch_2.setDistance(SketchLine_13.result(), SketchLine_9.endPoint(), 200, True) +SketchConstraintDistance_2 = Sketch_2.setDistance(SketchLine_10.endPoint(), SketchLine_13.result(), "len", True) +model.do() +ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_9r-SketchLine_10f-SketchLine_11f-SketchLine_12f")], model.selection(), model.selection(), 0, model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_7"), 0, [model.selection("SOLID", "Extrusion_1_1")]) +Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_1_1/Modified_Face&Sketch_1/SketchLine_3&weak_name_1")) +SketchCircle_1 = Sketch_3.addCircle(27.57793506087247, -80, 42.03963933117138) +SketchProjection_2 = Sketch_3.addProjection(model.selection("EDGE", "[Extrusion_1_1/From_Face][ExtrusionCut_1_1/Modified_Face&Sketch_1/SketchLine_3&weak_name_1]"), False) +SketchProjection_2.setName("SketchProjection_3") +SketchProjection_2.result().setName("SketchProjection_3") +SketchLine_14 = SketchProjection_2.createdFeature() +SketchLine_14.setName("SketchLine_15") +SketchLine_14.result().setName("SketchLine_15") +SketchConstraintDistance_4 = Sketch_3.setDistance(SketchLine_14.result(), SketchCircle_1.center(), 80, True) +SketchConstraintDistance_4.setName("SketchConstraintDistance_4") +SketchProjection_3 = Sketch_3.addProjection(model.selection("EDGE", "[(ExtrusionCut_1_1/Modified_Face&Sketch_1/SketchLine_1)(Extrusion_1_1/From_Face)(ExtrusionCut_1_1/Generated_Face&Sketch_2/SketchLine_9)][ExtrusionCut_1_1/Modified_Face&Sketch_1/SketchLine_3&weak_name_1]"), False) +SketchProjection_3.setName("SketchProjection_4") +SketchProjection_3.result().setName("SketchProjection_4") +SketchLine_15 = SketchProjection_3.createdFeature() +SketchLine_15.setName("SketchLine_16") +SketchLine_15.result().setName("SketchLine_16") +SketchConstraintDistance_3 = Sketch_3.setDistance(SketchLine_15.result(), SketchCircle_1.center(), 80, True) +SketchConstraintDistance_3.setName("SketchConstraintDistance_3") +model.do() +ExtrusionCut_2 = model.addExtrusionCut(Part_1_doc, [model.selection("WIRE", "Sketch_3/Face-SketchCircle_1_2r_wire")], model.selection(), model.selection(), 0, model.selection("FACE", "ExtrusionCut_1_1/Modified_Face&Sketch_1/SketchLine_7"), 0, [model.selection("SOLID", "ExtrusionCut_1_1")]) +model.do() +# update the sketch 2 to make split of a size of a box +lenParam.setValue(700) +model.end() + +# check that sketch_3 and extrusion are updated well +from ModelAPI import * +aFactory = ModelAPI_Session.get().validators() +assert(aFactory.validate(ExtrusionCut_2.feature())) diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 1b7753423..368f4452c 100755 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -263,38 +263,39 @@ void SketchPlugin_Sketch::attributeChanged(const std::string& theID) { GeomAPI_ShapeIterator anIt(aSelection); aFace = anIt.current()->face(); } - - std::shared_ptr aPlane = aFace->getPlane(); - if (aPlane) { - double anA, aB, aC, aD; - aPlane->coefficients(anA, aB, aC, aD); - - // calculate attributes of the sketch - std::shared_ptr aNormDir(new GeomAPI_Dir(anA, aB, aC)); - std::shared_ptr aCoords = aNormDir->xyz(); - std::shared_ptr aZero(new GeomAPI_XYZ(0, 0, 0)); - aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero)); - std::shared_ptr anOrigPnt(new GeomAPI_Pnt(aCoords)); - // X axis is preferable to be dirX on the sketch - // here can not be very small value to avoid very close to X normal axis (issue 595) - static const double tol = 0.1; - bool isX = fabs(anA) - 1.0 < tol && fabs(aB) < tol && fabs(aC) < tol; - std::shared_ptr aTempDir( - isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0)); - std::shared_ptr aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir))); - std::shared_ptr aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir))); - - // update position of the sketch - std::shared_ptr anOrigin = std::dynamic_pointer_cast - (data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); - anOrigin->setValue(anOrigPnt); - std::shared_ptr aNormal = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Sketch::NORM_ID())); - aNormal->setValue(aNormDir); - std::shared_ptr aDirX = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Sketch::DIRX_ID())); - aDirX->setValue(aXDir); - std::shared_ptr aDir = aPlane->direction(); + if (aFace.get()) { + std::shared_ptr aPlane = aFace->getPlane(); + if (aPlane.get()) { + double anA, aB, aC, aD; + aPlane->coefficients(anA, aB, aC, aD); + + // calculate attributes of the sketch + std::shared_ptr aNormDir(new GeomAPI_Dir(anA, aB, aC)); + std::shared_ptr aCoords = aNormDir->xyz(); + std::shared_ptr aZero(new GeomAPI_XYZ(0, 0, 0)); + aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero)); + std::shared_ptr anOrigPnt(new GeomAPI_Pnt(aCoords)); + // X axis is preferable to be dirX on the sketch + // here can not be very small value to avoid very close to X normal axis (issue 595) + static const double tol = 0.1; + bool isX = fabs(anA) - 1.0 < tol && fabs(aB) < tol && fabs(aC) < tol; + std::shared_ptr aTempDir( + isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0)); + std::shared_ptr aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir))); + std::shared_ptr aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir))); + + // update position of the sketch + std::shared_ptr anOrigin = std::dynamic_pointer_cast + (data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + anOrigin->setValue(anOrigPnt); + std::shared_ptr aNormal = std::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Sketch::NORM_ID())); + aNormal->setValue(aNormDir); + std::shared_ptr aDirX = std::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Sketch::DIRX_ID())); + aDirX->setValue(aXDir); + std::shared_ptr aDir = aPlane->direction(); + } } } } else if (theID == NORM_ID() || theID == DIRX_ID() || theID == ORIGIN_ID()) {