class BoundaryConditionsPressureView(QWidget, Ui_BoundaryConditionsPressureForm):
    def __init__(self, parent):
        """
        Constructor
        """
        QWidget.__init__(self, parent)

        Ui_BoundaryConditionsPressureForm.__init__(self)
        self.setupUi(self)


    def setup(self, case):
        """
        Setup the widget
        """
        self.__case = case
        self.__boundary = None

        self.__case.undoStopGlobal()

        # Connections
        self.connect(self.lineEditPressure,   SIGNAL("textChanged(const QString &)"), self.slotPressureValue)

        # Validators
        validatorP = DoubleValidator(self.lineEditPressure, min = 0.0)

        # Apply validators
        self.lineEditPressure.setValidator(validatorP)

        self.__case.undoStartGlobal()


    def showWidget(self, boundary):
        """
        Show the widget
        """
        label = boundary.getLabel()
        self.nature  = boundary.getNature()
        self.__boundary = Boundary(self.nature, label, self.__case)
        self.initialize()


    def initialize(self):

        # Initialize thermodynamic value
        pressure = self.__boundary.getPressureValue()
        self.lineEditPressure.setText(str(pressure))

        self.show()


    def hideWidget(self):
        """
        Hide all
        """
        self.hide()


    @pyqtSignature("const QString&")
    def slotPressureValue(self, text):
        """
        INPUT outlet pressure
        """
        if self.sender().validator().state == QValidator.Acceptable:
            t = from_qvariant(text, float)
            self.__boundary.setPressureValue(t)


    def tr(self, text):
        """
        Translation
        """
        return text
class BoundaryConditionsPressureView(QWidget,
                                     Ui_BoundaryConditionsPressureForm):
    def __init__(self, parent):
        """
        Constructor
        """
        QWidget.__init__(self, parent)

        Ui_BoundaryConditionsPressureForm.__init__(self)
        self.setupUi(self)

    def setup(self, case):
        """
        Setup the widget
        """
        self.__case = case
        self.__boundary = None

        self.__case.undoStopGlobal()

        # Connections
        self.lineEditPressure.textChanged[str].connect(self.slotPressureValue)

        # Validators
        validatorP = DoubleValidator(self.lineEditPressure, min=0.0)

        # Apply validators
        self.lineEditPressure.setValidator(validatorP)

        self.__case.undoStartGlobal()

    def showWidget(self, boundary):
        """
        Show the widget
        """
        label = boundary.getLabel()
        self.nature = boundary.getNature()
        self.__boundary = Boundary(self.nature, label, self.__case)
        self.initialize()

    def initialize(self):

        # Initialize thermodynamic value
        pressure = self.__boundary.getPressureValue()
        self.lineEditPressure.setText(str(pressure))

        self.show()

    def hideWidget(self):
        """
        Hide all
        """
        self.hide()

    @pyqtSlot(str)
    def slotPressureValue(self, text):
        """
        INPUT outlet pressure
        """
        if self.sender().validator().state == QValidator.Acceptable:
            t = from_qvariant(text, float)
            self.__boundary.setPressureValue(t)

    def tr(self, text):
        """
        Translation
        """
        return text
class BoundaryConditionsCompressibleOutletView(
        QWidget, Ui_BoundaryConditionsCompressibleOutletForm):
    def __init__(self, parent):
        """
        Constructor
        """
        QWidget.__init__(self, parent)

        Ui_BoundaryConditionsCompressibleOutletForm.__init__(self)
        self.setupUi(self)

    def setup(self, case):
        """
        Setup the widget
        """
        self.__case = case
        self.__boundary = None

        self.__case.undoStopGlobal()

        self.mdl = CompressibleModel(self.__case)

        # Connections
        self.comboBoxTypeOutlet.activated[str].connect(self.slotOutletType)
        self.lineEditPressure.textChanged[str].connect(self.slotPressureValue)

        # Combo models
        self.modelTypeOutlet = ComboModel(self.comboBoxTypeOutlet, 2, 1)
        self.modelTypeOutlet.addItem(self.tr("supersonic outlet"),
                                     'supersonic_outlet')
        self.modelTypeOutlet.addItem(self.tr("subsonic outlet"),
                                     'subsonic_outlet')

        # Validators
        validatorP = DoubleValidator(self.lineEditPressure, min=0.0)

        # Apply validators
        self.lineEditPressure.setValidator(validatorP)

        self.__case.undoStartGlobal()

    def showWidget(self, boundary):
        """
        Show the widget
        """
        label = boundary.getLabel()
        self.__boundary = Boundary('compressible_outlet', label, self.__case)
        self.initialize()

    def initialize(self):

        # Initialize thermodynamic value

        outlet_type = self.__boundary.getOutletType()
        self.modelTypeOutlet.setItem(str_model=outlet_type)
        self.__boundary.setOutletType(outlet_type)
        if outlet_type == 'supersonic_outlet':
            self.frameDensity.hide()
        else:
            self.frameDensity.show()
            pressure = self.__boundary.getPressureValue()
            self.lineEditPressure.setText(str(pressure))

        self.show()

    def hideWidget(self):
        """
        Hide all
        """
        self.hide()

    @pyqtSlot(str)
    def slotOutletType(self, text):
        """
        INPUT outlet type
        """
        value = self.modelTypeOutlet.dicoV2M[str(text)]
        log.debug("__slotOutletType value = %s " % value)

        self.__boundary.setOutletType(value)
        self.initialize()

    @pyqtSlot(str)
    def slotPressureValue(self, text):
        """
        INPUT outlet pressure
        """
        if self.sender().validator().state == QValidator.Acceptable:
            t = from_qvariant(text, float)
            self.__boundary.setPressureValue(t)

    def getCompressibleModel(self):
        """
        Return the compressible model
        """
        model = self.mdl.getCompressibleModel()
        return model

    def tr(self, text):
        """
        Translation
        """
        return text
class BoundaryConditionsCompressibleOutletView(QWidget, Ui_BoundaryConditionsCompressibleOutletForm):
    def __init__(self, parent):
        """
        Constructor
        """
        QWidget.__init__(self, parent)

        Ui_BoundaryConditionsCompressibleOutletForm.__init__(self)
        self.setupUi(self)


    def setup(self, case):
        """
        Setup the widget
        """
        self.__case = case
        self.__boundary = None

        self.__case.undoStopGlobal()

        self.mdl = CompressibleModel(self.__case)

        # Connections
        self.connect(self.comboBoxTypeOutlet, SIGNAL("activated(const QString&)"),    self.slotOutletType)
        self.connect(self.lineEditPressure,   SIGNAL("textChanged(const QString &)"), self.slotPressureValue)

        # Combo models
        self.modelTypeOutlet = ComboModel(self.comboBoxTypeOutlet, 2, 1)
        self.modelTypeOutlet.addItem(self.tr("supersonic outlet"), 'supersonic_outlet')
        self.modelTypeOutlet.addItem(self.tr("subsonic outlet"), 'subsonic_outlet')

        # Validators
        validatorP = DoubleValidator(self.lineEditPressure, min = 0.0)

        # Apply validators
        self.lineEditPressure.setValidator(validatorP)

        self.__case.undoStartGlobal()


    def showWidget(self, boundary):
        """
        Show the widget
        """
        label = boundary.getLabel()
        self.__boundary = Boundary('compressible_outlet', label, self.__case)
        self.initialize()


    def initialize(self):

        # Initialize thermodynamic value

        outlet_type = self.__boundary.getOutletType()
        self.modelTypeOutlet.setItem(str_model = outlet_type)
        self.__boundary.setOutletType(outlet_type)
        if outlet_type == 'supersonic_outlet':
            self.frameDensity.hide()
        else:
            self.frameDensity.show()
            pressure = self.__boundary.getPressureValue()
            self.lineEditPressure.setText(str(pressure))

        self.show()


    def hideWidget(self):
        """
        Hide all
        """
        self.hide()


    @pyqtSignature("const QString&")
    def slotOutletType(self, text):
        """
        INPUT outlet type
        """
        value = self.modelTypeOutlet.dicoV2M[str(text)]
        log.debug("__slotOutletType value = %s " % value)

        self.__boundary.setOutletType(value)
        self.initialize()


    @pyqtSignature("const QString&")
    def slotPressureValue(self, text):
        """
        INPUT outlet pressure
        """
        if self.sender().validator().state == QValidator.Acceptable:
            t = from_qvariant(text, float)
            self.__boundary.setPressureValue(t)


    def getCompressibleModel(self):
        """
        Return the compressible model
        """
        model = self.mdl.getCompressibleModel()
        return model


    def tr(self, text):
        """
        Translation
        """
        return text