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
Main file of the CFD_STUDY module. Defines the standard SALOME callback.
32
#-------------------------------------------------------------------------------
34
#-------------------------------------------------------------------------------
39
#-------------------------------------------------------------------------------
41
#-------------------------------------------------------------------------------
43
from PyQt4.QtGui import QApplication, QCursor, QDialog, QMessageBox, QDockWidget
44
from PyQt4.QtCore import Qt, QObject, QVariant, SIGNAL
46
#-------------------------------------------------------------------------------
48
#-------------------------------------------------------------------------------
50
from SalomePyQt import WT_ObjectBrowser, WT_PyConsole, WT_LogWindow
52
import SALOMEDS_Attributes_idl
54
#-------------------------------------------------------------------------------
56
#-------------------------------------------------------------------------------
58
import CFDSTUDYGUI_ActionsHandler
59
import CFDSTUDYGUI_DataModel
60
import CFDSTUDYGUI_Commons
61
import CFDSTUDYGUI_DesktopMgr
63
from CFDSTUDYGUI_Commons import CFD_Code, sg, sgPyQt
64
from CFDSTUDYGUI_Commons import CFD_Saturne, CFD_Neptune
65
from CFDSTUDYGUI_Commons import CheckCFD_CodeEnv
67
#-------------------------------------------------------------------------------
69
#-------------------------------------------------------------------------------
72
log = logging.getLogger("CFDSTUDYGUI")
73
log.setLevel(logging.DEBUG)
74
#log.setLevel(logging.NOTSET)
76
#-------------------------------------------------------------------------------
78
#-------------------------------------------------------------------------------
83
# Desktop manager: instance of CFDSTUDYGUI_DesktopMgr class to store the SALOME Workspace
84
_DesktopMgr = CFDSTUDYGUI_DesktopMgr.CFDSTUDYGUI_DesktopMgr()
86
# ObjectTR is a convenient object for traduction purpose
89
#-------------------------------------------------------------------------------
90
# Callback GUI functions
91
#-------------------------------------------------------------------------------
95
This method is called when GUI module is being created and initialized.
98
log.debug("initialize")
104
This method is called when GUI module is being created
106
Should return a layout of the SALOME dockable windows id's
107
needed to be opened when module is activated.
109
@return: layout of the SALOME dockable windows
110
@rtype: C{Dictionary}
115
winMap[ WT_ObjectBrowser ] = Qt.LeftDockWidgetArea
116
winMap[ WT_PyConsole ] = Qt.BottomDockWidgetArea
117
winMap[ WT_LogWindow ] = Qt.BottomDockWidgetArea
124
This method is called when GUI module is being created and initialized.
125
Should return a list of the SALOME view window types
126
needed to be opened when module is activated.
127
cf. SALOME_PYQT_Module.cxx : PyObjWrapper
129
@return: list of the SALOME view window types
130
@rtype: C{String} or C{list} of C{String}
133
winList = "VTKViewer"
134
#winList = "OCCViewer"
141
def setWorkSpace(ws):
143
Stores the SALOME Workspace I{ws} into the Desktop Manager.
146
@param ws: main window's central widget
148
log.debug("setWorkSpace")
150
dsk = sgPyQt.getDesktop()
151
_DesktopMgr.setWorkspace(dsk, ws)
154
def createPreferences():
156
Manages the preferences QDialog of the module.
158
log.debug("createPreferences")
159
sgPyQt = CFDSTUDYGUI_DataModel.sgPyQt
160
tabId = sgPyQt.addPreference(ObjectTR.tr("CFDSTUDY_PREF_TAB"))
161
genGroup = sgPyQt.addPreference(ObjectTR.tr("CFDSTUDY_PREF_GEN_GROUP"), tabId)
162
sgPyQt.setPreferenceProperty(genGroup, "columns", QVariant(1))
164
sgPyQt.addPreference(ObjectTR.tr("CFDSTUDY_PREF_EDITOR"), genGroup, 3, "CFDSTUDY", "Editor")
165
sgPyQt.addPreference(ObjectTR.tr("CFDSTUDY_PREF_READER"), genGroup, 3, "CFDSTUDY", "Reader")
166
sgPyQt.addPreference(ObjectTR.tr("CFDSTUDY_PREF_DIFF" ), genGroup, 3, "CFDSTUDY", "Tool_for_diff")
167
sgPyQt.addPreference(ObjectTR.tr("CFDSTUDY_PREF_DISPLAY"), genGroup, 3, "CFDSTUDY", "Display")
169
genGroup = sgPyQt.addPreference(ObjectTR.tr("CFDSTUDY_PREF_ENV_GROUP"), tabId)
170
sgPyQt.setPreferenceProperty(genGroup, "columns", QVariant(1))
175
This method is called when GUI module is being activated.
177
@rtype: C{True} or C{False}
178
@return: C{True} only if the activation is successful.
180
log.debug("activate")
181
global d_activation, studyId
183
dsk = sgPyQt.getDesktop()
184
studyId = sgPyQt.getStudyId()
185
# instance of the CFDSTUDYGUI_ActionsHandler class for the current desktop
186
ActionHandler = _DesktopMgr.getActionHandler(dsk)
188
if studyId not in d_activation.keys():
189
d_activation[studyId] = 1
191
if d_activation[studyId] == 1:
192
d_activation[studyId] = 0
193
env_saturne = CheckCFD_CodeEnv(CFD_Saturne)
194
env_neptune = CheckCFD_CodeEnv(CFD_Neptune)
196
#log.debug("activate -> env_saturne = %s" % env_saturne)
197
#log.debug("activate -> env_neptune = %s" % env_neptune)
199
if not env_saturne and not env_neptune:
200
mess = ObjectTR.tr("CFDSTUDY_INVALID_ENV")
201
QMessageBox.critical(ActionHandler.dskAgent().workspace(),
202
"Error", mess, QMessageBox.Ok, 0)
204
d_activation[studyId] = 1
207
ActionHandler.DialogCollector.InfoDialog.setCode(CFD_Saturne, True)
209
ActionHandler.DialogCollector.InfoDialog.setCode(CFD_Neptune, True)
211
ActionHandler.DialogCollector.InfoDialog.exec_()
213
if not ActionHandler.DialogCollector.InfoDialog.result() == QDialog.Accepted:
214
d_activation[studyId] = 1
217
ActionHandler.connect(ActionHandler._SalomeSelection,
218
SIGNAL('currentSelectionChanged()'),
219
ActionHandler.updateActions)
221
ActionHandler.connectSolverGUI()
222
ActionHandler.updateObjBrowser()
224
# Hide the Python Console window layout
225
dsk = sgPyQt.getDesktop()
226
ldockWindows = dsk.findChildren(QDockWidget)
227
for dock in ldockWindows:
228
dockTitle = dock.windowTitle()
229
if str(dockTitle) == "Python Console":
230
dock.setVisible(False)
237
Stores the selected CFD code and updates action according with current
238
selection and study states in the dekstop manager.
240
log.debug("setSettings")
242
dsk = sgPyQt.getDesktop()
243
ActionHandler = _DesktopMgr.getActionHandler(dsk)
244
ActionHandler.onCFDCode()
245
ActionHandler.updateActions()
250
This method is called when GUI module is being deactivated.
252
log.debug("deactivate")
253
dsk = sgPyQt.getDesktop()
254
ActionHandler = _DesktopMgr.getActionHandler(dsk)
255
ActionHandler.disconnect(ActionHandler._SalomeSelection, SIGNAL('currentSelectionChanged()'), ActionHandler.updateActions)
256
ActionHandler.disconnectSolverGUI()
259
def createPopupMenu(popup, context):
261
This method is called when popup menu is requested by the user (right click).
262
Should analyze the selection and fill in the popup menu with the corresponding actions.
264
@type popup: C{QPopupMenu}
265
@param popup: popup menu from the Object Browser.
266
@type context: C{String}
267
@param context: equal to 'ObjectBrowser' or 'VTKViewer' for example.
269
log.debug("createPopupMenu -> context = %s" % context)
271
study = CFDSTUDYGUI_DataModel._getStudy()
272
dsk = sgPyQt.getDesktop()
273
ActionHandler = _DesktopMgr.getActionHandler(dsk)
275
log.debug("createPopupMenu -> SelectedCount = %s" % sg.SelectedCount())
279
if sg.SelectedCount() <= 0:
281
elif sg.SelectedCount() == 1:
282
entry = sg.getSelected(0)
284
sobj = study.FindObjectID(entry)
286
test, anAttr = sobj.FindAttribute("AttributeLocalID")
288
id = anAttr._narrow(SALOMEDS.AttributeLocalID).Value()
290
ActionHandler.customPopup(id, popup)
291
if CFDSTUDYGUI_DataModel.isLinkPathObject(sobj):
292
popup.removeAction(ActionHandler.commonAction(CFDSTUDYGUI_ActionsHandler.EditAction))
293
popup.removeAction(ActionHandler.commonAction(CFDSTUDYGUI_ActionsHandler.MoveToDRAFTAction))
294
popup.removeAction(ActionHandler.commonAction(CFDSTUDYGUI_ActionsHandler.CopyCaseFileAction))
301
# #check for Pre MED files multi selection
302
# while index < sg.SelectedCount() and flag :
303
# sobj = study.FindObjectID(sg.getSelected(index))
304
# flag = CFDSTUDYGUI_DataModel.checkPreMEDType(sobj)
311
# #add MED conversion to popup
312
# popup.addAction(ActionHandler.commonAction(CFDSTUDYGUI_ActionsHandler.ECSConvertAction))
315
#add Display Mesh group to popup
317
for i in range(sg.SelectedCount()):
318
entry = sg.getSelected(i)
320
sobj = study.FindObjectID(entry)
322
test, anAttr = sobj.FindAttribute("AttributeLocalID")
324
id = anAttr._narrow(SALOMEDS.AttributeLocalID).Value()
325
if id != CFDSTUDYGUI_DataModel.dict_object["PublishedMeshGroupIntoObjectBrowser"]:
331
if id_flag == CFDSTUDYGUI_DataModel.dict_object["PublishedMeshGroupIntoObjectBrowser"]:
332
ActionHandler.customPopup(id, popup)
333
popup.removeAction(ActionHandler.commonAction(CFDSTUDYGUI_ActionsHandler.DisplayOnlyGroupMESHAction))
335
if context == "VTKViewer":
336
if id_flag == CFDSTUDYGUI_DataModel.dict_object["PublishedMeshGroupIntoObjectBrowser"]:
337
ActionHandler.customPopup("VTKViewer", popup)
346
# Stores the SALOME desktop (i.e. C{QMainWindow}) in the dekstop manager.
348
# log.debug("processMgr")
349
# dsk = sgPyQt.getDesktop()
350
# return _DesktopMgr.getProcessMgr(dsk)