Salome HOME
Updated copyright comment
[modules/shaper.git] / src / SketchPlugin / Test / TestChangeSketchPlane1.py
1 # Copyright (C) 2019-2024  CEA, EDF
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from SketchAPI import *
21 from salome.shaper import model
22 import math
23
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)
31
32
33 model.begin()
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)
47 model.do()
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")])
49 model.end()
50
51 SKETCH_DOF = 0
52 model.checkSketch(Sketch_1, SKETCH_DOF)
53
54 from GeomAPI import GeomAPI_Shape
55
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])
63
64 checkMiddlePoint(ExtrusionFuse_1, 4.972503122, 4.84876717, 5.0145146)
65
66 # change plane and check error
67 model.begin()
68 Sketch_1.setPlane(model.selection("FACE", "Box_1_1/Front"))
69 model.end()
70 assert(SketchIntersectionPoint_1.feature().error() != "")
71 # revert error
72 model.undo()
73
74 # change plane to get correct sketch
75 model.begin()
76 Sketch_1.setPlane(model.selection("FACE", "Box_1_1/Right"))
77 model.end()
78 model.checkSketch(Sketch_1, SKETCH_DOF)
79
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])
87
88 checkMiddlePoint(ExtrusionFuse_1, 4.972503122, 5.15123283, 5.0145146)
89
90 # change plane removing features related to external objects
91 model.begin()
92 Sketch_1.setPlane(model.selection("FACE", "Box_1_1/Top"), True)
93 model.end()
94 SKETCH_DOF = 6
95 model.checkSketch(Sketch_1, SKETCH_DOF)
96
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])
104
105 checkMiddlePoint(ExtrusionFuse_1, 5.0, 0.73606797, 5.5)
106
107 assert(model.checkPythonDump())