1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 def TestMeasureOperations (geompy, math):
26 p0 = geompy.MakeVertex(0 , 0, 0)
27 p137 = geompy.MakeVertex(10, 30, 70)
29 box = geompy.MakeBoxTwoPnt(p0, p137)
31 p678 = geompy.MakeVertex(60, 70, 80)
32 p789 = geompy.MakeVertex(70, 80, 90)
34 cube = geompy.MakeBoxTwoPnt(p678, p789)
36 ####### PointCoordinates #######
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], ")"
42 ####### CheckShape #######
44 (IsValid, err) = geompy.CheckShape(box, 0, 2)
46 geompy.PrintShapeError(box, err)
47 raise RuntimeError, "Invalid box created"
49 print "\nBox is valid"
51 ####### Detect Self-intersections #######
53 [Face_1,Face_2] = geompy.SubShapes(box, [33, 23])
54 Translation_1 = geompy.MakeTranslation(Face_1, 5, -15, -40)
55 Compound_1 = geompy.MakeCompound([Face_2, Translation_1])
56 if geompy.CheckSelfIntersections(Compound_1) == True:
57 raise RuntimeError, "Existing self-intersection is not detected"
59 ####### Detect Fast intersection #######
61 cylinder = geompy.MakeCylinderRH(100, 300)
62 if geompy.FastIntersect(box, cylinder) == False:
63 raise RuntimeError, "Existing intersection is not detected"
65 ####### WhatIs #######
67 Descr = geompy.WhatIs(box)
68 print "\nBox 10x30x70 description:"
71 ####### NbShapes #######
73 NbSolids = geompy.NbShapes(box, geompy.ShapeType["SOLID"])
74 print "\nBox 10x30x70 quantity of solids:", NbSolids
76 ####### ShapeInfo #######
78 BoxInfo = geompy.ShapeInfo(box)
79 print "\nBox 10x30x70 shapes:"
82 ####### BasicProperties #######
84 Props = geompy.BasicProperties(box)
85 print "\nBox 10x30x70 Basic Properties:"
86 print " Wires length: ", Props[0]
87 print " Surface area: ", Props[1]
88 print " Volume : ", Props[2]
90 dl = math.sqrt((Props[0] - 880)*(Props[0] - 880))
91 da = math.sqrt((Props[1] - 6200)*(Props[1] - 6200))
92 dv = math.sqrt((Props[2] - 21000)*(Props[2] - 21000))
93 #print "|Props[0] - 880| = ", dl
95 if dl > 1e-7 or da > 1e-7 or dv > 1e-7:
96 print "While must be:"
97 print " Wires length: ", 880
98 print " Surface area: ", 6200
99 print " Volume : ", 21000
101 ####### BoundingBox #######
103 BB = geompy.BoundingBox(box)
104 print "\nBounding Box of box 10x30x70:"
105 print " Xmin = ", BB[0], ", Xmax = ", BB[1]
106 print " Ymin = ", BB[2], ", Ymax = ", BB[3]
107 print " Zmin = ", BB[4], ", Zmax = ", BB[5]
108 BB = geompy.MakeBoundingBox(box)
109 geompy.addToStudy(BB, "BoundingBox")
111 ####### Inertia #######
113 In = geompy.Inertia(box)
114 print "\nInertia matrix of box 10x30x70:"
115 print " (", In[0], ", ", In[1], ", ", In[2], ")"
116 print " (", In[3], ", ", In[4], ", ", In[5], ")"
117 print " (", In[6], ", ", In[7], ", ", In[8], ")"
118 print "Main moments of inertia of box 10x30x70:"
119 print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]
121 ####### Tolerance #######
123 Toler = geompy.Tolerance(box)
124 print "\nBox 10x30x70 tolerance:"
125 print " Face min. tolerance: ", Toler[0]
126 print " Face max. tolerance: ", Toler[1]
127 print " Edge min. tolerance: ", Toler[2]
128 print " Edge max. tolerance: ", Toler[3]
129 print " Vertex min. tolerance: ", Toler[4]
130 print " Vertex max. tolerance: ", Toler[5]
132 ####### MakeCDG #######
134 pcdg = geompy.MakeCDG(box)
136 raise RuntimeError, "MakeCDG(box) failed"
138 print "\nCentre of gravity of box has been successfully obtained:"
139 Coords = geompy.PointCoordinates(pcdg)
140 print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
141 if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
142 print "But must be (5, 15, 35)"
144 ####### GetNormal #######
146 faces = geompy.SubShapeAllSortedCentres(box, geompy.ShapeType["FACE"])
148 vnorm = geompy.GetNormal(face0)
150 raise RuntimeError, "GetNormal(face0) failed"
152 geompy.addToStudy(face0, "Face0")
153 geompy.addToStudy(vnorm, "Normale to Face0")
154 print "\nNormale of face has been successfully obtained:"
155 #Coords = geompy.PointCoordinates(pcdg)
156 #print "(", Coords[0], ", ", Coords[1], ", ", Coords[2], ")"
157 #if Coords[0] != 5 or Coords[1] != 15 or Coords[2] != 35:
158 # print "But must be (5, 15, 35)"
160 ####### MinDistance #######
162 MinDist = geompy.MinDistance(box, cube)
164 #print "\nMinimal distance between Box and Cube = ", MinDist[0]
165 #print "It is reached at points:"
166 #print " On Box (", MinDist[1], ", ", MinDist[2], ", ", MinDist[3], ")"
167 #print " On Cube (", MinDist[4], ", ", MinDist[5], ", ", MinDist[6], ")"
169 print "\nMinimal distance between Box and Cube = ", MinDist
171 MinDistComps = geompy.MinDistanceComponents(box, cube)
172 print "\nMinimal distance between Box and Cube = ", MinDistComps[0]
173 print "Its components are (", MinDistComps[1], ", ", MinDistComps[2], ", ", MinDistComps[3], ")"
175 # Get all closest points
176 [nbSols, listCoords] = geompy.ClosestPoints(box, cube)
177 for i in range(nbSols):
178 v1 = geompy.MakeVertex(listCoords[i*6 + 0], listCoords[i*6 + 1], listCoords[i*6 + 2])
179 v2 = geompy.MakeVertex(listCoords[i*6 + 3], listCoords[i*6 + 4], listCoords[i*6 + 5])
181 geompy.addToStudy(v1, 'MinDist_%d_on_Box'%(i+1))
182 geompy.addToStudy(v2, 'MinDist_%d_on_Cube'%(i+1))
185 ####### Angle #######
187 OX = geompy.MakeVectorDXDYDZ(10, 0,0)
188 OXY = geompy.MakeVectorDXDYDZ(10,10,0)
191 Angle = geompy.GetAngle(OX, OXY)
193 print "\nAngle between OX and OXY = ", Angle
194 if math.fabs(Angle - 45.0) > 1e-05:
195 print " Error: returned angle is", Angle, "while must be 45.0"
197 Angle = geompy.GetAngleRadians(OX, OXY)
199 print "\nAngle between OX and OXY in radians = ", Angle
200 if math.fabs(Angle - math.pi/4) > 1e-05:
201 print " Error: returned angle is", Angle, "while must be pi/4"
205 OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
206 Angle = geompy.GetAngle(OX, OXY_shift)
208 print "Angle between OX and OXY_shift = ", Angle
209 if math.fabs(Angle - 45.0) > 1e-05:
210 print " Error: returned angle is", Angle, "while must be 45.0"
212 ####### Position (LCS) #######
214 Pos = geompy.GetPosition(box)
215 print "\nPosition(LCS) of box 10x30x70:"
216 print "Origin: (", Pos[0], ", ", Pos[1], ", ", Pos[2], ")"
217 print "Z axis: (", Pos[3], ", ", Pos[4], ", ", Pos[5], ")"
218 print "X axis: (", Pos[6], ", ", Pos[7], ", ", Pos[8], ")"
220 ####### KindOfShape #######
222 Kind = geompy.KindOfShape(box)
223 print "\nKindOfShape(box 10x30x70):", Kind
224 #if Kind[0] != geompy.kind.BOX:
225 # print "Error: returned type is", Kind[0], "while must be", geompy.kind.BOX
227 Kind = geompy.KindOfShape(p137)
228 print "\nKindOfShape(p137):", Kind
229 if Kind[0] != geompy.kind.VERTEX:
230 print " Error: returned type is", Kind[0], "while must be", geompy.kind.VERTEX
232 dx = math.fabs(Kind[1] - 10)
233 dy = math.fabs(Kind[2] - 30)
234 dz = math.fabs(Kind[3] - 70)
235 if (dx + dy + dz) > 1e-5:
236 print " Error: coordinates are (", Kind[1], ",", Kind[2], ",", Kind[3], ") while must be (10, 20, 30)"