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 ####### GetNormal #######
114 faces = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])
116 vnorm = geompy.GetNormal(face0)
118 raise RuntimeError, "GetNormal(face0) failed"
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)"
128 ####### MinDistance #######
130 MinDist = geompy.MinDistance(box, cube)
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], ")"
137 print "\nMinimal distance between Box and Cube = ", MinDist
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], ")"
143 ####### Angle #######
145 OX = geompy.MakeVectorDXDYDZ(10, 0,0)
146 OXY = geompy.MakeVectorDXDYDZ(10,10,0)
149 Angle = geompy.GetAngle(OX, OXY)
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"
156 OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
157 Angle = geompy.GetAngle(OX, OXY_shift)
159 print "Angle between OX and OXY_shift = ", Angle
160 if math.fabs(Angle - 45.0) > 1e-05:
161 print " Error: returned angle is", Angle, "while must be 45.0"
163 ####### Position (LCS) #######
165 Pos = geompy.GetPosition(box)
166 print "\nPosition(LCS) of box 10x30x70:"
167 print "Origin: (", Pos[0], ", ", Pos[1], ", ", Pos[2], ")"
168 print "Z axis: (", Pos[3], ", ", Pos[4], ", ", Pos[5], ")"
169 print "X axis: (", Pos[6], ", ", Pos[7], ", ", Pos[8], ")"
171 ####### KindOfShape #######
173 Kind = geompy.KindOfShape(box)
174 print "\nKindOfShape(box 10x30x70):", Kind
175 #if Kind[0] != geompy.kind.BOX:
176 # print "Error: returned type is", Kind[0], "while must be", geompy.kind.BOX
178 Kind = geompy.KindOfShape(p137)
179 print "\nKindOfShape(p137):", Kind
180 if Kind[0] != geompy.kind.VERTEX:
181 print " Error: returned type is", Kind[0], "while must be", geompy.kind.VERTEX
183 dx = math.fabs(Kind[1] - 10)
184 dy = math.fabs(Kind[2] - 30)
185 dz = math.fabs(Kind[3] - 70)
186 if (dx + dy + dz) > 1e-5:
187 print " Error: coordinates are (", Kind[1], ",", Kind[2], ",", Kind[3], ") while must be (10, 20, 30)"