Salome HOME
44d65f607f9aaf7417e42f2547372591b5f1dd9c
[modules/shaper.git] / src / FeaturesPlugin / Test / TestBooleanCut_Fuzzy_2.py
1 # Copyright (C) 2014-2023  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 salome.shaper import model
21 from GeomAPI import GeomAPI_Shape
22
23
24 model.begin()
25 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28 Param_fuzzy = model.addParameter(Part_1_doc, "fuzzy", '1e-07')
29
30 ### Create Point
31 Point_2 = model.addPoint(Part_1_doc, 5, 9.9999, 0)
32
33 ### Create Point
34 Point_3 = model.addPoint(Part_1_doc, 10, 10, 0)
35
36 ### Create Sketch
37 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
38 SketchLine_1 = Sketch_1.addLine(5, 0, 0, 0)
39 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
40 SketchPoint_1 = SketchProjection_1.createdFeature()
41 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchPoint_1.result())
42 SketchLine_2 = Sketch_1.addLine(0, 0, 0, 9.9999)
43 SketchLine_3 = Sketch_1.addLine(0, 9.9999, 5, 9.9999)
44 SketchLine_4 = Sketch_1.addLine(5, 9.9999, 5, 0)
45 Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
46 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
47 Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
48 Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
49 Sketch_1.setHorizontal(SketchLine_1.result())
50 Sketch_1.setVertical(SketchLine_2.result())
51 Sketch_1.setHorizontal(SketchLine_3.result())
52 Sketch_1.setVertical(SketchLine_4.result())
53 SketchProjection_2 = Sketch_1.addProjection(model.selection("VERTEX", "Point_1"), False)
54 SketchPoint_2 = SketchProjection_2.createdFeature()
55 Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchPoint_2.result())
56 SketchProjection_3 = Sketch_1.addProjection(model.selection("VERTEX", "Point_2"), False)
57 SketchPoint_3 = SketchProjection_3.createdFeature()
58 model.do()
59
60 ### Create Sketch
61 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
62 SketchLine_5 = Sketch_2.addLine(10, 0, 0, 0)
63 SketchProjection_4 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
64 SketchPoint_4 = SketchProjection_4.createdFeature()
65 Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchPoint_4.result())
66 SketchLine_6 = Sketch_2.addLine(0, 0, 0, 10)
67 SketchLine_7 = Sketch_2.addLine(0, 10, 10, 10)
68 SketchLine_8 = Sketch_2.addLine(10, 10, 10, 0)
69 Sketch_2.setCoincident(SketchLine_8.endPoint(), SketchLine_5.startPoint())
70 Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
71 Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
72 Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
73 Sketch_2.setHorizontal(SketchLine_5.result())
74 Sketch_2.setVertical(SketchLine_6.result())
75 Sketch_2.setHorizontal(SketchLine_7.result())
76 Sketch_2.setVertical(SketchLine_8.result())
77 SketchProjection_5 = Sketch_2.addProjection(model.selection("VERTEX", "Point_2"), False)
78 SketchPoint_5 = SketchProjection_5.createdFeature()
79 Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchPoint_5.result())
80 model.do()
81
82 ### Create Face
83 Face_1 = model.addFace(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")])
84 Face_1.result().setColor(255, 0, 0)
85
86 ### Create Face
87 Face_2 = model.addFace(Part_1_doc, [model.selection("COMPOUND", "Sketch_2")])
88 Face_2.result().setColor(0, 255, 0)
89
90 ### Create Cut
91 Cut_1 = model.addCut(Part_1_doc, [model.selection("FACE", "Face_2_1")], [model.selection("FACE", "Face_1_1")], fuzzyParam = "fuzzy", keepSubResults = True)
92 model.do()
93
94 model.testNbResults(Cut_1, 1)
95 model.testNbSubResults(Cut_1, [0])
96 model.testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.FACE, [1])
97 model.testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.EDGE, [6])
98 model.testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.VERTEX, [6])
99
100 ### Set a higher fuzzy value
101 Param_fuzzy.setValue(1.e-4)
102 model.do()
103
104 model.end()
105
106 model.testNbResults(Cut_1, 1)
107 model.testNbSubResults(Cut_1, [0])
108 model.testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.FACE, [1])
109 model.testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.EDGE, [4])
110 model.testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.VERTEX, [4])