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