Salome HOME
Bug 0020029: EDF 845 GEOM: impossible to set a negative angle for the revolution...
[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/ or email : webmaster.salome@opencascade.com
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   ####### GetNormal #######
113
114   faces = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])
115   face0 = faces[0]
116   vnorm = geompy.GetNormal(face0)
117   if vnorm is None:
118     raise RuntimeError, "GetNormal(face0) failed"
119   else:
120     geompy.addToStudy(face0, "Face0")
121     geompy.addToStudy(vnorm, "Normale to Face0")
122     print "\nNormale of face has been successfully obtained:"
123     #Coords = geompy.PointCoordinates(pcdg)
124     #print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
125     #if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
126     #  print "But must be (5, 15, 35)"
127
128   ####### MinDistance #######
129
130   MinDist = geompy.MinDistance(box, cube)
131
132   #print "\nMinimal distance between Box and Cube = ", MinDist[0]
133   #print "It is reached at points:"
134   #print " On Box  (", MinDist[1], ", ", MinDist[2], ", ", MinDist[3], ")"
135   #print " On Cube (", MinDist[4], ", ", MinDist[5], ", ", MinDist[6], ")"
136
137   print "\nMinimal distance between Box and Cube = ", MinDist
138
139   MinDistComps = geompy.MinDistanceComponents(box, cube)
140   print "\nMinimal distance between Box and Cube = ", MinDistComps[0]
141   print "Its components are  (", MinDistComps[1], ", ", MinDistComps[2], ", ", MinDistComps[3], ")"
142
143   ####### Angle #######
144
145   OX  = geompy.MakeVectorDXDYDZ(10, 0,0)
146   OXY = geompy.MakeVectorDXDYDZ(10,10,0)
147
148   # in one plane
149   Angle = geompy.GetAngle(OX, OXY)
150
151   print "\nAngle between OX and OXY = ", Angle
152   if math.fabs(Angle - 45.0) > 1e-05:
153     print "  Error: returned angle is", Angle, "while must be 45.0"
154
155   Angle = geompy.GetAngleRadians(OX, OXY)
156
157   print "\nAngle between OX and OXY in radians = ", Angle
158   if math.fabs(Angle - math.pi/4) > 1e-05:
159     print "  Error: returned angle is", Angle, "while must be pi/4"
160     pass
161
162   # not in one plane
163   OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
164   Angle = geompy.GetAngle(OX, OXY_shift)
165
166   print "Angle between OX and OXY_shift = ", Angle
167   if math.fabs(Angle - 45.0) > 1e-05:
168     print "  Error: returned angle is", Angle, "while must be 45.0"
169
170   ####### Position (LCS) #######
171
172   Pos = geompy.GetPosition(box)
173   print "\nPosition(LCS) of box 10x30x70:"
174   print "Origin: (", Pos[0], ", ", Pos[1], ", ", Pos[2], ")"
175   print "Z axis: (", Pos[3], ", ", Pos[4], ", ", Pos[5], ")"
176   print "X axis: (", Pos[6], ", ", Pos[7], ", ", Pos[8], ")"
177
178   ####### KindOfShape #######
179
180   Kind = geompy.KindOfShape(box)
181   print "\nKindOfShape(box 10x30x70):", Kind
182   #if Kind[0] != geompy.kind.BOX:
183   #  print "Error: returned type is", Kind[0], "while must be", geompy.kind.BOX
184
185   Kind = geompy.KindOfShape(p137)
186   print "\nKindOfShape(p137):", Kind
187   if Kind[0] != geompy.kind.VERTEX:
188     print "  Error: returned type is", Kind[0], "while must be", geompy.kind.VERTEX
189   else:
190     dx = math.fabs(Kind[1] - 10)
191     dy = math.fabs(Kind[2] - 30)
192     dz = math.fabs(Kind[3] - 70)
193     if (dx + dy + dz) > 1e-5:
194       print "  Error: coordinates are (", Kind[1], ",", Kind[2], ",", Kind[3], ") while must be (10, 20, 30)"
195
196   pass