Salome HOME
e04a6da53c8ac4310151fd9048658d8af6a79005
[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 class MACROTreeItem(compooper.EtapeTreeItem):
72 #  """ Cette classe hérite d'une grande partie des comportements
73 #      de la classe compooper.EtapeTreeItem
74 #  """
75     itemNode=MACRONode
76
77 # ------------------------------------
78 #  Classes necessaires a INCLUDE
79 # ------------------------------------
80
81 class INCLUDETreeItemBase(MACROTreeItem):
82
83     def __init__(self,appli, labeltext, object, setfunction):    
84        MACROTreeItem.__init__(self,appli, labeltext, object, setfunction)
85
86     def iscopiable(self):
87        return 0
88
89
90 class INCLUDENode(browser.JDCNode,typeNode.PopUpMenuNode):    
91
92     def getPanel(self):
93       from   monWidgetCommande import MonWidgetCommande
94       return MonWidgetCommande (self,self.editor ,self.item.object)
95
96     def createPopUpMenu(self):
97       typeNode.PopUpMenuNode.createPopUpMenu(self)
98       
99     def makeEdit(self):    #,appli,node
100         if self.item.object.text_converted == 0:
101                 # Le texte du fichier inclus n'a pas pu etre converti par le module convert
102                 msg=tr("Le fichier de commande n'a pas pu etre converti pour etre editable par Eficas\n\n")
103                 msg=msg+self.item.object.text_error
104                 return
105     
106         if not hasattr(self.item.object,"jdc_aux") or self.item.object.jdc_aux is None:
107                #L'include n'est pas initialise
108                self.item.object.build_include(None,"")
109     
110         # On cree un nouvel onglet dans le bureau
111         self.editor.vm.displayJDC( self.item.object.jdc_aux , self.item.object.jdc_aux.nom )
112      
113
114 class INCLUDETreeItem(INCLUDETreeItemBase):
115     itemNode=INCLUDENode
116     
117
118 # ------------------------------------
119 #  Classes necessaires à POURSUITE
120 # ------------------------------------
121     
122 class POURSUITENode(browser.JDCNode, typeNode.PopUpMenuNode):    
123
124     def getPanel(self):
125       from   monWidgetCommande import MonWidgetCommande
126       return MonWidgetCommande (self,self.editor ,self.item.object)
127
128     def createPopUpMenu(self):
129       typeNode.PopUpMenuNode.createPopUpMenu(self)
130
131     def makeEdit(self):    #,appli,node
132         if self.item.object.text_converted == 0:
133                 msg=tr("Le fichier de commande n'a pas pu etre converti pour etre editable par Eficas\n\n")
134                 msg=msg+self.item.object.text_error
135                 return
136     
137         if not hasattr(self.item.object,"jdc_aux") or self.item.object.jdc_aux is None:
138             text="""DEBUT()
139                     FIN()"""
140             self.object.build_poursuite(None,text)
141     
142         # On cree un nouvel onglet dans le bureau
143         self.editor.vm.displayJDC( self.item.object.jdc_aux , self.item.object.jdc_aux.nom)
144     
145 class POURSUITETreeItem(INCLUDETreeItemBase):
146   itemNode=POURSUITENode
147
148
149 # ----------------------------------------
150 #  Classes necessaires a INCLUDE MATERIAU
151 # ----------------------------------------
152     
153
154 class MATERIAUNode(MACRONode):
155
156     def getPanel(self):
157       from   monWidgetCommande import MonWidgetCommande
158       return MonWidgetCommande (self,self.editor ,self.item.object)
159
160     def createPopUpMenu(self):
161       typeNode.PopUpMenuNode.createPopUpMenu(self)
162
163     def makeView(self) :
164       if hasattr(self.item.object,'fichier_ini') and self.item.object.fichier_ini==None:
165          QMessageBox.information( self,tr("Include vide"),tr("L'include doit etre correctement initialise pour etre visualise"))
166          return
167       f = open(self.item.object.fichier_ini, "rb")
168       texte = f.read()
169       f.close()
170       from desVisu import DVisu
171       monVisuDialg=DVisu(parent=self.editor.appliEficas,fl=0)
172       monVisuDialg.TB.setText(texte)
173       monVisuDialg.show()
174
175
176 class INCLUDE_MATERIAUTreeItem(INCLUDETreeItemBase):
177     itemNode=MATERIAUNode
178
179 # ------------------------------------
180 # TreeItem
181 # ------------------------------------
182     
183
184 def treeitem(appli, labeltext, object, setfunction=None):
185    """ Factory qui retourne l'item adapte au type de macro : 
186        INCLUDE, POURSUITE, MACRO
187    """
188    if object.nom == "INCLUDE_MATERIAU":
189       return INCLUDE_MATERIAUTreeItem(appli, labeltext, object, setfunction)
190    elif object.nom == "INCLUDE" or object.nom== "DICTDATA":
191       return INCLUDETreeItem(appli, labeltext, object, setfunction)
192    elif object.nom == "POURSUITE":
193       return POURSUITETreeItem(appli, labeltext, object, setfunction)
194    else:
195       return MACROTreeItem(appli, labeltext, object, setfunction)
196
197 import Accas
198 objet=Accas.MACRO_ETAPE
199     
200