3 #sys.path.append(os.path.join(os.environ['MEDFILE_ROOT_DIR'], 'lib/python2.7/site-packages/med'))
4 #sys.path.append(os.path.join(os.environ['MEDFICHIER_INSTALL_DIR'], 'lib/python2.7/site-packages/med'))
5 hydro_solver_root = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', 'python2.7', 'site-packages', 'salome', 'salome', 'hydro')
6 #sys.path.append(hydro_solver_root)
12 from salome.smesh import smeshBuilder
13 smesh = smeshBuilder.New(salome.myStudy)
18 from PyQt5.QtWidgets import QDialog, QFileDialog, QTableWidgetItem, QComboBox, QMessageBox
23 salome_gui = libSALOME_Swig.SALOMEGUI_Swig()
25 from generate_interpolz import generate
27 def get_med_groups( file_path ):
28 #print "get_med_groups", file_path
30 #meshes = MEDLoader.GetMeshNames(file_path)
31 (meshes, status) = smesh.CreateMeshesFromMED(file_path)
33 print 'No meshes found'
39 print 'Found mesh:', mesh1
41 #groups = list(MEDLoader.GetMeshGroupsNames(file_path, mesh1))
42 grps = mesh1.GetGroups()
43 groups = [grp.GetName() for grp in grps if grp.GetType() == SMESH.FACE]
45 print "Problem! There are no groups of faces in the mesh!"
46 print "Please create at least the groups of faces corresponding to each region of the HYDRO case"
48 print 'Found groups:', groups
50 print 'No groups found'
54 def get_hydro_regions( calc_case_name ):
55 aStudyId = salome.myStudyId
56 doc = HYDROPy.HYDROData_Document.Document( aStudyId )
57 case = doc.FindObjectByName( calc_case_name )
58 if isinstance(case, HYDROPy.HYDROData_CalculationCase):
59 regions = case.GetRegions()
63 regions_names.append( str(rname) )
65 # shape_groups = case.GetGeometryGroups()
66 # for sg in shape_groups:
67 # sgname = sg.GetName()
68 # regions_names.append( sgname )
74 def get_selected_calc_case():
75 ind = SalomePyQt.SalomePyQt.getObjectBrowser().selectionModel().selectedIndexes()
76 aStudyId = salome.myStudyId
77 doc = HYDROPy.HYDROData_Document.Document( aStudyId )
81 case = doc.FindObjectByName( name )
82 if isinstance(case, HYDROPy.HYDROData_CalculationCase):
86 class InterpolzDlg( QDialog ):
87 def __init__(self, parent = None):
88 QDialog.__init__( self, parent )
90 uic.loadUi( p+'/interpolz.ui', self )
91 self.setWindowTitle( 'Generate interpolz script' )
92 SalomePyQt.SalomePyQt.getObjectBrowser().selectionChanged.connect(self.onSelectionChanged)
93 self.btnOutputPath.clicked.connect(self.onOutputFile)
94 self.btnMEDFile.clicked.connect(self.onMEDFile)
95 self.CalcCase.textChanged.connect(self.onCalcCaseChanged)
96 self.MEDFile.textChanged.connect(self.onMEDChanged)
97 self.UndefZ.setRange( -100000, 100000 )
98 self.UndefZ.setValue( -9999 )
99 self.InterpMethod.addItem( "Interpolation at the nearest point" )
100 self.InterpMethod.addItem( "Linear interpolation on a cloud triangulation" )
101 self.ApplyClose.clicked.connect(self.onApplyClose)
102 self.Apply.clicked.connect(self.onApply)
103 self.Close.clicked.connect(self.onClose)
104 self.Help.clicked.connect(self.onHelp)
106 def onSelectionChanged( self ):
107 calc_case_name = get_selected_calc_case()
108 if calc_case_name is not None:
109 self.CalcCase.setText( calc_case_name )
111 def onOutputFile( self ):
112 caption = "Python file"
114 fname, filt = QFileDialog.getSaveFileName( self, caption, ".", mask )
115 if fname!=None and fname!="":
116 self.OutputPath.setText( fname )
118 def onMEDFile( self ):
121 fname, filt = QFileDialog.getOpenFileName( self, caption, ".", mask )
122 if fname!=None and fname!="":
123 self.MEDFile.setText( fname )
125 def onCalcCaseChanged( self ):
126 self.regions = get_hydro_regions( str(self.CalcCase.text()) )
129 def onMEDChanged( self ):
130 self.med_groups = get_med_groups( str(self.MEDFile.text()) )
131 print self.med_groups
132 n = len( self.med_groups )
133 self.Groups.setRowCount( n )
134 for i in range( 0, n ):
135 if self.Groups.item( i, 0 ) is None:
136 self.Groups.setItem( i, 0, QTableWidgetItem() )
137 self.Groups.setItem( i, 1, QTableWidgetItem() )
138 self.Groups.item( i, 0 ).setText( self.med_groups[i] )
140 cb = QComboBox( self.Groups )
142 for r in self.regions:
144 self.Groups.setCellWidget( i, 1, cb )
146 def onApplyClose( self ):
151 path = str(self.OutputPath.text())
152 calc_case = str(self.CalcCase.text())
153 med_file = str(self.MEDFile.text())
154 med_groups_regions = {}
155 for i in range( 0, self.Groups.rowCount() ):
156 med_group = str( self.Groups.item( i, 0 ).text() )
157 hydro_reg = str( self.Groups.cellWidget( i, 1 ).currentText() )
158 if len(med_group)>0 and len(hydro_reg)>0 and hydro_reg != 'None' :
159 med_groups_regions[med_group] = hydro_reg
160 z_undef = self.UndefZ.value()
161 interp = str(self.InterpMethod.currentText())
165 msg = "Please input the output path"
166 elif len(calc_case)==0:
167 msg = "Please choose the calculation case"
168 elif len(med_file)==0:
169 msg = "Please choose the MED file"
170 elif len(med_groups_regions)==0:
171 msg = "Please fill groups table"
173 msg = "Please choose interpolation method"
178 if 'Linear' in interp:
180 generate( path, calc_case, med_file, med_groups_regions, z_undef, iinterp )
181 msg = "InterpolZ script is successfully generated"
184 QMessageBox.information( self, "", msg )
190 """Shows help page"""
193 <h2>Interpolz dialog</h2>
195 This dialog is a tool for automation the writing of the script <b>interpolz.py</b>.
197 <h3>Calculation case</h3>
198 The name of the calculation case. It can be filled automatically on the base of selection or can be input by user.
201 The path for the output, i.e. the path of the target script interpolz.
204 The path to MED file where MED groups are extracted.
207 The interpolation method (interpolation at the nearest point and linear interpolation from a triangulation of the cloud of points).
210 The Z value for nodes outside the regions.
213 The table with MED groups and regions names.
215 When the data is input, the user clicks on "Apply" or "Apply and Close" button to perform the script generation.
217 QMessageBox.about(self, self.tr("About boundary conditions dialog"), msg);
220 if __name__=='__main__':