1 # Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 def TestMeasureOperations (geompy, math):
22 p0 = geompy.MakeVertex(0 , 0, 0)
23 p137 = geompy.MakeVertex(10, 30, 70)
25 box = geompy.MakeBoxTwoPnt(p0, p137)
27 p678 = geompy.MakeVertex(60, 70, 80)
28 p789 = geompy.MakeVertex(70, 80, 90)
30 cube = geompy.MakeBoxTwoPnt(p678, p789)
32 ####### PointCoordinates #######
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], ")"
38 ####### CheckShape #######
40 IsValid = geompy.CheckShape(box)
42 raise RuntimeError, "Invalid box created"
44 print "\nBox is valid"
46 ####### WhatIs #######
48 Descr = geompy.WhatIs(box)
49 print "\nBox 10x30x70 description:"
52 ####### BasicProperties #######
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]
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
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
71 ####### BoundingBox #######
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]
79 ####### Inertia #######
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]
89 ####### Tolerance #######
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]
100 ####### MakeCDG #######
102 pcdg = geompy.MakeCDG(box)
104 raise RuntimeError, "MakeCDG(box) failed"
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)"
112 ####### MinDistance #######
114 MinDist = geompy.MinDistance(box, cube)
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], ")"
121 print "\nMinimal distance between Box and Cube = ", MinDist
123 MinDistComps = geompy.MinDistanceComponents(box, cube)
124 print "\nMinimal distance between Box and Cube = ", MinDistComps[0]
125 print "Its components are (", MinDistComps[1], ", ", MinDistComps[2], ", ", MinDistComps[3], ")"
127 ####### Angle #######
129 OX = geompy.MakeVectorDXDYDZ(10, 0,0)
130 OXY = geompy.MakeVectorDXDYDZ(10,10,0)
133 Angle = geompy.GetAngle(OX, OXY)
135 print "\nAngle between OX and OXY = ", Angle
136 if math.fabs(Angle - 45.0) > 1e-05:
137 print " Error: returned angle is", Angle, "while must be 45.0"
140 OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
141 Angle = geompy.GetAngle(OX, OXY_shift)
143 print "Angle between OX and OXY_shift = ", Angle
144 if math.fabs(Angle - 45.0) > 1e-05:
145 print " Error: returned angle is", Angle, "while must be 45.0"
147 ####### Position (LCS) #######
149 Pos = geompy.GetPosition(box)
150 print "\nPosition(LCS) of box 10x30x70:"
151 print "Origin: (", Pos[0], ", ", Pos[1], ", ", Pos[2], ")"
152 print "Z axis: (", Pos[3], ", ", Pos[4], ", ", Pos[5], ")"
153 print "X axis: (", Pos[6], ", ", Pos[7], ", ", Pos[8], ")"
155 ####### KindOfShape #######
157 Kind = geompy.KindOfShape(box)
158 print "\nKindOfShape(box 10x30x70):", Kind
159 #if Kind[0] != geompy.kind.BOX:
160 # print "Error: returned type is", Kind[0], "while must be", geompy.kind.BOX
162 Kind = geompy.KindOfShape(p137)
163 print "\nKindOfShape(p137):", Kind
164 if Kind[0] != geompy.kind.VERTEX:
165 print " Error: returned type is", Kind[0], "while must be", geompy.kind.VERTEX
167 dx = math.fabs(Kind[1] - 10)
168 dy = math.fabs(Kind[2] - 30)
169 dz = math.fabs(Kind[3] - 70)
170 if (dx + dy + dz) > 1e-5:
171 print " Error: coordinates are (", Kind[1], ",", Kind[2], ",", Kind[3], ") while must be (10, 20, 30)"