]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/Test/TestSewing_Manifold.py
Salome HOME
fixed bug where "Always create result" was required
[modules/shaper.git] / src / FeaturesPlugin / Test / TestSewing_Manifold.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 def testResults(theFeature,theModel,NbRes,NbSubRes,NbShell,NbFace,NbEdge,NbVertex):
46   """ Tests numbers of unique sub-shapes in the results
47   """
48   aResults = theFeature.feature().results()
49   aNbResults = len(aResults)
50   assert (aNbResults == NbRes), "Number of results: {} not equal to {}}.".format(aNbResults, NbRes)
51   theModel.testNbSubResults(theFeature, NbSubRes)
52   testNbUniqueSubShapes(theFeature, GeomAPI_Shape.SHELL, NbShell)
53   testNbUniqueSubShapes(theFeature, GeomAPI_Shape.FACE, NbFace)
54   testNbUniqueSubShapes(theFeature, GeomAPI_Shape.EDGE, NbEdge)
55   testNbUniqueSubShapes(theFeature, GeomAPI_Shape.VERTEX, NbVertex)
56
57 # Create document
58 model.begin()
59 partSet = model.moduleDocument()
60 Part_1 = model.addPart(partSet)
61 Part_1_doc = Part_1.document()
62 Param_dx = model.addParameter(Part_1_doc, "dx", '10')
63 Param_alfa = model.addParameter(Part_1_doc, "alfa", '90')
64
65 # =============================================================================
66 # Test 1a. Sew two shells with a single common edge (create result)
67 # =============================================================================
68 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
69 Box_2 = model.addBox(Part_1_doc, 10, 10, 10)
70 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_2_1")], axis = model.selection("EDGE", "PartSet/OX"), distance = "dx", keepSubResults = True)
71 Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], axis = model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Right]"), angle = "alfa", keepSubResults = True)
72
73 Shell_1_objects = [model.selection("FACE", "Box_1_1/Top"),
74                    model.selection("FACE", "Box_1_1/Left"),
75                    model.selection("FACE", "Box_1_1/Right"),
76                    model.selection("FACE", "Box_1_1/Back"),
77                    model.selection("FACE", "Box_1_1/Bottom")]
78 Shell_1 = model.addShell(Part_1_doc, Shell_1_objects)
79
80 Shell_2_objects = [model.selection("FACE", "Rotation_1_1/MF:Rotated&Box_2_1/Top"),
81                    model.selection("FACE", "Rotation_1_1/MF:Rotated&Box_2_1/Left"),
82                    model.selection("FACE", "Rotation_1_1/MF:Rotated&Box_2_1/Front"),
83                    model.selection("FACE", "Rotation_1_1/MF:Rotated&Box_2_1/Right"),
84                    model.selection("FACE", "Rotation_1_1/MF:Rotated&Box_2_1/Bottom")]
85 Shell_2 = model.addShell(Part_1_doc, Shell_2_objects)
86 model.do()
87
88 Sewing_1a = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-07, allowNonManifold = False, alwaysCreateResult = True)
89 model.end()
90
91 # sewing successful
92 testResults(Sewing_1a, model, 1, [0], [1], [10], [23], [14])
93
94 # =============================================================================
95 # Test 1b. Sew two shells with a single common edge (do not create result)
96 # =============================================================================
97 model.undo()
98 model.begin()
99
100 Sewing_1b = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-07, allowNonManifold = False, alwaysCreateResult = False)
101 model.end()
102
103 # sewing successful
104 testResults(Sewing_1b, model, 1, [0], [1], [10], [23], [14])
105
106 # =============================================================================
107 # Test 2a. Sew two shells with four common edges (create result)
108 # =============================================================================
109 model.undo()
110 model.begin()
111 Param_alfa.setValue(0)
112 model.do()
113
114 Sewing_2a = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-07, allowNonManifold = False, alwaysCreateResult = True)
115 model.end()
116
117 # sewing successful
118 testResults(Sewing_2a, model, 1, [0], [1], [10], [20], [12])
119
120 # =============================================================================
121 # Test 2b. Sew two shells with four common edges (do not create result)
122 # =============================================================================
123 model.undo()
124 model.begin()
125
126 Sewing_2b = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-07, allowNonManifold = False, alwaysCreateResult = False)
127 model.end()
128
129 # sewing successful
130 testResults(Sewing_2b, model, 1, [0], [1], [10], [20], [12])
131
132 # =============================================================================
133 # Test 3a. Sew two slightly disconnected shells (create result)
134 # =============================================================================
135 model.undo()
136 model.begin()
137 Param_dx.setValue(10.0001)
138 model.do()
139
140 Sewing_3a = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-07, allowNonManifold = False, alwaysCreateResult = True)
141 model.end()
142
143 # no sewing done (result is a compound with the two input shells)
144 testResults(Sewing_3a, model, 1, [2], [2], [10], [24], [16])
145
146 # =============================================================================
147 # Test 3b. Sew two slightly disconnected shells (do not create result)
148 # =============================================================================
149 model.undo()
150 model.begin()
151
152 Sewing_3b = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-07, allowNonManifold = False, alwaysCreateResult = False)
153 model.end()
154
155 # no sewing done (no result was created)
156 model.testNbResults(Sewing_3b, 0)
157
158 # =============================================================================
159 # Test 4a. Sew two slightly disconnected shells with larger tolerance (create result)
160 # =============================================================================
161 model.undo()
162 model.begin()
163 Param_dx.setValue(10.0001)
164 model.do()
165
166 Sewing_4a = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-04, allowNonManifold = False, alwaysCreateResult = True)
167 model.end()
168
169 # sewing successful
170 testResults(Sewing_4a, model, 1, [0], [1], [10], [20], [12])
171
172 # =============================================================================
173 # Test 4b. Sew two slightly disconnected shells with larger tolerance (do not create result)
174 # =============================================================================
175 model.undo()
176 model.begin()
177
178 Sewing_4b = model.addSewing(Part_1_doc, [model.selection("SHELL", "Shell_2_1"), model.selection("SHELL", "Shell_1_1")], 1e-04, allowNonManifold = False, alwaysCreateResult = False)
179 model.end()
180
181 # sewing successful
182 testResults(Sewing_4b, model, 1, [0], [1], [10], [20], [12])