Salome HOME
Merge branch V7_3_1_BR
[modules/smesh.git] / src / Tools / MacMesh / MacMesh / CentralUnrefine.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 # This object allows unrefining from a central point (actually, a line) to the exterior
26 # X0 and Y0 are the center points of the origin point and not those of the center of the generated block
27
28
29
30 import sys, math, commands
31 CWD = commands.getoutput('pwd')
32 sys.path.append(CWD)
33
34 from MacObject import *
35 import Config, GenFunctions
36
37 def CentralUnrefine (X0 , Y0 , DX , DY , Orientation, **args ) : 
38
39         DirPar =     {'SN' : lambda : ['NW', 'NE', 'EW', 'NW', 'SN', 'SN', 'NE', 'WE'],
40                       'NS' : lambda : ['SE', 'SW', 'WE', 'SE', 'NS', 'NS', 'SW', 'EW'],
41                       'EW' : lambda : ['NW', 'SW', 'SN', 'NW', 'EW', 'EW', 'SW', 'NS'],
42                       'WE' : lambda : ['SE', 'NE', 'NS', 'SE', 'WE', 'WE', 'NE', 'SN'], }[Orientation]()
43
44         CoefVer =   {'SN' : lambda :  1.,
45                      'NS' : lambda : -1.,
46                      'EW' : lambda :  0.,
47                      'WE' : lambda :  0., }[Orientation]()
48
49         CoefHor =   {'SN' : lambda :  0.,
50                      'NS' : lambda :  0.,
51                      'EW' : lambda : -1.,
52                      'WE' : lambda :  1., }[Orientation]()
53
54
55         MacObject('CompBoxF',[(X0+CoefHor*DX/2,Y0+CoefVer*DY/2),(DX,DY)],['auto'],publish=0)
56         ToLook1 = {'SN' : lambda : 2,
57                    'NS' : lambda : 3,
58                    'EW' : lambda : 1,
59                    'WE' : lambda : 0, }[Orientation]()
60
61         ToLook2 = {'SN' : lambda : 0,
62                    'NS' : lambda : 0,
63                    'EW' : lambda : 2,
64                    'WE' : lambda : 2, }[Orientation]()
65                    
66         ToLook3 = {'SN' : lambda : [0,1,2,3],
67                    'NS' : lambda : [1,0,3,2],
68                    'EW' : lambda : [3,2,1,0],
69                    'WE' : lambda : [2,3,0,1], }[Orientation]() 
70                                      
71         if args.__contains__('groups') :
72                 GroupNames = args['groups']
73         else : GroupNames = [None, None, None, None, None, None]
74                 
75         ExistingSegments = Config.ListObj[-1].DirectionalMeshParams[ToLook1]
76         ObjIDs = Config.Connections[-1][ToLook1]
77         RemoveLastObj()
78         
79         ExtensionSegments = math.ceil(ExistingSegments/12.)*12.
80         Dmin = 1.E50
81         Dmax = -1.E50
82         for ObjID in ObjIDs : 
83                 Boundaries = Config.ListObj[ObjID].Boundaries()
84                 if Boundaries[ToLook2] < Dmin : Dmin = Boundaries[ToLook2]
85                 if Boundaries[ToLook2+1] > Dmax : Dmax = Boundaries[ToLook2+1]
86         dx = 0                    
87         if ExtensionSegments > ExistingSegments :
88                 dn = (ExtensionSegments-ExistingSegments)/2.
89                 dx = dn*(Dmax-Dmin)/ExistingSegments
90                 #MacObject('CompBoxF',[(X0-CoefHor*dx/2+CoefVer*(-X0+Dmin-dx/2),Y0-CoefVer*dx/2+CoefHor*(-Y0+Dmin-dx/2)),(dx,dx)],[(dn,dn)],publish=0)
91                 #MacObject('CompBoxF',[(X0-CoefHor*dx/2+CoefVer*(-X0+Dmax+dx/2),Y0-CoefVer*dx/2+CoefHor*(-Y0+Dmax+dx/2)),(dx,dx)],[(dn,dn)],publish=0)
92         
93         BoxSide = (Dmax-Dmin+2*dx)/2.
94         
95         Obj = []
96         Obj.append(MacObject('BoxAng32',[(X0+CoefHor*(BoxSide/2)+CoefVer*(-BoxSide/2),Y0+CoefVer*(BoxSide/2)+CoefHor*(-BoxSide/2)),(BoxSide,BoxSide)],[int(ExtensionSegments/6),DirPar[0]],groups=GroupArray(ToLook3[0],GroupNames[0])))       
97         Obj.append(MacObject('BoxAng32',[(X0+CoefHor*(BoxSide/2)+CoefVer*(BoxSide/2),Y0+CoefVer*(BoxSide/2)+CoefHor*(BoxSide/2)),(BoxSide,BoxSide)],[int(ExtensionSegments/6),DirPar[1]],groups=GroupArray(ToLook3[0],GroupNames[0])))        
98
99         NLevOpt = 0
100         for NLevels in range (1,100) : 
101                 DX1 = abs(CoefVer)*BoxSide*2.**(NLevels+1)+abs(CoefHor)*BoxSide*2.**(NLevels)
102                 DY1 = abs(CoefHor)*BoxSide*2.**(NLevels+1)+abs(CoefVer)*BoxSide*2.**(NLevels)
103                 if DX1 > DX or DY1 > DY :
104                         NLevOpt = NLevels-1
105                         DXinner = DX1/2.
106                         DYinner = DY1/2.
107                         break
108                         
109         dummyArray = [DXinner,DYinner,DYinner,DXinner]                 
110         D1inner = dummyArray[ToLook2]           # = DXinner for SN and NS orientations
111         D2inner = dummyArray[ToLook2+1]         # = DYinner for SN and NS orientations
112          
113         dummyArray = [DX,DY,DY,DX]                 
114         D1 = dummyArray[ToLook2]                # = DX for SN and NS orientations
115         D2 = dummyArray[ToLook2+1]              # = DY for SN and NS orientations
116                        
117         if D1inner < D1 : 
118                 GN0a = GroupArray(ToLook3[0],GroupNames[1])
119                 GN0b = GroupArray(ToLook3[0],GroupNames[2])              
120                 GN01 = GroupArray(ToLook3[0],GroupNames[1])
121                 GN02 = GroupArray(ToLook3[0],GroupNames[2])
122                 if D2inner < D2 : 
123                         GN10 = [None,None,None,None]
124                         GN11 = [None,None,None,None]
125                         GN20 = [None,None,None,None]
126                 else : 
127                         GN10 = GroupArray(ToLook3[1],GroupNames[3])
128                         GN11 = GroupArray(ToLook3[1],GroupNames[3])
129                         GN20 = GroupArray(ToLook3[1],GroupNames[3]) 
130         else : 
131                 GN0a = GroupArray(ToLook3[0],GroupNames[1])
132                 GN0b = GroupArray(ToLook3[0],GroupNames[2])
133                 GN01 = GroupArray([ToLook3[0],ToLook3[2]],[GroupNames[1],GroupNames[4]]) 
134                 GN02 = GroupArray([ToLook3[0],ToLook3[3]],[GroupNames[2],GroupNames[5]]) 
135                 if D2inner < D2 : 
136                         GN10 = GroupArray(ToLook3[2],GroupNames[4])
137                         GN11 = GroupArray(ToLook3[3],GroupNames[5])
138                         GN20 = [None,None,None,None]
139                 else : 
140                         GN10 = GroupArray([ToLook3[1],ToLook3[2]],[GroupNames[3],GroupNames[4]])
141                         GN11 = GroupArray([ToLook3[1],ToLook3[3]],[GroupNames[3],GroupNames[5]])
142                         GN20 = GroupArray(ToLook3[1],GroupNames[3]) 
143                                               
144         for N in range (1,NLevOpt+1):
145                 n=N-1
146                 D = BoxSide*(2.**n)
147                 if N < NLevOpt : 
148                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefHor*1/2-CoefVer*3/2)  , Y0+D*(CoefVer*1/2-CoefHor*3/2) )          , (D,D)],['auto',DirPar[2]], groups=GN0a))
149                         Obj.append(MacObject('BoxAng32',[(X0+D*(CoefHor*3/2-CoefVer*3/2)  , Y0+D*(CoefVer*3/2-CoefHor*3/2) )          , (D,D)],['auto',DirPar[3]]))
150                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefHor*3/2-CoefVer*1/2)  , Y0+D*(CoefVer*3/2-CoefHor*1/2) )          , (D,D)],['auto',DirPar[4]]))
151                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefHor*3/2+CoefVer*1/2)  , Y0+D*(CoefHor*1/2+CoefVer*3/2) )          , (D,D)],['auto',DirPar[5]]))
152                         Obj.append(MacObject('BoxAng32',[(X0+D*(CoefVer*3/2+CoefHor*3/2)  , Y0+D*(CoefVer*3/2+CoefHor*3/2) )          , (D,D)],['auto',DirPar[6]]))
153                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefVer*3/2+CoefHor*1/2)  , Y0+D*(CoefHor*3/2+CoefVer*1/2) )          , (D,D)],['auto',DirPar[7]], groups=GN0b))
154                 else :
155                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefHor*1/2-CoefVer*3/2)  , Y0+D*(CoefVer*1/2-CoefHor*3/2) )          , (D,D)],['auto',DirPar[2]], groups=GN01))
156                         Obj.append(MacObject('BoxAng32',[(X0+D*(CoefHor*3/2-CoefVer*3/2)  , Y0+D*(CoefVer*3/2-CoefHor*3/2) )          , (D,D)],['auto',DirPar[3]], groups=GN10))
157                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefHor*3/2-CoefVer*1/2)  , Y0+D*(CoefVer*3/2-CoefHor*1/2) )          , (D,D)],['auto',DirPar[4]], groups=GN20))
158                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefHor*3/2+CoefVer*1/2)  , Y0+D*(CoefHor*1/2+CoefVer*3/2) )          , (D,D)],['auto',DirPar[5]], groups=GN20))
159                         Obj.append(MacObject('BoxAng32',[(X0+D*(CoefVer*3/2+CoefHor*3/2)  , Y0+D*(CoefVer*3/2+CoefHor*3/2) )          , (D,D)],['auto',DirPar[6]], groups=GN11))
160                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefVer*3/2+CoefHor*1/2)  , Y0+D*(CoefHor*3/2+CoefVer*1/2) )          , (D,D)],['auto',DirPar[7]], groups=GN02))
161
162         
163         if CoefVer and DX>DXinner : 
164                 Obj.append(MacObject('CompBoxF',[(X0-CoefVer*0.25*(DX+DXinner),Y0+CoefVer*DYinner/2),((DX-DXinner)/2,DYinner)],['auto'], groups = GroupArray([ToLook3[0],ToLook3[2]],[GroupNames[1],GroupNames[4]])))
165                 Obj.append(MacObject('CompBoxF',[(X0+CoefVer*0.25*(DX+DXinner),Y0+CoefVer*DYinner/2),((DX-DXinner)/2,DYinner)],['auto'], groups = GroupArray([ToLook3[0],ToLook3[3]],[GroupNames[2],GroupNames[5]])))
166                 if DY>DYinner : 
167                         Obj.append(MacObject('CompBoxF',[(X0-CoefVer*0.25*(DX+DXinner),Y0+CoefVer*(DY+DYinner)/2.),((DX-DXinner)/2,DY-DYinner)],['auto'], groups = GroupArray([ToLook3[1],ToLook3[2]],[GroupNames[3],GroupNames[4]])))
168                         Obj.append(MacObject('CompBoxF',[(X0+CoefVer*0.25*(DX+DXinner),Y0+CoefVer*(DY+DYinner)/2.),((DX-DXinner)/2,DY-DYinner)],['auto'], groups = GroupArray([ToLook3[1],ToLook3[3]],[GroupNames[3],GroupNames[5]])))
169                         Obj.append(MacObject('CompBoxF',[(X0,Y0+CoefVer*(DY+DYinner)/2.),(DXinner,DY-DYinner)],['auto'], groups = GroupArray(ToLook3[1],GroupNames[3])))
170         elif CoefHor and DY>DYinner : 
171                 Obj.append(MacObject('CompBoxF',[(X0+CoefHor*DXinner/2,Y0-CoefHor*0.25*(DY+DYinner)),(DXinner,(DY-DYinner)/2)],['auto'], groups = GroupArray([ToLook3[0],ToLook3[2]],[GroupNames[1],GroupNames[4]])))
172                 Obj.append(MacObject('CompBoxF',[(X0+CoefHor*DXinner/2,Y0+CoefHor*0.25*(DY+DYinner)),(DXinner,(DY-DYinner)/2)],['auto'], groups = GroupArray([ToLook3[0],ToLook3[3]],[GroupNames[2],GroupNames[5]])))
173                 if DX>DXinner : 
174                         Obj.append(MacObject('CompBoxF',[(X0+CoefHor*(DX+DXinner)/2.,Y0-CoefHor*0.25*(DY+DYinner)),(DX-DXinner,(DY-DYinner)/2)],['auto'], groups = GroupArray([ToLook3[1],ToLook3[2]],[GroupNames[3],GroupNames[4]])))
175                         Obj.append(MacObject('CompBoxF',[(X0+CoefHor*(DX+DXinner)/2.,Y0+CoefHor*0.25*(DY+DYinner)),(DX-DXinner,(DY-DYinner)/2)],['auto'], groups = GroupArray([ToLook3[1],ToLook3[3]],[GroupNames[3],GroupNames[5]])))
176                         Obj.append(MacObject('CompBoxF',[(X0+CoefHor*(DX+DXinner)/2.,Y0),(DX-DXinner,DYinner)],['auto'], groups = GroupArray(ToLook3[1],GroupNames[3])))
177         return Obj
178
179 def RemoveLastObj() : 
180         Config.ListObj = Config.ListObj[:-1]
181         Config.Connections = Config.Connections[:-1]
182  
183 def GroupArray(indices, GroupNames) :
184         if type(indices) is int : 
185                 indices = [indices]
186                 GroupNames = [GroupNames]
187         Output = [None,None,None,None]
188         for i, ind in enumerate(indices) : 
189                 Output[ind] = GroupNames[i]
190         return Output