Salome HOME
Merge branch V7_3_1_BR
[modules/smesh.git] / src / Tools / MacMesh / MacMesh / Cylinder.py
1 # Copyright (C) 2007-2014  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, or (at your option) any later version.
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
23
24
25
26 # This is an automation of the cylinder-box object, defined with the coordinates of its center, its radius, and the box's 
27 # boundary size.
28 # The pitch ratio is calculated automatically from the minimum of the box dimensions on x and y.
29 # This functions can take a groups input containing the group names of 4 sides in addition to the internal circular boundary
30 # in the following order : [South,North,West,East,Internal].
31
32 import sys, math, commands
33 CWD = commands.getoutput('pwd')
34 sys.path.append(CWD)
35
36
37 from MacObject import *
38 import Config, GenFunctions
39
40 def Cylinder (X0 , Y0 , D , DX , DY , LocalMeshing , **args) : 
41         if args.__contains__('DLocal') : DLocal = float(args['DLocal']) 
42         else : DLocal = float(min(DX,DY))
43
44         # K is the pitch ratio
45         K = float(D)/(DLocal-D)
46         print "A local pitch ratio of K =", K ," will be used.  "
47         NumCuts =  2*GenFunctions.QuarCylParam(K)
48         InternalMeshing = int(math.ceil(math.pi*D/(4*NumCuts*LocalMeshing)))
49         if InternalMeshing == 0 : InternalMeshing = 1           # This sets a minimum meshing condition in order to avoid an error. The user is notified of the value considered for the local meshing
50         print "Possible Local meshing is :", math.pi*D/(4*NumCuts*InternalMeshing), "\nThis value is returned by this function for your convenience.\n"
51         if args.__contains__('groups') :
52                 GroupNames = args['groups']
53         else : GroupNames = [None, None, None, None, None]
54         
55         if DY == DLocal :
56                 if DX == DLocal:
57                         GN1 = [None,GroupNames[1],None,GroupNames[3],GroupNames[4]]
58                         GN2 = [None,GroupNames[1],GroupNames[2],None,GroupNames[4]]
59                         GN3 = [GroupNames[0],None,GroupNames[2],None,GroupNames[4]]
60                         GN4 = [GroupNames[0],None,None,GroupNames[3],GroupNames[4]]
61                 else :
62                         GN1 = [None,GroupNames[1],None,None,GroupNames[4]]
63                         GN2 = [None,GroupNames[1],None,None,GroupNames[4]]
64                         GN3 = [GroupNames[0],None,None,None,GroupNames[4]]
65                         GN4 = [GroupNames[0],None,None,None,GroupNames[4]]
66                         
67                         GN5 = [GroupNames[0],GroupNames[1],None,GroupNames[3]]
68                         GN6 = [GroupNames[0],GroupNames[1],GroupNames[2],None]
69         else :
70                 if DX == DLocal:
71                         GN1 = [None,None,None,GroupNames[3],GroupNames[4]]
72                         GN2 = [None,None,GroupNames[2],None,GroupNames[4]]
73                         GN3 = [None,None,GroupNames[2],None,GroupNames[4]]
74                         GN4 = [None,None,None,GroupNames[3],GroupNames[4]]
75                         GN7 = [GroupNames[0],None,GroupNames[2],GroupNames[3]]
76                         GN8 = [None,GroupNames[1],GroupNames[2],GroupNames[3]]
77                 else :
78                         GN1 = [None,None,None,None,GroupNames[4]]
79                         GN2 = [None,None,None,None,GroupNames[4]]
80                         GN3 = [None,None,None,None,GroupNames[4]]
81                         GN4 = [None,None,None,None,GroupNames[4]]
82                         
83                         GN5 = [None,None,None,GroupNames[3]]
84                         GN6 = [None,None,GroupNames[2],None]
85                         
86                         GN9  = [GroupNames[0],None,None,GroupNames[3]]
87                         GN10 = [GroupNames[0],None,None,None]
88                         GN11 = [GroupNames[0],None,GroupNames[2],None]
89                         
90                         GN12 = [None,GroupNames[1],None,GroupNames[3]]
91                         GN13 = [None,GroupNames[1],None,None]
92                         GN14 = [None,GroupNames[1],GroupNames[2],None]
93                         
94         Obj = []
95
96         Obj.append(MacObject('QuartCyl',[(X0+DLocal/4.,Y0+DLocal/4.),(DLocal/2.,DLocal/2.)],[InternalMeshing,'NE',K], groups = GN1))
97         Obj.append(MacObject('QuartCyl',[(X0-DLocal/4.,Y0+DLocal/4.),(DLocal/2.,DLocal/2.)],['auto','NW',K], groups = GN2))
98         Obj.append(MacObject('QuartCyl',[(X0-DLocal/4.,Y0-DLocal/4.),(DLocal/2.,DLocal/2.)],['auto','SW',K], groups = GN3))
99         Obj.append(MacObject('QuartCyl',[(X0+DLocal/4.,Y0-DLocal/4.),(DLocal/2.,DLocal/2.)],['auto','SE',K], groups = GN4))
100
101         if DX > DLocal :
102                 dX = (DX - DLocal)/2.
103                 Obj.append(MacObject('CompBoxF',[(X0+DLocal/2.+dX/2.,Y0),(dX,DLocal)],['auto'], groups = GN5))
104                 Obj.append(MacObject('CompBoxF',[(X0-DLocal/2.-dX/2.,Y0),(dX,DLocal)],['auto'], groups = GN6))
105
106         if DY > DLocal :
107                 dY = (DY - DLocal)/2.
108                 if DX > DLocal : 
109                         Obj.append(MacObject('CompBoxF',[(X0+DLocal/2.+dX/2.,Y0-DLocal/2.-dY/2.),(dX,dY)],['auto'], groups = GN9))
110                         Obj.append(MacObject('CompBoxF',[(X0,Y0-DLocal/2.-dY/2.),(DLocal,dY)],['auto'], groups = GN10))
111                         Obj.append(MacObject('CompBoxF',[(X0-DLocal/2.-dX/2.,Y0-DLocal/2.-dY/2.),(dX,dY)],['auto'], groups = GN11))
112                         Obj.append(MacObject('CompBoxF',[(X0+DLocal/2.+dX/2.,Y0+DLocal/2.+dY/2.),(dX,dY)],['auto'], groups = GN12))
113                         Obj.append(MacObject('CompBoxF',[(X0,Y0+DLocal/2.+dY/2.),(DLocal,dY)],['auto'], groups = GN13))
114                         Obj.append(MacObject('CompBoxF',[(X0-DLocal/2.-dX/2.,Y0+DLocal/2.+dY/2.),(dX,dY)],['auto'], groups = GN14))
115                 else:
116                         Obj.append(MacObject('CompBoxF',[(X0,Y0-DLocal/2.-dY/2.),(DLocal,dY)],['auto'], groups = GN7))
117                         Obj.append(MacObject('CompBoxF',[(X0,Y0+DLocal/2.+dY/2.),(DLocal,dY)],['auto'], groups = GN8))
118                                         
119         return Obj