Salome HOME
76d4e2811e3df5bed2a1a60cea39a91f7e6691c2
[modules/geom.git] / src / GEOM_SWIG / GEOM_TestOthers.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
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.
10 #
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.
15 #
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
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #  GEOM GEOM_SWIG : binding of C++ implementaion with Python
23 #  File   : GEOM_TestOthers.py
24 #  Author : Julia DOROVSKIKH
25 #  Module : GEOM
26 #  $Header$
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
31 #
32 import os
33
34 def TestExportImport (geompy, shape):
35
36   print "Test Export/Import ...",
37
38   tmpDir = os.getenv("TEMP")
39   if tmpDir == None:
40     tmpDir = "/tmp"
41
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"
47
48   if os.access(fileExportImport, os.F_OK):
49     if os.access(fileExportImport, os.W_OK):
50       os.remove(fileExportImport)
51     else:
52       fileExportImport = tmpDir + "/testExportImport1.brep"
53
54     if os.access(fileExportImportBREP, os.W_OK):
55       os.remove(fileExportImportBREP)
56     else:
57       fileExportImportBREP = tmpDir + "/testExportImportBREP1.brep"
58
59     if os.access(fileExportImportIGES, os.W_OK):
60       os.remove(fileExportImportIGES)
61     else:
62       fileExportImportIGES = tmpDir + "/testExportImportIGES1.iges"
63
64     if os.access(fileExportImportSTEP, os.W_OK):
65       os.remove(fileExportImportSTEP)
66     else:
67       fileExportImportSTEP = tmpDir + "/testExportImportSTEP1.step"
68
69   # Export
70   geompy.Export(shape, fileExportImport, "BREP")
71
72   # ExportBREP, ExportIGES, ExportSTEP
73   geompy.ExportBREP(shape, fileExportImportBREP)
74   geompy.ExportIGES(shape, fileExportImportIGES)
75   geompy.ExportSTEP(shape, fileExportImportSTEP)
76
77   # Import
78   Import = geompy.Import(fileExportImport, "BREP")
79
80   id_Import = geompy.addToStudy(Import, "Import")
81
82   # ImportBREP, ImportIGES, ImportSTEP
83   ImportBREP = geompy.ImportBREP(fileExportImportBREP)
84   ImportIGES = geompy.ImportIGES(fileExportImportIGES)
85   ImportSTEP = geompy.ImportSTEP(fileExportImportSTEP)
86
87   id_ImportBREP = geompy.addToStudy(ImportBREP, "ImportBREP")
88   id_ImportIGES = geompy.addToStudy(ImportIGES, "ImportIGES")
89   id_ImportSTEP = geompy.addToStudy(ImportSTEP, "ImportSTEP")
90
91   # Remove files for Export/Import testing
92   os.remove(fileExportImport)
93   os.remove(fileExportImportBREP)
94   os.remove(fileExportImportIGES)
95   os.remove(fileExportImportSTEP)
96
97   print "OK"
98
99
100 def TestOtherOperations (geompy, math):
101
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)
106
107   p11 = geompy.MakeVertex( 0,  0, 0)
108   p12 = geompy.MakeVertex(30,  0, 0)
109   p13 = geompy.MakeVertex(30, 30, 0)
110   p14 = geompy.MakeVertex( 0, 30, 0)
111
112   p21 = geompy.MakeVertex(10, 10, 0)
113   p22 = geompy.MakeVertex(20, 10, 0)
114   p23 = geompy.MakeVertex(20, 20, 0)
115   p24 = geompy.MakeVertex(10, 20, 0)
116
117   e11 = geompy.MakeEdge(p11, p12)
118   e12 = geompy.MakeEdge(p12, p13)
119   e13 = geompy.MakeEdge(p13, p14)
120   e14 = geompy.MakeEdge(p14, p11)
121
122   e21 = geompy.MakeEdge(p21, p22)
123   e22 = geompy.MakeEdge(p22, p23)
124   e23 = geompy.MakeEdge(p23, p24)
125   e24 = geompy.MakeEdge(p24, p21)
126
127   w1 = geompy.MakeWire([e11, e12, e13, e14])
128   w2 = geompy.MakeWire([e21, e22, e23, e24])
129   w3 = geompy.MakeTranslation(w2, 0, 0, 10)
130
131   id_w1 = geompy.addToStudy(w1, "Outside Wire")
132   id_w2 = geompy.addToStudy(w2, "Inside Wire")
133   id_w3 = geompy.addToStudy(w3, "Inside Wire, translated along OZ")
134
135   # MakeFaces
136   f12 = geompy.MakeFaces([w1, w2], 0)
137   id_f12 = geompy.addToStudy(f12, "MakeFaces WO + WI")
138
139   # Export/Import
140   TestExportImport(geompy, f12)
141
142   # OrientationChange
143   Box = geompy.MakeBoxDXDYDZ(200, 200, 200)
144   Orientation = geompy.OrientationChange(Box)
145   id_Orientation = geompy.addToStudy(Orientation, "OrientationChange")
146
147   # MakeCommon, MakeCut, MakeFuse, MakeSection
148   Sphere = geompy.MakeSphereR(100)
149
150   Common  = geompy.MakeCommon (Box, Sphere)
151   Cut     = geompy.MakeCut    (Box, Sphere)
152   Fuse    = geompy.MakeFuse   (Box, Sphere)
153   Section = geompy.MakeSection(Box, Sphere)
154
155   id_Common  = geompy.addToStudy(Common,  "Common")
156   id_Cut     = geompy.addToStudy(Cut,     "Cut")
157   id_Fuse    = geompy.addToStudy(Fuse,    "Fuse")
158   id_Section = geompy.addToStudy(Section, "Section")
159
160   # Partition
161   p100 = geompy.MakeVertex(100, 100, 100)
162   p300 = geompy.MakeVertex(300, 300, 300)
163   Box1 = geompy.MakeBoxTwoPnt(p100, p300)
164   #Partition = geompy.Partition([Box], [Box1], [], [Box])
165   Partition = geompy.Partition([Box], [Box1])
166   id_Partition = geompy.addToStudy(Partition, "Partition of Box by Box1")
167
168   # MakeMultiRotation1D, MakeMultiRotation2D
169   pz = geompy.MakeVertex(0, 0, 100)
170   vy = geompy.MakeVectorDXDYDZ(0, 100, 0)
171
172   MultiRot1D = geompy.MakeMultiRotation1D(f12, vy, pz, 6)
173   MultiRot2D = geompy.MakeMultiRotation2D(f12, vy, pz, 45, 6, 30, 3)
174
175   id_MultiRot1D = geompy.addToStudy(MultiRot1D, "MakeMultiRotation1D")
176   id_MultiRot2D = geompy.addToStudy(MultiRot2D, "MakeMultiRotation2D")
177
178   # MakeFilletAll
179   radius_fillet = 10.
180   face5 = geompy.SubShapeSorted(Box, geompy.ShapeType["FACE"], [5])
181   f_glob_id = geompy.GetSubShapeID(Box, face5)
182   SuppFace = geompy.SuppressFaces(Box, [f_glob_id])
183
184   MakeFilletAll = geompy.MakeFilletAll(SuppFace, radius_fillet)
185   id_MakeFilletAll = geompy.addToStudy(MakeFilletAll, "MakeFilletAll")
186
187   # MakeChamferAll
188   dimension_chamfer = 10.
189   MakeChamferAll = geompy.MakeChamferAll(SuppFace, dimension_chamfer)
190   id_MakeChamferAll = geompy.addToStudy(MakeChamferAll, "MakeChamferAll")
191
192   # MakeChamfer
193   d1 = 13.
194   d2 = 7.
195   box_faces = geompy.SubShapeAllSorted(Box, geompy.ShapeType["FACE"])
196   f_ind_1 = geompy.GetSubShapeID(Box, box_faces[0])
197   f_ind_2 = geompy.GetSubShapeID(Box, box_faces[1])
198   f_ind_3 = geompy.GetSubShapeID(Box, box_faces[2])
199
200   MakeChamfer = geompy.MakeChamfer(Box, d1, d2, geompy.ShapeType["FACE"],
201                                    [f_ind_1, f_ind_2, f_ind_3])
202   id_MakeChamfer = geompy.addToStudy(MakeChamfer, "MakeChamfer")
203
204   # NumberOfFaces
205   NumberOfFaces = geompy.NumberOfFaces(Box)
206   if NumberOfFaces != 6:
207     print "Bad number of faces in BOX!"
208
209   # NumberOfEdges
210   NumberOfEdges = geompy.NumberOfEdges(Box)
211   if NumberOfEdges != 12:
212     print "Bad number of edges in BOX!"
213
214   # MakeBlockExplode
215   Compound = geompy.MakeCompound([Box, Sphere])
216   MakeBlockExplode = geompy.MakeBlockExplode(Compound, 6, 6)
217
218   id_MakeBlockExplode = geompy.addToStudy(MakeBlockExplode[0], "MakeBlockExplode")
219
220   # CheckCompoundOfBlocks
221   p1 = geompy.MakeVertex(200, 0, 0)
222   p2 = geompy.MakeVertex(400, 200, 200)
223   p3 = geompy.MakeVertex(400, 50, 50)
224   p4 = geompy.MakeVertex(600, 250, 250)
225
226   Box2 = geompy.MakeBoxTwoPnt(p1, p2)
227   Box3 = geompy.MakeBoxTwoPnt(p3, p4)
228   Cyl  = geompy.MakeCylinderRH(50, 300)
229   Cone = geompy.MakeConeR1R2H(150, 10, 400)
230
231   Compound1 = geompy.MakeCompound([Box, Cyl, Cone, Box3, Box2])
232
233   IsValid = geompy.CheckCompoundOfBlocks(Compound1)
234   if IsValid == 0:
235     print "The Blocks Compound is NOT VALID"
236   else:
237     print "The Blocks Compound is VALID"
238
239   IsValid = geompy.CheckCompoundOfBlocks(Box)
240   if IsValid == 0:
241     print "The Box is NOT VALID"
242   else:
243     print "The Box is VALID"
244
245   # GetSame
246   Cone_ss = geompy.GetSame(Compound1, Cone)
247   id_Cone_ss = geompy.addToStudyInFather(Compound1, Cone_ss, "Cone subshape")
248
249   # test geometrical groups
250
251   # CreateGroup
252   CreateGroup = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
253
254   id_CreateGroup = geompy.addToStudy(CreateGroup, "CreateGroup")
255
256   # AddObject
257   f_ind_4 = geompy.GetSubShapeID(Box, box_faces[3])
258   f_ind_5 = geompy.GetSubShapeID(Box, box_faces[4])
259   f_ind_6 = geompy.GetSubShapeID(Box, box_faces[5])
260
261   geompy.AddObject(CreateGroup, f_ind_6) # box_faces[5]
262   geompy.AddObject(CreateGroup, f_ind_1) # box_faces[0]
263   geompy.AddObject(CreateGroup, f_ind_4) # box_faces[3]
264   # Now contains f_ind_6, f_ind_1, f_ind_4
265
266   # UnionList
267   geompy.UnionList(CreateGroup, [box_faces[2], box_faces[4], box_faces[5]])
268   # Now contains f_ind_6, f_ind_1, f_ind_4, f_ind_3, f_ind_5
269
270   # RemoveObject(theGroup, theSubShapeID)
271   geompy.RemoveObject(CreateGroup, f_ind_1) # box_faces[0]
272   # Now contains f_ind_6, f_ind_4, f_ind_3, f_ind_5
273
274   # DifferenceList
275   geompy.DifferenceList(CreateGroup, [box_faces[1], box_faces[0], box_faces[3]])
276   # Now contains f_ind_6, f_ind_3, f_ind_5
277
278   # GetObjectIDs
279   GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
280
281   print "Group of Box's faces includes the following IDs:"
282   print "(must be ", f_ind_6, ", ", f_ind_3, " and ", f_ind_5, ")"
283   for ObjectID in GetObjectIDs:
284     print " ", ObjectID
285
286   # GetMainShape
287   BoxCopy = geompy.GetMainShape(CreateGroup)
288
289   # DifferenceIDs
290   geompy.DifferenceIDs(CreateGroup, [f_ind_3, f_ind_5])
291   # Now contains f_ind_6
292
293   # UnionIDs
294   geompy.UnionIDs(CreateGroup, [f_ind_1, f_ind_2, f_ind_6])
295   # Now contains f_ind_6, f_ind_1, f_ind_2
296
297   # Check
298   GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
299   print "Group of Box's faces includes the following IDs:"
300   print "(must be ", f_ind_6, ", ", f_ind_1, " and ", f_ind_2, ")"
301   for ObjectID in GetObjectIDs:
302     print " ", ObjectID
303
304   # -----------------------------------------------------------------------------
305   # enumeration ShapeTypeString as a dictionary
306   # -----------------------------------------------------------------------------
307   ShapeTypeString = {'0':"COMPOUND", '1':"COMPSOLID", '2':"SOLID", '3':"SHELL",
308                      '4':"FACE", '5':"WIRE", '6':"EDGE", '7':"VERTEX", '8':"SHAPE"}
309
310   GroupType = geompy.GetType(CreateGroup)
311   print "Type of elements of the created group is ", ShapeTypeString[`GroupType`]
312
313   # Prepare data for the following operations
314   p0 = geompy.MakeVertex(0, 0, 0)
315   b0 = geompy.MakeBox(-50, -50, -50, 50, 50, 50)
316   s0 = geompy.MakeSphereR(100)
317
318   id_b0 = geompy.addToStudy(b0, "b0")
319   id_s0 = geompy.addToStudy(s0, "s0")
320
321   v_0pp = geompy.MakeVectorDXDYDZ( 0,  1,  1)
322   #v_0np = geompy.MakeVectorDXDYDZ( 0, -1,  1)
323   #v_p0p = geompy.MakeVectorDXDYDZ( 1,  0,  1)
324   #v_n0p = geompy.MakeVectorDXDYDZ(-1,  0,  1)
325   #v_pp0 = geompy.MakeVectorDXDYDZ( 1,  1,  0)
326   #v_np0 = geompy.MakeVectorDXDYDZ(-1,  1,  0)
327   v_0n0 = geompy.MakeVectorDXDYDZ( 0, -1,  0)
328
329   #pln_0pp = geompy.MakePlane(p0, v_0pp, 300)
330   #pln_0np = geompy.MakePlane(p0, v_0np, 300)
331   #pln_p0p = geompy.MakePlane(p0, v_p0p, 300)
332   #pln_n0p = geompy.MakePlane(p0, v_n0p, 300)
333   #pln_pp0 = geompy.MakePlane(p0, v_pp0, 300)
334   #pln_np0 = geompy.MakePlane(p0, v_np0, 300)
335   #
336   #part_objs = [b0, pln_0pp, pln_0np, pln_p0p, pln_n0p, pln_pp0, pln_np0]
337   #part_tool_1 = geompy.MakePartition(part_objs, [], [], [b0])
338   #part_tool_1 = geompy.MakePartition(part_objs)
339   #
340   #id_part_tool_1 = geompy.addToStudy(part_tool_1, "part_tool_1")
341   #
342   #pt_pnt_1  = geompy.MakeVertex( 55,   0,  55)
343   #pt_pnt_2  = geompy.MakeVertex(  0,  55,  55)
344   #pt_pnt_3  = geompy.MakeVertex(-55,   0,  55)
345   #pt_pnt_4  = geompy.MakeVertex(  0, -55,  55)
346   #pt_pnt_5  = geompy.MakeVertex( 55,  55,   0)
347   #pt_pnt_6  = geompy.MakeVertex( 55, -55,   0)
348   #pt_pnt_7  = geompy.MakeVertex(-55,  55,   0)
349   #pt_pnt_8  = geompy.MakeVertex(-55, -55,   0)
350   #pt_pnt_9  = geompy.MakeVertex( 55,   0, -55)
351   #pt_pnt_10 = geompy.MakeVertex(  0,  55, -55)
352   #pt_pnt_11 = geompy.MakeVertex(-55,   0, -55)
353   #pt_pnt_12 = geompy.MakeVertex(  0, -55, -55)
354   #
355   #pt_face_1  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_1)
356   #pt_face_2  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_2)
357   #pt_face_3  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_3)
358   #pt_face_4  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_4)
359   #pt_face_5  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_5)
360   #pt_face_6  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_6)
361   #pt_face_7  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_7)
362   #pt_face_8  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_8)
363   #pt_face_9  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_9)
364   #pt_face_10 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_10)
365   #pt_face_11 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_11)
366   #pt_face_12 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_12)
367   #
368   #pt_box = geompy.GetBlockNearPoint(part_tool_1, p0)
369   #
370   #comp_parts = [pt_face_1, pt_face_4, pt_face_7, pt_face_10,
371   #              pt_face_2, pt_face_5, pt_face_8, pt_face_11,
372   #              #pt_face_3, pt_face_6, pt_face_9, pt_face_12, pt_box]
373   #              pt_face_3, pt_face_6, pt_face_9, pt_face_12]
374   #part_tool = geompy.MakeCompound(comp_parts)
375   #id_part_tool = geompy.addToStudy(part_tool, "part_tool")
376   #
377   #part = geompy.MakePartition([s0], [part_tool])
378   #
379   #part_tools = [pt_face_1, pt_face_4, pt_face_7, pt_face_10,
380   #              pt_face_2, pt_face_5, pt_face_8, pt_face_11,
381   #              pt_face_3, pt_face_6, pt_face_9, pt_face_12, b0]
382   #part = geompy.MakePartition([s0], part_tools)
383
384   p1 = geompy.MakeVertex(50, 0, 0)
385   p2 = geompy.MakeVertex(-50, 0, 0)
386   p3 = geompy.MakeVertex(0, 50, 0)
387   p4 = geompy.MakeVertex(0, -50, 0)
388   p5 = geompy.MakeVertex(0, 0, 50)
389   p6 = geompy.MakeVertex(0, 0, -50)
390
391   plnX1 = geompy.MakePlane(p1, vx, 300)
392   plnX2 = geompy.MakePlane(p2, vx, 300)
393   plnY1 = geompy.MakePlane(p3, vy, 300)
394   plnY2 = geompy.MakePlane(p4, vy, 300)
395   plnZ1 = geompy.MakePlane(p5, vz, 300)
396   plnZ2 = geompy.MakePlane(p6, vz, 300)
397
398   #part = geompy.MakePartition([s0], [plnX1,plnX2,plnY1,plnY2,plnZ1,plnZ2])
399   part = geompy.MakePartition([s0], [plnX1])
400   part = geompy.MakePartition([part], [plnX2])
401   part = geompy.MakePartition([part], [plnY1])
402   part = geompy.MakePartition([part], [plnY2])
403   part = geompy.MakePartition([part], [plnZ1])
404   part = geompy.MakePartition([part], [plnZ2])
405   geompy.addToStudy(part, "part")
406
407   # GetFreeFacesIDs
408   anIDs = geompy.GetFreeFacesIDs(part)
409   freeFaces = geompy.GetSubShape(part, anIDs)
410
411   geompy.addToStudy(freeFaces, "freeFaces")
412
413   # RemoveExtraEdges
414   freeFacesWithoutExtra = geompy.RemoveExtraEdges(freeFaces)
415
416   geompy.addToStudy(freeFacesWithoutExtra, "freeFacesWithoutExtra")
417
418   # GetSharedShapes
419   sharedFaces = geompy.GetSharedShapes(part, freeFacesWithoutExtra,
420                                        geompy.ShapeType["FACE"])
421
422   for shFace in sharedFaces:
423     geompy.addToStudy(shFace, "sharedFace")
424
425   # CheckAndImprove
426   blocksComp = geompy.CheckAndImprove(part)
427
428   geompy.addToStudy(blocksComp, "blocksComp")
429
430   # Propagate
431   listChains = geompy.Propagate(blocksComp)
432
433   for chain in listChains:
434     geompy.addToStudyInFather(blocksComp, chain, "propagation chain")
435
436   # GetPoint(theShape, theX, theY, theZ, theEpsilon)
437   #
438   # (-50,  50, 50) .-----. (50,  50, 50)
439   #      pb0_top_1 |     |
440   #                |     . pmidle
441   #                |     |
442   # (-50, -50, 50) '-----' (50, -50, 50)
443   #
444   pb0_top_1 = geompy.GetPoint(blocksComp, -50,  50,  50, 0.01)
445   pb0_bot_1 = geompy.GetPoint(blocksComp, -50, -50, -50, 0.01)
446
447   geompy.addToStudyInFather(blocksComp, pb0_top_1, "point from blocksComp (-50,  50,  50)")
448   geompy.addToStudyInFather(blocksComp, pb0_bot_1, "point from blocksComp (-50, -50, -50)")
449
450   # GetEdgeNearPoint(theShape, thePoint)
451   pmidle = geompy.MakeVertex(50, 0, 50)
452   edge1 = geompy.GetEdgeNearPoint(blocksComp, pmidle)
453
454   geompy.addToStudyInFather(blocksComp, edge1, "edge near point (50, 0, 50)")
455
456   # GetBlockByParts(theCompound, theParts)
457   b0_image = geompy.GetBlockByParts(blocksComp, [pb0_top_1, pb0_bot_1, edge1])
458
459   geompy.addToStudyInFather(blocksComp, b0_image, "b0 image")
460
461   # GetShapesOnPlane
462   faces_on_pln = geompy.GetShapesOnPlane(blocksComp, geompy.ShapeType["FACE"],
463                                          v_0pp, geompy.GEOM.ST_ONIN)
464   for face_i in faces_on_pln:
465     geompy.addToStudy(face_i, "Face on Plane (N = (0, 1, 1)) or below it")
466
467   # GetShapesOnPlaneIDs
468   faces_above_pln_ids = geompy.GetShapesOnPlaneIDs(blocksComp, geompy.ShapeType["FACE"],
469                                                    v_0pp, geompy.GEOM.ST_OUT)
470   faces_above = geompy.CreateGroup(blocksComp, geompy.ShapeType["FACE"])
471   geompy.UnionIDs(faces_above, faces_above_pln_ids)
472   geompy.addToStudy(faces_above, "Group of faces above Plane (N = (0, 1, 1))")
473
474   # GetShapesOnPlaneWithLocation
475   Loc = geompy.MakeVertex(0, -50, 0)
476   edges_on_pln = geompy.GetShapesOnPlaneWithLocation(blocksComp, geompy.ShapeType["EDGE"],
477                                                      v_0n0, Loc, geompy.GEOM.ST_ON)
478   for edge_i in edges_on_pln:
479     geompy.addToStudy(edge_i, "Edge on Plane (N = (0, -1, 0) & Location = (0, -50, 0)")
480     
481   # GetShapesOnPlaneWithLocationIDs
482   edges_on_pln_ids = geompy.GetShapesOnPlaneWithLocationIDs(
483            blocksComp, geompy.ShapeType["EDGE"], v_0n0, Loc, geompy.GEOM.ST_ON)
484   group_edges_on_pln = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
485   geompy.UnionIDs(group_edges_on_pln, edges_on_pln_ids)
486   grname = "Group of edges on Plane (N = (0, -1, 0) & Location = (0, -50, 0))"
487   geompy.addToStudy(group_edges_on_pln, grname)
488
489   # GetShapesOnCylinder
490   edges_out_cyl = geompy.GetShapesOnCylinder(blocksComp, geompy.ShapeType["EDGE"],
491                                              vy, 55, geompy.GEOM.ST_OUT)
492   for edge_i in edges_out_cyl:
493     geompy.addToStudy(edge_i, "Edge out of Cylinder (axis = (0, 1, 0), r = 55)")
494
495   # GetShapesOnCylinderIDs
496   edges_in_cyl_ids = geompy.GetShapesOnCylinderIDs(blocksComp, geompy.ShapeType["EDGE"],
497                                                    vy, 80, geompy.GEOM.ST_IN)
498   edges_in = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
499   geompy.UnionIDs(edges_in, edges_in_cyl_ids)
500   geompy.addToStudy(edges_in, "Group of edges inside Cylinder (axis = (0, 1, 0), r = 55)")
501
502   # GetShapesOnSphere
503   vertices_on_sph = geompy.GetShapesOnSphere(blocksComp, geompy.ShapeType["VERTEX"],
504                                              p0, 100, geompy.GEOM.ST_ON)
505   for vertex_i in vertices_on_sph:
506     geompy.addToStudy(vertex_i, "Vertex on Sphere (center = (0, 0, 0), r = 100)")
507
508   # GetShapesOnSphereIDs
509   vertices_on_sph_ids = geompy.GetShapesOnSphereIDs(blocksComp, geompy.ShapeType["VERTEX"],
510                                                     p0, 100, geompy.GEOM.ST_ON)
511   vertices_on = geompy.CreateGroup(blocksComp, geompy.ShapeType["VERTEX"])
512   geompy.UnionIDs(vertices_on, vertices_on_sph_ids)
513   geompy.addToStudy(vertices_on, "Group of vertices on Sphere (center = (0, 0, 0), r = 100)")
514
515   # GetShapesOnQuadrangle
516
517   geompy.addToStudy(f12, "F12" )
518
519   bl = geompy.MakeVertex(10,-10, 0)
520   br = geompy.MakeVertex(40,-10, 0)
521   tr = geompy.MakeVertex(40, 20, 0)
522   tl = geompy.MakeVertex(10, 20, 0)
523   qe1 = geompy.MakeEdge(bl, br)
524   qe2 = geompy.MakeEdge(br, tr)
525   qe3 = geompy.MakeEdge(tr, tl)
526   qe4 = geompy.MakeEdge(tl, bl)
527   quadrangle = geompy.MakeWire([qe1, qe2, qe3, qe4])
528   geompy.addToStudy(quadrangle, "Quadrangle")
529
530   edges_onin_quad = geompy.GetShapesOnQuadrangle(f12, geompy.ShapeType["EDGE"],
531                                                  tl, tr, bl, br, geompy.GEOM.ST_ONIN)
532   comp = geompy.MakeCompound(edges_onin_quad)
533   geompy.addToStudy(comp, "Edges of F12 ONIN Quadrangle")
534   if len( edges_onin_quad ) != 4:
535     print "Error in GetShapesOnQuadrangle()"
536
537   # GetShapesOnQuadrangleIDs
538   vertices_on_quad_ids = geompy.GetShapesOnQuadrangleIDs(f12, geompy.ShapeType["VERTEX"],
539                                                          tl, tr, bl, br, geompy.GEOM.ST_ON)
540   vertices_on_quad = geompy.CreateGroup(f12, geompy.ShapeType["VERTEX"])
541   geompy.UnionIDs(vertices_on_quad, vertices_on_quad_ids)
542   geompy.addToStudy(vertices_on_quad, "Group of vertices on Quadrangle F12")
543
544   # GetShapesOnBox
545   edges_on_box = geompy.GetShapesOnBox(b0, part, geompy.ShapeType["EDGE"],
546                                        geompy.GEOM.ST_ON)
547   comp = geompy.MakeCompound(edges_on_box)
548   geompy.addToStudy(comp, "Edges of part ON box b0")
549   if len( edges_on_box ) != 12:
550     print "Error in GetShapesOnBox()"
551
552   # GetShapesOnBoxIDs
553   faces_on_box_ids = geompy.GetShapesOnBoxIDs(b0, part, geompy.ShapeType["FACE"],
554                                               geompy.GEOM.ST_ON)
555   faces_on_box = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
556   geompy.UnionIDs(faces_on_box, faces_on_box_ids)
557   geompy.addToStudyInFather(part, faces_on_box, "Group of faces on box b0")
558
559   # Prepare arguments for GetShapesOnShape
560   sph1 = geompy.MakeSphere(50, 50,  50, 40)
561   sph2 = geompy.MakeSphere(50, 50, -50, 40)
562   pcyl = geompy.MakeVertex(50, 50, -50)
563   cyli = geompy.MakeCylinder(pcyl, vz, 40, 100)
564   fuse = geompy.MakeFuse(sph1, cyli)
565   fuse = geompy.MakeFuse(fuse, sph2)
566   # As after Fuse we have a compound, we need to obtain a solid from it
567   shsh = geompy.SubShapeAll(fuse, geompy.ShapeType["SOLID"])
568   sh_1 = shsh[0]
569   geompy.addToStudy(sh_1, "sh_1")
570
571   # GetShapesOnShape
572   faces_in_sh = geompy.GetShapesOnShape(sh_1, part, geompy.ShapeType["FACE"],
573                                         geompy.GEOM.ST_IN)
574   comp = geompy.MakeCompound(faces_in_sh)
575   geompy.addToStudy(comp, "Faces of part IN shape sh_1")
576   if len(faces_in_sh) != 11:
577     print "Error in GetShapesOnShape()"
578
579   # GetShapesOnShapeAsCompound
580   faces_in_sh_c = geompy.GetShapesOnShapeAsCompound(sh_1, part, geompy.ShapeType["FACE"],
581                                                     geompy.GEOM.ST_IN)
582   geompy.addToStudy(faces_in_sh_c, "Faces of part IN shape sh_1 (as compound)")
583
584   # GetShapesOnShapeIDs
585   edges_in_sh_ids = geompy.GetShapesOnShapeIDs(sh_1, part, geompy.ShapeType["EDGE"],
586                                                geompy.GEOM.ST_IN)
587   edges_in_sh = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
588   geompy.UnionIDs(edges_in_sh, edges_in_sh_ids)
589   geompy.addToStudyInFather(part, edges_in_sh, "Group of edges in shape sh_1")
590   if len(edges_in_sh_ids) != 15:
591     print "Error in GetShapesOnShapeIDs()"
592
593   # Prepare arguments for GetInPlace and GetInPlaceByHistory
594   box5 = geompy.MakeBoxDXDYDZ(100, 100, 100)
595   box6 = geompy.MakeTranslation(box5, 50, 50, 0)
596
597   geompy.addToStudy(box5, "Box 5")
598   geompy.addToStudy(box6, "Box 6")
599
600   part = geompy.MakePartition([box5], [box6])
601   geompy.addToStudy(part, "Partitioned")
602
603   box5_faces = geompy.SubShapeAll(box5, geompy.ShapeType["FACE"])
604   box6_faces = geompy.SubShapeAll(box6, geompy.ShapeType["FACE"])
605
606   for ifa in range(6):
607     geompy.addToStudyInFather(box5, box5_faces[ifa], "Face" + `ifa + 1`)
608     geompy.addToStudyInFather(box6, box6_faces[ifa], "Face" + `ifa + 1`)
609
610   # GetInPlace(theShapeWhere, theShapeWhat)
611   ibb = 5
612   faces_list = [box5_faces, box6_faces]
613   for afaces in faces_list:
614     ifa = 1
615     for aface in afaces:
616       refl_box_face = geompy.GetInPlace(part, aface)
617       if ibb == 6 and (ifa == 2 or ifa == 4):
618         # For two faces of the tool box
619         # there is no reflection in the result.
620         if refl_box_face is not None:
621           error = "Result of GetInPlace must be NULL for face "
622           error += `ifa` + " of box " + `ibb`
623           raise RuntimeError, error
624       else:
625         ssname = "Reflection of face " + `ifa` + " of box " + `ibb`
626         geompy.addToStudyInFather(part, refl_box_face, ssname)
627       ifa = ifa + 1
628     ibb = ibb + 1
629
630   # GetInPlaceByHistory(theShapeWhere, theShapeWhat)
631   part = geompy.MakePartition([box5], [box6])
632   geompy.addToStudy(part, "Partitioned")
633
634   ibb = 5
635   faces_list = [box5_faces, box6_faces]
636   for afaces in faces_list:
637     ifa = 1
638     for aface in afaces:
639       ssname = "Reflection of face " + `ifa` + " of box " + `ibb` + " (by history)"
640       if ibb == 6 and (ifa == 2 or ifa == 4):
641         # use IDL interface directly to avoid error message appearence in Python console
642         refl_box_face = geompy.ShapesOp.GetInPlaceByHistory(part, aface)
643         if refl_box_face is not None:
644           geompy.addToStudyInFather(part, refl_box_face, ssname)
645           error = "Result of GetInPlaceByHistory must be NULL for face "
646           error += `ifa` + " of box " + `ibb`
647           raise RuntimeError, error
648       else:
649         # use geompy interface
650         refl_box_face = geompy.GetInPlaceByHistory(part, aface)
651         geompy.addToStudyInFather(part, refl_box_face, ssname)
652       ifa = ifa + 1
653     ibb = ibb + 1
654
655 #END