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