Salome HOME
Useful commits from master and V8_5_0
[modules/shaper.git] / src / FeaturesPlugin / Test / TestPipe.py
1 ## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 # Initialization of the test
22 from ModelAPI import *
23 from GeomDataAPI import *
24 from GeomAlgoAPI import *
25 from GeomAPI import *
26
27 # Get document
28 aSession = ModelAPI_Session.get()
29 aDocument = aSession.moduleDocument()
30
31 # Create a part
32 aSession.startOperation()
33 aPartFeature = aDocument.addFeature("Part")
34 aSession.finishOperation()
35 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
36 aPart = aPartResult.partDoc()
37
38 # Create a sketch with circle for pipe profile
39 aSession.startOperation()
40 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
41 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
42 origin.setValue(0, 0, 0)
43 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
44 dirx.setValue(1, 0, 0)
45 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
46 norm.setValue(0, 0, 1)
47
48 # Create circle
49 aSketchCircleFeature = aSketchFeature.addFeature("SketchCircle")
50 anCircleCentr = geomDataAPI_Point2D(aSketchCircleFeature.attribute("circle_center"))
51 aCircleRadius = aSketchCircleFeature.real("circle_radius")
52 anCircleCentr.setValue(0, 0)
53 aCircleRadius.setValue(10)
54 aSession.finishOperation()
55 aSketchResult = aSketchFeature.firstResult()
56 aSketchShape = aSketchResult.shape()
57
58 # Create face
59 aSession.startOperation()
60 aFaceFeature = aPart.addFeature("Face")
61 aBaseObjectsList = aFaceFeature.selectionList("base_objects")
62 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
63 while aShapeExplorer.more():
64     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
65     aShapeExplorer.next()
66 aSession.finishOperation()
67 aFaceResult1 = aFaceFeature.firstResult()
68
69 # Create a sketch with edges for pipe path
70 aSession.startOperation()
71 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
72 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
73 origin.setValue(0, 0, 0)
74 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
75 dirx.setValue(1, 0, 0)
76 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
77 norm.setValue(0, -1, 0)
78
79 # Create line
80 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
81 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
82 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
83 aSketchLineStartPoint.setValue(0, 0)
84 aSketchLineEndPoint.setValue(0, 200)
85
86 # Create arc
87 aSketchArcFeature = aSketchFeature.addFeature("SketchArc")
88 aSketchArcCenterPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("center_point"))
89 aSketchArcStartPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("start_point"))
90 aSketchArcEndPoint = geomDataAPI_Point2D(aSketchArcFeature.attribute("end_point"))
91 aSketchArcCenterPoint.setValue(100, 200)
92 aSketchArcStartPoint.setValue(200, 200)
93 aSketchArcEndPoint.setValue(0, 200)
94
95 aSession.finishOperation()
96 aSketchResult = aSketchFeature.firstResult()
97 aSketchShape = aSketchResult.shape()
98
99 # Create wire
100 aSession.startOperation()
101 aWireFeature = aPart.addFeature("Wire")
102 aBaseObjectsList = aWireFeature.selectionList("base_objects")
103 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
104 while aShapeExplorer.more():
105     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
106     aShapeExplorer.next()
107 aSession.finishOperation()
108 aWireResult = aWireFeature.firstResult()
109
110 # Create simple pipe
111 aSession.startOperation()
112 aPipeFeature = aPart.addFeature("Pipe")
113 aBaseObjectsList = aPipeFeature.selectionList("base_objects")
114 aBaseObjectsList.append(aFaceResult1, None)
115 aPathObjectSelection = aPipeFeature.selection("path_object")
116 aPathObjectSelection.setValue(aWireResult, None)
117 aPipeFeature.string("creation_method").setValue("simple")
118 aSession.finishOperation()
119
120 # Test results
121 assert (len(aPipeFeature.results()) > 0)
122 # aSession.undo()
123
124 # Recover original face
125 aSession.startOperation()
126 aRecover = aPart.addFeature("Recover")
127 aBaseObject = aRecover.reference("base_feature")
128 aBaseObject.setValue(aPipeFeature)
129 aRecoveredObjects = aRecover.reflist("recovered")
130 aRecoveredObjects.append(aFaceResult1)
131 aSession.finishOperation()
132
133 # Create pipe with bi-normal
134 aSession.startOperation()
135 aPipeFeature = aPart.addFeature("Pipe")
136 aBaseObjectsList = aPipeFeature.selectionList("base_objects")
137 aBaseObjectsList.append(aRecover.firstResult(), None)
138 aPathObjectSelection = aPipeFeature.selection("path_object")
139 aPathObjectSelection.setValue(aWireResult, None)
140 aPipeFeature.string("creation_method").setValue("binormal")
141 aBinormalObjectSelection = aPipeFeature.selection("binormal")
142 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
143 aBinormalObjectSelection.setValue(aSketchResult, aShapeExplorer.current())
144 aSession.finishOperation()
145
146 # Test results
147 assert (len(aPipeFeature.results()) > 0)
148 # aSession.undo()
149
150 # Recover original face
151 aSession.startOperation()
152 aRecover2 = aPart.addFeature("Recover")
153 aBaseObject = aRecover2.reference("base_feature")
154 aBaseObject.setValue(aPipeFeature)
155 aRecoveredObjects = aRecover2.reflist("recovered")
156 aRecoveredObjects.append(aRecover.firstResult())
157 aSession.finishOperation()
158
159 # Create pipe with locations
160 # Create a sketch with circle for pipe profile
161 aSession.startOperation()
162 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
163 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
164 origin.setValue(0, 0, 200)
165 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
166 dirx.setValue(1, 0, 0)
167 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
168 norm.setValue(0, 0, 1)
169
170 # Create circle
171 aSketchCircleFeature = aSketchFeature.addFeature("SketchCircle")
172 anCircleCentr = geomDataAPI_Point2D(aSketchCircleFeature.attribute("circle_center"))
173 aCircleRadius = aSketchCircleFeature.real("circle_radius")
174 anCircleCentr.setValue(0, 0)
175 aCircleRadius.setValue(20)
176 aSession.finishOperation()
177 aSketchResult = aSketchFeature.firstResult()
178 aSketchShape = aSketchResult.shape()
179
180 # Create face
181 aSession.startOperation()
182 aFaceFeature = aPart.addFeature("Face")
183 aBaseObjectsList = aFaceFeature.selectionList("base_objects")
184 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
185 while aShapeExplorer.more():
186     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
187     aShapeExplorer.next()
188 aSession.finishOperation()
189 aFaceResult2 = aFaceFeature.firstResult()
190
191 aSession.startOperation()
192 aPipeFeature = aPart.addFeature("Pipe")
193 aBaseObjectsList = aPipeFeature.selectionList("base_objects")
194 aBaseObjectsList.append(aRecover2.firstResult(), None)
195 aBaseObjectsList.append(aFaceResult2, None)
196 aPathObjectSelection = aPipeFeature.selection("path_object")
197 aPathObjectSelection.setValue(aWireResult, None)
198 aPipeFeature.string("creation_method").setValue("locations")
199 aSession.finishOperation()
200
201 # Test results
202 assert (len(aPipeFeature.results()) > 0)
203
204 from salome.shaper import model
205 assert(model.checkPythonDump())