1 # Copyright (C) 2014-2022 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 Unit test of FeaturesPlugin_RevolutionFuse class
24 class FeaturesPlugin_RevolutionFuse : public FeaturesPlugin_RevolutionBoolean
25 static const std::string MY_REVOLUTION_ID("RevolutionFuse");
26 static const std::string MY_SKETCH_OBJECT_ID("sketch");
27 static const std::string MY_AXIS_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 static const std::string MY_BOOLEAN_OBJECTS_ID("boolean_objects");
37 data()->addAttribute(SKETCH_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
38 data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
39 data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
40 data()->addAttribute(TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
41 data()->addAttribute(FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
42 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
43 data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId());
44 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
45 data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeSelection::typeId());
46 data()->addAttribute(BOOLEAN_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
48 #=========================================================================
49 # Initialization of the test
50 #=========================================================================
51 from ModelAPI import *
52 from GeomDataAPI import *
53 from GeomAlgoAPI import *
57 __updated__ = "2014-12-16"
59 aSession = ModelAPI_Session.get()
60 aDocument = aSession.moduleDocument()
61 # Create a part for extrusion
62 aSession.startOperation()
63 aPartFeature = aDocument.addFeature("Part")
64 aSession.finishOperation()
65 assert (len(aPartFeature.results()) == 1)
67 # aPart = aSession.activeDocument()
68 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
69 aPart = aPartResult.partDoc()
70 #=========================================================================
71 # Create a sketch circle to extrude
72 #=========================================================================
73 aSession.startOperation()
74 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
75 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
76 origin.setValue(0, 0, 0)
77 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
78 dirx.setValue(1, 0, 0)
79 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
80 norm.setValue(0, 0, 1)
82 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
83 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
84 aCircleRadius = aSketchCircle.real("circle_radius")
85 anCircleCentr.setValue(0, 0)
86 aCircleRadius.setValue(20)
87 aSession.finishOperation()
88 #=========================================================================
89 # Make extrusion on circle
90 #=========================================================================
91 # Build shape from sketcher results
92 aCircleSketchResult = modelAPI_ResultConstruction(aCircleSketchFeature.firstResult())
93 assert (aCircleSketchResult.facesNum() > 0)
95 aSession.startOperation()
96 anExtrusionFt = aPart.addFeature("Extrusion")
97 assert (anExtrusionFt.getKind() == "Extrusion")
98 # selection type FACE=4
99 anExtrusionFt.selectionList("base").append(
100 aCircleSketchResult, aCircleSketchResult.face(0))
101 anExtrusionFt.string("CreationMethod").setValue("BySizes")
102 anExtrusionFt.real("to_size").setValue(50)
103 anExtrusionFt.real("from_size").setValue(0)
104 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
105 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
106 anExtrusionFt.execute()
107 aSession.finishOperation()
108 assert (anExtrusionFt.real("to_size").value() == 50.0)
110 # Check extrusion results
111 assert (len(anExtrusionFt.results()) > 0)
112 anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
113 assert (anExtrusionResult is not None)
115 #=========================================================================
116 # Create a sketch line to revol
117 #=========================================================================
118 aSession.startOperation()
119 aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
120 origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
121 origin.setValue(0, 0, 50)
122 dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
123 dirx.setValue(1, 0, 0)
124 norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
125 norm.setValue(0, 0, 1)
126 aLineSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/TopFace")
128 aSketchLine = aLineSketchFeature.addFeature("SketchLine")
129 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
130 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
131 aLineStartPoint.setValue(-20, -20)
132 aLineEndPoint.setValue(20, -20)
133 aSession.finishOperation()
135 # Build shape from sketcher results
136 aLineSketchResult = aLineSketchFeature.firstResult()
137 aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
138 aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
139 aLineEdge = aShapeExplorer.current()
141 #=========================================================================
142 # Make revolution fuse
143 #=========================================================================
144 aSession.startOperation()
145 anRevolutionFuseFt = featureToCompositeFeature(aPart.addFeature("RevolutionFuse"))
146 assert (anRevolutionFuseFt.getKind() == "RevolutionFuse")
147 # selection type FACE=4
148 aSession.startOperation()
149 aCircleSketchFeature = featureToCompositeFeature(anRevolutionFuseFt.addFeature("Sketch"))
150 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
151 origin.setValue(0, 0, 50)
152 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
153 dirx.setValue(1, 0, 0)
154 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
155 norm.setValue(0, 0, 1)
156 aCircleSketchFeature.selection("External").selectSubShape("face", "Extrusion_1/To_Face")
157 aSession.startOperation()
158 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
159 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
160 aCircleRadius = aSketchCircle.real("circle_radius")
161 anCircleCentr.setValue(0, 0)
162 aCircleRadius.setValue(10)
163 aSession.finishOperation()
164 aSession.finishOperation()
165 aSession.startOperation()
166 aCircleSketchFeature.execute() # execute for sketch should be called here, because it is not set as current feature, so it is disabled.
167 anRevolutionFuseFt.selectionList("base").append(aCircleSketchFeature.firstResult(), None)
168 anRevolutionFuseFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
169 anRevolutionFuseFt.string("CreationMethod").setValue("ByAngles")
170 anRevolutionFuseFt.real("to_angle").setValue(50)
171 anRevolutionFuseFt.real("from_angle").setValue(50)
172 anRevolutionFuseFt.real("to_offset").setValue(0) #TODO: remove
173 anRevolutionFuseFt.real("from_offset").setValue(0) #TODO: remove
174 anRevolutionFuseFt.selectionList("main_objects").append(anExtrusionResult, anExtrusionResult.shape())
175 aSession.finishOperation()
176 aSession.finishOperation()
178 #=========================================================================
180 #=========================================================================
181 aFactory = ModelAPI_Session.get().validators()
182 assert (aFactory.validate(anRevolutionFuseFt))
183 assert (len(anRevolutionFuseFt.results()) > 0)
184 aCurrentResult = modelAPI_ResultBody(anRevolutionFuseFt.firstResult())
185 assert (aCurrentResult is not None)
187 from salome.shaper import model
188 assert(model.checkPythonDump())