# -*- coding: iso-8859-1 -*- # Copyright 20003 - 2008: Julien Bourdaillet (julien.bourdaillet@lip6.fr), Jean-Gabriel Ganascia (jean-gabriel.ganascia@lip6.fr) # This file is part of MEDITE. # # MEDITE is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # MEDITE is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Foobar; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #---------------------------------------------------------------------------- # Nom: arbre.py # Objet: Classe qui regroupe les donnees d'un arbre # # Auteur: Julien Bourdaillet # # Cree: janvier 2005 # #---------------------------------------------------------------------------- # Arbre des versions class Arbre: # Constucteur de la classe def __init__(self, pListe=[]): self.__listeVersions = pListe #self.__nomDG = nomDG # Methodes d'acces aux attributs prives def getListeVersions(self): return self.__listeVersions # renvoie une liste plate (ce n'est plus un arbre) de tous les Etats de l'arbre # Chaque état est représenté par un couple (Etat,Version) où Version est la version # mére de l'Etat def getListePlateEtats(self): lEtats = [] for version in self.getListeVersions(): lEtats.extend(self.__getNode(version,version)) return lEtats def __getNode(self,node, versionMere): lEtats = [] if isinstance(node,Etat): lEtats.append((node,versionMere)) for fils in node.getListeFils(): lEtats.extend(self.__getNode(fils,versionMere)) else: # Version for fils in node.getListeFils(): lEtats.extend(self.__getNode(fils,node)) return lEtats def addVersion(self, version): self.__listeVersions.append(version) def toString(self): s = "Arbre [" for v in self.__listeVersions: s = s + v.toString() s += "]" return s # Version class Version: def __init__(self, pNom, pListe=[]): self.__nom = pNom self.__listeVersionOREtats = pListe def getListeFils(self): return self.__listeVersionOREtats def getNom(self): return self.__nom def addFils(self, versionORetat): self.__listeVersionOREtats.append(versionORetat) def toString(self): s = "V "+self.getNom()+ " [" for x in self.__listeVersionOREtats: s = s + x.toString() + " / " s += "]" return s # Etat d'un version class Etat: def __init__(self, pNom, pListe=[]): self.__nom = pNom self.__listeEtatsFils = pListe def getListeFils(self): return self.__listeEtatsFils def getNom(self): return self.__nom def addFils(self,etatFils): self.__listeEtatsFils.append(etatFils) def toString(self): s = "E "+self.getNom()+ " [" for x in self.__listeEtatsFils: s = s + x.toString() + " / " s += "]" return s