1 #=========================================================================
2 # Initialization of the test
3 #=========================================================================
5 from GeomDataAPI import *
6 from GeomAlgoAPI import *
11 from salome.shaper import model
13 aSession = ModelAPI_Session.get()
14 aDocument = aSession.moduleDocument()
17 aSession.startOperation()
18 aPartFeature = aDocument.addFeature("Part")
19 aSession.finishOperation()
20 assert (len(aPartFeature.results()) == 1)
21 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
22 aPart = aPartResult.partDoc()
24 #=========================================================================
25 # Create a first point
26 #=========================================================================
27 aSession.startOperation()
28 aPointFeature = aPart.addFeature("Point")
29 aPointFeatureData = aPointFeature.data()
30 assert(aPointFeatureData is not None)
31 # aPointFeatureData.string("creation_method").setValue("by_xyz")
32 aPointFeatureData.real("x").setValue(0.)
33 aPointFeatureData.real("y").setValue(0.)
34 aPointFeatureData.real("z").setValue(0.)
35 aPointFeature.execute()
36 aSession.finishOperation()
37 aPoint1Result = aPointFeature.firstResult();
39 #=========================================================================
40 # Create a second point
41 #=========================================================================
42 aSession.startOperation()
43 aPointFeature = aPart.addFeature("Point")
44 aPointFeatureData = aPointFeature.data()
45 assert(aPointFeatureData is not None)
46 # aPointFeatureData.string("creation_method").setValue("by_xyz")
47 aPointFeatureData.real("x").setValue(0.)
48 aPointFeatureData.real("y").setValue(0.)
49 aPointFeatureData.real("z").setValue(100.)
50 aPointFeature.execute()
51 aSession.finishOperation()
52 aPoint2Result = aPointFeature.firstResult();
54 #=========================================================================
55 # Create axis by two points
56 #=========================================================================
57 aSession.startOperation()
58 anAxisFeature = aPart.addFeature("Axis")
59 anAxisFeatureData = anAxisFeature.data()
60 assert(anAxisFeatureData is not None)
61 anAxisFeatureData.string("CreationMethod").setValue("AxisByPointsCase")
62 anAxisFeatureData.selection("FirstPoint").setValue(aPoint1Result, aPoint1Result.shape())
63 anAxisFeatureData.selection("SecondPoint").setValue(aPoint2Result, aPoint2Result.shape())
64 anAxisFeature.execute()
65 aSession.finishOperation()
67 assert (len(anAxisFeature.results()) > 0)
68 anAxisResult = modelAPI_ResultConstruction(anAxisFeature.firstResult())
69 assert (anAxisResult is not None)
71 #=========================================================================
72 # Create a sketch circle to extrude
73 #=========================================================================
74 aSession.startOperation()
75 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
76 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
77 origin.setValue(0, 0, 0)
78 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
79 dirx.setValue(1, 0, 0)
80 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
81 norm.setValue(0, 0, 1)
83 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
84 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
85 aCircleRadius = aSketchCircle.real("CircleRadius")
86 anCircleCentr.setValue(0, 0)
87 aCircleRadius.setValue(50)
88 aSession.finishOperation()
90 #=========================================================================
91 # Make extrusion on circle
92 #=========================================================================
93 # Build shape from sketcher results
94 aCircleSketchResult = aCircleSketchFeature.firstResult()
95 aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape()
96 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt()
97 dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir()
98 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir()
99 aCircleSketchFaces = ShapeList()
100 GeomAlgoAPI_SketchBuilder.createFaces(origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces)
101 assert (len(aCircleSketchFaces) > 0)
102 assert (aCircleSketchFaces[0] is not None)
105 aSession.startOperation()
106 anExtrusionFt = aPart.addFeature("Extrusion")
107 assert (anExtrusionFt.getKind() == "Extrusion")
108 # selection type FACE=4
109 anExtrusionFt.selectionList("base").append(aCircleSketchResult, aCircleSketchFaces[0])
110 anExtrusionFt.string("CreationMethod").setValue("BySizes")
111 anExtrusionFt.real("to_size").setValue(100)
112 anExtrusionFt.real("from_size").setValue(0)
113 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
114 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
115 anExtrusionFt.execute()
116 aSession.finishOperation()
117 assert (anExtrusionFt.real("to_size").value() == 100.0)
119 # Check extrusion results
120 assert (len(anExtrusionFt.results()) > 0)
121 anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
122 assert (anExtrusionResult is not None)
124 #=========================================================================
125 # Create axis by cylinder
126 #=========================================================================
127 aSession.startOperation()
128 anAxisFeature = aPart.addFeature("Axis")
129 anAxisFeatureData = anAxisFeature.data()
130 assert(anAxisFeatureData is not None)
131 anAxisFeatureData.string("CreationMethod").setValue("AxisByCylindricalFaceCase")
132 anAxisFeatureData.selection("CylindricalFace").selectSubShape("face", "Extrusion_1_1/Generated_Face_1")
133 anAxisFeature.execute()
134 aSession.finishOperation()
136 assert (len(anAxisFeature.results()) > 0)
137 anAxisResult = modelAPI_ResultConstruction(anAxisFeature.firstResult())
138 assert (anAxisResult is not None)
140 # Create a sketch with line
141 aSession.startOperation()
142 anOrigin = GeomAPI_Pnt(0, 0, 0)
143 aDirX = GeomAPI_Dir(1, 0, 0)
144 aNorm = GeomAPI_Dir(0, 0, 1)
145 aSketch = model.addSketch(aPart, GeomAPI_Ax3(anOrigin, aDirX, aNorm))
146 aSketchLine = aSketch.addLine(0, 0, 100, 100)
147 aSession.finishOperation()
149 # Test an axis by line
150 aSession.startOperation()
151 anAxis = model.addAxis(aPart, aSketchLine.result())
152 aSession.finishOperation()
153 assert (len(anAxis.results()) > 0)
156 aSession.startOperation()
157 aPlane1 = model.addPlane(aPart, 1, 1, 1, 0)
158 aSession.finishOperation()
160 # Create a sketch with point
161 aSession.startOperation()
162 anOrigin = GeomAPI_Pnt(0, 0, 0)
163 aDirX = GeomAPI_Dir(1, 0, 0)
164 aNorm = GeomAPI_Dir(0, 0, 1)
165 aSketch = model.addSketch(aPart, GeomAPI_Ax3(anOrigin, aDirX, aNorm))
166 aSketchPoint = aSketch.addPoint(50, 50)
167 aSession.finishOperation()
169 # Test an axis by plane and point
170 aSession.startOperation()
171 anAxis = model.addAxis(aPart, aPlane1.result(), aSketchPoint.result())
172 aSession.finishOperation()
173 assert (len(anAxis.results()) > 0)
176 aSession.startOperation()
177 aPlane2 = model.addPlane(aPart, 0, 1, 1, 0)
178 aSession.finishOperation()
180 # Test an axis by two planes
181 aSession.startOperation()
182 anAxis = model.addAxis(aPart, aPlane1.result(), aPlane2.result())
183 aSession.finishOperation()
184 assert (len(anAxis.results()) > 0)
186 # Test an axis by two planes and offsets
187 aSession.startOperation()
188 anAxis = model.addAxis(aPart, aPlane1.result(), 50, False, aPlane2.result(), 100, True)
189 aSession.finishOperation()
190 assert (len(anAxis.results()) > 0)
192 assert(model.checkPythonDump())