Salome HOME
gitignore V1
[tools/eficas.git] / generator / generator_map.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 import Accas
28
29 from generator_python import PythonGenerator
30
31 def entryPoint():
32    """
33       Retourne les informations necessaires pour le chargeur de plugins
34
35       Ces informations sont retournees dans un dictionnaire
36    """
37    return {
38         # Le nom du plugin
39           'name' : 'MAP',
40         # La factory pour creer une instance du plugin
41           'factory' : MapGenerator,
42           }
43
44
45 class MapGenerator(PythonGenerator):
46    """
47       Ce generateur parcourt un objet de type JDC et produit
48       un texte au format eficas et 
49       un texte au format py 
50
51    """
52
53    def gener(self,obj,format='brut',config=None):
54       self.initDico()
55       self.text=PythonGenerator.gener(self,obj,format)
56       if obj.isvalid() :self.genereExeMap()
57       return self.text
58
59
60    def genereExeMap(self) :
61       '''
62       Prepare le contenu du fichier de parametres python
63       peut ensuite etre obtenu au moyen de la fonction getTubePy().
64       '''
65       nomSpec="spec_"+self.schema
66       self.texteEXE="from map.spec import %s;\n"%nomSpec
67       self.texteEXE+="node=%s.new();\n"%nomSpec
68       self.texteEXE+="node.getInputData();\n"
69       self.texteEXE+="node.setInputData(%s);\n"%self.dictValeur
70       self.texteEXE+="node.execute();\n"
71       self.texteEXE+="res=node.getOutputData();\n"
72       
73
74    def initDico(self) :
75       if not hasattr(self,'schema') : self.schema=""
76       self.dictParam={}
77       self.dictValeur={}
78   
79    def writeDefault(self, fn):
80       fileEXE = fn[:fn.rfind(".")] + '.py'
81       f = open( str(fileEXE), 'wb')
82       f.write( self.texteEXE )
83       f.close()
84
85    def generMCSIMP(self,obj) :
86       """
87       Convertit un objet MCSIMP en texte python
88       Remplit le dictionnaire des MCSIMP 
89       """
90       
91       if obj.get_genealogie()[0][-6:-1]=="_PARA":
92          self.dictParam[obj.nom]=obj.valeur
93       else :
94          self.dictValeur[obj.nom]=obj.valeur
95       s=PythonGenerator.generMCSIMP(self,obj)
96       return s
97   
98   
99    def generRUN(self,obj,schema):
100        if not(obj.isvalid()) :
101           print "TODO TODO TODO"
102        self.texteEXE=""
103        self.schema=schema
104        textComm=self.gener(obj)
105        return self.texteEXE