Salome HOME
Fix compilation error (conflict of OK name between OCCT Plate_Plate.hxx and GEOM...
[modules/geom.git] / doc / salome / examples / topological_geom_objs_ex02.py
1 # Creation of a Wire
2
3 import salome
4 salome.salome_init_without_session()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New()
8 gg = salome.ImportComponentGUI("GEOM")
9
10 # create vertices
11 px   = geompy.MakeVertex(100., 0.  , 0.  )
12 py   = geompy.MakeVertex(0.  , 100., 0.  )
13 pz   = geompy.MakeVertex(0.  , 0.  , 100.)
14
15 # create a vector from two points
16 vxy = geompy.MakeVector(px, py)
17
18 # create an arc from three points
19 arc = geompy.MakeArc(py, pz, px)
20
21 # create a wire
22 wire = geompy.MakeWire([vxy, arc])
23
24 # add an object in the study
25 id_wire = geompy.addToStudy(wire,"Wire")
26
27 # display the wire
28 gg.createAndDisplayGO(id_wire) 
29
30 # Create a wire from edges that are not connected to each other.
31 # Given tolerance should cover the gaps to build connected wire.
32 # Three different modes to do that are possible.
33 gap = 1
34 tolerance = gap
35 px_gap  = geompy.MakeVertex(100. + gap, 0.  , 0.  )
36 py_gap  = geompy.MakeVertex(0.  , 100. + gap, 0.  )
37 vxy_gap = geompy.MakeVector(px_gap, py_gap)
38
39 # 1. Join edges by fixing tolerance
40 wire_ft = geompy.MakeWire([vxy_gap, arc], tolerance, "wire_fixed_tolerance")
41 # final wire tolerance will be near the half of the gap (0.5)
42 print(geompy.Tolerance(wire_ft)[5])
43 assert(abs(geompy.Tolerance(wire_ft)[5] - 0.5) < 1e-04)
44
45 # 2. Join edges by changing their underlying curves (but keeping curve types)
46 #    This functionality is available in TUI only.
47 wire_cc = geompy.MakeWireConstCurveType([vxy_gap, arc], tolerance, "wire_const_curve_type")
48 # final wire tolerance will stay small
49 print(geompy.Tolerance(wire_cc)[5])
50 assert(geompy.Tolerance(wire_cc)[5] < 1e-04)
51
52 # 3. Join edges by changing their underlying curves (approximating with b-splines)
53 #    This functionality is available in TUI only.
54 wire_ap = geompy.MakeWireWithMode([vxy_gap, arc], tolerance, GEOM.WBM_Approximation, "wire_approximated_curves")
55 # final wire tolerance will stay small
56 print(geompy.Tolerance(wire_ap)[5])
57 assert(geompy.Tolerance(wire_ap)[5] < 1e-04)