Salome HOME
mse a jour du 07/03/2016 pour sauvegarde
[tools/eficas.git] / generator / generator_CARMELCS.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 """Ce module contient le plugin generateur de fichier au format  Code_Carmel3D pour EFICAS.
21 """
22
23 import traceback
24 import types,string,re,os
25 from Extensions.i18n import tr
26 from generator_python import PythonGenerator
27 import Accas
28
29
30
31
32 #keys = ['Carmel3D_StudyDirectory','Syrthes_StudyDirectory']
33
34
35 def entryPoint():
36    """
37       Retourne les informations necessaires pour le chargeur de plugins
38       Ces informations sont retournees dans un dictionnaire
39    """
40    return {
41         # Le nom du plugin
42           'name' : 'CARMELCS',
43         # La factory pour creer une instance du plugin
44           'factory' : CARMELCSGenerator,
45           }
46
47
48 class CARMELCSGenerator(PythonGenerator):
49    """
50       Ce generateur parcourt un objet de type JDC et produit
51       un texte au format eficas et 
52       un texte au format dictionnaire
53
54    """
55    # Les extensions de fichier permis?
56    extensions=('.comm',)
57
58 #----------------------------------------------------------------------------------------
59    def gener(self,obj,format='brut',config=None):
60        
61       self.initDico()
62       
63       # Cette instruction genere le contenu du fichier de commandes (persistance)
64       self.text=PythonGenerator.gener(self,obj,format)
65       self.racine=obj
66       return self.text
67
68    def generxml(self,obj,format='brut',config=None):
69
70       texte = self.gener(obj,format,config)
71 #      print 'self.dictMCVal = ',self.dictMCVal
72       textePourRun = self.update_XMLYacsSchemaForRunning()
73       return textePourRun
74       
75 #----------------------------------------------------------------------------------------
76 # initialisations
77 #----------------------------------------------------------------------------------------
78    
79    def initDico(self) :
80  
81       self.texteDico = ""
82       self.dictMCVal={}
83       self.dicoCS={}
84       self.debutKey = '__PARAM_CS__'
85
86 #----------------------------------------------------------------------------------------
87 # ecriture
88 #----------------------------------------------------------------------------------------
89
90    def getdico(self) :
91       #print 'getdico : self.dictMCVal.keys() = ',self.dictMCVal.keys()
92       for k in self.dictMCVal.keys():
93           if k.find (self.debutKey) > -1 :
94             a,kproperty=k.split(self.debutKey)   
95             self.dicoCS[kproperty] = self.dictMCVal[k]
96       #print "self.dicoCS = ",self.dicoCS
97       return self.dicoCS
98
99    def getXMLYacsSchemaFileTemplate(self) :
100
101       for k in self.dictMCVal.keys():
102           if k.find (self.debutKey) > -1 :
103             a,kproperty=k.split(self.debutKey)   
104             if kproperty  ==   'XMLYacsFile' :
105                return  self.dictMCVal[k]
106
107    def getXMLYacsSchemaFileRun(self) :
108        xmlYacsSchemaFilePath = self.getXMLYacsSchemaFileTemplate()
109        filename = os.path.basename(xmlYacsSchemaFilePath)
110        dirname  = os.path.dirname(xmlYacsSchemaFilePath)
111        prefix = '_run_'
112        runxmlfile = os.path.join(dirname,prefix+filename)
113        return xmlYacsSchemaFilePath,runxmlfile
114
115    def update_XMLYacsSchemaForRunning(self) :
116        """
117        Creation du fichier _run_XXX.xml, a partir des elements donnes par l'utilisateur dans l'interface :
118        Carmel3D_StudyDirectory : YYY (path du repertoire de l'etude CARMEL3D de couplage)
119        Syrthes_StudyDirectory : YYY/THERMIQUE (path du repertoire de l'etude SYRTHES de couplage)
120        XMLYacsFile : PATH du fichier template du schema yacs d'execution du couplage
121        """
122        xmlYacsSchemaFilePath,runxmlfile = self.getXMLYacsSchemaFileRun()
123        f_xml = open( str(xmlYacsSchemaFilePath), 'r')
124        texte_template_xml = f_xml.read()
125        f_xml.close()
126        dicoCS = self.getdico()
127        print "dicoCS = ",dicoCS
128        # ajout dans dicoCS des elements pour SYRTHES qui sont deja sous cette forme la dans le fichier xml sinon ca pose pb
129        dicoCS['DEB']='%(DEB)s'
130        dicoCS['FIN']='%(FIN)s'
131        newTexteXml = texte_template_xml%dicoCS
132        f = open(runxmlfile,'w')
133        f.write(newTexteXml)
134        f.close()
135        return runxmlfile
136
137    def writeDefault(self,fn) :
138        fileDico = fn[:fn.rfind(".")] + '.py'
139        f = open( str(fileDico), 'wb')
140        f.write( self.texteDico )
141        f.close()
142        runxmlfile = self.update_XMLYacsSchemaForRunning()
143
144 #----------------------------------------------------------------------------------------
145 #  analyse de chaque noeud de l'arbre 
146 #----------------------------------------------------------------------------------------
147
148    def generMCSIMP(self,obj) :
149         """recuperation de l objet MCSIMP"""
150         s=PythonGenerator.generMCSIMP(self,obj)
151         self.texteDico+=obj.nom+ "=" + s[0:-1]+ "\n"
152 #        print 'generMCSIMP self.texteDico = ',self.texteDico
153         if hasattr(obj.etape,'sdnom'): clef=obj.etape.sdnom+"____"
154         else: clef=""
155         for i in obj.get_genealogie() :
156             clef=clef+"__"+i
157         self.dictMCVal[clef]=obj.valeur
158
159         return s
160
161