1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # File : GEOM_TestOthers.py
24 # Author : Julia DOROVSKIKH
27 # ! Please, if you edit this example file, update also
28 # ! GEOM/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
36 def TestExportImport (geompy, shape):
38 print("Test Export/Import ...", end=' ')
40 with tempfile.TemporaryDirectory() as tmpDir:
41 # Files for Export/Import testing
42 fileExportImportBREP = os.path.join(tmpDir, "testExportImportBREP.brep")
43 fileExportImportIGES = os.path.join(tmpDir, "testExportImportIGES.iges")
44 fileExportImportSTEP = os.path.join(tmpDir, "testExportImportSTEP.step")
46 # ExportBREP, ExportIGES, ExportSTEP
47 geompy.ExportBREP(shape, fileExportImportBREP)
48 geompy.ExportIGES(shape, fileExportImportIGES)
49 geompy.ExportSTEP(shape, fileExportImportSTEP)
51 # ImportBREP, ImportIGES, ImportSTEP
52 ImportBREP = geompy.ImportBREP(fileExportImportBREP)
53 ImportIGES = geompy.ImportIGES(fileExportImportIGES)
54 ImportSTEP = geompy.ImportSTEP(fileExportImportSTEP)
56 geompy.addToStudy(ImportBREP, "ImportBREP")
57 geompy.addToStudy(ImportIGES, "ImportIGES")
58 geompy.addToStudy(ImportSTEP, "ImportSTEP")
60 # GetIGESUnit and GetSTEPUnit
61 if geompy.GetIGESUnit(fileExportImportIGES) != "M":
62 ImportIGES_scaled = geompy.ImportIGES(fileExportImportIGES, True)
63 geompy.addToStudy(ImportIGES_scaled, "ImportIGES_scaled")
66 if geompy.GetSTEPUnit(fileExportImportSTEP) != "M":
67 ImportSTEP_scaled = geompy.ImportSTEP(fileExportImportSTEP, True)
68 geompy.addToStudy(ImportSTEP_scaled, "ImportSTEP_scaled")
72 # Test RestoreShape from binary BRep stream
73 aStream = shape.GetShapeStream()
74 aNewShape = geompy.RestoreShape(aStream)
75 geompy.addToStudy(aNewShape, "aNewShape")
80 def TestOtherOperations (geompy, math):
82 # prepare data for further operations
83 vx = geompy.MakeVectorDXDYDZ( 1, 0, 0)
84 vy = geompy.MakeVectorDXDYDZ( 0, 1, 0)
85 vz = geompy.MakeVectorDXDYDZ( 0, 0, 1)
87 v_y = geompy.MakeVectorDXDYDZ( 0, -1, 0)
89 p11 = geompy.MakeVertex( 0, 0, 0)
90 p12 = geompy.MakeVertex(30, 0, 0)
91 p13 = geompy.MakeVertex(30, 30, 0)
92 p14 = geompy.MakeVertex( 0, 30, 0)
94 p21 = geompy.MakeVertex(10, 10, 0)
95 p22 = geompy.MakeVertex(20, 10, 0)
96 p23 = geompy.MakeVertex(20, 20, 0)
97 p24 = geompy.MakeVertex(10, 20, 0)
99 e11 = geompy.MakeEdge(p11, p12)
100 e12 = geompy.MakeEdge(p12, p13)
101 e13 = geompy.MakeEdge(p13, p14)
102 e14 = geompy.MakeEdge(p14, p11)
104 e21 = geompy.MakeEdge(p21, p22)
105 e22 = geompy.MakeEdge(p22, p23)
106 e23 = geompy.MakeEdge(p23, p24)
107 e24 = geompy.MakeEdge(p24, p21)
109 w1 = geompy.MakeWire([e11, e12, e13, e14])
110 w2 = geompy.MakeWire([e21, e22, e23, e24])
111 w3 = geompy.MakeTranslation(w2, 0, 0, 10)
113 id_w1 = geompy.addToStudy(w1, "Outside Wire")
114 id_w2 = geompy.addToStudy(w2, "Inside Wire")
115 id_w3 = geompy.addToStudy(w3, "Inside Wire, translated along OZ")
118 f12 = geompy.MakeFaces([w1, w2], 0)
119 id_f12 = geompy.addToStudy(f12, "MakeFaces WO + WI")
122 TestExportImport(geompy, f12)
125 Box = geompy.MakeBoxDXDYDZ(200, 200, 200)
126 geompy.addToStudy(Box, "Box")
127 Orientation = geompy.OrientationChange(Box)
128 id_Orientation = geompy.addToStudy(Orientation, "OrientationChange")
130 # MakeCommon, MakeCut, MakeFuse, MakeSection
131 p1 = geompy.MakeVertex(60, 120, 0)
132 p2 = geompy.MakeVertex( 0, 0, 0)
133 v = geompy.MakeVector(p1, p2)
136 cylinder = geompy.MakeCylinder(p1, v, radius1, height)
137 Sphere = geompy.MakeSphereR(100)
139 Common1 = geompy.MakeCommon (Box, Sphere)
140 Cut1 = geompy.MakeCut (Box, Sphere)
141 Fuse1 = geompy.MakeFuse (Box, Sphere)
142 Section = geompy.MakeSection (Box, Sphere)
143 Common2 = geompy.MakeCommonList([Box, Sphere, cylinder])
144 Cut2 = geompy.MakeCutList (Box, [Sphere, cylinder])
145 Fuse2 = geompy.MakeFuseList ([Box, Sphere, cylinder])
147 id_Common1 = geompy.addToStudy(Common1, "Common_1")
148 id_Cut1 = geompy.addToStudy(Cut1, "Cut_1")
149 id_Fuse1 = geompy.addToStudy(Fuse1, "Fuse_1")
150 id_Section = geompy.addToStudy(Section, "Section")
151 id_Common2 = geompy.addToStudy(Common2, "Common_2")
152 id_Cut2 = geompy.addToStudy(Cut2, "Cut_2")
153 id_Fuse2 = geompy.addToStudy(Fuse2, "Fuse_2")
156 p100 = geompy.MakeVertex(100, 100, 100)
157 p300 = geompy.MakeVertex(300, 300, 300)
158 Box1 = geompy.MakeBoxTwoPnt(p100, p300)
159 Partition = geompy.Partition([Box], [Box1])
160 id_Partition = geompy.addToStudy(Partition, "Partition of Box by Box1")
162 # MakeMultiRotation1D, MakeMultiRotation2D
163 pz = geompy.MakeVertex(0, 0, 100)
164 vy = geompy.MakeVectorDXDYDZ(0, 100, 0)
166 MultiRot1Dt = geompy.MakeMultiRotation1DNbTimes(f12, vy, pz, 6)
167 MultiRot1Ds = geompy.MakeMultiRotation1DByStep(f12, vy, pz, math.pi/5., 6)
169 MultiRot2Dt = geompy.MakeMultiRotation2DNbTimes(f12, vy, pz, 5, 30, 3)
170 MultiRot2Ds = geompy.MakeMultiRotation2DByStep(f12, vy, pz, math.pi/4., 6, 30, 3)
172 geompy.addToStudy(MultiRot1Dt, "MakeMultiRotation1DNbTimes")
173 geompy.addToStudy(MultiRot1Ds, "MakeMultiRotation1DByStep")
174 geompy.addToStudy(MultiRot2Dt, "MakeMultiRotation2DNbTimes")
175 id_MultiRot2D = geompy.addToStudy(MultiRot2Ds, "MakeMultiRotation2DByStep")
179 face5 = geompy.SubShapeSortedCentres(Box, geompy.ShapeType["FACE"], [5])
180 f_glob_id = geompy.GetSubShapeID(Box, face5)
181 SuppFace = geompy.SuppressFaces(Box, [f_glob_id])
183 MakeFilletAll = geompy.MakeFilletAll(SuppFace, radius_fillet)
184 id_MakeFilletAll = geompy.addToStudy(MakeFilletAll, "MakeFilletAll")
187 dimension_chamfer = 10.
188 MakeChamferAll = geompy.MakeChamferAll(SuppFace, dimension_chamfer)
189 id_MakeChamferAll = geompy.addToStudy(MakeChamferAll, "MakeChamferAll")
194 box_faces = geompy.SubShapeAllSortedCentres(Box, geompy.ShapeType["FACE"])
195 f_ind_1 = geompy.GetSubShapeID(Box, box_faces[0])
196 f_ind_2 = geompy.GetSubShapeID(Box, box_faces[1])
197 f_ind_3 = geompy.GetSubShapeID(Box, box_faces[2])
199 MakeChamfer = geompy.MakeChamfer(Box, d1, d2, geompy.ShapeType["FACE"],
200 [f_ind_1, f_ind_2, f_ind_3])
201 id_MakeChamfer = geompy.addToStudy(MakeChamfer, "MakeChamfer")
204 NumberOfFaces = geompy.NumberOfFaces(Box)
205 NumberOfEdges = geompy.NumberOfEdges(Box)
206 NumberOfSolids = geompy.NumberOfSolids(Box)
207 NumberOfShapes = geompy.NumberOfSubShapes(Box, geompy.ShapeType["SHAPE"])
209 assert (NumberOfFaces == 6), "Bad number of faces in BOX!"
210 assert (NumberOfEdges == 12), "Bad number of edges in BOX!"
211 assert (NumberOfSolids == 1), "Bad number of solids in BOX!"
212 assert (NumberOfShapes == 34), "Bad number of shapes in BOX!"
215 Compound = geompy.MakeCompound([Box, Sphere])
216 MakeBlockExplode = geompy.MakeBlockExplode(Compound, 6, 6)
218 id_MakeBlockExplode = geompy.addToStudy(MakeBlockExplode[0], "MakeBlockExplode")
220 # CheckCompoundOfBlocks
221 p1 = geompy.MakeVertex(200, 0, 0)
222 p2 = geompy.MakeVertex(400, 200, 200)
223 p3 = geompy.MakeVertex(400, 50, 50)
224 p4 = geompy.MakeVertex(600, 250, 250)
226 Box2 = geompy.MakeBoxTwoPnt(p1, p2)
227 Box3 = geompy.MakeBoxTwoPnt(p3, p4)
228 Cyl = geompy.MakeCylinderRH(50, 300)
229 Cone = geompy.MakeConeR1R2H(150, 10, 400)
231 Compound1 = geompy.MakeCompound([Box, Cyl, Cone, Box3, Box2], "Compound1")
233 print("Printing errors of not valid Blocks Compound (EXPECTED):")
234 IsValid = geompy.CheckCompoundOfBlocks(Compound1)
235 # This Blocks Compound is NOT VALID
237 (NonBlocks, NonQuads) = geompy.GetNonBlocks(Compound1)
238 if NonBlocks is not None:
239 geompy.addToStudyInFather(Compound1, NonBlocks, "Group of non-hexahedral solids")
240 if NonQuads is not None:
241 geompy.addToStudyInFather(Compound1, NonQuads, "Group of non-quadrangular faces")
243 IsValid = geompy.CheckCompoundOfBlocks(Box)
244 assert (IsValid) # Box is a VALID Blocks Compound
247 Cone_ss = geompy.GetSame(Compound1, Cone)
248 id_Cone_ss = geompy.addToStudyInFather(Compound1, Cone_ss, "Cone subshape")
250 # test geometrical groups
253 CreateGroup = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
255 id_CreateGroup = geompy.addToStudy(CreateGroup, "CreateGroup")
258 f_ind_4 = geompy.GetSubShapeID(Box, box_faces[3])
259 f_ind_5 = geompy.GetSubShapeID(Box, box_faces[4])
260 f_ind_6 = geompy.GetSubShapeID(Box, box_faces[5])
262 geompy.AddObject(CreateGroup, f_ind_6) # box_faces[5]
263 geompy.AddObject(CreateGroup, f_ind_1) # box_faces[0]
264 geompy.AddObject(CreateGroup, f_ind_4) # box_faces[3]
265 # Now contains f_ind_6, f_ind_1, f_ind_4
268 geompy.UnionList(CreateGroup, [box_faces[2], box_faces[4], box_faces[5]])
269 # Now contains f_ind_6, f_ind_1, f_ind_4, f_ind_3, f_ind_5
271 # RemoveObject(theGroup, theSubShapeID)
272 geompy.RemoveObject(CreateGroup, f_ind_1) # box_faces[0]
273 # Now contains f_ind_6, f_ind_4, f_ind_3, f_ind_5
276 geompy.DifferenceList(CreateGroup, [box_faces[1], box_faces[0], box_faces[3]])
277 # Now contains f_ind_6, f_ind_3, f_ind_5
280 GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
281 assert (sorted(GetObjectIDs) == sorted([f_ind_6, f_ind_3, f_ind_5]))
284 BoxCopy = geompy.GetMainShape(CreateGroup)
287 geompy.DifferenceIDs(CreateGroup, [f_ind_3, f_ind_5])
288 # Now contains f_ind_6
291 geompy.UnionIDs(CreateGroup, [f_ind_1, f_ind_2, f_ind_6])
292 # Now contains f_ind_6, f_ind_1, f_ind_2
295 GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
296 assert (sorted(GetObjectIDs) == sorted([f_ind_6, f_ind_1, f_ind_2]))
298 # Boolean Operations on Groups (Union, Intersection, Cut)
299 Group_1 = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
300 geompy.UnionIDs(Group_1, [13, 23])
301 Group_2 = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
302 geompy.UnionIDs(Group_2, [3, 27])
303 Group_3 = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
304 geompy.UnionIDs(Group_3, [33, 23])
305 Group_4 = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
306 geompy.UnionIDs(Group_4, [31, 27])
308 geompy.addToStudyInFather(Box, Group_1, 'Group_1')
309 geompy.addToStudyInFather(Box, Group_2, 'Group_2')
310 geompy.addToStudyInFather(Box, Group_3, 'Group_3')
311 geompy.addToStudyInFather(Box, Group_4, 'Group_4')
314 Group_U_1_2 = geompy.UnionGroups(Group_1, Group_2)
315 Group_UL_3_4 = geompy.UnionListOfGroups([Group_3, Group_4])
317 geompy.addToStudyInFather(Box, Group_U_1_2, 'Group_U_1_2')
318 geompy.addToStudyInFather(Box, Group_UL_3_4, 'Group_UL_3_4')
321 Group_I_1_3 = geompy.IntersectGroups(Group_1, Group_3)
322 Group_IL_1_3 = geompy.IntersectListOfGroups([Group_1, Group_3])
324 geompy.addToStudyInFather(Box, Group_I_1_3, 'Group_I_1_3')
325 geompy.addToStudyInFather(Box, Group_IL_1_3, 'Group_IL_1_3')
328 Group_C_2_4 = geompy.CutGroups(Group_2, Group_4)
329 Group_CL_2_4 = geompy.CutListOfGroups([Group_2], [Group_4])
331 geompy.addToStudyInFather(Box, Group_C_2_4, 'Group_C_2_4')
332 geompy.addToStudyInFather(Box, Group_CL_2_4, 'Group_CL_2_4')
334 GroupType = geompy.GetType(CreateGroup)
335 assert (GroupType == geompy.ShapeType["FACE"])
337 # Example of sphere partitioning into hexahedral blocks
338 p0 = geompy.MakeVertex(0, 0, 0)
339 b0 = geompy.MakeBox(-50, -50, -50, 50, 50, 50)
340 s0 = geompy.MakeSphereR(100)
342 id_b0 = geompy.addToStudy(b0, "b0")
343 id_s0 = geompy.addToStudy(s0, "s0")
345 v_0pp = geompy.MakeVectorDXDYDZ( 0, 1, 1)
346 v_0np = geompy.MakeVectorDXDYDZ( 0, -1, 1)
347 v_p0p = geompy.MakeVectorDXDYDZ( 1, 0, 1)
348 v_p0n = geompy.MakeVectorDXDYDZ( 1, 0, -1)
349 v_pp0 = geompy.MakeVectorDXDYDZ( 1, 1, 0)
350 v_pn0 = geompy.MakeVectorDXDYDZ( 1, -1, 0)
352 pln_0pp = geompy.MakePlane(p0, v_0pp, 300)
353 pln_0np = geompy.MakePlane(p0, v_0np, 300)
354 pln_p0p = geompy.MakePlane(p0, v_p0p, 300)
355 pln_p0n = geompy.MakePlane(p0, v_p0n, 300)
356 pln_pp0 = geompy.MakePlane(p0, v_pp0, 300)
357 pln_pn0 = geompy.MakePlane(p0, v_pn0, 300)
359 part_objs = [b0, pln_0pp, pln_0np, pln_p0p, pln_p0n, pln_pp0, pln_pn0]
360 part_tool_1 = geompy.MakePartition(part_objs, KeepNonlimitShapes=1)
361 geompy.addToStudy(part_tool_1, "part_tool_1")
363 pt_pnt_1 = geompy.MakeVertex( 55, 0, 55)
364 pt_pnt_2 = geompy.MakeVertex( 0, 55, 55)
365 pt_pnt_3 = geompy.MakeVertex(-55, 0, 55)
366 pt_pnt_4 = geompy.MakeVertex( 0, -55, 55)
367 pt_pnt_5 = geompy.MakeVertex( 55, 55, 0)
368 pt_pnt_6 = geompy.MakeVertex( 55, -55, 0)
369 pt_pnt_7 = geompy.MakeVertex(-55, 55, 0)
370 pt_pnt_8 = geompy.MakeVertex(-55, -55, 0)
371 pt_pnt_9 = geompy.MakeVertex( 55, 0, -55)
372 pt_pnt_10 = geompy.MakeVertex( 0, 55, -55)
373 pt_pnt_11 = geompy.MakeVertex(-55, 0, -55)
374 pt_pnt_12 = geompy.MakeVertex( 0, -55, -55)
376 pt_face_1 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_1)
377 pt_face_2 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_2)
378 pt_face_3 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_3)
379 pt_face_4 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_4)
380 pt_face_5 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_5)
381 pt_face_6 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_6)
382 pt_face_7 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_7)
383 pt_face_8 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_8)
384 pt_face_9 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_9)
385 pt_face_10 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_10)
386 pt_face_11 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_11)
387 pt_face_12 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_12)
389 part_tools = [pt_face_1, pt_face_4, pt_face_7, pt_face_10,
390 pt_face_2, pt_face_5, pt_face_8, pt_face_11,
391 pt_face_3, pt_face_6, pt_face_9, pt_face_12, b0]
392 part_tool = geompy.MakeCompound(part_tools)
393 geompy.addToStudy(part_tool, "part_tool")
394 part = geompy.MakePartition([s0], [part_tool])
395 geompy.addToStudy(part, "part")
398 anIDs = geompy.GetFreeFacesIDs(part)
399 freeFaces = geompy.GetSubShape(part, anIDs)
401 geompy.addToStudy(freeFaces, "freeFaces")
403 # Example of hexahedral sphere creation
404 # (spherical surface of solid is made of six quasi-quadrangular faces)
405 tools = [pln_pp0, pln_pn0, pln_p0p, pln_p0n]
406 Partition_1 = geompy.MakePartition([Sphere], tools, [], [], geompy.ShapeType["SOLID"], 0, [])
407 geompy.addToStudy(Partition_1, "Partition_1")
409 faces = geompy.SubShapeAllSortedCentres(Partition_1, geompy.ShapeType["FACE"])
415 geompy.addToStudyInFather(Partition_1, Face_1, "Face_1")
416 geompy.addToStudyInFather(Partition_1, Face_2, "Face_2")
417 geompy.addToStudyInFather(Partition_1, Face_3, "Face_3")
419 Vector_5 = geompy.MakeVectorDXDYDZ(0, 20, 0)
420 geompy.addToStudy(Vector_5, "Vector_5")
422 Rotation_1 = geompy.MakeRotation(Face_1, Vector_5, 90*math.pi/180.0)
423 Rotation_2 = geompy.MakeRotation(Face_1, Vector_5, 180*math.pi/180.0)
424 Rotation_3 = geompy.MakeRotation(Face_1, Vector_5, 270*math.pi/180.0)
426 geompy.addToStudy(Rotation_1, "Rotation_1")
427 geompy.addToStudy(Rotation_2, "Rotation_2")
428 geompy.addToStudy(Rotation_3, "Rotation_3")
430 Vector_6 = geompy.MakeVectorDXDYDZ(0, 0, 20)
431 geompy.addToStudy(Vector_6, "Vector_6")
433 Rotation_4 = geompy.MakeRotation(Face_1, Vector_6, 90*math.pi/180.0)
434 Rotation_5 = geompy.MakeRotation(Face_1, Vector_6, -90*math.pi/180.0)
435 geompy.addToStudy(Rotation_4, "Rotation_4")
436 geompy.addToStudy(Rotation_5, "Rotation_5")
438 Shell_1 = geompy.MakeShell([Face_1, Rotation_1, Rotation_2, Rotation_3, Rotation_4, Rotation_5])
439 Solid_1 = geompy.MakeSolid([Shell_1])
441 # RemoveExtraEdges with union of all faces, sharing common surfaces
442 box10 = geompy.MakeBoxDXDYDZ(10, 10, 10, "box10")
443 box11 = geompy.MakeTranslation(box10, 10, 0, 0, "box11")
444 FuseB = geompy.MakeFuse(box10, box11, checkSelfInte=False, rmExtraEdges=False, theName="FuseB")
445 NoExtraEdges_1 = geompy.RemoveExtraEdges(FuseB, True) # doUnionFaces = True
447 geompy.addToStudy(Shell_1, "Shell_1")
448 geompy.addToStudy(Solid_1, "Solid_1")
449 geompy.addToStudy(NoExtraEdges_1, "NoExtraEdges_1")
451 # RemoveExtraEdges (by default, doUnionFaces = False)
452 freeFacesWithoutExtra = geompy.RemoveExtraEdges(freeFaces)
454 geompy.addToStudy(freeFacesWithoutExtra, "freeFacesWithoutExtra")
457 unitedFaces = geompy.UnionFaces(freeFaces)
459 geompy.addToStudy(unitedFaces, "unitedFaces")
462 sharedFaces = geompy.GetSharedShapes(part, freeFaces,
463 geompy.ShapeType["FACE"])
465 for shFace in sharedFaces:
466 geompy.addToStudy(shFace, "sharedFace_" + repr(ind))
470 sharedEdges = geompy.GetSharedShapesMulti([part, freeFaces],
471 geompy.ShapeType["EDGE"])
473 for shEdge in sharedEdges:
474 geompy.addToStudy(shEdge, "sharedEdge_" + repr(ind))
479 path = os.getenv("DATA_DIR")
480 fileName = path + "/Shapes/Step/black_and_white.step"
481 blackWhite = geompy.ImportSTEP(fileName)
482 blackWhiteCopy = geompy.MakeCopy(blackWhite[0])
483 subBlackWhite = geompy.SubShapeAll(blackWhiteCopy, GEOM.SOLID)
484 geompy.TransferData(blackWhite[0], blackWhiteCopy)
485 geompy.addToStudy(blackWhite[0], "blackWhite")
486 geompy.addToStudy(blackWhiteCopy, "blackWhiteCopy")
487 geompy.addToStudyInFather( blackWhiteCopy, subBlackWhite[0], "" )
488 geompy.addToStudyInFather( blackWhiteCopy, subBlackWhite[1], "" )
491 blocksComp = geompy.CheckAndImprove(part, "blocksComp")
492 assert (geompy.CheckCompoundOfBlocks(blocksComp))
495 listChains = geompy.Propagate(blocksComp)
497 for chain in listChains:
498 geompy.addToStudyInFather(blocksComp, chain, "propagation chain")
500 # GetPoint(theShape, theX, theY, theZ, theEpsilon)
502 # (-50, 50, 50) .-----. (50, 50, 50)
506 # (-50, -50, 50) '-----' (50, -50, 50)
508 pb0_top_1 = geompy.GetPoint(blocksComp, -50, 50, 50, 0.01)
509 pb0_bot_1 = geompy.GetPoint(blocksComp, -50, -50, -50, 0.01)
511 geompy.addToStudyInFather(blocksComp, pb0_top_1, "point from blocksComp (-50, 50, 50)")
512 geompy.addToStudyInFather(blocksComp, pb0_bot_1, "point from blocksComp (-50, -50, -50)")
514 # GetVertexNearPoint(theShape, thePoint)
515 pb0_top_2_near = geompy.MakeVertex(40, 40, 40)
516 pb0_top_2 = geompy.GetVertexNearPoint(blocksComp, pb0_top_2_near)
518 geompy.addToStudyInFather(blocksComp, pb0_top_2, "point from blocksComp near (40, 40, 40)")
520 # GetEdge(theShape, thePoint1, thePoint2)
521 edge_top_y50 = geompy.GetEdge(blocksComp, pb0_top_1, pb0_top_2)
523 geompy.addToStudyInFather(blocksComp, edge_top_y50, "edge from blocksComp by two points")
525 # GetEdgeNearPoint(theShape, thePoint)
526 pmidle = geompy.MakeVertex(50, 0, 50)
527 edge1 = geompy.GetEdgeNearPoint(blocksComp, pmidle)
529 geompy.addToStudyInFather(blocksComp, edge1, "edge near point (50, 0, 50)")
531 # GetBlockByParts(theCompound, theParts)
532 b0_image = geompy.GetBlockByParts(blocksComp, [pb0_top_1, pb0_bot_1, edge1])
534 geompy.addToStudyInFather(blocksComp, b0_image, "b0 image")
536 # GetShapesNearPoint(theShape, thePoint, theShapeType, theTolerance)
537 b0_faces_plus = geompy.GetShapesNearPoint(blocksComp, pb0_top_2_near, geompy.ShapeType["FACE"], 0.01)
539 geompy.addToStudyInFather(blocksComp, b0_faces_plus, "faces near point (40, 40, 40)")
542 faces_on_pln = geompy.GetShapesOnPlane(blocksComp, geompy.ShapeType["FACE"],
544 for face_i in faces_on_pln:
545 geompy.addToStudy(face_i, "Face on Plane (N = (0, 1, 1)) or below it")
547 # GetShapesOnPlaneIDs
548 faces_above_pln_ids = geompy.GetShapesOnPlaneIDs(blocksComp, geompy.ShapeType["FACE"],
550 faces_above = geompy.CreateGroup(blocksComp, geompy.ShapeType["FACE"])
551 geompy.UnionIDs(faces_above, faces_above_pln_ids)
552 geompy.addToStudy(faces_above, "Group of faces above Plane (N = (0, 1, 1))")
554 # GetShapesOnPlaneWithLocation
555 Loc = geompy.MakeVertex(0, -50, 0)
556 edges_on_pln = geompy.GetShapesOnPlaneWithLocation(blocksComp, geompy.ShapeType["EDGE"],
557 v_y, Loc, GEOM.ST_ON)
558 for edge_i in edges_on_pln:
559 geompy.addToStudy(edge_i, "Edge on Plane (N = (0, -1, 0) & Location = (0, -50, 0)")
561 # GetShapesOnPlaneWithLocationIDs
562 edges_on_pln_ids = geompy.GetShapesOnPlaneWithLocationIDs(
563 blocksComp, geompy.ShapeType["EDGE"], v_y, Loc, GEOM.ST_ON)
564 group_edges_on_pln = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
565 geompy.UnionIDs(group_edges_on_pln, edges_on_pln_ids)
566 grname = "Group of edges on Plane (N = (0, -1, 0) & Location = (0, -50, 0))"
567 geompy.addToStudy(group_edges_on_pln, grname)
569 # GetShapesOnCylinder
570 edges_out_cyl = geompy.GetShapesOnCylinder(blocksComp, geompy.ShapeType["EDGE"],
572 for edge_i in edges_out_cyl:
573 geompy.addToStudy(edge_i, "Edge out of Cylinder (axis = (0, 1, 0), r = 55)")
575 # GetShapesOnCylinderIDs
576 edges_in_cyl_ids = geompy.GetShapesOnCylinderIDs(blocksComp, geompy.ShapeType["EDGE"],
578 edges_in = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
579 geompy.UnionIDs(edges_in, edges_in_cyl_ids)
580 geompy.addToStudy(edges_in, "Group of edges inside Cylinder (axis = (0, 1, 0), r = 55)")
582 # GetShapesOnCylinderWithLocation
583 edges_out_cyl = geompy.GetShapesOnCylinderWithLocation(blocksComp, geompy.ShapeType["EDGE"],
584 vy, p11, 55, GEOM.ST_OUT)
585 for edge_i in edges_out_cyl:
586 geompy.addToStudy(edge_i, "Edge out of Cylinder (axis = (0, 1, 0), loc = (0, 0, 0), r = 55)")
588 # GetShapesOnCylinderWithLocationIDs
589 edges_in_cyl_ids = geompy.GetShapesOnCylinderWithLocationIDs(blocksComp, geompy.ShapeType["EDGE"],
590 vy, p11, 80, GEOM.ST_IN)
591 edges_in = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
592 geompy.UnionIDs(edges_in, edges_in_cyl_ids)
593 geompy.addToStudy(edges_in, "Group of edges inside Cylinder (axis = (0, 1, 0), loc = (0, 0, 0), r = 80)")
596 vertices_on_sph = geompy.GetShapesOnSphere(blocksComp, geompy.ShapeType["VERTEX"],
598 for vertex_i in vertices_on_sph:
599 geompy.addToStudy(vertex_i, "Vertex on Sphere (center = (0, 0, 0), r = 100)")
601 # GetShapesOnSphereIDs
602 vertices_on_sph_ids = geompy.GetShapesOnSphereIDs(blocksComp, geompy.ShapeType["VERTEX"],
604 vertices_on = geompy.CreateGroup(blocksComp, geompy.ShapeType["VERTEX"])
605 geompy.UnionIDs(vertices_on, vertices_on_sph_ids)
606 geompy.addToStudy(vertices_on, "Group of vertices on Sphere (center = (0, 0, 0), r = 100)")
608 # GetShapesOnQuadrangle
610 geompy.addToStudy(f12, "F12" )
612 bl = geompy.MakeVertex(10,-10, 0)
613 br = geompy.MakeVertex(40,-10, 0)
614 tr = geompy.MakeVertex(40, 20, 0)
615 tl = geompy.MakeVertex(10, 20, 0)
616 qe1 = geompy.MakeEdge(bl, br)
617 qe2 = geompy.MakeEdge(br, tr)
618 qe3 = geompy.MakeEdge(tr, tl)
619 qe4 = geompy.MakeEdge(tl, bl)
620 quadrangle = geompy.MakeWire([qe1, qe2, qe3, qe4])
621 geompy.addToStudy(quadrangle, "Quadrangle")
623 edges_onin_quad = geompy.GetShapesOnQuadrangle(f12, geompy.ShapeType["EDGE"],
624 tl, tr, bl, br, GEOM.ST_ONIN)
625 comp = geompy.MakeCompound(edges_onin_quad)
626 geompy.addToStudy(comp, "Edges of F12 ONIN Quadrangle")
627 assert (len( edges_onin_quad ) == 4), "Error in GetShapesOnQuadrangle()"
629 # GetShapesOnQuadrangleIDs
630 vertices_on_quad_ids = geompy.GetShapesOnQuadrangleIDs(f12, geompy.ShapeType["VERTEX"],
631 tl, tr, bl, br, GEOM.ST_ON)
632 vertices_on_quad = geompy.CreateGroup(f12, geompy.ShapeType["VERTEX"])
633 geompy.UnionIDs(vertices_on_quad, vertices_on_quad_ids)
634 geompy.addToStudy(vertices_on_quad, "Group of vertices on Quadrangle F12")
637 edges_on_box = geompy.GetShapesOnBox(b0, part, geompy.ShapeType["EDGE"],
639 comp = geompy.MakeCompound(edges_on_box)
640 geompy.addToStudy(comp, "Edges of part ON box b0")
641 assert (len( edges_on_box ) == 12), "Error in GetShapesOnBox()"
644 faces_on_box_ids = geompy.GetShapesOnBoxIDs(b0, part, geompy.ShapeType["FACE"],
646 faces_on_box = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
647 geompy.UnionIDs(faces_on_box, faces_on_box_ids)
648 geompy.addToStudyInFather(part, faces_on_box, "Group of faces on box b0")
651 sh_1 = geompy.MakeTranslation(s0, 100, 0, 0, "sh_1")
652 faces_in_sh = geompy.GetShapesOnShape(sh_1, part, geompy.ShapeType["FACE"],
654 comp = geompy.MakeCompound(faces_in_sh)
655 geompy.addToStudy(comp, "Faces of part IN shape sh_1")
656 assert (len(faces_in_sh) == 7), "Error in GetShapesOnShape()"
658 # GetShapesOnShapeAsCompound
659 faces_in_sh_c = geompy.GetShapesOnShapeAsCompound(sh_1, part, geompy.ShapeType["FACE"],
661 geompy.addToStudy(faces_in_sh_c, "Faces of part IN shape sh_1 (as compound)")
663 # GetShapesOnShapeIDs
664 edges_in_sh_ids = geompy.GetShapesOnShapeIDs(sh_1, part, geompy.ShapeType["EDGE"],
666 edges_in_sh = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
667 geompy.UnionIDs(edges_in_sh, edges_in_sh_ids)
668 geompy.addToStudyInFather(part, edges_in_sh, "Group of edges in shape sh_1")
669 assert (len(edges_in_sh_ids) == 15), "Error in GetShapesOnShapeIDs()"
671 # Prepare arguments for GetInPlace and GetInPlaceByHistory
672 box5 = geompy.MakeBoxDXDYDZ(100, 100, 100, "Box 5")
673 box6 = geompy.MakeTranslation(box5, 50, 50, 0, "Box 6")
674 part = geompy.MakePartition([box5], [box6])
675 geompy.addToStudy(part, "Partitioned")
677 box5_faces = geompy.SubShapeAll(box5, geompy.ShapeType["FACE"])
678 box6_faces = geompy.SubShapeAll(box6, geompy.ShapeType["FACE"])
681 geompy.addToStudyInFather(box5, box5_faces[ifa], "Face" + repr(ifa + 1))
682 geompy.addToStudyInFather(box6, box6_faces[ifa], "Face" + repr(ifa + 1))
684 # GetInPlace(theShapeWhere, theShapeWhat)
686 faces_list = [box5_faces, box6_faces]
687 for afaces in faces_list:
690 refl_box_face = geompy.GetInPlace(part, aface)
691 if ibb == 6 and (ifa == 2 or ifa == 4):
692 # For two faces of the tool box
693 # there is no reflection in the result.
694 if refl_box_face is not None:
695 error = "Result of GetInPlace must be NULL for face "
696 error += repr(ifa) + " of box " + repr(ibb)
697 raise RuntimeError(error)
699 ssname = "Reflection of face " + repr(ifa) + " of box " + repr(ibb)
700 geompy.addToStudyInFather(part, refl_box_face, ssname)
704 # GetInPlaceByHistory(theShapeWhere, theShapeWhat)
705 part = geompy.MakePartition([box5], [box6])
706 geompy.addToStudy(part, "Partitioned")
709 faces_list = [box5_faces, box6_faces]
710 for afaces in faces_list:
713 ssname = "Reflection of face " + repr(ifa) + " of box " + repr(ibb) + " (by history)"
714 if ibb == 6 and (ifa == 2 or ifa == 4):
715 # use IDL interface directly to avoid error message appearance in Python console
716 refl_box_face = geompy.ShapesOp.GetInPlaceByHistory(part, aface)
717 if refl_box_face is not None:
718 geompy.addToStudyInFather(part, refl_box_face, ssname)
719 error = "Result of GetInPlaceByHistory must be NULL for face "
720 error += repr(ifa) + " of box " + repr(ibb)
721 raise RuntimeError(error)
723 # use geompy interface
724 refl_box_face = geompy.GetInPlaceByHistory(part, aface)
725 geompy.addToStudyInFather(part, refl_box_face, ssname)