Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/geom.git] / src / GEOM_SWIG / GEOM_TestMeasures.py
1 #  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 #  See http://www.salome-platform.org/
19 #
20 def TestMeasureOperations (geompy, math):
21
22   p0   = geompy.MakeVertex(0 ,  0,  0)
23   p137 = geompy.MakeVertex(10, 30, 70)
24
25   box = geompy.MakeBoxTwoPnt(p0, p137)
26
27   p678 = geompy.MakeVertex(60, 70, 80)
28   p789 = geompy.MakeVertex(70, 80, 90)
29
30   cube = geompy.MakeBoxTwoPnt(p678, p789)
31
32   ####### PointCoordinates #######
33
34   Coords = geompy.PointCoordinates(p137)
35   if Coords[0] != 10 or Coords[1] != 30 or Coords[2] != 70:
36     print "Coordinates of p137 must be (10, 30, 70), but returned (", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
37
38   ####### CheckShape #######
39
40   IsValid = geompy.CheckShape(box)
41   if IsValid == 0:
42     raise RuntimeError, "Invalid box created"
43   else:
44     print "\nBox is valid"
45
46   ####### WhatIs #######
47
48   Descr = geompy.WhatIs(box)
49   print "\nBox 10x30x70 description:"
50   print Descr
51
52   ####### BasicProperties #######
53
54   Props = geompy.BasicProperties(box)
55   print "\nBox 10x30x70 Basic Properties:"
56   print " Wires length: ", Props[0]
57   print " Surface area: ", Props[1]
58   print " Volume      : ", Props[2]
59
60   dl = math.sqrt((Props[0] -   880)*(Props[0] -   880))
61   da = math.sqrt((Props[1] -  6200)*(Props[1] -  6200))
62   dv = math.sqrt((Props[2] - 21000)*(Props[2] - 21000))
63   #print "|Props[0] - 880| = ", dl
64
65   if dl > 1e-7 or da > 1e-7 or dv > 1e-7:
66     print "While must be:"
67     print " Wires length: ", 880
68     print " Surface area: ", 6200
69     print " Volume      : ", 21000
70
71   ####### BoundingBox #######
72
73   BB = geompy.BoundingBox(box)
74   print "\nBounding Box of box 10x30x70:"
75   print " Xmin = ", BB[0], ", Xmax = ", BB[1]
76   print " Ymin = ", BB[2], ", Ymax = ", BB[3]
77   print " Zmin = ", BB[4], ", Zmax = ", BB[5]
78
79   ####### Inertia #######
80
81   In = geompy.Inertia(box)
82   print "\nInertia matrix of box 10x30x70:"
83   print " (", In[0], ", ", In[1], ", ", In[2], ")"
84   print " (", In[3], ", ", In[4], ", ", In[5], ")"
85   print " (", In[6], ", ", In[7], ", ", In[8], ")"
86   print "Main moments of inertia of box 10x30x70:"
87   print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]
88
89   ####### Tolerance #######
90
91   Toler = geompy.Tolerance(box)
92   print "\nBox 10x30x70 tolerance:"
93   print " Face min. tolerance: ", Toler[0]
94   print " Face max. tolerance: ", Toler[1]
95   print " Edge min. tolerance: ", Toler[2]
96   print " Edge max. tolerance: ", Toler[3]
97   print " Vertex min. tolerance: ", Toler[4]
98   print " Vertex max. tolerance: ", Toler[5]
99
100   ####### MakeCDG #######
101
102   pcdg = geompy.MakeCDG(box)
103   if pcdg is None:
104     raise RuntimeError, "MakeCDG(box) failed"
105   else:
106     print "\nCentre of gravity of box has been successfully obtained:"
107     Coords = geompy.PointCoordinates(pcdg)
108     print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
109     if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
110       print "But must be (5, 15, 35)"
111
112   ####### MinDistance #######
113
114   MinDist = geompy.MinDistance(box, cube)
115
116   #print "\nMinimal distance between Box and Cube = ", MinDist[0]
117   #print "It is reached at points:"
118   #print " On Box  (", MinDist[1], ", ", MinDist[2], ", ", MinDist[3], ")"
119   #print " On Cube (", MinDist[4], ", ", MinDist[5], ", ", MinDist[6], ")"
120
121   print "\nMinimal distance between Box and Cube = ", MinDist