Salome HOME
PN pour notation scientifique
[tools/eficas.git] / Editeur / autre_analyse_cata.py
1 # -*- coding: utf-8 -*-
2 #            CONFIGURATION MANAGEMENT OF EDF VERSION
3 # ======================================================================
4 # COPYRIGHT (C) 1991 - 2002  EDF R&D                  WWW.CODE-ASTER.ORG
5 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
6 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
7 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
8 # (AT YOUR OPTION) ANY LATER VERSION.
9 #
10 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
11 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
12 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
13 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
14 #
15 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
16 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
17 #    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
18 #
19 #
20 # ======================================================================
21 """
22    Ce module sert a retrouver l'ordre des mots cles d'un catalogue de
23    commandes
24 """
25 if __name__ == "__main__" :
26    import sys
27    sys.path[:0]=[".."]
28    sys.path[:0]=["../Aster"]
29    sys.path[:0]=["../Saturne"]
30
31 from Accas import NUPL
32
33 def traite_entiteNUPL(entite):
34    """
35        Fonction speciale pour les nuplets (classe NUPL)
36        Cette fonction ajoute a l'objet entite un attribut de nom ordre_mc
37        qui est une liste vide.
38    """
39    entite.ordre_mc=[]
40
41 def traite_entite(entite,liste_simp_reel):
42    """
43        Cette fonction ajoute a l'objet entite un attribut de nom ordre_mc
44        qui est une liste contenant le nom des sous entites dans l'ordre 
45        de leur apparition dans le catalogue.
46        L'ordre d'apparition dans le catalogue est donné par l'attribut _no
47        de l'entite
48        La fonction active le meme type de traitement pour les sous entites
49        de entite
50    """
51    l=[]
52    for k,v in entite.entites.items():
53       if isinstance(v,NUPL):
54          traite_entiteNUPL(v)
55       else:
56          traite_reel(v,liste_simp_reel)
57          traite_entite(v,liste_simp_reel)
58       l.append((v._no,k))
59    l.sort()
60    entite.ordre_mc=[ item for index, item in l ]
61
62 def traite_reel(objet,liste_simp_reel):
63     if objet.__class__.__name__ == "SIMP":
64        if ( 'R' in objet.type):
65           if objet.nom not in liste_simp_reel :
66              liste_simp_reel.append(objet.nom)
67
68 def analyse_niveau(cata_ordonne_dico,niveau,liste_simp_reel):
69    """
70        Analyse un niveau dans un catalogue de commandes
71    """
72    if niveau.l_niveaux == ():
73        # Il n'y a pas de sous niveaux
74        for oper in niveau.entites:
75            traite_entite(oper,liste_simp_reel)
76            cata_ordonne_dico[oper.nom]=oper
77    else:
78        for niv in niveau.l_niveaux:
79            analyse_niveau(cata_ordonne_dico,niv)
80   
81 def analyse_catalogue(cata):
82    """
83       Cette fonction analyse le catalogue cata pour construire avec l'aide
84       de traite_entite la structure de données ordre_mc qui donne l'ordre
85       d'apparition des mots clés dans le catalogue
86       Elle retourne un dictionnaire qui contient toutes les commandes
87       du catalogue indexées par leur nom
88    """
89    cata_ordonne_dico={}
90    liste_simp_reel=[]
91    if cata.JdC.l_niveaux == ():
92        # Il n'y a pas de niveaux
93        a=1
94        for oper in cata.JdC.commandes:
95            traite_entite(oper,liste_simp_reel)
96            cata_ordonne_dico[oper.nom]=oper
97    else:
98        for niv in cata.JdC.l_niveaux:
99            analyse_niveau(cata_ordonne_dico,niv,liste_simp_reel)
100    return cata_ordonne_dico,liste_simp_reel
101
102
103 if __name__ == "__main__" :
104    from Cata import cata_STA6
105    dico=analyse_catalogue(cata_STA6)
106    #import cata_saturne
107    #dico=analyse_catalogue(cata_saturne)
108
109    def print_entite(entite,dec='  '):
110        print dec,entite.nom,entite.__class__.__name__
111        for mocle in entite.ordre_mc:
112           print_entite(entite.entites[mocle],dec=dec+'  ')
113
114    for k,v in dico.items():
115       print_entite(v,dec='')
116
117    print dico.keys()