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

« back to all changes in this revision

Viewing changes to gui/Pages/MatisseCustomView.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
 
- MatisseCustomView
33
 
"""
34
 
 
35
 
#-------------------------------------------------------------------------------
36
 
# Standard modules
37
 
#-------------------------------------------------------------------------------
38
 
 
39
 
import string
40
 
import logging
41
 
 
42
 
#-------------------------------------------------------------------------------
43
 
# Third-party modules
44
 
#-------------------------------------------------------------------------------
45
 
 
46
 
from PyQt4.QtCore import *
47
 
from PyQt4.QtGui  import *
48
 
 
49
 
#-------------------------------------------------------------------------------
50
 
# Application modules import
51
 
#-------------------------------------------------------------------------------
52
 
 
53
 
from Base.Toolbox import GuiParam
54
 
 
55
 
from MatisseCustomForm import Ui_MatisseCustomForm
56
 
import Base.QtPage as QtPage
57
 
 
58
 
import Pages.MatisseTypeModel as MatisseType
59
 
import Pages.MatisseGeomModel as MatisseGeom
60
 
 
61
 
from Pages.MatisseRangeDescriptionModel import MatisseRangeDescriptionModel
62
 
from Pages.MatisseNetworkModel import MatisseNetworkModel
63
 
from Pages.MatisseThermicModel import MatisseThermicModel
64
 
 
65
 
#-------------------------------------------------------------------------------
66
 
# log config
67
 
#-------------------------------------------------------------------------------
68
 
 
69
 
logging.basicConfig()
70
 
log = logging.getLogger("MatisseCustomView")
71
 
log.setLevel(GuiParam.DEBUG)
72
 
 
73
 
#-------------------------------------------------------------------------------
74
 
# StandarItemModel class
75
 
#-------------------------------------------------------------------------------
76
 
 
77
 
_EPSILON = 1e-6
78
 
 
79
 
class StandardItemModelMatisseCustom(QStandardItemModel):
80
 
    """
81
 
    QStandardItemModel associated with the QtableView for common Matisse operations.
82
 
 
83
 
    Behavior depends on the value of attribute tagName (self.tagName).
84
 
    """
85
 
 
86
 
    def __init__(self, parent, case, tagName, dico):
87
 
        """
88
 
        """
89
 
        QStandardItemModel.__init__(self)
90
 
 
91
 
        self.parent = parent
92
 
        self.case = case
93
 
        self.tagName = tagName
94
 
        self.dico = dico
95
 
        self.dataMatisse = []
96
 
        self.setColumnCount(len(self.dico['headers']))
97
 
        self.__initXMLModel()
98
 
        self.__initData()
99
 
 
100
 
 
101
 
    def __initXMLModel(self):
102
 
        """
103
 
        """
104
 
        if self.tagName in ["inlet_range_line", "inlet_range_height",
105
 
                            "outlet_range_line", "outlet_range_height",
106
 
                            "network_line", "network_row"]:
107
 
 
108
 
            self.default_row = ["default", 0., 0., 0., 0.]
109
 
            self.columns_editable = [0, 1, 2]
110
 
            self.column_step_min = 3
111
 
            self.column_step_max = 4
112
 
 
113
 
            # XML Model
114
 
            if self.tagName in ["network_line", "network_row"]:
115
 
 
116
 
                self.model = MatisseNetworkModel(self.case)
117
 
 
118
 
                model_geom = MatisseGeom.MatisseGeomModel(self.case)
119
 
                self.lineStep = model_geom.getMatisseGeomDoubleVar('ptrres')
120
 
                self.rowStep = model_geom.getMatisseGeomDoubleVar('plgres')
121
 
                self.heightStep = model_geom.getMatisseGeomDoubleVar('epchel')
122
 
                self.lineMax = model_geom.getMatisseGeomDoubleVar('nptran')
123
 
                self.rowMax = model_geom.getMatisseGeomDoubleVar('nplgrs')
124
 
                self.heightMax = model_geom.getMatisseGeomDoubleVar('nchest')
125
 
 
126
 
                model_mat_type = MatisseType.MatisseTypeModel(self.case)
127
 
                self.alveoStat = model_mat_type.node_alveo['status']
128
 
 
129
 
            elif self.tagName in ["inlet_range_line", "inlet_range_height"]:
130
 
 
131
 
                self.model = MatisseRangeDescriptionModel(self.case, 'inlet_range')
132
 
 
133
 
                model_geom = MatisseGeom.MatisseGeomModel(self.case)
134
 
                self.lineStep = model_geom.getMatisseGeomDoubleVar('ptrres')
135
 
                self.heightStep = model_geom.getMatisseGeomDoubleVar('epchel')
136
 
                self.lineMax = model_geom.getMatisseGeomDoubleVar('nptran')
137
 
                self.heightMax = model_geom.getMatisseGeomDoubleVar('nchest')
138
 
 
139
 
            elif self.tagName in ["outlet_range_line", "outlet_range_height"]:
140
 
 
141
 
                self.model = MatisseRangeDescriptionModel(self.case, 'outlet_range')
142
 
 
143
 
                model_geom = MatisseGeom.MatisseGeomModel(self.case)
144
 
                self.lineStep = model_geom.getMatisseGeomDoubleVar('ptrres')
145
 
                self.heightStep = model_geom.getMatisseGeomDoubleVar('epchel')
146
 
                self.lineMax = model_geom.getMatisseGeomDoubleVar('nptran')
147
 
                self.heightMax = model_geom.getMatisseGeomDoubleVar('nchest')
148
 
 
149
 
        else:
150
 
        #elif self.tagName in ["thermal_line", "thermal_row", "thermal_height"]:
151
 
 
152
 
            # Thermic load
153
 
            self.areatype = self.dico['areatype']
154
 
 
155
 
            self.default_row = ["default", 0., 0., 0., 0., 0.]
156
 
            self.columns_editable = [0, 1, 2, 3]
157
 
            self.column_step_min = 4
158
 
            self.column_step_max = 5
159
 
 
160
 
            # XML Model
161
 
            self.model = MatisseThermicModel(self.case)
162
 
 
163
 
            self.model_mat_type = MatisseType.MatisseTypeModel(self.case)
164
 
            model_geom = MatisseGeom.MatisseGeomModel(self.case)
165
 
            self.lineStep = model_geom.getMatisseGeomDoubleVar('ptrres')
166
 
            self.rowStep = model_geom.getMatisseGeomDoubleVar('plgres')
167
 
            self.heightStep = model_geom.getMatisseGeomDoubleVar('epchel')
168
 
 
169
 
            self.lineMax = model_geom.getMatisseGeomDoubleVar('nptran')
170
 
            self.rowMax = model_geom.getMatisseGeomDoubleVar('nplgrs')
171
 
            self.heightMax = model_geom.getMatisseGeomDoubleVar('nchest')
172
 
 
173
 
        #
174
 
        self.areatype = self.dico['areatype']
175
 
        if self.areatype == 'line' :
176
 
            self.step = self.lineStep
177
 
        elif self.areatype == 'height' :
178
 
            self.step = self.heightStep
179
 
        elif self.areatype == 'row' :
180
 
            self.step = self.rowStep
181
 
 
182
 
 
183
 
    def __initData(self):
184
 
        """
185
 
        Load previous values
186
 
        """
187
 
        if self.tagName in ["inlet_range_line", "inlet_range_height",
188
 
                            "outlet_range_line", "outlet_range_height",
189
 
                            "network_line", "network_row"]:
190
 
 
191
 
            llabel, lbmin, lbmax  = self.model.GetAreas(self.areatype)
192
 
 
193
 
            n = len(llabel)
194
 
            if ((n != len(lbmin)) or (n != len(lbmax))):
195
 
                print "XML format error : bad definition of <area> "
196
 
                sys.exit(1)
197
 
 
198
 
            for area in range(0,len(llabel)):
199
 
                row = self.default_row
200
 
                row[0] = llabel[area]
201
 
                row[1] = float(lbmin[area])
202
 
                row[2] = float(lbmax[area])
203
 
                row[self.column_step_min] = self.step * row[1]
204
 
                row[self.column_step_max] = self.step * row[2]
205
 
                self.dataMatisse.append(row)
206
 
                nrows = self.rowCount()
207
 
                self.setRowCount(nrows+1)
208
 
 
209
 
        elif self.tagName in ["thermal_line", "thermal_row", "thermal_height"]:
210
 
 
211
 
            llabel, lbmin, lbmax, lval  = self.model.GetAreas(self.areatype)
212
 
 
213
 
            n = len(llabel)
214
 
            if ((n != len(lbmin)) or (n != len(lbmax)) or (n != len(lval))):
215
 
                print "XML format error : bad definition of <area> "
216
 
                sys.exit(1)
217
 
 
218
 
            # Default values
219
 
            if len(llabel) == 0 :
220
 
                dlabel, dmin, dmax, dval = self.model.DefaultArea(self.areatype)
221
 
                self.model.NewArea(self.areatype, dlabel, dmin, dmax, dval)
222
 
                llabel.append(dlabel)
223
 
                lbmin.append(dmin)
224
 
                lbmax.append(dmax)
225
 
                lval.append(dval)
226
 
 
227
 
            for area in range(0,len(llabel)):
228
 
                row = self.default_row
229
 
                row[0] = llabel[area]
230
 
                row[1] = float(lbmin[area])
231
 
                row[2] = float(lbmax[area])
232
 
                row[3] = float(lval[area])
233
 
                row[self.column_step_min] = self.step * row[1]
234
 
                row[self.column_step_max] = self.step * row[2]
235
 
                self.dataMatisse.append(row)
236
 
                nrows = self.rowCount()
237
 
                self.setRowCount(nrows+1)
238
 
 
239
 
 
240
 
    def data(self, index, role):
241
 
        if not index.isValid():
242
 
            return QVariant()
243
 
        if role == Qt.DisplayRole:
244
 
            row = index.row()
245
 
            col = index.column()
246
 
            return QVariant(self.dataMatisse[row][col])
247
 
        return QVariant()
248
 
 
249
 
 
250
 
    def flags(self, index):
251
 
        if not index.isValid():
252
 
            return Qt.ItemIsEnabled
253
 
        else:
254
 
            return Qt.ItemIsEnabled | Qt.ItemIsSelectable
255
 
 
256
 
 
257
 
    def headerData(self, section, orientation, role):
258
 
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
259
 
            return QVariant(self.dico['headers'][section])
260
 
        return QVariant()
261
 
 
262
 
 
263
 
    def setData(self, index, value, role):
264
 
        self.emit(SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"), index, index)
265
 
        return True
266
 
 
267
 
 
268
 
    def addRow(self, label, sbmin, sbmax, svalue):
269
 
        """
270
 
        Add a row in the model.
271
 
        """
272
 
        log.debug("addRow")
273
 
        bool_create = False
274
 
        if self.tagName in ["inlet_range_line", "inlet_range_height",
275
 
                            "outlet_range_line", "outlet_range_height",
276
 
                            "network_line", "network_row"]:
277
 
 
278
 
            bool_create = self.__addRowRangeDescriptionNetwork(label, sbmin, sbmax, self.areatype, self.step)
279
 
 
280
 
        if self.tagName in ["thermal_line", "thermal_row", "thermal_height"]:
281
 
 
282
 
            bool_create = self.__addRowThermal(label, sbmin, sbmax, svalue, self.areatype, self.step)
283
 
 
284
 
 
285
 
        if bool_create:
286
 
            row = self.default_row
287
 
            row[0] = label
288
 
            row[1] = sbmin
289
 
            row[2] = sbmax
290
 
            row[self.column_step_min] = self.step * row[1]
291
 
            row[self.column_step_max] = self.step * row[2]
292
 
            self.dataMatisse.append(row)
293
 
            nrows = self.rowCount()
294
 
            self.setRowCount(nrows+1)
295
 
 
296
 
 
297
 
    def editRow(self, row, new_label, new_bmin, new_bmax, new_value):
298
 
        """
299
 
        Edit a row in the model
300
 
        """
301
 
        if self.tagName in ["inlet_range_line", "inlet_range_height",
302
 
                            "outlet_range_line", "outlet_range_height",
303
 
                            "network_line", "network_row"]:
304
 
 
305
 
            [label, sbmin, sbmax, sbmin2, sbmax2] = self.dataMatisse[row]
306
 
            bool_modify = self.__editRangeDescription(new_label, new_bmin, new_bmax,
307
 
                                                      label, sbmin, sbmax,
308
 
                                                      self.areatype, self.step)
309
 
 
310
 
        if self.tagName in ["thermal_line", "thermal_row", "thermal_height"]:
311
 
            [label, sbmin, sbmax, svalue, sbmin2, sbmax2] = self.dataMatisse[row]
312
 
            bool_modify = self.__editRangeThermal(new_label, new_bmin, new_bmax, new_value,
313
 
                                                  label, sbmin, sbmax, svalue,
314
 
                                                  self.areatype, self.step)
315
 
 
316
 
 
317
 
        if bool_modify:
318
 
            pass # TODO
319
 
 
320
 
    def deleteRow(self, row):
321
 
        """
322
 
        Delete a row in the model.
323
 
        """
324
 
        log.debug("deleteRow")
325
 
 
326
 
        if self.tagName in ["inlet_range_line", "inlet_range_height",
327
 
                            "outlet_range_line", "outlet_range_height",
328
 
                            "network_line", "network_row"]:
329
 
 
330
 
            [label, sbmin, sbmax, sbmin2, sbmax2] = self.dataMatisse[row]
331
 
            bool_cancel = self.__deleteRowRangeDescription(label, sbmin, sbmax, self.areatype)
332
 
 
333
 
        if self.tagName in ["thermal_line", "thermal_row", "thermal_height"]:
334
 
            [label, sbmin, sbmax, svalue, sbmin2, sbmax2] = self.dataMatisse[row]
335
 
            bool_cancel = self.__deleteRowThermal(label, sbmin, sbmax, svalue, self.areatype)
336
 
 
337
 
 
338
 
 
339
 
        if bool_cancel:
340
 
            del self.dataMatisse[row]
341
 
            nrows = self.rowCount()
342
 
            self.setRowCount(nrows-1)
343
 
 
344
 
 
345
 
    # RangeDescription & Network
346
 
    # --------------------------
347
 
 
348
 
    def __addRowRangeDescriptionNetwork(self, label, sbmin, sbmax, areatype, step):
349
 
        """
350
 
        Add a row : test for RangeDescription & Network
351
 
        """
352
 
        log.debug("__addRowRangeDescriptionNetwork")
353
 
 
354
 
        if not label:
355
 
            label = "Default"
356
 
 
357
 
        try :
358
 
            bmin = float(sbmin)
359
 
            bmax = float(sbmax)
360
 
        except:
361
 
            title = self.tr("Warning")
362
 
            msg   = self.tr("'%1' bad definition: see the bounds definition").arg(label)
363
 
            QMessageBox.warning(self.parent, title, msg)
364
 
            return
365
 
 
366
 
        llabel, lbmin, lbmax  = self.model.GetAreas(areatype)
367
 
        create = True
368
 
        #
369
 
        # Bounds check 1/2
370
 
        if (bmin > bmax) or (bmin < 0):
371
 
            create = False
372
 
        if (areatype == 'line'):
373
 
            if (bmax > self.lineMax) :
374
 
                create = False
375
 
        elif (areatype == 'height'):
376
 
            if (bmax > self.heightMax) :
377
 
                create = False
378
 
        elif (areatype == 'row'):
379
 
            if (bmax > self.rowMax) :
380
 
                create = False
381
 
 
382
 
        for area in range(0,len(llabel)) :
383
 
            if ((label == llabel[area]) and
384
 
                (abs(bmin - float(lbmin[area])) < _EPSILON) and
385
 
                (abs(bmax - float(lbmax[area])) < _EPSILON)):
386
 
 
387
 
                create = False
388
 
 
389
 
            #
390
 
            # Bounds check 2/2
391
 
            if (((bmin > float(lbmin[area])) and (bmin < float(lbmax[area]))) or
392
 
                ((bmax > float(lbmin[area])) and (bmax < float(lbmax[area])))) :
393
 
                create = False
394
 
 
395
 
        if create :
396
 
            #name = self.insertHlist(h, label, sbmin, sbmax, step)
397
 
            self.model.NewArea(areatype, label, bmin, bmax)
398
 
        else :
399
 
            title = self.tr("Warning")
400
 
            msg   = self.tr("'%1' bad definition: see the bounds definition").arg(label)
401
 
            QMessageBox.warning(self.parent, title, msg)
402
 
 
403
 
        return create
404
 
 
405
 
 
406
 
    def __editRowRangeDescriptionNetwork(self, new_label, new_bmin, new_bmax, label, sbmin, sbmax, areatype):
407
 
        """
408
 
        Edit row : test for RangeDescription & Network
409
 
        """
410
 
 
411
 
        if not new_label:
412
 
            new_label = "Default"
413
 
 
414
 
        if areatype == 'line' :
415
 
            step = self.lineStep
416
 
        elif areatype == 'height' :
417
 
            step = self.heightStep
418
 
        elif areatype == 'row' :
419
 
            step = self.rowStep
420
 
 
421
 
        #if len(self.currentEntry) == 1 : # TODO ONE SELECTION
422
 
        if 1 :
423
 
 
424
 
##             entry = self.currentEntry
425
 
##             if h == self.h :
426
 
##                 label, sbmin, sbmax = self.select.areaInfo(entry)
427
 
##             elif h == self.h3 :
428
 
##                 label, sbmin, sbmax = self.select3.areaInfo(entry)
429
 
 
430
 
            bmin = float(sbmin)
431
 
            bmax = float(sbmax)
432
 
 
433
 
            llabel, lbmin, lbmax  = self.model.GetAreas(areatype)
434
 
 
435
 
            #
436
 
            # Bounds check
437
 
            modify = True
438
 
 
439
 
            #
440
 
            # Type check
441
 
            try :
442
 
                fnew_bmin=float(new_bmin)
443
 
                fnew_bmax=float(new_bmax)
444
 
            except :
445
 
 
446
 
                title = self.tr("Warning")
447
 
                msg   = self.tr("'%1' bad definition: see the bounds definition").arg(label)
448
 
                QMessageBox.warning(self.parent, title, msg)
449
 
                return
450
 
 
451
 
            if (fnew_bmin > fnew_bmax) or (fnew_bmin < 0):
452
 
                modify = False
453
 
            if (areatype == 'line'):
454
 
                if fnew_bmax > self.lineMax :
455
 
                    modify = False
456
 
            elif (areatype == 'height'):
457
 
                if (fnew_bmax > self.heightMax) :
458
 
                    modify = False
459
 
 
460
 
            if not modify :
461
 
                title = self.tr("Warning")
462
 
                msg   = self.tr("'%1' bad definition: see the bounds definition").arg(label)
463
 
                QMessageBox.warning(self.parent, title, msg)
464
 
 
465
 
            else:
466
 
                for area in range(0,len(llabel)) :
467
 
                    if ((label == llabel[area]) and
468
 
                        (abs(bmin - float(lbmin[area])) <= _EPSILON) and
469
 
                        (abs(bmax - float(lbmax[area])) <= _EPSILON)):
470
 
 
471
 
 
472
 
                        if ((label != new_label) or
473
 
                            (abs(bmax - fnew_bmax) >= _EPSILON) or
474
 
                            (abs(bmin - fnew_bmin) >= _EPSILON)) :
475
 
 
476
 
                            for area1 in range(0,len(llabel)) :
477
 
                                if area1 != area :
478
 
                                    if (((fnew_bmin > float(lbmin[area1])) and (fnew_bmin < float(lbmax[area1]))) or
479
 
                                        ((fnew_bmax > float(lbmin[area1])) and (fnew_bmax < float(lbmax[area1])))) :
480
 
                                        modify = False
481
 
 
482
 
                            if modify :
483
 
                                self.model.SetArea(areatype, area, new_label, new_bmin, new_bmax)
484
 
                                #self.replaceHlist(h, entry, new_label, new_bmin, new_bmax, step)
485
 
                            else:
486
 
                                title = self.tr("Warning")
487
 
                                msg   = self.tr("'%1' bad definition: see the bounds definition").arg(label)
488
 
                                QMessageBox.warning(self.parent, title, msg)
489
 
 
490
 
        else: # # TODO MULTI-SELECTION
491
 
            for entry in self.currentEntry:
492
 
 
493
 
##                 if h == self.h :
494
 
##                     label, sbmin, sbmax = self.select.areaInfo(entry)
495
 
##                 elif h == self.h3 :
496
 
##                     label, sbmin, sbmax = self.select3.areaInfo(entry)
497
 
 
498
 
                bmin = float(sbmin)
499
 
                bmax = float(sbmax)
500
 
 
501
 
                llabel, lbmin, lbmax  = self.model.GetAreas(areatype)
502
 
 
503
 
                for area in range(0,len(llabel)) :
504
 
                    if ((label == llabel[area]) or
505
 
                        (abs(bmin - float(lbmin[area])) <= _EPSILON) and
506
 
                        (abs(bmax - float(lbmax[area])) <= _EPSILON)):
507
 
 
508
 
                        if (label != new_label) :
509
 
 
510
 
                            if (new_label != _MULTISEL) :
511
 
                                self.model.SetArea(areatype, area, new_label, None , None)
512
 
                                #self.replaceHlist( h, entry, new_label, bmin, bmax,step)
513
 
 
514
 
                            else :
515
 
                                pass
516
 
 
517
 
 
518
 
    def __deleteRowRangeDescriptionNetwork(self, label, sbmin, sbmax, areatype):
519
 
        """
520
 
        Delete row : test for RangeDescription & Network
521
 
        """
522
 
        log.debug("__deleteRowRangeDescriptionNetwork")
523
 
 
524
 
        bmin = float(sbmin)
525
 
        bmax = float(sbmax)
526
 
 
527
 
        llabel, lbmin, lbmax  = self.model.GetAreas(areatype)
528
 
 
529
 
        cancel = False
530
 
        for area in range(0,len(llabel)) :
531
 
            if ((label == llabel[area]) and
532
 
                (abs(bmin - float(lbmin[area])) < _EPSILON) and
533
 
                (abs(bmax - float(lbmax[area])) < _EPSILON)):
534
 
 
535
 
                self.model.EraseArea(areatype, area)
536
 
                cancel = True
537
 
 
538
 
        return cancel
539
 
 
540
 
##             # Delete boundary region from the Hlist
541
 
##             #
542
 
##             if not cancel :
543
 
##                 print "Entry is in Hlist but not in XML"
544
 
##                 sys.exit(1)
545
 
##             else :
546
 
## #
547
 
## #    Pb : si on ne supprime pas le dernier elt : lors de la creation d'une nouvelle hlist
548
 
## #         il recupere un nom deja donne !!!
549
 
## ##                if h == self.h :
550
 
## ##                    self.entriesNumberH1 = self.entriesNumberH1 -1
551
 
## ##                elif  h == self.h3 :
552
 
## ##                    self.entriesNumberH3 = self.entriesNumberH3 -1
553
 
##                 h.hlist.delete_entry(entry)
554
 
 
555
 
 
556
 
 
557
 
    # Thermal
558
 
    # -------
559
 
 
560
 
    def __addRowRangeThermal(self, label, sbmin, sbmax, svalue, areatype, step):
561
 
        """
562
 
        Add a row : test for Thermal load
563
 
        """
564
 
        log.debug("__addRowThermal")
565
 
 
566
 
        # Reading  and add to Hlist
567
 
        #
568
 
        if not label:
569
 
            label = "Default"
570
 
 
571
 
        try :
572
 
            bmin = float(sbmin)
573
 
            bmax = float(sbmax)
574
 
            value = float(svalue)
575
 
        except:
576
 
            title = self.tr("Warning")
577
 
            msg   = self.tr("'%1' bad definition: see the bounds definition").arg(label)
578
 
            QMessageBox.warning(self.parent, title, msg)
579
 
            return
580
 
 
581
 
        llabel, lbmin, lbmax, lval  = self.model.GetAreas(areatype)
582
 
 
583
 
        create = True
584
 
        #
585
 
        # Bounds check
586
 
        if (bmin > bmax) or (bmin < 0):
587
 
            create = False
588
 
        if (areatype == 'line'):
589
 
            if (bmax > self.lineMax) :
590
 
                create = False
591
 
        elif (areatype == 'row'):
592
 
            if (bmax > self.rowMax) :
593
 
                create = False
594
 
        elif (areatype == 'height'):
595
 
            if (bmax > self.heightMax) :
596
 
                create = False
597
 
 
598
 
        for area in range(0,len(llabel)) :
599
 
            #
600
 
            # No duplicate
601
 
            if ((label == llabel[area]) and
602
 
                (abs(bmin - float(lbmin[area])) < _EPSILON) and
603
 
                (abs(bmax - float(lbmax[area])) < _EPSILON) and
604
 
                (abs(value - float(lval[area])) < _EPSILON)) :
605
 
                create = False
606
 
 
607
 
            if (((bmin > float(lbmin[area])) and (bmin < float(lbmax[area]))) or
608
 
                ((bmax > float(lbmin[area])) and (bmax < float(lbmax[area])))) :
609
 
                create = False
610
 
 
611
 
 
612
 
        if create :
613
 
            #name = self.insertHlist(h, label, sbmin, sbmax, svalue ,step)
614
 
            self.model.NewArea(areatype, label, bmin, bmax, value)
615
 
        else :
616
 
            title = self.tr("Warning")
617
 
            msg   = self.tr("'%1' bad definition: see the bounds definition").arg(label)
618
 
            QMessageBox.warning(self.parent, title, msg)
619
 
 
620
 
        return create
621
 
 
622
 
 
623
 
    def __editRowThermal(self, new_label, new_bmin, new_bmax, label, sbmin, sbmax, areatype):
624
 
        """
625
 
        Edit row : test for Thermal load
626
 
        """
627
 
        log.debug("__editRowThermal")
628
 
 
629
 
 
630
 
        if not new_label:
631
 
            new_label = "Default"
632
 
 
633
 
        if areatype == 'line' :
634
 
            step = self.lineStep
635
 
        elif areatype == 'row' :
636
 
            step = self.rowStep
637
 
        elif areatype == 'height' :
638
 
            step = self.heightStep
639
 
 
640
 
        if 1:
641
 
        #if len(self.currentEntry) == 1 :
642
 
 
643
 
            bmin = float(sbmin)
644
 
            bmax = float(sbmax)
645
 
            value = float(svalue)
646
 
 
647
 
            llabel, lbmin, lbmax, lval  = self.model.GetAreas(areatype)
648
 
 
649
 
            #
650
 
            # Bounds check
651
 
            modify = True
652
 
 
653
 
            #
654
 
            # Type check
655
 
            try :
656
 
                fnew_bmin=float(new_bmin)
657
 
                fnew_bmax=float(new_bmax)
658
 
                fnew_value=float(new_value)
659
 
            except :
660
 
                title = self.tr("Warning")
661
 
                msg   = self.tr("'%1' bad definition: see the bounds definition").arg(label)
662
 
                QMessageBox.warning(self.parent, title, msg)
663
 
                return
664
 
 
665
 
            if (fnew_bmin > fnew_bmax) or (fnew_bmin < 0):
666
 
                modify = False
667
 
            if (areatype == 'line'):
668
 
                if fnew_bmax > self.lineMax :
669
 
                    modify = False
670
 
            elif (areatype == 'height'):
671
 
                if (fnew_bmax > self.heightMax) :
672
 
                    modify = False
673
 
            elif (areatype == 'row'):
674
 
                if (fnew_bmax > self.rowMax) :
675
 
                    modify = False
676
 
 
677
 
            if not modify :
678
 
                title = self.tr("Warning")
679
 
                msg   = self.tr("'%1' bad definition: see the bounds definition").arg(label)
680
 
                QMessageBox.warning(self.parent, title, msg)
681
 
            else:
682
 
                for area in range(0,len(llabel)) :
683
 
                    if ((label == llabel[area]) and
684
 
                        (abs(bmin - float(lbmin[area])) <= _EPSILON) and
685
 
                        (abs(bmax - float(lbmax[area])) <= _EPSILON) and
686
 
                        (abs(value - float(lval[area])) <= _EPSILON)) :
687
 
 
688
 
                        if ((label != new_label) or
689
 
                            (abs(bmax - fnew_bmax) >= _EPSILON) or
690
 
                            (abs(bmin - fnew_bmin) >= _EPSILON) or
691
 
                            (abs(value - fnew_value) >= _EPSILON)) :
692
 
 
693
 
                            for area1 in range(0,len(llabel)) :
694
 
                                if area1 != area :
695
 
                                    if (((fnew_bmin > float(lbmin[area1])) and (fnew_bmin < float(lbmax[area1]))) or
696
 
                                        ((fnew_bmax > float(lbmin[area1])) and (fnew_bmax < float(lbmax[area1])))) :
697
 
                                        modify = False
698
 
 
699
 
                            if modify :
700
 
                                self.model.SetArea(areatype, area, new_label, new_bmin, new_bmax, new_value)
701
 
                                #self.replaceHlist(h, entry, new_label, new_bmin, new_bmax, new_value, step)
702
 
                            else:
703
 
                                title = self.tr("Warning")
704
 
                                msg   = self.tr("'%1' bad definition: see the bounds definition").arg(label)
705
 
                                QMessageBox.warning(self.parent, title, msg)
706
 
 
707
 
 
708
 
        else :
709
 
            for entry in self.currentEntry:
710
 
 
711
 
                bmin = float(sbmin)
712
 
                bmax = float(sbmax)
713
 
                value = float(svalue)
714
 
 
715
 
                llabel, lbmin, lbmax, lval  = self.model.GetAreas(areatype)
716
 
 
717
 
                #
718
 
                # Type check
719
 
                try :
720
 
                    fnew_value=float(new_value)
721
 
                except :
722
 
                    if new_value != _MULTISEL :
723
 
                        title = self.tr("Warning")
724
 
                        msg   = self.tr("'%1' bad definition: see the bounds definition").arg(label)
725
 
                        QMessageBox.warning(self.parent, title, msg)
726
 
 
727
 
                        return
728
 
 
729
 
                for area in range(0,len(llabel)) :
730
 
                    if ((label == llabel[area]) or
731
 
                        (abs(bmin - float(lbmin[area])) <= _EPSILON) and
732
 
                        (abs(bmax - float(lbmax[area])) <= _EPSILON) and
733
 
                        (abs(value - float(lval[area])) <= _EPSILON)) :
734
 
 
735
 
                        if ((label != new_label) or new_value == _MULTISEL or
736
 
                            (abs(value - fnew_value) >= _EPSILON)) :
737
 
 
738
 
                            if (new_label == _MULTISEL) and (new_value != _MULTISEL):
739
 
                                self.model.SetArea(areatype, area, None, None , None , new_value)
740
 
                                #self.replaceHlist( h, entry, label, bmin, bmax, new_value, step)
741
 
 
742
 
                            elif (new_value == _MULTISEL) and (new_label != _MULTISEL) :
743
 
                                self.model.SetArea(areatype, area, new_label , None , None , None)
744
 
                                #self.replaceHlist( h, entry, new_label, bmin, bmax, value, step)
745
 
 
746
 
                            elif (new_value != _MULTISEL) and (new_label != _MULTISEL) :
747
 
                                self.model.SetArea(areatype, area, new_label, None , None , new_value)
748
 
                                #self.replaceHlist( h, entry, new_label, bmin, bmax, new_value, step)
749
 
 
750
 
                            else :
751
 
                                pass
752
 
 
753
 
 
754
 
    def __deleteRowThermal(self, label, sbmin, sbmax, svalue, areatype):
755
 
        """
756
 
        Delete row : test for Thermal
757
 
        """
758
 
        log.debug("__deleteRowThermal")
759
 
 
760
 
        llabel, lbmin, lbmax, lval  = self.model.GetAreas(areatype)
761
 
        cancel = False
762
 
        for area in range(0,len(llabel)) :
763
 
            if ((label == llabel[area]) and
764
 
                (abs(bmin - float(lbmin[area])) < _EPSILON) and
765
 
                (abs(bmax - float(lbmax[area])) < _EPSILON) and
766
 
                (abs(value - float(lval[area])) < _EPSILON)) :
767
 
                self.model.EraseArea(areatype, area)
768
 
                cancel = True
769
 
 
770
 
        return cancel
771
 
 
772
 
#-------------------------------------------------------------------------------
773
 
# Main class
774
 
#-------------------------------------------------------------------------------
775
 
 
776
 
class MatisseCustomView(QWidget, Ui_MatisseCustomForm):
777
 
    """
778
 
    """
779
 
 
780
 
    def __init__(self, *args):
781
 
        """
782
 
        Constructor
783
 
        """
784
 
        QWidget.__init__(self, *args)
785
 
        Ui_MatisseCustomForm.__init__(self)
786
 
        self.setupUi(self)
787
 
 
788
 
 
789
 
    def initWidget(self, case, tagName):
790
 
        """
791
 
        Method to initialize the widget.
792
 
        Must be explicitly called.
793
 
        """
794
 
        self.case = case
795
 
        self.tagName = tagName
796
 
        self._createWidgets()
797
 
 
798
 
 
799
 
    def getLabel(self):
800
 
        """
801
 
        Return the name of the boundary condition. It 's not allowed to have
802
 
        blank or not ASCII caracters in this name.
803
 
        """
804
 
        label = str(self.lineEditLabel.text())
805
 
        return  string.join(string.split(label), '_')
806
 
 
807
 
 
808
 
    def getBmin(self):
809
 
        """
810
 
        """
811
 
        bmin, ok = self.lineEditMin.text().toFloat()
812
 
        return bmin
813
 
 
814
 
 
815
 
    def getBmax(self):
816
 
        """
817
 
        """
818
 
        bmax, ok = self.lineEditMax.text().toFloat()
819
 
        return bmax
820
 
 
821
 
 
822
 
    def getValue(self):
823
 
        """
824
 
        """
825
 
        value, ok = self.lineEditValue.text().toFloat()
826
 
        return value
827
 
 
828
 
 
829
 
    def createItem(self):
830
 
        label = self.getLabel()
831
 
        sbmin = self.getBmin()
832
 
        sbmax = self.getBmax()
833
 
        svalue = self.getValue()
834
 
        self.modelMatisseCustom.addRow(label, sbmin, sbmax, svalue)
835
 
 
836
 
 
837
 
    def modifyItem(self):
838
 
        new_label = self.getLabel()
839
 
        new_bmin = self.getBmin()
840
 
        new_bmax = self.getBmax()
841
 
        new_value = self.getValue()
842
 
        nrows = 0
843
 
        tab_rows = []
844
 
        selectionModel = self.tableView.selectionModel()
845
 
        for index in selectionModel.selectedRows():
846
 
            tab_rows.append(index.row())
847
 
            nrows = nrows + 1
848
 
        log.debug("modifyItem nrows = %i tab_rows = %s "%(nrows, str(tab_rows)))
849
 
        for row in tab_rows:
850
 
            self.modelMatisseCustom.editRow(row, new_label, new_bmin, new_bmax, new_value)
851
 
 
852
 
 
853
 
    def cancelItem(self):
854
 
        nrows = 0
855
 
        tab_rows = []
856
 
        selectionModel = self.tableView.selectionModel()
857
 
        for index in selectionModel.selectedRows():
858
 
            tab_rows.append(index.row())
859
 
            nrows = nrows + 1
860
 
        log.debug("cancelItem nrows = %i tab_rows = %s "%(nrows, str(tab_rows)))
861
 
        for row in tab_rows:
862
 
            self.modelMatisseCustom.deleteRow(row)
863
 
 
864
 
 
865
 
    def _createWidgets(self):
866
 
        """
867
 
        Create the Page layout.
868
 
        """
869
 
        if self.tagName == "":
870
 
            log.debug("_createWidgets self.tagName is not set!")
871
 
            sys.exit(1)
872
 
 
873
 
        self.__initDico()
874
 
        dico = self.dico_custom[self.tagName]
875
 
 
876
 
        # Update title and labels in the view
877
 
        self.groupBox.setTitle(dico['title'])
878
 
        self.labelLabel.setText(QString(dico['label']))
879
 
        self.labelMin.setText(QString(dico['min']))
880
 
        self.labelMax.setText(QString(dico['max']))
881
 
        self.labelValue.hide()
882
 
        self.lineEditValue.hide()
883
 
 
884
 
        if 'value' in dico.keys():
885
 
            self.labelValue.setText(QString(dico['value']))
886
 
            self.labelValue.show()
887
 
            self.lineEditValue.show()
888
 
 
889
 
        # Set model for tableView
890
 
        self.modelMatisseCustom = StandardItemModelMatisseCustom(self, self.case, self.tagName, dico)
891
 
        self.tableView.setModel(self.modelMatisseCustom)
892
 
        self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
893
 
        self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection)
894
 
 
895
 
        # Connections
896
 
        self.connect(self.pushButtonNew,    SIGNAL("clicked()"), self.createItem)
897
 
        self.connect(self.pushButtonModify, SIGNAL("clicked()"), self.modifyItem)
898
 
        self.connect(self.pushButtonDelete, SIGNAL("clicked()"), self.cancelItem)
899
 
 
900
 
        # validators
901
 
        regExp = QRegExp("[_A-Za-z0-9]*") # QRegExp("^all[ ]*$|^[0-9\ ]*$")
902
 
        validatorLabel = QRegExpValidator(regExp, self.lineEditLabel)
903
 
        self.lineEditLabel.setValidator(validatorLabel)
904
 
 
905
 
        validatorFloat = QtPage.DoubleValidator(self.lineEditMin)
906
 
        self.lineEditMin.setValidator(validatorFloat)
907
 
        self.lineEditMax.setValidator(validatorFloat)
908
 
        self.lineEditValue.setValidator(validatorFloat)
909
 
 
910
 
 
911
 
    def tr(self, text):
912
 
        """
913
 
        Translation
914
 
        """
915
 
        return text
916
 
 
917
 
 
918
 
    def __initDico(self):
919
 
        """
920
 
        Set a dictionnary which contains field names.
921
 
        """
922
 
 
923
 
        line   = { 'areatype' : "line",
924
 
                   'title' : self.tr("headloss in line") ,
925
 
                   'label' : self.tr("Label"),
926
 
                   'min' : self.tr("Distance min \n  (in lines)"),
927
 
                   'max' : self.tr("Distance max \n  (in lines)"),
928
 
                   'headers' : [self.tr("Label"),
929
 
                                self.tr("Distance min \n  (in lines)"),
930
 
                                self.tr("Distance max \n  (in lines)"),
931
 
                                self.tr("Distance min \n      (m)"),
932
 
                                self.tr("Distance max \n      (m)")]
933
 
                   }
934
 
 
935
 
        height = { 'areatype' : "height",
936
 
                   'title' : self.tr("headloss in height") ,
937
 
                   'label' : self.tr("Label"),
938
 
                   'min' : self.tr("Height min \n  (in cells)"),
939
 
                   'max' : self.tr("Height max \n  (in cells)"),
940
 
                   'headers' : [self.tr("Label"),
941
 
                                self.tr("Height min \n  (in cells)"),
942
 
                                self.tr("Height max \n  (in cells)"),
943
 
                                self.tr("Height min \n     (m)"),
944
 
                                self.tr("Height max \n     (m)")]
945
 
                   }
946
 
 
947
 
        row    = { 'areatype' : "row",
948
 
                   'title' : self.tr("Headloss in row") ,
949
 
                   'label' : self.tr("Label"),
950
 
                   'min' : self.tr("Distance min \n (in rows)"),
951
 
                   'max' : self.tr("Distance max \n (in rows)"),
952
 
                   'headers' : [self.tr("Label"),
953
 
                                self.tr("Distance min \n (in rows)"),
954
 
                                self.tr("Distance max \n (in rows)"),
955
 
                                self.tr("Distance min \n      (m)"),
956
 
                                self.tr("Distance max \n      (m)")]
957
 
                   }
958
 
 
959
 
        dico_custom = {}
960
 
        dico_custom['inlet_range_line']    = line
961
 
        dico_custom['inlet_range_height']  = height
962
 
        dico_custom['outlet_range_line']   = line
963
 
        dico_custom['outlet_range_height'] = height
964
 
        dico_custom['network_line']        = line
965
 
        dico_custom['network_row']         = row
966
 
        dico_custom['thermal_line']        = line
967
 
        dico_custom['thermal_height']      = height
968
 
        dico_custom['thermal_row']         = row
969
 
 
970
 
        self.dico_custom = dico_custom
971
 
 
972
 
#-------------------------------------------------------------------------------
973
 
# Testing part
974
 
#-------------------------------------------------------------------------------
975
 
 
976
 
if __name__ == "__main__":
977
 
    pass
978
 
 
979
 
#-------------------------------------------------------------------------------
980
 
# End
981
 
#-------------------------------------------------------------------------------