Salome HOME
modif PSEN
[tools/eficas.git] / PSEN_Eficas / opsPSEN.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013   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
21 import re
22 #from ExtractGeneratorandLoadList import ExtractGeneratorandLoadList
23 from ExtractGeneratorandLoadList import ExtractGeneratorandLoadList2
24
25 def INCLUDE(self,chemin_psse,fichier_sav,**args):
26    """ 
27        Fonction sd_prod pour la macro INCLUDE
28    """
29    
30    print "INCLUDE", self
31    reevalue=0
32    if hasattr(self,'fichier_ini'):
33        reevalue=1
34        if self.fichier_ini == fichier_sav : return
35        if hasattr(self,'old_context_fichier_init' ):
36          for concept in self.old_context_fichier_init.values():
37              self.jdc.delete_concept(concept)
38          self.jdc_aux=None
39          self.contexte_fichier_init={}
40          self.reevalue_sd_jdc()
41          self.jdc.reset_context()
42
43    self.fichier_ini=fichier_sav
44    self.contexte_fichier_init = {}
45    self.fichier_unite = 999
46    self.fichier_err = None
47    self.fichier_text=""
48     
49    unite = 999
50
51    pattern_debut_ligne = re.compile(r'^[0-9].*')
52    try:
53      MachineListOrigin,LoadListOrigin= ExtractGeneratorandLoadList2(fichier_sav,chemin_psse)
54    except :
55      if self.jdc.appli is not None:
56         self.jdc.appli.affiche_alerte("Error", 'An error happened in ExtractGeneratorandLoadList execution ')
57         self.g_context = {}
58         self.etapes = []
59         self.jdc_aux = None
60         self.fichier_err = str(exc)
61         self.contexte_fichier_init = {}
62
63    MachineList=[]
64    LoadList=[]
65    BusBarList=[]
66    for m in MachineListOrigin:
67        if m in LoadListOrigin : BusBarList.append(m)
68        else : MachineList.append(m)
69
70    for m in LoadListOrigin:
71        if m not in MachineListOrigin : LoadList.append(m)
72
73    for m in MachineList:
74          nouv=m[0].replace(' ','_')
75          nouveau=nouv.replace('.','_')
76          nom = nouveau+"__"+str(m[1])
77          if pattern_debut_ligne.match(nom): nom='_'+nom
78          id  = str(m[3])
79          self.fichier_text += "%s=MONGENER(ID='%s',);\n" % (nom, id)
80
81    for m in BusBarList:
82          nouv=m[0].replace(' ','_')
83          nouveau=nouv.replace('.','_')
84          nom = nouveau+"__"+str(m[1])
85          if pattern_debut_ligne.match(nom): nom='_'+nom
86          id  = str(m[3])
87          self.fichier_text += "%s=MONBUSBAR(ID='%s',);\n" % (nom, id)
88
89    for m in LoadList:
90          nouv=m[0].replace(' ','_')
91          nouveau=nouv.replace('.','_')
92          nom = nouveau+"__"+str(m[1])
93          if pattern_debut_ligne.match(nom): nom='_'+nom
94          if pattern_debut_ligne.match(nom): print 'match'
95          id  = str(m[3])
96          self.fichier_text += "%s=MACHARGE(ID='%s',);\n" % (nom, id)
97
98    import Extensions.jdc_include
99    self.JdC_aux = Extensions.jdc_include.JDC_CATA_INCLUDE(code='PSEN', execmodul=None)
100    self.make_contexte_include(None, self.fichier_text)
101    self.old_context_fichier_init = self.contexte_fichier_init
102    self.parent.record_unit(unite, self)
103
104
105 def INCLUDE_context(self,d):
106    """ 
107        Fonction op_init pour macro INCLUDE
108    """
109    for k,v in self.g_context.items():
110       d[k]=v
111