Salome HOME
Merge commit 'refs/tags/V9_2_0^{}'
[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 = modelAPI_ResultConstruction(aCircleSketchFeature.firstResult())
66 assert (aCircleSketchResult.facesNum() > 0)
67 # Create extrusion
68 aSession.startOperation()
69 anExtrusionFt = aPart.addFeature("Extrusion")
70 assert (anExtrusionFt.getKind() == "Extrusion")
71 # selection type FACE=4
72 anExtrusionFt.selectionList("base").append(
73     aCircleSketchResult, aCircleSketchResult.face(0))
74 anExtrusionFt.string("CreationMethod").setValue("BySizes")
75 anExtrusionFt.real("to_size").setValue(50)
76 anExtrusionFt.real("from_size").setValue(0)
77 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
78 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
79 anExtrusionFt.execute()
80 aSession.finishOperation()
81 assert (anExtrusionFt.real("to_size").value() == 50.0)
82
83 # Check extrusion results
84 assert (len(anExtrusionFt.results()) > 0)
85 anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
86 assert (anExtrusionResult is not None)
87
88 #=========================================================================
89 # Create a sketch line to revol
90 #=========================================================================
91 aSession.startOperation()
92 aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
93 origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
94 origin.setValue(0, 0, 50)
95 dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
96 dirx.setValue(1, 0, 0)
97 norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
98 norm.setValue(0, 0, 1)
99 aLineSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/TopFace")
100
101 aSketchLine = aLineSketchFeature.addFeature("SketchLine")
102 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
103 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
104 aLineStartPoint.setValue(-20, -20)
105 aLineEndPoint.setValue(20, -20)
106 aSession.finishOperation()
107
108 # Build shape from sketcher results
109 aLineSketchResult = aLineSketchFeature.firstResult()
110 aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
111 aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
112 aLineEdge = aShapeExplorer.current()
113
114 #=========================================================================
115 # Make revolution cut
116 #=========================================================================
117 aSession.startOperation()
118 anRevolutionCutFt = featureToCompositeFeature(aPart.addFeature("RevolutionCut"))
119 assert (anRevolutionCutFt.getKind() == "RevolutionCut")
120 # selection type FACE=4
121 aSession.startOperation()
122 aCircleSketchFeature = featureToCompositeFeature(anRevolutionCutFt.addFeature("Sketch"))
123 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
124 origin.setValue(0, 0, 50)
125 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
126 dirx.setValue(1, 0, 0)
127 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
128 norm.setValue(0, 0, 1)
129 aCircleSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/To_Face")
130 aSession.startOperation()
131 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
132 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
133 aCircleRadius = aSketchCircle.real("circle_radius")
134 anCircleCentr.setValue(0, 0)
135 aCircleRadius.setValue(10)
136 aSession.finishOperation()
137 aSession.finishOperation()
138 aSession.startOperation()
139 aCircleSketchFeature.execute() # execute for sketch should be called here, because it is not set as current feature, so it is disabled.
140 anRevolutionCutFt.selectionList("base").append(aCircleSketchFeature.firstResult(), None)
141 anRevolutionCutFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
142 anRevolutionCutFt.string("CreationMethod").setValue("ByAngles")
143 anRevolutionCutFt.real("to_angle").setValue(50)
144 anRevolutionCutFt.real("from_angle").setValue(50)
145 anRevolutionCutFt.real("to_offset").setValue(0) #TODO: remove
146 anRevolutionCutFt.real("from_offset").setValue(0) #TODO: remove
147 anRevolutionCutFt.selectionList("main_objects").append(anExtrusionResult, anExtrusionResult.shape())
148 aSession.finishOperation()
149 aSession.finishOperation()
150
151 #=========================================================================
152 # Test results
153 #=========================================================================
154 aFactory = ModelAPI_Session.get().validators()
155 assert (aFactory.validate(anRevolutionCutFt))
156 assert (len(anRevolutionCutFt.results()) > 0)
157 aCurrentResult = modelAPI_ResultBody(anRevolutionCutFt.firstResult())
158 assert (aCurrentResult is not None)
159
160 from salome.shaper import model
161 assert(model.checkPythonDump())