Salome HOME
debug intempestif
[tools/eficas.git] / Noyau / N_UserASSDMultiple.py
1 # coding=utf-8
2 # Copyright (C) 2007-2021   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19
20 """
21
22 """
23
24 from __future__ import absolute_import
25 from __future__ import print_function
26 try :
27     from builtins import object
28 except : pass
29 import traceback
30 import sys
31
32 from .N_UserASSD import UserASSD
33 from .N_ASSD import ASSD
34
35 try:
36     from collections import UserList
37 except ImportError:
38     from UserList import UserList
39
40 class UserASSDMultiple(UserASSD):
41     """
42        Classe de base pour definir des types de structures de donnees definie par
43        l utilisateur
44        equivalent d un concept ASSD pour un SIMP ou un FACT
45        mais pouvant referencer 2 objets par exemple les groupes de mailles qui peuvent porter
46        le meme nom dans 2 maillages differents
47     """
48     def __init__(self,nom='sansNom'):
49         #print ('dans init de UserASSDMultiple ',nom)
50         UserASSD.__init__(self,nom)
51         self.peres=[]
52
53     def ajouteUnPere(self,pere):
54         #print ('dans ajouteUnPere', self.peres, self.nom, pere)
55         if pere not in self.peres : self.peres.append(pere)
56         etape = pere.getEtape()
57         if self not in etape.userASSDCrees : etape.userASSDCrees.append(self)
58
59     def renomme(self,nouveauNom):
60         print ('je passe dans renomme')
61         #import traceback
62         #traceback.print_stack()
63         self.jdc.delConcept(self.nom)
64         self.jdc.sdsDict[nouveauNom] = self
65         self.setName(nouveauNom)
66         for mc in (self.utilisePar):
67             mc.demandeRedessine()
68
69
70     def initialiseParent(self, pere):
71         # surcharge N_UserASSD  parent ici n a pas de sens
72         pass
73
74     def deleteReference(self,mcCreateur):
75         print ('je passe dans deleteReference', mcCreateur.nom)
76         if not(mcCreateur in self.peres) : return
77         self.peres.pop(self.peres.index(mcCreateur))
78         if len(self.peres)==0 :
79             UserASSD.deleteReference(self)
80
81
82     def getParentsWithId(self):
83         #print ('je suis dans getParentsWithId ')
84         listeRetour= listUserASSD()
85         for pere in self.peres :
86             pereWithId = pere.parent
87             monEtape = pere.getEtape()
88             while (pereWithId) :
89                 if pereWithId==monEtape :
90                     listeRetour.append(pereWithId)
91                     break
92                 if pereWithId.estIdentifiePar != None :
93                     listeRetour.append(pereWithId)
94                     break
95                 pereWithId=pereWithId.parent
96         return listeRetour
97
98     def getEtapes(self):
99         listeRetour= listUserASSD()
100         for pere in self.peres :
101             if pere.etape not in listeRetour : listeRetour.append(pere.etape)
102         return listeRetour
103
104
105 class listUserASSD(UserList):
106
107     def getListeMotsCles(self,nomMc):
108         if self.data == None : return []
109         listeRetour=[]
110         for concept in self.data:
111             listeRetour.append(concept.getChild(nomMc).val)
112         return listeRetour
113
114     def getListeNomsUserASSD(self,nomMc):
115         if self.data == None : return []
116         listeRetour=[]
117         for concept in self.data:
118             listeRetour.append(concept.getChild(nomMc).val.nom)
119         return listeRetour
120
121     def getListeUserASSD(self,nomMc):
122         if self.data == None : return []
123         listeRetour=[]
124         for concept in self.data:
125             if concept.getChild(nomMc) :
126                 if concept.getChild(nomMc).val :
127                     listeRetour.append(concept.getChild(nomMc).val)
128         return listeRetour