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