]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_SWIG/GEOM_TestMeasures.py
Salome HOME
PAL8375 improvement solving.
[modules/geom.git] / src / GEOM_SWIG / GEOM_TestMeasures.py
1 def TestMeasureOperations (geompy, math):
2
3   p0   = geompy.MakeVertex(0 ,  0,  0)
4   p137 = geompy.MakeVertex(10, 30, 70)
5
6   box = geompy.MakeBoxTwoPnt(p0, p137)
7
8   p678 = geompy.MakeVertex(60, 70, 80)
9   p789 = geompy.MakeVertex(70, 80, 90)
10
11   cube = geompy.MakeBoxTwoPnt(p678, p789)
12
13   ####### PointCoordinates #######
14
15   Coords = geompy.PointCoordinates(p137)
16   if Coords[0] != 10 or Coords[1] != 30 or Coords[2] != 70:
17     print "Coordinates of p137 must be (10, 30, 70), but returned (", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
18
19   ####### CheckShape #######
20
21   IsValid = geompy.CheckShape(box)
22   if IsValid == 0:
23     raise RuntimeError, "Invalid box created"
24   else:
25     print "\nBox is valid"
26
27   ####### WhatIs #######
28
29   Descr = geompy.WhatIs(box)
30   print "\nBox 10x30x70 description:"
31   print Descr
32
33   ####### BasicProperties #######
34
35   Props = geompy.BasicProperties(box)
36   print "\nBox 10x30x70 Basic Properties:"
37   print " Wires length: ", Props[0]
38   print " Surface area: ", Props[1]
39   print " Volume      : ", Props[2]
40
41   dl = math.sqrt((Props[0] -   880)*(Props[0] -   880))
42   da = math.sqrt((Props[1] -  6200)*(Props[1] -  6200))
43   dv = math.sqrt((Props[2] - 21000)*(Props[2] - 21000))
44   #print "|Props[0] - 880| = ", dl
45
46   if dl > 1e-7 or da > 1e-7 or dv > 1e-7:
47     print "While must be:"
48     print " Wires length: ", 880
49     print " Surface area: ", 6200
50     print " Volume      : ", 21000
51
52   ####### BoundingBox #######
53
54   BB = geompy.BoundingBox(box)
55   print "\nBounding Box of box 10x30x70:"
56   print " Xmin = ", BB[0], ", Xmax = ", BB[1]
57   print " Ymin = ", BB[2], ", Ymax = ", BB[3]
58   print " Zmin = ", BB[4], ", Zmax = ", BB[5]
59
60   ####### Inertia #######
61
62   In = geompy.Inertia(box)
63   print "\nInertia matrix of box 10x30x70:"
64   print " (", In[0], ", ", In[1], ", ", In[2], ")"
65   print " (", In[3], ", ", In[4], ", ", In[5], ")"
66   print " (", In[6], ", ", In[7], ", ", In[8], ")"
67   print "Main moments of inertia of box 10x30x70:"
68   print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]
69
70   ####### Tolerance #######
71
72   Toler = geompy.Tolerance(box)
73   print "\nBox 10x30x70 tolerance:"
74   print " Face min. tolerance: ", Toler[0]
75   print " Face max. tolerance: ", Toler[1]
76   print " Edge min. tolerance: ", Toler[2]
77   print " Edge max. tolerance: ", Toler[3]
78   print " Vertex min. tolerance: ", Toler[4]
79   print " Vertex max. tolerance: ", Toler[5]
80
81   ####### MakeCDG #######
82
83   pcdg = geompy.MakeCDG(box)
84   if pcdg is None:
85     raise RuntimeError, "MakeCDG(box) failed"
86   else:
87     print "\nCentre of gravity of box has been successfully obtained:"
88     Coords = geompy.PointCoordinates(pcdg)
89     print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
90     if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
91       print "But must be (5, 15, 35)"
92
93   ####### MinDistance #######
94
95   MinDist = geompy.MinDistance(box, cube)
96
97   #print "\nMinimal distance between Box and Cube = ", MinDist[0]
98   #print "It is reached at points:"
99   #print " On Box  (", MinDist[1], ", ", MinDist[2], ", ", MinDist[3], ")"
100   #print " On Cube (", MinDist[4], ", ", MinDist[5], ", ", MinDist[6], ")"
101
102   print "\nMinimal distance between Box and Cube = ", MinDist