Salome HOME
998e373a3365f80b43535fc1da31ba94705ae53f
[modules/shaper.git] / src / BuildPlugin / Test / TestFace.py
1 # Copyright (C) 2014-2023  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 # Initialization of the test
21 from ModelAPI import *
22 from GeomDataAPI import *
23 from GeomAlgoAPI import *
24 from GeomAPI import *
25
26 # Get document
27 aSession = ModelAPI_Session.get()
28 aDocument = aSession.moduleDocument()
29
30 # Create a part
31 aSession.startOperation()
32 aPartFeature = aDocument.addFeature("Part")
33 aSession.finishOperation()
34 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
35 aPart = aPartResult.partDoc()
36
37 # =============================================================================
38 # Test 1. Create face from edges of sketch
39 # =============================================================================
40
41 # Create a sketch
42 aSession.startOperation()
43 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
44 anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
45 anOrigin.setValue(0, 0, 0)
46 aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
47 aDirX.setValue(1, 0, 0)
48 aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
49 aNorm.setValue(0, 0, 1)
50
51 # Create lines
52 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
53 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
54 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
55 aSketchLineStartPoint.setValue(0, 0)
56 aSketchLineEndPoint.setValue(0, 50)
57 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
58 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
59 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
60 aSketchLineStartPoint.setValue(0, 50)
61 aSketchLineEndPoint.setValue(50, 50)
62 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
63 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
64 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
65 aSketchLineStartPoint.setValue(50, 50)
66 aSketchLineEndPoint.setValue(50, 0)
67 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
68 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
69 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
70 aSketchLineStartPoint.setValue(50, 0)
71 aSketchLineEndPoint.setValue(0, 0)
72 aSession.finishOperation()
73 aSketchResult = aSketchFeature.firstResult()
74 aSketchShape = aSketchResult.shape()
75
76 # Create face
77 aSession.startOperation()
78 aFaceFeature = aPart.addFeature("Face")
79 aBaseObjectsList = aFaceFeature.selectionList("base_objects")
80 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
81 while aShapeExplorer.more():
82     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
83     aShapeExplorer.next()
84 aSession.finishOperation()
85
86 # Test results
87 assert (len(aFaceFeature.results()) > 0)
88
89 # =============================================================================
90 # Test 2. Create face from edges of solid
91 # =============================================================================
92
93 # Cylinder
94 aSession.startOperation()
95 aCylinder = aPart.addFeature("Cylinder")
96 aCylinder.string("CreationMethod").setValue("Cylinder")
97 aCylinder.selection("base_point").selectSubShape("VERTEX", "PartSet/Origin")
98 aCylinder.selection("axis").selectSubShape("EDGE", "PartSet/OZ")
99 aCylinder.real("radius").setValue(5)
100 aCylinder.real("height").setValue(10)
101 aSession.finishOperation()
102 aCylinderResult = aCylinder.firstResult()
103 aCylinderShape = aCylinderResult.shape()
104
105 # Create face
106 aSession.startOperation()
107 aFaceFeature2 = aPart.addFeature("Face")
108 aBaseObjectsList = aFaceFeature2.selectionList("base_objects")
109 aBaseObjectsList.append("[Cylinder_1_1/Face_1][Cylinder_1_1/Face_2]", "EDGE")
110 aSession.finishOperation()
111 assert (len(aFaceFeature2.results()) > 0)
112
113 # =============================================================================
114 # Test 3. Create face from face of solid
115 # =============================================================================
116 aSession.startOperation()
117 aCylinder = aPart.addFeature("Cylinder")
118 aCylinder.string("CreationMethod").setValue("Cylinder")
119 aCylinder.selection("base_point").selectSubShape("VERTEX", "PartSet/Origin")
120 aCylinder.selection("axis").selectSubShape("EDGE", "PartSet/OZ")
121 aCylinder.real("radius").setValue(5)
122 aCylinder.real("height").setValue(10)
123 aSession.finishOperation()
124 aCylinderResult = aCylinder.firstResult()
125 aCylinderShape = aCylinderResult.shape()
126
127 aSession.startOperation()
128 aFaceFeature3 = aPart.addFeature("Face")
129 aBaseObjectsList = aFaceFeature3.selectionList("base_objects")
130 aBaseObjectsList.append("Cylinder_2_1/Face_1", "FACE")
131 aSession.finishOperation()
132 assert (len(aFaceFeature3.results()) > 0)
133
134 # =============================================================================
135 # Test 4. Verify error is reported if selection of face feature is mixed (edges and face)
136 # =============================================================================
137
138 aSession.startOperation()
139 aCylinder = aPart.addFeature("Cylinder")
140 aCylinder.string("CreationMethod").setValue("Cylinder")
141 aCylinder.selection("base_point").selectSubShape("VERTEX", "PartSet/Origin")
142 aCylinder.selection("axis").selectSubShape("EDGE", "PartSet/OZ")
143 aCylinder.real("radius").setValue(5)
144 aCylinder.real("height").setValue(10)
145 aSession.finishOperation()
146 aCylinderResult = aCylinder.firstResult()
147 aCylinderShape = aCylinderResult.shape()
148
149 aSession.startOperation()
150 aFaceFeature4 = aPart.addFeature("Face")
151 aBaseObjectsList = aFaceFeature4.selectionList("base_objects")
152 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
153 while aShapeExplorer.more():
154     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
155     aShapeExplorer.next()
156 aBaseObjectsList.append("Cylinder_3_1/Face_3", "FACE")
157 aSession.finishOperation()
158 assert (len(aFaceFeature4.results()) == 0)
159 # remove failed feature
160 aSession.startOperation()
161 aPart.removeFeature(aFaceFeature4)
162 aSession.finishOperation()
163
164 # =============================================================================
165 # Test 5. Check Face feature failed on incorrect input
166 # =============================================================================
167
168 aSession.startOperation()
169 aFaceFeature5 = aPart.addFeature("Face")
170 aBaseObjectsList = aFaceFeature5.selectionList("base_objects")
171 aBaseObjectsList.append(aCylinderResult, None)
172 aSession.finishOperation()
173 assert (len(aFaceFeature5.results()) == 0)
174
175 aSession.startOperation()
176 aBaseObjectsList.clear()
177 aShapeExplorer = GeomAPI_ShapeExplorer(aCylinderShape, GeomAPI_Shape.VERTEX)
178 aShape = aShapeExplorer.current()
179 aBaseObjectsList.append(aCylinderResult, aShape)
180 aSession.finishOperation()
181 assert (len(aFaceFeature5.results()) == 0)
182
183 aSession.startOperation()
184 aBaseObjectsList.clear()
185 aShapeExplorer = GeomAPI_ShapeExplorer(aFaceFeature.lastResult().shape(), GeomAPI_Shape.EDGE)
186 aShape = aShapeExplorer.current()
187 aBaseObjectsList.append(aFaceFeature.lastResult(), aShape)
188 aSession.finishOperation()
189 assert (len(aFaceFeature5.results()) == 0)
190
191 # remove failed feature
192 aSession.startOperation()
193 aPart.removeFeature(aFaceFeature5)
194 aSession.finishOperation()
195
196 from salome.shaper import model
197 assert(model.checkPythonDump())