1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # GEOM GEOM_SWIG : binding of C++ implementaion with Python
25 # File : GEOM_TestHealing.py
26 # Author : Julia DOROVSKIKH
30 def TestProcessShape (geompy):
32 ##Load shape from BREP file
34 #datadir = os.getenv("GEOM_TEST")
36 # datadir = datadir + "/Resources/"
38 # "Please, define GEOM_TEST variable !"
40 #print "Import ", datadir + "aze2.brep"
41 #Shape = batchmode_geompy.Import(datadir + "aze2.brep", "BREP")
43 p1 = geompy.MakeVertex(0,0,0)
44 p2 = geompy.MakeVertex(200,0,0)
45 p3 = geompy.MakeVertex(100,150,0)
47 edge = geompy.MakeEdge(p1,p2)
48 arc = geompy.MakeArc(p1,p3,p2)
49 wire = geompy.MakeWire([edge,arc])
50 face = geompy.MakeFace(wire, 1)
52 theShape = geompy.MakePrismVecH(face, edge, 130)
55 print "Before ProcessShape:"
56 isValid = geompy.CheckShape(theShape)
58 print "The shape is not valid"
60 print "The shape seems to be valid"
63 Operators = ["FixShape"]
64 Parameters = ["FixShape.Tolerance3d"]
67 PS = geompy.ProcessShape(theShape, Operators, Parameters, Values)
70 print "After ProcessShape:"
71 isValid = geompy.CheckShape(PS)
73 print "The shape is not valid"
74 raise RuntimeError, "It seems, that the ProcessShape() has failed"
76 print "The shape seems to be valid"
79 Id_Shape = geompy.addToStudy(theShape, "Invalid Shape")
80 Id_PS = geompy.addToStudy(PS, "Processed Shape")
82 def TestSuppressFaces (geompy):
84 #Create base geometry 3D
85 Box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
89 faces = geompy.SubShapeAllSortedCentres(Box, geompy.ShapeType["FACE"])
91 f_glob_id = geompy.GetSubShapeID(Box, faces[5])
94 SuppFace = geompy.SuppressFaces(Box, [f_glob_id])
97 Id_SuppFace = geompy.addToStudy(SuppFace, "SuppFace")
99 def TestSuppressInternalWires (geompy):
101 #Create Face with hole
102 p11 = geompy.MakeVertex( 0, 0, 0)
103 p12 = geompy.MakeVertex(30, 0, 0)
104 p13 = geompy.MakeVertex(30, 30, 0)
105 p14 = geompy.MakeVertex( 0, 30, 0)
107 p21 = geompy.MakeVertex(10, 10, 0)
108 p22 = geompy.MakeVertex(20, 10, 0)
109 p23 = geompy.MakeVertex(20, 20, 0)
110 p24 = geompy.MakeVertex(10, 20, 0)
112 e11 = geompy.MakeEdge(p11, p12)
113 e12 = geompy.MakeEdge(p12, p13)
114 e13 = geompy.MakeEdge(p13, p14)
115 e14 = geompy.MakeEdge(p14, p11)
117 e21 = geompy.MakeEdge(p21, p22)
118 e22 = geompy.MakeEdge(p22, p23)
119 e23 = geompy.MakeEdge(p23, p24)
120 e24 = geompy.MakeEdge(p24, p21)
122 w1 = geompy.MakeWire([e11, e12, e13, e14])
123 w2 = geompy.MakeWire([e21, e22, e23, e24])
125 id_w1 = geompy.addToStudy(w1, "Outside Wire")
126 id_w2 = geompy.addToStudy(w2, "Inside Wire")
128 f12 = geompy.MakeFaceWires([w1, w2], 0)
129 id_f12 = geompy.addToStudy(f12, "Face WO + WI")
132 Res1 = geompy.GetFreeBoundary(f12)
134 ClosedWires1 = Res1[1]
138 for wire in ClosedWires1:
142 raise RuntimeError, "GetFreeBoundary(f12) must return 2 closed wires, but returned ", nbw1
144 #SuppressInternalWires
145 face = geompy.SuppressInternalWires(f12, [])
148 Res2 = geompy.GetFreeBoundary(face)
150 ClosedWires2 = Res2[1]
154 for wire in ClosedWires2:
158 print "GetFreeBoundary(face) must return 1 closed wires, but returned ", nbw2
159 raise RuntimeError, "SuppressInternalWires() works not correctly"
162 Id_face = geompy.addToStudy(face, "Face without internal wires")
164 def TestCloseContour (geompy):
166 ##Load shape from BREP file
168 #datadir = os.getenv("GEOM_TEST")
170 # datadir = datadir + "/Resources/"
172 # "Please, define GEOM_TEST variable !"
174 #print "Import ", datadir + "open_cont.brep"
175 #Shape = geompy.Import(datadir + "open_cont.brep", "BREP")
177 p0 = geompy.MakeVertex(0. , 0. , 0. )
178 py = geompy.MakeVertex(0. , 100., 0. )
179 pz = geompy.MakeVertex(0. , 0. , 100.)
180 p200 = geompy.MakeVertex(200., 200., 200.)
182 Shape = geompy.MakePolyline([p0, pz, py, p200])
185 print "Before closing contour:"
186 isValid = geompy.CheckShape(Shape)
188 print "The shape is not valid"
190 print "The shape seems to be valid"
193 IsCommonVertex = 0 # false
195 shape_wires = geompy.SubShapeAll(Shape, geompy.ShapeType["WIRE"])
199 for wire in shape_wires:
200 Wires.append(geompy.GetSubShapeID(Shape, shape_wires[wi]))
203 CC = geompy.CloseContour(Shape, Wires, IsCommonVertex)
206 print "After closing contour:"
207 isValid = geompy.CheckShape(CC)
209 print "The shape is not valid"
210 raise RuntimeError, "It seems, that the contour was not closed"
212 print "The shape seems to be valid"
215 Id_Shape = geompy.addToStudy(Shape, "Shape with open wire")
216 Id_CC = geompy.addToStudy(CC, "Shape with closed wire")
218 def TestSuppressHoles (geompy):
220 #Create base Variables
225 p1 = geompy.MakeVertex(100., 100., 50.)
227 #Create base directions
228 vz = geompy.MakeVectorDXDYDZ(0., 0., 100.)
230 #Create base geometry 3D
231 Box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
232 Cylinder = geompy.MakeCylinder(p1, vz, radius, height)
235 Cut = geompy.MakeBoolean(Box, Cylinder, 2)
236 idCut = geompy.addToStudy(Cut, "CUT")
238 #IDList for SuppressFaces
240 faces = geompy.SubShapeAllSortedCentres(Cut, geompy.ShapeType["FACE"])
243 f_name = "FACE %d"%(ind)
244 f_id = geompy.addToStudyInFather(Cut, face, f_name)
246 f_glob_id = geompy.GetSubShapeID(Cut, face)
247 print "face ", ind, " global index = ", f_glob_id
250 f_glob_id_0 = geompy.GetSubShapeID(Cut, faces[0])
251 cut_without_f_0 = geompy.SuppressFaces(Cut, [f_glob_id_0])
252 geompy.addToStudy(cut_without_f_0, "Cut without face 0")
255 faces1 = geompy.SubShapeAllSortedCentres(cut_without_f_0, geompy.ShapeType["FACE"])
258 f_name = "FACE %d"%(ind)
259 f_id = geompy.addToStudyInFather(cut_without_f_0, face, f_name)
261 f_glob_id = geompy.GetSubShapeID(cut_without_f_0, face)
262 print "face ", ind, " global index = ", f_glob_id
265 f_glob_id_3 = geompy.GetSubShapeID(cut_without_f_0, faces1[3])
266 cut_without_f_0_3 = geompy.SuppressFaces(cut_without_f_0, [f_glob_id_3])
267 cut_without_f_0_3_id = geompy.addToStudy(cut_without_f_0_3, "Cut without faces 0 and 3")
271 wires = geompy.SubShapeAllSortedCentres(cut_without_f_0_3, geompy.ShapeType["WIRE"])
274 w_name = "WIRE %d"%(ind)
275 w_id = geompy.addToStudyInFather(cut_without_f_0_3, wire, w_name)
277 w_glob_id = geompy.GetSubShapeID(cut_without_f_0_3, wire)
278 print "wire ", ind, " global index = ", w_glob_id
281 w_3 = geompy.GetSubShapeID(cut_without_f_0_3, wires[3])
283 SuppHole3 = geompy.SuppressHoles(cut_without_f_0_3, [w_3])
284 SuppHole3_id = geompy.addToStudy(SuppHole3, "Supp Hole 3")
286 def TestMakeSewing (geompy, math):
289 px = geompy.MakeVertex(100., 0., 0.)
290 py = geompy.MakeVertex(0., 100., 0.)
291 pz = geompy.MakeVertex(0., 0., 100.)
293 #Create base geometry 2D & 3D
294 Vector = geompy.MakeVector(px, py)
295 Arc = geompy.MakeArc(py, pz, px)
298 angle = 45. * math.pi / 180
299 WantPlanarFace = 1 #True
301 Wire = geompy.MakeWire([Vector, Arc])
302 Face = geompy.MakeFace(Wire, WantPlanarFace)
303 S = geompy.MakeRotation(Face, Vector, angle)
307 Sewing = geompy.MakeSewing([Face, S], precision)
310 id_Sewing = geompy.addToStudy(Sewing, "Sewing")
312 def TestDivideEdge (geompy):
315 Box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
318 box_edges = geompy.SubShapeAllSortedCentres(Box, geompy.ShapeType["EDGE"])
319 edge_ind = geompy.GetSubShapeID(Box, box_edges[1])
321 Divide = geompy.DivideEdge(Box, edge_ind, 0.5, 1) # Obj, ind, param, is_curve_param
324 Id_Box = geompy.addToStudy(Box, "Box")
325 Id_Divide = geompy.addToStudy(Divide, "Box with Divided Edge")
327 def TestHealingOperations (geompy, math):
329 TestMakeSewing(geompy, math)
330 TestDivideEdge(geompy)
331 TestSuppressHoles(geompy)
332 TestSuppressInternalWires(geompy)
333 TestCloseContour(geompy)
334 TestSuppressFaces(geompy)
335 TestProcessShape(geompy)