Salome HOME
Update copyrights
[modules/shaper.git] / src / BuildPlugin / Test / TestFace.py
1 # Copyright (C) 2014-2019  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
117 aSession.startOperation()
118 aFaceFeature3 = aPart.addFeature("Face")
119 aBaseObjectsList = aFaceFeature3.selectionList("base_objects")
120 aBaseObjectsList.append("Cylinder_1_1/Face_1", "FACE")
121 aSession.finishOperation()
122 assert (len(aFaceFeature3.results()) > 0)
123
124 # =============================================================================
125 # Test 4. Verify error is reported if selection of face feature is mixed (edges and face)
126 # =============================================================================
127
128 aSession.startOperation()
129 aFaceFeature4 = aPart.addFeature("Face")
130 aBaseObjectsList = aFaceFeature4.selectionList("base_objects")
131 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
132 while aShapeExplorer.more():
133     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
134     aShapeExplorer.next()
135 aBaseObjectsList.append("Cylinder_1_1/Face_3", "FACE")
136 aSession.finishOperation()
137 assert (len(aFaceFeature4.results()) == 0)
138 # remove failed feature
139 aSession.startOperation()
140 aPart.removeFeature(aFaceFeature4)
141 aSession.finishOperation()
142
143 # =============================================================================
144 # Test 5. Check Face feature failed on incorrect input
145 # =============================================================================
146
147 aSession.startOperation()
148 aFaceFeature5 = aPart.addFeature("Face")
149 aBaseObjectsList = aFaceFeature5.selectionList("base_objects")
150 aBaseObjectsList.append(aCylinderResult, None)
151 aSession.finishOperation()
152 assert (len(aFaceFeature5.results()) == 0)
153
154 aSession.startOperation()
155 aBaseObjectsList.clear()
156 aShapeExplorer = GeomAPI_ShapeExplorer(aCylinderShape, GeomAPI_Shape.VERTEX)
157 aShape = aShapeExplorer.current()
158 aBaseObjectsList.append(aCylinderResult, aShape)
159 aSession.finishOperation()
160 assert (len(aFaceFeature5.results()) == 0)
161
162 aSession.startOperation()
163 aBaseObjectsList.clear()
164 aShapeExplorer = GeomAPI_ShapeExplorer(aFaceFeature.lastResult().shape(), GeomAPI_Shape.EDGE)
165 aShape = aShapeExplorer.current()
166 aBaseObjectsList.append(aFaceFeature.lastResult(), aShape)
167 aSession.finishOperation()
168 assert (len(aFaceFeature5.results()) == 0)
169
170 # remove failed feature
171 aSession.startOperation()
172 aPart.removeFeature(aFaceFeature5)
173 aSession.finishOperation()
174
175 from salome.shaper import model
176 assert(model.checkPythonDump())