Salome HOME
change version number
[modules/hydrosolver.git] / src / salome_hydro / interpolz_gui.py
index 2f5c5bc4e36a81c8cb0e79f0b8e4877bb1ee0991..978c1f13bd8ced35675f51fa2de68326471d2bda 100644 (file)
@@ -1,16 +1,22 @@
 
 import sys, os
-#sys.path.append(os.path.join(os.environ['MED3HOME'], 'lib/python2.7/site-packages/med'))
+#sys.path.append(os.path.join(os.environ['MEDFILE_ROOT_DIR'], 'lib/python2.7/site-packages/med'))
+#sys.path.append(os.path.join(os.environ['MEDFICHIER_INSTALL_DIR'], 'lib/python2.7/site-packages/med'))
 hydro_solver_root = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', 'python2.7', 'site-packages', 'salome', 'salome', 'hydro')
 #sys.path.append(hydro_solver_root)
 
 import salome
 salome.salome_init()
 
-import MEDLoader
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+#import MEDLoader
 import HYDROPy
 
-from PyQt4 import QtCore, QtGui, uic
+from PyQt5.QtWidgets import QDialog, QFileDialog, QTableWidgetItem, QComboBox, QMessageBox
+from PyQt5 import uic
 
 import SalomePyQt
 import libSALOME_Swig
@@ -21,16 +27,27 @@ from generate_interpolz import generate
 def get_med_groups( file_path ):
     #print "get_med_groups", file_path
     try:
-        meshes = MEDLoader.MEDLoader_GetMeshNames(file_path)
+        #meshes = MEDLoader.GetMeshNames(file_path)
+        (meshes, status) = smesh.CreateMeshesFromMED(file_path)
     except:
+        print 'No meshes found'
         return []
     if len(meshes)==0:
+        print 'No mesh found'
         return []
     mesh1 = meshes[0]
+    print 'Found mesh:', mesh1
     try:
-        groups = list(MEDLoader.MEDLoader_GetMeshGroupsNames(file_path, mesh1))
-
+        #groups = list(MEDLoader.GetMeshGroupsNames(file_path, mesh1))
+        grps = mesh1.GetGroups()
+        groups = [grp.GetName() for grp in grps if grp.GetType() == SMESH.NODE]
+        if len(groups) == 0:
+          print "Problem! There are no groups of nodes in the mesh!"
+          print "Please create at least the groups of nodes corresponding to each region of the HYDRO case"
+          return []
+        print 'Found groups:', groups
     except:
+        print 'No groups found'
         return []
     return groups
 
@@ -45,10 +62,10 @@ def get_hydro_regions( calc_case_name ):
         rname = r.GetName()
         regions_names.append( str(rname) )
 
-      #shape_groups = case.GetGeometryGroups()
-      #for sg in shape_groups:
-          #sgname = sg.GetName()
-          #regions_names.append( sgname )
+#       shape_groups = case.GetGeometryGroups()
+#       for sg in shape_groups:
+#           sgname = sg.GetName()
+#           regions_names.append( sgname )
 
       return regions_names
     else:
@@ -60,31 +77,31 @@ def get_selected_calc_case():
     doc = HYDROPy.HYDROData_Document.Document( aStudyId )
     for i in ind:
         if i.column()==0:
-            name = i.data().toString()
+            name = str(i.data())
             case = doc.FindObjectByName( name )
             if isinstance(case, HYDROPy.HYDROData_CalculationCase):
                 return name
     return None
 
-class InterpolzDlg( QtGui.QDialog ):
+class InterpolzDlg( QDialog ):
     def __init__(self, parent = None):
-        QtGui.QDialog.__init__( self, parent )
+        QDialog.__init__( self, parent )
         p = hydro_solver_root
         uic.loadUi( p+'/interpolz.ui', self )
         self.setWindowTitle( 'Generate interpolz script' )
-        self.connect( SalomePyQt.SalomePyQt.getObjectBrowser(), QtCore.SIGNAL("selectionChanged()"), self.onSelectionChanged )
-        self.connect( self.btnOutputPath, QtCore.SIGNAL( "clicked()" ), self.onOutputFile )
-        self.connect( self.btnMEDFile, QtCore.SIGNAL( "clicked()" ), self.onMEDFile )
-        self.connect( self.CalcCase, QtCore.SIGNAL( "textChanged( const QString& )" ), self.onCalcCaseChanged )
-        self.connect( self.MEDFile, QtCore.SIGNAL( "textChanged( const QString& )" ), self.onMEDChanged )
+        SalomePyQt.SalomePyQt.getObjectBrowser().selectionChanged.connect(self.onSelectionChanged)
+        self.btnOutputPath.clicked.connect(self.onOutputFile)
+        self.btnMEDFile.clicked.connect(self.onMEDFile)
+        self.CalcCase.textChanged.connect(self.onCalcCaseChanged)
+        self.MEDFile.textChanged.connect(self.onMEDChanged)
         self.UndefZ.setRange( -100000, 100000 )
         self.UndefZ.setValue( -9999 )
         self.InterpMethod.addItem( "Interpolation at the nearest point" )
         self.InterpMethod.addItem( "Linear interpolation on a cloud triangulation" )
-        self.connect( self.ApplyClose, QtCore.SIGNAL( "clicked()" ), self.onApplyClose )
-        self.connect( self.Apply, QtCore.SIGNAL( "clicked()" ), self.onApply )
-        self.connect( self.Close, QtCore.SIGNAL( "clicked()" ), self.onClose )
-        self.connect( self.Help, QtCore.SIGNAL( "clicked()" ), self.onHelp )
+        self.ApplyClose.clicked.connect(self.onApplyClose)
+        self.Apply.clicked.connect(self.onApply)
+        self.Close.clicked.connect(self.onClose)
+        self.Help.clicked.connect(self.onHelp)
 
     def onSelectionChanged( self ):
         calc_case_name = get_selected_calc_case()
@@ -94,16 +111,16 @@ class InterpolzDlg( QtGui.QDialog ):
     def onOutputFile( self ):
       caption = "Python file"
       mask = "*.py"
-      f = QtGui.QFileDialog.getSaveFileName( self, caption, ".", mask )
-      if f!=None and f!="":
-        self.OutputPath.setText( f )
+      fname, filt = QFileDialog.getSaveFileName( self, caption, ".", mask )
+      if fname!=None and fname!="":
+        self.OutputPath.setText( fname )
 
     def onMEDFile( self ):
       caption = "MED file"
       mask = "*.med"
-      f = QtGui.QFileDialog.getOpenFileName( self, caption, ".", mask )
-      if f!=None and f!="":
-        self.MEDFile.setText( f )
+      fname, filt = QFileDialog.getOpenFileName( self, caption, ".", mask )
+      if fname!=None and fname!="":
+        self.MEDFile.setText( fname )
 
     def onCalcCaseChanged( self ):
       self.regions = get_hydro_regions( str(self.CalcCase.text()) )
@@ -111,16 +128,16 @@ class InterpolzDlg( QtGui.QDialog ):
 
     def onMEDChanged( self ):
       self.med_groups = get_med_groups( str(self.MEDFile.text()) )
-      #print self.med_groups
+      print self.med_groups
       n = len( self.med_groups )
       self.Groups.setRowCount( n )
       for i in range( 0, n ):
         if self.Groups.item( i, 0 ) is None:
-          self.Groups.setItem( i, 0, QtGui.QTableWidgetItem() )
-          self.Groups.setItem( i, 1, QtGui.QTableWidgetItem() )
+          self.Groups.setItem( i, 0, QTableWidgetItem() )
+          self.Groups.setItem( i, 1, QTableWidgetItem() )
         self.Groups.item( i, 0 ).setText( self.med_groups[i] )
 
-        cb = QtGui.QComboBox( self.Groups )
+        cb = QComboBox( self.Groups )
         cb.addItem( 'None' )
         for r in self.regions:
           cb.addItem( r )
@@ -138,7 +155,7 @@ class InterpolzDlg( QtGui.QDialog ):
         for i in range( 0, self.Groups.rowCount() ):
             med_group = str( self.Groups.item( i, 0 ).text() )
             hydro_reg = str( self.Groups.cellWidget( i, 1 ).currentText() )
-            if len(med_group)>0 and len(hydro_reg)>0 and hydro_reg != 'None':
+            if len(med_group)>0 and len(hydro_reg)>0 and hydro_reg != 'None' :
                 med_groups_regions[med_group] = hydro_reg
         z_undef = self.UndefZ.value()
         interp = str(self.InterpMethod.currentText())
@@ -158,13 +175,13 @@ class InterpolzDlg( QtGui.QDialog ):
         result = False
         if len(msg)==0:
             iinterp = 0
-            if "Linear" in interp:
-              iinterp =1
+            if 'Linear' in interp:
+              iinterp = 1
             generate( path, calc_case, med_file, med_groups_regions, z_undef, iinterp )
             msg = "InterpolZ script is successfully generated"
             result = True
 
-        QtGui.QMessageBox.information( self, "", msg )
+        QMessageBox.information( self, "", msg )
         return result
 
     def onClose( self ):
@@ -197,7 +214,7 @@ class InterpolzDlg( QtGui.QDialog ):
 
         When the data is input, the user clicks on "Apply" or "Apply and Close" button to perform the script generation.
         """
-        QtGui.QMessageBox.about(self, self.tr("About boundary conditions dialog"), msg);
+        QMessageBox.about(self, self.tr("About boundary conditions dialog"), msg);
 
 
 if __name__=='__main__':