Salome HOME
Extend unit tests for Vertex, Edge, Wire, Face and Shell features
[modules/shaper.git] / src / BuildPlugin / Test / TestShell.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 def createFace(thePart, theNormX, theNormY, theNormZ):
28     # Create a sketch
29     aSession.startOperation()
30     aSketchFeature = featureToCompositeFeature(thePart.addFeature("Sketch"))
31     anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
32     anOrigin.setValue(0, 0, 0)
33     aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
34     aDirX.setValue(1, 0, 0)
35     aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
36     aNorm.setValue(theNormX, theNormY, theNormZ)
37
38     # Create lines
39     aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
40     aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
41     aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
42     aSketchLineStartPoint.setValue(0, 0)
43     aSketchLineEndPoint.setValue(0, 50)
44     aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
45     aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
46     aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
47     aSketchLineStartPoint.setValue(0, 50)
48     aSketchLineEndPoint.setValue(50, 50)
49     aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
50     aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
51     aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
52     aSketchLineStartPoint.setValue(50, 50)
53     aSketchLineEndPoint.setValue(50, 0)
54     aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
55     aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
56     aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
57     aSketchLineStartPoint.setValue(50, 0)
58     aSketchLineEndPoint.setValue(0, 0)
59     aSession.finishOperation()
60     aSketchResult = aSketchFeature.firstResult()
61     aSketchShape = aSketchResult.shape()
62
63     # Create face
64     aSession.startOperation()
65     aFaceFeature = thePart.addFeature("Face")
66     aBaseObjectsList = aFaceFeature.selectionList("base_objects")
67     aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
68     while aShapeExplorer.more():
69         aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
70         aShapeExplorer.next()
71     aSession.finishOperation()
72     return aFaceFeature.firstResult()
73
74 # Get document
75 aSession = ModelAPI_Session.get()
76 aDocument = aSession.moduleDocument()
77
78 # Create a part
79 aSession.startOperation()
80 aPartFeature = aDocument.addFeature("Part")
81 aSession.finishOperation()
82 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
83 aPart = aPartResult.partDoc()
84
85 # Create faces
86 aFaceResults = []
87 aFaceResults.append(createFace(aPart, 0, 0, 1))
88 aFaceResults.append(createFace(aPart, 0, 1, 0))
89
90 # Create shell
91 aSession.startOperation()
92 aShellFeature = aPart.addFeature("Shell")
93 aBaseObjectsList = aShellFeature.selectionList("base_objects")
94 for aFaceResult in aFaceResults:
95     aBaseObjectsList.append(aFaceResult, None)
96 aSession.finishOperation()
97
98 # Test results
99 assert (len(aShellFeature.results()) > 0)
100
101 # Test shell building on set of faces from another result
102
103 # Cylinder
104 aSession.startOperation()
105 aCylinder = aPart.addFeature("Cylinder")
106 aCylinder.string("CreationMethod").setValue("Cylinder")
107 aCylinder.selection("base_point").selectSubShape("VERTEX", "PartSet/Origin")
108 aCylinder.selection("axis").selectSubShape("EDGE", "PartSet/OZ")
109 aCylinder.real("radius").setValue(25)
110 aCylinder.real("height").setValue(50)
111 aSession.finishOperation()
112 aCylinderResult = aCylinder.firstResult()
113 aCylinderShape = aCylinderResult.shape()
114
115 # Create shell
116 aSession.startOperation()
117 aShellFeature2 = aPart.addFeature("Shell")
118 aBaseObjectsList = aShellFeature2.selectionList("base_objects")
119 aBaseObjectsList.append("Cylinder_1_1/Face_1", "FACE")
120 aBaseObjectsList.append("Cylinder_1_1/Face_3", "FACE")
121 aSession.finishOperation()
122
123 # Test results
124 assert (len(aShellFeature2.results()) > 0)
125
126 # Check Shell feature failed on incorrect input
127 aShellResult = aShellFeature.firstResult()
128 aSession.startOperation()
129 aShellFeature3 = aPart.addFeature("Shell")
130 aBaseObjectsList = aShellFeature3.selectionList("base_objects")
131 aShapeExplorer = GeomAPI_ShapeExplorer(aShellResult.shape(), GeomAPI_Shape.EDGE)
132 while aShapeExplorer.more():
133     aBaseObjectsList.append(aShellResult, aShapeExplorer.current())
134     aShapeExplorer.next()
135 aSession.finishOperation()
136 assert (len(aShellFeature3.results()) == 0)
137
138 # remove failed feature
139 aSession.startOperation()
140 aPart.removeFeature(aShellFeature3)
141 aSession.finishOperation()
142
143 from salome.shaper import model
144 assert(model.checkPythonDump())