Salome HOME
61a26425a07e9917d4f41b1f10f7de0a91e844a9
[modules/shaper.git] / src / FeaturesPlugin / Test / TestBooleanCut_Fuzzy_2.py
1 # Copyright (C) 2014-2022  CEA/DEN, EDF R&D
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 aShapeTypes = {
24   GeomAPI_Shape.SOLID:  "GeomAPI_Shape.SOLID",
25   GeomAPI_Shape.FACE:   "GeomAPI_Shape.FACE",
26   GeomAPI_Shape.EDGE:   "GeomAPI_Shape.EDGE",
27   GeomAPI_Shape.VERTEX: "GeomAPI_Shape.VERTEX"}
28
29 def testNbUniqueSubShapes(theFeature, theShapeType, theExpectedNbSubShapes):
30   """ Tests number of unique feature sub-shapes of passed type for each result.
31   :param theFeature: feature to test.
32   :param theShapeType: shape type of sub-shapes to test.
33   :param theExpectedNbSubShapes: list of sub-shapes numbers. Size of list should be equal to len(theFeature.results()).
34   """
35   aResults = theFeature.feature().results()
36   aNbResults = len(aResults)
37   aListSize = len(theExpectedNbSubShapes)
38   assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
39   for anIndex in range(0, aNbResults):
40     aNbResultSubShapes = 0
41     anExpectedNbSubShapes = theExpectedNbSubShapes[anIndex]
42     aNbResultSubShapes = aResults[anIndex].shape().subShapes(theShapeType, True).size()
43     assert (aNbResultSubShapes == anExpectedNbSubShapes), "Number of sub-shapes of type {} for result[{}]: {}. Expected: {}.".format(aShapeTypes[theShapeType], anIndex, aNbResultSubShapes, anExpectedNbSubShapes)
44
45
46 model.begin()
47 partSet = model.moduleDocument()
48 Part_1 = model.addPart(partSet)
49 Part_1_doc = Part_1.document()
50 Param_fuzzy = model.addParameter(Part_1_doc, "fuzzy", '1e-07')
51
52 ### Create Point
53 Point_2 = model.addPoint(Part_1_doc, 5, 9.9999, 0)
54
55 ### Create Point
56 Point_3 = model.addPoint(Part_1_doc, 10, 10, 0)
57
58 ### Create Sketch
59 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
60 SketchLine_1 = Sketch_1.addLine(5, 0, 0, 0)
61 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
62 SketchPoint_1 = SketchProjection_1.createdFeature()
63 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchPoint_1.result())
64 SketchLine_2 = Sketch_1.addLine(0, 0, 0, 9.9999)
65 SketchLine_3 = Sketch_1.addLine(0, 9.9999, 5, 9.9999)
66 SketchLine_4 = Sketch_1.addLine(5, 9.9999, 5, 0)
67 Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
68 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
69 Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
70 Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
71 Sketch_1.setHorizontal(SketchLine_1.result())
72 Sketch_1.setVertical(SketchLine_2.result())
73 Sketch_1.setHorizontal(SketchLine_3.result())
74 Sketch_1.setVertical(SketchLine_4.result())
75 SketchProjection_2 = Sketch_1.addProjection(model.selection("VERTEX", "Point_1"), False)
76 SketchPoint_2 = SketchProjection_2.createdFeature()
77 Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchPoint_2.result())
78 SketchProjection_3 = Sketch_1.addProjection(model.selection("VERTEX", "Point_2"), False)
79 SketchPoint_3 = SketchProjection_3.createdFeature()
80 model.do()
81
82 ### Create Sketch
83 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
84 SketchLine_5 = Sketch_2.addLine(10, 0, 0, 0)
85 SketchProjection_4 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
86 SketchPoint_4 = SketchProjection_4.createdFeature()
87 Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchPoint_4.result())
88 SketchLine_6 = Sketch_2.addLine(0, 0, 0, 10)
89 SketchLine_7 = Sketch_2.addLine(0, 10, 10, 10)
90 SketchLine_8 = Sketch_2.addLine(10, 10, 10, 0)
91 Sketch_2.setCoincident(SketchLine_8.endPoint(), SketchLine_5.startPoint())
92 Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
93 Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
94 Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
95 Sketch_2.setHorizontal(SketchLine_5.result())
96 Sketch_2.setVertical(SketchLine_6.result())
97 Sketch_2.setHorizontal(SketchLine_7.result())
98 Sketch_2.setVertical(SketchLine_8.result())
99 SketchProjection_5 = Sketch_2.addProjection(model.selection("VERTEX", "Point_2"), False)
100 SketchPoint_5 = SketchProjection_5.createdFeature()
101 Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchPoint_5.result())
102 model.do()
103
104 ### Create Face
105 Face_1 = model.addFace(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")])
106 Face_1.result().setColor(255, 0, 0)
107
108 ### Create Face
109 Face_2 = model.addFace(Part_1_doc, [model.selection("COMPOUND", "Sketch_2")])
110 Face_2.result().setColor(0, 255, 0)
111
112 ### Create Cut
113 Cut_1 = model.addCut(Part_1_doc, [model.selection("FACE", "Face_2_1")], [model.selection("FACE", "Face_1_1")], fuzzyParam = "fuzzy", keepSubResults = True)
114 model.do()
115
116 model.testNbResults(Cut_1, 1)
117 model.testNbSubResults(Cut_1, [0])
118 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.FACE, [1])
119 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.EDGE, [6])
120 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.VERTEX, [6])
121
122 ### Set a higher fuzzy value
123 Param_fuzzy.setValue(1.e-4)
124 model.do()
125
126 model.end()
127
128 model.testNbResults(Cut_1, 1)
129 model.testNbSubResults(Cut_1, [0])
130 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.FACE, [1])
131 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.EDGE, [4])
132 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.VERTEX, [4])