]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_SWIG/GEOM_TestMeasures.py
Salome HOME
Fix memory leaks
[modules/geom.git] / src / GEOM_SWIG / GEOM_TestMeasures.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 import salome_version
25
26 def TestMeasureOperations (geompy, math):
27
28   p0   = geompy.MakeVertex(0 ,  0,  0)
29   p137 = geompy.MakeVertex(10, 30, 70)
30
31   box = geompy.MakeBoxTwoPnt(p0, p137)
32
33   p678 = geompy.MakeVertex(60, 70, 80)
34   p789 = geompy.MakeVertex(70, 80, 90)
35
36   cube = geompy.MakeBoxTwoPnt(p678, p789)
37
38   ####### PointCoordinates #######
39
40   Coords = geompy.PointCoordinates(p137)
41   if Coords[0] != 10 or Coords[1] != 30 or Coords[2] != 70:
42     print "Coordinates of p137 must be (10, 30, 70), but returned (", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
43
44   ####### CheckShape #######
45
46   (IsValid, err) = geompy.CheckShape(box, 0, 2)
47   if IsValid == 0:
48     geompy.PrintShapeError(box, err)
49     raise RuntimeError, "Invalid box created"
50   else:
51     print "\nBox is valid"
52
53   ####### Detect Self-intersections #######
54
55   [Face_1,Face_2] = geompy.SubShapes(box, [33, 23])
56   Translation_1 = geompy.MakeTranslation(Face_1, 5, -15, -40)
57   Compound_1 = geompy.MakeCompound([Face_2, Translation_1])
58   if geompy.CheckSelfIntersections(Compound_1) == True:
59     raise RuntimeError, "Existing self-intersection is not detected"
60
61   ####### Detect Fast intersection #######
62
63   if salome_version.getXVersion() > "0x70501":
64     cylinder = geompy.MakeCylinderRH(100, 300)
65     if geompy.FastIntersect(box, cylinder)[0] == False:
66       raise RuntimeError, "Existing intersection is not detected"
67
68   ####### WhatIs #######
69
70   Descr = geompy.WhatIs(box)
71   print "\nBox 10x30x70 description:"
72   print Descr
73
74   ####### NbShapes #######
75
76   NbSolids = geompy.NbShapes(box, geompy.ShapeType["SOLID"])
77   print "\nBox 10x30x70 quantity of solids:", NbSolids
78
79   ####### ShapeInfo #######
80
81   BoxInfo = geompy.ShapeInfo(box)
82   print "\nBox 10x30x70 shapes:"
83   print BoxInfo
84
85   ####### BasicProperties #######
86
87   Props = geompy.BasicProperties(box)
88   print "\nBox 10x30x70 Basic Properties:"
89   print " Wires length: ", Props[0]
90   print " Surface area: ", Props[1]
91   print " Volume      : ", Props[2]
92
93   dl = math.sqrt((Props[0] -   880)*(Props[0] -   880))
94   da = math.sqrt((Props[1] -  6200)*(Props[1] -  6200))
95   dv = math.sqrt((Props[2] - 21000)*(Props[2] - 21000))
96   #print "|Props[0] - 880| = ", dl
97
98   if dl > 1e-7 or da > 1e-7 or dv > 1e-7:
99     print "While must be:"
100     print " Wires length: ", 880
101     print " Surface area: ", 6200
102     print " Volume      : ", 21000
103
104   ####### BoundingBox #######
105
106   BB = geompy.BoundingBox(box)
107   print "\nBounding Box of box 10x30x70:"
108   print " Xmin = ", BB[0], ", Xmax = ", BB[1]
109   print " Ymin = ", BB[2], ", Ymax = ", BB[3]
110   print " Zmin = ", BB[4], ", Zmax = ", BB[5]
111   BB = geompy.MakeBoundingBox(box)
112   geompy.addToStudy(BB, "BoundingBox")
113
114   ####### Inertia #######
115
116   In = geompy.Inertia(box)
117   print "\nInertia matrix of box 10x30x70:"
118   print " (", In[0], ", ", In[1], ", ", In[2], ")"
119   print " (", In[3], ", ", In[4], ", ", In[5], ")"
120   print " (", In[6], ", ", In[7], ", ", In[8], ")"
121   print "Main moments of inertia of box 10x30x70:"
122   print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]
123
124   ####### Tolerance #######
125
126   Toler = geompy.Tolerance(box)
127   print "\nBox 10x30x70 tolerance:"
128   print " Face min. tolerance: ", Toler[0]
129   print " Face max. tolerance: ", Toler[1]
130   print " Edge min. tolerance: ", Toler[2]
131   print " Edge max. tolerance: ", Toler[3]
132   print " Vertex min. tolerance: ", Toler[4]
133   print " Vertex max. tolerance: ", Toler[5]
134
135   ####### MakeCDG #######
136
137   pcdg = geompy.MakeCDG(box)
138   if pcdg is None:
139     raise RuntimeError, "MakeCDG(box) failed"
140   else:
141     print "\nCentre of gravity of box has been successfully obtained:"
142     Coords = geompy.PointCoordinates(pcdg)
143     print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
144     if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
145       print "But must be (5, 15, 35)"
146
147   ####### GetNormal #######
148
149   faces = geompy.SubShapeAllSortedCentres(box, geompy.ShapeType["FACE"])
150   face0 = faces[0]
151   vnorm = geompy.GetNormal(face0)
152   if vnorm is None:
153     raise RuntimeError, "GetNormal(face0) failed"
154   else:
155     geompy.addToStudy(face0, "Face0")
156     geompy.addToStudy(vnorm, "Normale to Face0")
157     print "\nNormale of face has been successfully obtained:"
158     #Coords = geompy.PointCoordinates(pcdg)
159     #print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
160     #if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
161     #  print "But must be (5, 15, 35)"
162
163   ####### MinDistance #######
164
165   MinDist = geompy.MinDistance(box, cube)
166
167   #print "\nMinimal distance between Box and Cube = ", MinDist[0]
168   #print "It is reached at points:"
169   #print " On Box  (", MinDist[1], ", ", MinDist[2], ", ", MinDist[3], ")"
170   #print " On Cube (", MinDist[4], ", ", MinDist[5], ", ", MinDist[6], ")"
171
172   print "\nMinimal distance between Box and Cube = ", MinDist
173
174   MinDistComps = geompy.MinDistanceComponents(box, cube)
175   print "\nMinimal distance between Box and Cube = ", MinDistComps[0]
176   print "Its components are  (", MinDistComps[1], ", ", MinDistComps[2], ", ", MinDistComps[3], ")"
177
178   # Get all closest points
179   [nbSols, listCoords] = geompy.ClosestPoints(box, cube)
180   for i in range(nbSols):
181     v1 = geompy.MakeVertex(listCoords[i*6 + 0], listCoords[i*6 + 1], listCoords[i*6 + 2])
182     v2 = geompy.MakeVertex(listCoords[i*6 + 3], listCoords[i*6 + 4], listCoords[i*6 + 5])
183
184     geompy.addToStudy(v1, 'MinDist_%d_on_Box'%(i+1))
185     geompy.addToStudy(v2, 'MinDist_%d_on_Cube'%(i+1))
186     pass
187
188   ####### Angle #######
189
190   OX  = geompy.MakeVectorDXDYDZ(10, 0,0)
191   OXY = geompy.MakeVectorDXDYDZ(10,10,0)
192
193   # in one plane
194   Angle = geompy.GetAngle(OX, OXY)
195
196   print "\nAngle between OX and OXY = ", Angle
197   if math.fabs(Angle - 45.0) > 1e-05:
198     print "  Error: returned angle is", Angle, "while must be 45.0"
199
200   Angle = geompy.GetAngleRadians(OX, OXY)
201
202   print "\nAngle between OX and OXY in radians = ", Angle
203   if math.fabs(Angle - math.pi/4) > 1e-05:
204     print "  Error: returned angle is", Angle, "while must be pi/4"
205     pass
206
207   # not in one plane
208   OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
209   Angle = geompy.GetAngle(OX, OXY_shift)
210
211   print "Angle between OX and OXY_shift = ", Angle
212   if math.fabs(Angle - 45.0) > 1e-05:
213     print "  Error: returned angle is", Angle, "while must be 45.0"
214
215   ####### Position (LCS) #######
216
217   Pos = geompy.GetPosition(box)
218   print "\nPosition(LCS) of box 10x30x70:"
219   print "Origin: (", Pos[0], ", ", Pos[1], ", ", Pos[2], ")"
220   print "Z axis: (", Pos[3], ", ", Pos[4], ", ", Pos[5], ")"
221   print "X axis: (", Pos[6], ", ", Pos[7], ", ", Pos[8], ")"
222
223   ####### KindOfShape #######
224
225   Kind = geompy.KindOfShape(box)
226   print "\nKindOfShape(box 10x30x70):", Kind
227   #if Kind[0] != geompy.kind.BOX:
228   #  print "Error: returned type is", Kind[0], "while must be", geompy.kind.BOX
229
230   Kind = geompy.KindOfShape(p137)
231   print "\nKindOfShape(p137):", Kind
232   if Kind[0] != geompy.kind.VERTEX:
233     print "  Error: returned type is", Kind[0], "while must be", geompy.kind.VERTEX
234   else:
235     dx = math.fabs(Kind[1] - 10)
236     dy = math.fabs(Kind[2] - 30)
237     dz = math.fabs(Kind[3] - 70)
238     if (dx + dy + dz) > 1e-5:
239       print "  Error: coordinates are (", Kind[1], ",", Kind[2], ",", Kind[3], ") while must be (10, 20, 30)"
240
241   pass