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