]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/Test/TestBooleanCut_Fuzzy_1.py
Salome HOME
support fuzzy parameter in all boolean operations
[modules/shaper.git] / src / FeaturesPlugin / Test / TestBooleanCut_Fuzzy_1.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_offset = model.addParameter(Part_1_doc, "offset", '5e-5')
51 Param_fuzzy = model.addParameter(Part_1_doc, "fuzzy", '1e-05')
52
53 ### Create Point
54 Point_2 = model.addPoint(Part_1_doc, "offset", "5", "5")
55
56 ### Create Box
57 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
58 Box_1.result().setColor(255, 0, 0)
59
60 ### Create Cylinder
61 Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "Point_1"), model.selection("EDGE", "PartSet/OX"), 6, 13)
62 Cylinder_1.result().setColor(255, 255, 0)
63 Cylinder_1.result().setTransparency(0.6)
64
65 ### Create Cut
66 Cut_1 = model.addCut(Part_1_doc, [model.selection("SOLID", "Box_1_1")], [model.selection("SOLID", "Cylinder_1_1")], fuzzyParam = "fuzzy", keepSubResults = True)
67 model.do()
68
69 model.testNbResults(Cut_1, 1)
70 model.testNbSubResults(Cut_1, [0])
71 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.SOLID, [1])
72 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.FACE, [14])
73 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.EDGE, [36])
74 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.VERTEX, [24])
75 model.testResultsVolumes(Cut_1, [49.093623770546])
76
77 ### Set a higher fuzzy value
78 Param_fuzzy.setValue(5.e-5)
79 model.do()
80
81 model.end()
82
83 model.testNbResults(Cut_1, 1)
84 model.testNbSubResults(Cut_1, [4])
85 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.SOLID, [4])
86 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.FACE, [20])
87 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.EDGE, [36])
88 testNbUniqueSubShapes(Cut_1, GeomAPI_Shape.VERTEX, [24])
89 model.testResultsVolumes(Cut_1, [49.088834629314])