Salome HOME
Issue #803: Put all the python modules in the same python package newgeom
[modules/shaper.git] / src / FeaturesPlugin / Test / TestPipe.py
1 # Initialization of the test
2 from ModelAPI import *
3 from GeomDataAPI import *
4 from GeomAlgoAPI import *
5 from GeomAPI import *
6
7 # Get document
8 aSession = ModelAPI_Session.get()
9 aDocument = aSession.moduleDocument()
10
11 # Create a part
12 aSession.startOperation()
13 aPartFeature = aDocument.addFeature("Part")
14 aSession.finishOperation()
15 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
16 aPart = aPartResult.partDoc()
17
18 # Create a sketch with circle for pipe profile
19 aSession.startOperation()
20 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
21 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
22 origin.setValue(0, 0, 0)
23 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
24 dirx.setValue(1, 0, 0)
25 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
26 norm.setValue(0, 0, 1)
27
28 # Create circle
29 aSketchCircleFeature = aSketchFeature.addFeature("SketchCircle")
30 anCircleCentr = geomDataAPI_Point2D(aSketchCircleFeature.attribute("CircleCenter"))
31 aCircleRadius = aSketchCircleFeature.real("CircleRadius")
32 anCircleCentr.setValue(0, 0)
33 aCircleRadius.setValue(10)
34 aSession.finishOperation()
35 aSketchResult = aSketchFeature.firstResult()
36 aSketchShape = aSketchResult.shape()
37
38 # Create face
39 aSession.startOperation()
40 aFaceFeature = aPart.addFeature("Face")
41 aBaseObjectsList = aFaceFeature.selectionList("base_objects")
42 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
43 while aShapeExplorer.more():
44     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
45     aShapeExplorer.next()
46 aSession.finishOperation()
47 aFaceResult1 = aFaceFeature.firstResult()
48
49 # Create a sketch with edges for pipe path
50 aSession.startOperation()
51 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
52 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
53 origin.setValue(0, 0, 0)
54 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
55 dirx.setValue(1, 0, 0)
56 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
57 norm.setValue(0, -1, 0)
58
59 # Create line
60 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
61 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
62 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
63 aSketchLineStartPoint.setValue(0, 0)
64 aSketchLineEndPoint.setValue(0, 200)
65
66 # Create arc
67 aSketchArcFeature = aSketchFeature.addFeature("SketchArc")
68 aSketchArcFeature.string("ArcType").setValue("CenterStartEnd")
69 aSketchArcCenterPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("ArcCenter"))
70 aSketchArcStartPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("ArcStartPoint"))
71 aSketchArcEndPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("ArcEndPoint"))
72 aSketchArcCenterPoint.setValue(100, 200)
73 aSketchArcStartPoint.setValue(200, 200)
74 aSketchArcEndPoint.setValue(0, 200)
75
76 aSession.finishOperation()
77 aSketchResult = aSketchFeature.firstResult()
78 aSketchShape = aSketchResult.shape()
79
80 # Create wire
81 aSession.startOperation()
82 aWireFeature = aPart.addFeature("Wire")
83 aBaseObjectsList = aWireFeature.selectionList("base_objects")
84 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
85 while aShapeExplorer.more():
86     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
87     aShapeExplorer.next()
88 aSession.finishOperation()
89 aWireResult = aWireFeature.firstResult()
90
91 # Create simple pipe
92 aSession.startOperation()
93 aPipeFeature = aPart.addFeature("Pipe")
94 aBaseObjectsList = aPipeFeature.selectionList("base_objects")
95 aBaseObjectsList.append(aFaceResult1, None)
96 aPathObjectSelection = aPipeFeature.selection("path_object")
97 aPathObjectSelection.setValue(aWireResult, None)
98 aPipeFeature.string("creation_method").setValue("simple")
99 aSession.finishOperation()
100
101 # Test results
102 assert (len(aPipeFeature.results()) > 0)
103 # aSession.undo()
104
105 # Create pipe with bi-normal
106 aSession.startOperation()
107 aPipeFeature = aPart.addFeature("Pipe")
108 aBaseObjectsList = aPipeFeature.selectionList("base_objects")
109 aBaseObjectsList.append(aFaceResult1, None)
110 aPathObjectSelection = aPipeFeature.selection("path_object")
111 aPathObjectSelection.setValue(aWireResult, None)
112 aPipeFeature.string("creation_method").setValue("binormal")
113 aBinormalObjectSelection = aPipeFeature.selection("binormal")
114 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
115 aBinormalObjectSelection.setValue(aSketchResult, aShapeExplorer.current())
116 aSession.finishOperation()
117
118 # Test results
119 assert (len(aPipeFeature.results()) > 0)
120 # aSession.undo()
121
122 # Create pipe with locations
123 # Create a sketch with circle for pipe profile
124 aSession.startOperation()
125 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
126 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
127 origin.setValue(0, 0, 200)
128 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
129 dirx.setValue(1, 0, 0)
130 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
131 norm.setValue(0, 0, 1)
132
133 # Create circle
134 aSketchCircleFeature = aSketchFeature.addFeature("SketchCircle")
135 anCircleCentr = geomDataAPI_Point2D(aSketchCircleFeature.attribute("CircleCenter"))
136 aCircleRadius = aSketchCircleFeature.real("CircleRadius")
137 anCircleCentr.setValue(0, 0)
138 aCircleRadius.setValue(20)
139 aSession.finishOperation()
140 aSketchResult = aSketchFeature.firstResult()
141 aSketchShape = aSketchResult.shape()
142
143 # Create face
144 aSession.startOperation()
145 aFaceFeature = aPart.addFeature("Face")
146 aBaseObjectsList = aFaceFeature.selectionList("base_objects")
147 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
148 while aShapeExplorer.more():
149     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
150     aShapeExplorer.next()
151 aSession.finishOperation()
152 aFaceResult2 = aFaceFeature.firstResult()
153
154 aSession.startOperation()
155 aPipeFeature = aPart.addFeature("Pipe")
156 aBaseObjectsList = aPipeFeature.selectionList("base_objects")
157 aBaseObjectsList.append(aFaceResult1, None)
158 aBaseObjectsList.append(aFaceResult2, None)
159 aPathObjectSelection = aPipeFeature.selection("path_object")
160 aPathObjectSelection.setValue(aWireResult, None)
161 aPipeFeature.string("creation_method").setValue("locations")
162 aSession.finishOperation()
163
164 # Test results
165 assert (len(aPipeFeature.results()) > 0)
166
167 from salome.shaper import model
168 assert(model.checkPythonDump())