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