]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_SWIG/GEOM_TestMeasures.py
Salome HOME
0021672: [CEA 565] Dump Study from script
[modules/geom.git] / src / GEOM_SWIG / GEOM_TestMeasures.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2012  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.
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 def TestMeasureOperations (geompy, math):
25
26   p0   = geompy.MakeVertex(0 ,  0,  0)
27   p137 = geompy.MakeVertex(10, 30, 70)
28
29   box = geompy.MakeBoxTwoPnt(p0, p137)
30
31   p678 = geompy.MakeVertex(60, 70, 80)
32   p789 = geompy.MakeVertex(70, 80, 90)
33
34   cube = geompy.MakeBoxTwoPnt(p678, p789)
35
36   ####### PointCoordinates #######
37
38   Coords = geompy.PointCoordinates(p137)
39   if Coords[0] != 10 or Coords[1] != 30 or Coords[2] != 70:
40     print "Coordinates of p137 must be (10, 30, 70), but returned (", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
41
42   ####### CheckShape #######
43
44   IsValid = geompy.CheckShape(box)
45   if IsValid == 0:
46     raise RuntimeError, "Invalid box created"
47   else:
48     print "\nBox is valid"
49
50   ####### Detect Self-intersections #######
51
52   [Face_1,Face_2] = geompy.SubShapes(box, [33, 23])
53   Translation_1 = geompy.MakeTranslation(Face_1, 5, -15, -40)
54   Compound_1 = geompy.MakeCompound([Face_2, Translation_1])
55   if geompy.CheckSelfIntersections(Compound_1) == True:
56     raise RuntimeError, "Existing self-intersection is not detected"
57
58   ####### WhatIs #######
59
60   Descr = geompy.WhatIs(box)
61   print "\nBox 10x30x70 description:"
62   print Descr
63
64   ####### NbShapes #######
65
66   NbSolids = geompy.NbShapes(box, geompy.ShapeType["SOLID"])
67   print "\nBox 10x30x70 quantity of solids:", NbSolids
68
69   ####### ShapeInfo #######
70
71   BoxInfo = geompy.ShapeInfo(box)
72   print "\nBox 10x30x70 shapes:"
73   print BoxInfo
74
75   ####### BasicProperties #######
76
77   Props = geompy.BasicProperties(box)
78   print "\nBox 10x30x70 Basic Properties:"
79   print " Wires length: ", Props[0]
80   print " Surface area: ", Props[1]
81   print " Volume      : ", Props[2]
82
83   dl = math.sqrt((Props[0] -   880)*(Props[0] -   880))
84   da = math.sqrt((Props[1] -  6200)*(Props[1] -  6200))
85   dv = math.sqrt((Props[2] - 21000)*(Props[2] - 21000))
86   #print "|Props[0] - 880| = ", dl
87
88   if dl > 1e-7 or da > 1e-7 or dv > 1e-7:
89     print "While must be:"
90     print " Wires length: ", 880
91     print " Surface area: ", 6200
92     print " Volume      : ", 21000
93
94   ####### BoundingBox #######
95
96   BB = geompy.BoundingBox(box)
97   print "\nBounding Box of box 10x30x70:"
98   print " Xmin = ", BB[0], ", Xmax = ", BB[1]
99   print " Ymin = ", BB[2], ", Ymax = ", BB[3]
100   print " Zmin = ", BB[4], ", Zmax = ", BB[5]
101
102   ####### Inertia #######
103
104   In = geompy.Inertia(box)
105   print "\nInertia matrix of box 10x30x70:"
106   print " (", In[0], ", ", In[1], ", ", In[2], ")"
107   print " (", In[3], ", ", In[4], ", ", In[5], ")"
108   print " (", In[6], ", ", In[7], ", ", In[8], ")"
109   print "Main moments of inertia of box 10x30x70:"
110   print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]
111
112   ####### Tolerance #######
113
114   Toler = geompy.Tolerance(box)
115   print "\nBox 10x30x70 tolerance:"
116   print " Face min. tolerance: ", Toler[0]
117   print " Face max. tolerance: ", Toler[1]
118   print " Edge min. tolerance: ", Toler[2]
119   print " Edge max. tolerance: ", Toler[3]
120   print " Vertex min. tolerance: ", Toler[4]
121   print " Vertex max. tolerance: ", Toler[5]
122
123   ####### MakeCDG #######
124
125   pcdg = geompy.MakeCDG(box)
126   if pcdg is None:
127     raise RuntimeError, "MakeCDG(box) failed"
128   else:
129     print "\nCentre of gravity of box has been successfully obtained:"
130     Coords = geompy.PointCoordinates(pcdg)
131     print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
132     if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
133       print "But must be (5, 15, 35)"
134
135   ####### GetNormal #######
136
137   faces = geompy.SubShapeAllSortedCentres(box, geompy.ShapeType["FACE"])
138   face0 = faces[0]
139   vnorm = geompy.GetNormal(face0)
140   if vnorm is None:
141     raise RuntimeError, "GetNormal(face0) failed"
142   else:
143     geompy.addToStudy(face0, "Face0")
144     geompy.addToStudy(vnorm, "Normale to Face0")
145     print "\nNormale of face has been successfully obtained:"
146     #Coords = geompy.PointCoordinates(pcdg)
147     #print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
148     #if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
149     #  print "But must be (5, 15, 35)"
150
151   ####### MinDistance #######
152
153   MinDist = geompy.MinDistance(box, cube)
154
155   #print "\nMinimal distance between Box and Cube = ", MinDist[0]
156   #print "It is reached at points:"
157   #print " On Box  (", MinDist[1], ", ", MinDist[2], ", ", MinDist[3], ")"
158   #print " On Cube (", MinDist[4], ", ", MinDist[5], ", ", MinDist[6], ")"
159
160   print "\nMinimal distance between Box and Cube = ", MinDist
161
162   MinDistComps = geompy.MinDistanceComponents(box, cube)
163   print "\nMinimal distance between Box and Cube = ", MinDistComps[0]
164   print "Its components are  (", MinDistComps[1], ", ", MinDistComps[2], ", ", MinDistComps[3], ")"
165
166   ####### Angle #######
167
168   OX  = geompy.MakeVectorDXDYDZ(10, 0,0)
169   OXY = geompy.MakeVectorDXDYDZ(10,10,0)
170
171   # in one plane
172   Angle = geompy.GetAngle(OX, OXY)
173
174   print "\nAngle between OX and OXY = ", Angle
175   if math.fabs(Angle - 45.0) > 1e-05:
176     print "  Error: returned angle is", Angle, "while must be 45.0"
177
178   Angle = geompy.GetAngleRadians(OX, OXY)
179
180   print "\nAngle between OX and OXY in radians = ", Angle
181   if math.fabs(Angle - math.pi/4) > 1e-05:
182     print "  Error: returned angle is", Angle, "while must be pi/4"
183     pass
184
185   # not in one plane
186   OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
187   Angle = geompy.GetAngle(OX, OXY_shift)
188
189   print "Angle between OX and OXY_shift = ", Angle
190   if math.fabs(Angle - 45.0) > 1e-05:
191     print "  Error: returned angle is", Angle, "while must be 45.0"
192
193   ####### Position (LCS) #######
194
195   Pos = geompy.GetPosition(box)
196   print "\nPosition(LCS) of box 10x30x70:"
197   print "Origin: (", Pos[0], ", ", Pos[1], ", ", Pos[2], ")"
198   print "Z axis: (", Pos[3], ", ", Pos[4], ", ", Pos[5], ")"
199   print "X axis: (", Pos[6], ", ", Pos[7], ", ", Pos[8], ")"
200
201   ####### KindOfShape #######
202
203   Kind = geompy.KindOfShape(box)
204   print "\nKindOfShape(box 10x30x70):", Kind
205   #if Kind[0] != geompy.kind.BOX:
206   #  print "Error: returned type is", Kind[0], "while must be", geompy.kind.BOX
207
208   Kind = geompy.KindOfShape(p137)
209   print "\nKindOfShape(p137):", Kind
210   if Kind[0] != geompy.kind.VERTEX:
211     print "  Error: returned type is", Kind[0], "while must be", geompy.kind.VERTEX
212   else:
213     dx = math.fabs(Kind[1] - 10)
214     dy = math.fabs(Kind[2] - 30)
215     dz = math.fabs(Kind[3] - 70)
216     if (dx + dy + dz) > 1e-5:
217       print "  Error: coordinates are (", Kind[1], ",", Kind[2], ",", Kind[3], ") while must be (10, 20, 30)"
218
219   pass