Salome HOME
*** empty log message ***
[tools/eficas.git] / Editeur / bureau.py
index 0fc27dd557b944fffb2b4c1b07a3a97f239ecedf..7c82a0eb1824d0f1e79ce93e08eabee8196ccf2a 100644 (file)
@@ -38,6 +38,9 @@ from jdcdisplay import JDCDISPLAY
 from utils import extension_fichier,stripPath,save_in_file
 from widgets import Fenetre,Ask_Format_Fichier
 from fenetre_mc_inconnus import fenetre_mc_inconnus
+from Ihm import CONNECTOR
+
+import comploader
 
 class BUREAU:
    menu_defs=[
@@ -75,6 +78,7 @@ class BUREAU:
    button_defs  =      (('New24',"newJDC","Création d'un nouveau fichier",'always'),
                         ('Open24',"openJDC","Ouverture d'un fichier existant",'always'),
                         ('Save24',"saveJDC","Sauvegarde du fichier courant",'always'),
+                       ('Fermer24',"closeJDC","Fermeture du fichier courant",'always'),
                         ('Zoom24',"visuJDC","Visualisation du fichier de commandes",'always'),
                         None,
                         ('Copy24',"copy","Copie l'objet courant",'jdc'),
@@ -96,13 +100,16 @@ class BUREAU:
    def __init__(self,appli,parent):
       self.parent=parent
       self.appli=appli
-      splash._splash.configure(text = "Création du bureau")
+      if self.appli.test == 0 :
+         splash._splash.configure(text = "Création du bureau")
       self.nb = Pmw.NoteBook(self.parent,raisecommand=self.selectJDC)
       self.nb.pack(fill='both',expand=1)
       self.JDCDisplay_courant=None
       self.fileName=None
       self.liste_JDCDisplay=[]
+      comploader.charger_composants()
       self.cree_cataitem()
+      self.text_reel=""
 
    def cree_cataitem(self):
       """
@@ -126,29 +133,58 @@ class BUREAU:
       if len(self.liste_JDCDisplay) == 0 : return
       #if self.JDCDisplay_courant : self.JDCDisplay_courant.jdc.unset_context()
       numero_jdc = self.nb.index(self.nb.getcurselection())
+      self.JDCDisplay_courant.unselect()
       self.JDCDisplay_courant = self.liste_JDCDisplay[numero_jdc]
       self.JDC = self.JDCDisplay_courant.jdc
-      #self.JDC.set_context()
       self.JDCName = self.JDC.nom
+      self.JDCDisplay_courant.select()
+      #print "selectJDC",numero_jdc,self.JDCDisplay_courant,self.JDCName
 
-   def newJDC(self,event=None):
+   def newJDC_include(self,event=None):
       """
           Initialise un nouveau JDC vierge
       """
+      import Extensions.jdc_include
+      JdC_aux=Extensions.jdc_include.JdC_include
+
       self.appli.statusbar.reset_affichage_infos()
 
       CONTEXT.unset_current_step()
-      J=self.cata[0].JdC(cata=self.cata,
-                         cata_ord_dico=self.cata_ordonne_dico,
-                         appli=self.appli,
+      jaux=self.cata[0].JdC(procedure="",appli=self.appli,
+                         cata=self.cata,cata_ord_dico=self.cata_ordonne_dico,
                          rep_mat=self.appli.CONFIGURATION.rep_mat,
                          )
+      jaux.analyse()
+
+      J=JdC_aux(procedure="",appli=self.appli,
+                         cata=self.cata,cata_ord_dico=self.cata_ordonne_dico,
+                         jdc_pere=jaux,
+                         rep_mat=self.appli.CONFIGURATION.rep_mat,
+                         )
+      J.analyse()
       self.JDCName=J.nom
       self.fileName=None
       self.ShowJDC(J,self.JDCName)
       self.appli.toolbar.active_boutons()
 
-   def ShowJDC(self,JDC,nom,label_onglet=None):
+   def newJDC(self,event=None):
+      """
+          Initialise un nouveau JDC include vierge
+      """
+      self.appli.statusbar.reset_affichage_infos()
+
+      CONTEXT.unset_current_step()
+      J=self.cata[0].JdC(procedure="",appli=self.appli,
+                         cata=self.cata,cata_ord_dico=self.cata_ordonne_dico,
+                         rep_mat=self.appli.CONFIGURATION.rep_mat,
+                         )
+      J.analyse()
+      self.JDCName=J.nom
+      self.fileName=None
+      self.ShowJDC(J,self.JDCName)
+      self.appli.toolbar.active_boutons()
+
+   def ShowJDC(self,JDC,nom,label_onglet=None,JDCDISPLAY=JDCDISPLAY):
       """
           Lance l'affichage du JDC cad création du JDCDisplay
           Rajoute le JDCDisplay à la liste des JDCDisplay si label_onglet == None cad si on crée
@@ -156,9 +192,8 @@ class BUREAU:
       """
       self.JDC=JDC
       self.JDCName = self.JDC.nom = nom
-      #XXX CCAR: pour le moment mis en commentaire
-      #self.JDC.set_context()
       if label_onglet == None :
+          # On veut un nouvel onglet
           label_onglet = self.GetLabelJDC()
           self.nb.add(label_onglet,tab_text = nom,tab_width=20)
           new = 'oui'
@@ -172,9 +207,45 @@ class BUREAU:
       self.nb.selectpage(label_onglet)
       self.nb.setnaturalsize()
       texte = "Jeu de commandes :" + self.JDCName+" ouvert"
+      CONNECTOR.Connect(JDC,"close",self.onClose,(self.JDCDisplay_courant,))
       self.appli.affiche_infos(texte)
 
+   def onClose(self,jdcdisplay):
+      #print "onClose",jdcdisplay
+      CONNECTOR.Disconnect(jdcdisplay.jdc,"close",self.onClose,(jdcdisplay,))
+      self.closeJDCDISPLAY(jdcdisplay)
+
+   def closeJDCDISPLAY(self,jdc):
+      """
+        Ferme le jdcdisplay spécifié par l'argument jdc
+      """
+      if jdc is self.JDCDisplay_courant:
+         # on ferme le jdcdisplay courant
+         self.closeSelectedJDC()
+      else:
+         # on ferme un autre jdcdisplay que le courant
+         old_JDCDisplay=self.JDCDisplay_courant
+         old_page=self.nb.getcurselection()
+
+         self.JDCDisplay_courant=jdc
+         self.JDC=jdc.jdc
+         numero_jdc=self.liste_JDCDisplay.index(jdc)
+         self.nb.selectpage(numero_jdc)
+         #print numero_jdc
+      
+         self.closeSelectedJDC()
+         self.JDCDisplay_courant=old_JDCDisplay
+         self.JDC=old_JDCDisplay.jdc
+         self.nb.selectpage(old_page)
+
    def closeJDC (self,event=None) :
+      """
+          Ferme le JDC associé au JDCDISPLAY selectionné
+      """
+      if self.JDCDisplay_courant :
+         self.JDCDisplay_courant.jdc.close()
+
+   def closeSelectedJDC (self) :
       """
       Ferme le JDC courant et détruit l'onglet associé dans le notebook self.nb
       """
@@ -212,7 +283,7 @@ class BUREAU:
           if not hasattr(self,'JDC') : return
           titre="rapport de validation du jeu de commandes courant"
           cr = self.JDC.report()
-          self.update_jdc_courant()
+          #self.update_jdc_courant()
       elif mode == 'CATA':
           from Noyau.N_CR import CR
           cr = CR()
@@ -229,7 +300,7 @@ class BUREAU:
       texte_cr = str(cr)
       self.visu_texte_cr = Fenetre(self.appli,titre=titre,texte=texte_cr)
 
-   def openJDC(self,file=None):
+   def openJDC(self,event=None,file=None,units=None):
       """
           Demande à l'utilisateur quel JDC existant il veut ouvrir
       """
@@ -240,10 +311,8 @@ class BUREAU:
       else:
           filetypes = ( ("format "+self.appli.format_fichier.get(), ".py"),)
       if not hasattr(self,'initialdir'):
-         #self.initialdir = self.appli.CONFIGURATION.rep_user
          self.initialdir = self.appli.CONFIGURATION.initialdir
-      if file.__class__.__name__ in  ('Event',):
-         file=None
+
       if not file :
           file = askopenfilename(title="Ouverture d'un fichier de commandes Aster",
                                  defaultextension=".comm",
@@ -253,11 +322,9 @@ class BUREAU:
           self.fileName = file
           e=extension_fichier(file)
           self.JDCName=stripPath(file)
-          self.initialdir = os.path.dirname(file)
+          self.initialdir = os.path.dirname(os.path.abspath(file))
       else :
           return
-      #XXX CCAR: pour le moment mis en commentaire
-      #if self.JDCDisplay_courant:self.JDCDisplay_courant.jdc.unset_context()
 
       format=self.appli.format_fichier.get()
       # Il faut convertir le contenu du fichier en fonction du format
@@ -265,7 +332,7 @@ class BUREAU:
          # Le convertisseur existe on l'utilise
          p=convert.plugins[format]()
          p.readfile(file)
-         text=p.convert('exec')
+         text=p.convert('exec',self.appli)
          if not p.cr.estvide(): 
             self.appli.affiche_infos("Erreur à la conversion")
             Fenetre(self.appli,
@@ -288,13 +355,19 @@ class BUREAU:
                          nom = self.JDCName,
                          rep_mat=self.appli.CONFIGURATION.rep_mat,
                          )
+      if units is not None:
+         J.recorded_units=units
+         J.old_recorded_units=units
+
       J.analyse()
       txt_exception = J.cr.get_mess_exception()
       if txt_exception :
           # des exceptions ont été levées à la création du JDC 
           # --> on affiche les erreurs mais pas le JDC
+          self.JDC=J
           self.appli.affiche_infos("Erreur fatale au chargement de %s" %file)
-          showerror("Erreur fatale au chargement d'un fichier",txt_exception)
+          if self.appli.test == 0 :
+             showerror("Erreur fatale au chargement d'un fichier",txt_exception)
       else:
           self.ShowJDC(J,self.JDCName)
           self.appli.toolbar.active_boutons()
@@ -305,7 +378,6 @@ class BUREAU:
             self.appli.top.update()
             self.visuCR(mode='JDC')
 
-
    def GetLabelJDC(self,nb_jdc = 'absent'):
       """
       Retourne le label de l'onglet du NoteBook associé au JDC à afficher
@@ -343,7 +415,6 @@ class BUREAU:
          if format == 'homard':
             self.jdc_homard=g.get_homard()
          if not g.cr.estvide():
-            print g.cr
             self.appli.affiche_infos("Erreur à la generation")
             showerror("Erreur à la generation","EFICAS ne sait pas convertir ce JDC")
             return
@@ -360,15 +431,23 @@ class BUREAU:
           #PN  Ajout --> Salome
           # Pour sauvegarde dans l etude si lancement depuis salome
           if self.appli.salome != 0:
-             import eficas_etude 
+             import eficasEtude 
              self.appli.salome.rangeInStudy(self.JDCDisplay_courant.fichier)
             from panelsSalome import SALOME_UNIQUE_BASE_Panel
             if len(SALOME_UNIQUE_BASE_Panel.dict_fichier_unite) > 0 :
                self.appli.salome.creeConfigTxt(self.appli.CONFIGURATION.initialdir,SALOME_UNIQUE_BASE_Panel.dict_fichier_unite)
+            try :
+            #if ( 1 == 1 ) :
+               import eficasCL
+               MyCLinit=eficasCL.CLinit()
+               MyCLinit.traiteCL()
+            except :
+            #else :
+               pass
           #PN  Fin Ajout --> Salome
           # le JDC a déjà un nom : on sauvegarde directement sans demander
           # un autre nom au développeur
-          if not save_in_file(self.JDCDisplay_courant.fichier,self.jdc_fini) :
+          if not save_in_file(self.JDCDisplay_courant.fichier,self.jdc_fini,self.appli.dir) :
               showinfo("Erreur","Problème à la sauvegarde du fichier :" + `self.JDCDisplay_courant.fichier`)
               return 0
           else :
@@ -396,13 +475,21 @@ class BUREAU:
           # PN ajout --> Salome
           # Pour sauvegarde dans l etude si lancement depuis salome
           if self.appli.salome != 0:
-             import eficas_etude 
+             import eficasEtude 
              self.appli.salome.rangeInStudy(sauvegarde)
             from panelsSalome import SALOME_UNIQUE_BASE_Panel
             if len(SALOME_UNIQUE_BASE_Panel.dict_fichier_unite) > 0 :
                self.appli.salome.creeConfigTxt(self.appli.CONFIGURATION.initialdir,SALOME_UNIQUE_BASE_Panel.dict_fichier_unite)
+            #try :
+            if ( 1 == 1 ):
+               import eficasCL
+               MyCLinit=eficasCL.CLinit()
+               MyCLinit.traiteCL()
+            #except :
+            else :
+               pass
           # PN fin ajout --> Salome
-          if not save_in_file(sauvegarde,self.jdc_fini) :
+          if not save_in_file(sauvegarde,self.jdc_fini,None) :
               showinfo("Erreur","Problème à la sauvegarde du fichier "+`sauvegarde`)
               return 0
           else :
@@ -414,6 +501,7 @@ class BUREAU:
                   # l'utilisateur a sauvegardé le JDC sous un autre nom
                   self.JDCDisplay_courant.fichier = sauvegarde
                   self.JDCName = self.JDC.nom = stripPath(sauvegarde)
+                  self.JDC.changefichier(sauvegarde)
                   self.changeNomPage()
               return 1
       else :
@@ -438,7 +526,7 @@ class BUREAU:
       liste = self.GetListeJDCaSauvegarder()
       if liste != [] :
           # Certains fichiers n'ont pas été sauvegardés ...
-          if askyesno("Enregistrer modifications","Enregister les modifications ?") :
+          if askyesno("Enregistrer modifications","Enregistrer les modifications ?") :
               test = self.saveall(liste)
               if test != 1 :
                   return
@@ -481,28 +569,10 @@ class BUREAU:
           Lance la suppression du noeud courant
       """
       if not self.JDCDisplay_courant : return
-      try:
-          if self.JDCDisplay_courant.modified == 'n' : 
-             self.JDCDisplay_courant.init_modif()
-          pere = self.JDCDisplay_courant.node_selected.parent
-          # Le noeud n'est pas au 1er niveau
-          if  pere.parent.parent != None:
-              self.JDCDisplay_courant.node_selected.delete()
-              pere.select()
-          else:
-              noeudselecte = self.JDCDisplay_courant.node_selected
-              parent = noeudselecte.parent
-              enfants = parent.children
-              index = enfants.index(noeudselecte) 
-              self.JDCDisplay_courant.node_selected.delete()
-              try:
-               enfants[index].select()
-              except :
-               enfants[index-1].select()
-      except AttributeError:
-          pass
+      self.JDCDisplay_courant.init_modif()
+      self.JDCDisplay_courant.node_selected.delete()
 
-   def visuJDC_py(self):
+   def visuJDC_py(self,event=None):
       """ 
           Méthode permettant d'afficher dans une fenêtre à part l'écho au 
             format python du jdc courant 
@@ -532,7 +602,6 @@ class BUREAU:
          g=generator.plugins[format]()
          jdc_formate=g.gener(self.JDC,format='beautifie')
          if not g.cr.estvide():
-            print g.cr
             self.appli.affiche_infos("Erreur à la generation")
             showerror("Erreur à la generation","EFICAS ne sait pas convertir ce JDC")
             return
@@ -609,6 +678,7 @@ class BUREAU:
       """
       test = 1
       for JDCDisplay in liste :
+          self.JDCDisplay_courant=JDCDisplay
           self.JDC = JDCDisplay.jdc
           test = test * self.saveJDC(echo = 'non')
       return test
@@ -624,8 +694,8 @@ class BUREAU:
        except:
            print "Pb a la sauvegarde sous le format homard"
        if self.appli.salome != 0:
-           import eficas_etude
-           self.appli.salome.rangeInStudy(file_homard)
+           import eficasEtude
+           self.appli.salome.rangeInStudy(file_homard,"_CONF")
 
 # ---------------------------------------------------------------------------
 #                      Méthodes liées aux mots-clés inconnus
@@ -644,4 +714,3 @@ class BUREAU:
    def update_jdc_courant(self):
       self.JDCDisplay_courant.update()
 
-