Salome HOME
Implement improvement PAL13394: disk building from circle
[modules/geom.git] / src / GEOM_SWIG / GEOM_TestOthers.py
index 356e23fc5d3bdb4e289e78cec933c68adf03e5c8..f3a92293f0dc39a393532da64423709968ea6343 100644 (file)
@@ -16,7 +16,7 @@
 #  License along with this library; if not, write to the Free Software
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 #
-#  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 #
 #  File   : GEOM_TestOthers.py
 #  Module : GEOM
 #  $Header$
 
+import os
+
+def TestExportImport (geompy, shape):
+
+  print "Test Export/Import ...",
+
+  # Files for Export/Import testing
+  fileExportImport = "/tmp/testExportImport.brep"
+  fileExportImportBREP = "/tmp/testExportImportBREP.brep"
+  fileExportImportIGES = "/tmp/testExportImportIGES.iges"
+  fileExportImportSTEP = "/tmp/testExportImportSTEP.step"
+
+  if os.access(fileExportImport, os.F_OK):
+    if os.access(fileExportImport, os.W_OK):
+      os.remove(fileExportImport)
+    else:
+      fileExportImport = "/tmp/testExportImport1.brep"
+
+    if os.access(fileExportImportBREP, os.W_OK):
+      os.remove(fileExportImportBREP)
+    else:
+      fileExportImportBREP = "/tmp/testExportImportBREP1.brep"
+
+    if os.access(fileExportImportIGES, os.W_OK):
+      os.remove(fileExportImportIGES)
+    else:
+      fileExportImportIGES = "/tmp/testExportImportIGES1.iges"
+
+    if os.access(fileExportImportSTEP, os.W_OK):
+      os.remove(fileExportImportSTEP)
+    else:
+      fileExportImportSTEP = "/tmp/testExportImportSTEP1.step"
+
+  # Export
+  geompy.Export(shape, fileExportImport, "BREP")
+
+  # ExportBREP, ExportIGES, ExportSTEP
+  geompy.ExportBREP(shape, fileExportImportBREP)
+  geompy.ExportIGES(shape, fileExportImportIGES)
+  geompy.ExportSTEP(shape, fileExportImportSTEP)
+
+  # Import
+  Import = geompy.Import(fileExportImport, "BREP")
+
+  id_Import = geompy.addToStudy(Import, "Import")
+
+  # ImportBREP, ImportIGES, ImportSTEP
+  ImportBREP = geompy.ImportBREP(fileExportImportBREP)
+  ImportIGES = geompy.ImportIGES(fileExportImportIGES)
+  ImportSTEP = geompy.ImportSTEP(fileExportImportSTEP)
+
+  id_ImportBREP = geompy.addToStudy(ImportBREP, "ImportBREP")
+  id_ImportIGES = geompy.addToStudy(ImportIGES, "ImportIGES")
+  id_ImportSTEP = geompy.addToStudy(ImportSTEP, "ImportSTEP")
+
+  # Remove files for Export/Import testing
+  os.remove(fileExportImport)
+  os.remove(fileExportImportBREP)
+  os.remove(fileExportImportIGES)
+  os.remove(fileExportImportSTEP)
+
+  print "OK"
+
+
 def TestOtherOperations (geompy, math):
 
   # MakeFaces
@@ -58,6 +122,9 @@ def TestOtherOperations (geompy, math):
   f12 = geompy.MakeFaces([w1, w2], 0)
   id_f12 = geompy.addToStudy(f12, "MakeFaces WO + WI")
 
+  # Export/Import
+  TestExportImport(geompy, f12)
+
   # OrientationChange
   Box = geompy.MakeBoxDXDYDZ(200, 200, 200)
   Orientation = geompy.OrientationChange(Box)
@@ -119,28 +186,6 @@ def TestOtherOperations (geompy, math):
                                    [f_ind_1, f_ind_2, f_ind_3])
   id_MakeChamfer = geompy.addToStudy(MakeChamfer, "MakeChamfer")
 
-  # Export
-  geompy.Export(f12, "/tmp/testExportImport.brep", "BREP")
-
-  # ExportBREP, ExportIGES, ExportSTEP
-  geompy.ExportBREP(f12, "/tmp/testExportImportBREP.brep")
-  geompy.ExportIGES(f12, "/tmp/testExportImportIGES.iges")
-  geompy.ExportSTEP(f12, "/tmp/testExportImportSTEP.step")
-
-  # Import
-  Import = geompy.Import("/tmp/testExportImport.brep", "BREP")
-
-  id_Import = geompy.addToStudy(Import, "Import")
-
-  # ImportBREP, ImportIGES, ImportSTEP
-  ImportBREP = geompy.ImportBREP("/tmp/testExportImportBREP.brep")
-  ImportIGES = geompy.ImportIGES("/tmp/testExportImportIGES.iges")
-  ImportSTEP = geompy.ImportSTEP("/tmp/testExportImportSTEP.step")
-
-  id_ImportBREP = geompy.addToStudy(ImportBREP, "ImportBREP")
-  id_ImportIGES = geompy.addToStudy(ImportIGES, "ImportIGES")
-  id_ImportSTEP = geompy.addToStudy(ImportSTEP, "ImportSTEP")
-
   # NumberOfFaces
   NumberOfFaces = geompy.NumberOfFaces(Box)
   if NumberOfFaces != 6:
@@ -194,22 +239,48 @@ def TestOtherOperations (geompy, math):
   f_ind_5 = geompy.GetSubShapeID(Box, box_faces[4])
   f_ind_6 = geompy.GetSubShapeID(Box, box_faces[5])
 
-  geompy.AddObject(CreateGroup, f_ind_6)
-  geompy.AddObject(CreateGroup, f_ind_1)
-  geompy.AddObject(CreateGroup, f_ind_4)
+  geompy.AddObject(CreateGroup, f_ind_6) # box_faces[5]
+  geompy.AddObject(CreateGroup, f_ind_1) # box_faces[0]
+  geompy.AddObject(CreateGroup, f_ind_4) # box_faces[3]
+  # Now contains f_ind_6, f_ind_1, f_ind_4
+
+  # UnionList
+  geompy.UnionList(CreateGroup, [box_faces[2], box_faces[4], box_faces[5]])
+  # Now contains f_ind_6, f_ind_1, f_ind_4, f_ind_3, f_ind_5
 
   # RemoveObject(theGroup, theSubShapeID)
-  geompy.RemoveObject(CreateGroup, f_ind_1)
+  geompy.RemoveObject(CreateGroup, f_ind_1) # box_faces[0]
+  # Now contains f_ind_6, f_ind_4, f_ind_3, f_ind_5
+
+  # DifferenceList
+  geompy.DifferenceList(CreateGroup, [box_faces[1], box_faces[0], box_faces[3]])
+  # Now contains f_ind_6, f_ind_3, f_ind_5
 
   # GetObjectIDs
   GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
 
   print "Group of Box's faces includes the following IDs:"
+  print "(must be ", f_ind_6, ", ", f_ind_3, " and ", f_ind_5, ")"
   for ObjectID in GetObjectIDs:
     print " ", ObjectID
 
   BoxCopy = geompy.GetMainShape(CreateGroup)
 
+  # DifferenceIDs
+  geompy.DifferenceIDs(CreateGroup, [f_ind_3, f_ind_5])
+  # Now contains f_ind_6
+
+  # UnionIDs
+  geompy.UnionIDs(CreateGroup, [f_ind_1, f_ind_2, f_ind_6])
+  # Now contains f_ind_6, f_ind_1, f_ind_2
+
+  # Check
+  GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
+  print "Group of Box's faces includes the following IDs:"
+  print "(must be ", f_ind_6, ", ", f_ind_1, " and ", f_ind_2, ")"
+  for ObjectID in GetObjectIDs:
+    print " ", ObjectID
+
   # -----------------------------------------------------------------------------
   # enumeration ShapeTypeString as a dictionary
   # -----------------------------------------------------------------------------
@@ -232,18 +303,51 @@ def TestOtherOperations (geompy, math):
   v_n0p = geompy.MakeVectorDXDYDZ(-1,  0,  1)
   v_pp0 = geompy.MakeVectorDXDYDZ( 1,  1,  0)
   v_np0 = geompy.MakeVectorDXDYDZ(-1,  1,  0)
-
-  pln_0pp = geompy.MakePlane(p0, v_0pp, 200)
-  pln_0np = geompy.MakePlane(p0, v_0np, 200)
-  pln_p0p = geompy.MakePlane(p0, v_p0p, 200)
-  pln_n0p = geompy.MakePlane(p0, v_n0p, 200)
-  pln_pp0 = geompy.MakePlane(p0, v_pp0, 200)
-  pln_np0 = geompy.MakePlane(p0, v_np0, 200)
-
-  part_tool = geompy.MakePartition([b0, pln_0pp, pln_0np, pln_p0p, pln_n0p, pln_pp0, pln_np0],
-                                   [],
-                                   [],
-                                   [b0])
+  v_0n0 = geompy.MakeVectorDXDYDZ( 0, -1,  0)
+
+  pln_0pp = geompy.MakePlane(p0, v_0pp, 300)
+  pln_0np = geompy.MakePlane(p0, v_0np, 300)
+  pln_p0p = geompy.MakePlane(p0, v_p0p, 300)
+  pln_n0p = geompy.MakePlane(p0, v_n0p, 300)
+  pln_pp0 = geompy.MakePlane(p0, v_pp0, 300)
+  pln_np0 = geompy.MakePlane(p0, v_np0, 300)
+
+  part_tool_1 = geompy.MakePartition([b0, pln_0pp, pln_0np, pln_p0p, pln_n0p, pln_pp0, pln_np0],
+                                     [],
+                                     [],
+                                     [b0])
+
+  pt_pnt_1  = geompy.MakeVertex( 55,   0,  55)
+  pt_pnt_2  = geompy.MakeVertex(  0,  55,  55)
+  pt_pnt_3  = geompy.MakeVertex(-55,   0,  55)
+  pt_pnt_4  = geompy.MakeVertex(  0, -55,  55)
+  pt_pnt_5  = geompy.MakeVertex( 55,  55,   0)
+  pt_pnt_6  = geompy.MakeVertex( 55, -55,   0)
+  pt_pnt_7  = geompy.MakeVertex(-55,  55,   0)
+  pt_pnt_8  = geompy.MakeVertex(-55, -55,   0)
+  pt_pnt_9  = geompy.MakeVertex( 55,   0, -55)
+  pt_pnt_10 = geompy.MakeVertex(  0,  55, -55)
+  pt_pnt_11 = geompy.MakeVertex(-55,   0, -55)
+  pt_pnt_12 = geompy.MakeVertex(  0, -55, -55)
+
+  pt_face_1  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_1)
+  pt_face_2  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_2)
+  pt_face_3  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_3)
+  pt_face_4  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_4)
+  pt_face_5  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_5)
+  pt_face_6  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_6)
+  pt_face_7  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_7)
+  pt_face_8  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_8)
+  pt_face_9  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_9)
+  pt_face_10 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_10)
+  pt_face_11 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_11)
+  pt_face_12 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_12)
+
+  pt_box = geompy.GetBlockNearPoint(part_tool_1, p0)
+
+  part_tool = geompy.MakeCompound([pt_face_1, pt_face_4, pt_face_7, pt_face_10,
+                                   pt_face_2, pt_face_5, pt_face_8, pt_face_11,
+                                   pt_face_3, pt_face_6, pt_face_9, pt_face_12, pt_box])
   id_part_tool = geompy.addToStudy(part_tool, "part_tool")
 
   part = geompy.MakePartition([s0], [part_tool])
@@ -278,11 +382,11 @@ def TestOtherOperations (geompy, math):
     geompy.addToStudyInFather(blocksComp, chain, "propagation chain")
 
   # GetPoint(theShape, theX, theY, theZ, theEpsilon)
-  # 
+  #
   # (-50,  50, 50) .-----. (50,  50, 50)
-  #      pb0_top_1 |     | 
+  #      pb0_top_1 |     |
   #                |     . pmidle
-  #                |     | 
+  #                |     |
   # (-50, -50, 50) '-----' (50, -50, 50)
   #
   pb0_top_1 = geompy.GetPoint(blocksComp, -50,  50,  50, 0.01)
@@ -302,8 +406,108 @@ def TestOtherOperations (geompy, math):
 
   geompy.addToStudyInFather(blocksComp, b0_image, "b0 image")
 
-  # GetShapesOnPlane(theShape, theShapeType, thePlane)
-  # GetShapesOnCylinder(theShape, theShapeType, theAxis, theRadius)
-  # GetShapesOnSphere(theShape, theShapeType, theCenter, theRadius)
+  # GetShapesOnPlane
+  faces_on_pln = geompy.GetShapesOnPlane(blocksComp, geompy.ShapeType["FACE"],
+                                         v_0pp, geompy.GEOM.ST_ONIN)
+  for face_i in faces_on_pln:
+    geompy.addToStudy(face_i, "Face on Plane (N = (0, 1, 1)) or below it")
+
+  # GetShapesOnPlaneIDs
+  faces_above_pln_ids = geompy.GetShapesOnPlaneIDs(blocksComp, geompy.ShapeType["FACE"],
+                                                   v_0pp, geompy.GEOM.ST_OUT)
+  faces_above = geompy.CreateGroup(blocksComp, geompy.ShapeType["FACE"])
+  geompy.UnionIDs(faces_above, faces_above_pln_ids)
+  geompy.addToStudy(faces_above, "Group of faces above Plane (N = (0, 1, 1))")
+
+  # GetShapesOnPlaneWithLocation
+  Loc = geompy.MakeVertex(0, -50, 0)
+  edges_on_pln = geompy.GetShapesOnPlaneWithLocation(blocksComp, geompy.ShapeType["EDGE"],
+                                                     v_0n0, Loc, geompy.GEOM.ST_ON)
+  for edge_i in edges_on_pln:
+    geompy.addToStudy(edge_i, "Edge on Plane (N = (0, -1, 0) & Location = (0, -50, 0)")
+    
+  # GetShapesOnPlaneWithLocationIDs
+  edges_on_pln_ids = geompy.GetShapesOnPlaneWithLocationIDs(blocksComp, geompy.ShapeType["EDGE"],
+                                                            v_0n0, Loc, geompy.GEOM.ST_ON)
+  group_edges_on_pln = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
+  geompy.UnionIDs(group_edges_on_pln, edges_on_pln_ids)
+  geompy.addToStudy(group_edges_on_pln, "Group of edges on Plane (N = (0, -1, 0) & Location = (0, -50, 0))")
+  
+  # GetShapesOnCylinder
+  edges_out_cyl = geompy.GetShapesOnCylinder(blocksComp, geompy.ShapeType["EDGE"],
+                                             vy, 55, geompy.GEOM.ST_OUT)
+  for edge_i in edges_out_cyl:
+    geompy.addToStudy(edge_i, "Edge out of Cylinder (axis = (0, 1, 0), r = 55)")
+
+  # GetShapesOnCylinderIDs
+  edges_in_cyl_ids = geompy.GetShapesOnCylinderIDs(blocksComp, geompy.ShapeType["EDGE"],
+                                                   vy, 80, geompy.GEOM.ST_IN)
+  edges_in = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
+  geompy.UnionIDs(edges_in, edges_in_cyl_ids)
+  geompy.addToStudy(edges_in, "Group of edges inside Cylinder (axis = (0, 1, 0), r = 55)")
+
+  # GetShapesOnSphere
+  vertices_on_sph = geompy.GetShapesOnSphere(blocksComp, geompy.ShapeType["VERTEX"],
+                                             p0, 100, geompy.GEOM.ST_ON)
+  for vertex_i in vertices_on_sph:
+    geompy.addToStudy(vertex_i, "Vertex on Sphere (center = (0, 0, 0), r = 100)")
+    pass
+
+  # GetShapesOnSphereIDs
+  vertices_on_sph_ids = geompy.GetShapesOnSphereIDs(blocksComp, geompy.ShapeType["VERTEX"],
+                                                    p0, 100, geompy.GEOM.ST_ON)
+  vertices_on = geompy.CreateGroup(blocksComp, geompy.ShapeType["VERTEX"])
+  geompy.UnionIDs(vertices_on, vertices_on_sph_ids)
+  geompy.addToStudy(vertices_on, "Group of vertices on Sphere (center = (0, 0, 0), r = 100)")
+
+  # GetShapesOnQuadrangle
+
+  geompy.addToStudy(f12, "F12" )
+
+  bl = geompy.MakeVertex(10,-10, 0)
+  br = geompy.MakeVertex(40,-10, 0)
+  tr = geompy.MakeVertex(40, 20, 0)
+  tl = geompy.MakeVertex(10, 20, 0)
+  qe1 = geompy.MakeEdge(bl, br)
+  qe2 = geompy.MakeEdge(br, tr)
+  qe3 = geompy.MakeEdge(tr, tl)
+  qe4 = geompy.MakeEdge(tl, bl)
+  quadrangle = geompy.MakeWire([qe1, qe2, qe3, qe4])
+  geompy.addToStudy(quadrangle, "Quadrangle")
+
+  edges_onin_quad = geompy.GetShapesOnQuadrangle( f12, geompy.ShapeType["EDGE"],
+                                                  tl, tr, bl, br, geompy.GEOM.ST_ONIN)
+  comp = geompy.MakeCompound(edges_onin_quad)
+  geompy.addToStudy(comp, "Edges of F12 ONIN Quadrangle")
+  if len( edges_onin_quad ) != 4:
+    print "Error in GetShapesOnQuadrangle()"
+    pass
+
+  # GetShapesOnQuadrangleIDs
+  vertices_on_quad_ids = geompy.GetShapesOnQuadrangleIDs(f12, geompy.ShapeType["VERTEX"],
+                                                         tl, tr, bl, br, geompy.GEOM.ST_ON)
+  vertices_on_quad = geompy.CreateGroup(f12, geompy.ShapeType["VERTEX"])
+  geompy.UnionIDs(vertices_on_quad, vertices_on_quad_ids)
+  geompy.addToStudy(vertices_on_quad, "Group of vertices on Quadrangle F12")
 
   # GetInPlace(theShapeWhere, theShapeWhat)
+  box5 = geompy.MakeBoxDXDYDZ(100, 100, 100)
+  box6 = geompy.MakeTranslation(box5, 50, 50, 0)
+
+  part = geompy.MakePartition([box5], [box6])
+  geompy.addToStudy(part, "Partitioned")
+
+  ibb = 5
+  box_list = [box5, box6]
+  for abox in box_list:
+    geompy.addToStudy(abox, "Box " + `ibb`)
+    box_faces = geompy.SubShapeAll(abox, geompy.ShapeType["FACE"])
+    ifa = 1
+    for aface in box_faces:
+      geompy.addToStudyInFather(abox, aface, "Face" + `ifa`)
+      refl_box_face = geompy.GetInPlace(part, aface)
+      if refl_box_face is not None:
+        geompy.addToStudyInFather(part, refl_box_face,
+                                  "Reflection of Face " + `ifa` + " of box " + `ibb`)
+      ifa = ifa + 1
+    ibb = ibb + 1