Salome HOME
Merge remote branch 'origin/V8_5_asterstudy'
[modules/smesh.git] / src / Tools / padder / spadderpy / gui / plugindialog.py
index 6acec908b49e28fc2bd2fc8916e23cb8d433998e..cb14896ab3aa3f7194ab4efa53a0e962cd8afb7d 100644 (file)
 # Author : Guillaume Boulant (EDF)
 #
 
-from PyQt4.QtGui import QDialog, QIcon
-from PyQt4.QtCore import QObject, SIGNAL, SLOT, Qt
+from qtsalome import QDialog, QIcon, Qt
 
-from plugindialog_ui import Ui_PluginDialog
-from inputdialog import InputDialog
-from inputdata import InputData
+from salome.smesh.spadder.gui.plugindialog_ui import Ui_PluginDialog
+from salome.smesh.spadder.gui.inputdialog import InputDialog, INPUTDATA_KEY_FILES, INPUTDATA_KEY_PARAM
+from salome.smesh.spadder.gui.inputdialog import PARAM_KEY_NBITER, PARAM_KEY_RMAXRMIN
+from salome.smesh.spadder.gui.inputdata import InputData
 # __GBO__: uncomment this line and comment the previous one to use the
 # demo input dialog instead of the real one.
 #from demoinputdialog import InputDialog
@@ -38,7 +38,7 @@ from salome.kernel.uiexception import AdminException
 from omniORB import CORBA
 import SMESH
 from salome.smesh import smeshBuilder
-smesh = smeshBuilder.New(salome.myStudy)
+smesh = smeshBuilder.New()
 import MESHJOB
 
 gui_states = ["CAN_SELECT", "CAN_COMPUTE", "CAN_REFRESH", "CAN_PUBLISH"]
@@ -87,27 +87,27 @@ class PluginDialog(QDialog):
         self.__ui.btnClear.setIcon(icon)
 
         # Then, we can connect the slot to there associated button event
-        self.connect(self.__ui.btnInput,       SIGNAL('clicked()'), self.onInput )
-        self.connect(self.__ui.btnCompute,     SIGNAL('clicked()'), self.onCompute )
-        self.connect(self.__ui.btnRefresh,     SIGNAL('clicked()'), self.onRefresh )
-        self.connect(self.__ui.btnPublish,     SIGNAL('clicked()'), self.onPublish )
-        self.connect(self.__ui.btnClear,       SIGNAL('clicked()'), self.onClear )
+        self.__ui.btnInput.clicked.connect( self.onInput )
+        self.__ui.btnCompute.clicked.connect( self.onCompute )
+        self.__ui.btnRefresh.clicked.connect( self.onRefresh )
+        self.__ui.btnPublish.clicked.connect( self.onPublish )
+        self.__ui.btnClear.clicked.connect( self.onClear )
 
         self.clear()
 
         self.setupJobManager()
-        
+
 
     def setupJobManager(self):
         '''
-        This function configures the jobmanager by transmiting the
+        This function configures the jobmanager by transmitting the
         parameters required for a local execution and a remote
         execution. The choice between "local" and "remote" is done at
-        the initialize step, by specifing the name of the resource to
+        the initialize step, by specifying the name of the resource to
         be used.
         '''
-        # We first 
-        
+        # We first
+
         configReader = ConfigReader()
         config = configReader.getLocalConfig()
         configId = config.resname
@@ -138,10 +138,10 @@ class PluginDialog(QDialog):
             # items in the object browser:
             self.__inputDialog.setWindowFlags(
                 self.__inputDialog.windowFlags() | Qt.WindowStaysOnTopHint)
-            # The signal inputValidated emited from inputDialog is
+            # The signal inputValidated emitted from inputDialog is
             # connected to the slot function onProcessInput:
-            self.connect(self.__inputDialog, SIGNAL('inputValidated()'), self.onProcessInput)
-            
+            self.__inputDialog.inputValidated.connect( self.onProcessInput )
+
         else:
             self.__ui.frameInput.setVisible(True)
             self.__ui.btnInput.setVisible(False)
@@ -151,13 +151,13 @@ class PluginDialog(QDialog):
 
     def getInputFrame(self):
         return self.__ui.frameInput
-        
+
     def __setGuiState(self,states=["CAN_SELECT"]):
         if "CAN_SELECT" in states:
             self.__ui.btnInput.setEnabled(True)
         else:
             self.__ui.btnInput.setEnabled(False)
-            
+
         if "CAN_COMPUTE" in states:
             self.__ui.btnCompute.setEnabled(True)
         else:
@@ -179,7 +179,7 @@ class PluginDialog(QDialog):
         servant. Note that the component is loaded on first demand,
         and then the reference is recycled.
         """
-        if self.__dict__.has_key("__jobManager") and self.__jobManager is not None:
+        if "__jobManager" in self.__dict__ and self.__jobManager is not None:
             return self.__jobManager
 
         # WARN: we first have to update the SALOME components catalog
@@ -201,7 +201,7 @@ class PluginDialog(QDialog):
     def __log(self, message):
         """
         This function prints the specified message in the log area
-        """ 
+        """
         self.__ui.txtLog.append(message)
 
     def __exportMesh(self, meshName, meshObject):
@@ -211,7 +211,7 @@ class PluginDialog(QDialog):
         name. This returns the filename.
         '''
         filename=str("/tmp/padder_inputfile_"+meshName+".med")
-        meshObject.ExportToMEDX( filename, 0, SMESH.MED_V2_2, 1, 1 )
+        meshObject.ExportMED(filename, False, True, True)
         return filename
 
     def clear(self):
@@ -219,6 +219,7 @@ class PluginDialog(QDialog):
         This function clears the log area and the states of the buttons
         """
         self.__listInputData = []
+        self.__dictInputParameters = {}
         self.__ui.txtLog.clear()
         self.__setGuiState(["CAN_SELECT"])
         self.__isRunning = False
@@ -242,7 +243,10 @@ class PluginDialog(QDialog):
         windows to process the validation event (see the slot
         onProcessInput which is connected to this event).
         '''
-        self.__inputDialog.setData(self.__listInputData)
+        dictInputData = {}
+        dictInputData[INPUTDATA_KEY_FILES] = self.__listInputData
+        dictInputData[INPUTDATA_KEY_PARAM] = self.__dictInputParameters
+        self.__inputDialog.setData(dictInputData)
         self.__inputDialog.open()
 
     def onProcessInput(self):
@@ -253,45 +257,56 @@ class PluginDialog(QDialog):
         """
         # The processing simply consists in requesting the input data
         # from the dialog window.
-        self.__listInputData = self.__inputDialog.getData()
+        dictInputData = self.__inputDialog.getData()
+        self.__listInputData = dictInputData[INPUTDATA_KEY_FILES]
+        self.__dictInputParameters = dictInputData[INPUTDATA_KEY_PARAM]
+
         self.__ui.lblStatusBar.setText("Input data OK")
         self.__log("INF: Press \"Compute\" to start the job")
         self.__setGuiState(["CAN_SELECT", "CAN_COMPUTE"])
-        
+
     def onCompute(self):
         '''
         This function is the slot connected to the Compute button. It
         initializes a mesh computation job and start it using the
-        SALOME launcher.  
+        SALOME launcher.
         '''
         # We first have to create the list of parameters for the
         # initialize function. For that, we have to create the files
         # from the mesh objects:
-        meshJobParameterList=[]
+        meshJobFileList=[]
         concreteIndex=0
         for inputData in self.__listInputData:
             # For each input data, we have to create a
-            # MeshJobParameter and add it to the list.
+            # MeshJobFile and add it to the list.
             filename  = self.__exportMesh(inputData.meshName, inputData.meshObject)
             if inputData.meshType == InputData.MESHTYPES.CONCRETE:
                 filetype = MESHJOB.MED_CONCRETE
             else:
                 filetype = MESHJOB.MED_STEELBAR
 
-            parameter = MESHJOB.MeshJobParameter(
+            parameter = MESHJOB.MeshJobFile(
                 file_name  = filename,
                 file_type  = filetype,
                 group_name = inputData.groupName)
+            meshJobFileList.append(parameter)
+
+        # And to create a list of the additional parameters.
+        # WARN: the CORBA interface requires string values.
+        meshJobParameterList=[]
+        for inputParameterKey in self.__dictInputParameters:
+            value = self.__dictInputParameters[inputParameterKey]
+            parameter = MESHJOB.MeshJobParameter(name=inputParameterKey,value=str(value))
             meshJobParameterList.append(parameter)
 
         jobManager = self.__getJobManager()
-        self.__jobid = jobManager.initialize(meshJobParameterList, self.__configId)
+        self.__jobid = jobManager.initialize(meshJobFileList, meshJobParameterList, self.__configId)
         if self.__jobid < 0:
             self.__log("ERR: the job can't be initialized")
             self.__log("ERR: %s"%jobManager.getLastErrorMessage())
             return
         self.__log("INF: the job has been initialized with jobid = "+str(self.__jobid))
-        
+
         startOk = jobManager.start(self.__jobid)
         if not startOk:
             self.__log("ERR: the job with jobid = "+str(self.__jobid)+" can't be started")
@@ -327,7 +342,7 @@ class PluginDialog(QDialog):
         This function is the slot connected on the Publish button. It
         requests the mesh job manager to download the results data
         from the computation resource host and load the med file in
-        the SALOME study. 
+        the SALOME study.
         """
         jobManager = self.__getJobManager()
         state = jobManager.getState(self.__jobid)
@@ -353,7 +368,7 @@ class PluginDialog(QDialog):
         medfilename = os.path.join(meshJobResults.results_dirname,
                                    meshJobResults.outputmesh_filename)
 
-        smesh.SetCurrentStudy(studyedit.getActiveStudy())
+        smesh.UpdateStudy()
         ([outputMesh], status) = smesh.CreateMeshesFromMED(medfilename)
 
         # By convention, the name of the output mesh in the study is
@@ -361,7 +376,7 @@ class PluginDialog(QDialog):
         meshname = 'padder_'+str(self.__jobid)
         smesh.SetName(outputMesh.GetMesh(), meshname)
         if salome.sg.hasDesktop():
-            salome.sg.updateObjBrowser(0)
+            salome.sg.updateObjBrowser()
 
         self.__ui.lblStatusBar.setText("Publication OK")
         self.__setGuiState(["CAN_SELECT"])
@@ -373,13 +388,13 @@ class PluginDialog(QDialog):
         one is running.
         """
         self.clear()
-        
+
 
 
 __dialog=None
 def getDialog():
     """
-    This function returns a singleton instance of the plugin dialog. 
+    This function returns a singleton instance of the plugin dialog.
     """
     global __dialog
     if __dialog is None:
@@ -393,16 +408,12 @@ def getDialog():
 #
 def TEST_PluginDialog():
     import sys
-    from PyQt4.QtGui import QApplication
-    from PyQt4.QtCore import QObject, SIGNAL, SLOT
+    from qtsalome import QApplication
     app = QApplication(sys.argv)
-    QObject.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
+    app.lastWindowClosed.connect( app.quit )
 
     dlg=PluginDialog()
     dlg.exec_()
 
 if __name__ == "__main__":
     TEST_PluginDialog()
-
-        
-