Salome HOME
Merge from V6_main (04/10/2012)
[modules/geom.git] / src / GEOM_SWIG / GEOM_TestOthers.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
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.
11 #
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.
16 #
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
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23 #  File   : GEOM_TestOthers.py
24 #  Author : Julia DOROVSKIKH
25 #  Module : GEOM
26 #  $Header$
27 #
28 # ! Please, if you edit this example file, update also
29 # ! GEOM_SRC/doc/salome/gui/GEOM/input/tui_test_others.doc
30 # ! as some sequences of symbols from this example are used during
31 # ! documentation generation to identify certain places of this file
32
33 import os
34
35 def TestExportImport (geompy, shape):
36
37   print "Test Export/Import ...",
38
39   tmpDir = os.getenv("TEMP")
40   if tmpDir == None:
41     tmpDir = "/tmp"
42
43   # Files for Export/Import testing
44   fileExportImport = tmpDir + "/testExportImport.brep"
45   fileExportImportBREP = tmpDir + "/testExportImportBREP.brep"
46   fileExportImportIGES = tmpDir + "/testExportImportIGES.iges"
47   fileExportImportSTEP = tmpDir + "/testExportImportSTEP.step"
48
49   if os.access(fileExportImport, os.F_OK):
50     if os.access(fileExportImport, os.W_OK):
51       os.remove(fileExportImport)
52     else:
53       fileExportImport = tmpDir + "/testExportImport1.brep"
54
55     if os.access(fileExportImportBREP, os.W_OK):
56       os.remove(fileExportImportBREP)
57     else:
58       fileExportImportBREP = tmpDir + "/testExportImportBREP1.brep"
59
60     if os.access(fileExportImportIGES, os.W_OK):
61       os.remove(fileExportImportIGES)
62     else:
63       fileExportImportIGES = tmpDir + "/testExportImportIGES1.iges"
64
65     if os.access(fileExportImportSTEP, os.W_OK):
66       os.remove(fileExportImportSTEP)
67     else:
68       fileExportImportSTEP = tmpDir + "/testExportImportSTEP1.step"
69
70   # Export
71   geompy.Export(shape, fileExportImport, "BREP")
72
73   # ExportBREP, ExportIGES, ExportSTEP
74   geompy.ExportBREP(shape, fileExportImportBREP)
75   geompy.ExportIGES(shape, fileExportImportIGES)
76   geompy.ExportSTEP(shape, fileExportImportSTEP)
77
78   # Import
79   Import = geompy.ImportFile(fileExportImport, "BREP")
80
81   id_Import = geompy.addToStudy(Import, "Import")
82
83   # ImportBREP, ImportIGES, ImportSTEP
84   ImportBREP = geompy.ImportBREP(fileExportImportBREP)
85   ImportIGES = geompy.ImportIGES(fileExportImportIGES)
86   ImportSTEP = geompy.ImportSTEP(fileExportImportSTEP)
87
88   id_ImportBREP = geompy.addToStudy(ImportBREP, "ImportBREP")
89   id_ImportIGES = geompy.addToStudy(ImportIGES, "ImportIGES")
90   id_ImportSTEP = geompy.addToStudy(ImportSTEP, "ImportSTEP")
91
92   # Remove files for Export/Import testing
93   os.remove(fileExportImport)
94   os.remove(fileExportImportBREP)
95   os.remove(fileExportImportIGES)
96   os.remove(fileExportImportSTEP)
97
98   # Test RestoreShape from binary BRep stream
99   aStream = shape.GetShapeStream()
100   aNewShape = geompy.RestoreShape(aStream)
101   geompy.addToStudy(aNewShape, "aNewShape")
102
103   print "OK"
104
105
106 def TestOtherOperations (geompy, math):
107
108   # prepare data for further operations
109   vx = geompy.MakeVectorDXDYDZ( 1,  0,  0)
110   vy = geompy.MakeVectorDXDYDZ( 0,  1,  0)
111   vz = geompy.MakeVectorDXDYDZ( 0,  0,  1)
112
113   v_y = geompy.MakeVectorDXDYDZ( 0, -1,  0)
114
115   p11 = geompy.MakeVertex( 0,  0, 0)
116   p12 = geompy.MakeVertex(30,  0, 0)
117   p13 = geompy.MakeVertex(30, 30, 0)
118   p14 = geompy.MakeVertex( 0, 30, 0)
119
120   p21 = geompy.MakeVertex(10, 10, 0)
121   p22 = geompy.MakeVertex(20, 10, 0)
122   p23 = geompy.MakeVertex(20, 20, 0)
123   p24 = geompy.MakeVertex(10, 20, 0)
124
125   e11 = geompy.MakeEdge(p11, p12)
126   e12 = geompy.MakeEdge(p12, p13)
127   e13 = geompy.MakeEdge(p13, p14)
128   e14 = geompy.MakeEdge(p14, p11)
129
130   e21 = geompy.MakeEdge(p21, p22)
131   e22 = geompy.MakeEdge(p22, p23)
132   e23 = geompy.MakeEdge(p23, p24)
133   e24 = geompy.MakeEdge(p24, p21)
134
135   w1 = geompy.MakeWire([e11, e12, e13, e14])
136   w2 = geompy.MakeWire([e21, e22, e23, e24])
137   w3 = geompy.MakeTranslation(w2, 0, 0, 10)
138
139   id_w1 = geompy.addToStudy(w1, "Outside Wire")
140   id_w2 = geompy.addToStudy(w2, "Inside Wire")
141   id_w3 = geompy.addToStudy(w3, "Inside Wire, translated along OZ")
142
143   # MakeFaces
144   f12 = geompy.MakeFaces([w1, w2], 0)
145   id_f12 = geompy.addToStudy(f12, "MakeFaces WO + WI")
146
147   # Export/Import
148   TestExportImport(geompy, f12)
149
150   # OrientationChange
151   Box = geompy.MakeBoxDXDYDZ(200, 200, 200)
152   geompy.addToStudy(Box, "Box")
153   Orientation = geompy.OrientationChange(Box)
154   id_Orientation = geompy.addToStudy(Orientation, "OrientationChange")
155
156   # MakeCommon, MakeCut, MakeFuse, MakeSection
157   Sphere = geompy.MakeSphereR(100)
158
159   Common  = geompy.MakeCommon (Box, Sphere)
160   Cut     = geompy.MakeCut    (Box, Sphere)
161   Fuse    = geompy.MakeFuse   (Box, Sphere)
162   Section = geompy.MakeSection(Box, Sphere)
163
164   id_Common  = geompy.addToStudy(Common,  "Common")
165   id_Cut     = geompy.addToStudy(Cut,     "Cut")
166   id_Fuse    = geompy.addToStudy(Fuse,    "Fuse")
167   id_Section = geompy.addToStudy(Section, "Section")
168
169   # Partition
170   p100 = geompy.MakeVertex(100, 100, 100)
171   p300 = geompy.MakeVertex(300, 300, 300)
172   Box1 = geompy.MakeBoxTwoPnt(p100, p300)
173   #Partition = geompy.Partition([Box], [Box1], [], [Box])
174   Partition = geompy.Partition([Box], [Box1])
175   id_Partition = geompy.addToStudy(Partition, "Partition of Box by Box1")
176
177   # MakeMultiRotation1D, MakeMultiRotation2D
178   pz = geompy.MakeVertex(0, 0, 100)
179   vy = geompy.MakeVectorDXDYDZ(0, 100, 0)
180
181   MultiRot1D = geompy.MakeMultiRotation1D(f12, vy, pz, 6)
182   MultiRot2D = geompy.MakeMultiRotation2D(f12, vy, pz, 45, 6, 30, 3)
183
184   id_MultiRot1D = geompy.addToStudy(MultiRot1D, "MakeMultiRotation1D")
185   id_MultiRot2D = geompy.addToStudy(MultiRot2D, "MakeMultiRotation2D")
186
187   # MakeFilletAll
188   radius_fillet = 10.
189   face5 = geompy.SubShapeSortedCentres(Box, geompy.ShapeType["FACE"], [5])
190   f_glob_id = geompy.GetSubShapeID(Box, face5)
191   SuppFace = geompy.SuppressFaces(Box, [f_glob_id])
192
193   MakeFilletAll = geompy.MakeFilletAll(SuppFace, radius_fillet)
194   id_MakeFilletAll = geompy.addToStudy(MakeFilletAll, "MakeFilletAll")
195
196   # MakeChamferAll
197   dimension_chamfer = 10.
198   MakeChamferAll = geompy.MakeChamferAll(SuppFace, dimension_chamfer)
199   id_MakeChamferAll = geompy.addToStudy(MakeChamferAll, "MakeChamferAll")
200
201   # MakeChamfer
202   d1 = 13.
203   d2 = 7.
204   box_faces = geompy.SubShapeAllSortedCentres(Box, geompy.ShapeType["FACE"])
205   f_ind_1 = geompy.GetSubShapeID(Box, box_faces[0])
206   f_ind_2 = geompy.GetSubShapeID(Box, box_faces[1])
207   f_ind_3 = geompy.GetSubShapeID(Box, box_faces[2])
208
209   MakeChamfer = geompy.MakeChamfer(Box, d1, d2, geompy.ShapeType["FACE"],
210                                    [f_ind_1, f_ind_2, f_ind_3])
211   id_MakeChamfer = geompy.addToStudy(MakeChamfer, "MakeChamfer")
212
213   # NumberOf
214   NumberOfFaces = geompy.NumberOfFaces(Box)
215   if NumberOfFaces != 6:
216     print "Bad number of faces in BOX!"
217
218   NumberOfEdges = geompy.NumberOfEdges(Box)
219   if NumberOfEdges != 12:
220     print "Bad number of edges in BOX!"
221
222   NumberOfSolids = geompy.NumberOfSolids(Box)
223   if NumberOfSolids != 1:
224     print "Bad number of solids in BOX!"
225
226   NumberOfShapes = geompy.NumberOfSubShapes(Box, geompy.ShapeType["SHAPE"])
227   if NumberOfShapes != 34:
228     print "Bad number of shapes in BOX!"
229
230   # MakeBlockExplode
231   Compound = geompy.MakeCompound([Box, Sphere])
232   MakeBlockExplode = geompy.MakeBlockExplode(Compound, 6, 6)
233
234   id_MakeBlockExplode = geompy.addToStudy(MakeBlockExplode[0], "MakeBlockExplode")
235
236   # CheckCompoundOfBlocks
237   p1 = geompy.MakeVertex(200, 0, 0)
238   p2 = geompy.MakeVertex(400, 200, 200)
239   p3 = geompy.MakeVertex(400, 50, 50)
240   p4 = geompy.MakeVertex(600, 250, 250)
241
242   Box2 = geompy.MakeBoxTwoPnt(p1, p2)
243   Box3 = geompy.MakeBoxTwoPnt(p3, p4)
244   Cyl  = geompy.MakeCylinderRH(50, 300)
245   Cone = geompy.MakeConeR1R2H(150, 10, 400)
246
247   Compound1 = geompy.MakeCompound([Box, Cyl, Cone, Box3, Box2])
248
249   IsValid = geompy.CheckCompoundOfBlocks(Compound1)
250   if IsValid == 0:
251     print "The Blocks Compound is NOT VALID"
252     (NonBlocks, NonQuads) = geompy.GetNonBlocks(Compound1)
253     if NonBlocks is not None:
254       geompy.addToStudyInFather(Compound1, NonBlocks, "Group of non-hexahedral solids")
255     if NonQuads is not None:
256       geompy.addToStudyInFather(Compound1, NonQuads, "Group of non-quadrangular faces")
257   else:
258     print "The Blocks Compound is VALID"
259
260   IsValid = geompy.CheckCompoundOfBlocks(Box)
261   if IsValid == 0:
262     print "The Box is NOT VALID"
263   else:
264     print "The Box is VALID"
265
266   # GetSame
267   Cone_ss = geompy.GetSame(Compound1, Cone)
268   id_Cone_ss = geompy.addToStudyInFather(Compound1, Cone_ss, "Cone subshape")
269
270   # test geometrical groups
271
272   # CreateGroup
273   CreateGroup = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
274
275   id_CreateGroup = geompy.addToStudy(CreateGroup, "CreateGroup")
276
277   # AddObject
278   f_ind_4 = geompy.GetSubShapeID(Box, box_faces[3])
279   f_ind_5 = geompy.GetSubShapeID(Box, box_faces[4])
280   f_ind_6 = geompy.GetSubShapeID(Box, box_faces[5])
281
282   geompy.AddObject(CreateGroup, f_ind_6) # box_faces[5]
283   geompy.AddObject(CreateGroup, f_ind_1) # box_faces[0]
284   geompy.AddObject(CreateGroup, f_ind_4) # box_faces[3]
285   # Now contains f_ind_6, f_ind_1, f_ind_4
286
287   # UnionList
288   geompy.UnionList(CreateGroup, [box_faces[2], box_faces[4], box_faces[5]])
289   # Now contains f_ind_6, f_ind_1, f_ind_4, f_ind_3, f_ind_5
290
291   # RemoveObject(theGroup, theSubShapeID)
292   geompy.RemoveObject(CreateGroup, f_ind_1) # box_faces[0]
293   # Now contains f_ind_6, f_ind_4, f_ind_3, f_ind_5
294
295   # DifferenceList
296   geompy.DifferenceList(CreateGroup, [box_faces[1], box_faces[0], box_faces[3]])
297   # Now contains f_ind_6, f_ind_3, f_ind_5
298
299   # GetObjectIDs
300   GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
301
302   print "Group of Box's faces includes the following IDs:"
303   print "(must be ", f_ind_6, ", ", f_ind_3, " and ", f_ind_5, ")"
304   for ObjectID in GetObjectIDs:
305     print " ", ObjectID
306
307   # GetMainShape
308   BoxCopy = geompy.GetMainShape(CreateGroup)
309
310   # DifferenceIDs
311   geompy.DifferenceIDs(CreateGroup, [f_ind_3, f_ind_5])
312   # Now contains f_ind_6
313
314   # UnionIDs
315   geompy.UnionIDs(CreateGroup, [f_ind_1, f_ind_2, f_ind_6])
316   # Now contains f_ind_6, f_ind_1, f_ind_2
317
318   # Check
319   GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
320   print "Group of Box's faces includes the following IDs:"
321   print "(must be ", f_ind_6, ", ", f_ind_1, " and ", f_ind_2, ")"
322   for ObjectID in GetObjectIDs:
323     print " ", ObjectID
324
325   # Boolean Operations on Groups (Union, Intersection, Cut)
326   Group_1 = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
327   geompy.UnionIDs(Group_1, [13, 23])
328   Group_2 = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
329   geompy.UnionIDs(Group_2, [3, 27])
330   Group_3 = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
331   geompy.UnionIDs(Group_3, [33, 23])
332   Group_4 = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
333   geompy.UnionIDs(Group_4, [31, 27])
334
335   geompy.addToStudyInFather(Box, Group_1, 'Group_1')
336   geompy.addToStudyInFather(Box, Group_2, 'Group_2')
337   geompy.addToStudyInFather(Box, Group_3, 'Group_3')
338   geompy.addToStudyInFather(Box, Group_4, 'Group_4')
339
340   # union groups
341   Group_U_1_2 = geompy.UnionGroups(Group_1, Group_2)
342   Group_UL_3_4 = geompy.UnionListOfGroups([Group_3, Group_4])
343
344   geompy.addToStudyInFather(Box, Group_U_1_2, 'Group_U_1_2')
345   geompy.addToStudyInFather(Box, Group_UL_3_4, 'Group_UL_3_4')
346
347   # intersect groups
348   Group_I_1_3 = geompy.IntersectGroups(Group_1, Group_3)
349   Group_IL_1_3 = geompy.IntersectListOfGroups([Group_1, Group_3])
350
351   geompy.addToStudyInFather(Box, Group_I_1_3, 'Group_I_1_3')
352   geompy.addToStudyInFather(Box, Group_IL_1_3, 'Group_IL_1_3')
353
354   # cut groups
355   Group_C_2_4 = geompy.CutGroups(Group_2, Group_4)
356   Group_CL_2_4 = geompy.CutListOfGroups([Group_2], [Group_4])
357
358   geompy.addToStudyInFather(Box, Group_C_2_4, 'Group_C_2_4')
359   geompy.addToStudyInFather(Box, Group_CL_2_4, 'Group_CL_2_4')
360
361   # -----------------------------------------------------------------------------
362   # enumeration ShapeTypeString as a dictionary
363   # -----------------------------------------------------------------------------
364   ShapeTypeString = {'0':"COMPOUND", '1':"COMPSOLID", '2':"SOLID", '3':"SHELL",
365                      '4':"FACE", '5':"WIRE", '6':"EDGE", '7':"VERTEX", '8':"SHAPE"}
366
367   GroupType = geompy.GetType(CreateGroup)
368   print "Type of elements of the created group is ", ShapeTypeString[`GroupType`]
369
370   # Prepare data for the following operations
371   p0 = geompy.MakeVertex(0, 0, 0)
372   b0 = geompy.MakeBox(-50, -50, -50, 50, 50, 50)
373   s0 = geompy.MakeSphereR(100)
374
375   id_b0 = geompy.addToStudy(b0, "b0")
376   id_s0 = geompy.addToStudy(s0, "s0")
377
378   v_0pp = geompy.MakeVectorDXDYDZ( 0,  1,  1)
379   #v_0np = geompy.MakeVectorDXDYDZ( 0, -1,  1)
380   v_p0p = geompy.MakeVectorDXDYDZ( 1,  0,  1)
381   v_p0n = geompy.MakeVectorDXDYDZ(1,  0,  -1)
382   v_pp0 = geompy.MakeVectorDXDYDZ( 1,  1,  0)
383   v_pn0 = geompy.MakeVectorDXDYDZ(1,  -1,  0)
384
385   #pln_0pp = geompy.MakePlane(p0, v_0pp, 300)
386   #pln_0np = geompy.MakePlane(p0, v_0np, 300)
387   pln_p0p = geompy.MakePlane(p0, v_p0p, 300)
388   pln_p0n = geompy.MakePlane(p0, v_p0n, 300)
389   pln_pp0 = geompy.MakePlane(p0, v_pp0, 300)
390   pln_pn0 = geompy.MakePlane(p0, v_pn0, 300)
391   #
392   #part_objs = [b0, pln_0pp, pln_0np, pln_p0p, pln_n0p, pln_pp0, pln_np0]
393   #part_tool_1 = geompy.MakePartition(part_objs, [], [], [b0])
394   #part_tool_1 = geompy.MakePartition(part_objs)
395   #
396   #id_part_tool_1 = geompy.addToStudy(part_tool_1, "part_tool_1")
397   #
398   #pt_pnt_1  = geompy.MakeVertex( 55,   0,  55)
399   #pt_pnt_2  = geompy.MakeVertex(  0,  55,  55)
400   #pt_pnt_3  = geompy.MakeVertex(-55,   0,  55)
401   #pt_pnt_4  = geompy.MakeVertex(  0, -55,  55)
402   #pt_pnt_5  = geompy.MakeVertex( 55,  55,   0)
403   #pt_pnt_6  = geompy.MakeVertex( 55, -55,   0)
404   #pt_pnt_7  = geompy.MakeVertex(-55,  55,   0)
405   #pt_pnt_8  = geompy.MakeVertex(-55, -55,   0)
406   #pt_pnt_9  = geompy.MakeVertex( 55,   0, -55)
407   #pt_pnt_10 = geompy.MakeVertex(  0,  55, -55)
408   #pt_pnt_11 = geompy.MakeVertex(-55,   0, -55)
409   #pt_pnt_12 = geompy.MakeVertex(  0, -55, -55)
410   #
411   #pt_face_1  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_1)
412   #pt_face_2  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_2)
413   #pt_face_3  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_3)
414   #pt_face_4  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_4)
415   #pt_face_5  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_5)
416   #pt_face_6  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_6)
417   #pt_face_7  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_7)
418   #pt_face_8  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_8)
419   #pt_face_9  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_9)
420   #pt_face_10 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_10)
421   #pt_face_11 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_11)
422   #pt_face_12 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_12)
423   #
424   #pt_box = geompy.GetBlockNearPoint(part_tool_1, p0)
425   #
426   #comp_parts = [pt_face_1, pt_face_4, pt_face_7, pt_face_10,
427   #              pt_face_2, pt_face_5, pt_face_8, pt_face_11,
428   #              #pt_face_3, pt_face_6, pt_face_9, pt_face_12, pt_box]
429   #              pt_face_3, pt_face_6, pt_face_9, pt_face_12]
430   #part_tool = geompy.MakeCompound(comp_parts)
431   #id_part_tool = geompy.addToStudy(part_tool, "part_tool")
432   #
433   #part = geompy.MakePartition([s0], [part_tool])
434   #
435   #part_tools = [pt_face_1, pt_face_4, pt_face_7, pt_face_10,
436   #              pt_face_2, pt_face_5, pt_face_8, pt_face_11,
437   #              pt_face_3, pt_face_6, pt_face_9, pt_face_12, b0]
438   #part = geompy.MakePartition([s0], part_tools)
439
440   p1 = geompy.MakeVertex(50, 0, 0)
441   p2 = geompy.MakeVertex(-50, 0, 0)
442   p3 = geompy.MakeVertex(0, 50, 0)
443   p4 = geompy.MakeVertex(0, -50, 0)
444   p5 = geompy.MakeVertex(0, 0, 50)
445   p6 = geompy.MakeVertex(0, 0, -50)
446
447   plnX1 = geompy.MakePlane(p1, vx, 300)
448   plnX2 = geompy.MakePlane(p2, vx, 300)
449   plnY1 = geompy.MakePlane(p3, vy, 300)
450   plnY2 = geompy.MakePlane(p4, vy, 300)
451   plnZ1 = geompy.MakePlane(p5, vz, 300)
452   plnZ2 = geompy.MakePlane(p6, vz, 300)
453
454   #part = geompy.MakePartition([s0], [plnX1,plnX2,plnY1,plnY2,plnZ1,plnZ2])
455   part = geompy.MakePartition([s0], [plnX1])
456   part = geompy.MakePartition([part], [plnX2])
457   part = geompy.MakePartition([part], [plnY1])
458   part = geompy.MakePartition([part], [plnY2])
459   part = geompy.MakePartition([part], [plnZ1])
460   part = geompy.MakePartition([part], [plnZ2])
461   geompy.addToStudy(part, "part")
462
463   # GetFreeFacesIDs
464   anIDs = geompy.GetFreeFacesIDs(part)
465   freeFaces = geompy.GetSubShape(part, anIDs)
466
467   geompy.addToStudy(freeFaces, "freeFaces")
468
469   # RemoveExtraEdges with union of all faces, sharing common surfaces
470   tools = [pln_pp0, pln_pn0, pln_p0p, pln_p0n]
471
472   Partition_1 = geompy.MakePartition([Sphere], tools, [], [], geompy.ShapeType["SOLID"], 0, [])
473   geompy.addToStudy(Partition_1, "Partition_1")
474
475   faces = geompy.SubShapeAllSortedCentres(Partition_1, geompy.ShapeType["FACE"])
476
477   Face_1 = faces[0]
478   Face_2 = faces[39]
479   Face_3 = faces[40]
480
481   geompy.addToStudyInFather(Partition_1, Face_1, "Face_1")
482   geompy.addToStudyInFather(Partition_1, Face_2, "Face_2")
483   geompy.addToStudyInFather(Partition_1, Face_3, "Face_3")
484
485   Vector_5 = geompy.MakeVectorDXDYDZ(0, 20, 0)
486   geompy.addToStudy(Vector_5, "Vector_5")
487
488   Rotation_1 = geompy.MakeRotation(Face_1, Vector_5, 90*math.pi/180.0)
489   Rotation_2 = geompy.MakeRotation(Face_1, Vector_5, 180*math.pi/180.0)
490   Rotation_3 = geompy.MakeRotation(Face_1, Vector_5, 270*math.pi/180.0)
491
492   geompy.addToStudy(Rotation_1, "Rotation_1")
493   geompy.addToStudy(Rotation_2, "Rotation_2")
494   geompy.addToStudy(Rotation_3, "Rotation_3")
495
496   Vector_6 = geompy.MakeVectorDXDYDZ(0, 0, 20)
497   geompy.addToStudy(Vector_6, "Vector_6")
498
499   Rotation_4 = geompy.MakeRotation(Face_1, Vector_6, 90*math.pi/180.0)
500   Rotation_5 = geompy.MakeRotation(Face_1, Vector_6, -90*math.pi/180.0)
501   geompy.addToStudy(Rotation_4, "Rotation_4")
502   geompy.addToStudy(Rotation_5, "Rotation_5")
503
504   Shell_1 = geompy.MakeShell([Face_1, Rotation_1, Rotation_2, Rotation_3, Rotation_4, Rotation_5])
505   Solid_1 = geompy.MakeSolid([Shell_1])
506   NoExtraEdges_1 = geompy.RemoveExtraEdges(Solid_1, True) # doUnionFaces = True
507
508   geompy.addToStudy(Shell_1, "Shell_1")
509   geompy.addToStudy(Solid_1, "Solid_1")
510   geompy.addToStudy(NoExtraEdges_1, "NoExtraEdges_1")
511
512   # RemoveExtraEdges (by default, doUnionFaces = False)
513   freeFacesWithoutExtra = geompy.RemoveExtraEdges(freeFaces)
514
515   geompy.addToStudy(freeFacesWithoutExtra, "freeFacesWithoutExtra")
516
517   # GetSharedShapes
518   sharedFaces = geompy.GetSharedShapes(part, freeFaces,
519                                        geompy.ShapeType["FACE"])
520   ind = 1
521   for shFace in sharedFaces:
522     geompy.addToStudy(shFace, "sharedFace_" + `ind`)
523     ind = ind + 1
524     pass
525
526   sharedEdges = geompy.GetSharedShapesMulti([part, freeFaces],
527                                              geompy.ShapeType["EDGE"])
528   ind = 1
529   for shEdge in sharedEdges:
530     geompy.addToStudy(shEdge, "sharedEdge_" + `ind`)
531     ind = ind + 1
532     pass
533
534   # CheckAndImprove
535   blocksComp = geompy.CheckAndImprove(part)
536
537   geompy.addToStudy(blocksComp, "blocksComp")
538
539   # Propagate
540   listChains = geompy.Propagate(blocksComp)
541
542   for chain in listChains:
543     geompy.addToStudyInFather(blocksComp, chain, "propagation chain")
544
545   # GetPoint(theShape, theX, theY, theZ, theEpsilon)
546   #
547   # (-50,  50, 50) .-----. (50,  50, 50)
548   #      pb0_top_1 |     |
549   #                |     . pmidle
550   #                |     |
551   # (-50, -50, 50) '-----' (50, -50, 50)
552   #
553   pb0_top_1 = geompy.GetPoint(blocksComp, -50,  50,  50, 0.01)
554   pb0_bot_1 = geompy.GetPoint(blocksComp, -50, -50, -50, 0.01)
555
556   geompy.addToStudyInFather(blocksComp, pb0_top_1, "point from blocksComp (-50,  50,  50)")
557   geompy.addToStudyInFather(blocksComp, pb0_bot_1, "point from blocksComp (-50, -50, -50)")
558
559   # GetVertexNearPoint(theShape, thePoint)
560   pb0_top_2_near = geompy.MakeVertex(40, 40, 40)
561   pb0_top_2      = geompy.GetVertexNearPoint(blocksComp, pb0_top_2_near)
562
563   geompy.addToStudyInFather(blocksComp, pb0_top_2, "point from blocksComp near (40,  40,  40)")
564
565   # GetEdge(theShape, thePoint1, thePoint2)
566   edge_top_y50 = geompy.GetEdge(blocksComp, pb0_top_1, pb0_top_2)
567
568   geompy.addToStudyInFather(blocksComp, edge_top_y50, "edge from blocksComp by two points")
569
570   # GetEdgeNearPoint(theShape, thePoint)
571   pmidle = geompy.MakeVertex(50, 0, 50)
572   edge1 = geompy.GetEdgeNearPoint(blocksComp, pmidle)
573
574   geompy.addToStudyInFather(blocksComp, edge1, "edge near point (50, 0, 50)")
575
576   # GetBlockByParts(theCompound, theParts)
577   b0_image = geompy.GetBlockByParts(blocksComp, [pb0_top_1, pb0_bot_1, edge1])
578
579   geompy.addToStudyInFather(blocksComp, b0_image, "b0 image")
580
581   # GetShapesNearPoint(theShape, thePoint, theShapeType, theTolerance)
582   b0_faces_plus = geompy.GetShapesNearPoint(blocksComp, pb0_top_2_near, geompy.ShapeType["FACE"], 0.01)
583
584   geompy.addToStudyInFather(blocksComp, b0_faces_plus, "faces near point (40,  40,  40)")
585
586   # GetShapesOnPlane
587   faces_on_pln = geompy.GetShapesOnPlane(blocksComp, geompy.ShapeType["FACE"],
588                                          v_0pp, geompy.GEOM.ST_ONIN)
589   for face_i in faces_on_pln:
590     geompy.addToStudy(face_i, "Face on Plane (N = (0, 1, 1)) or below it")
591
592   # GetShapesOnPlaneIDs
593   faces_above_pln_ids = geompy.GetShapesOnPlaneIDs(blocksComp, geompy.ShapeType["FACE"],
594                                                    v_0pp, geompy.GEOM.ST_OUT)
595   faces_above = geompy.CreateGroup(blocksComp, geompy.ShapeType["FACE"])
596   geompy.UnionIDs(faces_above, faces_above_pln_ids)
597   geompy.addToStudy(faces_above, "Group of faces above Plane (N = (0, 1, 1))")
598
599   # GetShapesOnPlaneWithLocation
600   Loc = geompy.MakeVertex(0, -50, 0)
601   edges_on_pln = geompy.GetShapesOnPlaneWithLocation(blocksComp, geompy.ShapeType["EDGE"],
602                                                      v_y, Loc, geompy.GEOM.ST_ON)
603   for edge_i in edges_on_pln:
604     geompy.addToStudy(edge_i, "Edge on Plane (N = (0, -1, 0) & Location = (0, -50, 0)")
605
606   # GetShapesOnPlaneWithLocationIDs
607   edges_on_pln_ids = geompy.GetShapesOnPlaneWithLocationIDs(
608            blocksComp, geompy.ShapeType["EDGE"], v_y, Loc, geompy.GEOM.ST_ON)
609   group_edges_on_pln = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
610   geompy.UnionIDs(group_edges_on_pln, edges_on_pln_ids)
611   grname = "Group of edges on Plane (N = (0, -1, 0) & Location = (0, -50, 0))"
612   geompy.addToStudy(group_edges_on_pln, grname)
613
614   # GetShapesOnCylinder
615   edges_out_cyl = geompy.GetShapesOnCylinder(blocksComp, geompy.ShapeType["EDGE"],
616                                              vy, 55, geompy.GEOM.ST_OUT)
617   for edge_i in edges_out_cyl:
618     geompy.addToStudy(edge_i, "Edge out of Cylinder (axis = (0, 1, 0), r = 55)")
619
620   # GetShapesOnCylinderIDs
621   edges_in_cyl_ids = geompy.GetShapesOnCylinderIDs(blocksComp, geompy.ShapeType["EDGE"],
622                                                    vy, 80, geompy.GEOM.ST_IN)
623   edges_in = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
624   geompy.UnionIDs(edges_in, edges_in_cyl_ids)
625   geompy.addToStudy(edges_in, "Group of edges inside Cylinder (axis = (0, 1, 0), r = 55)")
626
627   # GetShapesOnCylinderWithLocation
628   edges_out_cyl = geompy.GetShapesOnCylinderWithLocation(blocksComp, geompy.ShapeType["EDGE"],
629                                                          vy, p11, 55, geompy.GEOM.ST_OUT)
630   for edge_i in edges_out_cyl:
631     geompy.addToStudy(edge_i, "Edge out of Cylinder (axis = (0, 1, 0),  loc = (0, 0, 0), r = 55)")
632
633   # GetShapesOnCylinderWithLocationIDs
634   edges_in_cyl_ids = geompy.GetShapesOnCylinderWithLocationIDs(blocksComp, geompy.ShapeType["EDGE"],
635                                                                vy, p11, 80, geompy.GEOM.ST_IN)
636   edges_in = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
637   geompy.UnionIDs(edges_in, edges_in_cyl_ids)
638   geompy.addToStudy(edges_in, "Group of edges inside Cylinder (axis = (0, 1, 0), loc = (0, 0, 0), r = 80)")
639
640   # GetShapesOnSphere
641   vertices_on_sph = geompy.GetShapesOnSphere(blocksComp, geompy.ShapeType["VERTEX"],
642                                              p0, 100, geompy.GEOM.ST_ON)
643   for vertex_i in vertices_on_sph:
644     geompy.addToStudy(vertex_i, "Vertex on Sphere (center = (0, 0, 0), r = 100)")
645
646   # GetShapesOnSphereIDs
647   vertices_on_sph_ids = geompy.GetShapesOnSphereIDs(blocksComp, geompy.ShapeType["VERTEX"],
648                                                     p0, 100, geompy.GEOM.ST_ON)
649   vertices_on = geompy.CreateGroup(blocksComp, geompy.ShapeType["VERTEX"])
650   geompy.UnionIDs(vertices_on, vertices_on_sph_ids)
651   geompy.addToStudy(vertices_on, "Group of vertices on Sphere (center = (0, 0, 0), r = 100)")
652
653   # GetShapesOnQuadrangle
654
655   geompy.addToStudy(f12, "F12" )
656
657   bl = geompy.MakeVertex(10,-10, 0)
658   br = geompy.MakeVertex(40,-10, 0)
659   tr = geompy.MakeVertex(40, 20, 0)
660   tl = geompy.MakeVertex(10, 20, 0)
661   qe1 = geompy.MakeEdge(bl, br)
662   qe2 = geompy.MakeEdge(br, tr)
663   qe3 = geompy.MakeEdge(tr, tl)
664   qe4 = geompy.MakeEdge(tl, bl)
665   quadrangle = geompy.MakeWire([qe1, qe2, qe3, qe4])
666   geompy.addToStudy(quadrangle, "Quadrangle")
667
668   edges_onin_quad = geompy.GetShapesOnQuadrangle(f12, geompy.ShapeType["EDGE"],
669                                                  tl, tr, bl, br, geompy.GEOM.ST_ONIN)
670   comp = geompy.MakeCompound(edges_onin_quad)
671   geompy.addToStudy(comp, "Edges of F12 ONIN Quadrangle")
672   if len( edges_onin_quad ) != 4:
673     print "Error in GetShapesOnQuadrangle()"
674
675   # GetShapesOnQuadrangleIDs
676   vertices_on_quad_ids = geompy.GetShapesOnQuadrangleIDs(f12, geompy.ShapeType["VERTEX"],
677                                                          tl, tr, bl, br, geompy.GEOM.ST_ON)
678   vertices_on_quad = geompy.CreateGroup(f12, geompy.ShapeType["VERTEX"])
679   geompy.UnionIDs(vertices_on_quad, vertices_on_quad_ids)
680   geompy.addToStudy(vertices_on_quad, "Group of vertices on Quadrangle F12")
681
682   # GetShapesOnBox
683   edges_on_box = geompy.GetShapesOnBox(b0, part, geompy.ShapeType["EDGE"],
684                                        geompy.GEOM.ST_ON)
685   comp = geompy.MakeCompound(edges_on_box)
686   geompy.addToStudy(comp, "Edges of part ON box b0")
687   if len( edges_on_box ) != 12:
688     print "Error in GetShapesOnBox()"
689
690   # GetShapesOnBoxIDs
691   faces_on_box_ids = geompy.GetShapesOnBoxIDs(b0, part, geompy.ShapeType["FACE"],
692                                               geompy.GEOM.ST_ON)
693   faces_on_box = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
694   geompy.UnionIDs(faces_on_box, faces_on_box_ids)
695   geompy.addToStudyInFather(part, faces_on_box, "Group of faces on box b0")
696
697   # Prepare arguments for GetShapesOnShape
698   sph1 = geompy.MakeSphere(50, 50,  50, 40)
699   sph2 = geompy.MakeSphere(50, 50, -50, 40)
700   pcyl = geompy.MakeVertex(50, 50, -50)
701   cyli = geompy.MakeCylinder(pcyl, vz, 40, 100)
702   fuse = geompy.MakeFuse(sph1, cyli)
703   sh_1 = geompy.MakeFuse(fuse, sph2)
704   # As after Fuse we have a compound, we need to obtain a solid from it
705   #shsh = geompy.SubShapeAll(fuse, geompy.ShapeType["SOLID"])
706   #sh_1 = shsh[0]
707   geompy.addToStudy(sh_1, "sh_1")
708
709   # GetShapesOnShape
710   faces_in_sh = geompy.GetShapesOnShape(sh_1, part, geompy.ShapeType["FACE"],
711                                         geompy.GEOM.ST_IN)
712   comp = geompy.MakeCompound(faces_in_sh)
713   geompy.addToStudy(comp, "Faces of part IN shape sh_1")
714   if len(faces_in_sh) != 11:
715     print "Error in GetShapesOnShape()"
716
717   # GetShapesOnShapeAsCompound
718   faces_in_sh_c = geompy.GetShapesOnShapeAsCompound(sh_1, part, geompy.ShapeType["FACE"],
719                                                     geompy.GEOM.ST_IN)
720   geompy.addToStudy(faces_in_sh_c, "Faces of part IN shape sh_1 (as compound)")
721
722   # GetShapesOnShapeIDs
723   edges_in_sh_ids = geompy.GetShapesOnShapeIDs(sh_1, part, geompy.ShapeType["EDGE"],
724                                                geompy.GEOM.ST_IN)
725   edges_in_sh = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
726   geompy.UnionIDs(edges_in_sh, edges_in_sh_ids)
727   geompy.addToStudyInFather(part, edges_in_sh, "Group of edges in shape sh_1")
728   if len(edges_in_sh_ids) != 15:
729     print "Error in GetShapesOnShapeIDs()"
730
731   # Prepare arguments for GetInPlace and GetInPlaceByHistory
732   box5 = geompy.MakeBoxDXDYDZ(100, 100, 100)
733   box6 = geompy.MakeTranslation(box5, 50, 50, 0)
734
735   geompy.addToStudy(box5, "Box 5")
736   geompy.addToStudy(box6, "Box 6")
737
738   part = geompy.MakePartition([box5], [box6])
739   geompy.addToStudy(part, "Partitioned")
740
741   box5_faces = geompy.SubShapeAll(box5, geompy.ShapeType["FACE"])
742   box6_faces = geompy.SubShapeAll(box6, geompy.ShapeType["FACE"])
743
744   for ifa in range(6):
745     geompy.addToStudyInFather(box5, box5_faces[ifa], "Face" + `ifa + 1`)
746     geompy.addToStudyInFather(box6, box6_faces[ifa], "Face" + `ifa + 1`)
747
748   # GetInPlace(theShapeWhere, theShapeWhat)
749   ibb = 5
750   faces_list = [box5_faces, box6_faces]
751   for afaces in faces_list:
752     ifa = 1
753     for aface in afaces:
754       refl_box_face = geompy.GetInPlace(part, aface)
755       if ibb == 6 and (ifa == 2 or ifa == 4):
756         # For two faces of the tool box
757         # there is no reflection in the result.
758         if refl_box_face is not None:
759           error = "Result of GetInPlace must be NULL for face "
760           error += `ifa` + " of box " + `ibb`
761           raise RuntimeError, error
762       else:
763         ssname = "Reflection of face " + `ifa` + " of box " + `ibb`
764         geompy.addToStudyInFather(part, refl_box_face, ssname)
765       ifa = ifa + 1
766     ibb = ibb + 1
767
768   # GetInPlaceByHistory(theShapeWhere, theShapeWhat)
769   part = geompy.MakePartition([box5], [box6])
770   geompy.addToStudy(part, "Partitioned")
771
772   ibb = 5
773   faces_list = [box5_faces, box6_faces]
774   for afaces in faces_list:
775     ifa = 1
776     for aface in afaces:
777       ssname = "Reflection of face " + `ifa` + " of box " + `ibb` + " (by history)"
778       if ibb == 6 and (ifa == 2 or ifa == 4):
779         # use IDL interface directly to avoid error message appearence in Python console
780         refl_box_face = geompy.ShapesOp.GetInPlaceByHistory(part, aface)
781         if refl_box_face is not None:
782           geompy.addToStudyInFather(part, refl_box_face, ssname)
783           error = "Result of GetInPlaceByHistory must be NULL for face "
784           error += `ifa` + " of box " + `ibb`
785           raise RuntimeError, error
786       else:
787         # use geompy interface
788         refl_box_face = geompy.GetInPlaceByHistory(part, aface)
789         geompy.addToStudyInFather(part, refl_box_face, ssname)
790       ifa = ifa + 1
791     ibb = ibb + 1
792
793 #END