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

« back to all changes in this revision

Viewing changes to gui/Pages/MatisseHydrauView.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: iso-8859-1 -*-
2
 
#
3
 
#-------------------------------------------------------------------------------
4
 
#
5
 
#     This file is part of the Code_Saturne User Interface, element of the
6
 
#     Code_Saturne CFD tool.
7
 
#
8
 
#     Copyright (C) 1998-2009 EDF S.A., France
9
 
#
10
 
#     contact: saturne-support@edf.fr
11
 
#
12
 
#     The Code_Saturne User Interface is free software; you can redistribute it
13
 
#     and/or modify it under the terms of the GNU General Public License
14
 
#     as published by the Free Software Foundation; either version 2 of
15
 
#     the License, or (at your option) any later version.
16
 
#
17
 
#     The Code_Saturne User Interface is distributed in the hope that it will be
18
 
#     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
19
 
#     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 
#     GNU General Public License for more details.
21
 
#
22
 
#     You should have received a copy of the GNU General Public License
23
 
#     along with the Code_Saturne Kernel; if not, write to the
24
 
#     Free Software Foundation, Inc.,
25
 
#     51 Franklin St, Fifth Floor,
26
 
#     Boston, MA  02110-1301  USA
27
 
#
28
 
#-------------------------------------------------------------------------------
29
 
 
30
 
"""
31
 
This module contains the following classes and function:
32
 
- MatisseHydrauView
33
 
"""
34
 
 
35
 
#-------------------------------------------------------------------------------
36
 
# Standard modules
37
 
#-------------------------------------------------------------------------------
38
 
 
39
 
import logging
40
 
 
41
 
#-------------------------------------------------------------------------------
42
 
# Third-party modules
43
 
#-------------------------------------------------------------------------------
44
 
 
45
 
from PyQt4.QtCore import *
46
 
from PyQt4.QtGui  import *
47
 
 
48
 
#-------------------------------------------------------------------------------
49
 
# Application modules import
50
 
#-------------------------------------------------------------------------------
51
 
 
52
 
from Base.Toolbox import GuiParam
53
 
from MatisseHydrauForm import Ui_MatisseHydrauForm
54
 
import Base.QtPage as QtPage
55
 
import Pages.MatisseTypeModel as MatisseType
56
 
from MatisseHydrauModel import MatisseHydrauModel
57
 
 
58
 
#-------------------------------------------------------------------------------
59
 
# log config
60
 
#-------------------------------------------------------------------------------
61
 
 
62
 
logging.basicConfig()
63
 
log = logging.getLogger("MatisseHydrauView")
64
 
log.setLevel(GuiParam.DEBUG)
65
 
 
66
 
#-------------------------------------------------------------------------------
67
 
# Model class
68
 
#-------------------------------------------------------------------------------
69
 
 
70
 
class StandardItemModelHydrau(QStandardItemModel):
71
 
 
72
 
    def __init__(self, case):
73
 
        """
74
 
        """
75
 
        QStandardItemModel.__init__(self)
76
 
 
77
 
        self.case = case
78
 
        self.model = MatisseHydrauModel(self.case)
79
 
        self.model_mat_type = MatisseType.MatisseTypeModel(self.case)
80
 
 
81
 
        self.setColumnCount(4)
82
 
        self._initData()
83
 
 
84
 
 
85
 
    def _initData(self):
86
 
 
87
 
        # String Var
88
 
        self.icofor = ""
89
 
        self.iconlg = ""
90
 
 
91
 
        #
92
 
        # Double Var
93
 
        self.debmas = 0.
94
 
        self.pdccha = 0.
95
 
        self.pdcfch = 0.
96
 
        self.dhchea = 0.
97
 
        self.sdchea = 0.
98
 
        self.pdcche = 0.
99
 
        self.pdccch = 0.
100
 
        self.dhches = 0.
101
 
        self.sdches = 0.
102
 
        self.pdcalg = 0.
103
 
        self.pdcatv = 0.
104
 
        self.argamt = 0.
105
 
        self.pdcslg = 0.
106
 
        self.pdcstv = 0.
107
 
        self.argavl = 0.
108
 
        self.amppdc = 0.
109
 
        self.dhalve = 0.
110
 
        self.dpvent = 0.
111
 
 
112
 
        # association between variables and tag
113
 
 
114
 
        self.variables = [
115
 
            ['icofor', self.icofor],
116
 
            ['iconlg', self.iconlg],
117
 
            ['debmas', self.debmas],
118
 
            ['pdccha', self.pdccha],
119
 
            ['pdcfch', self.pdcfch],
120
 
            ['dhchea', self.dhchea],
121
 
            ['sdchea', self.sdchea],
122
 
            ['pdcche', self.pdcche],
123
 
            ['pdccch', self.pdccch],
124
 
            ['dhches', self.dhches],
125
 
            ['sdches', self.sdches],
126
 
            ['pdcalg', self.pdcalg],
127
 
            ['pdcatv', self.pdcatv],
128
 
            ['argamt', self.argamt],
129
 
            ['pdcslg', self.pdcslg],
130
 
            ['pdcstv', self.pdcstv],
131
 
            ['argavl', self.argavl],
132
 
            ['amppdc', self.amppdc],
133
 
            ['dhalve', self.dhalve],
134
 
            ['dpvent', self.dpvent]]
135
 
 
136
 
        self.texts = {}
137
 
        self.texts['icofor'] = (1,  self.tr("Forced hydraulic air circulation regime"))
138
 
        self.texts['iconlg'] = (2,  self.tr("Canister network in row (staggered arrangement otherwise)"))
139
 
        self.texts['debmas'] = (3,  self.tr("Forced circulation air flow"), "Kg/s")
140
 
        self.texts['pdccha'] = (4,  self.tr("Inlet chimney diffuser headloss"))
141
 
        self.texts['pdcfch'] = (5,  self.tr("Inlet chimney filter headloss"))
142
 
        self.texts['dhchea'] = (6,  self.tr("Inlet chimney hydraulic diameter"), "m")
143
 
        self.texts['sdchea'] = (7,  self.tr("Inlet chimney flow area"), "m<sup>2</sup>")
144
 
        self.texts['pdcche'] = (8,  self.tr("Outlet chimney diffuser headloss"))
145
 
        self.texts['pdccch'] = (9,  self.tr("Outlet chimney valve headloss"))
146
 
        self.texts['dhches'] = (10, self.tr("Outlet chimney hydraulic diameter"), "m")
147
 
        self.texts['sdches'] = (11, self.tr("Outlet chimney flow area"), "m<sup>2</sup>")
148
 
        self.texts['pdcalg'] = (12, self.tr("Upstream inlet door longitudinal headloss"))
149
 
        self.texts['pdcatv'] = (13, self.tr("Upstream inlet door transversal headloss"))
150
 
        self.texts['argamt'] = (14, self.tr("Upstream register incline angle (degree)"), "<sup>o</sup>")
151
 
        self.texts['pdcslg'] = (16, self.tr("Downstream outlet door longitudinal headloss"))
152
 
        self.texts['pdcstv'] = (17, self.tr("Downstream outlet door transversal headloss"))
153
 
        self.texts['argavl'] = (18, self.tr("Downstream register incline angle (degree)"), "<sup>o</sup>")
154
 
        self.texts['amppdc'] = (20, self.tr("Network headloss amplifying factor"))
155
 
        self.texts['dhalve'] = (23, self.tr("Double jacketed wells hydraulic diameter"), "m")
156
 
        self.texts['dpvent'] = (24, self.tr("Inlet/outlet atmospheric pressure difference"), "Pa")
157
 
 
158
 
        self.rows_disabled = []
159
 
 
160
 
        stat = self.model.getConstrainedConvStatus()
161
 
        self.icofor = stat
162
 
        if not 2 in self.rows_disabled and stat == "off":
163
 
            self.rows_disabled.append(2)
164
 
 
165
 
        stat = self.model.getInlineContainerNetworkStatus()
166
 
        self.iconlg = stat
167
 
 
168
 
        i = 0
169
 
        for variable in self.variables :
170
 
            if variable[0] not in ['icofor', 'iconlg']:
171
 
                val = self.model.getMatisseHydrauDoubleVar(variable[0])
172
 
                self.variables[i][1] = val
173
 
 
174
 
                if variable[0] == 'dhalve' :
175
 
                    stat = self.model_mat_type.node_alveo['status']
176
 
                    if not i in self.rows_disabled and stat == "off":
177
 
                        self.rows_disabled.append(i)
178
 
            i += 1
179
 
 
180
 
        self.setRowCount(len(self.variables))
181
 
 
182
 
 
183
 
    def data(self, index, role):
184
 
 
185
 
        if not index.isValid():
186
 
            return QVariant()
187
 
 
188
 
        if role == Qt.DisplayRole:
189
 
            row = index.row()
190
 
 
191
 
            if index.column() == 0:
192
 
                var = self.variables[row][0]
193
 
                num = self.texts[var][0]
194
 
                return QVariant(num)
195
 
 
196
 
            if index.column() == 1:
197
 
                var = self.variables[row][0]
198
 
                txt = self.texts[var][1]
199
 
                return QVariant(txt)
200
 
 
201
 
            if index.column() == 2:
202
 
                var = self.variables[row][0]
203
 
                val = self.variables[row][1]
204
 
                return QVariant(val)
205
 
 
206
 
            if index.column() == 3:
207
 
                var = self.variables[row][0]
208
 
                if len(self.texts[var])>2:
209
 
                    unit = self.texts[var][2]
210
 
                else:
211
 
                    unit = ""
212
 
                return QVariant(unit)
213
 
 
214
 
        if role == Qt.CheckStateRole:
215
 
 
216
 
            if index.row() == 0 and index.column() == 2:
217
 
                if self.icofor == "on":
218
 
                    return QVariant(Qt.Checked)
219
 
                else:
220
 
                    return QVariant(Qt.Unchecked)
221
 
 
222
 
            if index.row() == 1 and index.column() == 2:
223
 
                if self.iconlg == "on":
224
 
                    return QVariant(Qt.Checked)
225
 
                else:
226
 
                    return QVariant(Qt.Unchecked)
227
 
 
228
 
        return QVariant()
229
 
 
230
 
 
231
 
    def flags(self, index):
232
 
        if not index.isValid():
233
 
            return Qt.ItemIsEnabled
234
 
        if index.row() in self.rows_disabled:
235
 
            return Qt.ItemIsSelectable
236
 
        if index.row() in [0,1] and index.column()== 2:
237
 
            return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable
238
 
        if index.column() in [0,1,3]:
239
 
            return Qt.ItemIsEnabled | Qt.ItemIsSelectable
240
 
        else:
241
 
            return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable
242
 
 
243
 
 
244
 
    def setData(self, index, value, role):
245
 
 
246
 
        if index.column() == 2:
247
 
 
248
 
            if index.row() == 0: # icofor
249
 
                v, ok = value.toInt()
250
 
                if v == Qt.Unchecked:
251
 
                    self.icofor = "off"
252
 
                    if not 2 in self.rows_disabled:
253
 
                        self.rows_disabled.append(2)
254
 
                else:
255
 
                    self.icofor = "on"
256
 
                    if 2 in self.rows_disabled:
257
 
                        self.rows_disabled.remove(2)
258
 
                self.model.setConstrainedConvStatus(self.icofor)
259
 
 
260
 
            elif index.row() == 1: # iconlg
261
 
                v, ok = value.toInt()
262
 
                if v == Qt.Unchecked:
263
 
                    self.iconlg = "off"
264
 
                else:
265
 
                    self.iconlg = "on"
266
 
                self.model.setInlineContainerNetworkStatus(self.iconlg)
267
 
 
268
 
            else:
269
 
                tag = self.variables[index.row()][0]
270
 
                num = self.texts[tag][0]
271
 
                var = self.variables[index.row()][1]
272
 
                v, ok = value.toDouble()
273
 
                var = v
274
 
                self.model.setMatisseHydrauVar(num, v) # ???
275
 
 
276
 
        self.emit(SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"), index, index)
277
 
        return True
278
 
 
279
 
 
280
 
#-------------------------------------------------------------------------------
281
 
# Main class
282
 
#-------------------------------------------------------------------------------
283
 
 
284
 
class MatisseHydrauView(QWidget, Ui_MatisseHydrauForm):
285
 
    """
286
 
    """
287
 
 
288
 
    def __init__(self, parent, case):
289
 
        """
290
 
        Constructor
291
 
        """
292
 
        QWidget.__init__(self, parent)
293
 
 
294
 
        Ui_MatisseHydrauForm.__init__(self)
295
 
        self.setupUi(self)
296
 
 
297
 
        self.case = case
298
 
 
299
 
 
300
 
        # Create the Page layout.
301
 
 
302
 
        self.modelHydrau = StandardItemModelHydrau(self.case)
303
 
        self.tableView.setModel(self.modelHydrau)
304
 
        self.tableView.setAlternatingRowColors(True)
305
 
        self.tableView.resizeColumnsToContents()
306
 
        self.tableView.setShowGrid(False)
307
 
 
308
 
 
309
 
    def tr(self, text):
310
 
        """
311
 
        Translation
312
 
        """
313
 
        return text
314
 
 
315
 
 
316
 
#-------------------------------------------------------------------------------
317
 
# Testing part
318
 
#-------------------------------------------------------------------------------
319
 
 
320
 
 
321
 
if __name__ == "__main__":
322
 
    pass
323
 
 
324
 
 
325
 
#-------------------------------------------------------------------------------
326
 
# End
327
 
#-------------------------------------------------------------------------------
 
 
b'\\ No newline at end of file'