Salome HOME
Merge Python 3 porting.
[modules/smesh.git] / src / Tools / padder / spadderpy / gui / inputdialog.py
index 376a90039291f4cfd258687f099285b9b8a7c4db..f0d81eaeccad2b109124a4a7d670013546db44bc 100644 (file)
@@ -32,16 +32,24 @@ from omniORB import CORBA
 
 from qtsalome import QIcon, QStandardItemModel, QStandardItem, QMessageBox, pyqtSignal
 
 
 from qtsalome import QIcon, QStandardItemModel, QStandardItem, QMessageBox, pyqtSignal
 
-from inputframe_ui import Ui_InputFrame
-from inputdata import InputData
+from salome.smesh.spadder.gui.inputframe_ui import Ui_InputFrame
+from salome.smesh.spadder.gui.inputdata import InputData
 
 DEBUG_MODE=True
 GROUPNAME_MAXLENGTH=8
 
 
 DEBUG_MODE=True
 GROUPNAME_MAXLENGTH=8
 
+INPUTDATA_KEY_FILES="meshfiles"
+INPUTDATA_KEY_PARAM="parameters"
+
+PARAM_KEY_NBITER   = "NbIteration"
+PARAM_KEY_RMAXRMIN = "RmaxRmin"
+PARAM_NBITER_DEFAULT_VALUE = 10
+PARAM_RMAXRMIN_DEFAULT_VALUE = 3
+
 class InputDialog(GenericDialog):
 
     TBL_HEADER_LABEL=["Input Mesh", "Output group name"]
 class InputDialog(GenericDialog):
 
     TBL_HEADER_LABEL=["Input Mesh", "Output group name"]
-    
+
     inputValidated = pyqtSignal()
 
     def __init__(self, parent=None, name="InputDialog", modal=0):
     inputValidated = pyqtSignal()
 
     def __init__(self, parent=None, name="InputDialog", modal=0):
@@ -97,7 +105,7 @@ class InputDialog(GenericDialog):
         icon.addFile(os.path.join(iconfolder,"steelbar.png"))
         self.__ui.cmbMeshType.setItemIcon(meshTypeIndex, icon)
         self.MESHTYPE_ICONS[meshTypeIndex] = icon
         icon.addFile(os.path.join(iconfolder,"steelbar.png"))
         self.__ui.cmbMeshType.setItemIcon(meshTypeIndex, icon)
         self.MESHTYPE_ICONS[meshTypeIndex] = icon
-        
+
         # The click on btnSmeshObject (signal clicked() emitted by the
         # button btnSmeshObject) is connected to the slot
         # onSelectSmeshObject, etc ...
         # The click on btnSmeshObject (signal clicked() emitted by the
         # button btnSmeshObject) is connected to the slot
         # onSelectSmeshObject, etc ...
@@ -113,7 +121,11 @@ class InputDialog(GenericDialog):
         self.__ui.tblListInput.horizontalHeader().setStretchLastSection(True)
         # Note that the type is not display explicitly in the Qt table
         # because it is specified using an icon on the text of the
         self.__ui.tblListInput.horizontalHeader().setStretchLastSection(True)
         # Note that the type is not display explicitly in the Qt table
         # because it is specified using an icon on the text of the
-        # name item. 
+        # name item.
+
+        # Setup default values for numerical parameters
+        self.__ui.txtParamNbIter.setValue(PARAM_NBITER_DEFAULT_VALUE)
+        self.__ui.txtParamRmaxRmin.setValue(PARAM_RMAXRMIN_DEFAULT_VALUE)
 
         # Note that PADDER does not support group name longer than 8
         # characters. We apply then this limit in the gui field.
 
         # Note that PADDER does not support group name longer than 8
         # characters. We apply then this limit in the gui field.
@@ -135,7 +147,7 @@ class InputDialog(GenericDialog):
             self.__ui.txtSmeshObject.setEnabled(False)
             self.__ui.btnAddInput.setEnabled(False)
         self.__selectedMesh = None
             self.__ui.txtSmeshObject.setEnabled(False)
             self.__ui.btnAddInput.setEnabled(False)
         self.__selectedMesh = None
-        self.__dictInputData = {}
+        self.__dictInputFiles = {}
         self.__nbConcreteMesh = 0
         self.__nbSteelbarMesh = 0
 
         self.__nbConcreteMesh = 0
         self.__nbSteelbarMesh = 0
 
@@ -166,7 +178,7 @@ class InputDialog(GenericDialog):
             self.__selectedMesh = None
             return
 
             self.__selectedMesh = None
             return
 
-        self.smeshStudyTool.updateStudy(studyedit.getActiveStudyId())
+        self.smeshStudyTool.updateStudy()
         self.__selectedMesh = self.smeshStudyTool.getMeshObjectFromSObject(mySObject)
         if CORBA.is_nil(self.__selectedMesh):
             self.__ui.txtSmeshObject.setText("The selected object is not a mesh")
         self.__selectedMesh = self.smeshStudyTool.getMeshObjectFromSObject(mySObject)
         if CORBA.is_nil(self.__selectedMesh):
             self.__ui.txtSmeshObject.setText("The selected object is not a mesh")
@@ -228,26 +240,26 @@ class InputDialog(GenericDialog):
         """
         # if the entry already exists, we remove it to replace by a
         # new one
         """
         # if the entry already exists, we remove it to replace by a
         # new one
-        if self.__dictInputData.has_key(meshName):
+        if meshName in self.__dictInputFiles:
             self.__delInputFromMap(meshName)
             self.__delInputFromMap(meshName)
-        
+
         inputData = InputData()
         inputData.meshName   = meshName
         inputData.meshObject = meshObject
         inputData.meshType   = meshType
         inputData.groupName  = groupName
         # The key of the map is the mesh name
         inputData = InputData()
         inputData.meshName   = meshName
         inputData.meshObject = meshObject
         inputData.meshType   = meshType
         inputData.groupName  = groupName
         # The key of the map is the mesh name
-        self.__dictInputData[meshName] = inputData
+        self.__dictInputFiles[meshName] = inputData
         if inputData.meshType == InputData.MESHTYPES.CONCRETE:
             self.__nbConcreteMesh += 1
         else:
             self.__nbSteelbarMesh += 1
 
         if inputData.meshType == InputData.MESHTYPES.CONCRETE:
             self.__nbConcreteMesh += 1
         else:
             self.__nbSteelbarMesh += 1
 
-        print inputData
-        print "meshType = ",inputData.meshType
-        print "nb concrete mesh ",self.__nbConcreteMesh
-        print "nb steelbar mesh ",self.__nbSteelbarMesh
-            
+        print(inputData)
+        print("meshType = ",inputData.meshType)
+        print("nb concrete mesh ",self.__nbConcreteMesh)
+        print("nb steelbar mesh ",self.__nbSteelbarMesh)
+
 
     def onDeleteInput(self):
         """
 
     def onDeleteInput(self):
         """
@@ -267,47 +279,65 @@ class InputDialog(GenericDialog):
     def __delInputFromMap(self, meshName):
         """
         This function removes the specified entry from the internal
     def __delInputFromMap(self, meshName):
         """
         This function removes the specified entry from the internal
-        map (for data management purpose) 
+        map (for data management purpose)
         """
         """
-        inputData = self.__dictInputData.pop(meshName)
+        inputData = self.__dictInputFiles.pop(meshName)
         if inputData.meshType == InputData.MESHTYPES.CONCRETE:
             self.__nbConcreteMesh -= 1
         else:
             self.__nbSteelbarMesh -= 1
 
         if inputData.meshType == InputData.MESHTYPES.CONCRETE:
             self.__nbConcreteMesh -= 1
         else:
             self.__nbSteelbarMesh -= 1
 
-        print inputData
-        print "nb concrete mesh ",self.__nbConcreteMesh
-        print "nb steelbar mesh ",self.__nbSteelbarMesh
+        print(inputData)
+        print("nb concrete mesh ",self.__nbConcreteMesh)
+        print("nb steelbar mesh ",self.__nbSteelbarMesh)
 
 
 
 
-    def setData(self, listInputData=[]):
+    def setData(self, dictInputData={}):
         """
         This function fills the dialog widgets with values provided by
         the specified data list.
         """
         self.clear()
         """
         This function fills the dialog widgets with values provided by
         the specified data list.
         """
         self.clear()
-        for inputData in listInputData:
+        if INPUTDATA_KEY_FILES in dictInputData:
+            listInputData = dictInputData["meshfiles"]
+            for inputData in listInputData:
 
 
-            meshName   = inputData.meshName
-            meshObject = inputData.meshObject
-            meshType   = inputData.meshType
-            groupName  = inputData.groupName
-            
-            self.__addInputInGui(meshName, meshObject, meshType, groupName)
-            self.__addInputInMap(meshName, meshObject, meshType, groupName)
+                meshName = inputData.meshName
+                meshObject = inputData.meshObject
+                meshType = inputData.meshType
+                groupName = inputData.groupName
 
 
-            if not DEBUG_MODE:
-                self.onSelectSmeshObject()
+                self.__addInputInGui(meshName, meshObject, meshType, groupName)
+                self.__addInputInMap(meshName, meshObject, meshType, groupName)
+
+                if not DEBUG_MODE:
+                    self.onSelectSmeshObject()
+
+        if INPUTDATA_KEY_PARAM in dictInputData:
+            dictInputParameters = dictInputData[INPUTDATA_KEY_PARAM]
+            if PARAM_KEY_NBITER in dictInputParameters:
+                self.__ui.txtParamNbIter.setValue(dictInputParameters[PARAM_KEY_NBITER])
+            if PARAM_KEY_RMAXRMIN in dictInputParameters:
+                self.__ui.txtParamRminRmax.setValue(dictInputParameters[PARAM_KEY_RMAXRMIN])
 
     def getData(self):
         """
         This function returns a list of InputData that corresponds to
         the data in the dialog widgets of the current dialog.
         """
 
     def getData(self):
         """
         This function returns a list of InputData that corresponds to
         the data in the dialog widgets of the current dialog.
         """
+        # Get the list of mesh files
         # Note that the values() function returns a copy of the list
         # of values.
         # Note that the values() function returns a copy of the list
         # of values.
-        return self.__dictInputData.values()
-        
+        dictInputData={}
+        dictInputData[INPUTDATA_KEY_FILES] = self.__dictInputFiles.values()
+
+        # Get the list of additionnal parameters
+        dictInputParameters = {}
+        dictInputParameters[PARAM_KEY_NBITER] = self.__ui.txtParamNbIter.value()
+        dictInputParameters[PARAM_KEY_RMAXRMIN] = self.__ui.txtParamRmaxRmin.value()
+        dictInputData[INPUTDATA_KEY_PARAM] = dictInputParameters
+        return dictInputData
+
     def checkData(self):
         """
         This function checks if the data are valid, from the dialog
     def checkData(self):
         """
         This function checks if the data are valid, from the dialog
@@ -315,7 +345,7 @@ class InputDialog(GenericDialog):
         """
         if self.__nbConcreteMesh == 0 and self.__nbSteelbarMesh == 0:
             self.checkDataMessage = "You must define at least one mesh (CONCRETE or STEELBAR)"
         """
         if self.__nbConcreteMesh == 0 and self.__nbSteelbarMesh == 0:
             self.checkDataMessage = "You must define at least one mesh (CONCRETE or STEELBAR)"
-            return False        
+            return False
         if self.__nbConcreteMesh > 1:
             self.checkDataMessage  = "You define multiple CONCRETE meshes."
             self.checkDataMessage += "You should verify first that your version of PADDER support this configuration."
         if self.__nbConcreteMesh > 1:
             self.checkDataMessage  = "You define multiple CONCRETE meshes."
             self.checkDataMessage += "You should verify first that your version of PADDER support this configuration."
@@ -339,7 +369,7 @@ def TEST_InputDialog():
     dlg=InputDialog()
     dlg.displayAndWait()
     if dlg.wasOk():
     dlg=InputDialog()
     dlg.displayAndWait()
     if dlg.wasOk():
-        print "OK has been pressed"
+        print("OK has been pressed")
 
 def TEST_InputDialog_setData():
     import sys
 
 def TEST_InputDialog_setData():
     import sys
@@ -349,7 +379,7 @@ def TEST_InputDialog_setData():
 
     dlg=InputDialog()
 
 
     dlg=InputDialog()
 
-    from inputdata import InputData
+    from .inputdata import InputData
     inputData = InputData()
     inputData.meshName   = "myMesh"
     inputData.meshObject = None
     inputData = InputData()
     inputData.meshName   = "myMesh"
     inputData.meshObject = None
@@ -357,14 +387,14 @@ def TEST_InputDialog_setData():
     inputData.groupName  = "myGroup"
     listInputData = []
     listInputData.append(inputData)
     inputData.groupName  = "myGroup"
     listInputData = []
     listInputData.append(inputData)
-    
+
     dlg.setData2(listInputData)
     dlg.setData2(listInputData)
-    
+
     dlg.displayAndWait()
     if dlg.wasOk():
     dlg.displayAndWait()
     if dlg.wasOk():
-        print "OK has been pressed"
+        print("OK has been pressed")
         outputListInputData = dlg.getData2()
         outputListInputData = dlg.getData2()
-        print outputListInputData
+        print(outputListInputData)
 
 
 if __name__ == "__main__":
 
 
 if __name__ == "__main__":