Salome HOME
modif pour MT
[tools/eficas.git] / Traducteur / calcG.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2017   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 from Traducteur.parseur import FactNode
21 from Traducteur.load import jdcSet 
22 import logging
23
24 dict_commande={}
25 dict_contexte={}
26 dict_contexte_option={}
27
28 import sys
29 #--------------------------------------------------------------------------
30 def traitementRayon(jdc):
31 #--------------------------------------------------------------------------
32    
33     if "DEFI_FONCTION" not in jdcSet : return
34     for c in jdc.root.childNodes:
35        if c.name != "DEFI_FONCTION" : continue
36        monTexte=jdc.getLines()[c.lineno-1]
37        monNomVariable=monTexte.split("=")[0]
38        aExecuter=monNomVariable+'=0'
39        dict_commande[monNomVariable]=c
40        exec aExecuter in dict_contexte
41     liste_MC=(("CALC_G","R_INF_FO"),("CALC_G","R_SUP_FO"),("CALC_G","MODULE_FO"))
42     liste_achanger = chercheValeurSelonGenea2 (jdc,liste_MC)
43     liste_MC=(("CALC_THETA","THETA_3D","R_INF_FO"),("CALC_THETA","THETA_3D","R_SUP_FO"),("CALC_THETA","THETA_3D","MODULE_FO"))
44     liste_achanger2 = chercheValeurSelonGenea3 (jdc,liste_MC)
45     liste_achanger=liste_achanger+liste_achanger2
46     for item in liste_achanger :
47        commande=dict_commande[item]
48        changeValeurABSCNiveau1(commande,jdc)
49
50 #----------------------------------
51 def changeValeurABSCNiveau1(c,jdc):
52 #----------------------------------
53     for child in c.childNodes:
54        if child.name != "NOM_PARA":continue
55        MonTexte=child.getText(jdc)
56        if len(MonTexte.splitlines()) > 1 :
57           print "Le Traducteur ne sait pas gerer"
58           assert(0)
59        MonTexte=jdc.getLines()[child.lineno-1]
60        debut=MonTexte.find("NOM_PARA")
61        debChaine=MonTexte[0:debut+8]
62        ancien=MonTexte[debut+8:]
63        egal,nomval,fin=ancien.split("'",2)
64        nouvelleLigne=debChaine+egal+"'ABSC'"+fin
65        jdc.getLines()[child.lineno-1]=nouvelleLigne
66        logging.info("renommage parametre ABSC ligne %d",child.lineno-1)
67     return
68       
69 #--------------------------------------------------------------------------
70 def chercheValeurSelonGenea2(jdc,liste_cherche_valeur):
71 #
72 #--------------------------------------------------------------------------
73     liste_valeurs=[]
74     for genea in liste_cherche_valeur:
75        profondeur=len(genea)
76        if profondeur > 2 :
77           print "la methode chercheValeurSelonGenea ne convient"
78           print "pas pour cette généalogie"
79           assert(0)
80        command=genea[0]
81        fact=genea[1]
82       
83        for c in jdc.root.childNodes:
84           if c.name != command:continue
85           for mc in c.childNodes:
86              if mc.name != fact:continue
87              MonTexte=mc.getText(jdc)
88              try :
89              #if ( 1) :
90                 exec MonTexte in dict_contexte
91                 monNomVar=MonTexte.split("=")[1]
92                 monNomVarOk=monNomVar
93                 i=-1
94                 while (monNomVar[i] == "," or  monNomVar[i] == " ") :
95                    monNomVarOk=monNomVar[0:i]
96                    i=i-1
97                 monNomVar=monNomVarOk
98                 i=0
99                 while (monNomVar[i] == " ") :
100                    monNomVarOk=monNomVar[1:]
101                    i=i+1
102                 monNomVar=monNomVarOk
103                 if monNomVar not in liste_valeurs : liste_valeurs.append(monNomVar)
104              except :
105              #else :
106                 logging.error("Pb pour renommer le parametre ABSC dans defi_fonctions selon calcg")
107                 pass
108     return liste_valeurs
109
110       
111 #--------------------------------------------------------------------------
112 def chercheValeurSelonGenea3(jdc,liste_cherche_valeur):
113 #--------------------------------------------------------------------------
114     liste_valeurs=[]
115     for genea in liste_cherche_valeur:
116        profondeur=len(genea)
117        if profondeur > 3 :
118           print "la methode chercheValeurSelonGenea ne convient"
119           print "pas pour cette généalogie"
120           assert(0)
121        command=genea[0]
122        fact=genea[1]
123        mc=genea[2]
124       
125        for c in jdc.root.childNodes:
126           if c.name != command : continue
127           for mcf in c.childNodes:
128              if mcf.name != fact : continue
129              l=mcf.childNodes[:]
130              for ll in l:
131                  for lc in ll.childNodes:
132                     if lc.name !=mc : continue
133                     MonTexte=lc.getText(jdc)
134                     try :
135                     #if ( 1) :
136                        exec MonTexte in dict_contexte
137                        #monNomVar=MonTexte.split("=")[1][0:-1]
138                        monNomVar=MonTexte.split("=")[1]
139                        monNomVarOk=monNomVar
140                        i=-1
141                        while (monNomVar[i] == "," or  monNomVar[i] == " ") :
142                          monNomVarOk=monNomVar[0:i]
143                          i=i-1
144                        monNomVar=monNomVarOk
145                        i=0
146                        while (monNomVar[i] == " ") :
147                           monNomVarOk=monNomVar[1:]
148                           i=i+1
149                        monNomVar=monNomVarOk
150                        if monNomVar not in liste_valeurs : liste_valeurs.append(monNomVar)
151                     except :
152                     #else :
153                        logging.error("Pb pour renommer le parametre ABSC dans defi_fonctions selon calcg")
154                        pass
155     return liste_valeurs
156
157