try:
med_file_mesh = MEDFileMesh.New(file_path)
groups = list(med_file_mesh.getGroupsOnSpecifiedLev(-1))
- except:
+ except Exception as e:
+ print e.what()
return []
-
+
return groups
-"""Get preset name corresponding to the given values of LIHBOR, LIUBOR, LIVBOR and LITBOR"""
+"""Get preset name corresponding to the given values of LIHBOR, LIUBOR, LIVBOR and LITBOR"""
def get_preset_name(presets, lihbor, liubor, livbor, litbor):
name = ''
-
+
for preset_name in presets:
values = presets[preset_name]
-
+
p_lihbor = values[0]
p_liubor = values[1]
p_livbor = values[2]
if not p_livbor or p_livbor == livbor:
if not p_litbor or p_litbor == litbor:
name = preset_name
-
+
return name
-"""Convert string to integer, return None if conversion is not possible"""
+"""Convert string to integer, return None if conversion is not possible"""
def get_int(str):
value = None
-
+
if str.isdigit():
value = int(str)
-
+
return value
-"""Item delegate for LIHBOR, LIUBOR, LIVBOR and LITBOR columns"""
+"""Item delegate for LIHBOR, LIUBOR, LIVBOR and LITBOR columns"""
- class ValueDelegate(QtGui.QStyledItemDelegate):
+ class ValueDelegate(QStyledItemDelegate):
-
+
def __init__(self, parent = None):
- QtGui.QStyledItemDelegate.__init__(self, parent)
+ QStyledItemDelegate.__init__(self, parent)
-
+
def createEditor(self, parent, option, index):
- line_edit = QtGui.QLineEdit(parent)
+ line_edit = QLineEdit(parent)
-
+
- validator = QtGui.QIntValidator(parent)
+ validator = QIntValidator(parent)
validator.setRange(0, 6)
-
+
line_edit.setValidator(validator)
return line_edit
-
+
def setEditorData(self, editor, index):
- value, is_ok = index.model().data(index, QtCore.Qt.EditRole).toInt()
-
- if is_ok:
- editor.setText(str(value))
+ value = index.model().data(index, Qt.EditRole)
+ if value.isdigit():
+ editor.setText(value)
else:
editor.setText('')
-
+
def setModelData(self, editor, model, index):
- model.setData(index, editor.text(), QtCore.Qt.EditRole)
+ model.setData(index, editor.text(), Qt.EditRole)
def updateEditorGeometry(self, editor, option, index):
editor.setGeometry(option.rect)
-
-"""Boundary conditions definition dialog"""
+
+"""Boundary conditions definition dialog"""
- class BoundaryConditionsDialog(QtGui.QDialog):
+ class BoundaryConditionsDialog(QDialog):
def __init__(self, parent = None, modal = 0):
- QtGui.QDialog.__init__(self, parent)
+ QDialog.__init__(self, parent)
uic.loadUi(os.path.join(hydro_solver_root, 'BndConditionsDialog.ui'), self )
-
+
# Connections
self.medFileButton.clicked.connect(self.on_med_file_browse)
self.bndConditionsFileButton.clicked.connect(self.on_bnd_file_browse)
item = self.boundaryConditionsTable.item(row, 4)
if item:
litbor = get_int(str(item.text()))
-
+
preset_name = get_preset_name(self.presets, lihbor, liubor, livbor, litbor)
-
+
combo = self.boundaryConditionsTable.cellWidget(row, 0)
- if isinstance(combo, QtGui.QComboBox):
+ if isinstance(combo, QComboBox):
ind = combo.findText(preset_name)
if ind >= 0:
combo.setCurrentIndex(ind)
"""Select MED file"""
def on_med_file_browse(self):
# Get file path
- file_path = QtGui.QFileDialog.getOpenFileName(self, self.tr("Open MED file"), "", self.tr("MED files (*.med)"))
+ file_path, filt = QFileDialog.getOpenFileName(self, self.tr("Open MED file"), "", self.tr("MED files (*.med)"))
if not file_path:
return
-
+
# Get names of groups on edges
groups = get_med_groups_on_edges(str(file_path))
-
+
if len(groups) > 0:
# Display the path
self.medFileEdit.setText(file_path)
# Update table
self.set_groups(groups)
else:
- QtGui.QMessageBox.warning(self, self.tr("Warning"), self.tr("Can't get group names from the selected MED file."))
+ QMessageBox.warning(self, self.tr("Warning"), self.tr("Can't get group names from the selected MED file."))
-
+
"""Select boundary conditions file"""
def on_bnd_file_browse(self):
- file_path = QtGui.QFileDialog.getOpenFileName(self, self.tr("Open boundary conditions file"))
+ file_path, filt = QFileDialog.getOpenFileName(self, self.tr("Open boundary conditions file"))
-
+
if file_path:
self.bndConditionsFileEdit.setText(file_path)
reader = boundaryConditions.BoundaryConditionReader(file_path)
read_errors = reader.errors
if len( read_errors ) > 0:
msg = "\n".join(read_errors)
- QtGui.QMessageBox.warning(self, self.tr("Warning"), msg)
+ QMessageBox.warning(self, self.tr("Warning"), msg)
-
+
if len(self.input_conditions) > 0:
self.update_table()
else:
- QtGui.QMessageBox.warning(self, self.tr("Warning"), self.tr("No conditions have been read from the file."))
+ QMessageBox.warning(self, self.tr("Warning"), self.tr("No conditions have been read from the file."))
-
+
"""Called on preset selection in the first column of the table"""
def on_preset_changed(self):
combo = self.sender()
-
+
preset = str(combo.currentText())
-
+
if preset and self.presets.has_key(preset):
values = self.presets[preset]
- row_nb = combo.property(ROW_PROPERTY_NAME)
-
- if row_nb >= 0 and row_nb < self.boundaryConditionsTable.rowCount():
+ row_nb, is_ok = combo.property(ROW_PROPERTY_NAME).toInt()
+
+ if is_ok and row_nb >= 0 and row_nb < self.boundaryConditionsTable.rowCount():
++ #row_nb = combo.property(ROW_PROPERTY_NAME)
++
++ #if row_nb >= 0 and row_nb < self.boundaryConditionsTable.rowCount():
lihbor = values[0]
liubor = values[1]
livbor = values[2]
litbor = values[3]
-
+
if lihbor:
self.boundaryConditionsTable.item(row_nb, 1).setText(str(lihbor))
-
+
if liubor:
- self.boundaryConditionsTable.item(row_nb, 2).setText(str(liubor))
-
+ self.boundaryConditionsTable.item(row_nb, 2).setText(str(liubor))
+
if livbor:
- self.boundaryConditionsTable.item(row_nb, 3).setText(str(livbor))
-
+ self.boundaryConditionsTable.item(row_nb, 3).setText(str(livbor))
+
if litbor:
- self.boundaryConditionsTable.item(row_nb, 4).setText(str(litbor))
-
+ self.boundaryConditionsTable.item(row_nb, 4).setText(str(litbor))
+
"""Define result file path"""
def on_result_file_browse(self):
- file_path = QtGui.QFileDialog.getSaveFileName(self, self.tr("Select output file path"))
+ file_path, filt = QFileDialog.getSaveFileName(self, self.tr("Select output file path"))
+ #print file_path
if file_path:
self.resultBndConditionsFileEdit.setText(file_path)
-
+
"""Set groups list"""
def set_groups(self, groups):
self.boundaryConditionsTable.setRowCount(0)
# Add row
row_nb = self.boundaryConditionsTable.rowCount()
self.boundaryConditionsTable.insertRow(row_nb)
-
+
# 'Preset' column
- combo = QtGui.QComboBox(self)
+ combo = QComboBox(self)
combo.addItem('')
if len(self.presets) > 0:
combo.addItems(self.presets.keys())
-
+
combo.setProperty(ROW_PROPERTY_NAME, row_nb)
-
+
combo.currentIndexChanged.connect(self.on_preset_changed)
-
+
self.boundaryConditionsTable.setCellWidget(row_nb, 0, combo)
-
+
# 'LIHBOR' column
- self.boundaryConditionsTable.setItem(row_nb, 1, QtGui.QTableWidgetItem(''))
+ self.boundaryConditionsTable.setItem(row_nb, 1, QTableWidgetItem(''))
-
+
# 'LIUBOR' column
- self.boundaryConditionsTable.setItem(row_nb, 2, QtGui.QTableWidgetItem(''))
+ self.boundaryConditionsTable.setItem(row_nb, 2, QTableWidgetItem(''))
-
+
# 'LIVBOR' column
- self.boundaryConditionsTable.setItem(row_nb, 3, QtGui.QTableWidgetItem(''))
+ self.boundaryConditionsTable.setItem(row_nb, 3, QTableWidgetItem(''))
-
+
# 'LITBOR' column
- self.boundaryConditionsTable.setItem(row_nb, 4, QtGui.QTableWidgetItem(''))
+ self.boundaryConditionsTable.setItem(row_nb, 4, QTableWidgetItem(''))
-
+
# 'Group' column
- item = QtGui.QTableWidgetItem(group)
+ item = QTableWidgetItem(group)
font = item.font()
font.setBold(True)
item.setFont(font)
- item.setFlags(QtCore.Qt.ItemIsEnabled)
+ item.setFlags(Qt.ItemIsEnabled)
self.boundaryConditionsTable.setItem(row_nb, 5, item)
-
+
self.update_table()
-
+
"""Update conditions data in the table from the conditions input file"""
def update_table(self):
is_updated = False
self.boundaryConditionsTable.item(row_nb, 2).setText(liubor)
self.boundaryConditionsTable.item(row_nb, 3).setText(livbor)
self.boundaryConditionsTable.item(row_nb, 4).setText(litbor)
-
+
is_updated = True
-
+
if not is_updated and nb_rows > 0 and len(self.input_conditions) > 0:
- QtGui.QMessageBox.information(self, self.tr("Information"), self.tr("No one group name from the MED file is presented in the input list of conditions."))
+ QMessageBox.information(self, self.tr("Information"), self.tr("No one group name from the MED file is presented in the input list of conditions."))
-
+
"""Get output file path"""
def get_output_path(self):
path = self.bndConditionsFileEdit.text()
"""Check if the input data is valid"""
def is_valid(self):
is_ok = False
-
+
if self.boundaryConditionsTable.rowCount() < 1:
- QtGui.QMessageBox.critical(self, self.tr("Insufficient input data"), self.tr("Boundary conditions list is empty."))
- elif self.get_output_path().isEmpty():
- QtGui.QMessageBox.critical(self, self.tr("Insufficient input data"), self.tr("Output file path is empty."))
+ QMessageBox.critical(self, self.tr("Insufficient input data"), self.tr("Boundary conditions list is empty."))
+ elif len(self.get_output_path())==0:
+ QMessageBox.critical(self, self.tr("Insufficient input data"), self.tr("Output file path is empty."))
else:
has_empty_cells = False
for row_nb in xrange(0, self.boundaryConditionsTable.rowCount()):
if (not lihbor) or (not liubor) or (not livbor) or (not litbor):
has_empty_cells = True
break
-
+
if has_empty_cells:
- QtGui.QMessageBox.critical(self, self.tr("Insufficient input data"), self.tr("Table has empty cell(s)."))
+ QMessageBox.critical(self, self.tr("Insufficient input data"), self.tr("Table has empty cell(s)."))
else:
is_ok = True
-
+
return is_ok
-
+
"""Shows help page"""
def on_help(self):
msg = """
from generate_interpolz import generate
def get_med_groups( file_path ):
- #print "get_med_groups", file_path
+ print "get_med_groups", file_path
try:
- meshes = MEDLoader.MEDLoader_GetMeshNames(file_path)
+ meshes = MEDLoader.GetMeshNames(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.GetMeshGroupsNames(file_path, mesh1))
+ groups = list(MEDLoader.MEDLoader_GetMeshGroupsNames(file_path, mesh1))
-
+ print 'Found groups:', groups
except:
+ print 'No groups found'
return []
return groups
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.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()
if calc_case_name is not None:
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()) )
self.onMEDChanged()
-
+
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 )
self.Groups.setCellWidget( i, 1, cb )
msg = "Please fill groups table"
elif len(interp)==0:
msg = "Please choose interpolation method"
-
+
result = False
if len(msg)==0:
- generate( path, calc_case, med_file, med_groups_regions, z_undef, interp )
+ iinterp = 0
+ 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 ):
- self.close()
+ self.close()
"""Shows help page"""
def onHelp( self ):