1 # Copyright (C) 2019 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from SketchAPI import *
21 from salome.shaper import model
24 def checkMiddlePoint(feature, x, y, z, tolerance = 1.e-7):
25 shape = feature.results()[0].resultSubShapePair()[0].shape()
26 assert(shape is not None)
27 middlePoint = shape.middlePoint()
28 assert(math.fabs(middlePoint.x() - x) < tolerance), "X: {} != {}".format(middlePoint.x(), x)
29 assert(math.fabs(middlePoint.y() - y) < tolerance), "Y: {} != {}".format(middlePoint.y(), y)
30 assert(math.fabs(middlePoint.z() - z) < tolerance), "Z: {} != {}".format(middlePoint.z(), z)
34 partSet = model.moduleDocument()
35 Part_1 = model.addPart(partSet)
36 Part_1_doc = Part_1.document()
37 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
38 Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Left"))
39 SketchCircle_1 = Sketch_1.addCircle(4, 5.52786404500042, 3)
40 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Left]"), False)
41 SketchLine_1 = SketchProjection_1.createdFeature()
42 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_1.result(), 6, True)
43 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 3)
44 SketchIntersectionPoint_1 = Sketch_1.addIntersectionPoint(model.selection("EDGE", "[Box_1_1/Back][Box_1_1/Top]"), False)
45 [SketchPoint_1] = SketchIntersectionPoint_1.intersectionPoints()
46 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchCircle_1.center(), 6, True)
48 ExtrusionFuse_1 = model.addExtrusionFuse(Part_1_doc, [model.selection("WIRE", "Sketch_1/Face-SketchCircle_1_2r_wire")], model.selection(), 1, 0, [model.selection("SOLID", "Box_1_1")])
52 model.checkSketch(Sketch_1, SKETCH_DOF)
54 from GeomAPI import GeomAPI_Shape
56 model.testNbResults(ExtrusionFuse_1, 1)
57 model.testNbSubResults(ExtrusionFuse_1, [0])
58 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.SOLID, [1])
59 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.FACE, [8])
60 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.EDGE, [30])
61 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.VERTEX, [60])
62 model.testResultsVolumes(ExtrusionFuse_1, [1028.2743338823])
64 checkMiddlePoint(ExtrusionFuse_1, 4.96954097, 4.7867868, 5.0160782)
66 # change plane and check error
68 Sketch_1.setPlane(model.selection("FACE", "Box_1_1/Front"))
70 assert(SketchIntersectionPoint_1.feature().error() != "")
74 # change plane to get correct sketch
76 Sketch_1.setPlane(model.selection("FACE", "Box_1_1/Right"))
78 model.checkSketch(Sketch_1, SKETCH_DOF)
80 model.testNbResults(ExtrusionFuse_1, 1)
81 model.testNbSubResults(ExtrusionFuse_1, [0])
82 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.SOLID, [1])
83 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.FACE, [8])
84 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.EDGE, [30])
85 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.VERTEX, [60])
86 model.testResultsVolumes(ExtrusionFuse_1, [1028.2743338823])
88 checkMiddlePoint(ExtrusionFuse_1, 4.96954097, 5.2132132, 5.0160782)
90 # change plane removing features related to external objects
92 Sketch_1.setPlane(model.selection("FACE", "Box_1_1/Top"), True)
95 model.checkSketch(Sketch_1, SKETCH_DOF)
97 model.testNbResults(ExtrusionFuse_1, 1)
98 model.testNbSubResults(ExtrusionFuse_1, [2])
99 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.SOLID, [2])
100 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.FACE, [9])
101 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.EDGE, [30])
102 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.VERTEX, [60])
103 model.testResultsVolumes(ExtrusionFuse_1, [1028.2743338823])
105 checkMiddlePoint(ExtrusionFuse_1, 5.0, 0.73606797, 5.5)
107 assert(model.checkPythonDump())