1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2010 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 __author__="aribes/gboulant"
23 # HACK - Pour l'instant
25 logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s %(message)s')
26 logger = logging.getLogger()
28 class DevelException(Exception):
29 def __init__(self, message):
30 """Canonical constructor"""
31 Exception.__init__(self,message)
34 # ==============================================================================
35 # Interface of an eficas observer (for implementing the subject/observer pattern)
36 # ==============================================================================
38 from daGuiImpl.enumerate import Enumerate
41 This class specifies the interface of an eficas observer. See example at the
44 def processEficasEvent(self, eficasWrapper, eficasEvent):
46 This function should be implemented in the concrete Observer.
47 @param eficasWrapper the instance of the source EficasWrapper
48 @param eficasEvent the emitted event (instance of EficasEvent)
50 raise DevelException("processEficasEvent not implemented yet")
53 EVENT_TYPES=Enumerate([
58 def __init__(self,eventType,callbackId=None):
60 Creates an eficas event to be used by an EficasWrapper to notify an
63 The eventType depends of the context of creation. It specify the nature
64 of the event inside EficasWrapper that triggers the creation of this instance.
66 The callbackId is an object used by the EficasObserver to map the
67 notification (this received event) with the initial event (callback)
68 This object can be anything and has to be defined through a convention
69 that both the EficasWrapper and the EficasObserver can understand.
70 Typically, the eficas observer set the callback id to the eficas wrapper
71 before running the asynchronous show. Then, when an event is raised by
72 the eficas wrapper toward its observer, it embeds the callback id so that
73 the observer can match the received event to the initial trigger context.
75 @param the eventType to be choosen in the EVENT_TYPES
76 @param callbackId an arbitrary data object
78 if not self.EVENT_TYPES.isValid(eventType):
79 raise DevelException("The event type "+str(eventType)+" is not defined")
81 self.eventType = eventType
82 self.callbackId = callbackId
85 # ==============================================================================
86 # Definition of an Eficas wrapper for integration to the SALOME framework
87 # This wrapper is not specific to the OMA context and is intended not to be.
88 # ==============================================================================
90 eficasPath = '@EFICAS_DIR@'
92 if os.environ.has_key( "EFICAS_ROOT"):
93 eficasPath = os.environ["EFICAS_ROOT"]
95 sys.path[:0]=[eficasPath,
96 os.path.join( eficasPath,'Editeur'),
97 os.path.join( eficasPath,'UiQT4'),
101 from InterfaceQT4 import qtEficas
103 class EficasWrapper(qtEficas.Appli):
105 def __init__(self, parent, code , fichier=None, module="Eficas", version=None, salome=0):
107 self.__codetype = code
110 # variables for the notification procedure
111 self.__observer = None
112 self.__callbackId = None
114 # The convention is that the python pref associated to the code are in
115 # a folder whose name is the code name with lower letters but the
116 # first that is in capital letter.
117 pathCode=code[0]+code[1:].lower()
118 sys.path[:0]=[os.path.join(eficasPath,pathCode)]
120 if Editeur.__dict__.has_key( 'session' ):
121 from Editeur import session
123 eficasArg += sys.argv
125 eficasArg += [ fichier ]
127 eficasArg += [ "-c", version ]
130 session.parse( eficasArg )
132 qtEficas.Appli.__init__( self,code=code,salome=salome,parent=parent)
134 def setCodeType(self,code):
135 self.__codetype = code
137 def setJdc(self, value, name=None):
139 if self.__jdc is None:
140 editor = self.viewmanager.getEditor()
141 editor.fichier = os.path.abspath(unicode("/tmp/eficasfile.comm"))
143 fichier = os.path.abspath(unicode("/tmp/eficasfile.comm"))
144 f = open(fichier,'w')
147 editor=self.viewmanager.getEditor( fichier,units=None)
149 # _TODO_ set the name and indicate that it's not used to ask a filename
150 #index=self.viewmanager.myQtab.currentIndex()
151 #self.viewmanager.myQtab.setTabText(index,fileName)
154 # First update the jdc attribute and return the value
155 self.__jdc = self.__getJdcText()
158 # ==========================================================================
159 # Function for the notification interface between an EficasWrapper an an
162 def addObserver(self, observer):
164 In fact, only one observer may be defined for the moment.
167 observer.processEficasEvent
169 raise DevelException("the argument should implement the function processEficasEvent")
170 self.__observer = observer
172 def notifyObserver(self, eventType):
173 eficasEvent = EficasEvent(eventType, self.getCallbackId())
174 self.__observer.processEficasEvent(self, eficasEvent)
176 def setCallbackId(self, callbackId):
178 This function should be used to define the callback identifier that
179 will be used by the observer to map the notifcation event with the source
181 @param callbackId Any object to be used in the notification interface
183 self.__callbackId = callbackId
185 def getCallbackId(self):
186 return self.__callbackId
188 # ==========================================================================
189 # Functions to handle the Eficas callback functions
191 def closeEvent(self,event):
193 This method is a notification function called at the end of the eficas
195 This close event has to be overload to handle the management of data
196 saving process, and to prevent the application from bug when reopen
197 eficas after a first close operation inside SALOME.
200 logger.debug("#### Handle closeEvent")
202 # Get the data and notify the observers of the event
204 self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE)
207 # This is to prevent from bug when reopen eficas after a first close
208 # operation inside SALOME.
209 import InterfaceQT4.readercata
210 if hasattr(InterfaceQT4.readercata,'reader') :
211 del InterfaceQT4.readercata.reader
219 logger.debug("This is my fileSave")
220 # Notify the observers of the event
221 self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
223 qtEficas.Appli.fileSave(self)
226 def fileSaveAs(self):
230 logger.debug("This is my fileSaveAs")
237 logger.debug("This is my fileClose")
238 qtEficas.Appli.fileClose(self)
240 def fileCloseAll(self):
244 logger.debug("This is my fileCloseAll")
245 qtEficas.Appli.fileCloseAll(self)
247 # ==========================================================================
250 def __getJdcText(self):
252 This function returns the current jdc in text format.
254 index=self.viewmanager.myQtab.currentIndex()
255 if index < 0 : return
257 editor=self.viewmanager.dict_editors[index]
258 format = self.format_fichier
259 strSource = str( editor.get_text_JDC(format) )
262 def displayNew(self):
266 # ==========================================================================
269 def __displayData(self, textjdc):
270 index=self.viewmanager.myQtab.currentIndex()
271 if index < 0 : return
273 editor=self.viewmanager.dict_editors[index]
275 jdc=editor.readercata.cata[0].JdC(procedure=textjdc,appli=editor,cata=editor.readercata.cata,cata_ord_dico=editor.readercata.cata_ordonne_dico,nom="JDC name",rep_mat=editor.CONFIGURATION.rep_mat)
276 self.viewmanager.getEditor("toto.com",jdc)