Salome HOME
sauve du 9 mai
[tools/eficas.git] / InterfaceQT4 / compomacro.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 # Modules Python
22 import os,sys,string
23 import types
24 import traceback
25
26 # Modules Eficas
27 from Editeur import Objecttreeitem
28 from Extensions.i18n import tr
29 import compooper
30 import browser
31 import typeNode
32 from determine import monEnvQT5
33 if monEnvQT5:
34    from PyQt5.QtWidgets import QAction
35    from PyQt5.QtCore import Qt
36 else :
37    from PyQt4.QtGui  import *
38    from PyQt4.QtCore import *
39
40
41
42 class MACRONode(browser.JDCNode,typeNode.PopUpMenuNode):         
43     
44     def getPanel(self):
45       from   monWidgetCommande import MonWidgetCommande
46       return MonWidgetCommande (self,self.editor ,self.item.object)
47
48
49     def createPopUpMenu(self):
50       typeNode.PopUpMenuNode.createPopUpMenu(self)
51       if ("AFFE_CARA_ELEM" in self.item.get_genealogie()) and self.editor.salome:
52            self.ViewElt = QAction(tr('View3D'),self.tree)
53            if monEnvQT5:
54               self.ViewElt.triggered.connect(self.View3D)
55            else :
56               self.tree.connect(self.ViewElt,SIGNAL("triggered()"),self.view3D)
57            self.ViewElt.setStatusTip(tr("affiche dans Geom les elements de structure"))
58            self.menu.addAction(self.ViewElt)
59            if self.item.isvalid() :
60               self.ViewElt.setEnabled(1)
61            else:
62               self.ViewElt.setEnabled(0)
63
64     def view3D(self) :
65         from Editeur import TroisDPal
66         troisD=TroisDPal.TroisDPilote(self.item,self.editor.appliEficas)
67         troisD.envoievisu()
68
69         
70
71     
72 class MACROTreeItem(compooper.EtapeTreeItem):
73 #  """ Cette classe hérite d'une grande partie des comportements
74 #      de la classe compooper.EtapeTreeItem
75 #  """
76     itemNode=MACRONode
77
78 # ------------------------------------
79 #  Classes necessaires a INCLUDE
80 # ------------------------------------
81
82 class INCLUDETreeItemBase(MACROTreeItem):
83
84     def __init__(self,appli, labeltext, object, setfunction):    
85        MACROTreeItem.__init__(self,appli, labeltext, object, setfunction)
86
87     def iscopiable(self):
88        return 0
89
90
91 class INCLUDENode(browser.JDCNode,typeNode.PopUpMenuNode):    
92
93     def getPanel(self):
94       from   monWidgetCommande import MonWidgetCommande
95       return MonWidgetCommande (self,self.editor ,self.item.object)
96
97     def createPopUpMenu(self):
98       typeNode.PopUpMenuNode.createPopUpMenu(self)
99       
100     def makeEdit(self):    #,appli,node
101         if self.item.object.text_converted == 0:
102                 # Le texte du fichier inclus n'a pas pu etre converti par le module convert
103                 msg=tr("Le fichier de commande n'a pas pu etre converti pour etre editable par Eficas\n\n")
104                 msg=msg+self.item.object.text_error
105                 return
106     
107         if not hasattr(self.item.object,"jdc_aux") or self.item.object.jdc_aux is None:
108                #L'include n'est pas initialise
109                self.item.object.build_include(None,"")
110     
111         # On cree un nouvel onglet dans le bureau
112         self.editor.vm.displayJDC( self.item.object.jdc_aux , self.item.object.jdc_aux.nom )
113      
114
115 class INCLUDETreeItem(INCLUDETreeItemBase):
116     itemNode=INCLUDENode
117     
118
119 # ------------------------------------
120 #  Classes necessaires à POURSUITE
121 # ------------------------------------
122     
123 class POURSUITENode(browser.JDCNode, typeNode.PopUpMenuNode):    
124
125     def getPanel(self):
126       from   monWidgetCommande import MonWidgetCommande
127       return MonWidgetCommande (self,self.editor ,self.item.object)
128
129     def createPopUpMenu(self):
130       typeNode.PopUpMenuNode.createPopUpMenu(self)
131
132     def makeEdit(self):    #,appli,node
133         if self.item.object.text_converted == 0:
134                 msg=tr("Le fichier de commande n'a pas pu etre converti pour etre editable par Eficas\n\n")
135                 msg=msg+self.item.object.text_error
136                 return
137     
138         if not hasattr(self.item.object,"jdc_aux") or self.item.object.jdc_aux is None:
139             text="""DEBUT()
140                     FIN()"""
141             self.object.build_poursuite(None,text)
142     
143         # On cree un nouvel onglet dans le bureau
144         self.editor.vm.displayJDC( self.item.object.jdc_aux , self.item.object.jdc_aux.nom)
145     
146 class POURSUITETreeItem(INCLUDETreeItemBase):
147   itemNode=POURSUITENode
148
149
150 # ----------------------------------------
151 #  Classes necessaires a INCLUDE MATERIAU
152 # ----------------------------------------
153     
154
155 class MATERIAUNode(MACRONode):
156
157     def getPanel(self):
158       from   monWidgetCommande import MonWidgetCommande
159       return MonWidgetCommande (self,self.editor ,self.item.object)
160
161     def createPopUpMenu(self):
162       typeNode.PopUpMenuNode.createPopUpMenu(self)
163
164     def makeView(self) :
165       if hasattr(self.item.object,'fichier_ini') and self.item.object.fichier_ini==None:
166          QMessageBox.information( self,tr("Include vide"),tr("L'include doit etre correctement initialise pour etre visualise"))
167          return
168       f = open(self.item.object.fichier_ini, "rb")
169       texte = f.read()
170       f.close()
171       from desVisu import DVisu
172       monVisuDialg=DVisu(parent=self.editor.appliEficas,fl=0)
173       monVisuDialg.TB.setText(texte)
174       monVisuDialg.show()
175
176
177 class INCLUDE_MATERIAUTreeItem(INCLUDETreeItemBase):
178     itemNode=MATERIAUNode
179
180 # ------------------------------------
181 # TreeItem
182 # ------------------------------------
183     
184
185 def treeitem(appli, labeltext, object, setfunction=None):
186    """ Factory qui retourne l'item adapte au type de macro : 
187        INCLUDE, POURSUITE, MACRO
188    """
189    if object.nom == "INCLUDE_MATERIAU":
190       return INCLUDE_MATERIAUTreeItem(appli, labeltext, object, setfunction)
191    elif object.nom == "INCLUDE" or object.nom== "DICTDATA":
192       return INCLUDETreeItem(appli, labeltext, object, setfunction)
193    elif object.nom == "POURSUITE":
194       return POURSUITETreeItem(appli, labeltext, object, setfunction)
195    else:
196       return MACROTreeItem(appli, labeltext, object, setfunction)
197
198 import Accas
199 objet=Accas.MACRO_ETAPE
200     
201