]> SALOME platform Git repositories - modules/adao.git/blob - src/daEficas/generator_adao.py
Salome HOME
La partie GUI peut de nouveau générer le schéma testBlue_000
[modules/adao.git] / src / daEficas / generator_adao.py
1 # -*- coding: utf-8 -*-
2 print "import generator_adao"
3
4 from generator.generator_python import PythonGenerator
5
6 def entryPoint():
7    """
8       Retourne les informations necessaires pour le chargeur de plugins
9
10       Ces informations sont retournees dans un dictionnaire
11    """
12    return {
13         # Le nom du plugin
14         'name' : 'adao',
15         # La factory pour creer une instance du plugin
16           'factory' : AdaoGenerator,
17           }
18
19 class AdaoGenerator(PythonGenerator):
20
21   def __init__(self,cr=None):
22     PythonGenerator.__init__(self, cr)
23     self.dictMCVal={}
24     self.text_comm = ""
25     self.text_da = ""
26     self.text_da_status = False
27
28   def gener(self,obj,format='brut',config=None):
29     print "AdaoGenerator gener"
30     self.text_comm = PythonGenerator.gener(self, obj, format, config)
31
32     print "Dictionnaire"
33     print self.dictMCVal
34
35     try :
36       self.text_da_status = False
37       self.generate_da()
38       self.text_da_status = True
39     except:
40       print "Case seems not be correct"
41       pass
42     return self.text_comm
43
44   def writeDefault(self, fn):
45     if self.text_da_status:
46       print "write adao python command file"
47       filename = fn[:fn.rfind(".")] + '.py'
48       f = open( str(filename), 'wb')
49       f.write( self.text_da )
50       f.close()
51
52   def generMCSIMP(self,obj) :
53     """
54     Convertit un objet MCSIMP en texte python
55     """
56     clef=""
57     for i in obj.get_genealogie() :
58       clef=clef+"__"+i
59     self.dictMCVal[clef]=obj.valeur
60
61     s=PythonGenerator.generMCSIMP(self,obj)
62     return s
63
64   def generMCFACT(self,obj):
65
66    if obj.parent.nom == "ALGORITHM":
67      self.dictMCVal["ALGORITHM_NAME"] = obj.nom
68
69    s=PythonGenerator.generMCFACT(self,obj)
70    return s
71
72   def generate_da(self):
73
74     self.text_da += "#-*-coding:iso-8859-1-*- \n"
75     self.text_da += "study_config = {} \n"
76     self.text_da += "study_config[\"Name\"] = \"" + self.dictMCVal["__ASSIM_STUDY__STUDY_NAME"] + "\"\n"
77     self.text_da += "study_config[\"Algorithm\"] = \"" + self.dictMCVal["ALGORITHM_NAME"] + "\"\n"
78
79
80     self.add_data("Background")
81     self.add_data("BackgroundError")
82     self.add_data("Observation")
83     self.add_data("ObservationError")
84     self.add_data("ObservationOperator")
85
86     # Optionnel
87     self.add_analysis()
88
89   def add_data(self, data_name):
90     search_text = "__ASSIM_STUDY__ALGORITHM__" + self.dictMCVal["ALGORITHM_NAME"] + "__"
91     back_search_text = search_text + data_name + "__"
92
93     # Data is a Vector
94     search_vector = back_search_text + "Vector"
95     if search_vector + "__FROM" in self.dictMCVal:
96       back_from = self.dictMCVal[search_vector + "__FROM"]
97
98       search_string = search_vector + "__STRING_DATA__STRING"
99       search_script = search_vector + "__SCRIPT_DATA__SCRIPT_FILE"
100
101       # Vector is from a string
102       if search_string in self.dictMCVal:
103         back_data = self.dictMCVal[search_string]
104       # Vector is from a script
105       elif search_script in self.dictMCVal:
106         back_data = self.dictMCVal[search_script]
107       else:
108         print "[generator adao] Error cannot found Vector data"
109
110       self.text_da += data_name + "_config = {} \n"
111       self.text_da += data_name + "_config[\"Type\"] = \"Vector\" \n"
112       self.text_da += data_name + "_config[\"From\"] = \"" + back_from + "\" \n"
113       self.text_da += data_name + "_config[\"Data\"] = \"" + back_data + "\" \n"
114       self.text_da += "study_config[\"" + data_name + "\"] = " + data_name + "_config \n"
115       return 1
116
117     # Data is a Matrix
118     search_matrix = back_search_text + "Matrix"
119     if search_matrix + "__FROM" in self.dictMCVal:
120       back_from = self.dictMCVal[search_matrix + "__FROM"]
121
122       search_string = search_matrix + "__STRING_DATA__STRING"
123       search_script = search_matrix + "__SCRIPT_DATA__SCRIPT_FILE"
124
125       # Matrix is from a string
126       if search_string in self.dictMCVal:
127         back_data = self.dictMCVal[search_string]
128       # Matrix is from a script
129       elif search_script in self.dictMCVal:
130         back_data = self.dictMCVal[search_script]
131       else:
132         print "[generator adao] Error cannot found Matrix data"
133
134       self.text_da += data_name + "_config = {} \n"
135       self.text_da += data_name + "_config[\"Type\"] = \"Matrix\" \n"
136       self.text_da += data_name + "_config[\"From\"] = \"" + back_from + "\" \n"
137       self.text_da += data_name + "_config[\"Data\"] = \"" + back_data + "\" \n"
138       self.text_da += "study_config[\"" + data_name + "\"] = " + data_name + "_config \n"
139       return 1
140
141   def add_analysis(self):
142     search_text = "__ASSIM_STUDY__ALGORITHM__" + self.dictMCVal["ALGORITHM_NAME"] + "__Analysis__"
143     try :
144       ana_from = self.dictMCVal[search_text + "FROM"]
145
146       if ana_from == "String":
147         ana_data = self.dictMCVal[search_text + "STRING_DATA__STRING"]
148         self.text_da += "Analysis_config = {} \n"
149         self.text_da += "Analysis_config[\"From\"] = \"String\" \n"
150         self.text_da += "Analysis_config[\"Data\"] = \"\"\"" + ana_data + "\"\"\" \n"
151         self.text_da += "study_config[\"Analysis\"] = Analysis_config \n"
152         pass
153       if ana_from == "Script":
154         ana_data = self.dictMCVal[search_text + "SCRIPT_DATA__SCRIPT_FILE"]
155         self.text_da += "Analysis_config = {} \n"
156         self.text_da += "Analysis_config[\"From\"] = \"Script\" \n"
157         self.text_da += "Analysis_config[\"Data\"] = \"" + ana_data + "\" \n"
158         self.text_da += "study_config[\"Analysis\"] = Analysis_config \n"
159         pass
160     except:
161       pass
162