~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to salome/cfd_study/src/CFDSTUDYGUI/CFDSTUDYGUI.py

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
#-------------------------------------------------------------------------------
 
4
 
 
5
# This file is part of Code_Saturne, a general-purpose CFD tool.
 
6
#
 
7
# Copyright (C) 1998-2011 EDF S.A.
 
8
#
 
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
 
12
# version.
 
13
#
 
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
 
17
# details.
 
18
#
 
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.
 
22
 
 
23
#-------------------------------------------------------------------------------
 
24
 
 
25
"""
 
26
CFDSTUDY
 
27
========
 
28
 
 
29
Main file of the CFD_STUDY module. Defines the standard SALOME callback.
 
30
"""
 
31
 
 
32
#-------------------------------------------------------------------------------
 
33
# Standard modules
 
34
#-------------------------------------------------------------------------------
 
35
 
 
36
import os
 
37
import logging
 
38
 
 
39
#-------------------------------------------------------------------------------
 
40
# Third-party modules
 
41
#-------------------------------------------------------------------------------
 
42
 
 
43
from PyQt4.QtGui import QApplication, QCursor, QDialog, QMessageBox, QDockWidget
 
44
from PyQt4.QtCore import Qt, QObject, QVariant, SIGNAL
 
45
 
 
46
#-------------------------------------------------------------------------------
 
47
# Salome modules
 
48
#-------------------------------------------------------------------------------
 
49
 
 
50
from SalomePyQt import WT_ObjectBrowser, WT_PyConsole, WT_LogWindow
 
51
import SALOMEDS
 
52
import SALOMEDS_Attributes_idl
 
53
 
 
54
#-------------------------------------------------------------------------------
 
55
# Application modules
 
56
#-------------------------------------------------------------------------------
 
57
 
 
58
import CFDSTUDYGUI_ActionsHandler
 
59
import CFDSTUDYGUI_DataModel
 
60
import CFDSTUDYGUI_Commons
 
61
import CFDSTUDYGUI_DesktopMgr
 
62
 
 
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
 
66
 
 
67
#-------------------------------------------------------------------------------
 
68
# log config
 
69
#-------------------------------------------------------------------------------
 
70
 
 
71
logging.basicConfig()
 
72
log = logging.getLogger("CFDSTUDYGUI")
 
73
log.setLevel(logging.DEBUG)
 
74
#log.setLevel(logging.NOTSET)
 
75
 
 
76
#-------------------------------------------------------------------------------
 
77
# Global definitions
 
78
#-------------------------------------------------------------------------------
 
79
 
 
80
studyId = 1
 
81
d_activation = {}
 
82
 
 
83
# Desktop manager: instance of CFDSTUDYGUI_DesktopMgr class to store the SALOME Workspace
 
84
_DesktopMgr = CFDSTUDYGUI_DesktopMgr.CFDSTUDYGUI_DesktopMgr()
 
85
 
 
86
# ObjectTR is a convenient object for traduction purpose
 
87
ObjectTR = QObject()
 
88
 
 
89
#-------------------------------------------------------------------------------
 
90
# Callback GUI functions
 
91
#-------------------------------------------------------------------------------
 
92
 
 
93
def initialize():
 
94
    """
 
95
    This method is called when GUI module is being created and initialized.
 
96
    """
 
97
    # nothing to do here.
 
98
    log.debug("initialize")
 
99
    pass
 
100
 
 
101
 
 
102
def windows():
 
103
    """
 
104
    This method is called when GUI module is being created
 
105
    and initialized.
 
106
    Should return a layout of the SALOME dockable windows id's
 
107
    needed to be opened when module is activated.
 
108
 
 
109
    @return: layout of the SALOME dockable windows
 
110
    @rtype: C{Dictionary}
 
111
    """
 
112
    log.debug("windows")
 
113
 
 
114
    winMap = {}
 
115
    winMap[ WT_ObjectBrowser ] = Qt.LeftDockWidgetArea
 
116
    winMap[ WT_PyConsole ]     = Qt.BottomDockWidgetArea
 
117
    winMap[ WT_LogWindow ]     = Qt.BottomDockWidgetArea
 
118
 
 
119
    return winMap
 
120
 
 
121
 
 
122
def views():
 
123
    """
 
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
 
128
 
 
129
    @return: list of the SALOME view window types
 
130
    @rtype: C{String} or C{list} of C{String}
 
131
    """
 
132
    log.debug("views")
 
133
    winList = "VTKViewer"
 
134
    #winList = "OCCViewer"
 
135
    #winList = "Plot2d"
 
136
 
 
137
    #winList = ""
 
138
    return winList
 
139
 
 
140
 
 
141
def setWorkSpace(ws):
 
142
    """
 
143
    Stores the SALOME Workspace I{ws} into the Desktop Manager.
 
144
 
 
145
    @type ws: C{QWidget}
 
146
    @param ws: main window's central widget
 
147
    """
 
148
    log.debug("setWorkSpace")
 
149
 
 
150
    dsk = sgPyQt.getDesktop()
 
151
    _DesktopMgr.setWorkspace(dsk, ws)
 
152
 
 
153
 
 
154
def createPreferences():
 
155
    """
 
156
    Manages the preferences QDialog of the module.
 
157
    """
 
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))
 
163
 
 
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")
 
168
 
 
169
    genGroup = sgPyQt.addPreference(ObjectTR.tr("CFDSTUDY_PREF_ENV_GROUP"), tabId)
 
170
    sgPyQt.setPreferenceProperty(genGroup, "columns", QVariant(1))
 
171
 
 
172
 
 
173
def activate():
 
174
    """
 
175
    This method is called when GUI module is being activated.
 
176
 
 
177
    @rtype: C{True} or C{False}
 
178
    @return: C{True} only if the activation is successful.
 
179
    """
 
180
    log.debug("activate")
 
181
    global d_activation, studyId
 
182
 
 
183
    dsk = sgPyQt.getDesktop()
 
184
    studyId = sgPyQt.getStudyId()
 
185
    # instance of the CFDSTUDYGUI_ActionsHandler class for the current desktop
 
186
    ActionHandler = _DesktopMgr.getActionHandler(dsk)
 
187
 
 
188
    if studyId not in d_activation.keys():
 
189
        d_activation[studyId] = 1
 
190
 
 
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)
 
195
 
 
196
        #log.debug("activate -> env_saturne = %s" % env_saturne)
 
197
        #log.debug("activate -> env_neptune = %s" % env_neptune)
 
198
 
 
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)
 
203
 
 
204
            d_activation[studyId] = 1
 
205
            return False
 
206
        elif env_saturne:
 
207
            ActionHandler.DialogCollector.InfoDialog.setCode(CFD_Saturne, True)
 
208
        elif env_neptune:
 
209
            ActionHandler.DialogCollector.InfoDialog.setCode(CFD_Neptune, True)
 
210
 
 
211
        ActionHandler.DialogCollector.InfoDialog.exec_()
 
212
 
 
213
        if not ActionHandler.DialogCollector.InfoDialog.result() == QDialog.Accepted:
 
214
            d_activation[studyId] = 1
 
215
            return False
 
216
 
 
217
    ActionHandler.connect(ActionHandler._SalomeSelection,
 
218
                          SIGNAL('currentSelectionChanged()'),
 
219
                          ActionHandler.updateActions)
 
220
 
 
221
    ActionHandler.connectSolverGUI()
 
222
    ActionHandler.updateObjBrowser()
 
223
 
 
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)
 
231
 
 
232
    return True
 
233
 
 
234
 
 
235
def setSettings():
 
236
    """
 
237
    Stores the selected CFD code and updates action according with current
 
238
    selection and study states in the dekstop manager.
 
239
    """
 
240
    log.debug("setSettings")
 
241
 
 
242
    dsk = sgPyQt.getDesktop()
 
243
    ActionHandler = _DesktopMgr.getActionHandler(dsk)
 
244
    ActionHandler.onCFDCode()
 
245
    ActionHandler.updateActions()
 
246
 
 
247
 
 
248
def deactivate():
 
249
    """
 
250
    This method is called when GUI module is being deactivated.
 
251
    """
 
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()
 
257
 
 
258
 
 
259
def createPopupMenu(popup, context):
 
260
    """
 
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.
 
263
 
 
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.
 
268
    """
 
269
    log.debug("createPopupMenu -> context = %s" % context)
 
270
 
 
271
    study = CFDSTUDYGUI_DataModel._getStudy()
 
272
    dsk = sgPyQt.getDesktop()
 
273
    ActionHandler = _DesktopMgr.getActionHandler(dsk)
 
274
 
 
275
    log.debug("createPopupMenu -> SelectedCount = %s" % sg.SelectedCount())
 
276
 
 
277
    id_flag = 0
 
278
 
 
279
    if sg.SelectedCount() <= 0:
 
280
        return
 
281
    elif sg.SelectedCount() == 1:
 
282
        entry = sg.getSelected(0)
 
283
        if entry != '':
 
284
            sobj = study.FindObjectID(entry)
 
285
            if sobj is not None:
 
286
                test, anAttr = sobj.FindAttribute("AttributeLocalID")
 
287
                if test:
 
288
                    id = anAttr._narrow(SALOMEDS.AttributeLocalID).Value()
 
289
                    if id >= 0:
 
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))
 
295
                    id_flag = id
 
296
 
 
297
    else:
 
298
#        flag = True
 
299
#        index = 0
 
300
 
 
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)
 
305
#            index += 1
 
306
#
 
307
#        if not flag:
 
308
#            return
 
309
#
 
310
#        if flag:
 
311
#            #add MED conversion to popup
 
312
#            popup.addAction(ActionHandler.commonAction(CFDSTUDYGUI_ActionsHandler.ECSConvertAction))
 
313
#            return
 
314
 
 
315
        #add Display Mesh group to popup
 
316
 
 
317
        for i in range(sg.SelectedCount()):
 
318
            entry = sg.getSelected(i)
 
319
            if entry != '':
 
320
                sobj = study.FindObjectID(entry)
 
321
                if sobj is not None:
 
322
                    test, anAttr = sobj.FindAttribute("AttributeLocalID")
 
323
                    if test:
 
324
                        id = anAttr._narrow(SALOMEDS.AttributeLocalID).Value()
 
325
                        if id != CFDSTUDYGUI_DataModel.dict_object["PublishedMeshGroupIntoObjectBrowser"]:
 
326
                            id_flag = 0
 
327
                            break
 
328
                        else:
 
329
                            id_flag = id
 
330
 
 
331
            if id_flag == CFDSTUDYGUI_DataModel.dict_object["PublishedMeshGroupIntoObjectBrowser"]:
 
332
                ActionHandler.customPopup(id, popup)
 
333
                popup.removeAction(ActionHandler.commonAction(CFDSTUDYGUI_ActionsHandler.DisplayOnlyGroupMESHAction))
 
334
 
 
335
    if context == "VTKViewer":
 
336
        if id_flag == CFDSTUDYGUI_DataModel.dict_object["PublishedMeshGroupIntoObjectBrowser"]:
 
337
            ActionHandler.customPopup("VTKViewer", popup)
 
338
 
 
339
 
 
340
 
 
341
 
 
342
 
 
343
# TODELETE
 
344
#def processMgr():
 
345
#    """
 
346
#    Stores the SALOME desktop (i.e. C{QMainWindow}) in the dekstop manager.
 
347
#    """
 
348
#    log.debug("processMgr")
 
349
#    dsk = sgPyQt.getDesktop()
 
350
#    return _DesktopMgr.getProcessMgr(dsk)