X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=Ihm%2FI_MCSIMP.py;h=53067a77173f406a321d8bd92691654f7278be9f;hb=5ecef0dc64055f54a1f864b979e58cc05f1c9f4a;hp=1c6c87bfa1c91b3f04b95a697eebc957485af369;hpb=b2ab08fd7617bc1919416221b7032890e7fcc78a;p=tools%2Feficas.git diff --git a/Ihm/I_MCSIMP.py b/Ihm/I_MCSIMP.py index 1c6c87bf..53067a77 100644 --- a/Ihm/I_MCSIMP.py +++ b/Ihm/I_MCSIMP.py @@ -17,19 +17,21 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -import types,string +from __future__ import absolute_import +import types import traceback from copy import copy -from repr import Repr +from six.moves.reprlib import Repr from Extensions.i18n import tr from Extensions.eficas_exception import EficasException +from six.moves import range myrepr = Repr() myrepr.maxstring = 100 myrepr.maxother = 100 from Noyau.N_utils import repr_float import Validation -import CONNECTOR +from . import CONNECTOR # Attention : les classes ASSD,.... peuvent etre surchargees # dans le package Accas. Il faut donc prendre des precautions si @@ -48,9 +50,9 @@ import Accas from Extensions import parametre from Extensions import param2 -import I_OBJECT -import CONNECTOR -from I_VALIDATOR import ValError,listProto +from . import I_OBJECT +from . import CONNECTOR +from .I_VALIDATOR import ValError,listProto class MCSIMP(I_OBJECT.OBJECT): @@ -62,6 +64,8 @@ class MCSIMP(I_OBJECT.OBJECT): if hasattr(type_permis, "__class__") and type_permis.__class__.__name__ == 'Matrice': self.monType=type_permis return self.valideMatrice(cr=cr) + if self.definition.siValide != None : + self.definition.siValide(self) return Validation.V_MCSIMP.MCSIMP.isvalid(self,cr=cr) def GetNomConcept(self): @@ -87,34 +91,47 @@ class MCSIMP(I_OBJECT.OBJECT): if self.valeur == None : return None - elif type(self.valeur) == types.FloatType : + elif type(self.valeur) == float : # Traitement d'un flottant isole txt = str(self.valeur) clefobj=self.GetNomConcept() - if self.jdc.appli.appliEficas.dict_reels.has_key(clefobj): - if self.jdc.appli.appliEficas.dict_reels[clefobj].has_key(self.valeur): + if clefobj in self.jdc.appli.appliEficas.dict_reels : + if self.valeur in self.jdc.appli.appliEficas.dict_reels[clefobj]: txt=self.jdc.appli.appliEficas.dict_reels[clefobj][self.valeur] - elif type(self.valeur) in (types.ListType,types.TupleType) : + elif type(self.valeur) in (list,tuple) : + if self.valeur==[] or self.valeur == (): return str(self.valeur) # Traitement des listes txt='(' sep='' for val in self.valeur: - if type(val) == types.FloatType : + if type(val) == float : clefobj=self.GetNomConcept() - if self.jdc.appli.appliEficas.dict_reels.has_key(clefobj): - if self.jdc.appli.appliEficas.dict_reels[clefobj].has_key(val): + if clefobj in self.jdc.appli.appliEficas.dict_reels: + if val in self.jdc.appli.appliEficas.dict_reels[clefobj]: txt=txt + sep +self.jdc.appli.appliEficas.dict_reels[clefobj][val] else : txt=txt + sep + str(val) else : txt=txt + sep + str(val) else: - txt = txt + sep+ str(val) - if len(txt) > 200: - #ligne trop longue, on tronque - txt=txt+" ..." - break + if isinstance(val,tuple): + texteVal='(' + for i in val : + if isinstance(i, bytes) : texteVal = texteVal +"'"+str(i)+"'," + else : texteVal = texteVal + str(i)+',' + texteVal=texteVal[:-1]+')' + else : + if isinstance(val,bytes): texteVal="'"+str(val)+"'" + else :texteVal=str(val) + txt = txt + sep+ texteVal + +## if len(txt) > 200: +## #ligne trop longue, on tronque +## txt=txt+" ..." +## break sep=',' + # cas des listes de tuples de longueur 1 + if isinstance(val,tuple) and len(self.valeur) == 1 : txt=txt+',' txt=txt+')' else: # Traitement des autres cas @@ -132,30 +149,31 @@ class MCSIMP(I_OBJECT.OBJECT): Retourne une chaine de caractere representant la valeur de self """ val=self.valeur - if type(val) == types.FloatType : + if type(val) == float : clefobj=self.GetNomConcept() - if self.jdc.appli.appliEficas.dict_reels.has_key(clefobj): - if self.jdc.appli.appliEficas.appliEficas.dict_reels[clefobj].has_key(val): + if clefobj in self.jdc.appli.appliEficas.dict_reels : + if val in self.jdc.appli.appliEficas.appliEficas.dict_reels[clefobj] : return self.jdc.appli.appliEficas.dict_reels[clefobj][val] - if type(val) != types.TupleType : + if type(val) != tuple : try: return val.get_name() except: return val else : + if val ==() or val == [] : return val s='( ' for item in val : try : s=s+item.get_name()+',' except: - s=s+`item`+',' + s=s+repr(item)+',' s=s+' )' return s def wait_bool(self): for typ in self.definition.type: try : - if typ == types.BooleanType: return True + if typ == bool: return True except : pass return False @@ -166,7 +184,7 @@ class MCSIMP(I_OBJECT.OBJECT): qui n'existe pas encore (type CO()), 0 sinon """ for typ in self.definition.type: - if type(typ) == types.ClassType or isinstance(typ,type): + if type(typ) == type or isinstance(typ,type): if issubclass(typ,CO) : return 1 return 0 @@ -177,7 +195,7 @@ class MCSIMP(I_OBJECT.OBJECT): ou derive, 0 sinon """ for typ in self.definition.type: - if type(typ) == types.ClassType or isinstance(typ,type): + if type(typ) == type or isinstance(typ,type): if issubclass(typ,ASSD) and not issubclass(typ,GEOM): return 1 return 0 @@ -189,7 +207,7 @@ class MCSIMP(I_OBJECT.OBJECT): Retourne 0 dans le cas contraire """ for typ in self.definition.type: - if type(typ) == types.ClassType or isinstance(typ,type): + if type(typ) == type or isinstance(typ,type): if typ.__name__ in ("GEOM","ASSD","geom","assd") or issubclass(typ,GEOM) : return 1 return 0 @@ -200,7 +218,7 @@ class MCSIMP(I_OBJECT.OBJECT): Retourne 0 dans le cas contraire """ for typ in self.definition.type: - if type(typ) == types.ClassType or isinstance(typ,type): + if type(typ) == type or isinstance(typ,type): if issubclass(typ,GEOM) : return 1 return 0 @@ -219,9 +237,9 @@ class MCSIMP(I_OBJECT.OBJECT): """ if self.valeur == None: return [] - elif type(self.valeur) == types.TupleType: + elif type(self.valeur) == tuple: return list(self.valeur) - elif type(self.valeur) == types.ListType: + elif type(self.valeur) == list: return self.valeur else: return [self.valeur] @@ -347,7 +365,7 @@ class MCSIMP(I_OBJECT.OBJECT): if new_valeur in ('True','False') and 'TXM' in self.definition.type : valeur=self.eval_val_item(str(new_valeur)) return new_valeur - if type(new_valeur) in (types.ListType,types.TupleType): + if type(new_valeur) in (list,tuple): valeurretour=[] for item in new_valeur : valeurretour.append(self.eval_val_item(item)) @@ -388,7 +406,7 @@ class MCSIMP(I_OBJECT.OBJECT): return None def update_concept(self,sd): - if type(self.valeur) in (types.ListType,types.TupleType) : + if type(self.valeur) in (list,tuple) : if sd in self.valeur: self.init_modif() self.fin_modif() @@ -406,13 +424,13 @@ class MCSIMP(I_OBJECT.OBJECT): du concept sd Attention aux matrices """ - if type(self.valeur) == types.TupleType : + if type(self.valeur) == tuple : if sd in self.valeur: self.init_modif() self.valeur=list(self.valeur) self.valeur.remove(sd) self.fin_modif() - elif type(self.valeur) == types.ListType: + elif type(self.valeur) == list: if sd in self.valeur: self.init_modif() self.valeur.remove(sd) @@ -426,7 +444,8 @@ class MCSIMP(I_OBJECT.OBJECT): # Glut Horrible pour les matrices ??? if sd.__class__.__name__== "variable": for type_permis in self.definition.type: - if type(type_permis) == types.InstanceType: + #if type(type_permis) == types.InstanceType: + # a voir en python 3 if type_permis.__class__.__name__ == 'Matrice' : self.state="changed" self.isvalid() @@ -442,14 +461,14 @@ class MCSIMP(I_OBJECT.OBJECT): du concept old_sd """ #print "replace_concept",old_sd,sd - if type(self.valeur) == types.TupleType : + if type(self.valeur) == tuple : if old_sd in self.valeur: self.init_modif() self.valeur=list(self.valeur) i=self.valeur.index(old_sd) self.valeur[i]=sd self.fin_modif() - elif type(self.valeur) == types.ListType: + elif type(self.valeur) == list: if old_sd in self.valeur: self.init_modif() i=self.valeur.index(old_sd) @@ -510,8 +529,8 @@ class MCSIMP(I_OBJECT.OBJECT): # Attention : possible probleme avec include # A priori il n'y a pas de raison de retirer les concepts non existants # avant etape. En fait il s'agit uniquement eventuellement de ceux crees par une macro - l_sd_avant_etape = self.jdc.get_contexte_avant(self.etape).values() - if type(self.valeur) in (types.TupleType,types.ListType) : + l_sd_avant_etape = list(self.jdc.get_contexte_avant(self.etape).values()) + if type(self.valeur) in (tuple,list) : l=[] for sd in self.valeur: if isinstance(sd,ASSD) : @@ -609,8 +628,12 @@ class MCSIMP(I_OBJECT.OBJECT): def valideMatrice(self,cr): #Attention, la matrice contient comme dernier tuple l ordre des variables + if self.valideEnteteMatrice()==False : + self.set_valid(0) + if cr == "oui" : self.cr.fatal(tr("La matrice n'a pas le bon entete")) + return 0 if self.monType.methodeCalculTaille != None : - apply (MCSIMP.__dict__[self.monType.methodeCalculTaille],(self,)) + MCSIMP.__dict__[self.monType.methodeCalculTaille](*(self,)) try : #if 1 : ok=0 @@ -631,11 +654,23 @@ class MCSIMP(I_OBJECT.OBJECT): self.set_valid(0) return 0 + def NbDeVariables(self): listeVariables=self.jdc.get_variables(self.etape) self.monType.nbLigs=len(listeVariables) self.monType.nbCols=len(listeVariables) + def valideEnteteMatrice(self): + if self.jdc.get_distributions(self.etape) == () or self.valeur == None : return 0 + if self.jdc.get_distributions(self.etape) != self.valeur[0] : return 0 + return 1 + + def changeEnteteMatrice(self): + a=[self.jdc.get_distributions(self.etape),] + for t in self.valeur[1:]: + a.append(t) + self.valeur=a + def NbDeDistributions(self): listeVariables=self.jdc.get_distributions(self.etape)