Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/geom.git] / doc / salome / gui / GEOM / input / tui_measurement_tools.doc
1 /*!
2
3 \page tui_measurement_tools_page Measurement Tools
4
5 <br><h2>Point Coordinates</h2>
6
7 \code
8 import math
9 import geompy
10
11 # create a point
12 point = geompy.MakeVertex(15., 23., 80.)
13
14 # get the coordinates of the point and check its values
15 coords = geompy.PointCoordinates(point)
16
17 # check the obtained coordinate values
18 tolerance = 1.e-07
19 def IsEqual(val1, val2): return (math.fabs(val1 - val2) < tolerance)
20
21 if IsEqual(coords[0], 15.) and IsEqual(coords[1], 23.) and IsEqual(coords[2], 80.):
22     print "All values are OK."
23 else :
24     print "Coordinates of point must be (15, 23, 80), but returned (",
25     print coords[0], ", ", coords[1], ", ", coords[2], ")"
26     pass
27 \endcode
28
29 <br><h2>Basic Properties</h2>
30
31 \code
32 import geompy
33 import math
34
35 # create a box
36 box = geompy.MakeBoxDXDYDZ(100,30,100)
37 props = geompy.BasicProperties(box)
38 print "\nBox 100x30x100 Basic Properties:"
39 print " Wires length: ", props[0]
40 print " Surface area: ", props[1]
41 print " Volume      : ", props[2]
42 length = math.sqrt((props[0] - 1840)*(props[0] - 1840))
43 area = math.sqrt((props[1] - 32000)*(props[1] - 32000))
44 volume = math.sqrt((props[2] - 300000)*(props[2] - 300000))
45 if length > 1e-7 or area > 1e-7 or volume > 1e-7:
46     print "While must be:"
47     print " Wires length: ", 1840
48     print " Surface area: ", 32000
49     print " Volume      : ", 300000.
50 \endcode
51
52 <br><h2>Center of masses</h2>
53
54 \code
55 import geompy
56 import math
57
58 # create a box
59 box = geompy.MakeBoxDXDYDZ(100,30,100)
60 cm = geompy.MakeCDG(box)
61 if cm is None:
62     raise RuntimeError, "MakeCDG(box) failed"
63 else:
64     print "\nCentre of gravity of box has been successfully obtained:"
65     coords = geompy.PointCoordinates(cm)
66     print "(", coords[0], ", ", coords[1], ", ", coords[2], ")"
67     dx = math.sqrt((coords[0] - 50)*(coords[0] - 50))
68     dy = math.sqrt((coords[1] - 15)*(coords[1] - 15))
69     dz = math.sqrt((coords[2] - 50)*(coords[2] - 50))
70     if dx > 1e-7 or dy > 1e-7 or dz > 1e-7:
71         print "But must be (50, 15, 50)"
72 \endcode
73
74 <br><h2>Inertia</h2>
75
76 \code
77 import geompy
78 import math
79
80 # create a box
81 box = geompy.MakeBoxDXDYDZ(100,30,100)
82 In = geompy.Inertia(box)
83 print "\nInertia matrix of box 100x30x100:"
84 print " (", In[0], ", ", In[1], ", ", In[2], ")"
85 print " (", In[3], ", ", In[4], ", ", In[5], ")"
86 print " (", In[6], ", ", In[7], ", ", In[8], ")"
87 print "Main moments of inertia of box 100x30x100:"
88 print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]
89 \endcode
90
91 <br><h2>Check Free Boundaries</h2>
92
93 \code
94 import os
95 import geompy
96 import salome
97 gg = salome.ImportComponentGUI("GEOM")
98
99 # create boxes
100 box1 = geompy.MakeBox(0,0,0,100,50,100)
101 box2 = geompy.MakeBox(100,0,0,250,50,100)
102
103 # make a compound
104 compound = geompy.MakeCompound([box1, box2])
105
106 # import from *.brep
107 ImportFromBREP = geompy.ImportBREP(os.getenv("DATA_DIR")+"/Shapes/Brep/flight_solid.brep")
108
109 # get a face
110 faces = geompy.SubShapeAllSorted(ImportFromBREP, geompy.ShapeType["FACE"])
111
112 # get the free boundary for face 32
113 Res = geompy.GetFreeBoundary(faces[32])
114 isSuccess   = Res[0]
115 ClosedWires = Res[1]
116 OpenWires   = Res[2]
117
118 if isSuccess == 1 :
119     print "Checking free boudaries is OK."
120 else :
121     print "Checking free boudaries is KO!"
122 print "len(ClosedWires) = ", len(ClosedWires)
123
124 i = 0
125 for wire in ClosedWires :
126     wire_name = "Face 32 -> Close wires : WIRE %d"%(i+1)
127     geompy.addToStudy(ClosedWires[i], wire_name)
128     if i < len(ClosedWires) :
129         i = i+ 1
130
131 print "len(OpenWires) = ", len(OpenWires)
132
133 i = 0
134 for wire in OpenWires :
135     wire_name = "Face 32 -> Open wires : WIRE %d"%(i+1)
136     geompy.addToStudy(OpenWires[i], wire_name)
137     if i < len(OpenWires) :
138         i = i+ 1
139
140 # get the free boundary for face 41
141 Res = geompy.GetFreeBoundary(faces[41])
142 isSuccess   = Res[0]
143 ClosedWires = Res[1]
144 OpenWires   = Res[2]
145
146 if isSuccess == 1 :
147     print "Checking free boudaries is OK."
148 else :
149     print "Checking free boudaries is KO!"
150 print "len(ClosedWires) = ", len(ClosedWires)
151
152 i = 0
153 for wire in ClosedWires :
154     wire_name = "Face 41 -> Close wires : WIRE %d"%(i+1)
155     geompy.addToStudy(ClosedWires[i], wire_name)
156     if i < len(ClosedWires) :
157         i = i+ 1
158
159 print "len(OpenWires) = ", len(OpenWires)
160
161 i = 0
162 for wire in OpenWires :
163     wire_name = "Face 41 -> Open wires : WIRE %d"%(i+1)
164     geompy.addToStudy(OpenWires[i], wire_name)
165     if i < len(OpenWires) :
166         i = i+ 1
167
168 # add the imported object to the study
169 id_ImportFromBREP = geompy.addToStudy(ImportFromBREP, "ImportFromBREP")
170 salome.sg.updateObjBrowser(1)
171 \endcode
172
173
174 <br><h2>Check Free Faces</h2>
175
176 \code
177 import geompy
178 import salome
179 gg = salome.ImportComponentGUI("GEOM")
180
181 # create a vertex and a vector
182 p1 = geompy.MakeVertex(35, 35, 0)
183 p2 = geompy.MakeVertex(35, 35, 50)
184 v = geompy.MakeVector(p1, p2)
185
186 # create a cylinder
187 cylinder = geompy.MakeCone(p1, v, 30, 20, 20)
188
189 # create a cone
190 cone = geompy.MakeCone(p1, v, 70, 40, 60)
191
192 # make cut
193 cut = geompy.MakeCut(cone, cylinder)
194
195 # get faces as sub-shapes
196 faces = []
197 faces = geompy.SubShapeAllSorted(cut, geompy.ShapeType["FACE"])
198 f_2 = geompy.GetSubShapeID(cut, faces[0])
199
200 # remove one face from the shape
201 cut_without_f_2 = geompy.SuppressFaces(cut, [f_2])
202
203 # suppress the specified wire
204 result = geompy.GetFreeFacesIDs(cut_without_f_2)
205 print "A number of free faces is ", len(result)
206
207 # add objects in the study
208 all_faces = geompy.SubShapeAllSorted(cut_without_f_2, geompy.ShapeType["FACE"])
209 for face in all_faces :
210     sub_shape_id = geompy.GetSubShapeID(cut_without_f_2, face)
211     if result.count(sub_shape_id) > 0 :
212         face_name = "Free face %d"%(sub_shape_id)
213         geompy.addToStudy(face, face_name)
214
215 # in this example all faces from cut_without_f_2 are free
216 id_cut_without_f_2 = geompy.addToStudy(cut_without_f_2, "Cut without f_2")
217
218 # display the results
219 gg.createAndDisplayGO(id_cut_without_f_2)
220 gg.setDisplayMode(id_cut_without_f_2,1)
221 \endcode
222
223
224
225 <br><h2>Bounding Box</h2>
226
227 \code
228 import geompy
229
230 # create a box
231 box = geompy.MakeBoxDXDYDZ(100,30,100)
232 bb = geompy.BoundingBox(box)
233 print "\nBounding Box of box 100x30x100:"
234 print " Xmin = ", bb[0], ", Xmax = ", bb[1]
235 print " Ymin = ", bb[2], ", Ymax = ", bb[3]
236 print " Zmin = ", bb[4], ", Zmax = ", bb[5]
237 \endcode
238
239 <br><h2>Minimal Distance</h2>
240
241 \code
242 import geompy
243
244 # create boxes
245 box1 = geompy.MakeBoxDXDYDZ(100,30,100)
246 box2 = geompy.MakeBox(105,0,0,200,30,100)
247 min_dist = geompy.MinDistance(box1,box2)
248 print "\nMinimal distance between box1 and box2 = ", min_dist
249 \endcode
250
251 <br><h2>Tolerance</h2>
252
253 \code
254 import geompy
255
256 # create a box
257 box = geompy.MakeBoxDXDYDZ(100,30,100)
258 Toler = geompy.Tolerance(box)
259 print "\nBox 100x30x100 tolerance:"
260 print " Face min. tolerance: ", Toler[0]
261 print " Face max. tolerance: ", Toler[1]
262 print " Edge min. tolerance: ", Toler[2]
263 print " Edge max. tolerance: ", Toler[3]
264 print " Vertex min. tolerance: ", Toler[4]
265 print " Vertex max. tolerance: ", Toler[5]
266 \endcode
267
268 <br><h2>Angle</h2>
269
270 \code
271 import salome
272 salome.salome_init()
273
274 import math
275 import geompy
276 geompy.init_geom(salome.myStudy)
277
278 OX  = geompy.MakeVectorDXDYDZ(10, 0,0)
279 OXY = geompy.MakeVectorDXDYDZ(10,10,0)
280
281 # in one plane
282 Angle = geompy.GetAngle(OX, OXY)
283
284 print "\nAngle between OX and OXY = ", Angle
285 if math.fabs(Angle - 45.0) > 1e-05:
286     print "  Error: returned angle is", Angle, "while must be 45.0"
287     pass
288
289 Angle = geompy.GetAngleRadians(OX, OXY)
290
291 print "\nAngle between OX and OXY in radians = ", Angle
292 if math.fabs(Angle - math.pi/4) > 1e-05:
293     print "  Error: returned angle is", Angle, "while must be pi/4"
294     pass
295
296 # not in one plane
297 OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
298 Angle = geompy.GetAngle(OX, OXY_shift)
299
300 print "Angle between OX and OXY_shift = ", Angle
301 if math.fabs(Angle - 45.0) > 1e-05:
302     print "  Error: returned angle is", Angle, "while must be 45.0"
303     pass
304
305 # not linear
306 pnt1 = geompy.MakeVertex(0, 0, 0)
307 pnt2 = geompy.MakeVertex(10, 0, 0)
308 pnt3 = geompy.MakeVertex(20, 10, 0)
309 arc  = geompy.MakeArc(pnt1, pnt2, pnt3)
310 Angle = geompy.GetAngle(OX, arc)
311
312 if (math.fabs(Angle + 1.0) > 1e-6 or geompy.MeasuOp.IsDone()):
313     print "Error. Angle must not be computed on curvilinear edges"
314     pass
315
316 \endcode
317
318
319 <br><h2>What Is</h2>
320
321 \code
322 import geompy
323
324 # create a box
325 box = geompy.MakeBoxDXDYDZ(100,30,100)
326 Descr = geompy.WhatIs(box)
327 print "\nBox 100x30x100 description:"
328 print Descr
329 \endcode
330
331 <br><h2>Check Shape</h2>
332
333 \code
334 import geompy
335
336 # create a box
337 box = geompy.MakeBoxDXDYDZ(100,30,100)
338 IsValid = geompy.CheckShape(box)
339 if IsValid == 0:
340     raise RuntimeError, "Invalid box created"
341 else:
342     print "\nBox is valid"
343 \endcode
344
345 <br><h2>Check Compound of Blocks</h2>
346
347 \code
348 import geompy
349 import salome
350 gg = salome.ImportComponentGUI("GEOM")
351
352 # create boxes
353 box1 = geompy.MakeBox(0,0,0,100,50,100)
354 box2 = geompy.MakeBox(100,0,0,250,50,100)
355
356 # make a compound
357 compound = geompy.MakeCompound([box1, box2])
358
359 # glue the faces of the compound
360 tolerance = 1e-5
361 glue = geompy.MakeGlueFaces(compound, tolerance)
362 IsValid = geompy.CheckCompoundOfBlocks(glue)
363 if IsValid == 0:
364     raise RuntimeError, "Invalid compound created"
365 else:
366     print "\nCompound is valid"
367 \endcode
368
369 */