Salome HOME
Updating copyright date information and version
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / adaoGuiHelper.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008-2015 EDF R&D
3 #
4 # This file is part of SALOME ADAO module
5 #
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.
10 #
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.
15 #
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
19 #
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22
23 __author__="aribes/gboulant"
24
25 import salome
26 # Get SALOME PyQt interface
27 import SalomePyQt
28 __sgPyQt = SalomePyQt.SalomePyQt()
29
30 import adaoModuleHelper
31 from PyQt4 import QtGui,QtCore
32
33 def waitCursor():
34     QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
35
36 def restoreCursor():
37     QtGui.QApplication.restoreOverrideCursor()
38
39 def gui_warning(parent, msg="An error occurs" ):
40     """
41     This function displays a message dialog box displaying the specified message.
42     """
43     QtGui.QMessageBox.warning( parent, "Alerte", msg)
44
45 def getActiveStudyId():
46     """
47     This function returns the id of the active study. The concept of active study
48     makes sens only in the GUI context.
49     """
50     return salome.sg.getActiveStudyId()
51
52 def refreshObjectBrowser():
53     """
54     Refresh the graphical representation of the SALOME study, in case where the
55     GUI is working.
56     """
57     if salome.sg is not None:
58         salome.sg.updateObjBrowser(0)
59
60 def selectItem(salomeStudyItem):
61   if salome.sg is not None:
62     salome.sg.ClearIObjects()
63     salome.sg.AddIObject(salomeStudyItem)
64
65 def getSelectedItem(salomeStudyId=-100):
66     """
67     Get the current selection. If more than one item are selected, the
68     only first is considered. The object is return (not the id).
69     The item can be of any type, no control is done in this function.
70     """
71     if salome.sg is None:
72         raise Exception("GuiHelper.getSelectedItem can't be used without the GUI context")
73
74     if salomeStudyId != -100:
75       studyEditor = salome.kernel.studyedit.getStudyEditor(salomeStudyId)
76     studyEditor = salome.kernel.studyedit.getStudyEditor()
77     item = None
78     listEntries=salome.sg.getAllSelected()
79     if len(listEntries) >= 1:
80         entry = listEntries[0]
81         item = studyEditor.study.FindObjectID( entry )
82     return item
83
84 def getAllSelected(salomeStudyId):
85     """
86     Returns all selected items in the specified study.
87     """
88     if salome.sg is None:
89         raise OmaException("getSelectedItem can't be used without the GUI context", OmaException.TYPES.DEVEL)
90
91     study = adaoModuleHelper.getStudyManager().GetStudyByID( salomeStudyId )
92     selcount = salome.sg.SelectedCount()
93     seltypes = {}
94     for i in range( selcount ):
95         __incObjToMap( seltypes, adaoModuleHelper.getObjectID( study, salome.sg.getSelected( i ) ) )
96         pass
97     return selcount, seltypes
98
99 def __incObjToMap( m, id ):
100     """
101     Increment object counter in the specified map.
102     Not to be used outside this module.
103     """
104     if id not in m: m[id] = 0
105     m[id] += 1
106     pass
107
108 def getDesktop():
109     """
110     Returns the active Desktop. Usefull to set the relative position of a dialog box
111     """
112     return __sgPyQt.getDesktop()
113
114 def warning(msg):
115     """
116     This function displays a message dialog box displaying the specified message.
117     """
118     gui_warning(getDesktop(),msg)