1 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # GEOM GEOM_SWIG : binding of C++ implementaion with Python
23 # File : GEOM_TestHealing.py
24 # Author : Julia DOROVSKIKH
28 def TestProcessShape (geompy):
30 ##Load shape from BREP file
32 #datadir = os.getenv("GEOM_TEST")
34 # datadir = datadir + "/Resources/"
36 # "Please, define GEOM_TEST variable !"
38 #print "Import ", datadir + "aze2.brep"
39 #Shape = batchmode_geompy.Import(datadir + "aze2.brep", "BREP")
41 p1 = geompy.MakeVertex(0,0,0)
42 p2 = geompy.MakeVertex(200,0,0)
43 p3 = geompy.MakeVertex(100,150,0)
45 edge = geompy.MakeEdge(p1,p2)
46 arc = geompy.MakeArc(p1,p3,p2)
47 wire = geompy.MakeWire([edge,arc])
48 face = geompy.MakeFace(wire, 1)
50 theShape = geompy.MakePrismVecH(face, edge, 130)
53 print "Before ProcessShape:"
54 isValid = geompy.CheckShape(theShape)
56 print "The shape is not valid"
58 print "The shape seems to be valid"
61 Operators = ["FixShape"]
62 Parameters = ["FixShape.Tolerance3d"]
65 PS = geompy.ProcessShape(theShape, Operators, Parameters, Values)
68 print "After ProcessShape:"
69 isValid = geompy.CheckShape(PS)
71 print "The shape is not valid"
72 raise RuntimeError, "It seems, that the ProcessShape() has failed"
74 print "The shape seems to be valid"
77 Id_Shape = geompy.addToStudy(theShape, "Invalid Shape")
78 Id_PS = geompy.addToStudy(PS, "Processed Shape")
80 def TestSuppressFaces (geompy):
82 #Create base geometry 3D
83 Box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
87 faces = geompy.SubShapeAllSorted(Box, geompy.ShapeType["FACE"])
89 f_glob_id = geompy.GetSubShapeID(Box, faces[5])
92 SuppFace = geompy.SuppressFaces(Box, [f_glob_id])
95 Id_SuppFace = geompy.addToStudy(SuppFace, "SuppFace")
97 def TestSuppressInternalWires (geompy):
99 #Create Face with hole
100 p11 = geompy.MakeVertex( 0, 0, 0)
101 p12 = geompy.MakeVertex(30, 0, 0)
102 p13 = geompy.MakeVertex(30, 30, 0)
103 p14 = geompy.MakeVertex( 0, 30, 0)
105 p21 = geompy.MakeVertex(10, 10, 0)
106 p22 = geompy.MakeVertex(20, 10, 0)
107 p23 = geompy.MakeVertex(20, 20, 0)
108 p24 = geompy.MakeVertex(10, 20, 0)
110 e11 = geompy.MakeEdge(p11, p12)
111 e12 = geompy.MakeEdge(p12, p13)
112 e13 = geompy.MakeEdge(p13, p14)
113 e14 = geompy.MakeEdge(p14, p11)
115 e21 = geompy.MakeEdge(p21, p22)
116 e22 = geompy.MakeEdge(p22, p23)
117 e23 = geompy.MakeEdge(p23, p24)
118 e24 = geompy.MakeEdge(p24, p21)
120 w1 = geompy.MakeWire([e11, e12, e13, e14])
121 w2 = geompy.MakeWire([e21, e22, e23, e24])
123 id_w1 = geompy.addToStudy(w1, "Outside Wire")
124 id_w2 = geompy.addToStudy(w2, "Inside Wire")
126 f12 = geompy.MakeFaceWires([w1, w2], 0)
127 id_f12 = geompy.addToStudy(f12, "Face WO + WI")
130 Res1 = geompy.GetFreeBoundary(f12)
132 ClosedWires1 = Res1[1]
136 for wire in ClosedWires1:
140 raise RuntimeError, "GetFreeBoundary(f12) must return 2 closed wires, but returned ", nbw1
142 #SuppressInternalWires
143 face = geompy.SuppressInternalWires(f12, [])
146 Res2 = geompy.GetFreeBoundary(face)
148 ClosedWires2 = Res2[1]
152 for wire in ClosedWires2:
156 print "GetFreeBoundary(face) must return 1 closed wires, but returned ", nbw2
157 raise RuntimeError, "SuppressInternalWires() works not correctly"
160 Id_face = geompy.addToStudy(face, "Face without internal wires")
162 def TestCloseContour (geompy):
164 ##Load shape from BREP file
166 #datadir = os.getenv("GEOM_TEST")
168 # datadir = datadir + "/Resources/"
170 # "Please, define GEOM_TEST variable !"
172 #print "Import ", datadir + "open_cont.brep"
173 #Shape = geompy.Import(datadir + "open_cont.brep", "BREP")
175 p0 = geompy.MakeVertex(0. , 0. , 0. )
176 py = geompy.MakeVertex(0. , 100., 0. )
177 pz = geompy.MakeVertex(0. , 0. , 100.)
178 p200 = geompy.MakeVertex(200., 200., 200.)
180 Shape = geompy.MakePolyline([p0, pz, py, p200])
183 print "Before closing contour:"
184 isValid = geompy.CheckShape(Shape)
186 print "The shape is not valid"
188 print "The shape seems to be valid"
191 IsCommonVertex = 0 # false
193 shape_wires = geompy.SubShapeAll(Shape, geompy.ShapeType["WIRE"])
197 for wire in shape_wires:
198 Wires.append(geompy.GetSubShapeID(Shape, shape_wires[wi]))
201 CC = geompy.CloseContour(Shape, Wires, IsCommonVertex)
204 print "After closing contour:"
205 isValid = geompy.CheckShape(CC)
207 print "The shape is not valid"
208 raise RuntimeError, "It seems, that the contour was not closed"
210 print "The shape seems to be valid"
213 Id_Shape = geompy.addToStudy(Shape, "Shape with open wire")
214 Id_CC = geompy.addToStudy(CC, "Shape with closed wire")
216 def TestSuppressHoles (geompy):
218 #Create base Variables
223 p1 = geompy.MakeVertex(100., 100., 50.)
225 #Create base directions
226 vz = geompy.MakeVectorDXDYDZ(0., 0., 100.)
228 #Create base geometry 3D
229 Box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
230 Cylinder = geompy.MakeCylinder(p1, vz, radius, height)
233 Cut = geompy.MakeBoolean(Box, Cylinder, 2)
234 idCut = geompy.addToStudy(Cut, "CUT")
236 #IDList for SuppressFaces
238 faces = geompy.SubShapeAllSorted(Cut, geompy.ShapeType["FACE"])
241 f_name = "FACE %d"%(ind)
242 f_id = geompy.addToStudyInFather(Cut, face, f_name)
244 f_glob_id = geompy.GetSubShapeID(Cut, face)
245 print "face ", ind, " global index = ", f_glob_id
248 f_glob_id_0 = geompy.GetSubShapeID(Cut, faces[0])
249 cut_without_f_0 = geompy.SuppressFaces(Cut, [f_glob_id_0])
252 faces1 = geompy.SubShapeAllSorted(cut_without_f_0, geompy.ShapeType["FACE"])
255 f_name = "FACE %d"%(ind)
256 f_id = geompy.addToStudyInFather(cut_without_f_0, face, f_name)
258 f_glob_id = geompy.GetSubShapeID(cut_without_f_0, face)
259 print "face ", ind, " global index = ", f_glob_id
262 f_glob_id_5 = geompy.GetSubShapeID(cut_without_f_0, faces1[5])
263 cut_without_f_0_5 = geompy.SuppressFaces(cut_without_f_0, [f_glob_id_5])
264 cut_without_f_0_5_id = geompy.addToStudy(cut_without_f_0_5, "Cut without faces 0 and 5")
268 wires = geompy.SubShapeAllSorted(cut_without_f_0_5, geompy.ShapeType["WIRE"])
271 w_name = "WIRE %d"%(ind)
272 w_id = geompy.addToStudyInFather(cut_without_f_0_5, wire, w_name)
274 w_glob_id = geompy.GetSubShapeID(cut_without_f_0_5, wire)
275 print "wire ", ind, " global index = ", w_glob_id
278 w_3 = geompy.GetSubShapeID(cut_without_f_0_5, wires[3])
280 SuppHole3 = geompy.SuppressHoles(cut_without_f_0_5, [w_3])
281 SuppHole3_id = geompy.addToStudy(SuppHole3, "Supp Hole 3")
283 def TestMakeSewing (geompy, math):
286 px = geompy.MakeVertex(100., 0., 0.)
287 py = geompy.MakeVertex(0., 100., 0.)
288 pz = geompy.MakeVertex(0., 0., 100.)
290 #Create base geometry 2D & 3D
291 Vector = geompy.MakeVector(px, py)
292 Arc = geompy.MakeArc(py, pz, px)
295 angle = 45. * math.pi / 180
296 WantPlanarFace = 1 #True
298 Wire = geompy.MakeWire([Vector, Arc])
299 Face = geompy.MakeFace(Wire, WantPlanarFace)
300 S = geompy.MakeRotation(Face, Vector, angle)
304 Sewing = geompy.MakeSewing([Face, S], precision)
307 id_Sewing = geompy.addToStudy(Sewing, "Sewing")
309 def TestDivideEdge (geompy):
312 Box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
315 box_edges = geompy.SubShapeAllSorted(Box, geompy.ShapeType["EDGE"])
316 edge_ind = geompy.GetSubShapeID(Box, box_edges[1])
318 Divide = geompy.DivideEdge(Box, edge_ind, 0.5, 1) # Obj, ind, param, is_curve_param
321 Id_Box = geompy.addToStudy(Box, "Box")
322 Id_Divide = geompy.addToStudy(Divide, "Box with Divided Edge")
324 def TestHealingOperations (geompy, math):
326 TestMakeSewing(geompy, math)
327 TestDivideEdge(geompy)
328 TestSuppressHoles(geompy)
329 TestSuppressInternalWires(geompy)
330 TestCloseContour(geompy)
331 TestSuppressFaces(geompy)
332 TestProcessShape(geompy)