# -*- coding: iso-8859-1 -*-
#
#-------------------------------------------------------------------------------
#                    Code_Saturne version 1.3
#                    ------------------------
#
#
#     This file is part of the Code_Saturne User Interface, element of the
#     Code_Saturne CFD tool.
#
#     Copyright (C) 1998-2007 EDF S.A., France
#
#     contact: saturne-support@edf.fr
#
#     The Code_Saturne User Interface is free software; you can redistribute it
#     and/or modify it under the terms of the GNU General Public License
#     as published by the Free Software Foundation; either version 2 of
#     the License, or (at your option) any later version.
#
#     The Code_Saturne User Interface is distributed in the hope that it will be
#     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
#     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
#
#     You should have received a copy of the GNU General Public License
#     along with the Code_Saturne Kernel; if not, write to the
#     Free Software Foundation, Inc.,
#     51 Franklin St, Fifth Floor,
#     Boston, MA  02110-1301  USA
#
#-------------------------------------------------------------------------------


#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------

import os, re, sys
import string
import sys, unittest
import Tix
from Tkconstants import *

#-------------------------------------------------------------------------------
# Application modules import
#-------------------------------------------------------------------------------
from Base.Common import *
import Base.Toolbox as Tool
import Base.Dialog as Dialog
import Base.TkPage as TkPage
import Pages.CoalCombustion as CoalCombustion
import Pages.CommonCombustion as CommonCombustion


class CurrentSpeciesModel:

    def __init__(self, case):
        """ constructor """
        self.case = case
        model = CoalCombustion.CoalCombustionModel(self.case)
        if model.getCoalCombustionModel() != "off":
            import Pages.CoalThermoChemistry as CoalThermoChemistry
            model = CoalThermoChemistry.CoalThermoChemistryModel('dp_FCP', self.case)
            self.species = model.getSpecies()

    def getSpecies(self):
        return self.species


class CurrentSpeciesView(TkPage.Page):
    """
    Class to open species Page.
    """

    def _dependsPages(self, name):
        """
        Construction of the list of dependencies Pages.
        """
        pass


    def _tkControlVariables(self):
        """
        Tkinter variables declaration.
        """
        pass


    def _pageControl(self):
        self.model = CurrentSpeciesModel(self.case)
        self.species = self.model.getSpecies() 


    def _createWidgets(self):
        """
        Create the Page layout.
        """
        t = PageText()
        lf = Tix.LabelFrame(self.myPage, bd=2, label=t.ENTHTEMP, relief=FLAT)
        lf.label.config(font=fT)
        lf.pack(side=TOP, fill=X, padx=10, pady=10)

        self.w = Tix.Frame(lf.frame, relief=FLAT)
        self.w.pack(side=TOP, fill=X, padx=10, pady=10)

        lf1 = Tix.LabelFrame(self.myPage, bd=2, label=t.COMPOSITION, relief=FLAT)
        lf1.label.config(font=fT)
        lf1.pack(side=TOP, fill=X, padx=10, pady=10)

        lf2 = Tix.LabelFrame(self.myPage, bd=2, label=t.MOLARMASS, relief=FLAT)
        lf2.label.config(font=fT)
        lf2.pack(side=TOP, fill=X, padx=10, pady=10)

        self.w1 = Tix.Frame(lf1.frame, relief=FLAT)
        self.w1.pack(side=TOP, fill=X, padx=10, pady=10)

        self.w2 = Tix.Frame(lf2.frame, relief=FLAT)
        self.w2.pack(side=TOP, fill=X, padx=10, pady=10)

        l = Tix.Label(self.w, text=t.POINTSNB, font=fB)
        l.grid(row = 0, column = 0, padx=10, pady=5, sticky=E)
        l = Tix.Label(self.w, text=str(self.species.getEnthalpyTempTabNb()))
        l.grid(row = 0, column = 1, padx=10, pady=5, sticky=E)

        l = Tix.Label(self.w, text=t.MINTEMP, font=fB)
        l.grid(row = 1, column = 0, padx=10, pady=5, sticky=E)
        l = Tix.Label(self.w, text=str(self.species.getMinTempTab()))
        l.grid(row = 1, column = 1, padx=10, pady=5, sticky=E)
        l = Tix.Label(self.w, text="K")
        l.grid(row = 1, column = 2, padx=2, pady=5, sticky=E)

        l = Tix.Label(self.w, text=t.MAXTEMP, font=fB)
        l.grid(row = 2, column = 0, padx=10, pady=5, sticky=E)
        l = Tix.Label(self.w, text=str(self.species.getMaxTempTab()))
        l.grid(row = 2, column = 1, padx=10, pady=5, sticky=E)
        l = Tix.Label(self.w, text="K")
        l.grid(row = 2, column = 2, padx=2, pady=5, sticky=E)

        currentSpeciesName = self.species.getCurrentSpeciesList()
        for j in range(0,self.species.getCurrentSpeciesNb()):
            l1 = Tix.Label(self.w1, text=str(currentSpeciesName[j]), font=fB)
            l1.grid(row = 0, column = j+1, padx=10, pady=5, sticky=E)
        elemSpeciesName = self.species.getElementarySpeciesList()
        for i in range(0,self.species.getElementarySpeciesNb()):
            composition = self.species.getCurrentSpeciesCompositionList()[i]
            l1 = Tix.Label(self.w1, text=elemSpeciesName[i], font=fB)
            l1.grid(row = i+1, column = 0, padx=20, pady=5, sticky=E)
            for j in range(0,self.species.getCurrentSpeciesNb()):
                l1 = Tix.Label(self.w1, text=str(composition[j]))
                l1.grid(row = i+1, column = j+1, padx=10, pady=5, sticky=E)
                

        molarMass = self.species.getElementarySpeciesMolarMassesList()
        for i in range(0,self.species.getElementarySpeciesNb()):
            l1 = Tix.Label(self.w2, text=str(elemSpeciesName[i]), font=fB)
            l1.grid(row = i, column = 0, padx=10, pady=5, sticky=E)
            l2 = Tix.Label(self.w2, text=str(molarMass[i]))
            l2.grid(row = i, column = 1, padx=10, pady=5, sticky=E)
            l3 = Tix.Label(self.w2, text="kg/mol")
            l3.grid(row = i, column = 2, padx=2, pady=5, sticky=E)

    def _initializeWidgets(self):
        """
        Extract resquested informations from XML document.
        This informations are used to initialize the widgets.
        For this page default values of all widgets are necessary
        included in the XML file.
        """
        pass


class PageText:
    """
    Storage of all texts and messagages for this page.
    """
    def __init__(self):
        # 1) Texts
        #
        if Tool.GuiParam.lang == 'fr':
            self.SPECIES           = "Espèces courantes"
            self.COMPOSITION       = "Composition"
            self.MOLARMASS         = "Masse molaire des espèces élémentaires"
            self.ENTHTEMP          = "Table Enthalpie-Température"
            self.POINTSNB          = "Nombre de points de tabulation" 
            self.MINTEMP           = "Température min" 
            self.MAXTEMP           = "Température max" 
        else:
            self.SPECIES           = "Current species"
            self.COMPOSITION       = "Composition"
            self.MOLARMASS         = "Elementary species molar mass"
            self.ENTHTEMP          = "Enthalpy-Temperature tabutation"
            self.POINTSNB          = "points number of tabulation" 
            self.MINTEMP           = "Min temperature" 
            self.MAXTEMP           = "Max temperature" 
        # 2) Messages
        #
        if Tool.GuiParam.lang == 'fr':
            self.MSG_COAL     = "Sélectionner un modèle"
        else:
            self.MSG_COAL     = "Select a model"


syntax highlighted by Code2HTML, v. 0.9.1