Salome HOME
Update copyrights
[modules/smesh.git] / src / Tools / Verima / Base / tableMaillages.py
1 # Copyright (C) 2013-2019  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from qtsalome import QSqlQuery
21 from Base.tableDeBase import TableDeBase
22
23 class TableMaillages (TableDeBase):
24     def __init__(self):
25         TableDeBase.__init__(self,"Maillages")
26         self.setField(("id","nomMaillage","Script","fichier","idMailleur","Dimension","Seuil CPU","Seuil Ratio","Seuil Taille","Seuil Nb Maille","Commentaire"))
27         self.cols="(nomMaillage,nomScript,medResultat,idMailleur,dimension,seuilCPU,seuilRatio,seuilTaille,seuilNbMaille,commentaire)"
28         self.setTypeField(('int','str','str','str','int','int','int','int','int','int','str'),('id'))
29
30     def createSqlTable(self):
31         query=QSqlQuery()
32         texteQuery ="create table Maillages(id integer primary key autoincrement, nomMaillage varchar(10), "
33         texteQuery+="nomScript varchar(40), medResultat varchar(15), idMailleur int, dimension int,"
34         texteQuery+="seuilCPU int, seuilRatio int, seuilTaille int, seuilNbMaille int, commentaire varchar(60), "
35         texteQuery+="foreign key (idMailleur) references Mailleur(id));"
36         print("creation de TableMaillages : " , query.exec_(texteQuery))
37
38     def getVal(self,idMaillage, nomChamp):
39         query=QSqlQuery()
40         valeur=None
41         texteQuery ='select '+ nomChamp + ' from Maillages  where id=' + str(idMaillage) + ";"
42         query.exec_(texteQuery)
43         while (query.next()) :
44             valeur=query.value(0).toInt()[0]
45         while (query.next()) :
46             print("plusieurs enregistrements dans Maillages pour ",str(idMaillage))
47             exit()
48         return valeur
49
50     def dejaRemplie(self):
51         texteQuery="select * from  Maillages where medResultat='/tmp/tetra.med';"
52         maQuery=QSqlQuery()
53         maQuery.exec_(texteQuery)
54         nb=0
55         while(maQuery.next()): nb=nb+1
56         return nb
57
58     def remplit(self):
59         if self.dejaRemplie():
60             print("table Maillage deja initialisee")
61             return
62 #            self.insereLigneAutoId(('Fiche_7566_TUNNEL', '/home/H77945/CAS_TEST/MAILLEUR/FICHE_7566_TUNNEL/Fiche_7566_TUNNEL.py', '/tmp/Fiche_7566_TUNNEL.med', 3,3,10,10,10,10, 'Maillage d un tunnel'))
63 #            self.insereLigneAutoId(('Fiche_7957_AILETTE', '/home/H77945/CAS_TEST/MAILLEUR/FICHE_7957_AILETTE/Fiche_7957_AILETTE.py', '/tmp/Fiche_7957_AILETTE.med', 1,2,10,10,10,10, 'Maillage d une attache d aillette'))
64
65     def construitListeMaillages(self):
66         maQuery=QSqlQuery()
67         texteQuery="select id, nomScript,medResultat from Maillages;"
68         maQuery.exec_(texteQuery)
69         listeMaillages=[]
70         while(maQuery.next()):
71             listeMaillages.append((maQuery.value(0).toInt()[0], maQuery.value(1).toString(), maQuery.value(2).toString()))
72         return listeMaillages
73
74     def verifieListeMaillages(self,listeMaillage):
75         newListeMaillages=[]
76         maQuery=QSqlQuery()
77         for idM in listeMaillage:
78             texteQuery="select id, nomScript,medResultat from Maillages where id = " + str(idM) +';'
79             maQuery.exec_(texteQuery)
80             maSize=0
81             while(maQuery.next()):
82                 maSize+=1
83                 newListeMaillages.append((maQuery.value(0).toInt()[0], maQuery.value(1).toString(), maQuery.value(2).toString()))
84             if maSize != 1 :
85                 print("impossible de traiter le maillage : ", idM)
86         return  newListeMaillages
87
88     def getSeuilsPourMaillage(self,idMaillage):
89         texteQuery="select id,nomMaillage,seuilCPU,seuilRatio,seuilTaille,seuilNbMaille from  Maillages where id = "+ str(idMaillage) +"  ;"
90         maQuery=QSqlQuery()
91         maQuery.exec_(texteQuery)
92         while(maQuery.next()):
93             l1 = maQuery.value(0).toInt()[0]
94             l2 = maQuery.value(1).toString()
95             l3 = maQuery.value(2).toInt()[0]
96             l4 = maQuery.value(3).toInt()[0]
97             l5 = maQuery.value(4).toInt()[0]
98             l6 = maQuery.value(5).toInt()[0]
99         return l1,l2,l3,l4,l5,l6
100
101     def getTous(self):
102         maillagesIdListe=[]; maillagesNomListe=[]
103         texteQuery="select id,nomMaillage from  Maillages order by id;"
104         maQuery=QSqlQuery()
105         maQuery.exec_(texteQuery)
106         while(maQuery.next()):
107             maillagesIdListe.append( maQuery.value(0).toInt()[0])
108             maillagesNomListe.append( maQuery.value(1).toString())
109         return maillagesIdListe, maillagesNomListe
110
111     def getMailleurId(self,idMaillage):
112         texteQuery="select idMailleur from  Maillages where id = "+ str(idMaillage) +"  ;"
113         maQuery=QSqlQuery()
114         print(texteQuery)
115         print(maQuery.exec_(texteQuery))
116         maQuery.exec_(texteQuery)
117         while(maQuery.next()):
118             idMailleur = maQuery.value(0).toInt()[0]
119         return idMailleur