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-2021 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"""
26This module defines the 'Droplet Condensation-Evaporation' page.
27
28This module contains the following classes:
29- DropletCondensationEvaporationView
30"""
31
32#-------------------------------------------------------------------------------
33# Library modules import
34#-------------------------------------------------------------------------------
35
36import os, sys, string, types
37import logging
38
39#-------------------------------------------------------------------------------
40# Third-party modules
41#-------------------------------------------------------------------------------
42
43from code_saturne.Base.QtCore    import *
44from code_saturne.Base.QtGui     import *
45from code_saturne.Base.QtWidgets import *
46
47#-------------------------------------------------------------------------------
48# Application modules import
49#-------------------------------------------------------------------------------
50
51from code_saturne.model.Common import GuiParam
52from code_saturne.Base.QtPage import ComboModel, DoubleValidator, from_qvariant
53from DropletCondensationEvaporation import Ui_DropletCondensationEvaporation
54from code_saturne.model.DropletCondensationEvaporationModel import DropletCondensationEvaporationModel
55
56#-------------------------------------------------------------------------------
57# log config
58#-------------------------------------------------------------------------------
59
60logging.basicConfig()
61log = logging.getLogger("DropletCondensationEvaporationView")
62log.setLevel(GuiParam.DEBUG)
63
64
65#-------------------------------------------------------------------------------
66#  class InterfacialForces
67#-------------------------------------------------------------------------------
68
69class DropletCondensationEvaporationView(QWidget, Ui_DropletCondensationEvaporation):
70    """
71    Droplet Condensation-Evaporation model layout.
72    """
73    def __init__(self, parent):
74        """
75        Constructor
76        """
77        QWidget.__init__(self, parent)
78
79        Ui_DropletCondensationEvaporation.__init__(self)
80        self.setupUi(self)
81
82    def setup(self, case):
83        self.case = case
84        self.case.undoStopGlobal()
85        self.mdl = DropletCondensationEvaporationModel(self.case)
86
87        self.modelYPlus = ComboModel(self.comboBoxYPlus, 3, 1)
88        self.modelYPlus.addItem(self.tr("Boundary cell center"), "center")
89        self.modelYPlus.addItem(self.tr("Y+ = "), "Yplus_value")
90        self.modelYPlus.addItem(self.tr("Droplets diameter"), "diameter")
91
92        # Validators
93
94        validatorYplus = DoubleValidator(self.lineEditYPlus, min=0.0)
95
96        validatorYplus.setExclusiveMin(True)
97
98        self.lineEditYPlus.setValidator(validatorYplus)
99
100        # Connect signals to slots
101        self.comboBoxYPlus.activated[str].connect(self.slotYPlus)
102        self.lineEditYPlus.textChanged[str].connect(self.slotYPlusValue)
103
104        isYPlus = self.mdl.getYPlusModel()
105        self.modelYPlus.setItem(str_model=isYPlus)
106
107        if isYPlus == "Yplus_value" :
108           self.lineEditYPlus.show()
109           self.lineEditYPlus.setText(str(self.mdl.getYPlusValue()))
110        else :
111           self.lineEditYPlus.hide()
112
113        self.case.undoStartGlobal()
114
115    @pyqtSlot(str)
116    def slotYPlus(self, text):
117        """
118        configure Y Plus model
119        """
120        value = self.modelYPlus.dicoV2M[text]
121        log.debug("slotYPlus -> %s" % value)
122        self.mdl.setYPlusModel(value)
123
124        if value == "Yplus_value" :
125           self.lineEditYPlus.show()
126           self.lineEditYPlus.setText(str(self.mdl.getYPlusValue()))
127        else :
128           self.lineEditYPlus.hide()
129
130
131    @pyqtSlot(str)
132    def slotYPlusValue(self, text):
133        """
134        Update the Yplus value
135        """
136        if self.lineEditYPlus.validator().state == QValidator.Acceptable:
137            value = from_qvariant(text, float)
138            self.mdl.setYPlusValue(value)
139
140
141