Salome HOME
fixed non conformance with same feature behavior in GEOM
[modules/shaper.git] / src / FeaturesPlugin / Test / TestGlueFaces_Shell.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 testCompound(theFeature,theModel,NbSubRes,NbSolid,NbFace,NbEdge,NbVertex):
46   """ Tests numbers of unique sub-shapes in compound result
47   """
48   aResults = theFeature.feature().results()
49   aNbResults = len(aResults)
50   assert (aNbResults == 1), "Number of results: {} not equal to 1.".format(aNbResults)
51   assert aResults[0].shape().isCompound(), "Result shape type: {}. Expected: COMPOUND.".format(aResults[0].shape().shapeTypeStr())
52   theModel.testNbSubResults(theFeature, NbSubRes)
53   testNbUniqueSubShapes(theFeature, GeomAPI_Shape.SOLID, NbSolid)
54   testNbUniqueSubShapes(theFeature, GeomAPI_Shape.FACE, NbFace)
55   testNbUniqueSubShapes(theFeature, GeomAPI_Shape.EDGE, NbEdge)
56   testNbUniqueSubShapes(theFeature, GeomAPI_Shape.VERTEX, NbVertex)
57
58 # Create document
59 model.begin()
60 partSet = model.moduleDocument()
61 Part_1 = model.addPart(partSet)
62 Part_1_doc = Part_1.document()
63 Param_dx = model.addParameter(Part_1_doc, "dx", '10')
64 Param_alfa = model.addParameter(Part_1_doc, "alfa", '0')
65
66 # =============================================================================
67 # Test 1. Glue faces of 2 adjacent shells
68 # =============================================================================
69 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
70 Box_2 = model.addBox(Part_1_doc, 10, 10, 10)
71 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_2_1")], axis = model.selection("EDGE", "PartSet/OX"), distance = "dx", keepSubResults = True)
72 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)
73 Shell_1_Objects = [model.selection("FACE", "Box_1_1/Top"), model.selection("FACE", "Box_1_1/Front")]
74 Shell_1 = model.addShell(Part_1_doc, Shell_1_Objects)
75 Shell_2_Objects = [model.selection("FACE", "Rotation_1_1/MF:Rotated&Box_2_1/Top"), model.selection("FACE", "Rotation_1_1/MF:Rotated&Box_2_1/Back")]
76 Shell_2 = model.addShell(Part_1_doc, Shell_2_Objects)
77 model.do()
78
79 GlueFaces_1 = model.addGlueFaces(Part_1_doc, [model.selection("SHELL", "Shell_1_1"), model.selection("SHELL", "Shell_2_1")], 1.0e-7, True)
80 model.end()
81
82 # gluing successful
83 testCompound(GlueFaces_1, model, [2], [0], [3], [10], [8])
84
85 # =============================================================================
86 # Test 2. Glue faces for 2 shells with 1 common edge only
87 # =============================================================================
88 model.undo() # to reuse the 2 shells
89 model.begin()
90 Param_alfa.setValue(90)
91 model.do()
92
93 GlueFaces_2 = model.addGlueFaces(Part_1_doc, [model.selection("SHELL", "Shell_1_1"), model.selection("SHELL", "Shell_2_1")], 1.0e-7, True)
94 model.end()
95
96 # gluing successful
97 testCompound(GlueFaces_2, model, [2], [0], [4], [13], [10])
98
99 # =============================================================================
100 # Test 3. Glue faces for 2 shells with 2 adjacent faces above default tolerance
101 # =============================================================================
102 model.undo() # to reuse the 2 shells
103 model.begin()
104
105 Param_alfa.setValue(0)
106 Param_dx.setValue(10.0001)
107 model.do()
108
109 GlueFaces_3 = model.addGlueFaces(Part_1_doc, [model.selection("SHELL", "Shell_1_1"), model.selection("SHELL", "Shell_2_1")], 1.0e-7, True)
110 model.end()
111
112 # no faces glued
113 testCompound(GlueFaces_3, model, [2], [0], [4], [14], [12])
114
115 # =============================================================================
116 # Test 4. Glue faces for 2 solids with 2 adjacent faces using different tolerance
117 # =============================================================================
118 model.undo() # to reuse Box_1_1, Translation_1_1, and Rotation_1_1
119 model.begin()
120
121 tol = 1.e-4
122 GlueFaces_4 = model.addGlueFaces(Part_1_doc, [model.selection("SHELL", "Shell_1_1"), model.selection("SHELL", "Shell_2_1")], tol, True)
123 model.end()
124
125 # gluing successful
126 testCompound(GlueFaces_4, model, [2], [0], [3], [10], [8])
127
128 # =============================================================================
129 # Test 5. Check Python dump
130 # =============================================================================
131 assert(model.checkPythonDump())