2 # -*- coding: utf-8 -*-
3 # cette version ne fonctionne pas bien
10 from copy import deepcopy, copy
14 # CONTEXT est accessible (__init__.py de Noyau)
16 #import raw.efficas as efficas
17 sys.path.insert(0,os.path.abspath(os.path.join(os.getcwd(),'..')))
19 # ds l init du SIMP il manque siValide et fenetreIhm
21 from .mapDesTypes import dictSIMPEficasXML, dictSIMPXMLEficas
22 from .mapDesTypes import dictFACTEficasXML, dictFACTXMLEficas
23 from .mapDesTypes import dictPROCEficasXML, dictPROCXMLEficas
24 from .mapDesTypes import dictOPEREficasXML, dictOPERXMLEficas
25 from .mapDesTypes import dictBLOCEficasXML, dictBLOCXMLEficas
26 from .mapDesTypes import dictPourCast, dictNomsDesTypes
27 from .mapDesTypes import listeParamDeTypeTypeAttendu, listeParamDeTypeStr, dictPourCast
28 from .mapDesTypes import listeParamTjsSequence, listeParamSelonType
29 from .mapDesTypes import Tuple
31 PourTraduction = False
33 from .balisesXSD import *
38 def adjoint(self, liste1, liste2):
39 #print ('adjoint', liste1, liste2)
43 newListe=deepcopy(elt1)
44 if elt2 != []: newListe.append(elt2)
48 def adjointUnMot(self, liste1, mot):
51 newListe=deepcopy(elt1)
56 def remplaceListeParContenuEtVide(self, liste1, liste2):
59 for eltListe in liste2:
60 newListe=deepcopy(elt1)
61 if eltListe!=[] :newListe+=eltListe
62 if newListe not in listeFinale : listeFinale.append(newListe)
65 #def remplaceNomListeParContenu(self, liste1, liste2):
66 #print ('remplaceNomListeParContenu', liste1, liste2)
68 # for elt1 in liste1 :
69 # for eltListe in liste2:
70 # if eltListe == [] : continue
71 # newListe=deepcopy(elt1)
72 # if eltListe!=[] :newListe+=eltListe
73 # listeFinale.append(newListe)
74 #print ('listeFinale', listeFinale)
77 def fusionne2Listes(self, liste1, liste2):
78 #print ('fusionne2Liste', liste1, liste2)
81 for eltListe in liste2:
82 newListe=deepcopy(elt1)
83 if eltListe!=[] :newListe.append(eltListe)
84 listeFinale.append(newListe)
88 def getNomDuCodeDumpe(self):
89 if hasattr(self,'nomDuCodeDumpe') : return
91 while ( not hasattr(obj,'nomDuCodeDumpe') ): obj=obj.pere
92 self.nomDuCodeDumpe = obj.nomDuCodeDumpe
95 def getXPathComplet(self):
97 textePath='/'+self.code+":"+self.nom
98 while ( hasattr(obj,'pere') ):
100 if isinstance(obj, X_BLOC) : continue
101 textePath= '/'+ self.code + ":" + obj.nom + textePath
102 textePath='.' + textePath
105 def getXPathSansSelf(self):
108 while ( hasattr(obj,'pere') ):
110 if isinstance(obj, X_BLOC) : continue
111 textePath= self.code + ":" + obj.nom + '/' + textePath
112 textePath='./'+ self.code + ":" + textePath
115 def getNomCompletAvecBloc(self):
118 while ( hasattr(obj,'pere') ):
119 texteNom=obj.pere.nom+'_'+texteNom
124 def definitNomDuTypePyxb(self,forceACreer=False):
125 if hasattr(self,'nomDuTypePyxb') :
127 return self.nomDuTypePyxb
129 cata = CONTEXT.getCurrentCata()
131 if (hasattr (self, 'nomXML')) and self.nomXML != None : nom='T_'+self.nomXML
132 if not (nom in cata.dictTypesXSD.keys()) :
133 cata.dictTypesXSD[nom] = [self,]
134 self.nomDuTypePyxb=nom
137 if nom == 'T_Consigne' : return nom
139 listePossible=cata.dictTypesXSD[nom]
141 while (indice < len(listePossible)) :
142 objAComparer=listePossible[indice]
143 if self.compare(objAComparer) :
144 self.nomDuTypePyxb=objAComparer.nomDuTypePyxb
145 return objAComparer.nomDuTypePyxb
148 cata.dictTypesXSD[nom].append(self)
149 nomAlter='T_'+self.nom+'_'+str(indice)
150 if (hasattr (self, 'nomXML')) and self.nomXML != None :
151 nomAlter='T_'+self.nomXML+'_'+str(indice)
152 self.nomDuTypePyxb=nomAlter
153 #traceback.print_stack()
157 # ----------------------------------------
158 class X_compoFactoriseAmbigu(X_definition):
159 # ----------------------------------------
161 def __init__(self,nom,listeDeCreation,pere):
162 #print ('__ X_compoFactoriseAmbigu', listeDeCreation)
163 #for (i,index) in listeDeCreation : print i.nom
164 self.label = 'compoAmbigu'
171 self.mcDejaDumpe=set()
172 #print (listeDeCreation)
173 for (mc, index) in listeDeCreation :
174 self.mcXSD.append(mc)
175 self.ordre_mc.append(mc.nom)
176 #self.mcXSD=list(deepcopy(self.ordre_mc))
177 #for i in self.entites : print (i,self.entites[i])
178 #print ('creation de X_compoFactoriseAmbigu', self.nom, self.mcXSD)
179 self.construitEntites(self.mcXSD)
180 self.constructionArbrePossibles()
181 lesPossibles=deepcopy(self.arbrePossibles)
183 self.getNomDuCodeDumpe()
184 self.nomDuTypePyxb = self.definitNomDuTypePyxb()
185 self.texteSimple = ''
186 self.texteComplexeVenantDesFils = ''
187 self.texteComplexe = debutTypeSubstDsBlocFactorise.format(self.nomDuTypePyxb)
188 # on enleve [] des possibles puisque l elt sera optionnel
189 lesPossibles.remove([])
190 #print ('________________ init de compoAmbigu',self.nom, lesPossibles)
191 #print ('self.entites', self.entites)
192 self.mcXSD=self.factoriseEtCreeDump(lesPossibles,nomAppel='Root')
193 #print ('self.mcXSD',self.mcXSD)
194 self.texteComplexe += finTypeSubstDsBlocFactorise
195 self.texteComplexe +=self.texteComplexeVenantDesFils
196 # PN ?? 12 mai self.texteComplexe=self.texteComplexe+self.texteComplexeVenantDesFils
197 self.label='BlocAmbigu'
198 #print ('fin pour prepareDumpXSD pour', self.nom)
200 def compare(self,autreMC):
201 if self.label != autreMC.label : return False
202 if self.arbrePossibles== autreMC.arbrePossible : return True
205 def construitEntites(self, laListe):
207 if mc.nom in self.entites.keys() : self.entites[mc.nom].append(mc)
208 else : self.entites[mc.nom] = [mc,]
209 if mc.label == 'BLOC' or mc.label == 'BlocAmbigu':
210 self.ajouteLesMCFilsAEntite(mc)
213 def ajouteLesMCFilsAEntite(self,blocMc):
214 for mcFilsNom in blocMc.entites.keys():
215 if mcFilsNom not in self.entites.keys(): self.entites[mcFilsNom]=[]
216 if blocMc.label == 'BlocAmbigu' :
217 for mc in blocMc.entites[mcFilsNom] :
218 self.entites[mcFilsNom].append(mc)
219 if mc.label == 'BLOC' or mc.label == 'BlocAmbigu':
220 self.ajouteLesMCFilsAEntite(mc)
222 self.entites[mcFilsNom].append(blocMc.entites[mcFilsNom])
223 if blocMc.entites[mcFilsNom].label == 'BLOC' or blocMc.entites[mcFilsNom].label == 'BlocAmbigu':
224 self.ajouteLesMCFilsAEntite(blocMc.entites[mcFilsNom])
229 def constructionArbrePossibles(self):
230 #print ('construction pour FACT ambigu _______________', self.nom)
232 for child in self.mcXSD :
233 if not hasattr(child, 'arbrePossibles') : child.construitArbrePossibles()
234 if child.label != 'BLOC' :
235 toutesLesLignes = deepcopy(self.fusionne2Listes(toutesLesLignes, child.arbrePossibles))
237 toutesLesLignes = deepcopy(self.fusionne2Listes(toutesLesLignes, [child.nom, []]))
240 for ligne in toutesLesLignes:
244 objMC=self.entites[mc][0]
245 if objMC.label == 'BLOC' :
246 blocContenus.append(objMC)
247 for b in blocContenus :
248 for frere in blocContenus[blocContenus.index(b)+1:]:
249 if b.isDisjoint(frere) : continue
252 if not aAjouter : break
253 if aAjouter and ligne not in lignesAGarder :
254 lignesAGarder.append(ligne)
256 #print ("______________________________________")
257 #for l in lignesAGarder : print (l)
258 #print (len(lignesAGarder))
259 #print ("______________________________________")
260 self.arbrePossibles=[]
261 for ligne in lignesAGarder :
262 #print ('lignesAGarder', ligne)
263 for newLigne in self.deploye(ligne):
265 if newLigne not in self.arbrePossibles : self.arbrePossibles.append(newLigne)
266 #for l in self.arbrePossibles : print (l)
267 #print ("______________________________________")
270 def deploye (self, ligne):
273 #print ( 'mc in deploye', mc)
274 objMC=self.entites[mc][0]
275 #print ( 'nom', objMC.nom, objMC.label)
276 if objMC.label == 'BLOC' or objMC.label == 'BlocAmbigu':
277 toutesLesLignes = deepcopy(self.remplaceListeParContenuEtVide(toutesLesLignes, objMC.arbrePossibles))
279 toutesLesLignes = deepcopy(self.adjointUnMot(toutesLesLignes,mc ))
280 return toutesLesLignes
282 def construitArbrePossibles(self):
283 # inutile car on a deja l arbre mais appele parfois
284 #print ('dans X_factCompoAmbigue ne fait rien', self.nom, self.arbrePossibles)
287 def dumpXsd(self, dansFactorisation=False, multiple = False, first=False):
288 # on ne fait rien, tout a ete fait dans le init
289 self.texteElt=substDsSequence.format(self.code,self.nomDuTypePyxb,0,1)
291 def nomComplet(self) :
292 print ('dans nomComplet pourquoi ?',self, self.nom)
295 def factoriseEtCreeDump(self, laListe, indent=2 ,nomAppel=None):
296 #print ('_______________________________ factoriseEtCreeDump')
297 #print(self.nom, laListe, indent, nomAppel)
302 declencheChoiceAvecSeqVid=True
303 while [] in laListe : laListe.remove([])
306 declencheChoiceAvecSeqVid=False
310 for ligne in laListe :
311 if ligne[0] in aReduire.keys():
312 if len(ligne) == 1 :aReduire[ligne[0]].append([])
313 else : aReduire[ligne[0]].append(ligne[1:])
315 if len(ligne) == 1 : aReduire[ligne[0]]=[[]]
316 else : aReduire[ligne[0]]=[ligne[1:],]
319 if len(aReduire.keys()) == 1 :
320 if declencheChoiceAvecSeqVid == False :
323 self.texteComplexe += '\t'*(indent) + debSequenceDsBloc; indent=indent+1
327 # pour regler le souci du 1er Niveau
328 self.texteComplexe += '\t'*indent + debutChoiceDsBloc; indent=indent+1
329 #if min == 1 : self.texteComplexe += '\t'*indent + debutChoiceDsBloc; indent=indent+1
330 #else : self.texteComplexe += '\t'*indent + debutChoiceDsBlocAvecMin.format(min); indent=indent+1
332 #self.texteComplexe += '\t'*indent + debutChoiceDsBlocAvecMin.format(min); indent=indent+1
333 self.texteComplexe += '\t'*indent + debutChoiceDsBloc; indent=indent+1
337 for nomMC in aReduire.keys():
338 listeSuivante=aReduire[nomMC]
339 if creeChoice and listeSuivante != [[]] :
340 self.texteComplexe += '\t'*(indent) + debSequenceDsBloc; indent=indent+1
341 self.ajouteAuxTextes(nomMC,indent)
342 if listeSuivante == [[]] : continue # Est-ce toujours vrai ?
343 if len(listeSuivante) == 1 : self.ajouteAuxTextes(listeSuivante[0],indent)
344 else : self.factoriseEtCreeDump(listeSuivante, indent+int(creeSequence),nomMC)
345 if creeChoice : indent=indent -1 ; self.texteComplexe += '\t'*(indent) + finSequenceDsBloc
347 if declencheChoiceAvecSeqVid :
348 self.texteComplexe += '\t'*indent + debSequenceDsBloc
349 self.texteComplexe += '\t'*indent + finSequenceDsBloc
350 if creeChoice : indent=indent -1 ; self.texteComplexe += '\t'*indent + finChoiceDsBloc
351 if creeSequence : indent=indent -1 ; self.texteComplexe += '\t'*(indent) + finSequenceDsBloc
353 #if doitFermerSequence : indent=indent-1;self.texteComplexe += '\t'*(indent) + finSequenceDsBloc
354 #print (self.texteSimple)
355 #print ('______',' self.texteComplexe')
356 #print (self.texteComplexe)
357 #print ('_____', 'self.texteComplexeVenantDesFils')
358 #print (self.texteComplexeVenantDesFils)
359 print ('fin pour _______________________________', self.nom)
360 return (maListeRetour)
363 def ajouteAuxTextes(self,nomMC,indent) :
364 #print ('ajouteAuxTextes', nomMC, self.nom, self.entites)
365 #print ('ajouteAuxTextes', nomMC)
366 #for i in self.entites.keys() : print (self.entites[i][0].nom)
367 if (indent > 3) : indent = indent - 3
369 if len(self.entites[nomMC]) == 1:
370 mc=self.entites[nomMC][0]
371 mc.dumpXsd(dansFactorisation=True)
372 self.texteComplexe += '\t'*(indent) + mc.texteElt
373 if mc.nomDuTypePyxb not in self.mcDejaDumpe :
374 self.texteComplexeVenantDesFils += mc.texteComplexe
375 self.texteSimple += mc.texteSimple
376 self.mcDejaDumpe.add(mc.nomDuTypePyxb)
379 leType=type(self.entites[nomMC][0])
380 for e in (self.entites[nomMC][1:]) :
381 if type(e) != leType:
382 print ('Projection XSD impossible, changez un des ', nomMC)
386 # cette boucle ne fonctionne que pour des SIMP
387 resteATraiter=copy(self.entites[nomMC])
388 #print ('________resteATraiter', resteATraiter)
391 while resteATraiter != [] :
394 listePourUnion.append(mc)
395 for autre in resteATraiter[1:]:
396 if not (mc.compare(autre)) : nvlListeATraiter.append(autre)
397 resteATraiter=copy(nvlListeATraiter)
399 if len(listePourUnion) == 1:
401 mc.dumpXsd(dansFactorisation=True,multiple=False,first=first)
402 self.texteComplexe += '\t'*(indent) + mc.texteElt
403 if mc.nomDuTypePyxb not in self.mcDejaDumpe :
404 self.texteComplexeVenantDesFils += mc.texteComplexe
405 self.texteSimple += mc.texteSimple
406 self.mcDejaDumpe.add(mc.nomDuTypePyxb)
409 # on ajoute le nom de l element
410 self.entites[nomMC][0].dumpXsd(dansFactorisation=True,multiple=True,first=first)
411 self.texteComplexe += '\t'*(indent) + self.entites[nomMC][0].texteElt
412 texteSimpleUnion=debutSimpleType.format(self.entites[nomMC][0].nomDuTypePyxb)
413 texteSimpleUnion+=debutUnion
414 if len(listePourUnion) == 1 :
415 mc=self.entites[nomMC][0]
416 mc.dumpXsd(dansFactorisation=True,multiple=True,first=first)
417 if mc.nomDuTypePyxb not in self.mcDejaDumpe :
418 self.texteComplexeVenantDesFils += mc.texteComplexe
419 self.texteSimple += mc.texteSimple
420 self.mcDejaDumpe.add(mc.nomDuTypePyxb)
422 for e in listePourUnion :
423 e.dumpXsd(dansFactorisation=True,multiple=True,first=first)
424 if first and (e.nomDuTypePyxb not in self.mcDejaDumpe) :
425 self.texteComplexeVenantDesFils += e.texteComplexe
426 self.mcDejaDumpe.add(e.nomDuTypePyxb)
427 texteSimpleUnion += '\t'*(indent)+e.texteSimple
429 texteSimpleUnion += finUnion
430 texteSimpleUnion+=fermeSimpleType
431 self.texteSimple += texteSimpleUnion
435 # ----------------------------------------
436 class X_definitionComposee (X_definition):
437 # ------------------------------------------
439 def CreeTexteComplexeVenantDesFils(self,dansFactorisation=False):
440 texteComplexeVenantDesFils=""
441 blocsDejaDumpes=set()
442 #for nom in self.ordre_mc:
443 # mcFils = self.entites[nom]
445 for mcFils in self.mcXSD :
446 if not (isinstance(mcFils, Accas.BLOC)) :
447 mcFils.dumpXsd(dansFactorisation)
448 self.texteComplexe += mcFils.texteElt
449 self.texteSimple += mcFils.texteSimple
450 texteComplexeVenantDesFils += mcFils.texteComplexe
454 if hasattr(mcFils,'nomXML') and mcFils.nomXML in blocsDejaDumpes and mcFils.nomXML != None : continue
455 if hasattr(mcFils,'nomXML') and mcFils.nomXML != None: blocsDejaDumpes.add(mcFils.nomXML)
456 mcFils.dumpXsd(dansFactorisation)
457 self.texteComplexe += mcFils.texteElt
458 self.texteSimple += mcFils.texteSimple
459 texteComplexeVenantDesFils += mcFils.texteComplexe
460 return texteComplexeVenantDesFils
462 def dumpXsd(self, dansFactorisation=False, multiple = False, first=False):
463 #print ('_________ dumpXsd___________', self.nom)
464 if PourTraduction : print (self.nom)
465 self.prepareDumpXSD()
467 self.getNomDuCodeDumpe()
468 self.nomDuTypePyxb = self.definitNomDuTypePyxb()
469 self.texteSimple = "" # on n ajoute pas de type simple
472 # pour accepter les PROC et ...
475 self.texteComplexe = debutTypeCompo.format(self.nomDuTypePyxb)
476 if isinstance(self,X_OPER) or isinstance(self,X_PROC) :
477 self.texteComplexe += debutTypeCompoEtape.format(self.code)
478 self.texteComplexe += debutTypeCompoSeq
479 texteComplexeVenantDesFils=self.CreeTexteComplexeVenantDesFils(dansFactorisation)
480 self.texteComplexe = texteComplexeVenantDesFils + self.texteComplexe
481 # la fin de l oper est traitee dans le dumpXSD de X_OPER
482 if not isinstance(self,X_OPER ) : self.texteComplexe += finTypeCompoSeq
483 if isinstance(self,X_PROC) : self.texteComplexe += finTypeCompoEtape
484 if not isinstance(self,X_OPER ) : self.texteComplexe += finTypeCompo
486 self.texteComplexe = ""
488 self.texteElt=eltCompoDsSequence.format(self.nom,self.nomDuCodeDumpe,self.nomDuTypePyxb,self.minOccurs,self.maxOccurs)
489 #print (self.texteComplexe)
490 #print ('------------------------------------------------',self.nom)
492 def traduitMinMax(self):
493 # ______________________
494 # valable pour PROC et OPER
498 def compare(self,autreMC):
499 if self.label != autreMC.label : return False
500 if hasattr(self,'nomXML') and hasattr(autreMC,'nomXML') and self.nomXML==autreMC.nomXML and self.nomXML != None : return True
501 for attr in ( 'regles', 'fr', 'defaut', 'min' ,'max', 'position' , 'docu' ) :
502 val1=getattr(self,attr)
503 val2=getattr(autreMC,attr)
504 if val1 != val2 : return False
505 for defFille in self.entites.keys():
506 if defFille not in autreMC.entites.keys() : return False
507 if not self.entites[defFille].compare(autreMC.entites[defFille]) : return False
510 def prepareDumpXSD(self):
511 #print (' ************************ prepareDumpXSD pour', self.nom)
515 for nomMC in self.ordre_mc:
516 mc=self.entites[nomMC]
517 self.mcXSD.append(mc)
519 self.chercheListesDeBlocsNonDisjointsAvecIndex()
520 for l in list(self.listeDesBlocsNonDisjointsAvecIndex) :
521 #print ('je traite ', l, self.besoinDeFactoriserTrivial(l))
522 if not(self.besoinDeFactoriserTrivial(l)) : self.listeDesBlocsNonDisjointsAvecIndex.remove(l)
523 else : self.factorise(l)
524 #print (self.aUnPremierCommunDansLesPossibles(l))
525 #if self.aUnPremierCommunDansLesPossibles(l) :
526 # print ('aUnCommunDansLesPossibles --> Factorisation')
527 #else : self.listeDesBlocsNonDisjointsAvecIndex.remove(l)
528 # trouver un cas test
530 def chercheListesDeBlocsNonDisjointsAvecIndex(self):
531 self.listeDesBlocsNonDisjointsAvecIndex=[]
533 for nomChild in self.ordre_mc :
534 child=self.entites[nomChild]
536 if child.label != 'BLOC' : continue
537 if self.listeDesBlocsNonDisjointsAvecIndex == [] :
538 self.listeDesBlocsNonDisjointsAvecIndex.append([(child,index),])
540 vraimentIndependant=True
541 for liste in list(self.listeDesBlocsNonDisjointsAvecIndex):
543 for (bloc,indInListe) in liste :
544 if bloc.isDisjoint(child) : continue
545 if bloc.estLeMemeQue(child) : continue
547 vraimentIndependant=False
548 if not (independant) :
549 liste.append((child, index))
550 if vraimentIndependant:
551 self.listeDesBlocsNonDisjointsAvecIndex.append([(child,index),])
552 # on nettoye la liste des blocs tous seuls
553 for l in list(self.listeDesBlocsNonDisjointsAvecIndex) :
554 if len(l) ==1 : self.listeDesBlocsNonDisjointsAvecIndex.remove(l)
556 def estLeMemeQue(self,autreMC):
557 if hasattr(self,'nomXML') and hasattr(autreMC,'nomXML') and self.nomXML==autreMC.nomXML and self.nomXML != None: return True
560 def aUnPremierCommunDansLesPossibles(self, laListe) :
561 # fonctionne avec liste de mc ou une liste(mc,index)
564 for elt,index in laListe :
565 if not type(e) == types.ListType :
566 if elt.nom in mesPremiers : return True
567 mesPremiers.add(elt.nom)
569 if elt[0].nom in mesPremiers : return True
570 mesPremiers.add(elt[0].nom)
573 def besoinDeFactoriserTrivial(self,laListe):
576 for mcBloc,indice in laListe :
578 if mc.label == 'BLOC': return True
579 if not(mc.statut=='o') : return True
580 if mc.nom in lesPremiers : return True
581 lesPremiers.add(mc.nom)
584 def factorise(self,liste):
585 self.listeConstruction=liste
586 indexDebut=liste[0][1]
587 nomDebut=liste[0][0].nom
588 indexFin=liste[-1][1]+1
589 nomFin=liste[-1][0].nom
590 nom=nomDebut+'_'+nomFin
592 for i in range(indexDebut, indexFin) :
593 listeAFactoriser.append((self.mcXSD[i],i))
595 newListe=self.mcXSD[0:indexDebut]
596 #print (newListe, newListe.__class__)
597 #print ('je factorise dans -->', self.nom)
598 monEltFacteur=X_compoFactoriseAmbigu(nom,listeAFactoriser,self)
599 newListe.append(monEltFacteur)
600 newListe=newListe+self.mcXSD[indexFin:]
603 #for i in self.mcXSD : print (i.nom)
605 def construitTousLesFils(self):
606 for nomChild in self.ordre_mc :
607 child=self.entites[nomChild]
608 if child.label != 'BLOC' :
609 self.tousLesFils.append(child.nom)
611 if child.tousLesFils == [] : child.construitTousLesFils()
612 for nomPetitFils in child.tousLesFils : self.tousLesFils.append(nomPetitFils)
613 #print ('construitArbreEntier pour ', self.nom, self.tousLesFils)
616 def isDisjoint(self, mc1) :
617 if self.tousLesFils == [] : self.construitTousLesFils()
618 if not (hasattr(mc1, 'tousLesFils')) : mc1.tousLesFils = []
619 if mc1.tousLesFils == [] : mc1.construitTousLesFils()
620 for fils in mc1.tousLesFils :
621 if fils in self.tousLesFils : return False
627 # ---------------------------------
628 class X_FACT (X_definitionComposee):
629 #--------- ------------------------
630 #Un FACT avec max=** doit se projeter en XSD sous forme d'une sequence a cardinalite 1 et
631 # l'element qui porte la repetition du FACT
632 def traduitMinMax(self):
633 if self.max == '**' or self.max == float('inf') : self.maxOccurs="unbounded"
634 else : self.maxOccurs = self.max
635 self.minOccurs = self.min
636 if self.statut =='f' : self.minOccurs=0
638 def construitArbrePossibles(self):
639 if self.statut == 'f' :
640 self.arbrePossibles = (self.nom,[])
641 self.arbreMCPossibles = (self,None)
643 self.arbrePossibles = (self.nom,)
644 self.arbreMCPossibles = (self,)
645 #print ('XFACT arbre des possibles de ' ,self.nom, self.arbrePossibles)
649 # ---------------------------------
650 class X_OPER (X_definitionComposee):
651 # ---------------------------------
652 def dumpXsd(self, dansFactorisation=False, multiple = False, first=False):
653 X_definitionComposee.dumpXsd(self,dansFactorisation)
654 self.texteComplexe += finTypeCompoSeq
655 self.texteComplexe += operAttributeName
656 self.texteComplexe += attributeTypeForASSD
657 self.texteComplexe += attributeTypeUtilisateurName.format(self.sd_prod.__name__)
658 self.texteComplexe += finTypeCompoEtape
659 self.texteComplexe += finTypeCompo
662 cata = CONTEXT.getCurrentCata()
663 if self.sd_prod.__name__ not in list(cata.dictTypesASSDorUserASSDCrees) :
664 cata.dictTypesASSDorUserASSDCrees[self.sd_prod.__name__]=[self,]
666 cata.dictTypesASSDorUserASSDCrees[self.sd_prod.__name__].append(self)
669 # ----------------------------------
670 class X_PROC (X_definitionComposee):
671 #-----------------------------------
674 #-----------------------------------
675 class X_BLOC (X_definitionComposee):
676 #-----------------------------------
677 def dumpXsd(self, dansFactorisation=False, multiple = False, first=False):
680 self.getNomDuCodeDumpe()
681 # dans ce cas les blocs successifs sont identiques et on ne dumpe que le 1er
683 self.nomDuTypePyxb = self.definitNomDuTypePyxb()
684 self.texteSimple = "" # on n ajoute pas de type simple
686 # Pour les blocs le minOccurs vaut 0 et le max 1
687 #print ('dumpXsd Bloc', self.nom, self.aCreer)
689 self.texteComplexe = debutTypeSubst.format(self.nomDuTypePyxb)
690 texteComplexeVenantDesFils=self.CreeTexteComplexeVenantDesFils(dansFactorisation)
691 self.texteComplexe = texteComplexeVenantDesFils + self.texteComplexe
692 self.texteComplexe += finTypeSubst
694 self.texteComplexe = ""
696 self.texteElt=substDsSequence.format(self.code,self.nomDuTypePyxb,0,1)
698 #print ('------------------------------------------------')
700 def compare(self,autreMC):
701 if self.label != autreMC.label : return False
702 if self.inUnion == True or autreMC.inUnion == True : return False
703 if hasattr(self,'nomXML') and hasattr(autreMC,'nomXML') and self.nomXML==autreMC.nomXML and self.nomXML != None : return True
704 for attr in ( 'condition', 'regles', ):
705 val1=getattr(self,attr)
706 val2=getattr(autreMC,attr)
707 if val1 != val2 : return False
708 for defFille in self.entites.keys():
709 if defFille not in autreMC.entites.keys() : return False
710 if not self.entites[defFille].compare(autreMC.entites[defFille]) : return False
713 def construitArbrePossibles(self):
714 self.arbrePossibles=[[],]
715 #print ('X_BLOC je construis l arbre des possibles pour ', self.nom)
716 for child in self.mcXSD :
717 if not hasattr(child, 'arbrePossibles') : child.construitArbrePossibles()
718 #print (child.nom, child.label, child.arbrePossibles)
719 if child.label == 'BLOC' :
720 self.arbrePossibles = deepcopy(self.remplaceListeParContenuEtVide(self.arbrePossibles, child.arbrePossibles))
721 elif child.label == 'BlocAmbigu':
722 #print ("je passe par la pour", self.nom, child.nom, self.arbrePossibles, child.arbrePossibles)
723 self.arbrePossibles = deepcopy(self.remplaceListeParContenuEtVide(self.arbrePossibles, child.arbrePossibles))
724 #print ('resultat', self.arbrePossibles)
726 self.arbrePossibles = deepcopy(self.adjoint(self.arbrePossibles, child.arbrePossibles))
727 self.arbrePossibles.append([]) # un bloc n est pas obligatoire
728 #print ('arbre des possibles de ' ,self.nom, self.arbrePossibles)
731 #--------------------------------
732 class X_SIMP (X_definition):
733 #--------------------------------
734 def dumpXsd(self, dansFactorisation=False, multiple = False, first=False):
735 #print ('_______________' , '*******************', 'je passe la dans dumpXsd SIMP', self.nom, multiple, first)
736 if PourTraduction : print (self.nom)
737 self.prepareDumpXSD()
738 if multiple : self.inUnion=True
739 #print ('exploreObjet SIMP')
740 self.getNomDuCodeDumpe()
742 self.texteComplexe = ""
743 self.texteSimple = ""
745 if self.nom =='Consigne' : return
747 # --> homonymie on peut utiliser genealogie ?
748 self.nomDuTypeDeBase = self.traduitType()
750 self.nomDuTypePyxb = self.definitNomDuTypePyxb()
751 if first : self.aCreer = True
753 self.nomDuTypePyxb = self.definitNomDuTypePyxb(forceACreer=1)
755 #else : print ('multiple and not first', self.aCreer)
759 # on se sert des listes ou non pour la gestion des minOccurs /maxOccurs est > 0
760 if self.statut =='f' : minOccurs = 0
762 if dansFactorisation : minOccurs = 1
764 #print ('minOccurs',minOccurs)
765 # le defaut est dans l elt Name -> tester la coherence d existence avec Accas
767 if (hasattr (self, 'nomXML')) and self.nomXML != None : nomUtil=self.nomXML
768 else : nomUtil = self.nom
770 # pas d elt si on est dans multiple
771 # sauf si on est le '1er' dans un element ambigu
773 #print ('je passe la pas multiple')
775 if self.max > 1 or self.max == '**' or self.max == float('inf') :
776 # a revoir pour les tuples avec defaut
778 for val in self.defaut : txtDefaut+=str(val) +" "
779 self.texteElt = eltWithDefautDsSequence.format(nomUtil,self.code,self.nomDuTypePyxb,minOccurs,1,txtDefaut)
781 if str(self.defaut) == 'True' : txtDefaut = 'true'
782 else : txtDefaut = str(self.defaut)
783 self.texteElt = eltWithDefautDsSequence.format(nomUtil,self.code,self.nomDuTypePyxb,minOccurs,1,txtDefaut)
784 else : self.texteElt = eltDsSequence.format(nomUtil,self.code,self.nomDuTypePyxb,minOccurs,1)
786 self.texteElt = eltDsSequence.format(nomUtil,self.code,self.nomDuTypePyxb,1,1)
788 # self.aCreer est mis a jour ds definitNomDuTypePyxb
789 # ou si elt est le 1er d une liste identique
790 if not self.aCreer : return
792 if not multiple : self.texteSimple += debutSimpleType.format(self.nomDuTypePyxb)
793 else : self.texteSimple += debutSimpleTypeSsNom
794 # On est dans une liste
795 if self.max > 1 or self.max == '**' or self.max == float('inf') or hasattr(self.type[0], 'ntuple') :
796 self.texteSimple += debutTypeSimpleListe
797 self.texteSimple += "\t\t\t\t"+debutRestrictionBase.format(self.nomDuTypeDeBase)
798 if self.val_min != float('-inf') : self.texteSimple += "\t\t\t\t"+minInclusiveBorne.format(self.val_min)
799 if self.val_max != float('inf') and self.val_max != '**' : self.texteSimple +="\t\t\t\t"+ maxInclusiveBorne.format(self.val_max)
800 if self.into != None:
801 # PN --> traduction des into
803 if self.intoXML != None : into = self.intoXML
804 for val in into : self.texteSimple += "\t\t\t\t"+enumeration.format(val)
806 for val in into : print (str(val))
807 self.texteSimple += fermeBalisesMileu
808 if self.max !=1 and self.max != '**' and self.max != float('inf') : self.texteSimple += maxLengthTypeSimple.format(self.max)
809 if self.min !=1 and self.min != float('-inf') : self.texteSimple += minLengthTypeSimple.format(self.min)
810 self.texteSimple += fermeRestrictionBase
813 self.texteSimple += debutRestrictionBase.format(self.nomDuTypeDeBase)
814 if self.val_min != float('-inf') : self.texteSimple += minInclusiveBorne.format(self.val_min)
815 if self.val_max != float('inf') and self.val_max != '**' : self.texteSimple += maxInclusiveBorne.format(self.val_max)
816 if self.into != None:
818 if self.intoXML != None : into = self.intoXML
819 for val in into : self.texteSimple += enumeration.format(val)
821 for val in into : print (str(val))
822 self.texteSimple += fermeRestrictionBase
823 self.texteSimple += fermeSimpleType
826 def prepareDumpXSD(self):
828 if self.statut == 'f' :
829 self.arbrePossibles = (self.nom,[])
831 self.arbrePossibles = (self.nom,)
836 def traduitType(self):
837 # il faut traduire le min et le max
838 # il faut ajouter les regles
839 # il faut gerer les types tuple et fichier
840 if hasattr(self.type[0], 'ntuple') :
842 leType=self.validators.typeDesTuples[0]
843 for i in range(self.type[0].ntuple):
844 if self.validators.typeDesTuples[i] != leType : return ('XXXXXXXX')
849 typeATraduire=self.type[0]
850 if not (typeATraduire in list(dictNomsDesTypes.keys())) :
851 if (isinstance(typeATraduire, Accas.ASSD) or issubclass(typeATraduire, Accas.ASSD)) :
853 cata = CONTEXT.getCurrentCata()
854 if len(self.type) == 2 and self.type[1]=='createObject' :
855 if typeATraduire.__name__ not in list(cata.dictTypesASSDorUserASSDCrees) :
856 cata.dictTypesASSDorUserASSDCrees[typeATraduire.__name__]=[self,]
858 cata.dictTypesASSDorUserASSDCrees[typeATraduire.__name__].append(self)
861 # cas d une consommation
862 if typeATraduire not in list(cata.dictTypesASSDorUserASSDUtilises) :
863 cata.dictTypesASSDorUserASSDUtilises[typeATraduire]=[self,]
865 cata.dictTypesASSDorUserASSDUtilises[typeATraduire].append(self,)
867 else : return ('YYYYY')
868 return dictNomsDesTypes[typeATraduire]
870 def traduitValMinValMax(self):
871 self.maxInclusive=self.val_max
872 self.minInclusive=self.val_min
873 if self.val_min == float('-inf') and val_max== float('inf') : return
874 #print ('il faut affiner le type du SIMP ', self.nom)
875 if self.val_max == '**' or self.val_max == float('inf') : self.maxInclusive=None
876 else : self.maxInclusive = self.val_max
877 if self.val_min == '**' or self.val_max == float('-inf') : self.maxInclusive=None
878 else : self.minInclusive = self.val_min
880 def traduitMinMax(self):
881 if self.min == 1 and self.max == 1 : return
882 #print ('il faut creer une liste ' , self.nom)
884 def compare(self,autreMC):
885 if self.label != autreMC.label : return False
886 if self.inUnion == True or autreMC.inUnion == True : return False
887 listeAComparer = [ 'type', 'defaut', 'min' ,'max' ,'val_min' , 'val_max' ]
888 if self.intoXML != None : listeAComparer.append('intoXML')
889 else : listeAComparer.append('into')
890 if (hasattr (self, 'nomXML')) and self.nomXML != None : nomUtil=self.nomXML
891 for attr in listeAComparer :
892 val1=getattr(self,attr)
893 val2=getattr(autreMC,attr)
894 if val1 != val2 : return False
897 def construitArbrePossibles(self):
898 if self.statut == 'f' :
899 self.arbrePossibles = (self.nom,[])
901 self.arbrePossibles = (self.nom,)
902 #print ('SIMP arbre des possibles de ' ,self.nom, self.arbrePossibles)
909 def dumpXsd(self, avecEltAbstrait, debug = True):
910 cata = CONTEXT.getCurrentCata()
911 if debug : print ('avecEltAbstrait -------------------', avecEltAbstrait)
913 if debug : print ('self.importedBy -------------------', self.importedBy)
914 if debug : print ('self.code -------------------', self.code)
916 self.texteSimple = ""
917 self.texteComplexe = ""
919 self.texteDeclaration = ""
920 self.texteInclusion = ""
922 self.texteTypeAbstrait = ""
924 if self.implement == "" :
925 self.nomDuCodeDumpe = self.code
926 self.implement = self.code
927 self.nomDuXsdPere = self.code
929 self.implement,self.nomDuXsdPere=self.implement.split(':')
930 self.nomDuCodeDumpe = self.implement
932 if debug : print ('self.implement -------------------', self.implement)
933 if debug : print ('self.nomDuCodeDumpe -------------------', self.nomDuCodeDumpe)
934 if debug : print ('self.nomDuXsdPere -------------------', self.nomDuXsdPere)
936 self.nomDuTypePyxb = 'T_'+self.nomDuCodeDumpe
937 self.dumpLesCommandes()
939 if self.implement == self.code :
940 self.texteCata += eltAbstraitCataPPal.format(self.code)
941 self.texteCata += eltCataPPal.format(self.code,self.code,self.code)
943 self.texteCata += eltAbstraitCataFils.format(self.implement,self.nomDuXsdPere,self.nomDuXsdPere)
944 self.texteCata += eltCataFils.format(self.implement,self.nomDuXsdPere,self.nomDuXsdPere,self.nomDuXsdPere)
945 self.texteInclusion += includeCata.format(self.nomDuXsdPere)
947 self.texteCata += eltCata.format(self.implement,self.implement,self.implement,self.implement,self.nomDuXsdPere)
948 #if self.implement == self.code :
949 # self.texteCata += debutTypeCata.format(self.nomDuCodeDumpe)
951 # self.texteCata += debutTypeCataExtension.format(self.nomDuCodeDumpe)
952 # self.texteCata += debutExtension.format(self.code,self.nomDuCodeDumpe)
953 # self.texteInclusion += includeCata.format(self.nomDuXsdPere)
957 #for codeHeritant in self.importedBy:
958 # self.texteCata += eltCodeSpecDsCata.format(codeHeritant)
959 # self.texteTypeAbstrait += eltAbstrait.format(codeHeritant,codeHeritant,self.code,codeHeritant)
961 #if self.implement != "" : self.texteCata = self.texteCata + finExtension + finTypeCompo
962 #else : self.texteCata += finTypeCata
964 #if self.implement != "" :
965 # self.texteElt=implementeAbstrait.format(self.nomDuCodeDumpe,self.code,self.nomDuTypePyxb,self.code,self.nomDuCodeDumpe)
967 # self.texteElt = eltCata.format(self.nomDuCodeDumpe,self.code, self.nomDuTypePyxb)
969 if self.implement == self.code :
970 self.texteXSD = texteDebut.format(self.code,self.code,self.code,self.code,self.code,self.code)
971 elif self.nomDuXsdPere == self.code :
972 self.texteXSD = texteDebutNiveau2.format(self.code,self.implement,self.code,self.code,self.code, self.code,self.code,self.code,self.code,self.code)
974 self.texteXSD = texteDebutNiveau3.format(self.code,self.implement,self.code,self.nomDuXsdPere,self.code,self.code,self.code, self.code,self.code,self.code,self.code,self.code)
976 if self.texteInclusion != "" : self.texteXSD += self.texteInclusion
977 self.texteXSD += self.texteSimple
978 self.texteXSD += self.texteComplexe
980 #if self.texteTypeAbstrait != "" : self.texteXSD += self.texteTypeAbstrait
981 self.texteXSD += self.texteCata
982 #self.texteXSD += self.texteElt
986 # Pour le nom des key_ref en creation : le type ( une seule key-ref par type. facile a retrouver)
987 for clef in self.dictTypesASSDorUserASSDCrees:
990 for unOper in self.dictTypesASSDorUserASSDCrees[clef]:
991 if not(isinstance(unOper, Accas.OPER)) : continue
993 texteDesFields+=texteFieldUnitaire.format(self.code, unOper.nom)
994 if existeASSD : texteDesFields=texteDesFields[0:-2]
997 for unSimp in self.dictTypesASSDorUserASSDCrees[clef]:
998 if not (isinstance(unSimp, Accas.SIMP)) : continue
999 texteDesUserASSD += unSimp.getXPathSansSelf() + " | "
1000 #print (unSimp.getXPathSansSelf())
1001 #texteFieldUnitaire='/'+self.code+":"+unSimp.nom
1003 if existeunUserASSD:
1004 if existeASSD : texteDesFields = texteDesFields + texteDesUserASSD[0:-2] +"/>\n\t\t"
1005 else: texteDesFields = texteDesUserASSD[0:-2]
1006 print (texteDesUserASSD)
1007 print (texteDesFields)
1008 if texteDesFields != "" :
1009 texteKeyRef += producingASSDkeyRefDeclaration.format( clef ,texteDesFields)
1012 # Pour le nom des key-ref en utilisation : la genealogie complete ( une key-ref par utilisation et on retrouve facilement la )
1013 for clef in self.dictTypesASSDorUserASSDUtilises:
1014 for unSimp in self.dictTypesASSDorUserASSDUtilises[clef]:
1015 # il faut la genealogie
1016 texteKeyRef += UsingASSDkeyRefDeclaration.format(unSimp.getNomCompletAvecBloc(), unSimp.type[0].__name__,self.code, unSimp.type[0].__name__,unSimp.getXPathComplet() )
1018 #PNPN on debranche les keyref le temps de bien reflechir a leur forme
1019 #if texteKeyRef != '' :
1020 # self.texteXSD = self.texteXSD[0:-3]+'>\n'
1021 # self.texteXSD += texteKeyRef
1022 # self.texteXSD += fermeEltCata
1024 self.texteXSD += texteFin
1028 #if not PourTraduction : print (self.texteXSD)
1030 for k in list(cata.dictTypesXSD.keys()):
1031 if len(cata.dictTypesXSD[k]) > 1:
1034 for definition in cata.dictTypesXSD[k] :
1035 nom=definition.nomComplet()
1036 if index == 0 : dico[k][nom]=k+str(index)
1037 else : dico[k][nom]=k+str(index)
1041 #if (not PourTraduction) and (dico != {}) : pprint.pprint(dico)
1042 print ('__________________________ decommenter pour le texteXSD________________________')
1043 print (self.texteXSD)
1044 return self.texteXSD
1047 def dumpLesCommandes(self):
1048 cata = CONTEXT.getCurrentCata()
1049 fichierCataSourceExt=os.path.basename(cata.cata.__file__)
1050 fichierCataSource, extension=os.path.splitext(fichierCataSourceExt)
1051 importCataSource=__import__(fichierCataSource,{},{})
1054 for m in sys.modules:
1055 monModule=sys.modules[m]
1057 if m in ('os', 'sys', 'inspect', 'six', 'pickle', 'codecs') : continue
1058 if m in ('cPickle', 'pprint', 'dis', '_sre', 'encodings.aliases'): continue
1059 if m in ('numbers', 'optparse', 'binascii', 'posixpath') : continue
1060 if m in ('_locale', '_sysconfigdata_nd', 'gc', 'functools') : continue
1061 if m in ('posixpath', 'types', 'posix', 'prefs') : continue
1062 if m in ('warnings', 'types', 'posix', 'prefs') : continue
1063 if monModule.__name__[0:15] == '_sysconfigdata_' : continue
1064 if monModule.__name__ == '__future__' : continue
1065 if monModule.__name__[0:3] == 'Ihm' : continue
1066 if monModule.__name__[0:5] == 'numpy' : continue
1067 if monModule.__name__[0:5] == 'Noyau' : continue
1068 if monModule.__name__[0:5] == 'Accas' : continue
1069 if monModule.__name__[0:7] == 'convert' : continue
1070 if monModule.__name__[0:7] == 'Efi2Xsd' : continue
1071 if monModule.__name__[0:7] == 'Editeur' : continue
1072 if monModule.__name__[0:9] == 'generator' : continue
1073 if monModule.__name__[0:10] == 'Validation' : continue
1074 if monModule.__name__[0:10] == 'Extensions' : continue
1075 if monModule.__name__[0:12] == 'InterfaceQT4' : continue
1076 if monModule.__name__ == fichierCataSource : continue
1077 texte= texte + "try : import "+ monModule.__name__ + " \n"
1078 texte= texte + "except : pass \n"
1079 texte= texte + "try : from "+ monModule.__name__ + ' import * \n'
1080 texte= texte + "except : pass \n"
1084 newModule=imp.new_module('__main__')
1085 exec (texte, newModule.__dict__)
1087 for i in dir(importCataSource):
1088 if i not in dir(newModule):
1089 allClassToDump.append(importCataSource.__dict__[i])
1092 self.texteSimple = ''
1093 self.texteComplexe = ''
1094 for c in allClassToDump :
1095 if not(isinstance(c, Accas.OPER)) and not(isinstance(c, Accas.PROC)) : continue
1096 c.nomDuCodeDumpe=self.nomDuCodeDumpe
1097 c.code=self.implement
1100 self.texteSimple += c.texteSimple
1101 self.texteComplexe += c.texteComplexe
1102 #c.texteElt=eltCompoDsSequenceInExtension.format(c.nom,self.code,c.nomDuTypePyxb)
1103 c.texteElt=eltEtape.format(c.nom,self.implement,c.nomDuTypePyxb,self.implement)
1104 self.texteCata += c.texteElt