3 sys.path.append(os.path.join(os.environ['MEDFILE_ROOT_DIR'], 'lib/python2.7/site-packages/med'))
4 hydro_solver_root = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', 'python2.7', 'site-packages', 'salome', 'salome', 'hydro')
5 sys.path.append(hydro_solver_root)
13 from PyQt4 import QtCore, QtGui, uic
17 salome_gui = libSALOME_Swig.SALOMEGUI_Swig()
19 from generate_interpolz import generate
21 def get_med_groups( file_path ):
22 #print "get_med_groups", file_path
24 meshes = MEDLoader.MEDLoader_GetMeshNames(file_path)
31 groups = list(MEDLoader.MEDLoader_GetMeshGroupsNames(file_path, mesh1))
36 def get_hydro_regions( calc_case_name ):
37 aStudyId = salome.myStudyId
38 doc = HYDROPy.HYDROData_Document.Document( aStudyId )
39 case = doc.FindObjectByName( calc_case_name )
40 if isinstance(case, HYDROPy.HYDROData_CalculationCase):
41 regions = case.GetRegions()
45 regions_names.append( str(rname) )
47 shape_groups = case.GetGeometryGroups()
48 for sg in shape_groups:
50 regions_names.append( sgname )
56 def get_selected_calc_case():
57 ind = SalomePyQt.SalomePyQt.getObjectBrowser().selectionModel().selectedIndexes()
58 aStudyId = salome.myStudyId
59 doc = HYDROPy.HYDROData_Document.Document( aStudyId )
62 name = i.data().toString()
63 case = doc.FindObjectByName( name )
64 if isinstance(case, HYDROPy.HYDROData_CalculationCase):
68 class InterpolzDlg( QtGui.QDialog ):
69 def __init__(self, parent = None):
70 QtGui.QDialog.__init__( self, parent )
72 uic.loadUi( p+'/interpolz.ui', self )
73 self.setWindowTitle( 'Generate interpolz script' )
74 self.connect( SalomePyQt.SalomePyQt.getObjectBrowser(), QtCore.SIGNAL("selectionChanged()"), self.onSelectionChanged )
75 self.connect( self.btnOutputPath, QtCore.SIGNAL( "clicked()" ), self.onOutputFile )
76 self.connect( self.btnMEDFile, QtCore.SIGNAL( "clicked()" ), self.onMEDFile )
77 self.connect( self.CalcCase, QtCore.SIGNAL( "textChanged( const QString& )" ), self.onCalcCaseChanged )
78 self.connect( self.MEDFile, QtCore.SIGNAL( "textChanged( const QString& )" ), self.onMEDChanged )
79 self.UndefZ.setRange( -100000, 100000 )
80 self.UndefZ.setValue( -9999 )
81 self.InterpMethod.addItem( "Interpolation at the nearest point" )
82 self.connect( self.ApplyClose, QtCore.SIGNAL( "clicked()" ), self.onApplyClose )
83 self.connect( self.Apply, QtCore.SIGNAL( "clicked()" ), self.onApply )
84 self.connect( self.Close, QtCore.SIGNAL( "clicked()" ), self.onClose )
85 self.connect( self.Help, QtCore.SIGNAL( "clicked()" ), self.onHelp )
87 def onSelectionChanged( self ):
88 calc_case_name = get_selected_calc_case()
89 if calc_case_name is not None:
90 self.CalcCase.setText( calc_case_name )
92 def onOutputFile( self ):
93 caption = "Python file"
95 f = QtGui.QFileDialog.getSaveFileName( self, caption, ".", mask )
97 self.OutputPath.setText( f )
99 def onMEDFile( self ):
102 f = QtGui.QFileDialog.getOpenFileName( self, caption, ".", mask )
103 if f!=None and f!="":
104 self.MEDFile.setText( f )
106 def onCalcCaseChanged( self ):
107 self.regions = get_hydro_regions( str(self.CalcCase.text()) )
110 def onMEDChanged( self ):
111 self.med_groups = get_med_groups( str(self.MEDFile.text()) )
112 #print self.med_groups
113 n = len( self.med_groups )
114 self.Groups.setRowCount( n )
115 for i in range( 0, n ):
116 if self.Groups.item( i, 0 ) is None:
117 self.Groups.setItem( i, 0, QtGui.QTableWidgetItem() )
118 self.Groups.setItem( i, 1, QtGui.QTableWidgetItem() )
119 self.Groups.item( i, 0 ).setText( self.med_groups[i] )
121 cb = QtGui.QComboBox( self.Groups )
122 for r in self.regions:
124 self.Groups.setCellWidget( i, 1, cb )
126 def onApplyClose( self ):
131 path = str(self.OutputPath.text())
132 calc_case = str(self.CalcCase.text())
133 med_file = str(self.MEDFile.text())
134 med_groups_regions = {}
135 for i in range( 0, self.Groups.rowCount() ):
136 med_group = str( self.Groups.item( i, 0 ).text() )
137 hydro_reg = str( self.Groups.cellWidget( i, 1 ).currentText() )
138 if len(med_group)>0 and len(hydro_reg)>0:
139 med_groups_regions[med_group] = hydro_reg
140 z_undef = self.UndefZ.value()
141 interp = str(self.InterpMethod.currentText())
145 msg = "Please input the output path"
146 elif len(calc_case)==0:
147 msg = "Please choose the calculation case"
148 elif len(med_file)==0:
149 msg = "Please choose the MED file"
150 elif len(med_groups_regions)==0:
151 msg = "Please fill groups table"
153 msg = "Please choose interpolation method"
157 generate( path, calc_case, med_file, med_groups_regions, z_undef, interp )
158 msg = "InterpolZ script is successfully generated"
161 QtGui.QMessageBox.information( self, "", msg )
167 """Shows help page"""
170 <h2>Interpolz dialog</h2>
172 This dialog is a tool for automation the writing of the script <b>interpolz.py</b>.
174 <h3>Calculation case</h3>
175 The name of the calculation case. It can be filled automatically on the base of selection or can be input by user.
178 The path for the output, i.e. the path of the target script interpolz.
181 The path to MED file where MED groups are extracted.
184 The interpolation method (interpolation at the nearest point and linear interpolation from a triangulation of the cloud of points).
187 The Z value for nodes outside the regions.
190 The table with MED groups and regions names.
192 When the data is input, the user clicks on "Apply" or "Apply and Close" button to perform the script generation.
194 QtGui.QMessageBox.about(self, self.tr("About boundary conditions dialog"), msg);
197 if __name__=='__main__':