Package Pmv :: Module multiresCommands
[hide private]
[frames] | no frames]

Source Code for Module Pmv.multiresCommands

  1  ############################################################################# 
  2  # 
  3  # Author: Kevin Chan, Michel F. SANNER 
  4  # 
  5  # Copyright: M. Sanner TSRI 2000 
  6  # 
  7  ############################################################################# 
  8   
  9  # 
 10  # $Header: /opt/cvs/python/packages/share1.5/Pmv/multiresCommands.py,v 1.4 2004/05/28 02:16:18 sanner Exp $ 
 11  # 
 12  # $Id: multiresCommands.py,v 1.4 2004/05/28 02:16:18 sanner Exp $ 
 13  # 
 14   
 15   
 16  from ViewerFramework.VFCommand import CommandGUI 
 17  from Pmv.mvCommand import MVCommand 
 18  from multires import * 
 19  ##  from ViewerFramework.gui import InputForm, InputFormDescr 
 20  from mglutil.gui.InputForm.Tk.gui import InputForm, InputFormDescr 
 21   
 22  from mglutil.util.callback import CallBackFunction 
 23   
 24  import Pmw, Tkinter 
 25  from Pmv.picker import NewMsmsPicker 
 26   
 27   
28 -class GoCoarserFiner(MVCommand):
29
30 - def __init__(self):
31 MVCommand.__init__(self) 32 self.curMol = None 33 self.curSurf = None
34 35
36 - def doit(self, coarse_fine, mol, surface = 'msms'):
37 if not mol or not surface: return 38 if not mol.geomContainer.geoms.has_key(surface) or \ 39 not hasattr(mol, '%smodel'%surface): return 40 geom = mol.geomContainer.geoms[surface] 41 model = getattr(mol, '%smodel'%surface) 42 if coarse_fine=='coarser': done = model.GoCoarser() 43 elif coarse_fine=='finer': done = model.GoFiner() 44 else: done = 0 45 if done: 46 tri = getTriangles(model) 47 geom.Set(faces = tri, tagModified=False) 48 self.vf.GUI.VIEWER.Redraw() 49 else: 50 if coarse_fine=='coarser': 51 print 'surface already at coarsest level' 52 elif coarse_fine=='finer': 53 print 'surface already at finest level' 54 else: return 55 self.log(mol, surface, coarse_fine)
56 57
58 - def __call__(self, mol, surface, coarse_fine):
59 if mol not in self.vf.Mols: return 60 if not mol.geomContainer.geoms.has_key(surface): return 61 if not hasattr(mol, '%smodel'%surface): 62 geom = mol.geomContainer.geoms[surface] 63 v = geom.vertexSet.vertices.array 64 f = geom.faceSet.faces.array 65 setattr(mol, '%smodel'%surface, ModelT(v, f)) 66 if coarse_fine not in ('coarser', 'finer'): 67 print "last arg must be 'coarser' or 'finer'" 68 self.doit(mol, surface, coarse_fine)
69 70
71 - def guiCallback(self):
72 self.ifd = ifd = InputFormDescr(title = 'Go Coarser/Finer') 73 mols = self.vf.Mols.name 74 if not mols: mols = () 75 ifd.append({'widgetType':Pmw.ScrolledListBox, 76 'name':'molecule', 77 'wcfg':{'label_text':'Select Molecule:', 78 'labelpos':'nw', 79 'items':mols, 80 'selectioncommand':self.selectMol, 81 'listbox_height':10 82 }, 83 'gridcfg':{'row':0, 'column':0} 84 }) 85 ifd.append({'widgetType':Pmw.ScrolledListBox, 86 'name':'surface', 87 'wcfg':{'label_text':'Select Surface:', 88 'labelpos':'nw', 89 'selectioncommand':self.selectSurf, 90 'listbox_height':10 91 }, 92 'gridcfg':{'row':0, 'column':1} 93 }) 94 ifd.append({'widgetType':Tkinter.Button, 95 'name':'goCoarser', 96 'wcfg':{'text':'Go Coarser', 97 'command':self.goCoarser 98 }, 99 'gridcfg':{'row':1, 'column':0, 'sticky':'ew'} 100 }) 101 ifd.append({'widgetType':Tkinter.Button, 102 'name':'goFiner', 103 'wcfg':{'text':'Go Finer', 104 'command':self.goFiner 105 }, 106 'gridcfg':{'row':1, 'column':1, 'sticky':'ew'} 107 }) 108 ifd.append({'widgetType':Tkinter.Button, 109 'name':'reset', 110 'wcfg':{'text':'Reset', 111 'command':self.reset 112 }, 113 'gridcfg':{'row':2, 'column':0, 'columnspan':2} 114 }) 115 ifd.append({'widgetType':Tkinter.Button, 116 'name':'done', 117 'wcfg':{'text':'done', 118 'command':self.done 119 }, 120 'gridcfg':{'row':3, 'column':0, 'columnspan':2} 121 }) 122 self.form = self.vf.getUserInput(ifd, modal = 0, blocking = 0)
123 124
125 - def selectMol(self, event = None):
126 molLB = self.ifd.entryByName['molecule']['widget'] 127 sel = molLB.curselection() 128 if not sel: return 129 self.curMol = self.vf.Mols[int(sel[0])] 130 surfLB = self.ifd.entryByName['surface']['widget'] 131 surflist = [] 132 if self.curMol.geomContainer.geoms.has_key('msms'): 133 if self.curMol.geomContainer.geoms['msms'].vertexSet and \ 134 self.curMol.geomContainer.geoms['msms'].faceSet: 135 surflist.append('msms') 136 surfLB.setlist(surflist)#and other surf.
137 138
139 - def selectSurf(self, event = None):
140 surfLB = self.ifd.entryByName['surface']['widget'] 141 sel = surfLB.getcurselection() 142 if not sel: return 143 self.curSurf = sel[0] 144 if not hasattr(self.curMol, '%smodel'%self.curSurf): 145 geom = self.curMol.geomContainer.geoms[self.curSurf] 146 v = geom.vertexSet.vertices.array 147 f = geom.faceSet.faces.array 148 setattr(self.curMol, '%smodel'%self.curSurf, ModelT(v, f))
149 150
151 - def goCoarser(self, event = None):
152 self.doit('coarser', self.curMol, self.curSurf)
153 154
155 - def goFiner(self, event = None):
156 self.doit('finer', self.curMol, self.curSurf)
157 158
159 - def reset(self, event = None):
160 if not self.curMol or not self.curSurf: return 161 if not hasattr(self.curMol, '%smodel'%self.curSurf): return 162 geom = self.curMol.geomContainer.geoms[self.curSurf] 163 model = getattr(self.curMol, '%smodel'%self.curSurf) 164 while model.GoFiner(): 165 self.log(self.curMol, self.curSurf, 'finer') 166 tri = getTriangles(model) 167 geom.Set(faces = tri, tagModified=False) 168 self.vf.GUI.VIEWER.Redraw()
169 170
171 - def done(self, event = None):
172 self.form.destroy() 173 self.curMol = None 174 self.curSurf = None
175 176 goCoarserFinerGuiDescr1 = {'widgetType':'Menu', 'menuBarName':'menuRoot', 177 'menuButtonName':'Multires', 178 'menuEntryLabel':'Coarser/Finer 1'} 179 180 GoCoarserFinerGUI = CommandGUI() 181 GoCoarserFinerGUI.addMenuCommand('menuRoot', 'Multires', 'Coarser/Finer 1') 182 183
184 -class goCoarserFiner(MVCommand):
185
186 - def __init__(self):
187 MVCommand.__init__(self) 188 self.curSurf = None
189 190
191 - def doit(self, coarse_fine, surface):
192 mol = surface.mol 193 model = getattr(mol, '%smodel'%surface.name) 194 if coarse_fine=='coarser': done = model.GoCoarser() 195 elif coarse_fine=='finer': done = model.GoFiner() 196 else: done = 0 197 if done: 198 tri = getTriangles(model) 199 surface.Set(faces = tri, tagModified=False) 200 self.vf.GUI.VIEWER.Redraw() 201 else: 202 if coarse_fine=='coarser': 203 print 'surface already at coarsest level' 204 elif coarse_fine=='finer': 205 print 'surface already at finest level' 206 else: return 207 self.log(coarse_fine, surface.name, mol.name)
208 209
210 - def __call__(self, coarse_fine, surfname, molecule):
211 """ call with a surface name """ 212 mol = self.vf.Mols.get(molecule)[0] 213 if not mol: return 214 if not mol.geomContainer.geoms.has_key(surfname): return 215 surface = mol.geomContainer.geoms[surfname] 216 if coarse_fine not in ('coarser', 'finer'): 217 return 218 if not hasattr(mol, '%smodel'%surfname): 219 surface = mol.geomContainer.geoms[surfname] 220 v = surface.vertexSet.vertices.array 221 f = surface.faceSet.faces.array 222 setattr(mol, '%smodel'%surface.name, ModelT(v, f)) 223 self.doit(coarse_fine, surface)
224 225
226 - def guiCallback(self):
227 self.vf.picker = NewMsmsPicker(self.vf, numberOfObjects=1, 228 callbacks=[self.InitCoarserFiner])
229 230
231 - def InitCoarserFiner(self, surfaces):
232 self.curSurf = surfaces[0] 233 mol = self.curSurf.mol 234 if not hasattr(mol, '%smodel'%self.curSurf.name): 235 surface = mol.geomContainer.geoms[self.curSurf.name] 236 v = surface.vertexSet.vertices.array 237 f = surface.faceSet.faces.array 238 setattr(mol, '%smodel'%self.curSurf.name, ModelT(v, f)) 239 self.ifd = ifd = InputFormDescr(title = 'Go Coarser/Finer') 240 ifd.append({'widgetType':Tkinter.Label, 241 'name':'surfname', 242 'wcfg':{'text':'%s : %s'%(self.curSurf.mol.name, 243 self.curSurf.name)}, 244 'gridcfg':{'row':0, 'column':0, 'columnspan':2} 245 }) 246 ifd.append({'widgetType':Tkinter.Button, 247 'name':'goCoarser', 248 'wcfg':{'text':'Go Coarser', 249 'command':CallBackFunction(self.doit, 'coarser', 250 self.curSurf) 251 }, 252 'gridcfg':{'row':1, 'column':0, 'sticky':'ew'} 253 }) 254 ifd.append({'widgetType':Tkinter.Button, 255 'name':'goFiner', 256 'wcfg':{'text':'Go Finer', 257 'command':CallBackFunction(self.doit, 'finer', 258 self.curSurf) 259 }, 260 'gridcfg':{'row':1, 'column':1, 'sticky':'ew'} 261 }) 262 ifd.append({'widgetType':Tkinter.Button, 263 'name':'reset', 264 'wcfg':{'text':'Reset', 265 'command':self.reset 266 }, 267 'gridcfg':{'row':2, 'column':0, 'columnspan':2} 268 }) 269 ifd.append({'widgetType':Tkinter.Button, 270 'name':'done', 271 'wcfg':{'text':'done', 272 'command':self.done 273 }, 274 'gridcfg':{'row':3, 'column':0, 'columnspan':2} 275 }) 276 self.form = self.vf.getUserInput(ifd, modal = 0, blocking = 0)
277 278
279 - def goCoarser(self, event = None):
280 self.doit('coarser', self.curSurf)
281 282
283 - def goFiner(self, event = None):
284 self.doit('finer', self.curSurf)
285 286
287 - def reset(self, event = None):
288 mol = self.curSurf.mol 289 model = getattr(mol, '%smodel'%self.curSurf.name) 290 while model.GoFiner(): 291 #self.log(self.curMol, self.curSurf, 'finer') 292 pass 293 tri = getTriangles(model) 294 self.curSurf.Set(faces = tri, tagModified=False) 295 self.vf.GUI.VIEWER.Redraw()
296 297
298 - def done(self, event = None):
299 self.form.destroy() 300 self.curSurf = None
301 302 goCoarserFinerGuiDescr2 = {'widgetType':'Menu', 'menuBarName':'menuRoot', 303 'menuButtonName':'Multires', 304 'menuEntryLabel':'Coarser/Finer 2'} 305 306 goCoarserFinerGUI = CommandGUI() 307 goCoarserFinerGUI.addMenuCommand('menuRoot', 'Multires', 'Coarser/Finer 2') 308 309 310 from mglutil.gui.BasicWidgets.Tk.customizedWidgets import SliderWidget 311 import Numeric 312
313 -class Multires(MVCommand):
314
315 - def __init__(self):
316 MVCommand.__init__(self) 317 self.curSurf = None 318 self.vSize = None 319 self.scaleVector = None
320 321
322 - def doit(self, surface, scVect):
323 mol = surface.mol 324 model = getattr(mol, '%smodel'%surface.name) 325 model.SetAllScalingVector(scVect) 326 model.Transform() 327 v = getVertices(model) 328 surface.Set(vertices = v, tagModified=False) 329 self.vf.GUI.VIEWER.Redraw() 330 self.log(surface.name, mol.name, scVect)
331 332
333 - def __call__(self, surfname, molecule, scaleVect):
334 """ call with a surface name """ 335 mol = self.vf.Mols.get(molecule)[0] 336 if not mol: return 337 if not mol.geomContainer.geoms.has_key(surfname): return 338 surface = mol.geomContainer.geoms[surfname] 339 if not hasattr(mol, '%smodel'%surfname): 340 surface = mol.geomContainer.geoms[surfname] 341 v = surface.vertexSet.vertices.array 342 f = surface.faceSet.faces.array 343 setattr(mol, '%smodel'%surface.name, ModelT(v, f)) 344 model = getattr(mol, '%smodel'%surface.name) 345 model.InitMultires() 346 vSize = model.ScalingVectorSize() 347 ## if vSize==0: 348 ## model.InitMultires() 349 ## vSize = model.ScalingVectorSize() 350 if len(scaleVect) != vSize: return 351 self.doit(surface, scaleVect)
352 353
354 - def guiCallback(self):
355 self.vf.picker = NewMsmsPicker(self.vf, numberOfObjects=1, 356 callbacks=[self.SetupMultires])
357 358
359 - def SetupMultires(self, surfaces):
360 self.curSurf = surfaces[0] 361 mol = self.curSurf.mol 362 if not hasattr(mol, '%smodel'%self.curSurf.name): 363 surface = mol.geomContainer.geoms[self.curSurf.name] 364 v = surface.vertexSet.vertices.array 365 f = surface.faceSet.faces.array 366 setattr(mol, '%smodel'%self.curSurf.name, ModelT(v, f)) 367 model = getattr(mol, '%smodel'%self.curSurf.name) 368 model.InitMultires() 369 self.vSize = vSize = model.ScalingVectorSize() 370 self.scaleVector = Numeric.ones((vSize,), 'f') 371 self.ifd = ifd = InputFormDescr(title = 'Multires Scaling') 372 ifd.append({'widgetType':Tkinter.Label, 373 'name':'surfname', 374 'wcfg':{'text':'%s : %s'%(self.curSurf.mol.name, 375 self.curSurf.name)}, 376 'gridcfg':{'row':0, 'column':0, 'columnspan':2} 377 }) 378 for i in range(vSize): 379 ifd.append({'widgetType':SliderWidget, 380 'name':'ScaleRes%i'%i, 381 'wcfg':{'minval':0.0, 'maxval':5.0, 'init':1.0, 382 'labelsCursorFormat':'%1.3f', 383 'command':CallBackFunction(self.scale, i), 384 'immediate':0} 385 }) 386 ifd.append({'widgetType':Tkinter.Button, 387 'name':'reset', 388 'wcfg':{'text':'Reset', 389 'command':self.reset 390 }#, 391 #'gridcfg':{'row':2, 'column':0, 'columnspan':2} 392 }) 393 ifd.append({'widgetType':Tkinter.Button, 394 'name':'done', 395 'wcfg':{'text':'done', 396 'command':self.done 397 }#, 398 #'gridcfg':{'row':3, 'column':0, 'columnspan':2} 399 }) 400 self.form = self.vf.getUserInput(ifd, modal = 0, blocking = 0)
401 402
403 - def scale(self, index, val):
404 self.scaleVector[index] = val 405 self.doit(self.curSurf, self.scaleVector)
406 407
408 - def reset(self, event = None):
409 for i in range(self.vSize): 410 widget = self.ifd.entryByName['ScaleRes%i'%i]['widget'] 411 if widget.get() != 1.0: 412 widget.set(1.0)
413 ## self.scaleVector = Numeric.ones((self.vSize,), 'f') 414 ## self.doit(self.curSurf, self.scaleVector) 415 416
417 - def done(self, event = None):
418 self.form.destroy() 419 self.curSurf = None 420 self.vSize = None 421 self.scaleVector = None
422 423 multiresGuiDescr = {'widgetType':'Menu', 'menuBarName':'menuRoot', 424 'menuButtonName':'Multires', 425 'menuEntryLabel':'Frequencies Scaling'} 426 427 MultiresGUI = CommandGUI() 428 MultiresGUI.addMenuCommand('menuRoot', 'Multires', 'Frequencies Scaling') 429 430 431 commandList = [ 432 {'name':'GoCoarserFiner', 'cmd':GoCoarserFiner(), 'gui':GoCoarserFinerGUI}, 433 {'name':'goCoarserFiner', 'cmd':goCoarserFiner(), 'gui':goCoarserFinerGUI}, 434 {'name':'Multires', 'cmd':Multires(), 'gui':MultiresGUI} 435 ] 436
437 -def initModule(viewer):
438 439 for dict in commandList: 440 viewer.addCommand( dict['cmd'], dict['name'], dict['gui'])
441