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