Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/geom.git] / src / GEOM_SWIG / GEOM_example4.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #  GEOM GEOM_SWIG : binding of C++ omplementaion with Python
23 #  File   : GEOM_example4.py
24 #  Module : GEOM
25 #import SMESH
26 #import smeshpy
27 #
28 import salome
29 from salome import sg
30 import math
31
32 import geompy
33
34 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
35 myBuilder = salome.myStudy.NewBuilder()
36 #from geompy import gg
37
38 #smeshgui = salome.ImportComponentGUI("SMESH")
39 #smeshgui.Init(salome.myStudyId);
40
41 ShapeTypeCompSolid = 1
42 ShapeTypeSolid = 2
43 ShapeTypeShell = 3
44 ShapeTypeFace = 4
45 ShapeTypeWire = 5
46 ShapeTypeEdge = 6
47 ShapeTypeVertex = 7
48
49 pi=math.pi
50
51 # ---------------------------------------------
52 xa=math.sin(pi/12)
53 ya=0
54 za=math.cos(pi/12)
55
56 xb=0
57 yb=math.sin(pi/18)
58 zb=math.cos(pi/18)
59
60 xc=math.cos(-pi/18)
61 yc=0
62 zc=math.sin(-pi/18)
63
64 rc1=150
65 hc1=300
66 rc2=150
67 rc3=150
68 rc4=300
69 # ---------------------------------------------
70 point_0 = geompy.MakeVertex(0, 0, 0)
71 point_z = geompy.MakeVertex(0, 0, 1)
72
73 point_a = geompy.MakeVertex(xa, ya, za)
74 point_b = geompy.MakeVertex(xb, yb, zb)
75 point_c = geompy.MakeVertex(xc, yc, zc)
76
77 dir_z = geompy.MakeVector(point_0,point_z)
78 dir_a = geompy.MakeVector(point_0,point_a)
79 dir_b = geompy.MakeVector(point_0,point_b)
80 dir_c = geompy.MakeVector(point_0,point_c)
81
82 cyl_1 = geompy.MakeCylinder(point_0, dir_z, rc1, hc1)
83
84 hc2=2*hc1
85 cyl_t = geompy.MakeCylinder(point_0, dir_a, rc2, hc2)
86 cyl_a = geompy.MakeTranslation(cyl_t, 1.2*rc1, 0.1*rc1, -0.5*hc1)
87
88 hc3=2*hc1
89 cyl_t = geompy.MakeCylinder(point_0, dir_b, rc3, hc3)
90 cyl_b = geompy.MakeTranslation(cyl_t, -1.2*rc1, -0.1*rc1, -0.5*hc1)
91
92 hc4=2*hc1
93 cyl_t = geompy.MakeCylinder(point_0, dir_c, rc4, hc4)
94 cyl_t = geompy.MakeRotation(cyl_t, dir_c, pi/2)
95 cyl_c = geompy.MakeTranslation(cyl_t, -hc1, 0, 0)
96 cyl_d = geompy.MakeTranslation(cyl_t, -hc1, 0, 1.3*rc4)
97
98 inter_t = geompy.MakeBoolean(cyl_c,cyl_d, 1) # common
99
100 blob_t = geompy.MakeBoolean(cyl_1, cyl_a, 2) # cut
101 blob_t = geompy.MakeBoolean(blob_t, cyl_b, 2)
102
103 blob = geompy.MakeBoolean(blob_t, inter_t, 1) # common
104
105 idblob = geompy.addToStudy(blob,"blob")
106 #idc = geompy.addToStudy(cyl_c,"cyl_c")
107 #idd = geompy.addToStudy(cyl_d,"cyl_d")