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.InterpMethod.currentIndexChanged.connect(self.onInterpChanged)
102 self.ApplyClose.clicked.connect(self.onApplyClose)
103 self.Apply.clicked.connect(self.onApply)
104 self.Close.clicked.connect(self.onClose)
105 self.Help.clicked.connect(self.onHelp)
107 def onSelectionChanged( self ):
108 calc_case_name = get_selected_calc_case()
109 if calc_case_name is not None:
110 self.CalcCase.setText( calc_case_name )
112 def onOutputFile( self ):
113 caption = "Python file"
115 fname, filt = QFileDialog.getSaveFileName( self, caption, ".", mask )
116 if fname!=None and fname!="":
117 self.OutputPath.setText( fname )
119 def onMEDFile( self ):
122 fname, filt = QFileDialog.getOpenFileName( self, caption, ".", mask )
123 if fname!=None and fname!="":
124 self.MEDFile.setText( fname )
126 def onCalcCaseChanged( self ):
127 self.regions = get_hydro_regions( str(self.CalcCase.text()) )
130 def onMEDChanged( self ):
131 self.med_groups = get_med_groups( str(self.MEDFile.text()) )
132 print self.med_groups
133 n = len( self.med_groups )
134 self.Groups.setRowCount( n )
135 for i in range( 0, n ):
136 if self.Groups.item( i, 0 ) is None:
137 self.Groups.setItem( i, 0, QTableWidgetItem() )
138 self.Groups.setItem( i, 1, QTableWidgetItem() )
139 self.Groups.setItem( i, 2, QTableWidgetItem() )
140 self.Groups.item( i, 0 ).setText( self.med_groups[i] )
142 cb = QComboBox( self.Groups )
144 for r in self.regions:
146 self.Groups.setCellWidget( i, 1, cb )
148 icb = QComboBox( self.Groups )
149 icb.addItem( 'Interpolation at the nearest point' )
150 icb.addItem( 'Linear interpolation on a cloud triangulation' )
151 self.Groups.setCellWidget( i, 2, icb )
152 icb.currentIndexChanged.connect(self.onCBInterpChanged)
154 def onCBInterpChanged( self ):
156 for i in range( 0, self.Groups.rowCount() ):
157 ind_set.add( self.Groups.cellWidget( i, 2 ).currentIndex() )
158 if len(ind_set) == 2:
159 self.InterpMethod.setStyleSheet("QComboBox { background-color: grey; }")
160 elif len(ind_set) == 1:
161 self.InterpMethod.setStyleSheet("")
163 def onInterpChanged( self ):
164 n = self.Groups.rowCount()
165 for i in range( 0, n ):
166 icb = self.Groups.cellWidget(i, 2)
167 icb.setCurrentIndex(self.InterpMethod.currentIndex())
169 def onApplyClose( self ):
174 path = str(self.OutputPath.text())
175 calc_case = str(self.CalcCase.text())
176 med_file = str(self.MEDFile.text())
177 med_groups_regions = {}
178 regions_interp_method = {}
179 for i in range( 0, self.Groups.rowCount() ):
180 med_group = str( self.Groups.item( i, 0 ).text() )
181 hydro_reg = str( self.Groups.cellWidget( i, 1 ).currentText() )
182 if len(med_group)>0 and len(hydro_reg)>0 and hydro_reg != 'None' :
183 med_groups_regions[med_group] = hydro_reg
184 interp_ind = str( self.Groups.cellWidget( i, 2 ).currentIndex() )
185 regions_interp_method[hydro_reg] = interp_ind
186 z_undef = self.UndefZ.value()
187 #interp = str(self.InterpMethod.currentText())
191 msg = "Please input the output path"
192 elif len(calc_case)==0:
193 msg = "Please choose the calculation case"
194 elif len(med_file)==0:
195 msg = "Please choose the MED file"
196 elif len(med_groups_regions)==0:
197 msg = "Please fill groups table"
198 #elif len(interp)==0:
199 # msg = "Please choose interpolation method"
204 #if 'Linear' in interp:
206 #generate( path, calc_case, med_file, med_groups_regions, z_undef, iinterp )
207 generate( path, calc_case, med_file, med_groups_regions, z_undef, regions_interp_method )
208 msg = "InterpolZ script is successfully generated"
211 QMessageBox.information( self, "", msg )
217 """Shows help page"""
220 <h2>Interpolz dialog</h2>
222 This dialog is a tool for automation the writing of the script <b>interpolz.py</b>.
224 <h3>Calculation case</h3>
225 The name of the calculation case. It can be filled automatically on the base of selection or can be input by user.
228 The path for the output, i.e. the path of the target script interpolz.
231 The path to MED file where MED groups are extracted.
234 The interpolation method (interpolation at the nearest point and linear interpolation from a triangulation of the cloud of points).
237 The Z value for nodes outside the regions.
240 The table with MED groups and regions names.
242 When the data is input, the user clicks on "Apply" or "Apply and Close" button to perform the script generation.
244 QMessageBox.about(self, self.tr("About boundary conditions dialog"), msg);
247 if __name__=='__main__':