1 # Copyright (C) 2014-2021 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
20 #=========================================================================
21 # Initialization of the test
22 #=========================================================================
23 from ModelAPI import *
24 from GeomDataAPI import *
25 from GeomAlgoAPI import *
28 from ModelAPI import *
30 from salome.shaper import model
32 aSession = ModelAPI_Session.get()
33 aDocument = aSession.moduleDocument()
36 aSession.startOperation()
37 aPartFeature = aDocument.addFeature("Part")
38 aSession.finishOperation()
39 assert (len(aPartFeature.results()) == 1)
40 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
41 aPart = aPartResult.partDoc()
43 #=========================================================================
44 # Create a first point
45 #=========================================================================
46 aSession.startOperation()
47 aPointFeature = aPart.addFeature("Point")
48 aPointFeatureData = aPointFeature.data()
49 assert(aPointFeatureData is not None)
50 geomDataAPI_Point(aPointFeatureData.attribute("point3d")).setValue(0., 0., 0.)
51 aPointFeatureData.string("creation_method").setValue("by_xyz")
52 aPointFeature.execute()
53 aSession.finishOperation()
54 aPoint1Result = aPointFeature.firstResult();
56 #=========================================================================
57 # Create a second point
58 #=========================================================================
59 aSession.startOperation()
60 aPointFeature = aPart.addFeature("Point")
61 aPointFeatureData = aPointFeature.data()
62 assert(aPointFeatureData is not None)
63 geomDataAPI_Point(aPointFeatureData.attribute("point3d")).setValue(0., 0., 100.)
64 aPointFeatureData.string("creation_method").setValue("by_xyz")
65 aPointFeature.execute()
66 aSession.finishOperation()
67 aPoint2Result = aPointFeature.firstResult();
69 #=========================================================================
70 # Create axis by two points
71 #=========================================================================
72 aSession.startOperation()
73 anAxisFeature = aPart.addFeature("Axis")
74 anAxisFeatureData = anAxisFeature.data()
75 assert(anAxisFeatureData is not None)
76 anAxisFeatureData.string("CreationMethod").setValue("AxisByPointsCase")
77 anAxisFeatureData.selection("FirstPoint").setValue(aPoint1Result, aPoint1Result.shape())
78 anAxisFeatureData.selection("SecondPoint").setValue(aPoint2Result, aPoint2Result.shape())
79 anAxisFeature.execute()
80 aSession.finishOperation()
82 assert (len(anAxisFeature.results()) > 0)
83 anAxisResult = modelAPI_ResultConstruction(anAxisFeature.firstResult())
84 assert (anAxisResult is not None)
86 #=========================================================================
87 # Create a sketch circle to extrude
88 #=========================================================================
89 aSession.startOperation()
90 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
91 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
92 origin.setValue(0, 0, 0)
93 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
94 dirx.setValue(1, 0, 0)
95 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
96 norm.setValue(0, 0, 1)
98 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
99 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
100 aCircleRadius = aSketchCircle.real("circle_radius")
101 anCircleCentr.setValue(0, 0)
102 aCircleRadius.setValue(50)
103 aSession.finishOperation()
105 #=========================================================================
106 # Make extrusion on circle
107 #=========================================================================
108 # Build shape from sketcher results
109 aCircleSketchResult = modelAPI_ResultConstruction(aCircleSketchFeature.firstResult())
110 assert (aCircleSketchResult.facesNum() > 0)
113 aSession.startOperation()
114 anExtrusionFt = aPart.addFeature("Extrusion")
115 assert (anExtrusionFt.getKind() == "Extrusion")
116 # selection type FACE=4
117 anExtrusionFt.selectionList("base").append(aCircleSketchResult, aCircleSketchResult.face(0))
118 anExtrusionFt.string("CreationMethod").setValue("BySizes")
119 anExtrusionFt.real("to_size").setValue(100)
120 anExtrusionFt.real("from_size").setValue(0)
121 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
122 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
123 anExtrusionFt.execute()
124 aSession.finishOperation()
125 assert (anExtrusionFt.real("to_size").value() == 100.0)
127 # Check extrusion results
128 assert (len(anExtrusionFt.results()) > 0)
129 anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
130 assert (anExtrusionResult is not None)
132 #=========================================================================
133 # Create axis by cylinder
134 #=========================================================================
135 aSession.startOperation()
136 anAxisFeature = aPart.addFeature("Axis")
137 anAxisFeatureData = anAxisFeature.data()
138 assert(anAxisFeatureData is not None)
139 anAxisFeatureData.string("CreationMethod").setValue("AxisByCylindricalFaceCase")
140 anAxisFeatureData.selection("CylindricalFace").selectSubShape("face", "Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2")
141 anAxisFeature.execute()
142 aSession.finishOperation()
144 assert (len(anAxisFeature.results()) > 0)
145 anAxisResult = modelAPI_ResultConstruction(anAxisFeature.firstResult())
146 assert (anAxisResult is not None)
148 # Create a sketch with line
149 aSession.startOperation()
150 anOrigin = GeomAPI_Pnt(0, 0, 0)
151 aDirX = GeomAPI_Dir(1, 0, 0)
152 aNorm = GeomAPI_Dir(0, 0, 1)
153 aSketch = model.addSketch(aPart, GeomAPI_Ax3(anOrigin, aDirX, aNorm))
154 aSketchLine = aSketch.addLine(0, 0, 100, 100)
155 aSession.finishOperation()
157 # Test an axis by line
158 aSession.startOperation()
159 anAxis = model.addAxis(aPart, aSketchLine.result())
160 aSession.finishOperation()
161 assert (len(anAxis.results()) > 0)
164 aSession.startOperation()
165 aPlane1 = model.addPlane(aPart, 1, 1, 1, 0)
166 aSession.finishOperation()
168 # Create a sketch with point
169 aSession.startOperation()
170 anOrigin = GeomAPI_Pnt(0, 0, 0)
171 aDirX = GeomAPI_Dir(1, 0, 0)
172 aNorm = GeomAPI_Dir(0, 0, 1)
173 aSketch = model.addSketch(aPart, GeomAPI_Ax3(anOrigin, aDirX, aNorm))
174 aSketchPoint = aSketch.addPoint(50, 50)
175 aSession.finishOperation()
177 # Test an axis by plane and point
178 aSession.startOperation()
179 anAxis = model.addAxis(aPart, aPlane1.result(), aSketchPoint.result())
180 aSession.finishOperation()
181 assert (len(anAxis.results()) > 0)
184 aSession.startOperation()
185 aPlane2 = model.addPlane(aPart, 0, 1, 1, 0)
186 aSession.finishOperation()
188 # Test an axis by two planes
189 aSession.startOperation()
190 anAxis = model.addAxis(aPart, aPlane1.result(), aPlane2.result())
191 aSession.finishOperation()
192 assert (len(anAxis.results()) > 0)
194 # Test an axis by two planes and offsets
195 aSession.startOperation()
196 anAxis = model.addAxis(aPart, aPlane1.result(), 50, False, aPlane2.result(), 100, True)
197 aSession.finishOperation()
198 assert (len(anAxis.results()) > 0)
200 assert(model.checkPythonDump())