1 # Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
30 import sys, math, commands
31 CWD = commands.getoutput('pwd')
34 from MacObject import *
35 import Config, GenFunctions
37 def CentralUnrefine (X0 , Y0 , DX , DY , Orientation, **args ) :
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]()
44 CoefVer = {'SN' : lambda : 1.,
47 'WE' : lambda : 0., }[Orientation]()
49 CoefHor = {'SN' : lambda : 0.,
52 'WE' : lambda : 1., }[Orientation]()
55 MacObject('CompBoxF',[(X0+CoefHor*DX/2,Y0+CoefVer*DY/2),(DX,DY)],['auto'],publish=0)
56 ToLook1 = {'SN' : lambda : 2,
59 'WE' : lambda : 0, }[Orientation]()
61 ToLook2 = {'SN' : lambda : 0,
64 'WE' : lambda : 2, }[Orientation]()
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]()
71 if args.__contains__('groups') :
72 GroupNames = args['groups']
73 else : GroupNames = [None, None, None, None, None, None]
75 ExistingSegments = Config.ListObj[-1].DirectionalMeshParams[ToLook1]
76 ObjIDs = Config.Connections[-1][ToLook1]
79 ExtensionSegments = math.ceil(ExistingSegments/12.)*12.
83 Boundaries = Config.ListObj[ObjID].Boundaries()
84 if Boundaries[ToLook2] < Dmin : Dmin = Boundaries[ToLook2]
85 if Boundaries[ToLook2+1] > Dmax : Dmax = Boundaries[ToLook2+1]
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)
93 BoxSide = (Dmax-Dmin+2*dx)/2.
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])))
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 :
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
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
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])
123 GN10 = [None,None,None,None]
124 GN11 = [None,None,None,None]
125 GN20 = [None,None,None,None]
127 GN10 = GroupArray(ToLook3[1],GroupNames[3])
128 GN11 = GroupArray(ToLook3[1],GroupNames[3])
129 GN20 = GroupArray(ToLook3[1],GroupNames[3])
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]])
136 GN10 = GroupArray(ToLook3[2],GroupNames[4])
137 GN11 = GroupArray(ToLook3[3],GroupNames[5])
138 GN20 = [None,None,None,None]
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])
144 for N in range (1,NLevOpt+1):
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))
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))
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]])))
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]])))
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])))
179 def RemoveLastObj() :
180 Config.ListObj = Config.ListObj[:-1]
181 Config.Connections = Config.Connections[:-1]
183 def GroupArray(indices, GroupNames) :
184 if type(indices) is int :
186 GroupNames = [GroupNames]
187 Output = [None,None,None,None]
188 for i, ind in enumerate(indices) :
189 Output[ind] = GroupNames[i]