1
# -*- coding: utf-8 -*-
3
#-------------------------------------------------------------------------------
5
# This file is part of Code_Saturne, a general-purpose CFD tool.
7
# Copyright (C) 1998-2011 EDF S.A.
9
# This program is free software; you can redistribute it and/or modify it under
10
# the terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
14
# This program is distributed in the hope that it will be useful, but WITHOUT
15
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19
# You should have received a copy of the GNU General Public License along with
20
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
21
# Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#-------------------------------------------------------------------------------
29
The two solvers I{Code_Saturne} and C{NEPTUNE_CFD} have their own GUI. The
30
purpose of the class C{CFDSTUDYGUI_SolverGUI} is to display the solver GUI of
31
the selected code in the SALOME workspace.
34
#-------------------------------------------------------------------------------
36
#-------------------------------------------------------------------------------
41
#-------------------------------------------------------------------------------
43
#-------------------------------------------------------------------------------
45
from PyQt4.QtGui import QApplication, QMainWindow, QDockWidget, QTreeView, QMessageBox
46
from PyQt4.QtCore import Qt, QObject, QEvent, SIGNAL, SLOT
48
#-------------------------------------------------------------------------------
50
#-------------------------------------------------------------------------------
52
#-------------------------------------------------------------------------------
54
#-------------------------------------------------------------------------------
56
from CFDSTUDYGUI_Commons import CFD_Code, Trace, CFD_Saturne, CFD_Neptune, sgPyQt
57
from CFDSTUDYGUI_Commons import LogModeOn, LogModeOff, LoggingMgr, LoggingAgent
58
import CFDSTUDYGUI_DataModel
60
#-------------------------------------------------------------------------------
62
#-------------------------------------------------------------------------------
65
_d_DockWindowsBrowser = {}
66
_d_DockWindowsRuncase = {}
68
_selectedMainViewCase = []
71
_LoggingMgr = LoggingMgr()
73
#-------------------------------------------------------------------------------
74
# Function definitions
75
#-------------------------------------------------------------------------------
77
def getDockWindowsLists():
80
studyId = sgPyQt.getStudyId()
81
if studyId in _d_DockWindows.keys() and studyId in _d_DockWindowsBrowser.keys():
82
return True #_d_DockWindows[studyId],_d_DockWindowsBrowser[studyId]
87
def tabObjectBrowser():
89
Regroupe en onglets les DockWidgets contenant des QTreeView:
90
Object Browser et arbres CFDSTUDY
92
dsk = sgPyQt.getDesktop()
93
ldock=dsk.findChildren(QDockWidget)
96
lo=i.findChildren(QTreeView)
99
for i in range(1, len(ldocktree)):
100
dsk.tabifyDockWidget(ldocktree[0], ldocktree[i])
103
def updateObjectBrowser():
105
force le regroupement en onglets des QTreeView apres updateObjBrowser
107
studyId = sgPyQt.getStudyId()
108
sgPyQt.updateObjBrowser(studyId, 1)
112
def updateDockWindows() :
114
force le regroupement en onglets des fenetres d'etudes CFD
116
dsk = sgPyQt.getDesktop()
117
studyId = sgPyQt.getStudyId()
119
if not getDockWindowsLists():
121
if len(_d_DockWindows[studyId]) > 1:
122
for i in range(1,len(_d_DockWindows[studyId])):
123
dsk.tabifyDockWidget(_d_DockWindows[studyId][0], _d_DockWindows[studyId][i])
126
def updateDockWindowsBrowser() :
128
force le regroupement en onglets des fenetres Browser d'etudes CFD
130
dsk = sgPyQt.getDesktop()
131
studyId = sgPyQt.getStudyId()
133
if not getDockWindowsLists():
135
if len(_d_DockWindowsBrowser[studyId]) > 1 :
136
for i in range(1,len(_d_DockWindowsBrowser[studyId])):
137
dsk.tabifyDockWidget(_d_DockWindowsBrowser[studyId][0], _d_DockWindowsBrowser[studyId][i])
140
def findDockWindow(xmlName,caseName,studyCFDName) :
142
find if the dockwindow corresponding to this xmlcase is already opened
145
name = string.join([studyCFDName,caseName,xmlName],".")
146
bool_findDockWindow = False
147
dsk = sgPyQt.getDesktop()
148
studyId = sgPyQt.getStudyId()
149
ldockWindows =dsk.findChildren(QDockWidget)
150
for dock in ldockWindows:
151
dockTitle = dock.windowTitle()
152
if studyId not in _d_DockWindowsBrowser.keys():
153
_d_DockWindowsBrowser[studyId] = []
154
if (str(dockTitle) == 'Object Browser') and (dock not in _d_DockWindowsBrowser[studyId]):
155
_d_DockWindowsBrowser[studyId].append(dock)
156
if studyId not in _d_DockWindows.keys():
157
_d_DockWindows[studyId] = []
159
if _d_DockWindows[studyId] != [] :
160
for dock in _d_DockWindows[studyId] :
161
if str(name) in str(dock.windowTitle()) :
162
bool_findDockWindow = True
166
return bool_findDockWindow
169
def removeDockWindow(caseName) :
172
remove the CFD_study_dock_windows from remove popup menu in object browser
174
dsk = sgPyQt.getDesktop()
175
studyId = sgPyQt.getStudyId()
176
ldockWindows =dsk.findChildren(QDockWidget)
177
for dock in ldockWindows:
178
dockTitle = dock.windowTitle()
179
if string.split(str(dockTitle),".")[0] == str(caseName):
180
if "Browser" not in str(dockTitle) :
181
_d_DockWindows[studyId].remove(dock)
182
dsk.removeDockWidget(dock)
185
_d_DockWindowsBrowser[studyId].remove(dock)
186
dsk.removeDockWidget(dock)
188
updateObjectBrowser()
191
#-------------------------------------------------------------------------------
193
#-------------------------------------------------------------------------------
195
class CFDSTUDYGUI_SolverGUI(QObject):
197
Auxilliary class for interaction with solvers GUI
200
if Trace() : print "CFDSTUDY_SolverGUI.__init__ : "
201
QObject.__init__(self, None)
202
self._WindowsMap = {}
203
self._CurrentWindow = None
205
_d_DockWindowsBrowser = {}
207
def ExecGUI(self, WorkSpace, aTitle, aCase, Args=''):
209
Executes GUI for solver relatively CFDCode
211
if Trace() : print "CFDSTUDY_SolverGUI.ExecGUI : "
213
if aTitle != None and aTitle != "":
214
#searching in existing tabs
215
win = self._findWindow(aTitle,aCase)
218
QApplication.postEvent(win, QEvent(QEvent.FocusIn))
222
if findDockWindow(aTitle,aCase.GetName(),aCase.GetFather().GetName()) :
223
mess = "A case is not finished to be set"
224
QMessageBox.warning(None, "Warning : ",mess)
228
if CFD_Code() == CFD_Saturne:
229
# object of DATA folder
230
aChildList = CFDSTUDYGUI_DataModel.ScanChildren(aCase, "^DATA$")
231
if not len(aChildList)== 1:
233
if Trace(): print "CFDSTUDYGUI_SolverGUI.ExecGUI :There are not data folder in selected by user case"
235
aStartPath = CFDSTUDYGUI_DataModel._GetPath(aChildList[0])
236
elif CFD_Code() == CFD_Neptune:
237
aStartPath = CFDSTUDYGUI_DataModel._GetPath(aCase)
238
if aStartPath != None and aStartPath != '':
240
if CFD_Code() == CFD_Saturne:
241
mw = self._ExecICS(WorkSpace, aCase, aTitle, Args)
242
elif CFD_Code() == CFD_Neptune:
243
mw = self._ExecIPB(WorkSpace, aTitle, Args)
245
self._WindowsMap[mw] = aCase
246
self._CurrentWindow = mw
247
_selectedMainViewCase.append(mw)
251
def eventFilter(self, anObject, anEvent):
252
if Trace() : print "CFDSTUDY_SolverGUI.eventFilter : "
253
if anEvent.type() == QEvent.Close:
254
del self._WindowsMap[anObject]
255
elif anEvent.type() == QEvent.Hide:
256
if self._CurrentWindow == anObject:
257
self._CurrentWindow = None
258
elif anEvent.type() == QEvent.Show:
259
self._CurrentWindow = anObject
264
return self._CurrentWindow != None
267
def onSaveXmlFile(self):
268
if Trace() : print "CFDSTUDY_SolverGUI.onSaveXmlFile : "
269
if self._CurrentWindow != None:
270
if CFD_Code() == CFD_Saturne:
271
self._CurrentWindow.fileSave()
273
def onSaveAsXmlFile(self):
278
if len(_selectedMainViewCase) != 0:
279
_sMainViewCase = self._CurrentWindow
280
if CFD_Code() == CFD_Saturne:
281
old_xml_file = _sMainViewCase.case['xmlfile']
282
_sMainViewCase.fileSaveAs()
283
xml_file = _sMainViewCase.case['xmlfile']
284
if xml_file != None and xml_file != "" and xml_file != old_xml_file:
285
#need update object browser
286
case = self._WindowsMap[_sMainViewCase]
287
study = CFDSTUDYGUI_DataModel.GetStudyByObj(case)
289
obj = CFDSTUDYGUI_DataModel.checkPathUnderObject(study, xml_file)
291
#changes Title of the tab
292
new_title = os.path.basename(xml_file)
293
_sMainViewCase.setWindowTitle(new_title)
295
#updates Object Browser
296
CFDSTUDYGUI_DataModel._RebuildTreeRecursively(obj)
297
#if os.path.exists(old_xml_file) and os.path.exists(xml_file) :
298
if os.path.exists(xml_file) :
299
self.replaceDockTitleName(xml_file,old_xml_file,case,study)
301
updateObjectBrowser()
304
def getDockTitleName(self,xml_file) :
306
Build the Dock Title Name STUDY.CASE.file.xml with the entire file Name
308
lnames = string.split(xml_file,"/")
309
if len(lnames) < 4 : return None
311
casename = lnames[-3]
312
studyname = lnames[-4]
313
return string.join([studyname,casename,xmlname],".")
316
def replaceDockTitleName(self,new_xml_file,old_xml_file,case,study) :
318
replace dock title name in the title of the dock widget and update
319
the _d_DockWindows and _d_DockWindowsBrowser dictionary
321
OldDockTitleName = self.getDockTitleName(old_xml_file)
322
NewDockTitleName = self.getDockTitleName(new_xml_file)
324
if NewDockTitleName == None :
325
mess = "File : "+xml_file+ \
326
" is not stored into a CFDSTUDY directory structure like .../STUDY_CFD/CASE/DATA/filename.xml"
327
QMessageBox.warning(None, "File Error : ",mess)
329
if OldDockTitleName == None :
330
studyname = study.GetName()
331
casename = case.GetName()
333
OldDockTitleName = string.join([studyname,casename,xmlname],".")
334
if NewDockTitleName != None :
335
studyId = sgPyQt.getStudyId()
336
if studyId in _d_DockWindows.keys():
337
for dock in _d_DockWindows[studyId]:
338
if str(OldDockTitleName) in str(dock.windowTitle()) :
339
dock.setWindowTitle(str(NewDockTitleName))
342
if studyId in _d_DockWindowsBrowser.keys():
343
for dock in _d_DockWindowsBrowser[studyId]:
344
if str(OldDockTitleName) in str(dock.windowTitle()) :
345
dock.setWindowTitle(string.join([str(NewDockTitleName),"Browser"]))
351
def onOpenShell(self):
354
if Trace() : print "CFDSTUDY_SolverGUI.onOpenShell : "
355
if self._CurrentWindow != None :
356
if CFD_Code() == CFD_Saturne:
357
self._CurrentWindow.openXterm()
360
def onDisplayCase(self):
361
if Trace() : print "CFDSTUDY_SolverGUI.onDisplayCase : "
362
_LoggingMgr.start(sys)
363
if self._CurrentWindow != None:
365
if CFD_Code() == CFD_Saturne:
366
self._CurrentWindow.displayCase()
367
_LoggingMgr.finish(sys)
369
def onHelpAbout(self):
370
if Trace() : print "CFDSTUDY_SolverGUI.onHelpAbout : "
371
if self._CurrentWindow != None:
372
if CFD_Code() == CFD_Saturne:
373
self._CurrentWindow.displayAbout()
375
#-----------------------------------------------------------------------------
377
def onSaturneReloadModule(self):
380
if Trace() : print "CFDSTUDY_SolverGUI.onSaturneReloadModule: "
381
if self._CurrentWindow != None :
382
if CFD_Code() == CFD_Saturne:
383
self._CurrentWindow.reload_modules()
386
def onSaturneReloadPage(self):
389
if Trace() : print "CFDSTUDY_SolverGUI.onSaturneReloadPage: "
390
if self._CurrentWindow != None :
391
if CFD_Code() == CFD_Saturne:
392
self._CurrentWindow.reload_page()
395
def onSaturneHelpLicense(self):
398
if Trace() : print "CFDSTUDY_SolverGUI.onSaturneHelpLicense: "
399
if self._CurrentWindow != None :
400
if CFD_Code() == CFD_Saturne:
401
self._CurrentWindow.displayLicence()
404
def onSaturneHelpCS(self):
407
if Trace() : print "CFDSTUDY_SolverGUI.onSaturneHelpcs: "
408
if self._CurrentWindow != None :
409
if CFD_Code() == CFD_Saturne:
410
self._CurrentWindow.displayCSManual()
413
def onSaturneHelpSD(self):
416
if Trace() : print "CFDSTUDY_SolverGUI.onSaturneHelpSD: "
417
if self._CurrentWindow != None :
418
if CFD_Code() == CFD_Saturne:
419
self._CurrentWindow.displayECSManual()
423
def onSaturneHelpCS_Kernel(self):
426
if Trace() : print "CFDSTUDY_SolverGUI.onSaturneHelpCS_Kernel : "
427
if self._CurrentWindow != None :
428
if CFD_Code() == CFD_Saturne:
429
self._CurrentWindow.displayCSKernel()
434
def onSaturneHelpCS_Infos(self):
437
if Trace() : print "CFDSTUDYGUI_SolverGUI.onSaturneHelpCS_INFOS : "
438
if self._CurrentWindow != None :
439
if CFD_Code() == CFD_Saturne:
440
self._CurrentWindow.displayECSInfos()
445
def onNeptuneWinBrowser(self, flag):
446
if self._CurrentWindow != None:
447
if CFD_Code() == CFD_Neptune:
448
self._CurrentWindow.browserDockDisplay(flag)
451
def onNeptuneWinIdenty(self,flag):
452
if self._CurrentWindow != None:
453
if CFD_Code() == CFD_Neptune:
454
self._CurrentWindow.identityDockDisplay(flag)
457
def _ExecIPB(self, WorkSpace, Title, Args):
464
def _ExecICS(self, WorkSpace, aCase, Title, Args):
467
from Base.MainView import MainView
468
from cs_gui import process_cmd_line
470
self.Workspace = WorkSpace
471
case, splash, batch_window, batch_file, tree_window, read_only = process_cmd_line(Args)
473
mw = MainView(case, batch_window, batch_file, tree_window, read_only, aCase)
474
fatherName = aCase.GetFather().GetName()
476
aTitle = str(fatherName + "." + aCase.GetName()) + '.' + str(Title)
477
mw.setWindowTitle(aTitle)
479
dsk = sgPyQt.getDesktop()
480
dock = QDockWidget(aTitle)
482
dock.setWidget(mw.frame)
483
dock.setMinimumWidth(520)
484
dsk.addDockWidget(Qt.RightDockWidgetArea, dock)
486
studyId = sgPyQt.getStudyId()
488
if studyId not in _d_DockWindows.keys():
489
_d_DockWindows[studyId] = []
490
_d_DockWindows[studyId].append(dock)
492
dock.setVisible(True)
496
BrowserTitle = aTitle + " Browser"
497
mw.dockWidgetBrowser.setWindowTitle(BrowserTitle)
498
dsk.addDockWidget(Qt.LeftDockWidgetArea,mw.dockWidgetBrowser)
500
if studyId not in _d_DockWindowsBrowser.keys():
501
_d_DockWindowsBrowser[studyId] = []
502
_d_DockWindowsBrowser[studyId].append(mw.dockWidgetBrowser)
504
mw.dockWidgetBrowser.setVisible(True)
505
mw.dockWidgetBrowser.show()
506
mw.dockWidgetBrowser.raise_()
509
self.connect(dock, SIGNAL("visibilityChanged(bool)"), self.setdockWindowBrowserActivated)
510
self.connect(mw.dockWidgetBrowser, SIGNAL("visibilityChanged(bool)"),self.setdockWindowActivated)
512
updateDockWindowsBrowser()
513
updateObjectBrowser()
517
def _findWindow(self, aTitle, aCase):
519
if aTitle == '' or aCase == None:
522
for win in self._WindowsMap.keys():
523
if aTitle == str(win.windowTitle().toLatin1()) and \
524
aCase.GetID() == self._WindowsMap[win].GetID():
530
def setdockWindowBrowserActivated(self,visible) :
532
if not visible : return
534
if dock.isActiveWindow() == False : return
535
titledock = str(dock.windowTitle())
536
studyId = sgPyQt.getStudyId()
537
if studyId not in _d_DockWindowsBrowser.keys():
539
for i in range(len(_d_DockWindowsBrowser[studyId])):
540
if titledock in str(_d_DockWindowsBrowser[studyId][i].windowTitle()):
541
_d_DockWindowsBrowser[studyId][i].activateWindow()
542
_d_DockWindowsBrowser[studyId][i].setVisible(True)
543
_d_DockWindowsBrowser[studyId][i].show()
544
_d_DockWindowsBrowser[studyId][i].raise_()
545
self.activateCurrentWindow(titledock)
548
def setdockWindowActivated(self,visible) :
550
if not visible : return
552
if dock.isActiveWindow() == False : return
553
title = str(dock.windowTitle())
554
titledock,br = string.split(title," Browser")
555
studyId = sgPyQt.getStudyId()
556
if studyId not in _d_DockWindowsBrowser.keys():
558
for i in range(len(_d_DockWindows[studyId])):
559
if str(_d_DockWindows[studyId][i].windowTitle()) in str(title):
560
_d_DockWindows[studyId][i].activateWindow()
561
_d_DockWindows[studyId][i].setVisible(True)
562
_d_DockWindows[studyId][i].show()
563
_d_DockWindows[studyId][i].raise_()
564
self.activateCurrentWindow(titledock)
567
def activateCurrentWindow(self,title) :
570
for mw in self._WindowsMap.keys() :
571
casename = mw.case['salome'].GetName()
572
xmlfile = mw.case['xmlfile']
573
if xmlfile == "" or xmlfile == None :
574
xmlfileName = "unnamed"
576
xmlfileName = os.path.basename(xmlfile)
577
fatherCaseName = mw.case['salome'].GetFather().GetName()
578
if title == string.join([fatherCaseName,casename,xmlfileName],".") :
579
self._CurrentWindow = mw
580
if mw not in _selectedMainViewCase :
581
_selectedMainViewCase.append(mw)
585
def disconnectDockWindows(self) :
587
Hide the dock windows of CFDSTUDY GUI, when activating another Salome Component
588
We can have one or several of them with the right click on the main menu bar of
591
studyId = sgPyQt.getStudyId()
592
if studyId not in _d_DockWindowsBrowser.keys():
594
if studyId not in _d_DockWindows.keys():
597
if len(_d_DockWindows[studyId]) != 0 :
598
for dock in _d_DockWindows[studyId]:
601
if len(_d_DockWindowsBrowser[studyId]) != 0 :
602
for dock in _d_DockWindowsBrowser[studyId]:
603
if dock.windowTitle() != 'Object Browser':
605
if studyId not in _d_DockWindowsRuncase.keys():
607
if len(_d_DockWindowsRuncase[studyId]) != 0:
608
for dock in _d_DockWindowsRuncase[studyId]:
612
def connectDockWindows(self) :
614
Show all the dock windows of CFDSTUDY GUI, when activating another Salome Component
615
visualise les dock windows lors d'un changement de composant
617
studyId = sgPyQt.getStudyId()
618
if studyId not in _d_DockWindowsBrowser.keys():
620
if studyId not in _d_DockWindows.keys():
623
if len(_d_DockWindows[studyId]) != 0:
624
for dock in _d_DockWindows[studyId]:
626
dock.setVisible(True)
628
if len(_d_DockWindowsBrowser[studyId]) != 0:
629
for dock in _d_DockWindowsBrowser[studyId]:
631
dock.setVisible(True)
633
if studyId not in _d_DockWindowsRuncase.keys():
635
if len(_d_DockWindowsRuncase[studyId]) != 0:
636
for dock in _d_DockWindowsRuncase[studyId]:
638
dock.setVisible(True)