3 #sys.path.append(os.path.join(os.environ['MED3HOME'], '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))
37 def get_hydro_regions( calc_case_name ):
38 aStudyId = salome.myStudyId
39 doc = HYDROPy.HYDROData_Document.Document( aStudyId )
40 case = doc.FindObjectByName( calc_case_name )
41 if isinstance(case, HYDROPy.HYDROData_CalculationCase):
42 regions = case.GetRegions()
46 regions_names.append( str(rname) )
48 #shape_groups = case.GetGeometryGroups()
49 #for sg in shape_groups:
50 #sgname = sg.GetName()
51 #regions_names.append( sgname )
57 def get_selected_calc_case():
58 ind = SalomePyQt.SalomePyQt.getObjectBrowser().selectionModel().selectedIndexes()
59 aStudyId = salome.myStudyId
60 doc = HYDROPy.HYDROData_Document.Document( aStudyId )
63 name = i.data().toString()
64 case = doc.FindObjectByName( name )
65 if isinstance(case, HYDROPy.HYDROData_CalculationCase):
69 class InterpolzDlg( QtGui.QDialog ):
70 def __init__(self, parent = None):
71 QtGui.QDialog.__init__( self, parent )
73 uic.loadUi( p+'/interpolz.ui', self )
74 self.setWindowTitle( 'Generate interpolz script' )
75 self.connect( SalomePyQt.SalomePyQt.getObjectBrowser(), QtCore.SIGNAL("selectionChanged()"), self.onSelectionChanged )
76 self.connect( self.btnOutputPath, QtCore.SIGNAL( "clicked()" ), self.onOutputFile )
77 self.connect( self.btnMEDFile, QtCore.SIGNAL( "clicked()" ), self.onMEDFile )
78 self.connect( self.CalcCase, QtCore.SIGNAL( "textChanged( const QString& )" ), self.onCalcCaseChanged )
79 self.connect( self.MEDFile, QtCore.SIGNAL( "textChanged( const QString& )" ), self.onMEDChanged )
80 self.UndefZ.setRange( -100000, 100000 )
81 self.UndefZ.setValue( -9999 )
82 self.InterpMethod.addItem( "Interpolation at the nearest point" )
83 self.InterpMethod.addItem( "Linear interpolation on a cloud triangulation" )
84 self.connect( self.ApplyClose, QtCore.SIGNAL( "clicked()" ), self.onApplyClose )
85 self.connect( self.Apply, QtCore.SIGNAL( "clicked()" ), self.onApply )
86 self.connect( self.Close, QtCore.SIGNAL( "clicked()" ), self.onClose )
87 self.connect( self.Help, QtCore.SIGNAL( "clicked()" ), self.onHelp )
89 def onSelectionChanged( self ):
90 calc_case_name = get_selected_calc_case()
91 if calc_case_name is not None:
92 self.CalcCase.setText( calc_case_name )
94 def onOutputFile( self ):
95 caption = "Python file"
97 f = QtGui.QFileDialog.getSaveFileName( self, caption, ".", mask )
99 self.OutputPath.setText( f )
101 def onMEDFile( self ):
104 f = QtGui.QFileDialog.getOpenFileName( self, caption, ".", mask )
105 if f!=None and f!="":
106 self.MEDFile.setText( f )
108 def onCalcCaseChanged( self ):
109 self.regions = get_hydro_regions( str(self.CalcCase.text()) )
112 def onMEDChanged( self ):
113 self.med_groups = get_med_groups( str(self.MEDFile.text()) )
114 #print self.med_groups
115 n = len( self.med_groups )
116 self.Groups.setRowCount( n )
117 for i in range( 0, n ):
118 if self.Groups.item( i, 0 ) is None:
119 self.Groups.setItem( i, 0, QtGui.QTableWidgetItem() )
120 self.Groups.setItem( i, 1, QtGui.QTableWidgetItem() )
121 self.Groups.item( i, 0 ).setText( self.med_groups[i] )
123 cb = QtGui.QComboBox( self.Groups )
125 for r in self.regions:
127 self.Groups.setCellWidget( i, 1, cb )
129 def onApplyClose( self ):
134 path = str(self.OutputPath.text())
135 calc_case = str(self.CalcCase.text())
136 med_file = str(self.MEDFile.text())
137 med_groups_regions = {}
138 for i in range( 0, self.Groups.rowCount() ):
139 med_group = str( self.Groups.item( i, 0 ).text() )
140 hydro_reg = str( self.Groups.cellWidget( i, 1 ).currentText() )
141 if len(med_group)>0 and len(hydro_reg)>0 and hydro_reg != 'None':
142 med_groups_regions[med_group] = hydro_reg
143 z_undef = self.UndefZ.value()
144 interp = str(self.InterpMethod.currentText())
148 msg = "Please input the output path"
149 elif len(calc_case)==0:
150 msg = "Please choose the calculation case"
151 elif len(med_file)==0:
152 msg = "Please choose the MED file"
153 elif len(med_groups_regions)==0:
154 msg = "Please fill groups table"
156 msg = "Please choose interpolation method"
161 if "Linear" in interp:
163 generate( path, calc_case, med_file, med_groups_regions, z_undef, iinterp )
164 msg = "InterpolZ script is successfully generated"
167 QtGui.QMessageBox.information( self, "", msg )
173 """Shows help page"""
176 <h2>Interpolz dialog</h2>
178 This dialog is a tool for automation the writing of the script <b>interpolz.py</b>.
180 <h3>Calculation case</h3>
181 The name of the calculation case. It can be filled automatically on the base of selection or can be input by user.
184 The path for the output, i.e. the path of the target script interpolz.
187 The path to MED file where MED groups are extracted.
190 The interpolation method (interpolation at the nearest point and linear interpolation from a triangulation of the cloud of points).
193 The Z value for nodes outside the regions.
196 The table with MED groups and regions names.
198 When the data is input, the user clicks on "Apply" or "Apply and Close" button to perform the script generation.
200 QtGui.QMessageBox.about(self, self.tr("About boundary conditions dialog"), msg);
203 if __name__=='__main__':