Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / FeaturesPlugin / Test / TestRevolutionCut.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 #=========================================================================
22 # Initialization of the test
23 #=========================================================================
24 from ModelAPI import *
25 from GeomDataAPI import *
26 from GeomAlgoAPI import *
27 from GeomAPI import *
28 import math
29
30 __updated__ = "2014-12-16"
31
32 aSession = ModelAPI_Session.get()
33 aDocument = aSession.moduleDocument()
34 # Create a part for extrusion
35 aSession.startOperation()
36 aPartFeature = aDocument.addFeature("Part")
37 aSession.finishOperation()
38 assert (len(aPartFeature.results()) == 1)
39 # Another way is:
40 # aPart = aSession.activeDocument()
41 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
42 aPart = aPartResult.partDoc()
43 #=========================================================================
44 # Create a sketch circle to extrude
45 #=========================================================================
46 aSession.startOperation()
47 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
48 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
49 origin.setValue(0, 0, 0)
50 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
51 dirx.setValue(1, 0, 0)
52 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
53 norm.setValue(0, 0, 1)
54 # Create circle
55 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
56 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
57 aCircleRadius = aSketchCircle.real("circle_radius")
58 anCircleCentr.setValue(0, 0)
59 aCircleRadius.setValue(20)
60 aSession.finishOperation()
61 #=========================================================================
62 # Make extrusion on circle
63 #=========================================================================
64 # Build shape from sketcher results
65 aCircleSketchResult = aCircleSketchFeature.firstResult()
66 aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape()
67 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt()
68 dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir()
69 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir()
70 aCircleSketchFaces = ShapeList()
71 GeomAlgoAPI_SketchBuilder.createFaces(
72     origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces)
73 assert (len(aCircleSketchFaces) > 0)
74 assert (aCircleSketchFaces[0] is not None)
75 # Create extrusion
76 aSession.startOperation()
77 anExtrusionFt = aPart.addFeature("Extrusion")
78 assert (anExtrusionFt.getKind() == "Extrusion")
79 # selection type FACE=4
80 anExtrusionFt.selectionList("base").append(
81     aCircleSketchResult, aCircleSketchFaces[0])
82 anExtrusionFt.string("CreationMethod").setValue("BySizes")
83 anExtrusionFt.real("to_size").setValue(50)
84 anExtrusionFt.real("from_size").setValue(0)
85 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
86 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
87 anExtrusionFt.execute()
88 aSession.finishOperation()
89 assert (anExtrusionFt.real("to_size").value() == 50.0)
90
91 # Check extrusion results
92 assert (len(anExtrusionFt.results()) > 0)
93 anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
94 assert (anExtrusionResult is not None)
95
96 #=========================================================================
97 # Create a sketch line to revol
98 #=========================================================================
99 aSession.startOperation()
100 aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
101 origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
102 origin.setValue(0, 0, 50)
103 dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
104 dirx.setValue(1, 0, 0)
105 norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
106 norm.setValue(0, 0, 1)
107 aLineSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/TopFace_1")
108
109 aSketchLine = aLineSketchFeature.addFeature("SketchLine")
110 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
111 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
112 aLineStartPoint.setValue(-20, -20)
113 aLineEndPoint.setValue(20, -20)
114 aSession.finishOperation()
115
116 # Build shape from sketcher results
117 aLineSketchResult = aLineSketchFeature.firstResult()
118 aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
119 aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
120 aLineEdge = aShapeExplorer.current()
121
122 #=========================================================================
123 # Make revolution cut
124 #=========================================================================
125 aSession.startOperation()
126 anRevolutionCutFt = featureToCompositeFeature(aPart.addFeature("RevolutionCut"))
127 assert (anRevolutionCutFt.getKind() == "RevolutionCut")
128 # selection type FACE=4
129 aSession.startOperation()
130 aCircleSketchFeature = featureToCompositeFeature(anRevolutionCutFt.addFeature("Sketch"))
131 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
132 origin.setValue(0, 0, 50)
133 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
134 dirx.setValue(1, 0, 0)
135 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
136 norm.setValue(0, 0, 1)
137 aCircleSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/To_Face_1")
138 aSession.startOperation()
139 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
140 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
141 aCircleRadius = aSketchCircle.real("circle_radius")
142 anCircleCentr.setValue(0, 0)
143 aCircleRadius.setValue(10)
144 aSession.finishOperation()
145 aSession.finishOperation()
146 aSession.startOperation()
147 aCircleSketchFeature.execute() # execute for sketch should be called here, because it is not set as current feature, so it is disabled.
148 anRevolutionCutFt.selectionList("base").append(aCircleSketchFeature.firstResult(), None)
149 anRevolutionCutFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
150 anRevolutionCutFt.string("CreationMethod").setValue("ByAngles")
151 anRevolutionCutFt.real("to_angle").setValue(50)
152 anRevolutionCutFt.real("from_angle").setValue(50)
153 anRevolutionCutFt.real("to_offset").setValue(0) #TODO: remove
154 anRevolutionCutFt.real("from_offset").setValue(0) #TODO: remove
155 anRevolutionCutFt.selectionList("main_objects").append(anExtrusionResult, anExtrusionResult.shape())
156 aSession.finishOperation()
157 aSession.finishOperation()
158
159 #=========================================================================
160 # Test results
161 #=========================================================================
162 aFactory = ModelAPI_Session.get().validators()
163 assert (aFactory.validate(anRevolutionCutFt))
164 assert (len(anRevolutionCutFt.results()) > 0)
165 aCurrentResult = modelAPI_ResultBody(anRevolutionCutFt.firstResult())
166 assert (aCurrentResult is not None)
167
168 from salome.shaper import model
169 assert(model.checkPythonDump())