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_TestOthers.py
24 # Author : Julia DOROVSKIKH
27 # ! Please, if you edit this example file, update also
28 # ! GEOM_SRC/doc/salome/gui/GEOM/input/tui_test_others.doc
29 # ! as some sequences of symbols from this example are used during
30 # ! documentation generation to identify certain places of this file
34 def TestExportImport (geompy, shape):
36 print "Test Export/Import ...",
38 tmpDir = os.getenv("TEMP")
42 # Files for Export/Import testing
43 fileExportImport = tmpDir + "/testExportImport.brep"
44 fileExportImportBREP = tmpDir + "/testExportImportBREP.brep"
45 fileExportImportIGES = tmpDir + "/testExportImportIGES.iges"
46 fileExportImportSTEP = tmpDir + "/testExportImportSTEP.step"
48 if os.access(fileExportImport, os.F_OK):
49 if os.access(fileExportImport, os.W_OK):
50 os.remove(fileExportImport)
52 fileExportImport = tmpDir + "/testExportImport1.brep"
54 if os.access(fileExportImportBREP, os.W_OK):
55 os.remove(fileExportImportBREP)
57 fileExportImportBREP = tmpDir + "/testExportImportBREP1.brep"
59 if os.access(fileExportImportIGES, os.W_OK):
60 os.remove(fileExportImportIGES)
62 fileExportImportIGES = tmpDir + "/testExportImportIGES1.iges"
64 if os.access(fileExportImportSTEP, os.W_OK):
65 os.remove(fileExportImportSTEP)
67 fileExportImportSTEP = tmpDir + "/testExportImportSTEP1.step"
70 geompy.Export(shape, fileExportImport, "BREP")
72 # ExportBREP, ExportIGES, ExportSTEP
73 geompy.ExportBREP(shape, fileExportImportBREP)
74 geompy.ExportIGES(shape, fileExportImportIGES)
75 geompy.ExportSTEP(shape, fileExportImportSTEP)
78 Import = geompy.Import(fileExportImport, "BREP")
80 id_Import = geompy.addToStudy(Import, "Import")
82 # ImportBREP, ImportIGES, ImportSTEP
83 ImportBREP = geompy.ImportBREP(fileExportImportBREP)
84 ImportIGES = geompy.ImportIGES(fileExportImportIGES)
85 ImportSTEP = geompy.ImportSTEP(fileExportImportSTEP)
87 id_ImportBREP = geompy.addToStudy(ImportBREP, "ImportBREP")
88 id_ImportIGES = geompy.addToStudy(ImportIGES, "ImportIGES")
89 id_ImportSTEP = geompy.addToStudy(ImportSTEP, "ImportSTEP")
91 # Remove files for Export/Import testing
92 os.remove(fileExportImport)
93 os.remove(fileExportImportBREP)
94 os.remove(fileExportImportIGES)
95 os.remove(fileExportImportSTEP)
100 def TestOtherOperations (geompy, math):
102 # prepare data for further operations
103 vx = geompy.MakeVectorDXDYDZ( 1, 0, 0)
104 vy = geompy.MakeVectorDXDYDZ( 0, 1, 0)
105 vz = geompy.MakeVectorDXDYDZ( 0, 0, 1)
107 v_y = geompy.MakeVectorDXDYDZ( 0, -1, 0)
109 p11 = geompy.MakeVertex( 0, 0, 0)
110 p12 = geompy.MakeVertex(30, 0, 0)
111 p13 = geompy.MakeVertex(30, 30, 0)
112 p14 = geompy.MakeVertex( 0, 30, 0)
114 p21 = geompy.MakeVertex(10, 10, 0)
115 p22 = geompy.MakeVertex(20, 10, 0)
116 p23 = geompy.MakeVertex(20, 20, 0)
117 p24 = geompy.MakeVertex(10, 20, 0)
119 e11 = geompy.MakeEdge(p11, p12)
120 e12 = geompy.MakeEdge(p12, p13)
121 e13 = geompy.MakeEdge(p13, p14)
122 e14 = geompy.MakeEdge(p14, p11)
124 e21 = geompy.MakeEdge(p21, p22)
125 e22 = geompy.MakeEdge(p22, p23)
126 e23 = geompy.MakeEdge(p23, p24)
127 e24 = geompy.MakeEdge(p24, p21)
129 w1 = geompy.MakeWire([e11, e12, e13, e14])
130 w2 = geompy.MakeWire([e21, e22, e23, e24])
131 w3 = geompy.MakeTranslation(w2, 0, 0, 10)
133 id_w1 = geompy.addToStudy(w1, "Outside Wire")
134 id_w2 = geompy.addToStudy(w2, "Inside Wire")
135 id_w3 = geompy.addToStudy(w3, "Inside Wire, translated along OZ")
138 f12 = geompy.MakeFaces([w1, w2], 0)
139 id_f12 = geompy.addToStudy(f12, "MakeFaces WO + WI")
142 TestExportImport(geompy, f12)
145 Box = geompy.MakeBoxDXDYDZ(200, 200, 200)
146 Orientation = geompy.OrientationChange(Box)
147 id_Orientation = geompy.addToStudy(Orientation, "OrientationChange")
149 # MakeCommon, MakeCut, MakeFuse, MakeSection
150 Sphere = geompy.MakeSphereR(100)
152 Common = geompy.MakeCommon (Box, Sphere)
153 Cut = geompy.MakeCut (Box, Sphere)
154 Fuse = geompy.MakeFuse (Box, Sphere)
155 Section = geompy.MakeSection(Box, Sphere)
157 id_Common = geompy.addToStudy(Common, "Common")
158 id_Cut = geompy.addToStudy(Cut, "Cut")
159 id_Fuse = geompy.addToStudy(Fuse, "Fuse")
160 id_Section = geompy.addToStudy(Section, "Section")
163 p100 = geompy.MakeVertex(100, 100, 100)
164 p300 = geompy.MakeVertex(300, 300, 300)
165 Box1 = geompy.MakeBoxTwoPnt(p100, p300)
166 #Partition = geompy.Partition([Box], [Box1], [], [Box])
167 Partition = geompy.Partition([Box], [Box1])
168 id_Partition = geompy.addToStudy(Partition, "Partition of Box by Box1")
170 # MakeMultiRotation1D, MakeMultiRotation2D
171 pz = geompy.MakeVertex(0, 0, 100)
172 vy = geompy.MakeVectorDXDYDZ(0, 100, 0)
174 MultiRot1D = geompy.MakeMultiRotation1D(f12, vy, pz, 6)
175 MultiRot2D = geompy.MakeMultiRotation2D(f12, vy, pz, 45, 6, 30, 3)
177 id_MultiRot1D = geompy.addToStudy(MultiRot1D, "MakeMultiRotation1D")
178 id_MultiRot2D = geompy.addToStudy(MultiRot2D, "MakeMultiRotation2D")
182 face5 = geompy.SubShapeSorted(Box, geompy.ShapeType["FACE"], [5])
183 f_glob_id = geompy.GetSubShapeID(Box, face5)
184 SuppFace = geompy.SuppressFaces(Box, [f_glob_id])
186 MakeFilletAll = geompy.MakeFilletAll(SuppFace, radius_fillet)
187 id_MakeFilletAll = geompy.addToStudy(MakeFilletAll, "MakeFilletAll")
190 dimension_chamfer = 10.
191 MakeChamferAll = geompy.MakeChamferAll(SuppFace, dimension_chamfer)
192 id_MakeChamferAll = geompy.addToStudy(MakeChamferAll, "MakeChamferAll")
197 box_faces = geompy.SubShapeAllSorted(Box, geompy.ShapeType["FACE"])
198 f_ind_1 = geompy.GetSubShapeID(Box, box_faces[0])
199 f_ind_2 = geompy.GetSubShapeID(Box, box_faces[1])
200 f_ind_3 = geompy.GetSubShapeID(Box, box_faces[2])
202 MakeChamfer = geompy.MakeChamfer(Box, d1, d2, geompy.ShapeType["FACE"],
203 [f_ind_1, f_ind_2, f_ind_3])
204 id_MakeChamfer = geompy.addToStudy(MakeChamfer, "MakeChamfer")
207 NumberOfFaces = geompy.NumberOfFaces(Box)
208 if NumberOfFaces != 6:
209 print "Bad number of faces in BOX!"
212 NumberOfEdges = geompy.NumberOfEdges(Box)
213 if NumberOfEdges != 12:
214 print "Bad number of edges in BOX!"
217 Compound = geompy.MakeCompound([Box, Sphere])
218 MakeBlockExplode = geompy.MakeBlockExplode(Compound, 6, 6)
220 id_MakeBlockExplode = geompy.addToStudy(MakeBlockExplode[0], "MakeBlockExplode")
222 # CheckCompoundOfBlocks
223 p1 = geompy.MakeVertex(200, 0, 0)
224 p2 = geompy.MakeVertex(400, 200, 200)
225 p3 = geompy.MakeVertex(400, 50, 50)
226 p4 = geompy.MakeVertex(600, 250, 250)
228 Box2 = geompy.MakeBoxTwoPnt(p1, p2)
229 Box3 = geompy.MakeBoxTwoPnt(p3, p4)
230 Cyl = geompy.MakeCylinderRH(50, 300)
231 Cone = geompy.MakeConeR1R2H(150, 10, 400)
233 Compound1 = geompy.MakeCompound([Box, Cyl, Cone, Box3, Box2])
235 IsValid = geompy.CheckCompoundOfBlocks(Compound1)
237 print "The Blocks Compound is NOT VALID"
239 print "The Blocks Compound is VALID"
241 IsValid = geompy.CheckCompoundOfBlocks(Box)
243 print "The Box is NOT VALID"
245 print "The Box is VALID"
248 Cone_ss = geompy.GetSame(Compound1, Cone)
249 id_Cone_ss = geompy.addToStudyInFather(Compound1, Cone_ss, "Cone subshape")
251 # test geometrical groups
254 CreateGroup = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
256 id_CreateGroup = geompy.addToStudy(CreateGroup, "CreateGroup")
259 f_ind_4 = geompy.GetSubShapeID(Box, box_faces[3])
260 f_ind_5 = geompy.GetSubShapeID(Box, box_faces[4])
261 f_ind_6 = geompy.GetSubShapeID(Box, box_faces[5])
263 geompy.AddObject(CreateGroup, f_ind_6) # box_faces[5]
264 geompy.AddObject(CreateGroup, f_ind_1) # box_faces[0]
265 geompy.AddObject(CreateGroup, f_ind_4) # box_faces[3]
266 # Now contains f_ind_6, f_ind_1, f_ind_4
269 geompy.UnionList(CreateGroup, [box_faces[2], box_faces[4], box_faces[5]])
270 # Now contains f_ind_6, f_ind_1, f_ind_4, f_ind_3, f_ind_5
272 # RemoveObject(theGroup, theSubShapeID)
273 geompy.RemoveObject(CreateGroup, f_ind_1) # box_faces[0]
274 # Now contains f_ind_6, f_ind_4, f_ind_3, f_ind_5
277 geompy.DifferenceList(CreateGroup, [box_faces[1], box_faces[0], box_faces[3]])
278 # Now contains f_ind_6, f_ind_3, f_ind_5
281 GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
283 print "Group of Box's faces includes the following IDs:"
284 print "(must be ", f_ind_6, ", ", f_ind_3, " and ", f_ind_5, ")"
285 for ObjectID in GetObjectIDs:
289 BoxCopy = geompy.GetMainShape(CreateGroup)
292 geompy.DifferenceIDs(CreateGroup, [f_ind_3, f_ind_5])
293 # Now contains f_ind_6
296 geompy.UnionIDs(CreateGroup, [f_ind_1, f_ind_2, f_ind_6])
297 # Now contains f_ind_6, f_ind_1, f_ind_2
300 GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
301 print "Group of Box's faces includes the following IDs:"
302 print "(must be ", f_ind_6, ", ", f_ind_1, " and ", f_ind_2, ")"
303 for ObjectID in GetObjectIDs:
306 # -----------------------------------------------------------------------------
307 # enumeration ShapeTypeString as a dictionary
308 # -----------------------------------------------------------------------------
309 ShapeTypeString = {'0':"COMPOUND", '1':"COMPSOLID", '2':"SOLID", '3':"SHELL",
310 '4':"FACE", '5':"WIRE", '6':"EDGE", '7':"VERTEX", '8':"SHAPE"}
312 GroupType = geompy.GetType(CreateGroup)
313 print "Type of elements of the created group is ", ShapeTypeString[`GroupType`]
315 # Prepare data for the following operations
316 p0 = geompy.MakeVertex(0, 0, 0)
317 b0 = geompy.MakeBox(-50, -50, -50, 50, 50, 50)
318 s0 = geompy.MakeSphereR(100)
320 id_b0 = geompy.addToStudy(b0, "b0")
321 id_s0 = geompy.addToStudy(s0, "s0")
323 v_0pp = geompy.MakeVectorDXDYDZ( 0, 1, 1)
324 #v_0np = geompy.MakeVectorDXDYDZ( 0, -1, 1)
325 v_p0p = geompy.MakeVectorDXDYDZ( 1, 0, 1)
326 v_p0n = geompy.MakeVectorDXDYDZ(1, 0, -1)
327 v_pp0 = geompy.MakeVectorDXDYDZ( 1, 1, 0)
328 v_pn0 = geompy.MakeVectorDXDYDZ(1, -1, 0)
330 #pln_0pp = geompy.MakePlane(p0, v_0pp, 300)
331 #pln_0np = geompy.MakePlane(p0, v_0np, 300)
332 pln_p0p = geompy.MakePlane(p0, v_p0p, 300)
333 pln_p0n = geompy.MakePlane(p0, v_p0n, 300)
334 pln_pp0 = geompy.MakePlane(p0, v_pp0, 300)
335 pln_pn0 = geompy.MakePlane(p0, v_pn0, 300)
337 #part_objs = [b0, pln_0pp, pln_0np, pln_p0p, pln_n0p, pln_pp0, pln_np0]
338 #part_tool_1 = geompy.MakePartition(part_objs, [], [], [b0])
339 #part_tool_1 = geompy.MakePartition(part_objs)
341 #id_part_tool_1 = geompy.addToStudy(part_tool_1, "part_tool_1")
343 #pt_pnt_1 = geompy.MakeVertex( 55, 0, 55)
344 #pt_pnt_2 = geompy.MakeVertex( 0, 55, 55)
345 #pt_pnt_3 = geompy.MakeVertex(-55, 0, 55)
346 #pt_pnt_4 = geompy.MakeVertex( 0, -55, 55)
347 #pt_pnt_5 = geompy.MakeVertex( 55, 55, 0)
348 #pt_pnt_6 = geompy.MakeVertex( 55, -55, 0)
349 #pt_pnt_7 = geompy.MakeVertex(-55, 55, 0)
350 #pt_pnt_8 = geompy.MakeVertex(-55, -55, 0)
351 #pt_pnt_9 = geompy.MakeVertex( 55, 0, -55)
352 #pt_pnt_10 = geompy.MakeVertex( 0, 55, -55)
353 #pt_pnt_11 = geompy.MakeVertex(-55, 0, -55)
354 #pt_pnt_12 = geompy.MakeVertex( 0, -55, -55)
356 #pt_face_1 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_1)
357 #pt_face_2 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_2)
358 #pt_face_3 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_3)
359 #pt_face_4 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_4)
360 #pt_face_5 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_5)
361 #pt_face_6 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_6)
362 #pt_face_7 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_7)
363 #pt_face_8 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_8)
364 #pt_face_9 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_9)
365 #pt_face_10 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_10)
366 #pt_face_11 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_11)
367 #pt_face_12 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_12)
369 #pt_box = geompy.GetBlockNearPoint(part_tool_1, p0)
371 #comp_parts = [pt_face_1, pt_face_4, pt_face_7, pt_face_10,
372 # pt_face_2, pt_face_5, pt_face_8, pt_face_11,
373 # #pt_face_3, pt_face_6, pt_face_9, pt_face_12, pt_box]
374 # pt_face_3, pt_face_6, pt_face_9, pt_face_12]
375 #part_tool = geompy.MakeCompound(comp_parts)
376 #id_part_tool = geompy.addToStudy(part_tool, "part_tool")
378 #part = geompy.MakePartition([s0], [part_tool])
380 #part_tools = [pt_face_1, pt_face_4, pt_face_7, pt_face_10,
381 # pt_face_2, pt_face_5, pt_face_8, pt_face_11,
382 # pt_face_3, pt_face_6, pt_face_9, pt_face_12, b0]
383 #part = geompy.MakePartition([s0], part_tools)
385 p1 = geompy.MakeVertex(50, 0, 0)
386 p2 = geompy.MakeVertex(-50, 0, 0)
387 p3 = geompy.MakeVertex(0, 50, 0)
388 p4 = geompy.MakeVertex(0, -50, 0)
389 p5 = geompy.MakeVertex(0, 0, 50)
390 p6 = geompy.MakeVertex(0, 0, -50)
392 plnX1 = geompy.MakePlane(p1, vx, 300)
393 plnX2 = geompy.MakePlane(p2, vx, 300)
394 plnY1 = geompy.MakePlane(p3, vy, 300)
395 plnY2 = geompy.MakePlane(p4, vy, 300)
396 plnZ1 = geompy.MakePlane(p5, vz, 300)
397 plnZ2 = geompy.MakePlane(p6, vz, 300)
399 #part = geompy.MakePartition([s0], [plnX1,plnX2,plnY1,plnY2,plnZ1,plnZ2])
400 part = geompy.MakePartition([s0], [plnX1])
401 part = geompy.MakePartition([part], [plnX2])
402 part = geompy.MakePartition([part], [plnY1])
403 part = geompy.MakePartition([part], [plnY2])
404 part = geompy.MakePartition([part], [plnZ1])
405 part = geompy.MakePartition([part], [plnZ2])
406 geompy.addToStudy(part, "part")
409 anIDs = geompy.GetFreeFacesIDs(part)
410 freeFaces = geompy.GetSubShape(part, anIDs)
412 geompy.addToStudy(freeFaces, "freeFaces")
414 # RemoveExtraEdges with union of all faces, sharing common surfaces
415 tools = [pln_pp0, pln_pn0, pln_p0p, pln_p0n]
417 Partition_1 = geompy.MakePartition([Sphere], tools, [], [], geompy.ShapeType["SOLID"], 0, [])
418 geompy.addToStudy(Partition_1, "Partition_1")
420 faces = geompy.SubShapeAllSorted(Partition_1, geompy.ShapeType["FACE"])
426 geompy.addToStudyInFather(Partition_1, Face_1, "Face_1")
427 geompy.addToStudyInFather(Partition_1, Face_2, "Face_2")
428 geompy.addToStudyInFather(Partition_1, Face_3, "Face_3")
430 Vector_5 = geompy.MakeVectorDXDYDZ(0, 20, 0)
431 geompy.addToStudy(Vector_5, "Vector_5")
433 Rotation_1 = geompy.MakeRotation(Face_1, Vector_5, 90*math.pi/180.0)
434 Rotation_2 = geompy.MakeRotation(Face_1, Vector_5, 180*math.pi/180.0)
435 Rotation_3 = geompy.MakeRotation(Face_1, Vector_5, 270*math.pi/180.0)
437 geompy.addToStudy(Rotation_1, "Rotation_1")
438 geompy.addToStudy(Rotation_2, "Rotation_2")
439 geompy.addToStudy(Rotation_3, "Rotation_3")
441 Vector_6 = geompy.MakeVectorDXDYDZ(0, 0, 20)
442 geompy.addToStudy(Vector_6, "Vector_6")
444 Rotation_4 = geompy.MakeRotation(Face_1, Vector_6, 90*math.pi/180.0)
445 Rotation_5 = geompy.MakeRotation(Face_1, Vector_6, -90*math.pi/180.0)
446 geompy.addToStudy(Rotation_4, "Rotation_4")
447 geompy.addToStudy(Rotation_5, "Rotation_5")
449 Shell_1 = geompy.MakeShell([Face_1, Rotation_1, Rotation_2, Rotation_3, Rotation_4, Rotation_5])
450 Solid_1 = geompy.MakeSolid([Shell_1])
451 NoExtraEdges_1 = geompy.RemoveExtraEdges(Solid_1, 0)
453 geompy.addToStudy(Shell_1, "Shell_1")
454 geompy.addToStudy(Solid_1, "Solid_1")
455 geompy.addToStudy(NoExtraEdges_1, "NoExtraEdges_1")
458 freeFacesWithoutExtra = geompy.RemoveExtraEdges(freeFaces)
460 geompy.addToStudy(freeFacesWithoutExtra, "freeFacesWithoutExtra")
463 sharedFaces = geompy.GetSharedShapes(part, freeFacesWithoutExtra,
464 geompy.ShapeType["FACE"])
466 for shFace in sharedFaces:
467 geompy.addToStudy(shFace, "sharedFace")
470 blocksComp = geompy.CheckAndImprove(part)
472 geompy.addToStudy(blocksComp, "blocksComp")
475 listChains = geompy.Propagate(blocksComp)
477 for chain in listChains:
478 geompy.addToStudyInFather(blocksComp, chain, "propagation chain")
480 # GetPoint(theShape, theX, theY, theZ, theEpsilon)
482 # (-50, 50, 50) .-----. (50, 50, 50)
486 # (-50, -50, 50) '-----' (50, -50, 50)
488 pb0_top_1 = geompy.GetPoint(blocksComp, -50, 50, 50, 0.01)
489 pb0_bot_1 = geompy.GetPoint(blocksComp, -50, -50, -50, 0.01)
491 geompy.addToStudyInFather(blocksComp, pb0_top_1, "point from blocksComp (-50, 50, 50)")
492 geompy.addToStudyInFather(blocksComp, pb0_bot_1, "point from blocksComp (-50, -50, -50)")
494 # GetEdgeNearPoint(theShape, thePoint)
495 pmidle = geompy.MakeVertex(50, 0, 50)
496 edge1 = geompy.GetEdgeNearPoint(blocksComp, pmidle)
498 geompy.addToStudyInFather(blocksComp, edge1, "edge near point (50, 0, 50)")
500 # GetBlockByParts(theCompound, theParts)
501 b0_image = geompy.GetBlockByParts(blocksComp, [pb0_top_1, pb0_bot_1, edge1])
503 geompy.addToStudyInFather(blocksComp, b0_image, "b0 image")
506 faces_on_pln = geompy.GetShapesOnPlane(blocksComp, geompy.ShapeType["FACE"],
507 v_0pp, geompy.GEOM.ST_ONIN)
508 for face_i in faces_on_pln:
509 geompy.addToStudy(face_i, "Face on Plane (N = (0, 1, 1)) or below it")
511 # GetShapesOnPlaneIDs
512 faces_above_pln_ids = geompy.GetShapesOnPlaneIDs(blocksComp, geompy.ShapeType["FACE"],
513 v_0pp, geompy.GEOM.ST_OUT)
514 faces_above = geompy.CreateGroup(blocksComp, geompy.ShapeType["FACE"])
515 geompy.UnionIDs(faces_above, faces_above_pln_ids)
516 geompy.addToStudy(faces_above, "Group of faces above Plane (N = (0, 1, 1))")
518 # GetShapesOnPlaneWithLocation
519 Loc = geompy.MakeVertex(0, -50, 0)
520 edges_on_pln = geompy.GetShapesOnPlaneWithLocation(blocksComp, geompy.ShapeType["EDGE"],
521 v_y, Loc, geompy.GEOM.ST_ON)
522 for edge_i in edges_on_pln:
523 geompy.addToStudy(edge_i, "Edge on Plane (N = (0, -1, 0) & Location = (0, -50, 0)")
525 # GetShapesOnPlaneWithLocationIDs
526 edges_on_pln_ids = geompy.GetShapesOnPlaneWithLocationIDs(
527 blocksComp, geompy.ShapeType["EDGE"], v_y, Loc, geompy.GEOM.ST_ON)
528 group_edges_on_pln = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
529 geompy.UnionIDs(group_edges_on_pln, edges_on_pln_ids)
530 grname = "Group of edges on Plane (N = (0, -1, 0) & Location = (0, -50, 0))"
531 geompy.addToStudy(group_edges_on_pln, grname)
533 # GetShapesOnCylinder
534 edges_out_cyl = geompy.GetShapesOnCylinder(blocksComp, geompy.ShapeType["EDGE"],
535 vy, 55, geompy.GEOM.ST_OUT)
536 for edge_i in edges_out_cyl:
537 geompy.addToStudy(edge_i, "Edge out of Cylinder (axis = (0, 1, 0), r = 55)")
539 # GetShapesOnCylinderIDs
540 edges_in_cyl_ids = geompy.GetShapesOnCylinderIDs(blocksComp, geompy.ShapeType["EDGE"],
541 vy, 80, geompy.GEOM.ST_IN)
542 edges_in = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
543 geompy.UnionIDs(edges_in, edges_in_cyl_ids)
544 geompy.addToStudy(edges_in, "Group of edges inside Cylinder (axis = (0, 1, 0), r = 55)")
547 vertices_on_sph = geompy.GetShapesOnSphere(blocksComp, geompy.ShapeType["VERTEX"],
548 p0, 100, geompy.GEOM.ST_ON)
549 for vertex_i in vertices_on_sph:
550 geompy.addToStudy(vertex_i, "Vertex on Sphere (center = (0, 0, 0), r = 100)")
552 # GetShapesOnSphereIDs
553 vertices_on_sph_ids = geompy.GetShapesOnSphereIDs(blocksComp, geompy.ShapeType["VERTEX"],
554 p0, 100, geompy.GEOM.ST_ON)
555 vertices_on = geompy.CreateGroup(blocksComp, geompy.ShapeType["VERTEX"])
556 geompy.UnionIDs(vertices_on, vertices_on_sph_ids)
557 geompy.addToStudy(vertices_on, "Group of vertices on Sphere (center = (0, 0, 0), r = 100)")
559 # GetShapesOnQuadrangle
561 geompy.addToStudy(f12, "F12" )
563 bl = geompy.MakeVertex(10,-10, 0)
564 br = geompy.MakeVertex(40,-10, 0)
565 tr = geompy.MakeVertex(40, 20, 0)
566 tl = geompy.MakeVertex(10, 20, 0)
567 qe1 = geompy.MakeEdge(bl, br)
568 qe2 = geompy.MakeEdge(br, tr)
569 qe3 = geompy.MakeEdge(tr, tl)
570 qe4 = geompy.MakeEdge(tl, bl)
571 quadrangle = geompy.MakeWire([qe1, qe2, qe3, qe4])
572 geompy.addToStudy(quadrangle, "Quadrangle")
574 edges_onin_quad = geompy.GetShapesOnQuadrangle(f12, geompy.ShapeType["EDGE"],
575 tl, tr, bl, br, geompy.GEOM.ST_ONIN)
576 comp = geompy.MakeCompound(edges_onin_quad)
577 geompy.addToStudy(comp, "Edges of F12 ONIN Quadrangle")
578 if len( edges_onin_quad ) != 4:
579 print "Error in GetShapesOnQuadrangle()"
581 # GetShapesOnQuadrangleIDs
582 vertices_on_quad_ids = geompy.GetShapesOnQuadrangleIDs(f12, geompy.ShapeType["VERTEX"],
583 tl, tr, bl, br, geompy.GEOM.ST_ON)
584 vertices_on_quad = geompy.CreateGroup(f12, geompy.ShapeType["VERTEX"])
585 geompy.UnionIDs(vertices_on_quad, vertices_on_quad_ids)
586 geompy.addToStudy(vertices_on_quad, "Group of vertices on Quadrangle F12")
589 edges_on_box = geompy.GetShapesOnBox(b0, part, geompy.ShapeType["EDGE"],
591 comp = geompy.MakeCompound(edges_on_box)
592 geompy.addToStudy(comp, "Edges of part ON box b0")
593 if len( edges_on_box ) != 12:
594 print "Error in GetShapesOnBox()"
597 faces_on_box_ids = geompy.GetShapesOnBoxIDs(b0, part, geompy.ShapeType["FACE"],
599 faces_on_box = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
600 geompy.UnionIDs(faces_on_box, faces_on_box_ids)
601 geompy.addToStudyInFather(part, faces_on_box, "Group of faces on box b0")
603 # Prepare arguments for GetShapesOnShape
604 sph1 = geompy.MakeSphere(50, 50, 50, 40)
605 sph2 = geompy.MakeSphere(50, 50, -50, 40)
606 pcyl = geompy.MakeVertex(50, 50, -50)
607 cyli = geompy.MakeCylinder(pcyl, vz, 40, 100)
608 fuse = geompy.MakeFuse(sph1, cyli)
609 fuse = geompy.MakeFuse(fuse, sph2)
610 # As after Fuse we have a compound, we need to obtain a solid from it
611 shsh = geompy.SubShapeAll(fuse, geompy.ShapeType["SOLID"])
613 geompy.addToStudy(sh_1, "sh_1")
616 faces_in_sh = geompy.GetShapesOnShape(sh_1, part, geompy.ShapeType["FACE"],
618 comp = geompy.MakeCompound(faces_in_sh)
619 geompy.addToStudy(comp, "Faces of part IN shape sh_1")
620 if len(faces_in_sh) != 11:
621 print "Error in GetShapesOnShape()"
623 # GetShapesOnShapeAsCompound
624 faces_in_sh_c = geompy.GetShapesOnShapeAsCompound(sh_1, part, geompy.ShapeType["FACE"],
626 geompy.addToStudy(faces_in_sh_c, "Faces of part IN shape sh_1 (as compound)")
628 # GetShapesOnShapeIDs
629 edges_in_sh_ids = geompy.GetShapesOnShapeIDs(sh_1, part, geompy.ShapeType["EDGE"],
631 edges_in_sh = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
632 geompy.UnionIDs(edges_in_sh, edges_in_sh_ids)
633 geompy.addToStudyInFather(part, edges_in_sh, "Group of edges in shape sh_1")
634 if len(edges_in_sh_ids) != 15:
635 print "Error in GetShapesOnShapeIDs()"
637 # Prepare arguments for GetInPlace and GetInPlaceByHistory
638 box5 = geompy.MakeBoxDXDYDZ(100, 100, 100)
639 box6 = geompy.MakeTranslation(box5, 50, 50, 0)
641 geompy.addToStudy(box5, "Box 5")
642 geompy.addToStudy(box6, "Box 6")
644 part = geompy.MakePartition([box5], [box6])
645 geompy.addToStudy(part, "Partitioned")
647 box5_faces = geompy.SubShapeAll(box5, geompy.ShapeType["FACE"])
648 box6_faces = geompy.SubShapeAll(box6, geompy.ShapeType["FACE"])
651 geompy.addToStudyInFather(box5, box5_faces[ifa], "Face" + `ifa + 1`)
652 geompy.addToStudyInFather(box6, box6_faces[ifa], "Face" + `ifa + 1`)
654 # GetInPlace(theShapeWhere, theShapeWhat)
656 faces_list = [box5_faces, box6_faces]
657 for afaces in faces_list:
660 refl_box_face = geompy.GetInPlace(part, aface)
661 if ibb == 6 and (ifa == 2 or ifa == 4):
662 # For two faces of the tool box
663 # there is no reflection in the result.
664 if refl_box_face is not None:
665 error = "Result of GetInPlace must be NULL for face "
666 error += `ifa` + " of box " + `ibb`
667 raise RuntimeError, error
669 ssname = "Reflection of face " + `ifa` + " of box " + `ibb`
670 geompy.addToStudyInFather(part, refl_box_face, ssname)
674 # GetInPlaceByHistory(theShapeWhere, theShapeWhat)
675 part = geompy.MakePartition([box5], [box6])
676 geompy.addToStudy(part, "Partitioned")
679 faces_list = [box5_faces, box6_faces]
680 for afaces in faces_list:
683 ssname = "Reflection of face " + `ifa` + " of box " + `ibb` + " (by history)"
684 if ibb == 6 and (ifa == 2 or ifa == 4):
685 # use IDL interface directly to avoid error message appearence in Python console
686 refl_box_face = geompy.ShapesOp.GetInPlaceByHistory(part, aface)
687 if refl_box_face is not None:
688 geompy.addToStudyInFather(part, refl_box_face, ssname)
689 error = "Result of GetInPlaceByHistory must be NULL for face "
690 error += `ifa` + " of box " + `ibb`
691 raise RuntimeError, error
693 # use geompy interface
694 refl_box_face = geompy.GetInPlaceByHistory(part, aface)
695 geompy.addToStudyInFather(part, refl_box_face, ssname)