1 # GEOM GEOM_SWIG : binding of C++ implementaion with Python
3 # Copyright (C) 2003 CEA
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # File : GEOM_TestHealing.py
23 # Author : Julia DOROVSKIKH
27 def TestProcessShape (geompy):
29 ##Load shape from BREP file
31 #datadir = os.getenv("GEOM_TEST")
33 # datadir = datadir + "/Resources/"
35 # "Please, define GEOM_TEST variable !"
37 #print "Import ", datadir + "aze2.brep"
38 #Shape = batchmode_geompy.Import(datadir + "aze2.brep", "BREP")
40 p1 = geompy.MakeVertex(0,0,0)
41 p2 = geompy.MakeVertex(200,0,0)
42 p3 = geompy.MakeVertex(100,150,0)
44 edge = geompy.MakeEdge(p1,p2)
45 arc = geompy.MakeArc(p1,p3,p2)
46 wire = geompy.MakeWire([edge,arc])
47 face = geompy.MakeFace(wire, 1)
49 theShape = geompy.MakePrismVecH(face, edge, 130)
52 print "Before ProcessShape:"
53 isValid = geompy.CheckShape(theShape)
55 print "The shape is not valid"
57 print "The shape seems to be valid"
60 Operators = ["FixShape"]
61 Parameters = ["FixShape.Tolerance3d"]
64 PS = geompy.ProcessShape(theShape, Operators, Parameters, Values)
67 print "After ProcessShape:"
68 isValid = geompy.CheckShape(PS)
70 print "The shape is not valid"
71 raise RuntimeError, "It seems, that the ProcessShape() has failed"
73 print "The shape seems to be valid"
76 Id_Shape = geompy.addToStudy(theShape, "Invalid Shape")
77 Id_PS = geompy.addToStudy(PS, "Processed Shape")
79 def TestSuppressFaces (geompy):
81 #Create base geometry 3D
82 Box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
86 faces = geompy.SubShapeAllSorted(Box, geompy.ShapeType["FACE"])
88 f_glob_id = geompy.GetSubShapeID(Box, faces[5])
91 SuppFace = geompy.SuppressFaces(Box, [f_glob_id])
94 Id_SuppFace = geompy.addToStudy(SuppFace, "SuppFace")
96 def TestSuppressInternalWires (geompy):
98 #Create Face with hole
99 p11 = geompy.MakeVertex( 0, 0, 0)
100 p12 = geompy.MakeVertex(30, 0, 0)
101 p13 = geompy.MakeVertex(30, 30, 0)
102 p14 = geompy.MakeVertex( 0, 30, 0)
104 p21 = geompy.MakeVertex(10, 10, 0)
105 p22 = geompy.MakeVertex(20, 10, 0)
106 p23 = geompy.MakeVertex(20, 20, 0)
107 p24 = geompy.MakeVertex(10, 20, 0)
109 e11 = geompy.MakeEdge(p11, p12)
110 e12 = geompy.MakeEdge(p12, p13)
111 e13 = geompy.MakeEdge(p13, p14)
112 e14 = geompy.MakeEdge(p14, p11)
114 e21 = geompy.MakeEdge(p21, p22)
115 e22 = geompy.MakeEdge(p22, p23)
116 e23 = geompy.MakeEdge(p23, p24)
117 e24 = geompy.MakeEdge(p24, p21)
119 w1 = geompy.MakeWire([e11, e12, e13, e14])
120 w2 = geompy.MakeWire([e21, e22, e23, e24])
122 id_w1 = geompy.addToStudy(w1, "Outside Wire")
123 id_w2 = geompy.addToStudy(w2, "Inside Wire")
125 f12 = geompy.MakeFaceWires([w1, w2], 0)
126 id_f12 = geompy.addToStudy(f12, "Face WO + WI")
129 Res1 = geompy.GetFreeBoundary(f12)
131 ClosedWires1 = Res1[1]
135 for wire in ClosedWires1:
139 raise RuntimeError, "GetFreeBoundary(f12) must return 2 closed wires, but returned ", nbw1
141 #SuppressInternalWires
142 face = geompy.SuppressInternalWires(f12, [])
145 Res2 = geompy.GetFreeBoundary(face)
147 ClosedWires2 = Res2[1]
151 for wire in ClosedWires2:
155 print "GetFreeBoundary(face) must return 1 closed wires, but returned ", nbw2
156 raise RuntimeError, "SuppressInternalWires() works not correctly"
159 Id_face = geompy.addToStudy(face, "Face without internal wires")
161 def TestCloseContour (geompy):
163 ##Load shape from BREP file
165 #datadir = os.getenv("GEOM_TEST")
167 # datadir = datadir + "/Resources/"
169 # "Please, define GEOM_TEST variable !"
171 #print "Import ", datadir + "open_cont.brep"
172 #Shape = geompy.Import(datadir + "open_cont.brep", "BREP")
174 p0 = geompy.MakeVertex(0. , 0. , 0. )
175 py = geompy.MakeVertex(0. , 100., 0. )
176 pz = geompy.MakeVertex(0. , 0. , 100.)
177 p200 = geompy.MakeVertex(200., 200., 200.)
179 Shape = geompy.MakePolyline([p0, pz, py, p200])
182 print "Before closing contour:"
183 isValid = geompy.CheckShape(Shape)
185 print "The shape is not valid"
187 print "The shape seems to be valid"
190 IsCommonVertex = 0 # false
192 shape_wires = geompy.SubShapeAll(Shape, geompy.ShapeType["WIRE"])
196 for wire in shape_wires:
197 Wires.append(geompy.GetSubShapeID(Shape, shape_wires[wi]))
200 CC = geompy.CloseContour(Shape, Wires, IsCommonVertex)
203 print "After closing contour:"
204 isValid = geompy.CheckShape(CC)
206 print "The shape is not valid"
207 raise RuntimeError, "It seems, that the contour was not closed"
209 print "The shape seems to be valid"
212 Id_Shape = geompy.addToStudy(Shape, "Shape with open wire")
213 Id_CC = geompy.addToStudy(CC, "Shape with closed wire")
215 def TestSuppressHoles (geompy):
217 #Create base Variables
222 p1 = geompy.MakeVertex(100., 100., 50.)
224 #Create base directions
225 vz = geompy.MakeVectorDXDYDZ(0., 0., 100.)
227 #Create base geometry 3D
228 Box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
229 Cylinder = geompy.MakeCylinder(p1, vz, radius, height)
232 Cut = geompy.MakeBoolean(Box, Cylinder, 2)
233 idCut = geompy.addToStudy(Cut, "CUT")
235 #IDList for SuppressFaces
237 faces = geompy.SubShapeAllSorted(Cut, geompy.ShapeType["FACE"])
240 f_name = "FACE %d"%(ind)
241 f_id = geompy.addToStudyInFather(Cut, face, f_name)
243 f_glob_id = geompy.GetSubShapeID(Cut, face)
244 print "face ", ind, " global index = ", f_glob_id
247 f_glob_id_0 = geompy.GetSubShapeID(Cut, faces[0])
248 cut_without_f_0 = geompy.SuppressFaces(Cut, [f_glob_id_0])
251 faces1 = geompy.SubShapeAllSorted(cut_without_f_0, geompy.ShapeType["FACE"])
254 f_name = "FACE %d"%(ind)
255 f_id = geompy.addToStudyInFather(cut_without_f_0, face, f_name)
257 f_glob_id = geompy.GetSubShapeID(cut_without_f_0, face)
258 print "face ", ind, " global index = ", f_glob_id
261 f_glob_id_5 = geompy.GetSubShapeID(cut_without_f_0, faces1[5])
262 cut_without_f_0_5 = geompy.SuppressFaces(cut_without_f_0, [f_glob_id_5])
263 cut_without_f_0_5_id = geompy.addToStudy(cut_without_f_0_5, "Cut without faces 0 and 5")
267 wires = geompy.SubShapeAllSorted(cut_without_f_0_5, geompy.ShapeType["WIRE"])
270 w_name = "WIRE %d"%(ind)
271 w_id = geompy.addToStudyInFather(cut_without_f_0_5, wire, w_name)
273 w_glob_id = geompy.GetSubShapeID(cut_without_f_0_5, wire)
274 print "wire ", ind, " global index = ", w_glob_id
277 w_3 = geompy.GetSubShapeID(cut_without_f_0_5, wires[3])
279 SuppHole3 = geompy.SuppressHoles(cut_without_f_0_5, [w_3])
280 SuppHole3_id = geompy.addToStudy(SuppHole3, "Supp Hole 3")
282 def TestMakeSewing (geompy, math):
285 px = geompy.MakeVertex(100., 0., 0.)
286 py = geompy.MakeVertex(0., 100., 0.)
287 pz = geompy.MakeVertex(0., 0., 100.)
289 #Create base geometry 2D & 3D
290 Vector = geompy.MakeVector(px, py)
291 Arc = geompy.MakeArc(py, pz, px)
294 angle = 45. * math.pi / 180
295 WantPlanarFace = 1 #True
297 Wire = geompy.MakeWire([Vector, Arc])
298 Face = geompy.MakeFace(Wire, WantPlanarFace)
299 S = geompy.MakeRotation(Face, Vector, angle)
303 Sewing = geompy.MakeSewing([Face, S], precision)
306 id_Sewing = geompy.addToStudy(Sewing, "Sewing")
308 def TestDivideEdge (geompy):
311 Box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
314 box_edges = geompy.SubShapeAllSorted(Box, geompy.ShapeType["EDGE"])
315 edge_ind = geompy.GetSubShapeID(Box, box_edges[1])
317 Divide = geompy.DivideEdge(Box, edge_ind, 0.5, 1) # Obj, ind, param, is_curve_param
320 Id_Box = geompy.addToStudy(Box, "Box")
321 Id_Divide = geompy.addToStudy(Divide, "Box with Divided Edge")
323 def TestHealingOperations (geompy, math):
325 TestMakeSewing(geompy, math)
326 TestDivideEdge(geompy)
327 TestSuppressHoles(geompy)
328 TestSuppressInternalWires(geompy)
329 TestCloseContour(geompy)
330 TestSuppressFaces(geompy)
331 TestProcessShape(geompy)