Salome HOME
IMPs 21044, 21057, 21067
[modules/geom.git] / src / GEOM_SWIG / GEOM_TestMeasures.py
index 1700ca16785fa1ef9d43eff20bee070e97cd9746..8eca09311fd749326e12c8e641d78e86c704640e 100644 (file)
@@ -1,4 +1,7 @@
-#  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+#  -*- coding: iso-8859-1 -*-
+#  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+#
+#  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #
 #  This library is free software; you can redistribute it and/or
@@ -15,8 +18,9 @@
 #  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/
+#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
+
 def TestMeasureOperations (geompy, math):
 
   p0   = geompy.MakeVertex(0 ,  0,  0)
@@ -49,6 +53,17 @@ def TestMeasureOperations (geompy, math):
   print "\nBox 10x30x70 description:"
   print Descr
 
+  ####### NbShapes #######
+
+  NbSolids = geompy.NbShapes(box, geompy.ShapeType["SOLID"])
+  print "\nBox 10x30x70 quantity of solids:", NbSolids
+
+  ####### ShapeInfo #######
+
+  BoxInfo = geompy.ShapeInfo(box)
+  print "\nBox 10x30x70 shapes:"
+  print BoxInfo
+
   ####### BasicProperties #######
 
   Props = geompy.BasicProperties(box)
@@ -109,6 +124,22 @@ def TestMeasureOperations (geompy, math):
     if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
       print "But must be (5, 15, 35)"
 
+  ####### GetNormal #######
+
+  faces = geompy.SubShapeAllSortedCentres(box, geompy.ShapeType["FACE"])
+  face0 = faces[0]
+  vnorm = geompy.GetNormal(face0)
+  if vnorm is None:
+    raise RuntimeError, "GetNormal(face0) failed"
+  else:
+    geompy.addToStudy(face0, "Face0")
+    geompy.addToStudy(vnorm, "Normale to Face0")
+    print "\nNormale of face has been successfully obtained:"
+    #Coords = geompy.PointCoordinates(pcdg)
+    #print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
+    #if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
+    #  print "But must be (5, 15, 35)"
+
   ####### MinDistance #######
 
   MinDist = geompy.MinDistance(box, cube)
@@ -119,3 +150,62 @@ def TestMeasureOperations (geompy, math):
   #print " On Cube (", MinDist[4], ", ", MinDist[5], ", ", MinDist[6], ")"
 
   print "\nMinimal distance between Box and Cube = ", MinDist
+
+  MinDistComps = geompy.MinDistanceComponents(box, cube)
+  print "\nMinimal distance between Box and Cube = ", MinDistComps[0]
+  print "Its components are  (", MinDistComps[1], ", ", MinDistComps[2], ", ", MinDistComps[3], ")"
+
+  ####### Angle #######
+
+  OX  = geompy.MakeVectorDXDYDZ(10, 0,0)
+  OXY = geompy.MakeVectorDXDYDZ(10,10,0)
+
+  # in one plane
+  Angle = geompy.GetAngle(OX, OXY)
+
+  print "\nAngle between OX and OXY = ", Angle
+  if math.fabs(Angle - 45.0) > 1e-05:
+    print "  Error: returned angle is", Angle, "while must be 45.0"
+
+  Angle = geompy.GetAngleRadians(OX, OXY)
+
+  print "\nAngle between OX and OXY in radians = ", Angle
+  if math.fabs(Angle - math.pi/4) > 1e-05:
+    print "  Error: returned angle is", Angle, "while must be pi/4"
+    pass
+
+  # not in one plane
+  OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
+  Angle = geompy.GetAngle(OX, OXY_shift)
+
+  print "Angle between OX and OXY_shift = ", Angle
+  if math.fabs(Angle - 45.0) > 1e-05:
+    print "  Error: returned angle is", Angle, "while must be 45.0"
+
+  ####### Position (LCS) #######
+
+  Pos = geompy.GetPosition(box)
+  print "\nPosition(LCS) of box 10x30x70:"
+  print "Origin: (", Pos[0], ", ", Pos[1], ", ", Pos[2], ")"
+  print "Z axis: (", Pos[3], ", ", Pos[4], ", ", Pos[5], ")"
+  print "X axis: (", Pos[6], ", ", Pos[7], ", ", Pos[8], ")"
+
+  ####### KindOfShape #######
+
+  Kind = geompy.KindOfShape(box)
+  print "\nKindOfShape(box 10x30x70):", Kind
+  #if Kind[0] != geompy.kind.BOX:
+  #  print "Error: returned type is", Kind[0], "while must be", geompy.kind.BOX
+
+  Kind = geompy.KindOfShape(p137)
+  print "\nKindOfShape(p137):", Kind
+  if Kind[0] != geompy.kind.VERTEX:
+    print "  Error: returned type is", Kind[0], "while must be", geompy.kind.VERTEX
+  else:
+    dx = math.fabs(Kind[1] - 10)
+    dy = math.fabs(Kind[2] - 30)
+    dz = math.fabs(Kind[3] - 70)
+    if (dx + dy + dz) > 1e-5:
+      print "  Error: coordinates are (", Kind[1], ",", Kind[2], ",", Kind[3], ") while must be (10, 20, 30)"
+
+  pass