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