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