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.org
22 # File : GEOM_TestOthers.py
23 # Author : Julia DOROVSKIKH
29 def TestExportImport (geompy, shape):
31 print "Test Export/Import ...",
33 # Files for Export/Import testing
34 fileExportImport = "/tmp/testExportImport.brep"
35 fileExportImportBREP = "/tmp/testExportImportBREP.brep"
36 fileExportImportIGES = "/tmp/testExportImportIGES.iges"
37 fileExportImportSTEP = "/tmp/testExportImportSTEP.step"
39 if os.access(fileExportImport, os.F_OK):
40 if os.access(fileExportImport, os.W_OK):
41 os.remove(fileExportImport)
43 fileExportImport = "/tmp/testExportImport1.brep"
45 if os.access(fileExportImportBREP, os.W_OK):
46 os.remove(fileExportImportBREP)
48 fileExportImportBREP = "/tmp/testExportImportBREP1.brep"
50 if os.access(fileExportImportIGES, os.W_OK):
51 os.remove(fileExportImportIGES)
53 fileExportImportIGES = "/tmp/testExportImportIGES1.iges"
55 if os.access(fileExportImportSTEP, os.W_OK):
56 os.remove(fileExportImportSTEP)
58 fileExportImportSTEP = "/tmp/testExportImportSTEP1.step"
61 geompy.Export(shape, fileExportImport, "BREP")
63 # ExportBREP, ExportIGES, ExportSTEP
64 geompy.ExportBREP(shape, fileExportImportBREP)
65 geompy.ExportIGES(shape, fileExportImportIGES)
66 geompy.ExportSTEP(shape, fileExportImportSTEP)
69 Import = geompy.Import(fileExportImport, "BREP")
71 id_Import = geompy.addToStudy(Import, "Import")
73 # ImportBREP, ImportIGES, ImportSTEP
74 ImportBREP = geompy.ImportBREP(fileExportImportBREP)
75 ImportIGES = geompy.ImportIGES(fileExportImportIGES)
76 ImportSTEP = geompy.ImportSTEP(fileExportImportSTEP)
78 id_ImportBREP = geompy.addToStudy(ImportBREP, "ImportBREP")
79 id_ImportIGES = geompy.addToStudy(ImportIGES, "ImportIGES")
80 id_ImportSTEP = geompy.addToStudy(ImportSTEP, "ImportSTEP")
82 # Remove files for Export/Import testing
83 os.remove(fileExportImport)
84 os.remove(fileExportImportBREP)
85 os.remove(fileExportImportIGES)
86 os.remove(fileExportImportSTEP)
91 def TestOtherOperations (geompy, math):
94 p11 = geompy.MakeVertex( 0, 0, 0)
95 p12 = geompy.MakeVertex(30, 0, 0)
96 p13 = geompy.MakeVertex(30, 30, 0)
97 p14 = geompy.MakeVertex( 0, 30, 0)
99 p21 = geompy.MakeVertex(10, 10, 0)
100 p22 = geompy.MakeVertex(20, 10, 0)
101 p23 = geompy.MakeVertex(20, 20, 0)
102 p24 = geompy.MakeVertex(10, 20, 0)
104 e11 = geompy.MakeEdge(p11, p12)
105 e12 = geompy.MakeEdge(p12, p13)
106 e13 = geompy.MakeEdge(p13, p14)
107 e14 = geompy.MakeEdge(p14, p11)
109 e21 = geompy.MakeEdge(p21, p22)
110 e22 = geompy.MakeEdge(p22, p23)
111 e23 = geompy.MakeEdge(p23, p24)
112 e24 = geompy.MakeEdge(p24, p21)
114 w1 = geompy.MakeWire([e11, e12, e13, e14])
115 w2 = geompy.MakeWire([e21, e22, e23, e24])
116 w3 = geompy.MakeTranslation(w2, 0, 0, 10)
118 id_w1 = geompy.addToStudy(w1, "Outside Wire")
119 id_w2 = geompy.addToStudy(w2, "Inside Wire")
120 id_w3 = geompy.addToStudy(w3, "Inside Wire, translated along OZ")
122 f12 = geompy.MakeFaces([w1, w2], 0)
123 id_f12 = geompy.addToStudy(f12, "MakeFaces WO + WI")
126 TestExportImport(geompy, f12)
129 Box = geompy.MakeBoxDXDYDZ(200, 200, 200)
130 Orientation = geompy.OrientationChange(Box)
131 id_Orientation = geompy.addToStudy(Orientation, "OrientationChange")
133 # MakeCommon, MakeCut, MakeFuse, MakeSection
134 Sphere = geompy.MakeSphereR(100)
136 Common = geompy.MakeCommon (Box, Sphere)
137 Cut = geompy.MakeCut (Box, Sphere)
138 Fuse = geompy.MakeFuse (Box, Sphere)
139 Section = geompy.MakeSection(Box, Sphere)
141 id_Common = geompy.addToStudy(Common, "Common")
142 id_Cut = geompy.addToStudy(Cut, "Cut")
143 id_Fuse = geompy.addToStudy(Fuse, "Fuse")
144 id_Section = geompy.addToStudy(Section, "Section")
147 p100 = geompy.MakeVertex(100, 100, 100)
148 p300 = geompy.MakeVertex(300, 300, 300)
149 Box1 = geompy.MakeBoxTwoPnt(p100, p300)
150 Partition = geompy.Partition([Box], [Box1], [], [Box])
151 id_Partition = geompy.addToStudy(Partition, "Partition of Box by Box1")
153 # MakeMultiRotation1D, MakeMultiRotation2D
154 pz = geompy.MakeVertex(0, 0, 100)
155 vy = geompy.MakeVectorDXDYDZ(0, 100, 0)
157 MultiRot1D = geompy.MakeMultiRotation1D(f12, vy, pz, 6)
158 MultiRot2D = geompy.MakeMultiRotation2D(f12, vy, pz, 45, 6, 30, 3)
160 id_MultiRot1D = geompy.addToStudy(MultiRot1D, "MakeMultiRotation1D")
161 id_MultiRot2D = geompy.addToStudy(MultiRot2D, "MakeMultiRotation2D")
165 face5 = geompy.SubShapeSorted(Box, geompy.ShapeType["FACE"], [5])
166 f_glob_id = geompy.GetSubShapeID(Box, face5)
167 SuppFace = geompy.SuppressFaces(Box, [f_glob_id])
169 MakeFilletAll = geompy.MakeFilletAll(SuppFace, radius_fillet)
170 id_MakeFilletAll = geompy.addToStudy(MakeFilletAll, "MakeFilletAll")
173 dimension_chamfer = 10.
174 MakeChamferAll = geompy.MakeChamferAll(SuppFace, dimension_chamfer)
175 id_MakeChamferAll = geompy.addToStudy(MakeChamferAll, "MakeChamferAll")
180 box_faces = geompy.SubShapeAllSorted(Box, geompy.ShapeType["FACE"])
181 f_ind_1 = geompy.GetSubShapeID(Box, box_faces[0])
182 f_ind_2 = geompy.GetSubShapeID(Box, box_faces[1])
183 f_ind_3 = geompy.GetSubShapeID(Box, box_faces[2])
185 MakeChamfer = geompy.MakeChamfer(Box, d1, d2, geompy.ShapeType["FACE"],
186 [f_ind_1, f_ind_2, f_ind_3])
187 id_MakeChamfer = geompy.addToStudy(MakeChamfer, "MakeChamfer")
190 NumberOfFaces = geompy.NumberOfFaces(Box)
191 if NumberOfFaces != 6:
192 print "Bad number of faces in BOX!"
195 NumberOfEdges = geompy.NumberOfEdges(Box)
196 if NumberOfEdges != 12:
197 print "Bad number of edges in BOX!"
200 Compound = geompy.MakeCompound([Box, Sphere])
201 MakeBlockExplode = geompy.MakeBlockExplode(Compound, 6, 6)
203 id_MakeBlockExplode = geompy.addToStudy(MakeBlockExplode[0], "MakeBlockExplode")
205 # CheckCompoundOfBlocks
206 p1 = geompy.MakeVertex(200, 0, 0)
207 p2 = geompy.MakeVertex(400, 200, 200)
208 p3 = geompy.MakeVertex(400, 50, 50)
209 p4 = geompy.MakeVertex(600, 250, 250)
211 Box2 = geompy.MakeBoxTwoPnt(p1, p2)
212 Box3 = geompy.MakeBoxTwoPnt(p3, p4)
213 Cyl = geompy.MakeCylinderRH(50, 300)
214 Cone = geompy.MakeConeR1R2H(150, 10, 400)
216 Compound1 = geompy.MakeCompound([Box, Cyl, Cone, Box3, Box2])
218 IsValid = geompy.CheckCompoundOfBlocks(Compound1)
220 print "The Blocks Compound is NOT VALID"
222 print "The Blocks Compound is VALID"
224 IsValid = geompy.CheckCompoundOfBlocks(Box)
226 print "The Box is NOT VALID"
228 print "The Box is VALID"
230 # test geometrical groups
233 CreateGroup = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
235 id_CreateGroup = geompy.addToStudy(CreateGroup, "CreateGroup")
238 f_ind_4 = geompy.GetSubShapeID(Box, box_faces[3])
239 f_ind_5 = geompy.GetSubShapeID(Box, box_faces[4])
240 f_ind_6 = geompy.GetSubShapeID(Box, box_faces[5])
242 geompy.AddObject(CreateGroup, f_ind_6) # box_faces[5]
243 geompy.AddObject(CreateGroup, f_ind_1) # box_faces[0]
244 geompy.AddObject(CreateGroup, f_ind_4) # box_faces[3]
247 geompy.UnionList(CreateGroup, [box_faces[2], box_faces[4], box_faces[5]])
249 # RemoveObject(theGroup, theSubShapeID)
250 geompy.RemoveObject(CreateGroup, f_ind_1) # box_faces[0]
253 geompy.DifferenceList(CreateGroup, [box_faces[1], box_faces[0], box_faces[3]])
256 GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
258 print "Group of Box's faces includes the following IDs:"
259 print "(must be ", f_ind_6, ", ", f_ind_3, " and ", f_ind_5, ")"
260 for ObjectID in GetObjectIDs:
263 BoxCopy = geompy.GetMainShape(CreateGroup)
265 # -----------------------------------------------------------------------------
266 # enumeration ShapeTypeString as a dictionary
267 # -----------------------------------------------------------------------------
268 ShapeTypeString = {'0':"COMPOUND", '1':"COMPSOLID", '2':"SOLID", '3':"SHELL", '4':"FACE", '5':"WIRE", '6':"EDGE", '7':"VERTEX", '8':"SHAPE"}
270 GroupType = geompy.GetType(CreateGroup)
271 print "Type of elements of the created group is ", ShapeTypeString[`GroupType`]
273 # Prepare data for the following operations
274 p0 = geompy.MakeVertex(0, 0, 0)
275 b0 = geompy.MakeBox(-50, -50, -50, 50, 50, 50)
276 s0 = geompy.MakeSphereR(100)
278 id_b0 = geompy.addToStudy(b0, "b0")
279 id_s0 = geompy.addToStudy(s0, "s0")
281 v_0pp = geompy.MakeVectorDXDYDZ( 0, 1, 1)
282 v_0np = geompy.MakeVectorDXDYDZ( 0, -1, 1)
283 v_p0p = geompy.MakeVectorDXDYDZ( 1, 0, 1)
284 v_n0p = geompy.MakeVectorDXDYDZ(-1, 0, 1)
285 v_pp0 = geompy.MakeVectorDXDYDZ( 1, 1, 0)
286 v_np0 = geompy.MakeVectorDXDYDZ(-1, 1, 0)
288 pln_0pp = geompy.MakePlane(p0, v_0pp, 300)
289 pln_0np = geompy.MakePlane(p0, v_0np, 300)
290 pln_p0p = geompy.MakePlane(p0, v_p0p, 300)
291 pln_n0p = geompy.MakePlane(p0, v_n0p, 300)
292 pln_pp0 = geompy.MakePlane(p0, v_pp0, 300)
293 pln_np0 = geompy.MakePlane(p0, v_np0, 300)
295 part_tool_1 = geompy.MakePartition([b0, pln_0pp, pln_0np, pln_p0p, pln_n0p, pln_pp0, pln_np0],
300 pt_pnt_1 = geompy.MakeVertex( 55, 0, 55)
301 pt_pnt_2 = geompy.MakeVertex( 0, 55, 55)
302 pt_pnt_3 = geompy.MakeVertex(-55, 0, 55)
303 pt_pnt_4 = geompy.MakeVertex( 0, -55, 55)
304 pt_pnt_5 = geompy.MakeVertex( 55, 55, 0)
305 pt_pnt_6 = geompy.MakeVertex( 55, -55, 0)
306 pt_pnt_7 = geompy.MakeVertex(-55, 55, 0)
307 pt_pnt_8 = geompy.MakeVertex(-55, -55, 0)
308 pt_pnt_9 = geompy.MakeVertex( 55, 0, -55)
309 pt_pnt_10 = geompy.MakeVertex( 0, 55, -55)
310 pt_pnt_11 = geompy.MakeVertex(-55, 0, -55)
311 pt_pnt_12 = geompy.MakeVertex( 0, -55, -55)
313 pt_face_1 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_1)
314 pt_face_2 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_2)
315 pt_face_3 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_3)
316 pt_face_4 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_4)
317 pt_face_5 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_5)
318 pt_face_6 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_6)
319 pt_face_7 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_7)
320 pt_face_8 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_8)
321 pt_face_9 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_9)
322 pt_face_10 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_10)
323 pt_face_11 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_11)
324 pt_face_12 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_12)
326 pt_box = geompy.GetBlockNearPoint(part_tool_1, p0)
328 part_tool = geompy.MakeCompound([pt_face_1, pt_face_4, pt_face_7, pt_face_10,
329 pt_face_2, pt_face_5, pt_face_8, pt_face_11,
330 pt_face_3, pt_face_6, pt_face_9, pt_face_12, pt_box])
331 id_part_tool = geompy.addToStudy(part_tool, "part_tool")
333 part = geompy.MakePartition([s0], [part_tool])
334 geompy.addToStudy(part, "part")
337 anIDs = geompy.GetFreeFacesIDs(part)
338 freeFaces = geompy.GetSubShape(part, anIDs)
340 geompy.addToStudy(freeFaces, "freeFaces")
343 freeFacesWithoutExtra = geompy.RemoveExtraEdges(freeFaces)
345 geompy.addToStudy(freeFacesWithoutExtra, "freeFacesWithoutExtra")
348 sharedFaces = geompy.GetSharedShapes(part, freeFacesWithoutExtra, geompy.ShapeType["FACE"])
350 for shFace in sharedFaces:
351 geompy.addToStudy(shFace, "sharedFace")
354 blocksComp = geompy.CheckAndImprove(part)
356 geompy.addToStudy(blocksComp, "blocksComp")
359 listChains = geompy.Propagate(blocksComp)
361 for chain in listChains:
362 geompy.addToStudyInFather(blocksComp, chain, "propagation chain")
364 # GetPoint(theShape, theX, theY, theZ, theEpsilon)
366 # (-50, 50, 50) .-----. (50, 50, 50)
370 # (-50, -50, 50) '-----' (50, -50, 50)
372 pb0_top_1 = geompy.GetPoint(blocksComp, -50, 50, 50, 0.01)
373 pb0_bot_1 = geompy.GetPoint(blocksComp, -50, -50, -50, 0.01)
375 geompy.addToStudyInFather(blocksComp, pb0_top_1, "point from blocksComp (-50, 50, 50)")
376 geompy.addToStudyInFather(blocksComp, pb0_bot_1, "point from blocksComp (-50, -50, -50)")
378 # GetEdgeNearPoint(theShape, thePoint)
379 pmidle = geompy.MakeVertex(50, 0, 50)
380 edge1 = geompy.GetEdgeNearPoint(blocksComp, pmidle)
382 geompy.addToStudyInFather(blocksComp, edge1, "edge near point (50, 0, 50)")
384 # GetBlockByParts(theCompound, theParts)
385 b0_image = geompy.GetBlockByParts(blocksComp, [pb0_top_1, pb0_bot_1, edge1])
387 geompy.addToStudyInFather(blocksComp, b0_image, "b0 image")
390 faces_on_pln = geompy.GetShapesOnPlane(blocksComp, geompy.ShapeType["FACE"],
391 v_0pp, geompy.GEOM.ST_ONIN)
392 for face_i in faces_on_pln:
393 geompy.addToStudy(face_i, "Face on Plane (N = (0, 1, 1)) or below it")
395 # GetShapesOnCylinder
396 edges_on_cyl = geompy.GetShapesOnCylinder(blocksComp, geompy.ShapeType["EDGE"],
397 vy, 55, geompy.GEOM.ST_OUT)
398 for edge_i in edges_on_cyl:
399 geompy.addToStudy(edge_i, "Edge out of Cylinder (axis = (0, 1, 0), r = 55)")
402 vertices_on_sph = geompy.GetShapesOnSphere(blocksComp, geompy.ShapeType["VERTEX"],
403 p0, 100, geompy.GEOM.ST_ON)
404 for vertex_i in vertices_on_sph:
405 geompy.addToStudy(vertex_i, "Vertex on Sphere (center = (0, 0, 0), r = 100)")
407 # GetInPlace(theShapeWhere, theShapeWhat)
408 box5 = geompy.MakeBoxDXDYDZ(100, 100, 100)
409 box6 = geompy.MakeTranslation(box5, 50, 50, 0)
411 part = geompy.MakePartition([box5], [box6])
412 geompy.addToStudy(part, "Partitioned")
415 box_list = [box5, box6]
416 for abox in box_list:
417 geompy.addToStudy(abox, "Box " + `ibb`)
418 box_faces = geompy.SubShapeAll(abox, geompy.ShapeType["FACE"])
420 for aface in box_faces:
421 geompy.addToStudyInFather(abox, aface, "Face" + `ifa`)
422 refl_box_face = geompy.GetInPlace(part, aface)
423 if refl_box_face is not None:
424 geompy.addToStudyInFather(part, refl_box_face,
425 "Reflection of Face " + `ifa` + " of box " + `ibb`)