Salome HOME
7.7 rc0
[tools/eficas.git] / generator / generator_map.py
index 9835fe775943475e3a1f7bee698eb983e870c3cd..a009f759a87bd35b4147250b0fd520de81bf35d6 100644 (file)
@@ -1,34 +1,33 @@
 # -*- coding: utf-8 -*-
-#            CONFIGURATION MANAGEMENT OF EDF VERSION
-# ======================================================================
-# COPYRIGHT (C) 1991 - 2002  EDF R&D                  WWW.CODE-ASTER.ORG
-# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
-# IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
-# THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
-# (AT YOUR OPTION) ANY LATER VERSION.
+# Copyright (C) 2007-2013   EDF R&D
 #
-# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
-# WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
-# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
-# GENERAL PUBLIC LICENSE FOR MORE DETAILS.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
 #
-# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
-# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
-#    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
 #
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
-# ======================================================================
 """
-   Ce module contient le plugin generateur de fichier au format
-   SEP pour EFICAS.
+   Ce module contient le plugin generateur de fichier au format 
+   CARMEL3D pour EFICAS.
 
 """
 import traceback
 import types,string,re,os
+import Accas
 
 from generator_python import PythonGenerator
 
-
 def entryPoint():
    """
       Retourne les informations necessaires pour le chargeur de plugins
@@ -46,114 +45,61 @@ def entryPoint():
 class MapGenerator(PythonGenerator):
    """
       Ce generateur parcourt un objet de type JDC et produit
-      un texte au format eficas et
-      un texte au format py
+      un texte au format eficas et 
+      un texte au format py 
 
    """
-   # Les extensions de fichier permis?
-   extensions=('.map',)
-
-
-   def initialise(self,config):
-      self.config=config
-      self.nom_racine=self.config.PATH_STUDY+"/"+self.config.NAME_SCHEME+"/"
-      if not( os.path.exists(self.nom_racine)):
-         os.makedirs(self.nom_racine)
-      self.listeCODE=[]
-      self.text=""
-      self.textCode=""
-      self.texteExecution=""
-      self.ssCode=self.config.appli.ssCode
-
-   def verifie(self):
-      print 'verification generique'
 
    def gener(self,obj,format='brut',config=None):
-      print 'generation dans generator_map'
-      self.initialise(config)
-      text=PythonGenerator.gener(self,obj,format)
-      self.verifie()
-      self.generePythonMap("non")
-      return text
-
-   def generRUN(self,obj,format='brut',config=None,):
-      print 'generRUN dans generator_map'
-      self.initialise(config)
-      text=PythonGenerator.gener(self,obj,format)
-      self.verifie()
-      self.generePythonMap("oui") 
-      return self.texteExecution
+      self.initDico()
+      self.text=PythonGenerator.gener(self,obj,format)
+      if obj.isvalid() :self.genereExeMap()
+      return self.text
 
 
-   def generRUNYACS(self,obj,format='brut',config=None,nomFichier=None):
-      self.initialise(config)
-      text=PythonGenerator.gener(self,obj,format)
-      import sys
-      sys.path.append('/local/noyret/Salome_5.1.3/Install/YACS/lib/python2.5/site-packages/salome/')
-      self.verifie()
-      import monCreateYacs
-      self.monSchema=monCreateYacs.getSchema(config)
-      self.proc=self.monSchema.createProc()
-      for elt in self.listeCODE:
-          code=elt.keys()[0]
-          dico=elt[code]
-          if code in self.__class__.__dict__.keys():
-             codeYACS=str(code)+"YACS"
-             if hasattr(self.monSchema, codeYACS): 
-                fct=getattr(self.monSchema, codeYACS)
-                fct(self.proc,dico)
-      self.monSchema.write_yacs_proc(self.proc,str(nomFichier))
-
-   def generePythonMap(self,execution) :
+   def genereExeMap(self) :
       '''
-         self.dictMCVal est un dictionnaire qui est indexe par le nom du code (exple PYGMEE)
-         la valeur associee a la clef est egalement un dictionnaire 
-         ce dictionnaire a pour clef la genealogie du MCSimp suivi de sa valeur
-
+      Prepare le contenu du fichier de parametres python
+      peut ensuite etre obtenu au moyen de la fonction getTubePy().
       '''
-      for elt in self.listeCODE:
-          code=elt.keys()[0]
-          dico=elt[code]
-          self.dictMCVal={}
-          self.dictMCVal[code]=dico
-          if code in self.__class__.__dict__.keys():
-             texteCode=apply(self.__class__.__dict__[code],(self,execution))
-             self.texteExecution=self.texteExecution+texteCode
-
-   def generPROC_ETAPE(self,obj):
-      clefDico=obj.nom
-      self.DictTemp={}
-      s=PythonGenerator.generPROC_ETAPE(self,obj)
-      dico={}
-      dico[obj.nom]=self.DictTemp
-      self.listeCODE.append(dico)
-      return s
-
+      nomSpec="spec_"+self.schema
+      self.texteEXE="from map.spec import %s;\n"%nomSpec
+      self.texteEXE+="node=%s.new();\n"%nomSpec
+      self.texteEXE+="node.getInputData();\n"
+      self.texteEXE+="node.setInputData(%s);\n"%self.dictValeur
+      self.texteEXE+="node.execute();\n"
+      self.texteEXE+="res=node.getOutputData();\n"
+      
+
+   def initDico(self) :
+      if not hasattr(self,'schema') : self.schema=""
+      self.dictParam={}
+      self.dictValeur={}
+  
+   def writeDefault(self, fn):
+      fileEXE = fn[:fn.rfind(".")] + '.py'
+      f = open( str(fileEXE), 'wb')
+      f.write( self.texteEXE )
+      f.close()
 
    def generMCSIMP(self,obj) :
       """
       Convertit un objet MCSIMP en texte python
-      Remplit le dictionnaire des MCSIMP si nous ne sommes ni dans une loi, ni dans une variable
+      Remplit le dictionnaire des MCSIMP 
       """
+      
+      if obj.get_genealogie()[0][-6:-1]=="_PARA":
+         self.dictParam[obj.nom]=obj.valeur
+      else :
+         self.dictValeur[obj.nom]=obj.valeur
       s=PythonGenerator.generMCSIMP(self,obj)
-      clef=""
-      for i in obj.get_genealogie() :
-           clef=clef+"_"+i
-      self.DictTemp[clef]=obj.valeur
       return s
-
-
-   def  remplaceCONFIG(self,chaine,liste) :
-       for mot in liste :
-           rplact="%_"+mot+"%"
-           result=chaine.replace(rplact,self.config.__dict__[mot])
-           chaine=result
-       return chaine
-
-   def  remplaceDICO(self,chaine,dico) :
-       for mot in dico.keys() :
-           rplact="%"+mot+"%"
-           result=chaine.replace(rplact,str(dico[mot]))
-           chaine=result
-       return chaine
-
+  
+  
+   def generRUN(self,obj,schema):
+       if not(obj.isvalid()) :
+          print "TODO TODO TODO"
+       self.texteEXE=""
+       self.schema=schema
+       textComm=self.gener(obj)
+       return self.texteEXE