2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2021 EDF R&D
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.
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.
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
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 from copy import deepcopy, copy
30 # CONTEXT est accessible (__init__.py de Noyau)
32 #import raw.efficas as efficas
33 sys.path.insert(0,os.path.abspath(os.path.join(os.getcwd(),'..')))
35 # ds l init du SIMP il manque siValide et fenetreIhm
37 from .mapDesTypes import dictSIMPEficasXML, dictSIMPXMLEficas
38 from .mapDesTypes import dictFACTEficasXML, dictFACTXMLEficas
39 from .mapDesTypes import dictPROCEficasXML, dictPROCXMLEficas
40 from .mapDesTypes import dictOPEREficasXML, dictOPERXMLEficas
41 from .mapDesTypes import dictBLOCEficasXML, dictBLOCXMLEficas
42 from .mapDesTypes import dictPourCast, dictNomsDesTypes
43 from .mapDesTypes import listeParamDeTypeTypeAttendu, listeParamDeTypeStr, dictPourCast
44 from .mapDesTypes import listeParamTjsSequence, listeParamSelonType
45 from .mapDesTypes import Tuple
47 PourTraduction = False
49 from .balisesXSD import *
54 def adjoint(self, liste1, liste2):
55 #print ('adjoint', liste1, liste2)
59 newListe=deepcopy(elt1)
60 if elt2 != []: newListe.append(elt2)
64 def adjointUnMot(self, liste1, mot):
67 newListe=deepcopy(elt1)
72 def remplaceListeParContenuEtVide(self, liste1, liste2):
75 for eltListe in liste2:
76 newListe=deepcopy(elt1)
77 if eltListe!=[] :newListe+=eltListe
78 if newListe not in listeFinale : listeFinale.append(newListe)
82 def fusionne2Listes(self, liste1, liste2):
83 #print ('fusionne2Liste', liste1, liste2)
86 for eltListe in liste2:
87 newListe=deepcopy(elt1)
88 if eltListe!=[] :newListe.append(eltListe)
89 listeFinale.append(newListe)
93 def getNomDuCodeDumpe(self):
94 if hasattr(self,'nomDuCodeDumpe') : return
96 while ( not hasattr(obj,'nomDuCodeDumpe') ): obj=obj.pere
97 self.nomDuCodeDumpe = obj.nomDuCodeDumpe
100 def getXPathComplet(self):
102 textePath='/'+self.code+":"+self.nom
103 while ( hasattr(obj,'pere') ):
105 if isinstance(obj, X_BLOC) : continue
106 textePath= '/'+ self.code + ":" + obj.nom + textePath
107 textePath='.' + textePath
110 def getXPathSansSelf(self):
113 while ( hasattr(obj,'pere') ):
115 if isinstance(obj, X_BLOC) : continue
116 textePath= self.code + ":" + obj.nom + '/' + textePath
117 textePath='./'+ self.code + ":" + textePath
120 def getNomCompletAvecBloc(self):
123 while ( hasattr(obj,'pere') ):
124 texteNom=obj.pere.nom+'_'+texteNom
128 def metAJourPyxb(self,nomDuTypePyxb) :
130 self.nomDuTypePyxb=nomDuTypePyxb
131 cata = CONTEXT.getCurrentCata()
133 if (hasattr (self, 'nomXML')) and self.nomXML != None : nom='T_'+self.nomXML
134 if not (nom in cata.dictTypesXSD.keys()) :
135 cata.dictTypesXSD[nom] = [self,]
137 cata.dictTypesXSD[nom].append(self)
139 def definitNomDuTypePyxb(self,forceACreer=False,debug=False):
140 #if self.nom == 'SubgridScaleModel' : debug=True
141 #print ('definitNomDuTypePyxb', self, self.nom,self.nomComplet(),forceACreer)
143 if hasattr(self,'nomDuTypePyxb') : self.aCreer = False; return self.nomDuTypePyxb
145 if debug : print ('definitNomDuTypePyxb traitement pour ', self.nom)
147 cata = CONTEXT.getCurrentCata()
149 if (hasattr (self, 'nomXML')) and self.nomXML != None : nom='T_'+self.nomXML
150 if not (nom in cata.dictTypesXSD.keys()) :
151 if debug : print ('definitNomDuTypePyxb encore jamais traite ', self.nom , ' a pour type' , nom)
152 cata.dictTypesXSD[nom] = [self,]
153 self.nomDuTypePyxb=nom
156 if nom == 'T_Consigne' : return nom
160 listePossible=cata.dictTypesXSD[nom]
162 while (indice < len(listePossible)) :
163 objAComparer=listePossible[indice]
164 if debug : print (self.compare)
165 if self.compare(objAComparer) :
166 self.nomDuTypePyxb=objAComparer.nomDuTypePyxb
167 if debug : print (self, objAComparer)
168 if debug : print (type(self), type(objAComparer))
169 if debug : print ('definitNomDuTypePyxb', self.nom , 'type identique', objAComparer.nomDuTypePyxb )
170 # c est nul pour la comparaison mais cela permet d etre ok dans le dictionnaire passe a Accas
171 cata.dictTypesXSD[nom].append(self)
172 if self.label != 'SIMP' :
173 if objAComparer not in list(cata.dictTypesXSDJumeaux.keys()) : cata.dictTypesXSDJumeaux[objAComparer]=[self,]
174 else : cata.dictTypesXSDJumeaux[objAComparer].append(self)
175 return objAComparer.nomDuTypePyxb
178 cata.dictTypesXSD[nom].append(self)
179 nomAlter='T_'+self.nom+'_'+str(indice)
180 if (hasattr (self, 'nomXML')) and self.nomXML != None :
181 nomAlter='T_'+self.nomXML+'_'+str(indice)
182 self.nomDuTypePyxb=nomAlter
186 # ----------------------------------------
187 class X_compoFactoriseAmbigu(X_definition):
188 # ----------------------------------------
190 def __init__(self,nom,listeDeCreation,pere, debug=True):
193 for i in listeDeCreation : print (i.nom)
194 self.label='BlocAmbigu'
200 self.typesXSDDejaDumpes=[]
202 self.lesConditions = 'Possible Conditions : '
203 for mc in listeDeCreation :
204 if hasattr(mc, 'condition'):self.lesConditions += '\n\t\t\t\t\t\t' + mc.condition
205 self.mcXSD.append(mc)
206 self.ordre_mc.append(mc.nom)
208 if debug : print (self.mcXSD)
209 if debug : print (self.ordre_mc)
210 self.construitEntites(self.mcXSD)
211 self.constructionArbrePossibles()
212 lesPossibles=deepcopy(self.arbrePossibles)
213 if debug : print ('lesPossibles ', lesPossibles)
215 self.getNomDuCodeDumpe()
216 self.nomDuTypePyxb = self.definitNomDuTypePyxb()
217 if debug : print (self.nomDuTypePyxb)
218 self.texteSimple = ''
219 self.texteComplexeVenantDesFils = ''
220 self.texteComplexe = debutTypeSubstDsBlocFactorise.format(self.nomDuTypePyxb)
221 # on enleve [] des possibles puisque l elt sera optionnel
222 lesPossibles.remove([])
223 if debug : print ('________________ init de compoAmbigu',self.nom, lesPossibles)
224 if debug : print ('self.entites', self.entites)
225 self.mcXSD=self.factoriseEtCreeDump(lesPossibles,nomAppel='Root')
226 if debug : print ('self.mcXSD',self.mcXSD)
227 self.texteComplexe += finTypeSubstDsBlocFactorise
228 self.texteComplexe +=self.texteComplexeVenantDesFils
229 #print ('fin pour prepareDumpXSD pour', self.nom)
231 def compare(self,autreMC):
232 if self.label != autreMC.label : return False
234 # arbre des possibles identiques mais les types different
236 #print (self.arbrePossibles)
237 #print (autreMC.arbrePossibles)
238 #if self.arbrePossibles== autreMC.arbrePossibles : return True
241 def construitEntites(self, laListe):
243 if mc.nom in self.entites.keys() : self.entites[mc.nom].append(mc)
244 else : self.entites[mc.nom] = [mc,]
245 if mc.label == 'BLOC' or mc.label == 'BlocAmbigu':
246 self.ajouteLesMCFilsAEntite(mc)
249 def ajouteLesMCFilsAEntite(self,blocMc):
250 for mcFilsNom in blocMc.entites.keys():
251 if mcFilsNom == 'Consigne' or mcFilsNom == 'blocConsigne' : continue
252 if mcFilsNom not in self.entites.keys(): self.entites[mcFilsNom]=[]
253 if blocMc.label == 'BlocAmbigu' :
254 for mc in blocMc.entites[mcFilsNom] :
255 self.entites[mcFilsNom].append(mc)
256 if mc.label == 'BLOC' or mc.label == 'BlocAmbigu':
257 self.ajouteLesMCFilsAEntite(mc)
259 self.entites[mcFilsNom].append(blocMc.entites[mcFilsNom])
260 if blocMc.entites[mcFilsNom].label == 'BLOC' or blocMc.entites[mcFilsNom].label == 'BlocAmbigu':
261 self.ajouteLesMCFilsAEntite(blocMc.entites[mcFilsNom])
266 def constructionArbrePossibles(self, debug = False):
267 if debug : print ('construction pour FACT ambigu _______________', self.nom)
269 for child in self.mcXSD :
270 if not hasattr(child, 'arbrePossibles') : child.construitArbrePossibles()
271 if child.label != 'BLOC' :
272 toutesLesLignes = deepcopy(self.fusionne2Listes(toutesLesLignes, child.arbrePossibles))
274 toutesLesLignes = deepcopy(self.fusionne2Listes(toutesLesLignes, [child.nom, []]))
277 for ligne in toutesLesLignes:
281 objMC=self.entites[mc][0]
282 if objMC.label == 'BLOC' :
283 blocContenus.append(objMC)
284 for b in blocContenus :
285 for frere in blocContenus[blocContenus.index(b)+1:]:
286 if b.isDisjoint(frere) : continue
289 if not aAjouter : break
290 if aAjouter and ligne not in lignesAGarder :
291 lignesAGarder.append(ligne)
293 #print ("______________________________________")
294 #for l in lignesAGarder : print (l)
295 #print (len(lignesAGarder))
296 #print ("______________________________________")
297 self.arbrePossibles=[]
298 for ligne in lignesAGarder :
299 #print ('lignesAGarder', ligne)
300 for newLigne in self.deploye(ligne):
302 if newLigne not in self.arbrePossibles : self.arbrePossibles.append(newLigne)
303 #for l in self.arbrePossibles : print (l)
304 #print ("______________________________________")
307 def deploye (self, ligne):
310 #print ( 'mc in deploye', mc)
311 objMC=self.entites[mc][0]
312 #print ( 'nom', objMC.nom, objMC.label)
313 if objMC.label == 'BLOC' or objMC.label == 'BlocAmbigu':
314 toutesLesLignes = deepcopy(self.remplaceListeParContenuEtVide(toutesLesLignes, objMC.arbrePossibles))
316 toutesLesLignes = deepcopy(self.adjointUnMot(toutesLesLignes,mc ))
317 return toutesLesLignes
319 def construitArbrePossibles(self):
320 # inutile car on a deja l arbre mais appele parfois
321 #print ('dans X_factCompoAmbigu ne fait rien', self.nom, self.arbrePossibles)
324 def dumpXsd(self, dansFactorisation=False, multiple = False, first=False):
325 # on ne fait rien, tout a ete fait dans le init
326 self.texteElt=substDsSequence.format(self.code,self.nomDuTypePyxb,0,1, self.lesConditions)
328 def nomComplet(self) :
329 print ('dans nomComplet pourquoi ?',self, self.nom)
332 def factoriseEtCreeDump(self, laListe, indent=2 ,nomAppel=None, debug=False):
333 if debug : print ('_______________________________ factoriseEtCreeDump')
334 if debug : print(self.nom, laListe, indent, nomAppel)
339 declencheChoiceAvecSeqVid=True
340 while [] in laListe : laListe.remove([])
343 declencheChoiceAvecSeqVid=False
348 for ligne in laListe :
349 if ligne[0] in aReduire.keys():
350 if len(ligne) == 1 :aReduire[ligne[0]].append([])
351 else : aReduire[ligne[0]].append(ligne[1:])
353 if len(ligne) == 1 : aReduire[ligne[0]]=[[]]
354 else : aReduire[ligne[0]]=[ligne[1:],]
357 if debug : print ('la Liste', laListe, declencheChoiceAvecSeqVid)
358 if debug : print (aReduire)
359 if len(aReduire.keys()) == 1 :
360 if declencheChoiceAvecSeqVid == False :
363 self.texteComplexe += '\t'*(indent) + debSequenceDsBloc; indent=indent+1
367 # pour regler le souci du 1er Niveau
368 self.texteComplexe += '\t'*indent + debutChoiceDsBloc; indent=indent+1
369 #if min == 1 : self.texteComplexe += '\t'*indent + debutChoiceDsBloc; indent=indent+1
370 #else : self.texteComplexe += '\t'*indent + debutChoiceDsBlocAvecMin.format(min); indent=indent+1
372 #self.texteComplexe += '\t'*indent + debutChoiceDsBlocAvecMin.format(min); indent=indent+1
373 self.texteComplexe += '\t'*indent + debutChoiceDsBloc; indent=indent+1
377 if debug : print ('creeSequence', creeSequence, aReduire)
378 for nomMC in aReduire.keys():
379 if debug : print (nomMC)
380 listeSuivante=aReduire[nomMC]
381 if creeChoice and listeSuivante != [[]] :
382 self.texteComplexe += '\t'*(indent) + debSequenceDsBloc; indent=indent+1
383 self.ajouteAuxTextes(nomMC,indent)
384 if listeSuivante == [[]] : continue # Est-ce toujours vrai ?
385 if len(listeSuivante) == 1 : self.ajouteAuxTextes(listeSuivante[0],indent)
386 else : self.factoriseEtCreeDump(listeSuivante, indent+int(creeSequence),nomMC)
387 if creeChoice : indent=indent -1 ; self.texteComplexe += '\t'*(indent) + finSequenceDsBloc
389 if declencheChoiceAvecSeqVid :
390 self.texteComplexe += '\t'*indent + debSequenceDsBloc
391 self.texteComplexe += '\t'*indent + finSequenceDsBloc
392 if creeChoice : indent=indent -1 ; self.texteComplexe += '\t'*indent + finChoiceDsBloc
393 if creeSequence : indent=indent -1 ; self.texteComplexe += '\t'*(indent) + finSequenceDsBloc
395 #if doitFermerSequence : indent=indent-1;self.texteComplexe += '\t'*(indent) + finSequenceDsBloc
396 #print (self.texteSimple)
397 #print ('______',' self.texteComplexe')
398 #print (self.texteComplexe)
399 #print ('_____', 'self.texteComplexeVenantDesFils')
400 #print (self.texteComplexeVenantDesFils)
401 #print ('fin pour _______________________________', self.nom)
402 return (maListeRetour)
405 def ajouteAuxTextes(self,nomMC,indent,debug=False) :
407 print ('______________________________________________________')
408 print ('ajouteAuxTextes', nomMC, self.nom)
409 # for i in self.entites.keys() : print (self.entites[i][0].nom)
410 if (indent > 3) : indent = indent - 3
412 # PN change le 17 fevrier . Est-ce normal d arriver la ?
413 # if faut traiter les Blocs exclusifs qui donnent des choices de sequences
414 # mais celles-ci risquent d etre ambigues
415 while (isinstance(nomMC,list)) :
418 if nomMC == 'Consigne' or nomMC == 'blocConsigne' : return
419 if debug : print (nomMC, 'dans ajoute vraiment aux textes', self.entites )
420 if len(self.entites[nomMC]) == 1:
421 mc=self.entites[nomMC][0]
422 mc.dumpXsd(dansFactorisation=True)
423 self.texteComplexe += '\t'*(indent) + mc.texteElt
424 if mc.aCreer : self.texteComplexeVenantDesFils += mc.texteComplexe
425 if mc.aCreer : self.texteSimple += mc.texteSimple
426 if mc.aCreer : mc.aCreer=False
429 leType=type(self.entites[nomMC][0])
430 for e in (self.entites[nomMC][1:]) :
431 if type(e) != leType:
432 print ('Projection XSD impossible, changez un des ', nomMC)
435 # cette boucle ne fonctionne que pour des SIMP
436 resteATraiter=copy(self.entites[nomMC])
437 #print ('________resteATraiter', resteATraiter)
440 while resteATraiter != [] :
443 listePourUnion.append(mc)
444 for autre in resteATraiter[1:]:
445 if not (mc.compare(autre)) : nvlListeATraiter.append(autre)
446 resteATraiter=copy(nvlListeATraiter)
448 if len(listePourUnion) == 1:
450 mc.dumpXsd(dansFactorisation=True,multiple=False,first=first)
451 self.texteComplexe += '\t'*(indent) + mc.texteElt
452 if mc.aCreer : self.texteComplexeVenantDesFils += mc.texteComplexe
453 if mc.aCreer : self.texteSimple += mc.texteSimple
454 for mcIdent in self.entites[nomMC][1:]: mcIdent.metAJourPyxb(mc.nomDuTypePyxb)
455 if mc.aCreer : mc.aCreer=False
458 # on ajoute le nom de l element
459 if not (isinstance(self.entites[nomMC][0], Accas.SIMP)) :
460 sontTousDisjoint=True
462 if debug : print ('on cherche si ils sont disjoints : ',self.entites[nomMC])
463 for mc in self.entites[nomMC] :
464 if debug : print ('compare mc' , mc, ' avec :')
465 for mcFrere in self.entites[nomMC][index:]:
466 ok = mc.isDisjoint(mcFrere)
468 sontTousDisjoint=False
470 if not(sontTousDisjoint) : break
472 if not sontTousDisjoint:
473 print ('2 blocs freres ont le meme nom et ne sont pas disjoints : pas encore traite')
474 print ('Projection XSD impossible, changez un des ', nomMC)
476 self.fusionneDsUnChoix(nomMC,indent)
477 if debug : print ('self.nom', self.nom)
478 if debug : print ('self.texteComplexe' , self.texteComplexe)
479 if debug : print ('self.texteSimple' , self.texteSimple)
480 if debug : print ('self.texteElt' , self.texteElt)
481 if debug : print ('________________________')
485 if hasattr(self.entites[nomMC][0], 'dejaDumpe') : # on a deja cree le type
486 if debug : print (self.entites[nomMC][0].nomDuTypePyxb, ' deja dumpe')
488 if debug : print ('appel de dumpXsd')
489 self.entites[nomMC][0].dejaDumpe=True
490 self.entites[nomMC][0].dumpXsd(dansFactorisation=True,multiple=True,first=first)
491 if debug : print (self.entites[nomMC][0].nomDuTypePyxb)
495 for mc in self.entites[nomMC]:
496 if mc.ang != '' : texteDocUnion += str(i) + '- ' + mc.ang + ' or \n'; i=i+1
497 elif mc .fr != '' : texteDocUnion += str(i) + '- ' + mc.fr + ' ou \n'; i=i+1
498 if texteDocUnion == '\n' :
499 self.texteComplexe += '\t'*(indent) + self.entites[nomMC][0].texteElt
501 texteDocUnion = texteDocUnion[0:-4]
502 debutTexteEltUnion = self.entites[nomMC][0].texteElt.split('maxOccurs=')[0]
503 self.texteComplexe += '\t'*(indent)+ reconstitueUnion.format(debutTexteEltUnion,texteDocUnion)
504 if self.entites[nomMC][0].nomDuTypePyxb in self.typesXSDDejaDumpes : return
505 self.typesXSDDejaDumpes.append(self.entites[nomMC][0].nomDuTypePyxb)
506 if debug : print ('et la j ajoute les definitions de type', self.entites[nomMC][0].nomDuTypePyxb)
508 nomTypePyxbUnion=self.entites[nomMC][0].nomDuTypePyxb
509 texteSimpleUnion = debutSimpleType.format(nomTypePyxbUnion)
510 texteSimpleUnion += debutUnion
511 texteSimpleUnion += '\t'*(indent)+self.entites[nomMC][0].texteSimplePart2
512 texteSimplePart1 = self.entites[nomMC][0].texteSimplePart1
513 for e in listePourUnion[1:] :
514 e.dumpXsd(dansFactorisation=True,multiple=True,first=False)
515 # si on ext un mc simple la ligne suivante est inutile
516 # en revanche on ajoute le texte a tous les coups
517 #self.texteComplexeVenantDesFils += e.texteComplexe
518 e.metAJourPyxb(nomTypePyxbUnion)
519 texteSimpleUnion += '\t'*(indent) + e.texteSimplePart2
520 texteSimplePart1 += e.texteSimplePart1
521 texteSimpleUnion += finUnion
522 texteSimpleUnion +=fermeSimpleType
523 self.texteSimple += texteSimplePart1 + texteSimpleUnion
525 print ('______________')
526 print (self.texteSimple)
527 print ('______________')
528 #print ('self.texteSimple', self.texteSimple)
530 def fusionneDsUnChoix(self, nomMC,indent, debug=False):
531 if debug : print ('_________________________________', self.nom, self, nomMC,indent)
532 if debug : print (self.texteComplexe)
535 texteComplexeVenantDesFils=''
537 mcRef= self.entites[nomMC][0]
538 # max = 1 : a priori les choix sont exclusifs
539 if (hasattr (mcRef, 'aDejaEteDumpe')) :
540 if debug : print ("je passe la NORMALEMENT car j ai deja ete dumpe")
542 leNomDuTypePyxb = mcRef.definitNomDuTypePyxb(forceACreer=True)
543 if debug : print ('nomMC', nomMC)
544 for mc in self.entites[nomMC]:
545 if debug : print ('------------', mc)
546 # on laisse dansFactorisation a False car ce n est pas comme une fusion de bloc
547 mc.texteComplexe = ''
550 mc.dumpXsd(dansFactorisationDeFusion=True)
551 if debug : print ('texteSimple\n', mc.texteSimple, '\n fin\n')
552 if debug : print ('texteComplexeVenantDesFils\n',mc.texteComplexeVenantDesFils, '\n fin\n')
553 if debug : print ('texteComplexe\n', mc.texteComplexe, '\n fin\n')
554 if mc.ang != '' : texteDocUnion += str(i) + '- ' + mc.ang + ' or \n'; i=i+1
555 elif mc .fr != '' : texteDocUnion += str(i) + '- ' + mc.fr + ' ou \n'; i=i+1
556 texteComplexe += mc.texteComplexe
557 texteComplexeVenantDesFils += mc.texteComplexeVenantDesFils
558 texteSimple += mc.texteSimple
560 if debug : print ('______________________________')
561 if debug : print ('textecomplexeVenantDesFils : \n' ,texteComplexeVenantDesFils )
562 if debug : print ('______________________________')
563 if debug : print ('______________________________')
564 if debug : print ('textecomplexe : \n' ,texteComplexe )
565 if debug : print ('______________________________')
566 self.entites[nomMC][0].aDejaEteDumpe=True
568 self.texteElt = eltCompoDsSequence.format(nomMC, self.nomDuCodeDumpe,mcRef.nomDuTypePyxb,1,1)
569 self.texteDuFact = debutTypeCompo.format(self.entites[nomMC][0].nomDuTypePyxb)
570 self.texteDuFact += debutChoiceDsBloc
571 self.texteDuFact += texteComplexe
572 self.texteDuFact += finChoiceDsBloc
573 self.texteDuFact += finTypeCompo
574 self.texteSimple += texteSimple
575 self.texteComplexeVenantDesFils += texteComplexeVenantDesFils
576 self.texteComplexeVenantDesFils += self.texteDuFact
577 self.texteComplexe += self.texteElt
578 if debug : print ('______________________________')
579 if debug : print ('texteSimple : \n' ,self.texteSimple )
580 if debug : print ('______________________________')
581 self.entites[nomMC][0].aDejaEteDumpe=True
585 # ----------------------------------------
586 class X_definitionComposee (X_definition):
587 # ------------------------------------------
589 def creeTexteComplexeVenantDesFils(self,dansFactorisation=False,debug=False):
590 texteComplexeVenantDesFils=""
591 blocsDejaDumpes=set()
592 #for nom in self.ordre_mc:
593 # mcFils = self.entites[nom]
594 if debug : print ('creeTexteComplexeVenantDesFils', self.nom)
595 if self.nom == 'LeProc' : debug = True
596 for mcFils in self.mcXSD :
597 #print (mcFils,mcFils.nom)
598 if mcFils.nom == 'B1_B2' :debug=True
600 if not (isinstance(mcFils, Accas.BLOC)) :
601 mcFils.dumpXsd(dansFactorisation)
602 self.texteComplexe += mcFils.texteElt
603 if mcFils.aCreer : self.texteSimple += mcFils.texteSimple
604 if mcFils.aCreer : texteComplexeVenantDesFils += mcFils.texteComplexe
606 if hasattr(mcFils,'nomXML') and mcFils.nomXML in blocsDejaDumpes and mcFils.nomXML != None : continue
607 if hasattr(mcFils,'nomXML') and mcFils.nomXML != None: blocsDejaDumpes.add(mcFils.nomXML)
608 mcFils.dumpXsd(dansFactorisation)
609 self.texteComplexe += mcFils.texteElt
610 if mcFils.aCreer : self.texteSimple += mcFils.texteSimple
611 if mcFils.aCreer : texteComplexeVenantDesFils += mcFils.texteComplexe
612 return texteComplexeVenantDesFils
614 def dumpXsd(self, dansFactorisation=False, dansFactorisationDeFusion = False, multiple = False, first=True, debug=False):
615 if PourTraduction : print (self.nom)
616 # le prepareDump est appele sur les fils
617 if not (self.dejaPrepareDump) : self.prepareDumpXSD()
619 self.getNomDuCodeDumpe()
621 if multiple : self.nomDuTypePyxb = self.definitNomDuTypePyxb(forceACreer=True)
622 else : self.nomDuTypePyxb = self.definitNomDuTypePyxb()
623 self.texteSimple = "" # on n ajoute pas de type simple
626 # pour accepter les PROC et ...
628 if debug : print ('dumpXsd', self.nom, self.aCreer)
629 if self.aCreer or dansFactorisationDeFusion:
630 if not dansFactorisationDeFusion : self.texteComplexe = debutTypeCompo.format(self.nomDuTypePyxb)
631 if isinstance(self,X_OPER) or isinstance(self,X_PROC) :
632 self.texteComplexe += debutTypeCompoEtape.format(self.code)
633 self.texteComplexe += debutTypeCompoSeq
634 texteComplexeVenantDesFils= self.creeTexteComplexeVenantDesFils(dansFactorisation)
635 if not dansFactorisationDeFusion :
636 self.texteComplexe = texteComplexeVenantDesFils + self.texteComplexe
637 self.texteComplexeVenantDesFils = ''
639 self.texteComplexeVenantDesFils = texteComplexeVenantDesFils
640 # la fin de l oper est traitee dans le dumpXSD de X_OPER
641 if not isinstance(self,X_OPER ) : self.texteComplexe += finTypeCompoSeq
642 if isinstance(self,X_PROC) : self.texteComplexe += finTypeCompoEtape
643 if not isinstance(self,X_OPER ) and not dansFactorisationDeFusion: self.texteComplexe += finTypeCompo
645 self.texteComplexe = ""
647 if self.ang != "" : self.texteElt=eltCompoDsSequenceWithHelp.format(self.nom,self.nomDuCodeDumpe,self.nomDuTypePyxb,self.minOccurs,self.maxOccurs, self.ang)
648 elif self.fr != "" : self.texteElt=eltCompoDsSequenceWithHelp.format(self.nom,self.nomDuCodeDumpe,self.nomDuTypePyxb,self.minOccurs,self.maxOccurs, self.fr)
649 else : self.texteElt=eltCompoDsSequence.format(self.nom,self.nomDuCodeDumpe,self.nomDuTypePyxb,self.minOccurs,self.maxOccurs)
650 #print ('------------------------------------------------',self.nom)
651 #print (self.texteComplexe)
653 def traduitMinMax(self):
654 # ______________________
655 # valable pour PROC et OPER
659 def compare(self,autreMC):
660 if self.label != autreMC.label : return False
661 if hasattr(self,'nomXML') and hasattr(autreMC,'nomXML') and self.nomXML==autreMC.nomXML and self.nomXML != None : return True
662 for attr in ( 'regles', 'fr', 'defaut', 'min' ,'max', 'position' , 'docu' ) :
663 val1=getattr(self,attr)
664 val2=getattr(autreMC,attr)
665 if val1 != val2 : return False
666 if len(self.entites) != len(autreMC.entites) : return False
667 for defFille in self.entites.keys():
668 if defFille not in autreMC.entites.keys() : return False
669 if not self.entites[defFille].compare(autreMC.entites[defFille]) : return False
672 def prepareDumpXSD(self):
673 self.dejaPrepareDump=True
677 for nomMC in self.ordre_mc:
678 mc=self.entites[nomMC]
679 self.mcXSD.append(mc)
681 self.chercheListesDeBlocsNonDisjoints()
682 for l in list(self.listeDesBlocsNonDisjoints) :
683 if not(self.besoinDeFactoriserTrivial(l)) : self.listeDesBlocsNonDisjoints.remove(l)
684 else : self.factorise(l)
686 def chercheListesDeBlocsNonDisjoints(self):
687 self.listeDesBlocsNonDisjoints=[]
688 for nomChild in self.ordre_mc :
689 child=self.entites[nomChild]
690 if child.label != 'BLOC' : continue
691 if self.listeDesBlocsNonDisjoints == [] :
692 self.listeDesBlocsNonDisjoints.append([child])
694 vraimentIndependant=True
695 for liste in list(self.listeDesBlocsNonDisjoints):
698 if bloc.isDisjoint(child) : continue
699 if bloc.estLeMemeQue(child) : continue
701 vraimentIndependant=False
702 if not (independant) :
704 if vraimentIndependant:
705 self.listeDesBlocsNonDisjoints.append([child])
706 # on nettoye la liste des blocs tous seuls
707 for l in list(self.listeDesBlocsNonDisjoints) :
708 if len(l) ==1 : self.listeDesBlocsNonDisjoints.remove(l)
710 def estLeMemeQue(self,autreMC):
711 if hasattr(self,'nomXML') and hasattr(autreMC,'nomXML') and self.nomXML==autreMC.nomXML and self.nomXML != None: return True
714 def aUnPremierCommunDansLesPossibles(self, laListe) :
715 # fonctionne avec liste de mc ou une liste(mc,index)
718 for elt,index in laListe :
719 if not type(e) == types.ListType :
720 if elt.nom in mesPremiers : return True
721 mesPremiers.add(elt.nom)
723 if elt[0].nom in mesPremiers : return True
724 mesPremiers.add(elt[0].nom)
727 def besoinDeFactoriserTrivial(self,laListe):
733 for mcBloc in laListe :
735 if mc.label == 'BLOC' : return True
736 if not(mc.statut=='o') : return True
737 if mc.nom in lesPremiers : return True
738 lesPremiers.add(mc.nom)
741 def factorise(self,liste,debug=False):
742 self.listeConstruction=liste
743 nomDebut=liste[0].nom
744 indexDebut=self.mcXSD.index(liste[0])
746 indexFin=self.mcXSD.index(liste[-1]) + 1
747 nom=nomDebut+'_'+nomFin
748 if debug : print ('___________ dans factorise', nom)
750 for i in range(indexDebut, indexFin) :
751 listeAFactoriser.append(self.mcXSD[i])
753 newListe=self.mcXSD[0:indexDebut]
755 monEltFacteur=X_compoFactoriseAmbigu(nom,listeAFactoriser,self)
756 newListe.append(monEltFacteur)
757 newListe=newListe+self.mcXSD[indexFin:]
759 if debug :print ('___________ fin fin factorise', nom)
761 def construitTousLesFils(self):
762 for nomChild in self.ordre_mc :
763 if nomChild == 'Consigne' or nomChild == 'blocConsigne' : continue
764 child=self.entites[nomChild]
765 if child.label != 'BLOC' :
766 self.tousLesFils.append(child.nom)
768 if child.tousLesFils == [] : child.construitTousLesFils()
769 for nomPetitFils in child.tousLesFils : self.tousLesFils.append(nomPetitFils)
770 #print ('construitArbreEntier pour ', self.nom, self.tousLesFils)
773 def isDisjoint(self, mc1) :
774 if self.tousLesFils == [] : self.construitTousLesFils()
775 if not (hasattr(mc1, 'tousLesFils')) : mc1.tousLesFils = []
776 if mc1.tousLesFils == [] : mc1.construitTousLesFils()
777 for fils in mc1.tousLesFils :
778 if fils in self.tousLesFils : return False
784 # ---------------------------------
785 class X_FACT (X_definitionComposee):
786 #--------- ------------------------
787 #Un FACT avec max=** doit se projeter en XSD sous forme d'une sequence a cardinalite 1 et
788 # l'element qui porte la repetition du FACT
789 def traduitMinMax(self):
790 if self.max == '**' or self.max == float('inf') : self.maxOccurs="unbounded"
791 else : self.maxOccurs = self.max
792 self.minOccurs = self.min
793 if self.statut =='f' : self.minOccurs=0
794 if self.statut =='o' and self.min < 2: self.minOccurs=1
796 def construitArbrePossibles(self):
797 if self.statut == 'f' :
798 self.arbrePossibles = (self.nom,[])
799 self.arbreMCPossibles = (self,None)
801 self.arbrePossibles = (self.nom,)
802 self.arbreMCPossibles = (self,)
803 #print ('XFACT arbre des possibles de ' ,self.nom, self.arbrePossibles)
807 # ---------------------------------
808 class X_OPER (X_definitionComposee):
809 # ---------------------------------
810 def dumpXsd(self, dansFactorisation=False, multiple = False, first=False):
811 X_definitionComposee.dumpXsd(self,dansFactorisation)
812 self.texteComplexe += finTypeCompoSeq
813 self.texteComplexe += attributeNameName
814 self.texteComplexe += attributeTypeForASSD
815 self.texteComplexe += attributeTypeUtilisateurName.format(self.sd_prod.__name__)
816 self.texteComplexe += finTypeCompoEtape
817 self.texteComplexe += finTypeCompo
820 cata = CONTEXT.getCurrentCata()
821 if self.sd_prod.__name__ not in list(cata.dictTypesASSDorUserASSDCrees) :
822 cata.dictTypesASSDorUserASSDCrees[self.sd_prod.__name__]=[self,]
824 cata.dictTypesASSDorUserASSDCrees[self.sd_prod.__name__].append(self)
827 # ----------------------------------
828 class X_PROC (X_definitionComposee):
829 #-----------------------------------
832 #-----------------------------------
833 class X_BLOC (X_definitionComposee):
834 #-----------------------------------
835 def dumpXsd(self, dansFactorisation=False, multiple = False, first=False, debug = False):
836 if debug : print ('X_BLOC dumpXsd', self.nom)
838 if self.nom == 'blocConsigne' :
839 self.texteComplexe = ""
840 self.texteSimple = ""
841 self.nomDuTypePyxb = "NonTraiteConsigne"
842 self.texteSimpleVenantDesFils = ""
847 self.getNomDuCodeDumpe()
848 # dans ce cas les blocs successifs sont identiques et on ne dumpe que le 1er
850 self.nomDuTypePyxb = self.definitNomDuTypePyxb()
851 self.texteSimple = "" # on n ajoute pas de type simple
853 # Pour les blocs le minOccurs vaut 0 et le max 1
855 self.texteComplexe = debutTypeSubst.format(self.nomDuTypePyxb)
856 texteComplexeVenantDesFils=self.creeTexteComplexeVenantDesFils(dansFactorisation)
857 self.texteComplexe = texteComplexeVenantDesFils + self.texteComplexe
858 self.texteComplexe += finTypeSubst
861 self.texteComplexe = ""
863 self.texteElt=substDsSequence.format(self.code,self.nomDuTypePyxb,0,1,'condition : ' +self.condition)
865 #print ('------------------------------------------------')
867 def compare(self,autreMC):
868 if self.label != autreMC.label : return False
869 if self.inUnion == True or autreMC.inUnion == True : return False
870 if hasattr(self,'nomXML') and hasattr(autreMC,'nomXML') and self.nomXML==autreMC.nomXML and self.nomXML != None : return True
871 for attr in ( 'condition', 'regles', ):
872 val1=getattr(self,attr)
873 val2=getattr(autreMC,attr)
874 if val1 != val2 : return False
875 if len(self.entites) != len(autreMC.entites) : return False
876 for defFille in self.entites.keys():
877 if defFille not in autreMC.entites.keys() : return False
878 if not self.entites[defFille].compare(autreMC.entites[defFille]) : return False
881 def construitArbrePossibles(self):
882 self.arbrePossibles=[[],]
883 #print ('X_BLOC je construis l arbre des possibles pour ', self.nom)
884 for child in self.mcXSD :
885 if not hasattr(child, 'arbrePossibles') : child.construitArbrePossibles()
886 #print (child.nom, child.label, child.arbrePossibles)
887 if child.label == 'BLOC' :
888 self.arbrePossibles = deepcopy(self.remplaceListeParContenuEtVide(self.arbrePossibles, child.arbrePossibles))
889 elif child.label == 'BlocAmbigu':
890 #print ("je passe par la pour", self.nom, child.nom, self.arbrePossibles, child.arbrePossibles)
891 self.arbrePossibles = deepcopy(self.remplaceListeParContenuEtVide(self.arbrePossibles, child.arbrePossibles))
892 #print ('resultat', self.arbrePossibles)
894 self.arbrePossibles = deepcopy(self.adjoint(self.arbrePossibles, child.arbrePossibles))
895 self.arbrePossibles.append([]) # un bloc n est pas obligatoire
896 #print ('arbre des possibles de ' ,self.nom, self.arbrePossibles)
899 #--------------------------------
900 class X_SIMP (X_definition):
901 #--------------------------------
902 def dumpXsd(self, dansFactorisation=False, multiple=False, first=False, debug=False):
904 #if PourTraduction : print (self.nom)
905 if debug : print ('X_SIMP dumpXsd pour', self.nom, '___________________________')
906 self.prepareDumpXSD()
907 # si inUnion la comparaison est fausse : on cree le nomDuType
908 if multiple : self.inUnion=True
909 #print ('exploreObjet SIMP')
910 self.getNomDuCodeDumpe()
912 self.texteComplexe = ""
913 self.texteSimple = ""
915 if self.nom =='Consigne' : return
917 # --> homonymie on peut utiliser genealogie ?
918 self.nomDuTypeDeBase = self.traduitType()
919 if debug : print ('nomDuTypeDeBase', self.nomDuTypeDeBase)
920 if debug : print ('multiple', multiple, 'first', first)
922 self.nomDuTypePyxb = self.definitNomDuTypePyxb()
925 # on force la creation
926 self.nomDuTypePyxb = self.definitNomDuTypePyxb()
929 self.nomDuTypePyxb='NonDetermine'
931 if debug : print ('nomDuTypePyxb', self.nomDuTypePyxb)
932 if debug : print ('aCreer', self.aCreer)
935 # on se sert des listes ou non pour la gestion des minOccurs /maxOccurs est > 0
936 if self.statut =='f' : minOccurs = 0
938 if dansFactorisation : minOccurs = 1
940 if self.suisUneMatrice :
941 self.dumpSpecifiqueMatrice(minOccurs)
944 if self.suisUnTuple :
945 self.dumpSpecifiqueTuple(minOccurs)
948 if self.avecBlancs and self.max > 1 :
949 #print ('je suis avec blanc pour ', self.nom)
950 self.dumpSpecifiqueTexteAvecBlancs(minOccurs,multiple)
953 #print ('minOccurs',minOccurs)
954 # le defaut est dans l elt Name -> tester la coherence d existence avec Accas
957 # pas d elt si on est dans multiple
958 # sauf si on est le '1er' dans un element ambigu
960 #print ('je passe la pas multiple')
962 if self.ang != '' : texteAide = self.ang
963 else : texteAide = self.fr
964 if self.intoXML and self.into :
965 if self.intoXML != self.into :
966 #print ('je passe la pour ', self.nom)
967 texteAide :texteAide = texteAide+'\nPossible choices for '+ self.nom + 'at this place : \n'+str(self.into)+'\n'
970 if self.max > 1 or self.max == '**' or self.max == float('inf') :
972 for val in self.defaut : txtDefaut+=str(val) + " "
973 # cela ne fonctionne pas tres bien. a revoir
974 txtDefaut+=txtDefaut[0:-1]
975 if not('TXM' in (self.type)) :
976 # a revoir pour les tuples avec defaut
977 if texteAide != '' : self.texteElt = eltDsSequenceWithDefautAndHelp.format(self.nom,self.code,self.nomDuTypePyxb,minOccurs,1,txtDefaut,texteAide)
978 else : self.texteElt = eltDsSequenceWithDefaut.format(self.nom,self.code,self.nomDuTypePyxb,minOccurs,1,txtDefaut)
980 texteAide += texteAide+'\ndefault Value in MDM : \n'+txtDefaut
981 self.texteElt = eltDsSequenceWithHelp.format(self.nom,self.code,self.nomDuTypePyxb,minOccurs,1,texteAide)
983 if str(self.defaut) == 'True' : txtDefaut = 'true'
984 elif str(self.defaut) == 'False' : txtDefaut = 'false'
985 else : txtDefaut = str(self.defaut)
986 if texteAide != '' : self.texteElt = eltDsSequenceWithDefautAndHelp.format(self.nom,self.code,self.nomDuTypePyxb,minOccurs,1,txtDefaut,texteAide)
987 else : self.texteElt = eltDsSequenceWithDefaut.format(self.nom,self.code,self.nomDuTypePyxb,minOccurs,1,txtDefaut)
989 if texteAide != '' : self.texteElt = eltDsSequenceWithHelp.format(self.nom,self.code,self.nomDuTypePyxb,minOccurs,1,texteAide)
990 else : self.texteElt = eltDsSequence.format(self.nom,self.code,self.nomDuTypePyxb,minOccurs,1)
992 # l'aide est geree a la fusion
993 self.texteElt = eltDsSequence.format(self.nom,self.code,self.nomDuTypePyxb,1,1)
995 # self.aCreer est mis a jour ds definitNomDuTypePyxb
996 # ou si elt est le 1er d une liste identique
997 if debug : print ('je suis aCreer', self.aCreer)
998 if not self.aCreer : return
1000 typeATraduire=self.type[0]
1002 self.texteSimplePart1=""
1003 if not(isinstance(typeATraduire,str)) and not(isinstance(typeATraduire,Accas.Tuple)) and issubclass(typeATraduire, Accas.UserASSD) :
1004 cata = CONTEXT.getCurrentCata()
1005 if len(self.type) == 2 and self.type[1]=='createObject' : suffixe = 'C'
1006 else : suffixe = 'U'
1007 #print (cata.listeUserASSDDumpes)
1008 #print (typeATraduire.__name__)
1009 #print (typeATraduire.__name__ in cata.listeUserASSDDumpes)
1010 if typeATraduire.__name__ not in cata.listeUserASSDDumpes :
1011 cata.listeUserASSDDumpes.add(typeATraduire.__name__)
1012 if issubclass(typeATraduire, Accas.UserASSDMultiple) :
1013 self.texteSimplePart1 = defUserASSDMultiple.format(typeATraduire.__name__)
1014 if cata.definitUserASSDMultiple == False :
1015 cata.definitUserASSDMultiple = True
1016 cata.texteSimple = cata.texteSimple + defBaseXSDUserASSDMultiple
1018 self.texteSimplePart1 = defUserASSD.format(typeATraduire.__name__)
1019 if cata.definitUserASSD == False :
1020 cata.definitUserASSD = True
1021 cata.texteSimple = cata.texteSimple + defBaseXSDUserASSD
1022 if typeATraduire.__name__+'_'+suffixe not in cata.listeUserASSDDumpes :
1023 cata.texteSimple = cata.texteSimple + defUserASSDOrUserASSDMultiple.format(typeATraduire.__name__, suffixe,typeATraduire.__name__)
1024 cata.listeUserASSDDumpes.add(typeATraduire.__name__+'_'+suffixe)
1027 if not multiple : self.texteSimple += debutSimpleType.format(self.nomDuTypePyxb)
1028 else : self.texteSimple += debutSimpleTypeSsNom
1029 # On est dans une liste
1030 if self.max > 1 or self.max == '**' or self.max == float('inf') or hasattr(self.type[0], 'ntuple') :
1031 self.texteSimple += debutTypeSimpleListe
1032 self.texteSimple += "\t\t\t\t"+debutRestrictionBase.format(self.nomDuTypeDeBase)
1033 if self.val_min != float('-inf') : self.texteSimple += "\t\t\t\t"+minInclusiveBorne.format(self.val_min)
1034 if self.val_max != float('inf') and self.val_max != '**' : self.texteSimple +="\t\t\t\t"+ maxInclusiveBorne.format(self.val_max)
1035 if self.into != None:
1036 # PN --> traduction des into
1038 if self.intoXML != None : into = self.intoXML
1039 for val in into : self.texteSimple += "\t\t\t\t"+enumeration.format(val)
1041 for val in into : print (str(val))
1042 self.texteSimple += fermeBalisesMileu
1043 if self.max !=1 and self.max != '**' and self.max != float('inf') : self.texteSimple += maxLengthTypeSimple.format(self.max)
1044 if self.min !=1 and self.min != float('-inf') : self.texteSimple += minLengthTypeSimple.format(self.min)
1045 self.texteSimple += fermeRestrictionBase
1048 self.texteSimple += debutRestrictionBase.format(self.nomDuTypeDeBase)
1049 if self.val_min != float('-inf') : self.texteSimple += minInclusiveBorne.format(self.val_min)
1050 if self.val_max != float('inf') and self.val_max != '**' : self.texteSimple += maxInclusiveBorne.format(self.val_max)
1051 if self.into != None:
1053 if self.intoXML != None : into = self.intoXML
1054 for val in into : self.texteSimple += enumeration.format(val)
1056 for val in into : print (str(val))
1057 self.texteSimple += fermeRestrictionBase
1058 self.texteSimple += fermeSimpleType
1059 self.texteSimplePart2 = self.texteSimple
1060 self.texteSimple = self.texteSimplePart1 + self.texteSimplePart2
1063 def dumpSpecifiqueTexteAvecBlancs(self,minOccurs,multiple):
1064 # attention multiple non traite
1065 # pour l instant on n a pas max =1 et on ne traite pas les into
1068 if self.ang != '' : texteAide = self.ang
1069 elif self.fr != '' : texteAide = self.fr
1071 self.texteElt = eltDsSequenceWithHelp.format(self.nom,self.code,self.nomDuTypePyxb,minOccurs,1,texteAide)
1073 # Pas de Defaut pour les string en XSD
1074 # max sert pour la taille de la liste
1075 if self.defaut : texteAide += ' Valeur par defaut dans le comm : '+str(self.defaut)
1076 if texteAide != '' : self.texteElt = eltDsSequenceWithHelp.format(self.nom,self.code,self.nomDuTypePyxb,minOccurs,1,texteAide)
1077 else : self.texteElt = eltDsSequence.format(self.nom,self.code,self.nomDuTypePyxb,minOccurs,1)
1080 if self.max == '**' or self.max == float('inf') : max='unbounded'
1081 else : max = self.max
1083 if self.max > 1 : # juste au cas ou on traite 1 pareil
1084 self.texteSimple = ''
1085 cata = CONTEXT.getCurrentCata()
1086 if self.nomDuTypePyxb in cata.listeTypeTXMAvecBlancs: return
1087 cata.listeTypeTXMAvecBlancs.add(self.nomDuTypePyxb)
1088 self.texteSimple = complexChaineAvecBlancs.format(self.nomDuTypePyxb,max,self.nomDuTypePyxb)
1089 if self.intoXML != None : into = self.intoXML
1090 else : into = self.into
1092 self.texteSimple += typeEltChaineAvecBlancSansInto.format(self.nomDuTypePyxb)
1094 self.texteSimple += debutChaineAvecBlancsInto.format(self.nomDuTypePyxb)
1095 for val in into : self.texteSimple += milieuChaineAvecBlancsInto.format(val)
1096 self.texteSimple += finChaineAvecBlancsInto
1099 def dumpSpecifiqueTuple(self,minOccurs):
1100 self.nomDuTypeDeBase = self.traduitType()
1102 # il faut gerer l aide et les defaut
1103 if self.defaut : print ('il faut tester le defaut')
1104 if self.max == '**' or self.max == float('inf') : max='unbounded'
1105 else : max = self.max
1106 self.texteElt = tupleNonHomogeneElt.format(self.nom,self.code,self.nomDuTypePyxb,minOccurs,max)
1107 leType=self.nomDuTypeDeBase[0]
1108 for leTypeComp in self.nomDuTypeDeBase[1:] :
1109 if leTypeComp != leType :
1114 # self.texteSimple += debutSimpleType.format(self.nomDuTypePyxb)
1115 # self.texteSimple += debutTypeSimpleListe
1116 # self.texteSimple += "\t\t\t\t"+debutRestrictionBase.format(leType)
1117 # if self.val_min != float('-inf') : self.texteSimple += "\t\t\t\t"+minInclusiveBorne.format(self.val_min)
1118 # if self.val_max != float('inf') and self.val_max != '**' : self.texteSimple +="\t\t\t\t"+ maxInclusiveBorne.format(self.val_max)
1119 # if self.into != None:
1121 # if self.intoXML != None : into = self.intoXML
1122 # for val in into : self.texteSimple += "\t\t\t\t"+enumeration.format(val)
1123 # if PourTraduction :
1124 # for val in into : print (str(val))
1125 # self.texteSimple += fermeBalisesMileu
1126 # if self.max !=1 and self.max != '**' and self.max != float('inf') : self.texteSimple += maxLengthTypeSimple.format(self.max)
1127 # if self.min !=1 and self.min != float('-inf') : self.texteSimple += minLengthTypeSimple.format(self.min)
1128 # self.texteSimple += fermeSimpleType
1131 self.texteSimple = ''
1132 complexeTypeTuple = tupleDebutComplexeType.format(self.nomDuTypePyxb)
1134 for leType in self.nomDuTypeDeBase :
1135 self.texteSimple += tupleNonHomogeneSimpleType.format(self.nomDuTypePyxb,str(num),leType)
1136 complexeTypeTuple += tupleMilieuComplexeType.format(str(num),self.nomDuTypePyxb,str(num))
1138 complexeTypeTuple += tupleFinComplexeType
1139 self.texteSimple += complexeTypeTuple
1142 def dumpSpecifiqueMatrice(self,minOccurs):
1143 # if faut traiter le defaut
1144 typeDeMatrice =self.type[0]
1146 self.texteSimple += debutSimpleType.format(self.nomDuTypePyxb+'_element')
1147 self.texteSimple += debutRestrictionBase.format(self.nomDuTypeDeBase)
1148 if typeDeMatrice.typEltInto != None:
1149 for val in typeDeMatrice.typEltInto : self.texteSimple += enumeration.format(val)
1150 self.texteSimple += fermeRestrictionBase
1151 self.texteSimple += fermeSimpleType
1152 nom=self.nomDuTypePyxb
1153 nbCols=typeDeMatrice.nbCols
1154 nbLigs=typeDeMatrice.nbCols
1155 self.texteSimple += matriceSimpleType.format(nom,nom,nbCols,nom,self.code,nom,nbLigs,nbLigs,nom,self.code,nom,self.min,self.max)
1156 self.texteElt = eltMatrice.format(self.nom,self.code,self.nomDuTypePyxb,minOccurs,1)
1159 def prepareDumpXSD(self):
1161 if self.statut == 'f' : self.arbrePossibles = (self.nom,[])
1162 else : self.arbrePossibles = (self.nom,)
1167 def traduitType(self,debug=False):
1168 # il faut traduire le min et le max
1169 # il faut ajouter les regles
1170 # il faut gerer les types tuple et fichier
1171 # on ne paut pas tester le type qui depend du cataloge
1172 if hasattr(self.type[0], 'typElt') :
1173 #print ('je suis une Matrice de ' ,dictNomsDesTypes[self.type[0].typElt])
1174 self.suisUneMatrice = True
1175 # on presume que le type de l elt est un ASSD
1176 if self.type[0].typElt not in dictNomsDesTypes.keys(): return 'xs:string'
1177 return dictNomsDesTypes[self.type[0].typElt]
1179 self.suisUneMatrice = False
1180 if hasattr(self.type[0], 'ntuple') :
1181 self.suisUnTuple = True
1182 # Pour l instant pas de into dans les tuples non homogenes et pas de reference
1183 # sinon, il faudra faire un for sur la suite avec les createObjet
1184 leType=self.validators.typeDesTuples[0]
1186 for i in range(self.type[0].ntuple):
1187 enRetour.append(dictNomsDesTypes[self.validators.typeDesTuples[i]])
1189 #typeATraduire=leType
1191 self.suisUnTuple = False
1192 typeATraduire=self.type[0]
1193 if not (typeATraduire in list(dictNomsDesTypes.keys())) :
1194 #if (isinstance(typeATraduire, Accas.ASSD) or issubclass(typeATraduire, Accas.ASSD)) :
1195 if (not(isinstance(typeATraduire,str)) and issubclass(typeATraduire, Accas.ASSD)) :
1196 # cas d une creation
1197 cata = CONTEXT.getCurrentCata()
1198 # PNPNPN a Revoir pour la creation des keyrefs
1199 if len(self.type) == 2 and self.type[1]=='createObject' :
1200 if typeATraduire.__name__ not in list(cata.dictTypesASSDorUserASSDCrees) :
1201 cata.dictTypesASSDorUserASSDCrees[typeATraduire.__name__]=[self,]
1203 cata.dictTypesASSDorUserASSDCrees[typeATraduire.__name__].append(self)
1204 if issubclass(typeATraduire, Accas.UserASSD) : return typeATraduire.__name__+'_C'
1205 else : return 'xs:string'
1207 # cas d une consommation
1208 if typeATraduire not in list(cata.dictTypesASSDorUserASSDUtilises) :
1209 cata.dictTypesASSDorUserASSDUtilises[typeATraduire]=[self,]
1211 cata.dictTypesASSDorUserASSDUtilises[typeATraduire].append(self,)
1212 if issubclass(typeATraduire, Accas.UserASSD) : return typeATraduire.__name__+'_U'
1213 else : return 'xs:string'
1214 else : return ('YYYYY')
1215 return dictNomsDesTypes[typeATraduire]
1217 def traduitValMinValMax(self):
1218 self.maxInclusive=self.val_max
1219 self.minInclusive=self.val_min
1220 if self.val_min == float('-inf') and val_max== float('inf') : return
1221 #print ('il faut affiner le type du SIMP ', self.nom)
1222 if self.val_max == '**' or self.val_max == float('inf') : self.maxInclusive=None
1223 else : self.maxInclusive = self.val_max
1224 if self.val_min == '**' or self.val_max == float('-inf') : self.maxInclusive=None
1225 else : self.minInclusive = self.val_min
1227 def traduitMinMax(self):
1228 if self.min == 1 and self.max == 1 : return
1229 #print ('il faut creer une liste ' , self.nom)
1231 def compare(self,autreMC):
1232 if self.label != autreMC.label : return False
1233 if self.inUnion == True or autreMC.inUnion == True : return False
1234 if hasattr(self,'nomXML') and hasattr(autreMC,'nomXML') and self.nomXML==autreMC.nomXML and self.nomXML != None : return True
1235 listeAComparer = [ 'type', 'defaut', 'min' ,'max' ,'val_min' , 'val_max' ]
1236 if self.intoXML != None : listeAComparer.append('intoXML')
1237 else : listeAComparer.append('into')
1238 if (hasattr (self, 'nomXML')) and self.nomXML != None : nomUtil=self.nomXML
1239 for attr in listeAComparer :
1240 val1=getattr(self,attr)
1241 val2=getattr(autreMC,attr)
1242 if val1 != val2 : return False
1245 def construitArbrePossibles(self):
1246 if self.statut == 'f' :
1247 self.arbrePossibles = (self.nom,[])
1249 self.arbrePossibles = (self.nom,)
1250 #print ('SIMP arbre des possibles de ' ,self.nom, self.arbrePossibles)
1257 def dumpXsd(self, avecEltAbstrait, debug = True):
1258 cata = CONTEXT.getCurrentCata()
1259 if debug : print ('avecEltAbstrait -------------------', avecEltAbstrait)
1261 if debug : print ('self.importedBy -------------------', self.importedBy)
1262 if debug : print ('self.code -------------------', self.code)
1264 self.texteSimple = ""
1265 self.texteComplexe = ""
1267 self.texteDeclaration = ""
1268 self.texteInclusion = ""
1270 self.texteTypeAbstrait = ""
1272 if self.implement == "" :
1273 self.nomDuCodeDumpe = self.code
1274 self.implement = self.code
1275 self.nomDuXsdPere = self.code
1277 self.implement,self.nomDuXsdPere=self.implement.split(':')
1278 self.nomDuCodeDumpe = self.implement
1280 if debug : print ('self.implement -------------------', self.implement)
1281 if debug : print ('self.nomDuCodeDumpe -------------------', self.nomDuCodeDumpe)
1282 if debug : print ('self.nomDuXsdPere -------------------', self.nomDuXsdPere)
1284 self.nomDuTypePyxb = 'T_'+self.nomDuCodeDumpe
1285 self.dumpLesCommandes()
1287 if self.implement == self.code :
1288 self.texteCata += eltAbstraitCataPPal.format(self.code)
1290 else : self.texteCata += eltCataPPal.format(self.code,self.code,self.code)
1292 self.texteCata += eltAbstraitCataFils.format(self.implement,self.nomDuXsdPere,self.nomDuXsdPere)
1294 else : self.texteCata += eltCataFils.format(self.implement,self.nomDuXsdPere,self.nomDuXsdPere,self.nomDuXsdPere)
1295 self.texteInclusion += includeCata.format(self.nomDuXsdPere)
1298 self.texteCata += eltCata.format(self.implement,self.implement,self.implement,self.implement,self.nomDuXsdPere)
1299 #if self.implement == self.code :
1300 # self.texteCata += debutTypeCata.format(self.nomDuCodeDumpe)
1302 # self.texteCata += debutTypeCataExtension.format(self.nomDuCodeDumpe)
1303 # self.texteCata += debutExtension.format(self.code,self.nomDuCodeDumpe)
1304 # self.texteInclusion += includeCata.format(self.nomDuXsdPere)
1308 #for codeHeritant in self.importedBy:
1309 # self.texteCata += eltCodeSpecDsCata.format(codeHeritant)
1310 # self.texteTypeAbstrait += eltAbstrait.format(codeHeritant,codeHeritant,self.code,codeHeritant)
1312 #if self.implement != "" : self.texteCata = self.texteCata + finExtension + finTypeCompo
1313 #else : self.texteCata += finTypeCata
1315 #if self.implement != "" :
1316 # self.texteElt=implementeAbstrait.format(self.nomDuCodeDumpe,self.code,self.nomDuTypePyxb,self.code,self.nomDuCodeDumpe)
1318 # self.texteElt = eltCata.format(self.nomDuCodeDumpe,self.code, self.nomDuTypePyxb)
1320 if self.implement == self.code :
1321 self.texteXSD = texteDebut.format(self.code,self.code,self.code,self.code,self.code,self.code)
1322 elif self.nomDuXsdPere == self.code :
1323 self.texteXSD = texteDebutNiveau2.format(self.code,self.implement,self.code,self.code,self.code, self.code,self.code,self.code,self.code,self.code)
1325 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)
1327 if self.texteInclusion != "" : self.texteXSD += self.texteInclusion
1328 self.texteXSD += self.texteSimple
1329 self.texteXSD += self.texteComplexe
1331 #if self.texteTypeAbstrait != "" : self.texteXSD += self.texteTypeAbstrait
1332 self.texteXSD += self.texteCata
1333 #self.texteXSD += self.texteElt
1337 # Pour le nom des key_ref en creation : le type ( une seule key-ref par type. facile a retrouver)
1338 for clef in self.dictTypesASSDorUserASSDCrees:
1341 for unOper in self.dictTypesASSDorUserASSDCrees[clef]:
1342 if not(isinstance(unOper, Accas.OPER)) : continue
1344 texteDesFields+=texteFieldUnitaire.format(self.code, unOper.nom)
1345 if existeASSD : texteDesFields=texteDesFields[0:-2]
1348 for unSimp in self.dictTypesASSDorUserASSDCrees[clef]:
1349 if not (isinstance(unSimp, Accas.SIMP)) : continue
1350 texteDesUserASSD += unSimp.getXPathSansSelf() + " | "
1351 #print (unSimp.getXPathSansSelf())
1352 #texteFieldUnitaire='/'+self.code+":"+unSimp.nom
1354 if existeunUserASSD:
1355 if existeASSD : texteDesFields = texteDesFields + texteDesUserASSD[0:-2] +"/>\n\t\t"
1356 else: texteDesFields = texteDesUserASSD[0:-2]
1357 #print (texteDesUserASSD)
1358 #print (texteDesFields)
1359 if texteDesFields != "" :
1360 texteKeyRef += producingASSDkeyRefDeclaration.format( clef ,texteDesFields)
1363 # Pour le nom des key-ref en utilisation : la genealogie complete ( une key-ref par utilisation et on retrouve facilement la )
1364 for clef in self.dictTypesASSDorUserASSDUtilises:
1365 for unSimp in self.dictTypesASSDorUserASSDUtilises[clef]:
1366 # il faut la genealogie
1367 texteKeyRef += UsingASSDkeyRefDeclaration.format(unSimp.getNomCompletAvecBloc(), unSimp.type[0].__name__,self.code, unSimp.type[0].__name__,unSimp.getXPathComplet() )
1369 #PNPN on debranche les keyref le temps de bien reflechir a leur forme
1370 #if texteKeyRef != '' :
1371 # self.texteXSD = self.texteXSD[0:-3]+'>\n'
1372 # self.texteXSD += texteKeyRef
1373 # self.texteXSD += fermeEltCata
1377 #if not PourTraduction : print (self.texteXSD)
1380 #pprint.pprint (cata.dictTypesXSDJumeaux)
1381 #for k in cata.dictTypesXSDJumeaux:
1382 # print (k.nom, k.nomComplet())
1383 # print (cata.dictTypesXSDJumeaux[k][0].nom, cata.dictTypesXSDJumeaux[k][0].nomComplet())
1385 #pprint.pprint (cata.dictTypesXSD)
1386 #for k in cata.dictTypesXSD:
1388 # print (cata.dictTypesXSD)
1391 for k in list(cata.dictTypesXSD.keys()):
1394 for definition in cata.dictTypesXSD[k] :
1395 if definition.label == 'BLOC' or definition.label == 'BlocAmbigu':continue
1396 if definition.nomDuTypePyxb != 'T_'+definition.nom : different=True
1397 listeATraiter=[definition.geneaCompleteSousFormeDeListe(),]
1398 while listeATraiter != [] :
1399 listeGenea=listeATraiter[0]
1400 listeATraiter=listeATraiter[1:]
1403 for MC in listeGenea:
1404 txtNomComplet=txtNomComplet+'_'+MC.nom
1405 if MC in list(cata.dictTypesXSDJumeaux.keys()) :
1406 for MCJumeau in cata.dictTypesXSDJumeaux[MC]:
1407 # attention nvlleGenalogie n a pas de sens en Accas
1408 nvlleGenalogie=listeGenea[:indexMC]+MCJumeau.geneaCompleteSousFormeDeListe()
1409 listeATraiter.append(nvlleGenalogie)
1411 dico[k][txtNomComplet]=definition.nomDuTypePyxb
1412 if dico[k]== {} or (not different) : del dico[k]
1414 #pprint.pprint(dico)
1415 # PN reflechir a ce *** de nom
1416 #if dico != {} : self.texteXSD += texteAnnotation.format(self.nomDuCodeDumpe,str(dico))
1417 if dico != {} : self.texteXSD += texteAnnotation.format(str(dico))
1420 #if (not PourTraduction) and (dico != {}) : pprint.pprint(dico)
1421 print ('__________________________ decommenter pour le texteXSD________________________')
1423 #print (self.texteXSD)
1424 self.texteXSD += texteFin
1425 return self.texteXSD
1428 def dumpLesCommandes(self):
1429 cata = CONTEXT.getCurrentCata()
1430 fichierCataSourceExt=os.path.basename(cata.cata.__file__)
1431 fichierCataSource, extension=os.path.splitext(fichierCataSourceExt)
1432 importCataSource=__import__(fichierCataSource,{},{})
1435 for m in sys.modules:
1436 monModule=sys.modules[m]
1438 if m in ('os', 'sys', 'inspect', 'six', 'pickle', 'codecs') : continue
1439 if m in ('cPickle', 'pprint', 'dis', '_sre', 'encodings.aliases'): continue
1440 if m in ('numbers', 'optparse', 'binascii', 'posixpath') : continue
1441 if m in ('_locale', '_sysconfigdata_nd', 'gc', 'functools') : continue
1442 if m in ('posixpath', 'types', 'posix', 'prefs') : continue
1443 if m in ('warnings', 'types', 'posix', 'prefs') : continue
1444 if monModule.__name__[0:15] == '_sysconfigdata_' : continue
1445 if monModule.__name__ == '__future__' : continue
1446 if monModule.__name__[0:3] == 'Ihm' : continue
1447 if monModule.__name__[0:5] == 'numpy' : continue
1448 if monModule.__name__[0:5] == 'Noyau' : continue
1449 if monModule.__name__[0:5] == 'Accas' : continue
1450 if monModule.__name__[0:7] == 'convert' : continue
1451 if monModule.__name__[0:7] == 'Efi2Xsd' : continue
1452 if monModule.__name__[0:7] == 'Editeur' : continue
1453 if monModule.__name__[0:9] == 'generator' : continue
1454 if monModule.__name__[0:10] == 'Validation' : continue
1455 if monModule.__name__[0:10] == 'Extensions' : continue
1456 if monModule.__name__[0:12] == 'InterfaceQT4' : continue
1457 if monModule.__name__ == fichierCataSource : continue
1458 texte= texte + "try : import "+ monModule.__name__ + " \n"
1459 texte= texte + "except : pass \n"
1460 texte= texte + "try : from "+ monModule.__name__ + ' import * \n'
1461 texte= texte + "except : pass \n"
1465 newModule=imp.new_module('__main__')
1466 exec (texte, newModule.__dict__)
1468 for i in dir(importCataSource):
1469 if i not in dir(newModule):
1470 allClassToDump.append(importCataSource.__dict__[i])
1473 self.texteSimple = ''
1474 self.texteComplexe = ''
1475 for c in allClassToDump :
1476 if not(isinstance(c, Accas.OPER)) and not(isinstance(c, Accas.PROC)) : continue
1477 c.nomDuCodeDumpe=self.nomDuCodeDumpe
1478 c.code=self.implement
1481 self.texteSimple += c.texteSimple
1482 self.texteComplexe += c.texteComplexe
1483 if c.ang != '' : c.texteElt = eltEtapeWithHelp.format(c.nom,self.implement,c.nomDuTypePyxb,self.implement,c.ang)
1484 elif c.fr != '' : c.texteElt = eltEtapeWithHelp.format(c.nom,self.implement,c.nomDuTypePyxb,self.implement,c.fr)
1485 else : c.texteElt = eltEtape.format(c.nom,self.implement,c.nomDuTypePyxb,self.implement)
1486 self.texteCata += c.texteElt