Salome HOME
0020673: EDF 1240 GEOM : Option for orientation in MakeFilling
[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>Get vertex by index</h2>
75
76 \code
77 import geompy
78
79 # Create auxiliary objects
80 Vertex_1 = geompy.MakeVertex(0, 0, 0)
81 Vertex_2 = geompy.MakeVertex(10, 20, 0)
82 Vertex_3 = geompy.MakeVertex(0, 40, 0)
83 Vertex_4 = geompy.MakeVertex(-10, 60, 0)
84 Vertex_5 = geompy.MakeVertex(0, 80, 0)
85 Curve_1 = geompy.MakeInterpol([Vertex_1, Vertex_2, Vertex_3])
86 Curve_2 = geompy.MakeInterpol([Vertex_5, Vertex_4, Vertex_3])
87 Wire_1 = geompy.MakeWire([Curve_1, Curve_2])
88 Reversed_Wire = geompy.ChangeOrientationShellCopy(Wire_1)
89
90 # Get The vertexes from Reversed Wire by different functions
91 vertex_0 = geompy.GetFirstVertex(Reversed_Wire)
92 vertex_1 = geompy.GetVertexByIndex(Reversed_Wire, 1)
93 vertex_2 = geompy.GetLastVertex(Reversed_Wire)
94
95 # Publish objects in study
96 geompy.addToStudy( Wire_1, "Wire_1" )
97 geompy.addToStudy( Reversed_Wire, "Reversed_Wire" )
98 geompy.addToStudy( vertex_0, "vertex_0" )
99 geompy.addToStudy( vertex_1, "vertex_1" )
100 geompy.addToStudy( vertex_2, "vertex_2" )
101 \endcode
102
103 <br><h2>Inertia</h2>
104
105 \code
106 import geompy
107 import math
108
109 # create a box
110 box = geompy.MakeBoxDXDYDZ(100,30,100)
111 In = geompy.Inertia(box)
112 print "\nInertia matrix of box 100x30x100:"
113 print " (", In[0], ", ", In[1], ", ", In[2], ")"
114 print " (", In[3], ", ", In[4], ", ", In[5], ")"
115 print " (", In[6], ", ", In[7], ", ", In[8], ")"
116 print "Main moments of inertia of box 100x30x100:"
117 print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]
118 \endcode
119
120 <br><h2>Check Free Boundaries</h2>
121
122 \code
123 import os
124 import geompy
125 import salome
126 gg = salome.ImportComponentGUI("GEOM")
127
128 # create boxes
129 box1 = geompy.MakeBox(0,0,0,100,50,100)
130 box2 = geompy.MakeBox(100,0,0,250,50,100)
131
132 # make a compound
133 compound = geompy.MakeCompound([box1, box2])
134
135 # import from *.brep
136 ImportFromBREP = geompy.ImportBREP(os.getenv("DATA_DIR")+"/Shapes/Brep/flight_solid.brep")
137
138 # get a face
139 faces = geompy.SubShapeAllSorted(ImportFromBREP, geompy.ShapeType["FACE"])
140
141 # get the free boundary for face 32
142 Res = geompy.GetFreeBoundary(faces[32])
143 isSuccess   = Res[0]
144 ClosedWires = Res[1]
145 OpenWires   = Res[2]
146
147 if isSuccess == 1 :
148     print "Checking free boudaries is OK."
149 else :
150     print "Checking free boudaries is KO!"
151 print "len(ClosedWires) = ", len(ClosedWires)
152
153 i = 0
154 for wire in ClosedWires :
155     wire_name = "Face 32 -> Close wires : WIRE %d"%(i+1)
156     geompy.addToStudy(ClosedWires[i], wire_name)
157     if i < len(ClosedWires) :
158         i = i+ 1
159
160 print "len(OpenWires) = ", len(OpenWires)
161
162 i = 0
163 for wire in OpenWires :
164     wire_name = "Face 32 -> Open wires : WIRE %d"%(i+1)
165     geompy.addToStudy(OpenWires[i], wire_name)
166     if i < len(OpenWires) :
167         i = i+ 1
168
169 # get the free boundary for face 41
170 Res = geompy.GetFreeBoundary(faces[41])
171 isSuccess   = Res[0]
172 ClosedWires = Res[1]
173 OpenWires   = Res[2]
174
175 if isSuccess == 1 :
176     print "Checking free boudaries is OK."
177 else :
178     print "Checking free boudaries is KO!"
179 print "len(ClosedWires) = ", len(ClosedWires)
180
181 i = 0
182 for wire in ClosedWires :
183     wire_name = "Face 41 -> Close wires : WIRE %d"%(i+1)
184     geompy.addToStudy(ClosedWires[i], wire_name)
185     if i < len(ClosedWires) :
186         i = i+ 1
187
188 print "len(OpenWires) = ", len(OpenWires)
189
190 i = 0
191 for wire in OpenWires :
192     wire_name = "Face 41 -> Open wires : WIRE %d"%(i+1)
193     geompy.addToStudy(OpenWires[i], wire_name)
194     if i < len(OpenWires) :
195         i = i+ 1
196
197 # add the imported object to the study
198 id_ImportFromBREP = geompy.addToStudy(ImportFromBREP, "ImportFromBREP")
199 salome.sg.updateObjBrowser(1)
200 \endcode
201
202
203 <br><h2>Check Free Faces</h2>
204
205 \code
206 import geompy
207 import salome
208 gg = salome.ImportComponentGUI("GEOM")
209
210 # create a vertex and a vector
211 p1 = geompy.MakeVertex(35, 35, 0)
212 p2 = geompy.MakeVertex(35, 35, 50)
213 v = geompy.MakeVector(p1, p2)
214
215 # create a cylinder
216 cylinder = geompy.MakeCone(p1, v, 30, 20, 20)
217
218 # create a cone
219 cone = geompy.MakeCone(p1, v, 70, 40, 60)
220
221 # make cut
222 cut = geompy.MakeCut(cone, cylinder)
223
224 # get faces as sub-shapes
225 faces = []
226 faces = geompy.SubShapeAllSorted(cut, geompy.ShapeType["FACE"])
227 f_2 = geompy.GetSubShapeID(cut, faces[0])
228
229 # remove one face from the shape
230 cut_without_f_2 = geompy.SuppressFaces(cut, [f_2])
231
232 # suppress the specified wire
233 result = geompy.GetFreeFacesIDs(cut_without_f_2)
234 print "A number of free faces is ", len(result)
235
236 # add objects in the study
237 all_faces = geompy.SubShapeAllSorted(cut_without_f_2, geompy.ShapeType["FACE"])
238 for face in all_faces :
239     sub_shape_id = geompy.GetSubShapeID(cut_without_f_2, face)
240     if result.count(sub_shape_id) > 0 :
241         face_name = "Free face %d"%(sub_shape_id)
242         geompy.addToStudy(face, face_name)
243
244 # in this example all faces from cut_without_f_2 are free
245 id_cut_without_f_2 = geompy.addToStudy(cut_without_f_2, "Cut without f_2")
246
247 # display the results
248 gg.createAndDisplayGO(id_cut_without_f_2)
249 gg.setDisplayMode(id_cut_without_f_2,1)
250 \endcode
251
252
253
254 <br><h2>Bounding Box</h2>
255
256 \code
257 import geompy
258
259 # create a box
260 box = geompy.MakeBoxDXDYDZ(100,30,100)
261 bb = geompy.BoundingBox(box)
262 print "\nBounding Box of box 100x30x100:"
263 print " Xmin = ", bb[0], ", Xmax = ", bb[1]
264 print " Ymin = ", bb[2], ", Ymax = ", bb[3]
265 print " Zmin = ", bb[4], ", Zmax = ", bb[5]
266 \endcode
267
268 <br><h2>Minimal Distance</h2>
269
270 \code
271 import geompy
272
273 # create boxes
274 box1 = geompy.MakeBoxDXDYDZ(100,30,100)
275 box2 = geompy.MakeBox(105,0,0,200,30,100)
276 min_dist = geompy.MinDistance(box1,box2)
277 print "\nMinimal distance between box1 and box2 = ", min_dist
278 \endcode
279
280 <br><h2>Tolerance</h2>
281
282 \code
283 import geompy
284
285 # create a box
286 box = geompy.MakeBoxDXDYDZ(100,30,100)
287 Toler = geompy.Tolerance(box)
288 print "\nBox 100x30x100 tolerance:"
289 print " Face min. tolerance: ", Toler[0]
290 print " Face max. tolerance: ", Toler[1]
291 print " Edge min. tolerance: ", Toler[2]
292 print " Edge max. tolerance: ", Toler[3]
293 print " Vertex min. tolerance: ", Toler[4]
294 print " Vertex max. tolerance: ", Toler[5]
295 \endcode
296
297 <br><h2>Angle</h2>
298
299 \code
300 import salome
301 salome.salome_init()
302
303 import math
304 import geompy
305 geompy.init_geom(salome.myStudy)
306
307 OX  = geompy.MakeVectorDXDYDZ(10, 0,0)
308 OXY = geompy.MakeVectorDXDYDZ(10,10,0)
309
310 # in one plane
311 Angle = geompy.GetAngle(OX, OXY)
312
313 print "\nAngle between OX and OXY = ", Angle
314 if math.fabs(Angle - 45.0) > 1e-05:
315     print "  Error: returned angle is", Angle, "while must be 45.0"
316     pass
317
318 Angle = geompy.GetAngleRadians(OX, OXY)
319
320 print "\nAngle between OX and OXY in radians = ", Angle
321 if math.fabs(Angle - math.pi/4) > 1e-05:
322     print "  Error: returned angle is", Angle, "while must be pi/4"
323     pass
324
325 # not in one plane
326 OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
327 Angle = geompy.GetAngle(OX, OXY_shift)
328
329 print "Angle between OX and OXY_shift = ", Angle
330 if math.fabs(Angle - 45.0) > 1e-05:
331     print "  Error: returned angle is", Angle, "while must be 45.0"
332     pass
333
334 # not linear
335 pnt1 = geompy.MakeVertex(0, 0, 0)
336 pnt2 = geompy.MakeVertex(10, 0, 0)
337 pnt3 = geompy.MakeVertex(20, 10, 0)
338 arc  = geompy.MakeArc(pnt1, pnt2, pnt3)
339 Angle = geompy.GetAngle(OX, arc)
340
341 if (math.fabs(Angle + 1.0) > 1e-6 or geompy.MeasuOp.IsDone()):
342     print "Error. Angle must not be computed on curvilinear edges"
343     pass
344
345 \endcode
346
347
348 <br><h2>What Is</h2>
349
350 \code
351 import geompy
352
353 # create a box
354 box = geompy.MakeBoxDXDYDZ(100,30,100)
355 Descr = geompy.WhatIs(box)
356 print "\nBox 100x30x100 description:"
357 print Descr
358 \endcode
359
360 <br><h2>Check Shape</h2>
361
362 \code
363 import geompy
364
365 # create a box
366 box = geompy.MakeBoxDXDYDZ(100,30,100)
367 IsValid = geompy.CheckShape(box)
368 if IsValid == 0:
369     raise RuntimeError, "Invalid box created"
370 else:
371     print "\nBox is valid"
372 \endcode
373
374 <br><h2>Check Compound of Blocks</h2>
375
376 \code
377 import geompy
378 import salome
379 gg = salome.ImportComponentGUI("GEOM")
380
381 # create boxes
382 box1 = geompy.MakeBox(0,0,0,100,50,100)
383 box2 = geompy.MakeBox(100,0,0,250,50,100)
384
385 # make a compound
386 compound = geompy.MakeCompound([box1, box2])
387
388 # glue the faces of the compound
389 tolerance = 1e-5
390 glue = geompy.MakeGlueFaces(compound, tolerance)
391 IsValid = geompy.CheckCompoundOfBlocks(glue)
392 if IsValid == 0:
393     raise RuntimeError, "Invalid compound created"
394 else:
395     print "\nCompound is valid"
396 \endcode
397
398 */