Salome HOME
onItem=Deplie
[tools/eficas.git] / InterfaceQT4 / browser.py
index 302719f23a2a4230692e5d67a3d4a61d13c5cb0c..7761a6c373863c9713df5f8c11b2bcfa0a6a264c 100644 (file)
@@ -108,7 +108,7 @@ class JDCTree( QTreeWidget,GereRegles ):
         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)
@@ -117,47 +117,47 @@ class JDCTree( QTreeWidget,GereRegles ):
         itemParent=item
         item.setPlie()
         item.plieToutEtReaffiche()
+        item.select()
 
     def handleExpandedItem(self,item):
-        #print "dans ExpandItem", self.inhibeExpand  
+        #print "handleExpandedItem pour ", item.item.nom, self.inhibeExpand
         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"
         if self.tree.node_selected != itemParent : 
              item.setExpanded(True)
-             #print "je suis la"
              return
         item.deplieToutEtReaffiche()
 
 
     def handleOnItem(self,item,int):
-        #if (len(self.selectedIndexes())!=2): return
-        #print "je passe dans handleOnItem pour ", item.item.nom, item, item.item
+        #print "je passe dans handleOnItem pour ",self, 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.item.nom
-        #print itemParent.fenetre
-        #print self.editor.afficheCommandesPliees
         if itemParent.fenetre != self.editor.fenetreCentraleAffichee : 
-            if self.editor.afficheCommandesPliees : itemParent.plieToutEtReaffiche()
+             # il faut afficher le parent
+            if self.editor.afficheCommandesPliees : itemParent.plieToutEtReafficheSaufItem(item)
             else :                                  itemParent.affichePanneau()
-        if itemParent!=item and item.fenetre != None: item.fenetre.rendVisible()
-        #try :
-        if 1:
+
+
+        from InterfaceQT4 import composimp
+        if (isinstance(item,composimp.Node)) : item.fenetre.rendVisible()
+        elif itemParent!=item:
+             #self.tree.handleExpandedItem(item)
+             #item.fenetre.donnePremier()
+             print 'il faut afficher le 1er'
+        try :
            fr = item.item.get_fr()
            if self.editor: self.editor.labelCommentaire.setText(unicode(fr))
-        #except:
-        else :
+        except:
             pass
+        item.select()
         self.inhibeExpand == False 
         #print "je mets inhibeExpand a false handleOnItem"
 
@@ -172,9 +172,9 @@ COMMENT     = "COMMENTAIRE"
 PARAMETERS  = "PARAMETRE"
  
 class JDCNode(QTreeWidgetItem,GereRegles):
-    def __init__( self, treeParent, item):
+    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
@@ -186,6 +186,7 @@ class JDCNode(QTreeWidgetItem,GereRegles):
                         
         from InterfaceQT4 import compocomm
         from InterfaceQT4 import compoparam
+        from InterfaceQT4 import composimp
         if   (isinstance(self.item,compocomm.COMMTreeItem)) : name=tr("Commentaire")
         elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=self.appliEficas.trUtf8(str(item.GetLabelText()[0]))
         else:   name  = self.appliEficas.trUtf8(str(tr( item.nom))+" :")
@@ -203,6 +204,10 @@ class JDCNode(QTreeWidgetItem,GereRegles):
             self.plie        = False
             self.appartientAUnNoeudPlie = False
 
+        if ancien and itemExpand     : self.plie = False
+        if ancien and not itemExpand : self.plie = True 
+        if (isinstance(self.item,composimp.SIMPTreeItem)) : self.plie=False
+
         from InterfaceQT4 import compobloc
         from InterfaceQT4 import compomclist
 
@@ -232,6 +237,7 @@ class JDCNode(QTreeWidgetItem,GereRegles):
         self.item.connect("valid",self.onValid,())
         self.item.connect("supp" ,self.onSupp,())
         self.item.connect("add"  ,self.onAdd,())
+
         self.state=""
         self.fenetre=None
         try :
@@ -247,31 +253,35 @@ class JDCNode(QTreeWidgetItem,GereRegles):
         """ Se charge de remettre les noeuds Expanded dans le meme etat """
         #print "*********** build_children ",self,self.item, self.item.nom
         
-        listeExpanded=[]
-        for enfant in self.childrenComplete :
-            #if enfant.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.listeItemExpanded=[]
+        self.listeItemPlie=[]
 
+        for enfant in self.childrenComplete :
+            if enfant.plie : self.listeItemPlie.append(enfant.item)
+            else : self.listeItemExpanded.append(enfant.item)
 
+        for enfant in self.childrenComplete :
             p=enfant.vraiParent
             parent=enfant.treeParent
             parent.removeChild(enfant)
-
             enfant.JESUISOFF=1
+         
         
-        #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 "fin *********** build_children ",self,self.item, self.item.nom
+
         
     def chercheNoeudCorrespondant(self,objSimp):
         sublist = self.item._GetSubList()
@@ -281,30 +291,33 @@ class JDCNode(QTreeWidgetItem,GereRegles):
 
 
     def affichePanneau(self) :
+        #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)
+        for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
+            widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
+            self.editor.widgetCentraleLayout.removeItem(widget)
+        # ceinture et bretelle
+        #print 'old fenetre = ',self.editor.fenetreCentraleAffichee
+        if self.editor.fenetreCentraleAffichee != None : 
+            #print "j enleve ", self.editor.fenetreCentraleAffichee, self.editor.fenetreCentraleAffichee.node.item.nom
+            self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
+            self.editor.fenetreCentraleAffichee.close()
 
-        self.editor.anciennefenetre=self.editor.fenetreCentraleAffichee
+        self.editor.widgetCentraleLayout.addWidget(self.fenetre)
+        #print "j ajoute ", self.fenetre, self.fenetre.node.item.nom
         self.editor.fenetreCentraleAffichee=self.fenetre
         self.tree.node_selected= self
 
-        if self.editor.anciennefenetre != None : 
-           a=self.editor.anciennefenetre.close()
-
-        if self.editor.widgetTree !=None  : index=1
-        else : index=0
-
         if self.editor.first :
            self.editor.splitter.setSizes((400,1400,400))
            if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
@@ -312,7 +325,7 @@ class JDCNode(QTreeWidgetItem,GereRegles):
         self.tree.expandItem(self)
         self.select()
         self.tree.inhibeExpand=False
-        #print "fin de affichePanneau"
+        #print "fin de affichePanneau", self.item.nom
         #print "______________________________"
           
 
@@ -382,9 +395,7 @@ class JDCNode(QTreeWidgetItem,GereRegles):
         for item in self.tree.selectedItems() :
             item.setSelected(0)
         self.setSelected( True )    
-        #self.setExpanded( True )    
         self.tree.setCurrentItem( self )    
-        self.tree.node_selected= self
                                
     #------------------------------------------------------------------
     # Methodes de creation et destruction de noeuds
@@ -473,32 +484,14 @@ class JDCNode(QTreeWidgetItem,GereRegles):
         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):
@@ -518,7 +511,11 @@ class JDCNode(QTreeWidgetItem,GereRegles):
         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
@@ -584,14 +581,15 @@ class JDCNode(QTreeWidgetItem,GereRegles):
 
     def onAdd(self,object):
         if self.JESUISOFF==1 : return
+        #print "onAdd pour ", self.item.nom, object.nom
         self.editor.init_modif()
         self.update_nodes()
-
         # PN -- non necessaire si item=jdc
         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
  
     def onSupp(self,object):
         if self.JESUISOFF==1 : return
+        #print "onSup pour ", self.item.nom, object.nom
         self.editor.init_modif()
         self.update_nodes()
         # PN -- non necessaire si item=jdc
@@ -721,6 +719,19 @@ class JDCNode(QTreeWidgetItem,GereRegles):
         child = self.append_child(objet,pos='first')
         return child
 
+    def plieToutEtReafficheSaufItem(self, itemADeplier):
+        #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()
+            if item==itemADeplier : 
+                  print itemADeplier.item.nom
+                  itemADeplier.setDeplie()
+        
+        self.affichePanneau()
 
     def plieToutEtReaffiche(self):
         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
@@ -757,12 +768,14 @@ class JDCNode(QTreeWidgetItem,GereRegles):
         #       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
@@ -787,6 +800,7 @@ class JDCNode(QTreeWidgetItem,GereRegles):
         #        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
@@ -799,7 +813,7 @@ class JDCNode(QTreeWidgetItem,GereRegles):
         #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