Salome HOME
*** empty log message ***
[tools/eficas.git] / generator / generator_map.py
1 # -*- coding: utf-8 -*-
2 #            CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002  EDF R&D                  WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
9 #
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
14 #
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 #    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
18 #
19 #
20 # ======================================================================
21 """
22    Ce module contient le plugin generateur de fichier au format
23    SEP pour EFICAS.
24
25 """
26 import traceback
27 import types,string,re,os
28
29 from generator_python import PythonGenerator
30
31
32 def entryPoint():
33    """
34       Retourne les informations necessaires pour le chargeur de plugins
35
36       Ces informations sont retournees dans un dictionnaire
37    """
38    return {
39         # Le nom du plugin
40           'name' : 'MAP',
41         # La factory pour creer une instance du plugin
42           'factory' : MapGenerator,
43           }
44
45
46 class MapGenerator(PythonGenerator):
47    """
48       Ce generateur parcourt un objet de type JDC et produit
49       un texte au format eficas et
50       un texte au format py
51
52    """
53    # Les extensions de fichier permis?
54    extensions=('.map',)
55
56
57    def initialise(self,config):
58       self.config=config
59       self.nom_racine=self.config.PATH_STUDY+"/"+self.config.NAME_SCHEME+"/"
60       if not( os.path.exists(self.nom_racine)):
61          os.makedirs(self.nom_racine)
62       self.listeCODE=[]
63       self.text=""
64       self.textCode=""
65       self.texteExecution=""
66       self.ssCode=self.config.appli.ssCode
67
68    def verifie(self):
69       print 'verification generique'
70
71    def gener(self,obj,format='brut',config=None):
72       print 'generation dans generator_map'
73       self.initialise(config)
74       text=PythonGenerator.gener(self,obj,format)
75       self.verifie()
76       self.generePythonMap("non")
77       return text
78
79    def generRUN(self,obj,format='brut',config=None,):
80       print 'generRUN dans generator_map'
81       self.initialise(config)
82       text=PythonGenerator.gener(self,obj,format)
83       self.verifie()
84       self.generePythonMap("oui") 
85       return self.texteExecution
86
87
88    def generRUNYACS(self,obj,format='brut',config=None,nomFichier=None):
89       self.initialise(config)
90       text=PythonGenerator.gener(self,obj,format)
91       import sys
92       sys.path.append('/local/noyret/Salome_5.1.3/Install/YACS/lib/python2.5/site-packages/salome/')
93       self.verifie()
94       import monCreateYacs
95       self.monSchema=monCreateYacs.getSchema(config)
96       self.proc=self.monSchema.createProc()
97       for elt in self.listeCODE:
98           code=elt.keys()[0]
99           dico=elt[code]
100           if code in self.__class__.__dict__.keys():
101              codeYACS=str(code)+"YACS"
102              if hasattr(self.monSchema, codeYACS): 
103                 fct=getattr(self.monSchema, codeYACS)
104                 fct(self.proc,dico)
105       self.monSchema.write_yacs_proc(self.proc,str(nomFichier))
106
107    def generePythonMap(self,execution) :
108       '''
109          self.dictMCVal est un dictionnaire qui est indexe par le nom du code (exple PYGMEE)
110          la valeur associee a la clef est egalement un dictionnaire 
111          ce dictionnaire a pour clef la genealogie du MCSimp suivi de sa valeur
112
113       '''
114       for elt in self.listeCODE:
115           code=elt.keys()[0]
116           dico=elt[code]
117           self.dictMCVal={}
118           self.dictMCVal[code]=dico
119           if code in self.__class__.__dict__.keys():
120              texteCode=apply(self.__class__.__dict__[code],(self,execution))
121              self.texteExecution=self.texteExecution+texteCode
122
123    def generPROC_ETAPE(self,obj):
124       clefDico=obj.nom
125       self.DictTemp={}
126       s=PythonGenerator.generPROC_ETAPE(self,obj)
127       dico={}
128       dico[obj.nom]=self.DictTemp
129       self.listeCODE.append(dico)
130       return s
131
132
133    def generMCSIMP(self,obj) :
134       """
135       Convertit un objet MCSIMP en texte python
136       Remplit le dictionnaire des MCSIMP si nous ne sommes ni dans une loi, ni dans une variable
137       """
138       s=PythonGenerator.generMCSIMP(self,obj)
139       clef=""
140       for i in obj.get_genealogie() :
141            clef=clef+"_"+i
142       self.DictTemp[clef]=obj.valeur
143       return s
144
145
146    def  remplaceCONFIG(self,chaine,liste) :
147        for mot in liste :
148            rplact="%_"+mot+"%"
149            result=chaine.replace(rplact,self.config.__dict__[mot])
150            chaine=result
151        return chaine
152
153    def  remplaceDICO(self,chaine,dico) :
154        for mot in dico.keys() :
155            rplact="%"+mot+"%"
156            result=chaine.replace(rplact,str(dico[mot]))
157            chaine=result
158        return chaine
159