Salome HOME
nettoyage des GetPanel et affichage pler deplier selon l ancien etat
[tools/eficas.git] / InterfaceQT4 / browser.py
index 67cb348983678424b40b5a460d6d1712c2c7ec1b..ef6657f8b923f87234805d55b810fe11124b195a 100644 (file)
@@ -27,9 +27,10 @@ from PyQt4 import *
 from PyQt4.QtGui  import *
 from PyQt4.QtCore import *
 from Extensions.i18n import tr
+from gereRegles import GereRegles
 from monChoixCommande import MonChoixCommande
 
-class JDCTree( QTreeWidget ):
+class JDCTree( QTreeWidget,GereRegles ):
     def __init__( self, jdc_item, QWParent):        
         #if hasattr(QWParent,'widgetTree') : 
         self.editor       = QWParent
@@ -51,7 +52,6 @@ class JDCTree( QTreeWidget ):
         self.tree          = self        
         self.appliEficas   = self.editor.appliEficas
         self.childrenComplete=[]
-        self.childrenIssusDesBlocs=[]
         self.racine=self.item.itemNode(self,self.item)
  
         self.itemCourrant=None
@@ -67,8 +67,12 @@ class JDCTree( QTreeWidget ):
         self.inhibeExpand=False
         #print "self.editor.afficheCommandesPliees", self.editor.afficheCommandesPliees
         if self.racine.children !=[] :  
+
+            
            if self.editor.afficheCommandesPliees : self.racine.children[0].plieToutEtReaffiche()
            else : self.racine.children[0].deplieToutEtReaffiche()
+        
+
            self.racine.children[0].fenetre.donnePremier()
         else : self.racine.affichePanneau()
         #PNPNPN
@@ -104,7 +108,7 @@ class JDCTree( QTreeWidget ):
         if self.inhibeExpand == True : return
         # On traite le cas de l item non selectionne
         itemParent=item
-        while not (hasattr (itemParent,'getPanel2')) : 
+        while not (hasattr (itemParent,'getPanel')) : 
            itemParent=itemParent.treeParent 
         if self.tree.node_selected != itemParent : 
              item.setExpanded(False)
@@ -119,7 +123,7 @@ class JDCTree( QTreeWidget ):
         if self.inhibeExpand == True : return
         #print "apres if"
         itemParent=item
-        while not (hasattr (itemParent,'getPanel2')) : 
+        while not (hasattr (itemParent,'getPanel')) : 
            if itemParent.plie==True : itemParent.setDeplie()
            itemParent=itemParent.treeParent 
         #print "apres if"
@@ -129,21 +133,21 @@ class JDCTree( QTreeWidget ):
              return
         item.deplieToutEtReaffiche()
 
+
     def handleOnItem(self,item,int):
         #if (len(self.selectedIndexes())!=2): return
-        #print "je passe dans handleOnItem"
+        #print "je passe dans handleOnItem pour ", item.item.nom, item, item.item
         self.inhibeExpand == True 
         self.itemCourrant=item
         itemParent=item
         #print self.itemCourrant
-        while not (hasattr (itemParent,'getPanel2')) : 
+        while not (hasattr (itemParent,'getPanel')) : 
            if itemParent.plie==True : itemParent.setDeplie()
            itemParent=itemParent.treeParent 
-        #print itemParent
+        #print itemParent.item.nom
         #print itemParent.fenetre
         #print self.editor.afficheCommandesPliees
         if itemParent.fenetre != self.editor.fenetreCentraleAffichee : 
-            #print self.editor.afficheCommandesPliees
             if self.editor.afficheCommandesPliees : itemParent.plieToutEtReaffiche()
             else :                                  itemParent.affichePanneau()
         if itemParent!=item and item.fenetre != None: item.fenetre.rendVisible()
@@ -167,17 +171,17 @@ class JDCTree( QTreeWidget ):
 COMMENT     = "COMMENTAIRE"
 PARAMETERS  = "PARAMETRE"
  
-class JDCNode(QTreeWidgetItem):
-    def __init__( self, treeParent, item):
+class JDCNode(QTreeWidgetItem,GereRegles):
+    def __init__( self, treeParent, item, itemExpand=False, ancien=False ):
         #print "creation d'un noeud : ", item, " ",item.nom,"", treeParent, self
-        self.a=0
+        #self.a=0
         self.item        = item
         self.vraiParent  = treeParent
         self.treeParent  = treeParent
         self.tree        = self.treeParent.tree
         self.editor     = self.treeParent.editor
         self.appliEficas = treeParent.appliEficas
-        self.treeParent.childrenIssusDesBlocs=[]
+        self.JESUISOFF=0
         self.childrenComplete=[]
                         
         from InterfaceQT4 import compocomm
@@ -186,6 +190,7 @@ class JDCNode(QTreeWidgetItem):
         elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=self.appliEficas.trUtf8(str(item.GetLabelText()[0]))
         else:   name  = self.appliEficas.trUtf8(str(tr( item.nom))+" :")
         value = self.appliEficas.trUtf8(str( item.GetText() ) )
 
         mesColonnes=QStringList()
         if self.editor.enteteQTree=='complet': mesColonnes <<  name << value
@@ -197,28 +202,23 @@ class JDCNode(QTreeWidgetItem):
         else :
             self.plie        = False
             self.appartientAUnNoeudPlie = False
-        #print "self.plie", self.plie
-        #print "self.appartientAUnNoeudPlie", self.appartientAUnNoeudPlie
-        #print self.treeParent
+        if ancien and itemExpand     : self.plie = False
+        if ancien and not itemExpand : self.plie = True 
+
 
-        ajoutAuParentduNoeud=0
         from InterfaceQT4 import compobloc
         from InterfaceQT4 import compomclist
+
+        ajoutAuParentduNoeud=0
+        self.treeParent=treeParent
         while (isinstance(self.treeParent,compobloc.Node) or ( isinstance(self.treeParent,compomclist.Node) and self.treeParent.item.isMCList())) : 
-        #while (isinstance(self.treeParent,compobloc.Node)) :
-              self.treeParent=self.treeParent.treeParent
-              ajoutAuParentduNoeud=1
-        if ajoutAuParentduNoeud :
-           treeParent.childrenComplete.append(self)
-           self.treeParent.childrenIssusDesBlocs.append(self)
-        while (isinstance(self.treeParent,compobloc.Node)) : self.treeParent=self.treeParent.treeParent
-
-        #if isinstance(self,compobloc.Node) : 
+              self.treeParent.childrenComplete.append(self)
+              self.treeParent=self.treeParent.vraiParent
+        self.treeParent.childrenComplete.append(self)
         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
            QTreeWidgetItem.__init__(self,None,mesColonnes)
         else :
            QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
-           self.treeParent.childrenComplete.append(self)
 
         self.setToolTip(0,QString(self.item.get_fr()))
         self.setToolTip(1,QString(self.item.get_fr()))
@@ -235,6 +235,7 @@ class JDCNode(QTreeWidgetItem):
         self.item.connect("valid",self.onValid,())
         self.item.connect("supp" ,self.onSupp,())
         self.item.connect("add"  ,self.onAdd,())
+
         self.state=""
         self.fenetre=None
         try :
@@ -248,40 +249,36 @@ class JDCNode(QTreeWidgetItem):
     def build_children(self,posInsertion=10000):
         """ Construit la liste des enfants de self """
         """ Se charge de remettre les noeuds Expanded dans le meme etat """
-        #print "*********** build_children ",self.item, self.item.GetLabelText()
+        #print "*********** build_children ",self,self.item, self.item.nom
+        
+        self.listeItemExpanded=[]
+        self.listeItemPlie=[]
+        for enfant in self.childrenComplete :
+            if enfant.isExpanded()      : self.listeItemExpanded.append(enfant.item)
+            if not(enfant.isExpanded()) : self.listeItemPlie.append(enfant.item)
+
+        for enfant in self.childrenComplete :
+            p=enfant.vraiParent
+            parent=enfant.treeParent
+            parent.removeChild(enfant)
+            enfant.JESUISOFF=1
+         
         
-        listeExpanded=[]
-        for item in self.childrenComplete :
-            #print dir(item)
-            #if item.isExpanded():
-            #   if self.childrenComplete.index(item) < posInsertion :
-            #      listeExpanded.append(self.childrenComplete.index(item))
-            #      print dir(item.item )
-            #   else :
-            #      listeExpanded.append( self.childrenComplete.index(item) +1)
-            self.detruit_les_noeuds_issus_de_blocs(item)
-            parent=item.treeParent
-            parent.removeChild(item)
-
-        #print listeExpanded
         self.children = []
         self.childrenComplete = []
         sublist = self.item._GetSubList()
         ind=0
+        
         for item in sublist :
-            nouvelItem=item.itemNode(self,item)
+            itemExpand=False
+            ancien=False
+            if item in self.listeItemExpanded : itemExpand=True;  ancien=True
+            if item in self.listeItemPlie     : itemExpand=False; ancien=True
+            nouvelItem=item.itemNode(self,item,itemExpand,ancien)
             self.children.append(nouvelItem)
-            #print "         J ajoute ", nouvelItem ,nouvelItem.item.GetLabelText(),"dans" ,self.item.GetLabelText()
-            #print item
-            #if ind in listeExpanded : nouvelItem.setExpanded(1)
-            #if ind in listeExpanded : print "plie=0"
-            #else                  : print "plie=1"
-            #if ind in listeExpanded : nouvelItem.plie=0
-            #else                  : nouvelItem.plie=1
-            #ind=ind+1
 
-        #print "*********** fin build_children ",self.item, self.item.GetLabelText()
+        #print "fin *********** build_children ",self,self.item, self.item.nom
+
         
     def chercheNoeudCorrespondant(self,objSimp):
         sublist = self.item._GetSubList()
@@ -289,32 +286,28 @@ class JDCNode(QTreeWidgetItem):
             if node.item.object==objSimp : return node
         return None
 
+
     def affichePanneau(self) :
-        #print "dans affichePanneau appel getPanel2", self.item.GetLabelText()
+        #print " affichePanneau " , self.item.nom 
         if self.item.isactif(): 
            itemParent=self
-           while not (hasattr (itemParent,'getPanel2')) : 
-                itemParent=itemParent.treeParent 
+           while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent 
            if itemParent!=self : 
               itemParent.affichePanneau()
               return
-           self.fenetre=self.getPanel2()
+           self.fenetre=self.getPanel()
         else:
             from monInactifPanel import PanelInactif
             self.fenetre = PanelInactif(self,self.editor)
          
         self.editor.widgetCentraleLayout.addWidget(self.fenetre)
-        #print "widgetCentraleLayout = ", self.editor.widgetCentraleLayout
-        #print "nouvelle fenetre ", self.fenetre, " associee a ", self
 
         self.editor.anciennefenetre=self.editor.fenetreCentraleAffichee
-        #print "ancienne fenetre ", self.editor.anciennefenetre
         self.editor.fenetreCentraleAffichee=self.fenetre
         self.tree.node_selected= self
 
         if self.editor.anciennefenetre != None : 
            a=self.editor.anciennefenetre.close()
-           #print "je ferme ", self.editor.anciennefenetre
 
         if self.editor.widgetTree !=None  : index=1
         else : index=0
@@ -382,11 +375,10 @@ class JDCNode(QTreeWidgetItem):
         Ajoute un parametre a l'interieur du JDC :
         """
         self.editor.init_modif()
-        if after:
-            pos = 'after'
-        else:
-            pos = 'before'
-        return self.append_brother( PARAMETERS, pos )
+        if after: pos = 'after'
+        else: pos = 'before'
+        child=self.append_brother( PARAMETERS, pos )
+        return  child
     
     
     def select( self ):
@@ -394,7 +386,6 @@ class JDCNode(QTreeWidgetItem):
         Rend le noeud courant (self) selectionne et deselectionne
         tous les autres
         """        
-        #print "je suis sur select"
         for item in self.tree.selectedItems() :
             item.setSelected(0)
         self.setSelected( True )    
@@ -413,6 +404,10 @@ class JDCNode(QTreeWidgetItem):
         Methode externe
         """
         self.editor.init_modif()
+
+        from InterfaceQT4 import compojdc
+        if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos)  : return 0
+        
         index = self.treeParent.children.index(self)
         if   pos == 'before': index = index
         elif pos == 'after': index = index +1
@@ -421,6 +416,35 @@ class JDCNode(QTreeWidgetItem):
             return 0
         return self.treeParent.append_child(name,pos=index,plier=plier)
 
+    def verifiePosition(self,name,pos,aLaRacine=False):
+        if name not in self.editor.Classement_Commandes_Ds_Arbre : return True
+        indexName=self.editor.Classement_Commandes_Ds_Arbre.index(name)
+
+        etapes=self.item.get_jdc().etapes
+        if etapes == [] : return True
+
+        if aLaRacine == False :indexOu=etapes.index(self.item.object)
+        else : indexOu=0
+
+        if pos=="after" : indexOu = indexOu+1
+        for e in etapes[:indexOu] :
+            nom=e.nom
+            if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
+            indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
+            if indexEtape > indexName :
+               comment=tr('le mot clef ')+name+tr(' doit etre insere avant ')+nom
+               QMessageBox.information( None,tr('insertion impossible'),comment, )
+               return False
+        for e in etapes[indexOu:] :
+            nom=e.nom
+            if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
+            indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
+            if indexEtape < indexName :
+               comment=tr('le mot clef ')+name+tr(' doit etre insere apres ')+nom
+               QMessageBox.information( None,tr('insertion impossible'),comment, )
+               return False
+        return True
+
     def append_child(self,name,pos=None,plier=False):
         """
            Methode pour ajouter un objet fils a l'objet associe au noeud self.
@@ -429,6 +453,8 @@ class JDCNode(QTreeWidgetItem):
            Si pos vaut None, on le place a la position du catalogue.
         """
         #print "************** append_child ",self.item.GetLabelText(), plier
+
+         
         self.editor.init_modif()
         if pos == 'first':
             index = 0
@@ -444,36 +470,24 @@ class JDCNode(QTreeWidgetItem):
             index = self.item.get_index_child(name.nom)
         else:
             index = self.item.get_index_child(name)
+
+        # si on essaye d inserer a la racine
+        if (isinstance(self.treeParent,JDCTree) and index==0) :
+           verifiePosition=self.verifiePosition(name,'first',aLaRacine=True)
+           if not verifiePosition : return 0
+
         self.tree.inhibeExpand=True
         obj=self.item.additem(name,index) #CS_pbruno emet le signal 'add'
         if obj is None:obj=0
         if obj == 0:return 0
-        #try :
-        #  old_obj = self.item.object.get_child(name.nom,restreint = 'oui')
-        #  child=old_obj[-1]
-        #  if plier : child.plieToutEtReaffiche()
-        #  else     : child.affichePanneau() 
-        #  print "dans le 1er Try"
-        #else :
-        #except:
-          # Souci pour gerer les copies des AFFE d'une commande à l autre
-        #  try :
-        #     child=self.children[index]
-        #     if plier == True : child.setPlie()
-        #     else             : child.setDeplie() 
-        #     print "dans le 2nd Try"
-        #  except :
-        #     child=self.children[index]
-        #     print "dans le except"
         try :
-        #if 1:
            child=self.children[index]
            if plier == True : child.setPlie()
            else             : child.setDeplie() 
         except :
            child=self.children[index]
-           #print "dans le except"
         self.tree.inhibeExpand=False
+        #print " fin append child"
         return child
 
     def deplace(self):
@@ -493,7 +507,11 @@ class JDCNode(QTreeWidgetItem):
         if self.item.nom == "VARIABLE" :
            recalcule=1
            jdc=self.item.jdc
-        ret=self.vraiParent.item.suppitem(self.item)
+        ret,commentaire=self.vraiParent.item.suppitem(self.item)
+        if ret==0 :
+          self.editor.affiche_infos(commentaire,Qt.red)
+        else :
+          self.editor.affiche_infos(commentaire)
         self.treeParent.build_children()
         if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
         else: toselect=self.treeParent
@@ -546,9 +564,8 @@ class JDCNode(QTreeWidgetItem):
     def onValid(self):        
 
         #print "onValid pour ", self.item.nom
-        if hasattr(self,'fenetre') and self.fenetre: 
-           self.fenetre.setValide()
-        if self.item.nom == "VARIABLE" and self.item.isvalid():
+        if hasattr(self,'fenetre') and self.fenetre: self.fenetre.setValide()
+        if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isvalid():
            self.item.jdc.recalcule_etat_correlation()
         if hasattr(self.item,'forceRecalcul'):
            self.forceRecalculChildren(self.item.forceRecalcul)
@@ -559,28 +576,22 @@ class JDCNode(QTreeWidgetItem):
         self.update_node_texte()
 
     def onAdd(self,object):
-        #print "onAdd pour ", self.item.nom
+        if self.JESUISOFF==1 : return
         self.editor.init_modif()
         self.update_nodes()
-        #print "dans onAdd" ,self.item 
+
         # PN -- non necessaire si item=jdc
         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
  
     def onSupp(self,object):
-        #print "onSupp pour ", self.item.nom
+        if self.JESUISOFF==1 : return
         self.editor.init_modif()
         self.update_nodes()
         # PN -- non necessaire si item=jdc
         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
          
-    def detruit_les_noeuds_issus_de_blocs(self,bloc):
-        from InterfaceQT4 import compobloc
-        if (isinstance(bloc,compobloc.Node)) :
-           for node in bloc.childrenComplete :
-               self.detruit_les_noeuds_issus_de_blocs(node)
-               parent=node.treeParent
-               #print "je detruit " , node.item.GetLabelText()
-               parent.removeChild(node)
+
+
 
     def update_node_valid(self):
         """Cette methode remet a jour la validite du noeud (icone)
@@ -630,6 +641,7 @@ class JDCNode(QTreeWidgetItem):
         """ Met a jour les noms des SD et valeurs des mots-cles """
         value = self.item.GetText()
         self.setText(1, value)
+        
 
     def update_node_texte_in_blue(self):
         self.setTextColor( 1,Qt.blue )
@@ -707,6 +719,9 @@ class JDCNode(QTreeWidgetItem):
         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
         self.editor.deplier = False
         for item in self.children :
+            # il ne faut pas plier les blocs 
+            from InterfaceQT4 import compobloc
+            if (isinstance(item,compobloc.Node)) : continue
             item.setPlie()
         self.affichePanneau()
 
@@ -735,12 +750,14 @@ class JDCNode(QTreeWidgetItem):
         #       item.appartientAUnNoeudPlie=False
 
     def setPlieChildren(self):
+        #print "dans setPlieChildren pour", self.item.nom
         self.plie=True
         for c in self.children :
             c.setPlieChildren()
             #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0]
             c.appartientAUnNoeudPlie=True
             c.plie=True
+            #print "dans setPlieChildren plie", c.item.nom
             c.setExpanded(False)
 
         # Pour les blocs et les motcles list
@@ -765,6 +782,7 @@ class JDCNode(QTreeWidgetItem):
         #        c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
 
     def setDeplie(self):
+        #print "dans setPlieChildren pour", self.item.nom
         #print "je mets inhibeExpand a true dans setDeplie"
         self.tree.inhibeExpand=True
         self.plie=False
@@ -777,7 +795,7 @@ class JDCNode(QTreeWidgetItem):
         #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.GetLabelText()
         for c in self.children :
             c.setDeplieChildren()
-            #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", c.item.GetLabelText()
+            #print "dans setDeplieChildren ", c.item.nom
             c.appartientAUnNoeudPlie=False
             c.setExpanded(True)
             c.plie=False