From 4989b371369901f92354384dfebd54b460018c71 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9?= Date: Wed, 28 Apr 2010 15:07:06 +0200 Subject: [PATCH] =?utf8?q?-=20On=20g=C3=A9re=20bien=20le=20GUI=20EFICAS?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/daEficas/generator_datassim.py | 22 ++++-- .../daEficasWrapper/datassimEficasWrapper.py | 70 ++++++++++++++++--- .../daGUI/daEficasWrapper/eficasWrapper.py.in | 18 ++++- src/daSalome/daGUI/daGuiImpl/Makefile.am | 1 + src/daSalome/daGUI/daGuiImpl/datassimCase.py | 32 +++++++++ .../daGUI/daGuiImpl/datassimGuiManager.py | 50 +++++++++---- .../daGUI/daGuiImpl/datassimStudyEditor.py | 22 +----- 7 files changed, 167 insertions(+), 48 deletions(-) create mode 100644 src/daSalome/daGUI/daGuiImpl/datassimCase.py diff --git a/src/daEficas/generator_datassim.py b/src/daEficas/generator_datassim.py index 7aeb035..1520939 100644 --- a/src/daEficas/generator_datassim.py +++ b/src/daEficas/generator_datassim.py @@ -23,6 +23,7 @@ class DatassimGenerator(PythonGenerator): self.dictMCVal={} self.text_comm = "" self.text_da = "" + self.text_da_status = False def gener(self,obj,format='brut',config=None): print "DatassimGenerator gener" @@ -30,16 +31,23 @@ class DatassimGenerator(PythonGenerator): print "Dictionnaire" print self.dictMCVal - - self.generate_da() + + try : + self.text_da_status = False + self.generate_da() + self.text_da_status = True + except: + print "Case seems not be correct" + pass return self.text_comm def writeDefault(self, fn): - print "writeDefault" - filename = fn[:fn.rfind(".")] + '.py' - f = open( str(filename), 'wb') - f.write( self.text_da ) - f.close() + if self.text_da_status: + print "write datassim python command file" + filename = fn[:fn.rfind(".")] + '.py' + f = open( str(filename), 'wb') + f.write( self.text_da ) + f.close() def generMCSIMP(self,obj) : """ diff --git a/src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py b/src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py index 5963037..01a6f64 100644 --- a/src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py +++ b/src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py @@ -19,6 +19,7 @@ # from eficasWrapper import * +from PyQt4 import QtGui,QtCore import sys # Configuration de l'installation @@ -32,15 +33,33 @@ sys.path[:0]=[DATASSIM_INSTALL_DIR] # ================================================ # class DatassimEficasWrapper(EficasWrapper): + + __myCallbackId = {} + __close_editor = None + def __init__(self, parent, code="DATASSIM"): EficasWrapper.__init__(self, parent, code) + # Association de l'objet editor avec le callbackId + def setCallbackId(self, callbackId): + index = self.viewmanager.myQtab.currentIndex() + self.__myCallbackId[self.viewmanager.dict_editors[index]] = callbackId + + def getCallbackId(self): + if self.__close_editor is None: + index = self.viewmanager.myQtab.currentIndex() + return self.__myCallbackId[self.viewmanager.dict_editors[index]] + else: + return self.__myCallbackId[self.__close_editor] + def fileSave(self): """ @overload """ qtEficas.Appli.fileSave(self) - self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE) + index = self.viewmanager.myQtab.currentIndex() + if index > -1 : + self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE) def fileSaveAs(self): """ @@ -49,10 +68,45 @@ class DatassimEficasWrapper(EficasWrapper): qtEficas.Appli.fileSaveAs(self) self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE) - def getCurrentFileName(self): - index = self.viewmanager.myQtab.currentIndex() - print index - rtn = "" - if index > 0 : - rtn = self.viewmanager.myQtab.tabText(index) - return rtn + def getCaseName(self): + if self.__close_editor is None: + index = self.viewmanager.myQtab.currentIndex() + CaseName = self.viewmanager.myQtab.tabText(index) + return CaseName + else: + CaseName = self.__close_editor.fichier.split('/')[-1] + return CaseName + + def fileOpen(self): + """ + @overload + """ + QtGui.QMessageBox.warning( self, "Alerte", "You cannot Open a Case into Eficas window when you are using Datassim SALOME module") + + def fileClose(self): + """ + @overload + """ + index = self.viewmanager.myQtab.currentIndex() + self.__close_editor = self.viewmanager.dict_editors[index] + res = self.viewmanager.handleClose(self) + if res != 2: # l utilsateur a annule + if self.__close_editor.fichier is None: + # We have to destroy the case + self.notifyObserver(EficasEvent.EVENT_TYPES.DESTROY) + self.__myCallbackId.pop(self.__close_editor) + else: + # Il faudrait en faire plus -> Voir Edit dans SALOME ! + self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE) + self.__myCallbackId.pop(self.__close_editor) + self.__close_editor = None + return res + + def fileCloseAll(self): + """ + @overload + """ + while len(self.viewmanager.dict_editors) > 0: + self.viewmanager.myQtab.setCurrentIndex(0) + res = self.fileClose() + if res==2 : return res # l utilsateur a annule diff --git a/src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in b/src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in index 4b646df..10ed4b2 100644 --- a/src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in +++ b/src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in @@ -52,7 +52,9 @@ class EficasObserver: class EficasEvent: EVENT_TYPES=Enumerate([ 'CLOSE', - 'SAVE' + 'SAVE', + 'DESTROY', + 'NEW' ]) def __init__(self,eventType,callbackId=None): @@ -170,8 +172,11 @@ class EficasWrapper(qtEficas.Appli): self.__observer = observer def notifyObserver(self, eventType): + if eventType != EficasEvent.EVENT_TYPES.NEW: eficasEvent = EficasEvent(eventType, self.getCallbackId()) - self.__observer.processEficasEvent(self, eficasEvent) + else: + eficasEvent = EficasEvent(eventType) + self.__observer.processEficasEvent(self, eficasEvent) def setCallbackId(self, callbackId): """ @@ -211,6 +216,15 @@ class EficasWrapper(qtEficas.Appli): del InterfaceQT4.readercata.reader event.accept() + def fileNew(self): + """ + @overload + """ + logger.debug("This is my fileNew") + qtEficas.Appli.fileNew(self) + # Notify the observers of the event - after to be able to handled with editor + # If needed + self.notifyObserver(EficasEvent.EVENT_TYPES.NEW) def fileSave(self): """ diff --git a/src/daSalome/daGUI/daGuiImpl/Makefile.am b/src/daSalome/daGUI/daGuiImpl/Makefile.am index 2c142b4..dfc4733 100644 --- a/src/daSalome/daGUI/daGuiImpl/Makefile.am +++ b/src/daSalome/daGUI/daGuiImpl/Makefile.am @@ -29,6 +29,7 @@ mypkgpython_PYTHON = \ datassimModuleHelper.py \ datassimStudyEditor.py \ studyedit.py \ + datassimCase.py \ enumerate.py diff --git a/src/daSalome/daGUI/daGuiImpl/datassimCase.py b/src/daSalome/daGUI/daGuiImpl/datassimCase.py new file mode 100644 index 0000000..e37c9af --- /dev/null +++ b/src/daSalome/daGUI/daGuiImpl/datassimCase.py @@ -0,0 +1,32 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2010 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +class DatassimCase: + + __name = "new_case" + + def __init__(self): + pass + + def get_name(self): + return self.__name + + def set_name(self, name): + self.__name = name diff --git a/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py b/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py index 9d53d56..231d7cb 100644 --- a/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py +++ b/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py @@ -31,12 +31,15 @@ import SalomePyQt sgPyQt = SalomePyQt.SalomePyQt() from daGuiImpl.enumerate import Enumerate +from daGuiImpl.datassimCase import DatassimCase from daEficasWrapper.datassimEficasWrapper import DatassimEficasWrapper from daEficasWrapper.eficasWrapper import EficasObserver from daEficasWrapper.eficasWrapper import EficasEvent import datassimGuiHelper import datassimStudyEditor +__cases__ = {} + # # ============================================================================== # Classes to manage the building of UI components @@ -106,12 +109,6 @@ class DatassimGuiActionImpl(EficasObserver): print msg def newDatassimCase(self): - print "newDatassimCase" - salomeStudyId = datassimGuiHelper.getActiveStudyId() - salomeStudyItem = datassimStudyEditor.addInStudy(salomeStudyId, "newDatassimCase") - datassimGuiHelper.refreshObjectBrowser() - callbackId = [salomeStudyId, salomeStudyItem] - self.__dlgEficasWrapper.setCallbackId(callbackId) self.__dlgEficasWrapper.displayNew() # ========================================================================== @@ -119,7 +116,9 @@ class DatassimGuiActionImpl(EficasObserver): # __processOptions={ EficasEvent.EVENT_TYPES.CLOSE : "_processEficasCloseEvent", - EficasEvent.EVENT_TYPES.SAVE : "_processEficasSaveEvent" + EficasEvent.EVENT_TYPES.SAVE : "_processEficasSaveEvent", + EficasEvent.EVENT_TYPES.NEW : "_processEficasNewEvent", + EficasEvent.EVENT_TYPES.DESTROY : "_processEficasDestroyEvent" } def processEficasEvent(self, eficasWrapper, eficasEvent): """ @@ -135,6 +134,17 @@ class DatassimGuiActionImpl(EficasObserver): print "Remove datassim case in study if empty..." pass + def _processEficasNewEvent(self, eficasWrapper, eficasEvent): + global __cases__ + new_case = DatassimCase() + salomeStudyId = datassimGuiHelper.getActiveStudyId() + salomeStudyItem = datassimStudyEditor.addInStudy(salomeStudyId, new_case) + case_key = (salomeStudyId, salomeStudyItem) + __cases__[case_key] = new_case + datassimGuiHelper.refreshObjectBrowser() + callbackId = [salomeStudyId, salomeStudyItem] + self.__dlgEficasWrapper.setCallbackId(callbackId) + def _processEficasSaveEvent(self, eficasWrapper, eficasEvent): callbackId = eficasEvent.callbackId if callbackId is None: @@ -143,11 +153,27 @@ class DatassimGuiActionImpl(EficasObserver): if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ): raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None") - file_name = eficasWrapper.getCurrentFileName() - datassimStudyEditor.updateItem(targetSalomeStudyId, targetSalomeStudyItem, file_name) - #studyCase = omaStudyEditor.getOmaCaseFromItem(targetSalomeStudyId, targetSalomeStudyItem) - #studyCase = eficasWrapper.getData(studyCase) - #logger.debug("jdc="+str(studyCase.userdata.getJdc())) + # Get Editor All infos we need ! + file_name = eficasWrapper.getCaseName() + if file_name != "" : + case_key = (targetSalomeStudyId, targetSalomeStudyItem) + case =__cases__[case_key] + case.set_name(file_name) + datassimStudyEditor.updateItem(targetSalomeStudyId, targetSalomeStudyItem, case) + datassimGuiHelper.refreshObjectBrowser() + + def _processEficasDestroyEvent(self, eficasWrapper, eficasEvent): + callbackId = eficasEvent.callbackId + if callbackId is None: + raise DevelException("the callback data should not be None. Can't guess what are the study and case") + [targetSalomeStudyId,targetSalomeStudyItem] = callbackId + if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ): + raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None") + + case_key = (targetSalomeStudyId, targetSalomeStudyItem) + __cases__.pop(case_key) + datassimStudyEditor.removeItem(targetSalomeStudyId, targetSalomeStudyItem) + datassimGuiHelper.refreshObjectBrowser() def _processEficasUnknownEvent(self, eficasWrapper, eficasEvent): print "Unknown Eficas Event" diff --git a/src/daSalome/daGUI/daGuiImpl/datassimStudyEditor.py b/src/daSalome/daGUI/daGuiImpl/datassimStudyEditor.py index 42eac25..cd8af4b 100644 --- a/src/daSalome/daGUI/daGuiImpl/datassimStudyEditor.py +++ b/src/daSalome/daGUI/daGuiImpl/datassimStudyEditor.py @@ -23,6 +23,7 @@ __author__="aribes/gboulant" from enumerate import Enumerate import studyedit import datassimModuleHelper +from daGuiImpl.datassimCase import DatassimCase # # ============================================================================== @@ -58,7 +59,7 @@ def addInStudy(salomeStudyId, datassimCase): engineName = datassimModuleHelper.componentName(), componentName = datassimModuleHelper.componentUserName()) - itemName = datassimCase + itemName = datassimCase.get_name() itemValue = "" itemType = DATASSIM_ITEM_TYPES.DATASSIM_CASE @@ -75,7 +76,7 @@ def updateItem(salomeStudyId, salomeStudyItem, datassimCase): studyEditor = studyedit.getStudyEditor(salomeStudyId) - itemName = datassimCase + itemName = datassimCase.get_name() itemValue = "" studyEditor.setItem(salomeStudyItem, @@ -86,8 +87,6 @@ def removeItem(salomeStudyId, item): """ Remove the item from the specified study. """ - if not isValidDatassimCaseItem(salomeStudyId, item): - return False studyEditor = studyedit.getStudyEditor(salomeStudyId) return studyEditor.removeItem(item,True) @@ -105,18 +104,3 @@ def isValidDatassimCaseItem(salomeStudyId,item): return False return True - - -def getDatassimCaseFromItem(salomeStudyId, item): - """ - Get the datassim case from the selected item. - Note that the study must be specify to retrieve the attributes value from - the item reference. The attribute values are stored in the study object. - """ - if not isValidDatassimCaseItem(salomeStudyId, item): - return None - - itemName = item.GetName() - itemValue = item.GetComment() - return itemName - -- 2.39.2