Salome HOME
Merge branch 'master' into cgt/devCEA
[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 from salome.shaper import model
102 assert(model.checkPythonDump())