Salome HOME
9ab17ddccefc95a8457e6ca6054117f0ec7ba9b2
[modules/geom.git] / src / GEOM_SWIG / GEOM_example4.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
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.
11 #
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.
16 #
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
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 #  GEOM GEOM_SWIG : binding of C++ implementation with Python
25 #  File   : GEOM_example4.py
26 #  Module : GEOM
27 #
28 import salome
29 salome.salome_init()
30 import GEOM
31 from salome.geom import geomBuilder
32 geompy = geomBuilder.New()
33
34 import math
35
36 pi=math.pi
37
38 # ---------------------------------------------
39 xa=math.sin(pi/12)
40 ya=0
41 za=math.cos(pi/12)
42
43 xb=0
44 yb=math.sin(pi/18)
45 zb=math.cos(pi/18)
46
47 xc=math.cos(-pi/18)
48 yc=0
49 zc=math.sin(-pi/18)
50
51 rc1=150
52 hc1=300
53 rc2=150
54 rc3=150
55 rc4=300
56 # ---------------------------------------------
57 point_0 = geompy.MakeVertex(0, 0, 0)
58 point_z = geompy.MakeVertex(0, 0, 1)
59
60 point_a = geompy.MakeVertex(xa, ya, za)
61 point_b = geompy.MakeVertex(xb, yb, zb)
62 point_c = geompy.MakeVertex(xc, yc, zc)
63
64 dir_z = geompy.MakeVector(point_0,point_z)
65 dir_a = geompy.MakeVector(point_0,point_a)
66 dir_b = geompy.MakeVector(point_0,point_b)
67 dir_c = geompy.MakeVector(point_0,point_c)
68
69 cyl_1 = geompy.MakeCylinder(point_0, dir_z, rc1, hc1)
70
71 hc2=2*hc1
72 cyl_t = geompy.MakeCylinder(point_0, dir_a, rc2, hc2)
73 cyl_a = geompy.MakeTranslation(cyl_t, 1.2*rc1, 0.1*rc1, -0.5*hc1)
74
75 hc3=2*hc1
76 cyl_t = geompy.MakeCylinder(point_0, dir_b, rc3, hc3)
77 cyl_b = geompy.MakeTranslation(cyl_t, -1.2*rc1, -0.1*rc1, -0.5*hc1)
78
79 hc4=2*hc1
80 cyl_t = geompy.MakeCylinder(point_0, dir_c, rc4, hc4)
81 cyl_t = geompy.MakeRotation(cyl_t, dir_c, pi/2)
82 cyl_c = geompy.MakeTranslation(cyl_t, -hc1, 0, 0)
83 cyl_d = geompy.MakeTranslation(cyl_t, -hc1, 0, 1.3*rc4)
84
85 inter_t = geompy.MakeBoolean(cyl_c,cyl_d, 1) # common
86
87 blob_t = geompy.MakeBoolean(cyl_1, cyl_a, 2) # cut
88 blob_t = geompy.MakeBoolean(blob_t, cyl_b, 2)
89
90 blob = geompy.MakeBoolean(blob_t, inter_t, 1) # common
91
92 idblob = geompy.addToStudy(blob,"blob")
93 #idc = geompy.addToStudy(cyl_c,"cyl_c")
94 #idd = geompy.addToStudy(cyl_d,"cyl_d")