1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 """Ce module contient le plugin generateur de fichier au format Code_Carmel3D pour EFICAS.
24 import types,string,re,os
25 from Extensions.i18n import tr
26 from generator_python import PythonGenerator
32 #keys = ['Carmel3D_StudyDirectory','Syrthes_StudyDirectory']
37 Retourne les informations necessaires pour le chargeur de plugins
38 Ces informations sont retournees dans un dictionnaire
43 # La factory pour creer une instance du plugin
44 'factory' : CARMELCSGenerator,
48 class CARMELCSGenerator(PythonGenerator):
50 Ce generateur parcourt un objet de type JDC et produit
51 un texte au format eficas et
52 un texte au format dictionnaire
55 # Les extensions de fichier permis?
58 #----------------------------------------------------------------------------------------
59 def gener(self,obj,format='brut',config=None):
63 # Cette instruction genere le contenu du fichier de commandes (persistance)
64 self.text=PythonGenerator.gener(self,obj,format)
68 def generxml(self,obj,format='brut',config=None):
70 texte = self.gener(obj,format,config)
71 # print 'self.dictMCVal = ',self.dictMCVal
72 textePourRun = self.update_XMLYacsSchemaForRunning()
75 #----------------------------------------------------------------------------------------
77 #----------------------------------------------------------------------------------------
84 self.debutKey = '__PARAM_CS__'
86 #----------------------------------------------------------------------------------------
88 #----------------------------------------------------------------------------------------
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
99 def getXMLYacsSchemaFileTemplate(self) :
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]
107 def getXMLYacsSchemaFileRun(self) :
108 xmlYacsSchemaFilePath = self.getXMLYacsSchemaFileTemplate()
109 filename = os.path.basename(xmlYacsSchemaFilePath)
110 dirname = os.path.dirname(xmlYacsSchemaFilePath)
112 runxmlfile = os.path.join(dirname,prefix+filename)
113 return xmlYacsSchemaFilePath,runxmlfile
115 def update_XMLYacsSchemaForRunning(self) :
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
122 xmlYacsSchemaFilePath,runxmlfile = self.getXMLYacsSchemaFileRun()
123 f_xml = open( str(xmlYacsSchemaFilePath), 'r')
124 texte_template_xml = f_xml.read()
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')
137 def writeDefault(self,fn) :
138 fileDico = fn[:fn.rfind(".")] + '.py'
139 f = open( str(fileDico), 'wb')
140 f.write( self.texteDico )
142 runxmlfile = self.update_XMLYacsSchemaForRunning()
144 #----------------------------------------------------------------------------------------
145 # analyse de chaque noeud de l'arbre
146 #----------------------------------------------------------------------------------------
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+"____"
155 for i in obj.get_genealogie() :
157 self.dictMCVal[clef]=obj.valeur