Salome HOME
debug intempestif
[tools/eficas.git] / Efi2Xsd / MCAccasXML.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2021   EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 import sys,os
23 import inspect
24 import traceback
25 def trace():
26     traceback.print_stack()
27 #import raw.efficas as efficas
28 import types
29
30 sys.path.insert(0,os.path.abspath(os.path.join(os.getcwd(),'..')))
31
32 try :
33     import pyxb
34     import pyxb.binding
35     import pyxb.binding.basis
36     #import pyxb.utils.utility
37     #import pyxb.utils.domutils
38 except : pass
39
40 from Accas import A_ASSD
41
42 class X_OBJECT:
43 # -------------
44
45     def delObjPyxb(self, debug=False):
46         if not self.cata or not self.cata.modeleMetier : return
47         if self.nom == 'Consigne' : return None
48         trouve = False
49
50         if debug : print ('--------------- in delObjPyxb pour ' , self.nom)
51         if debug : print (self.perePyxb.objPyxb.orderedContent())
52         if debug : print (list(map(lambda o:o.value, self.perePyxb.objPyxb.orderedContent())))
53
54         elt=pyxb.binding.basis.ElementContent(self.objPyxb, instance=self.perePyxb.objPyxb, tag=pyxb.namespace.ExpandedName(self.cata.modeleMetier.Namespace, self.nom))
55         if debug : print ('element moi = ', elt, 'id de moi = ', id(self.objPyxb), self.objPyxb)
56         if (elt.elementDeclaration.isPlural()):
57             if debug : print ('je suis Plural')
58         #   monIndexInOrderedContent=0
59         #   for c in self.perePyxb.objPyxb.orderedContent():
60         #     if isinstance(c._Content__value,list) and  isinstance(c._Content__value[0], type(self.objPyxb)): monIndexInOrderedContent += 1
61         #   listeObjetsAccas=self.parent.getChild(self.nom,restreint='oui')
62         #   if len(listeObjetsAccas) == 1 : monIndex=0
63         #   else : monIndex=listeObjetsAccas.index(self)
64         #   listeObjetsPyxb=getattr(self.perePyxb.objPyxb,elt.elementDeclaration._ElementDeclaration__key)
65         #   listeObjetsPyxb.pop(monIndex)
66         #   self.perePyxb.objPyxb.orderedContent().pop(monIndexInOrderedContent)
67             for c in self.perePyxb.objPyxb.orderedContent():
68                 trouve=False
69                 if isinstance(c._Content__value,list) and  isinstance(c._Content__value[0],type(self.objPyxb)):
70                     monIndex=c.value.index(self.objPyxb)
71                     trouve = True
72                 if trouve : break
73             if not trouve : print ("************ pas trouve au delete"); return
74             listeObjetsPyxb=getattr(self.perePyxb.objPyxb,elt.elementDeclaration._ElementDeclaration__key)
75             listeObjetsPyxb.pop(monIndex)
76             # si dernier ?
77         else :
78             newOrderedContent = []
79             for i in self.perePyxb.objPyxb.orderedContent():
80                 if id(self.objPyxb) == id(i._Content__value) : trouve = True ;continue
81                 newOrderedContent.append(i)
82             if not trouve : print ('elt a supprimer ', self.nom, 'non trouve')
83             for i in range(len(newOrderedContent)):
84                 self.perePyxb.objPyxb.orderedContent()[i]=newOrderedContent[i]
85             self.perePyxb.objPyxb.orderedContent().pop(len(newOrderedContent))
86
87             setattr(self.perePyxb.objPyxb,elt.elementDeclaration._ElementDeclaration__key,None)
88             if debug : print (list(map(lambda o:o.value, self.perePyxb.objPyxb.orderedContent())))
89
90
91
92     def addObjPyxb(self,indiceDsLeContenu,debug=False):
93         if not self.cata or not self.cata.modeleMetier : return
94         if debug :print ('_____________ addObjPyxb ds X_OBJECT', self.nom, indiceDsLeContenu)
95         # adherence Accas sur le parent
96         parent=self.parent
97         while (parent.isBLOC()):
98             if parent != self.parent : indiceDsLeContenu += parent.rangDsPyxb()
99             parent=parent.parent
100         self.perePyxb=parent
101
102         if debug :print ('indiceDsLeContenu',indiceDsLeContenu)
103         if debug :print (pyxb.namespace.ExpandedName(self.cata.modeleMetier.Namespace, self.nom))
104
105         #if self.objPyxb ! = None : self.objPyxb.objAccas=self
106         elt=pyxb.binding.basis.ElementContent(self.objPyxb, instance=self.perePyxb.objPyxb, tag=pyxb.namespace.ExpandedName(self.cata.modeleMetier.Namespace, self.nom))
107         self.perePyxb.objPyxb.orderedContent().insert(indiceDsLeContenu,elt)
108         if (elt.elementDeclaration.isPlural()):
109         # je suis donc un MCList
110             listeObjetsAccas=self.parent.getChild(self.nom,restreint='oui')
111             if len(listeObjetsAccas) == 1 : monIndex=1
112             else : monIndex=listeObjetsAccas.index(self)
113             listeObjetsPyxb=getattr(self.perePyxb.objPyxb,elt.elementDeclaration._ElementDeclaration__key)
114             listeObjetsPyxb.insert(monIndex,self.objPyxb)
115         else :
116             setattr(self.perePyxb.objPyxb,elt.elementDeclaration._ElementDeclaration__key,self.objPyxb)
117         if debug : print (list(map(lambda o:o.value, self.perePyxb.objPyxb.orderedContent())))
118         if debug : print ('fin _____________ addObjPyxb ds X_OBJECT', self.nom, indiceDsLeContenu)
119
120
121     def rangDsPyxb(self):
122         monRangEnAccas=self.parent.mcListe.index(self)
123         rangEnPyxb=0
124         for frere in self.parent.mcListe[0: monRangEnAccas] :
125             rangEnPyxb += frere.longueurDsArbre()
126         return rangEnPyxb
127
128
129 class X_MCSIMP(X_OBJECT):
130 # -----------------------
131
132     def buildObjPyxb(self, debug=True) :
133         if not self.cata or not self.cata.modeleMetier : return
134         if self.nom == 'Consigne' : return None
135         if debug : print (self.definition.nomComplet())
136         if debug : print ('_______________ X_MCSIMP buildObjPyxb', self.nom, self,self.valeur)
137         if debug and self.objPyxbDeConstruction == None : print (self.nom, ' pas de pyxb')
138         elif debug : print ('objPyxbDeConstruction', self.objPyxbDeConstruction)
139
140         if self.objPyxbDeConstruction != None :
141             self.objPyxb = self.objPyxbDeConstruction
142             self.maClasseModeleMetier =type(self.objPyxb)
143             self.objPyxbDeConstruction = None
144             if issubclass(self.maClasseModeleMetier, self.cata.modeleMetier.pyxb.binding.basis.STD_union):
145                 self.needFactory=True
146                 self.maClasseModeleMetierFactory=getattr(self.maClasseModeleMetier,'Factory')
147             else : self.needFactory=False
148         else :
149             self.monNomClasseModeleMetier ='T_'+self.nom
150             if hasattr(self.definition,'nomXML') and self.definition.nomXML != None : self.monNomClasseModeleMetier='T_'+self.definition.nomXML
151             if self.monNomClasseModeleMetier in list(self.cata.DicoNomTypeDifferentNomElt.keys()) :
152                 nomComplet=self.definition.nomComplet()
153                 if nomComplet in list(self.cata.DicoNomTypeDifferentNomElt[self.monNomClasseModeleMetier].keys()):
154                     self.monNomClasseModeleMetier=self.cata.DicoNomTypeDifferentNomElt[self.monNomClasseModeleMetier][nomComplet]
155             if debug : print ('Pour', self.nom, ' le type est ', self.monNomClasseModeleMetier)
156             self.maClasseModeleMetier=getattr(self.cata.modeleMetier,self.monNomClasseModeleMetier)
157
158             if self.waitMatrice() :
159                #PNPN : Attention rien ne relie les objets listeObjPyxb a un objAccas
160                # 27/04 je ne sais pas si cela posera pb
161                self.listeLines = []
162                self.maClasseModeleMetier=getattr(self.cata.modeleMetier,self.monNomClasseModeleMetier)
163                self.maClasseModeleMetier_line=getattr(self.cata.modeleMetier,self.monNomClasseModeleMetier+'_line')
164                if debug : print ('Matrice  de type ', self.maClasseModeleMetier)
165                for v in self.valeur: 
166                    l=self.maClasseModeleMetier_line(v)
167                    self.listeLines.append(l)
168                self.objPyxb=self.maClasseModeleMetier(*self.listeLines)
169                #if self.objPyxb !=None : self.objPyxb.objAccas=self
170                if debug : print ('Matrice ', self.nom, self.objPyxb)
171                return
172             if self.waitTuple() :
173                self.objPyxb = []
174                self.maClasseModeleMetier=getattr(self.cata.modeleMetier,self.monNomClasseModeleMetier)
175                # if faut traiter l autre cas
176                # et optimiser
177                if self.definition.max !=1 :
178                   for v in self.valeur :
179                     if debug : print ('je traite ', v)
180                     listeConstruction=[]
181                     for i in range(self.combienEltDsTuple()):
182                         num=i+1
183                         maClasseElt=getattr(self.cata.modeleMetier,self.monNomClasseModeleMetier+'_n'+str(num))
184                         listeConstruction.append(maClasseElt(v[i]))
185                     self.objPyxb.append(self.maClasseModeleMetier(*listeConstruction))
186                     if debug  : print (self.objPyxb)
187                   return
188             if self.waitChaineAvecBlancs() and self.definition.max > 1:
189                self.maClasseModeleMetier=getattr(self.cata.modeleMetier,self.monNomClasseModeleMetier)
190                print (self.valeur)
191                self.objPyxb = self.maClasseModeleMetier(*self.valeur)
192                if debug : print ('X_MCSIMP', self.nom, self.objPyxb, )
193                if debug : print ('__________ fin X_MCSIMP', self.objPyxb, self.nom, self, self.maClasseModeleMetier,self.valeur)
194                return
195
196                         
197             if issubclass(self.maClasseModeleMetier, self.cata.modeleMetier.pyxb.binding.basis.STD_union):
198                 if debug : print ('needFactory')
199                 self.needFactory=True
200                 self.maClasseModeleMetierFactory=getattr(self.maClasseModeleMetier,'Factory')
201             else : self.needFactory=False
202
203             if self.valeur != None :
204                 if self.needFactory :
205                     if self.definition.max > 1 :
206                        # PNPN A corriger 
207                        # self.objPyxb=self.maClasseModeleMetier(self.valeur)
208                             self.objPyxb=self.maClasseModeleMetierFactory(self.valeur)
209                     else :  self.objPyxb=self.maClasseModeleMetierFactory(self.valeur)
210                 else                :  self.objPyxb=self.maClasseModeleMetier(self.valeur)
211             else                   :
212                 if self.needFactory : self.objPyxb=None
213                 else                : self.objPyxb=self.maClasseModeleMetier(_validate_constraints=False)
214
215
216             #if self.objPyxb !=None : self.objPyxb.objAccas=self
217         if debug : print ('X_MCSIMP', self.nom, self.objPyxb, )
218         if debug : print ('__________ fin X_MCSIMP', self.objPyxb, self.nom, self, self.maClasseModeleMetier,self.valeur)
219
220
221     def setValeurObjPyxb(self,newVal, debug=False):
222         if not self.cata or not self.cata.modeleMetier : return
223         if debug : print (' ___________________________ dans setValeurObjPyxb MCSIMP ', self.nom, newVal)
224         if debug : print (' self.perePyxb = ', self.perePyxb.nom)
225         if debug : print (self.nom , ' a pour pere', self.perePyxb, self.perePyxb.nom, self.perePyxb.objPyxb)
226         if debug : print ('debut du setValeurObjPyxb pour ', self.nom, self.perePyxb.objPyxb.orderedContent())
227
228         #if newVal != None : nvlObj=self.maClasseModeleMetier(newVal)
229         if newVal != None :
230             if self.needFactory : nvlObj=self.maClasseModeleMetierFactory(newVal)
231             else                : nvlObj=self.maClasseModeleMetier(newVal)
232         else                   :
233             if self.needFactory : nvlObj =None
234             else                : nvlObj=self.maClasseModeleMetier(_validate_constraints=False)
235         self.val=newVal
236         if debug : print ('fin du setValeurObjPyxb pour ', self.nom, self.perePyxb.objPyxb.orderedContent())
237
238         if inspect.isclass(newVal) and issubclass(newVal,A_ASSD)  :
239             newVal = newVal.nom
240         setattr(self.perePyxb.objPyxb,self.nom,nvlObj)
241         trouve=False
242         indice=0
243         for i in self.perePyxb.objPyxb.orderedContent():
244             if i.elementDeclaration.id() == self.nom:
245             #if isinstance(i._Content__value, self.maClasseModeleMetier) :
246                 self.perePyxb.objPyxb.orderedContent()[indice]=self.perePyxb.objPyxb.orderedContent()[-1]
247                 del(self.perePyxb.objPyxb.orderedContent()[-1])
248                 trouve=True
249                 break
250             indice+=1
251         if not trouve : print ('Attention souci au changement de valeur de ', self.nom)
252         self.objPyxb=nvlObj
253         #self.objPyxb.objAccas=self
254         if debug : print ('fin du setValeurObjPyxb pour ', self.nom, self.perePyxb.objPyxb.orderedContent())
255
256
257
258
259 class X_MCCOMPO(X_OBJECT) :
260 # -------------------------
261 #
262     def buildObjPyxb(self,mc_list, debug=False) :
263         if not self.cata or not self.cata.modeleMetier : return
264
265         #if self.nom == 'Scenario_data' : debug=1
266         if debug : print ('X_MCCOMPO', self.nom)
267         deepDebug=False
268         self.listArg=[]
269         self.dicoArg={}
270         for objAccas in mc_list :
271             if objAccas.nature == 'MCBLOC' :
272                 self.exploreBLOC(objAccas)
273             elif objAccas.nature == 'MCList' :
274                 if objAccas[0].definition.max > 1 :
275                     self.listArg.append(objAccas) # les MCList n ont pas objPyxb
276                     self.dicoArg[objAccas.nom]=[]
277                     for fils in objAccas :
278                         fils.perePyxb=self
279                         self.dicoArg[objAccas.nom].append(fils.objPyxb)
280                 else :
281                     objAccas[0].perePyxb=self
282                     self.dicoArg[objAccas.nom]=objAccas[0].objPyxb
283                     self.listArg.append(objAccas[0].objPyxb)
284             else :
285                 if objAccas.nom == 'Consigne'     : continue
286                 print ('______________', objAccas.nom, objAccas.objPyxb)
287                 self.listArg.append(objAccas.objPyxb)
288                 self.dicoArg[objAccas.nom]=objAccas.objPyxb
289                 objAccas.perePyxb=self
290
291         if debug : print('X_MCCOMPO -- listArg ---',self.nom,self.listArg)
292         if debug : print('X_MCCOMPO -- dicoArg ---',self.nom,self.dicoArg)
293
294
295         self.monNomClasseModeleMetier='T_'+self.nom
296         if self.monNomClasseModeleMetier in list(self.cata.DicoNomTypeDifferentNomElt.keys()) :
297             self.nomComplet=self.definition.nomComplet()
298             self.monNomClasseModeleMetier=self.cata.DicoNomTypeDifferentNomElt[self.monNomClasseModeleMetier][self.nomComplet]
299         self.maClasseModeleMetier=getattr(self.cata.modeleMetier,self.monNomClasseModeleMetier)
300
301         # PN : Ne doit-on pas tester avant
302         if self.objPyxbDeConstruction != None :
303             self.objPyxb = self.objPyxbDeConstruction
304             self.objPyxbDeConstruction = None
305             if debug : print ('je passe dans le if pour ', self.nom, self.objPyxb, self)
306             if debug : print ('X_MCCOMPO', self, self.nom, self.objPyxb,self.listArg,self.objPyxb.orderedContent())
307         else :
308             if debug : print (self.listArg)
309             if debug : print (self.maClasseModeleMetier)
310             # self.objPyxb=self.maClasseModeleMetier(*self.listArg)
311             self.objPyxb=self.maClasseModeleMetier(**self.dicoArg)
312             if deepDebug :
313                 print ('debut de __________ new ordered content')
314                 for o in self.objPyxb.orderedContent():
315                     print ('o', o)
316                     print ('value', o.value)
317                     print ('type', type(o.value))
318                     print ('id', id(o.value))
319                 print ('fin __________ new ordered content')
320                 print ('debut de  __________ listArg')
321                 for obj in self.listArg:
322                     print ('obj',obj)
323                     print ('type obj', type(obj))
324                     print ('id(obj)', id(obj))
325                 print ('fin __________  listArg')
326
327             newOrderedContent=[]
328             if debug  : print ('list Arg')
329             for obj in self.listArg:
330                 if debug :
331                     print ('obj',obj)
332                     print ('type obj', type(obj))
333                     print ('id(obj)', id(obj))
334
335                 # on teste le caractere pluriel
336                 if  isinstance(obj, list):
337                     for c in self.objPyxb.orderedContent() :
338                         if hasattr (c,'value') and c.value == obj :
339                            newOrderedContent.append(c)
340                     continue
341                 if (hasattr(obj, 'nature')) : # attention on a un object Accas et non un pyxb car les MCList n ont pas de objPyxb
342                     max=obj[0].definition.max
343                 else : max = 1
344                 if  max == 1 :
345                     #if not(issubclass(type(obj), pyxb.binding.basis.enumeration_mixin) ):
346                     #   newOrderedContent.append(self.objPyxb.orderedContent()[list(map(lambda o:id(o.value), self.objPyxb.orderedContent())).index(id(obj))] )
347                     #else :
348                     #   newOrderedContent.append(self.objPyxb.orderedContent()[list(map(lambda o:type(o.value), self.objPyxb.orderedContent())).index(type(obj))] )
349                     # PN 22 sept 2020 . pourquoi pas toujours l id. le tyoe ne convient pas en cas d union d enum
350                     newOrderedContent.append(self.objPyxb.orderedContent()[list(map(lambda o:id(o.value), self.objPyxb.orderedContent())).index(id(obj))] )
351                 else  : # element Pural
352                     for c in self.objPyxb.orderedContent() :
353                         if isinstance(c._Content__value,list) and  isinstance(c._Content__value[0], type(obj[0].objPyxb)): newOrderedContent.append(c)
354
355             for i in range(len(self.listArg)):
356                 self.objPyxb.orderedContent()[i]=newOrderedContent[i]
357             debug=True
358             if debug : print ('X_MCCOMPO', self, self.nom, self.objPyxb)
359             if debug : print ('X_MCCOMPO', self.listArg)
360             if debug : print ('X_MCCOMPO', newOrderedContent)
361             if debug : print ( 'X_MCCOMPO',self.objPyxb.orderedContent())
362         if debug : print ('fin buildObjetPyxb _______________________________________')
363         # assert(self.objPyxb.validateBinding())
364
365
366     def exploreBLOC(self,objAccas,debug=False):
367         if debug : print (' ds exploreBLOC', objAccas.nom)
368         laListeSsLesBlocs=[]
369         for fils in objAccas.mcListe:
370             if fils.nature == 'MCBLOC' :
371                 self.exploreBLOC(fils)
372             elif fils.nature == 'MCList' :
373                 #print ('exploreBLOC des MCList', fils.nom)
374                 self.dicoArg[fils.nom]=[]
375                 if fils[0].definition.max > 1 :
376                     #print ('ajout de ', fils)
377                     self.listArg.append(fils) # les MCList n ont pas objPyxb
378                     for objFils in fils :
379                         objFils.perePyxb=self
380                         self.dicoArg[fils.nom].append(objFils.objPyxb)
381                 else:
382                     fils[0].perePyxb=self
383                     self.dicoArg[fils.nom]=fils[0].objPyxb
384                     self.listArg.append(fils[0].objPyxb)
385             else :
386                 if fils.nom == "Consigne" : continue
387                 self.listArg.append(fils.objPyxb)
388                 self.dicoArg[fils.nom]=fils.objPyxb
389                 fils.perePyxb=self
390                 if debug : print (fils.nom ,' est un SIMP a pour pere Pyxb', self, self.nom)
391         if debug : print ('fin  ds exploreBLOC', objAccas .nom)
392
393
394
395
396 class X_MCBLOC (X_MCCOMPO):
397 # --------------------------
398     def buildObjPyxb(self,mc_list,debug=False):
399         if not self.cata or not self.cata.modeleMetier : return
400         if debug : print ('X_MCBLOC buildObjPyxb', self.nom, self, mc_list, 'ne fait rien')
401         self.perePyxb=None
402         self.objPyxb=None
403
404     def addObjPyxb(self, indiceDsLeContenu, debug=False):
405         if not self.cata or not self.cata.modeleMetier : return
406         if debug : print ('X_MCBLOC addObjPyxb', self.nom, self, self.mcListe, indiceDsLeContenu)
407         rangDeLObjet=indiceDsLeContenu
408         for obj in self.mcListe:
409             obj.addObjPyxb( rangDeLObjet)
410             rangDeLObjet=rangDeLObjet+obj.longueurDsArbre()
411
412     def delObjPyxb(self, debug=False):
413         if not self.cata or not self.cata.modeleMetier : return
414         if debug : print ('X_MCBLOC delObjPyxb', self.nom, ' --------------------------')
415         for obj in self.mcListe:
416             obj.delObjPyxb()
417         if debug : print ('fin X_MCBLOC delObjPyxb --------------------------')
418
419 class X_MCLIST (X_MCCOMPO):
420 # --------------------------
421
422     def buildObjPyxb(self,mc_list, debug=False):
423         if debug : print ('X_MCLIST buildObjPyxb ne fait rien', self.nom, self, mc_list)
424         pass
425
426     def addObjPyxb(self,indiceDsLeContenu, debug=False):
427         if debug : print ('X_MCLIST addObjPyxb', self.nom, indiceDsLeContenu)
428         rangDeLObjet=indiceDsLeContenu
429         for objFils in self :
430             objFils.addObjPyxb(rangDeLObjet)
431             rangDeLObjet= rangDeLObjet + 1
432
433     def delObjPyxb(self, debug=False):
434         if not self.cata or not self.cata.modeleMetier : return
435         if debug : print ('X_MCLIST delObjPyxb', self.nom, ' --------------------------')
436         for obj in self:
437             obj.delObjPyxb()
438         if debug : print ('fin X_MCLIST delObjPyxb --------------------------')
439
440
441 class X_MCFACT (X_MCCOMPO):
442 # -------------------------
443     pass
444
445 class X_ETAPE(X_MCCOMPO) :
446 # -------------------------
447
448     def metAJourNomASSD(self, nom,debug=False):
449         if not self.cata or not self.cata.modeleMetier : return
450         if debug : print ('X_ETAPE metAJourLesAttributs', self.nom, nom,' --------------------------')
451         self.objPyxb.sdName=nom
452
453 class X_JDC (X_MCCOMPO):
454 # ---------------------
455
456     def  __init__(self):
457         self.perePyxb=None
458         if not self.cata or not self.cata.modeleMetier : return
459         #if hasattr(self.cata,'DicoNomTypeDifferentNomElt') : print ('jkllllllllllllllll')
460         if not(hasattr(self.cata,'DicoNomTypeDifferentNomElt')) : self.cata.DicoNomTypeDifferentNomElt={}
461         self.monNomClasseModeleMetier=self.code
462         self.maClasseModeleMetier=getattr(self.cata.modeleMetier,self.monNomClasseModeleMetier)
463         self.objPyxb=self.maClasseModeleMetier()
464         #self.objPyxb.objAccas=self
465         pyxb.GlobalValidationConfig._setContentInfluencesGeneration(pyxb.GlobalValidationConfig.NEVER)
466         pyxb.GlobalValidationConfig._setInvalidElementInContent(pyxb.GlobalValidationConfig.RAISE_EXCEPTION)
467         pyxb.GlobalValidationConfig._setOrphanElementInContent(pyxb.GlobalValidationConfig.RAISE_EXCEPTION)
468
469
470
471     def enregistreEtapePyxb(self,etape,indice=0):
472       # ne fonctionne pas : a reecrire avec les fonctions addObjPyxb et ReconstruitPerePyxb
473       # ne contient pas indice pour l insant
474       # print ( 'hhhhhhhhhhhhhhh enregistreEtapePyxb hhhhhhhhhhhhhhhhhhhhhhhhh')
475       # print ('enregistre ds ',self, etape.nom, 'indice = ', indice)
476         if not self.cata.modeleMetier : return
477         self.objPyxb.append(etape.objPyxb)
478         etape.perePyxb = self
479
480         #print (self.objPyxb.orderedContent())
481         #if indice   != (len(self.objPyxb.orderedContent()) ) :
482         #  tampon=self.objPyxb.orderedContent()[-1]
483         #  for i in reversed(range(len(self.objPyxb.orderedContent()))):
484         #    self.objPyxb.orderedContent()[i]=self.objPyxb.orderedContent()[i-1]
485         #    if i == indice + 1 : break
486         #  self.objPyxb.orderedContent()[indice]=tampon
487
488         #print (self.objPyxb.orderedContent())
489         #try:
490         #   self.objPyxb.validateBinding()
491         #except pyxb.ValidationError as e:
492         #   print(e.details())
493
494     def toXml(self,fichier=None, debug=False):
495         if debug : print ('ds to XML')
496         if not self.cata or not self.cata.modeleMetier : return
497         if debug : print (' to xml ***************',self.objPyxb,'***************',)
498         if debug : print (' to xml ***************',self,'***************',)
499         if debug : print (' to xml ***************',self.objPyxb.orderedContent(),'***************',)
500         if debug : print(self.objPyxb.toDOM().toprettyxml())
501         if debug : print(self.objPyxb.toxml())
502         return (self.objPyxb.toDOM().toprettyxml())
503
504
505     def analyseFromXML(self,debug=False):
506         print ("je suis ds analyseFromXML -- > appel ds analyseXML de I_JDC.py")
507         if self.procedure == "" : return
508         self.objPyxb=self.cata.modeleMetier.CreateFromDocument(self.procedure)
509         if not hasattr(self.cata.modeleMetier,'AccasUserAssd'):
510             from Accas import UserASSD
511             self.cata.modeleMetier.AccasUserAssd=UserASSD
512         for contentObjEtape in self.objPyxb.orderedContent():
513             objEtape=contentObjEtape.value
514             objEtape.dictArgs=(self.pyxbToDict(objEtape))
515             objEtape.monNomClasseAccas=objEtape._ExpandedName.localName()
516             objEtape.monNomClasseAccas=objEtape.monNomClasseAccas[2:]
517             # doute sur les 2 lignes suivantes : objEtape peut etre contentObjEtape 2juin20
518             objEtape.dictPyxb['objEnPyxb']=objEtape
519             objEtape.dictArgs['dicoPyxbDeConstruction']=objEtape.dictPyxb
520             if debug : print ('dicoPyxbDeConstruction', objEtape.dictArgs['dicoPyxbDeConstruction'])
521             maClasseAccas=getattr(self.cata,objEtape.monNomClasseAccas)
522             if debug : print ( 'hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh')
523             if debug : print ('maClasseAccas ', maClasseAccas)
524             if debug : print ('objEtape ', objEtape , type(objEtape))
525             if debug : print ('nomClasseAccas ',objEtape.monNomClasseAccas, type(objEtape.monNomClasseAccas))
526             if debug : print ('_ExpandedName ', objEtape._ExpandedName, type(objEtape._ExpandedName))
527             if debug : print ('dictArgs ',objEtape.dictArgs)
528             if debug : print ('dictPyxb ',objEtape.dictPyxb)
529             # attention au call d Oper qui renomme l objet pyxb
530             if hasattr(objEtape,'sdName') :
531                 if debug and hasattr(objEtape,'sdName') :print ('sdName',objEtape.sdName)
532                 objAccasEtape=maClasseAccas(nomXML=objEtape.sdName, **(objEtape.dictArgs))
533             else : objAccasEtape=maClasseAccas(**(objEtape.dictArgs))
534             if debug : print ( 'hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh')
535
536
537     def pyxbToDict(self,objAAnalyser, debug=True):
538         # la transformation de l objAAnalyser en type lu par eficas ne fonctionne pas pour tout
539         if objAAnalyser is None: return
540         if debug : print ('debut pour_____________________________ ',objAAnalyser)
541         dictArgs = {}
542         # traitement SIMP
543         # ---------------
544         # a revoir pour les matrices
545         # et les tuples
546         debug = 1
547         if isinstance(objAAnalyser, pyxb.binding.basis.simpleTypeDefinition):
548             if debug : print ('je suis un MCSimple', objAAnalyser)
549             # traitement scalaire
550             objAAnalyser.dictPyxb=objAAnalyser
551             if not (isinstance(objAAnalyser,pyxb.binding.basis.STD_list)):
552                 if debug :  print ('je suis un scalaire')
553                 if isinstance(objAAnalyser,self.cata.modeleMetier.AccasUserAssd) or isinstance(objAAnalyser,self.cata.modeleMetier.AccasUserAssdMultiple):
554                     if debug : print ('je suis un UserASSD')
555                     laClassePyxbUserAssd=type(objAAnalyser)
556                     return self.creeUserAssd(objAAnalyser,laClassePyxbUserAssd)
557                 if isinstance(objAAnalyser, pyxb.binding.datatypes.boolean) : return bool(objAAnalyser)
558                 if isinstance(objAAnalyser, str)  : return str(objAAnalyser)
559                 if isinstance(objAAnalyser, int)  : return int(objAAnalyser)
560                 if isinstance(objAAnalyser, float): return float(objAAnalyser)
561                 if isinstance(objAAnalyser, pyxb.binding.basis.enumeration_mixin):    return str(objAAnalyser)
562                 return objAAnalyser
563             else :
564                 if debug : print ('je suis une liste')
565                 laListe=[]
566                 # liste homogene
567                 if len(objAAnalyser)>0:
568                     if issubclass(objAAnalyser[0].__class__,self.cata.modeleMetier.AccasUserAssd) or issubclass(objAAnalyser[0].__class__,self.cata.modeleMetier.AccasUserAssdMultiple): estUnUserASSDorUserASSDMultiple = True
569                     else : estUnUserASSDorUserASSDMultiple=False
570                 else : estUnUserASSDorUserASSDMultiple=False
571                 if debug : print ('estUnUserASSDorUserASSDMultiple', estUnUserASSDorUserASSDMultiple)
572                 for obj in objAAnalyser :
573                     if estUnUserASSDorUserASSDMultiple:
574                        laClassePyxbUserAssd=obj.__class__
575                        laListe.append(self.creeUserAssd(obj,laClassePyxbUserAssd))
576                     elif isinstance(obj, str): laListe.append (str(obj))
577                     elif isinstance(obj, int): laListe.append (int(obj))
578                     elif isinstance(obj, float): laListe.append (float(obj))
579                     elif isinstance(obj, pyxb.binding.basis.enumeration_mixin): laListe.append(str(obj))
580                     else :  laListe.append(obj)
581                 return (laListe)
582             #  if debug : print ('je suis Plural')
583             # ou ? return objAAnalyser
584             #if isinstance(objAAnalyser, types.StringTypes): return pyxb.utils.utility.QuotedEscaped(objAAnalyser,)
585             #pour une enum getattr(value dans le type)
586             # return pythonLiteral(ReferenceFacet(facet=value, **kw))
587         #print ('je suis un mot complexe')
588         # traitement FACT ou BLOC
589         # ------------------------
590         # il faut traiter les fact multiples
591         objAAnalyser.dictPyxb = {}
592         objAAnalyser.dictPyxb['objEnPyxb']=objAAnalyser
593         #for expandedName, elementDeclaration in objAAnalyser._ElementMap.items():
594         #    objPyxbName  = expandedName.localName()
595         #    objPyxbValue = getattr(objAAnalyser, objPyxbName)
596         for objEltContentFils in objAAnalyser.orderedContent():
597             objPyxbValue = objEltContentFils.value
598             objPyxbName  = objEltContentFils.elementDeclaration.id()
599             elementDeclaration = objEltContentFils.elementDeclaration
600             #if objPyxbValue == None or objPyxbValue == [] : continue
601             if elementDeclaration.isPlural():
602                 if objPyxbName not in list(dictArgs.keys()) : dictArgs[objPyxbName]=[]
603                 if objPyxbName not in list(objAAnalyser.dictPyxb.keys()) : objAAnalyser.dictPyxb[objPyxbName]=[]
604                 dictArgs[objPyxbName].append(self.pyxbToDict(objPyxbValue))
605                 objAAnalyser.dictPyxb[objPyxbName].append(objPyxbValue.dictPyxb)
606             else:
607                 dictArgs[objPyxbName] = self.pyxbToDict(getattr(objAAnalyser, objPyxbName))
608                 objAAnalyser.dictPyxb[objPyxbName] = objPyxbValue.dictPyxb
609                 # print ('ajout dans dictPyxb', objPyxbName, objPyxbValue.dictPyxb)
610                 #print ('avec la valeur', 'de',  objAAnalyser.dictPyxb[objPyxbName])
611
612         #print ("***********************************")
613         #print ('pyxbToDict  fin pour ********** ', objAAnalyser)
614         #print ('pyxbToDict ', objAAnalyser, objAAnalyser.dictPyxb)
615         #print ('pyxbToDict  fin pour ********** ', objAAnalyser)
616         #print ("***********************************")
617         #print (dictArgs)
618         #print (dictPyxb)
619         #for i in dictArgs.keys(): print (i, " ", dictArgs[i], " ", type(dictArgs[i]))
620         #print ('fin pour ',objAAnalyser)
621         return dictArgs
622
623     def creeUserAssd(self,objAAnalyser,laClassePyxbUserAssd,debug=True):
624
625         enCreation=False
626         if debug : print ('creeUserAssd ', objAAnalyser, ' ',laClassePyxbUserAssd)
627         leTypeIntermediaire=laClassePyxbUserAssd.XsdSuperType()  
628         if debug : print ('leTypeIntermediaire ', leTypeIntermediaire)
629         if debug : print ('leTypeIntermediaire ', leTypeIntermediaire.XsdSuperType())
630         if leTypeIntermediaire.__name__[-2:]== '_C' : enCreation = True
631         elif leTypeIntermediaire.__name__[-2:] != '_U' : print ('pb avec', laClassePyxbUserAssd); return None #exit() 
632         nomClasseAccasUserAssd=leTypeIntermediaire.XsdSuperType().__name__
633         if debug : print ('nomClasseAccasUserAssd', nomClasseAccasUserAssd)
634         laClasseAccas=getattr(self.cata,nomClasseAccasUserAssd)
635         print (laClasseAccas)
636         if not(enCreation):
637             if str(objAAnalyser) in self.g_context.keys():return self.g_context[str(objAAnalyser)]
638             else :
639                 obj=laClasseAccas()
640                 self.g_context[str(objAAnalyser)]=obj
641                 return obj
642         if str(objAAnalyser) in self.g_context.keys():
643             if isinstance(self.g_context[str(objAAnalyser)],laClasseAccas):
644                 return self.g_context[str(objAAnalyser)]
645             else :
646                 nvlObj=laClasseAccas()
647                 oldObj=self.g_context[str(objAAnalyser)]
648                 nvlObj.transfere(oldObj)
649                 self.g_context[str(objAAnalyser)]=nvlObj
650                 return nvlObj
651         else :
652             obj=laClasseAccas()
653             self.g_context[str(objAAnalyser)]=obj
654             return obj
655
656 #   def analyseContent(self,objAAnalyser):
657 #       objAAnalyser.dictArgs={}
658 #       for objContenu in objAAnalyser.content():
659 #          #print ('j analyse ', objContenu)
660 #          objContenu.monNomClasseModeleMetier=str(objContenu.__class__).split('.')[-1]
661 #          objContenu.monNomClasseAccas=objContenu.monNomClasseModeleMetier[2:-2]
662 #          #maClasseAccas=classeAccasPere.entites[objContenu.monNomClasseAccas]
663 #          if objContenu._IsSimpleTypeContent():
664 #             print (objContenu.monNomClasseAccas,objContenu.pythonLiteral())
665 #             print (objContenu.monNomClasseAccas,objContenu.xsdLiteral())
666 #             #chaine=objContenu.pythonLiteral().split('(')[1].split(')')[0]
667 #             print (dir(objContenu))
668 #             objAAnalyser.dictArgs[objContenu.monNomClasseAccas]=None
669 #             #objAAnalyser.dictArgs[objContenu.monNomClasseAccas]=objContenu.pythonLiteral()
670 #          else :
671 #             self.analyseContent(objContenu)
672 #             objAAnalyser.dictArgs[objContenu.monNomClasseAccas]=objContenu.dictArgs
673             #print ( '________________')
674             #print (objAAnalyser.monNomClasseAccas)
675             #for i in objAAnalyser.dictArgs : print (i, objAAnalyser.dictArgs[i])
676             #print ( '________________')
677
678
679
680 if __name__ == "__main__":
681     print ('a faire')