Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestRevolution.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 """
21       TestRevolution.py
22       Unit test of FeaturesPlugin_Revolution class
23
24       class FeaturesPlugin_Revolution : public ModelAPI_Feature
25         static const std::string MY_REVOLUTION_ID("Revolution");
26         static const std::string MY_GROUP_LIST_ID("base");
27         static const std::string MY_TO_OBJECT_ID("axis_object");
28         static const std::string METHOD_ATTR("CreationMethod");
29         static const std::string MY_TO_ANGLE_ID("to_angle");
30         static const std::string MY_FROM_ANGLE_ID("from_angle");
31         static const std::string MY_TO_OBJECT_ID("to_object");
32         static const std::string MY_TO_OFFSET_ID("to_offset");
33         static const std::string MY_FROM_OBJECT_ID("from_object");
34         static const std::string MY_FROM_OFFSET_ID("from_offset");
35
36         data()->addAttribute(LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
37         data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
38         data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
39         data()->addAttribute(TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
40         data()->addAttribute(FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
41         data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
42         data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
43         data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
44         data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
45 """
46 #=========================================================================
47 # Initialization of the test
48 #=========================================================================
49 from ModelAPI import *
50 from GeomDataAPI import *
51 from GeomAlgoAPI import *
52 from GeomAPI import *
53 import math
54
55 aSession = ModelAPI_Session.get()
56 aDocument = aSession.moduleDocument()
57 # Create a part for revol
58 aSession.startOperation()
59 aPartFeature = aDocument.addFeature("Part")
60 aSession.finishOperation()
61 assert (len(aPartFeature.results()) == 1)
62 # Another way is:
63 # aPart = aSession.activeDocument()
64 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
65 aPart = aPartResult.partDoc()
66
67 #=========================================================================
68 # Create a sketch circle to revol
69 #=========================================================================
70 aSession.startOperation()
71 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
72 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
73 origin.setValue(0, 0, 0)
74 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
75 dirx.setValue(1, 0, 0)
76 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
77 norm.setValue(0, 0, 1)
78
79 # Create circle
80 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
81 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
82 aCircleRadius = aSketchCircle.real("circle_radius")
83 anCircleCentr.setValue(0., 0.)
84 aCircleRadius.setValue(30.)
85 aSession.finishOperation()
86
87 # Build shape from sketcher results
88 aCircleSketchResult = modelAPI_ResultConstruction(aCircleSketchFeature.firstResult())
89 assert (aCircleSketchResult.facesNum() > 0)
90
91 #=========================================================================
92 # Create a sketch line to revol
93 #=========================================================================
94 aSession.startOperation()
95 aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
96 origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
97 origin.setValue(0, 0, 0)
98 dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
99 dirx.setValue(1, 0, 0)
100 norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
101 norm.setValue(0, 0, 1)
102
103 aSketchLine = aLineSketchFeature.addFeature("SketchLine")
104 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
105 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
106 aLineStartPoint.setValue(-100., -100.)
107 aLineEndPoint.setValue(100., -100.)
108 aSession.finishOperation()
109
110 # Build shape from sketcher results
111 aLineSketchResult = aLineSketchFeature.firstResult()
112 aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
113 aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
114 aLineEdge = aShapeExplorer.current()
115
116 #=========================================================================
117 # Test revol between from and to angles
118 #=========================================================================
119 aSession.startOperation()
120 aRevolFt = aPart.addFeature("Revolution")
121 assert (aRevolFt.getKind() == "Revolution")
122 # selection type FACE=4
123 aRevolFt.selectionList("base").append(
124     aCircleSketchResult, aCircleSketchResult.face(0))
125 aRevolFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
126 aRevolFt.string("CreationMethod").setValue("ByAngles")
127 aRevolFt.real("from_angle").setValue(10)
128 aRevolFt.real("to_angle").setValue(10)
129 aRevolFt.real("to_offset").setValue(0) #TODO: remove
130 aRevolFt.real("from_offset").setValue(0) #TODO: remove
131 aRevolFt.execute()
132 aSession.finishOperation()
133 assert (aRevolFt.real("from_angle").value() == 10.0)
134 assert (aRevolFt.real("to_angle").value() == 10.0)
135
136 # Check revol results
137 assert (len(aRevolFt.results()) > 0)
138 aRevolResult = modelAPI_ResultBody(aRevolFt.firstResult())
139 assert (aRevolResult is not None)
140
141 #=========================================================================
142 # Create bounding planes
143 #=========================================================================
144 # Create from plane
145 aSession.startOperation()
146 aFromPlaneFeature = aPart.addFeature("Plane")
147 aFromPlaneFeature.string("creation_method").setValue("by_general_equation")
148 aFromPlaneFeature.string("by_other_plane_option").setValue("by_distance_from_other") # TODO: remove
149 aFromPlaneFeature.real("A").setValue(0.)
150 aFromPlaneFeature.real("B").setValue(0.)
151 aFromPlaneFeature.real("C").setValue(1.)
152 aFromPlaneFeature.real("D").setValue(50.)
153 aSession.finishOperation()
154 aFromResult = aFromPlaneFeature.firstResult()
155 aFromShape = modelAPI_ResultConstruction(aFromResult).shape()
156
157 # Create to plane
158 aSession.startOperation()
159 aToPlaneFeature = aPart.addFeature("Plane")
160 aToPlaneFeature.string("creation_method").setValue("by_general_equation")
161 aToPlaneFeature.string("by_other_plane_option").setValue("by_distance_from_other") # TODO: remove
162 aToPlaneFeature.real("A").setValue(0.)
163 aToPlaneFeature.real("B").setValue(0.)
164 aToPlaneFeature.real("C").setValue(1.)
165 aToPlaneFeature.real("D").setValue(-50.)
166 aSession.finishOperation()
167 aToResult = aToPlaneFeature.firstResult()
168 aToShape = modelAPI_ResultConstruction(aToResult).shape()
169
170 #=========================================================================
171 # Test revol between bounding planes
172 #=========================================================================
173 aSession.startOperation()
174 aRevolFt = aPart.addFeature("Revolution")
175 assert (aRevolFt.getKind() == "Revolution")
176 # selection type FACE=4
177 aRevolFt.selectionList("base").append(
178     aCircleSketchResult, aCircleSketchResult.face(0))
179 aRevolFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
180 aRevolFt.string("CreationMethod").setValue("ByPlanesAndOffsets")
181 aRevolFt.real("from_angle").setValue(0) #TODO: remove
182 aRevolFt.real("to_angle").setValue(0) #TODO: remove
183 aRevolFt.selection("to_object").setValue(aToResult, None)
184 aRevolFt.real("to_offset").setValue(0)
185 aRevolFt.selection("from_object").setValue(aFromResult, None)
186 aRevolFt.real("from_offset").setValue(0)
187 aRevolFt.execute()
188 aSession.finishOperation()
189
190 # Check revol results
191 assert (len(aRevolFt.results()) > 0)
192 aRevolResult = modelAPI_ResultBody(aRevolFt.firstResult())
193 assert (aRevolResult is not None)
194 aSession.undo()
195
196 #=========================================================================
197 # Test revol between bounding plane
198 #=========================================================================
199 aSession.startOperation()
200 aRevolFt = aPart.addFeature("Revolution")
201 assert (aRevolFt.getKind() == "Revolution")
202 # selection type FACE=4
203 aRevolFt.selectionList("base").append(
204     aCircleSketchResult, aCircleSketchResult.face(0))
205 aRevolFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
206 aRevolFt.string("CreationMethod").setValue("ByPlanesAndOffsets")
207 aRevolFt.real("from_angle").setValue(0) #TODO: remove
208 aRevolFt.real("to_angle").setValue(0) #TODO: remove
209 aRevolFt.selection("to_object").setValue(aToResult, None)
210 aRevolFt.real("to_offset").setValue(0)
211 aRevolFt.selection("from_object").setValue(None, None)
212 aRevolFt.real("from_offset").setValue(0)
213 aRevolFt.execute()
214 aSession.finishOperation()
215
216 # Check revol results
217 assert (len(aRevolFt.results()) > 0)
218 aRevolResult = modelAPI_ResultBody(aRevolFt.firstResult())
219 assert (aRevolResult is not None)
220
221 from salome.shaper import model
222 assert(model.checkPythonDump())