Salome HOME
Merge branch 'nouvelEficas' of http://git.forge-pleiade.der.edf.fr/git/eficas into...
[tools/eficas.git] / generator / generator_Creation.py
1 # -*- coding: utf-8 -*-
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    Ce module contient le plugin generateur de fichier au format 
22    CARMEL3D pour EFICAS.
23
24 """
25 import traceback
26 import types,string,re,os
27 from Extensions.i18n import tr
28 from generator_python import PythonGenerator
29 debut="""
30 lqdkqmldk
31 """
32
33
34 def entryPoint():
35    """
36       Retourne les informations necessaires pour le chargeur de plugins
37
38       Ces informations sont retournees dans un dictionnaire
39    """
40    return {
41         # Le nom du plugin
42           'name' : 'Creation',
43         # La factory pour creer une instance du plugin
44           'factory' : CreationGenerator,
45           }
46
47
48 class CreationGenerator(PythonGenerator):
49    """
50
51    """
52    # Les extensions de fichier permis?
53
54    def gener(self,obj,format='brut',config=None):
55        
56       self.initDico(obj)
57       # Cette instruction genère le contenu du fichier de commandes (persistance)
58       self.text=PythonGenerator.gener(self,obj,format)
59       if obj.isvalid() : self.genereDescription()
60       return self.text
61
62
63    def genereParam(self):
64       listeParam=[]
65       for monParam in self.dictParam.keys():
66           if self.dico.has_key(monParam) : continue
67           listeParam.append(self.dictParam[monParam])
68
69       if len(listeParam)== 0 : return
70       try:
71          jdcDict=self.jdc.jdcDict
72       except:
73          raise ValueError,tr("toutes les donnees ne sont pas connues")
74       for param in listeParam:
75           obj=None
76           for etape in self.jdc.jdcDict.etapes:
77               if str(etape.sdnom) != str(param) : 
78                   continue
79               obj=etape
80               break
81               
82       if obj==None:
83          raise ValueError,tr("toutes les donnees ne sont pas connues")
84          return
85
86       texteEtape=self.generETAPE(obj)
87
88    def genereDescription(self) :
89       '''
90       '''
91       self.texte=debut 
92       self.genereParam()
93
94    def initDico(self,obj) :
95       self.dicoCourant={}
96       self.dico={}
97       self.dictParam={}
98       self.listeParam=[]
99       self.jdc=obj.get_jdc_root()
100       try :
101         self.texte_jdc_aux=self.jdc.recorded_units[999]
102       except :
103         self.texte_jdc_aux=""
104
105
106    def generMCSIMP(self,obj) :
107       """
108       Convertit un objet MCSIMP en texte python
109       Remplit le dictionnaire des MCSIMP si nous ne sommes ni dans une loi, ni dans une variable
110       """
111       
112       #print "MCSIMP", obj.nom, "  ", obj.valeur
113       from cree_map_cata import param_map
114       if isinstance(obj.valeur,param_map):
115         self.dicoCourant[obj.nom]=obj.valeur.nom
116         self.dictParam[obj.valeur.nom]=obj.valeur
117       else :
118         self.dicoCourant[obj.nom]=obj.valeur
119       s=PythonGenerator.generMCSIMP(self,obj)
120       return s
121   
122    def generPROC_ETAPE(self,obj):
123       self.dicoCourant={}
124       s=PythonGenerator.generPROC_ETAPE(self,obj)
125       self.dico[obj.nom]=self.dicoCourant
126       return s
127   
128    def generETAPE(self,obj):
129       #print "ETAPE", obj.nom, " ",obj.sdnom
130       self.dicoCourant={}
131       s=PythonGenerator.generETAPE(self,obj)
132       self.dico[obj.sdnom]=self.dicoCourant
133       return s
134