SET(TEMPLFILES
interpolz.template
+ interpolz_b.template
assignStrickler.template
)
f.write( line )
f.close()
+def generate_B( path, bathy_name, med_file, group_name, z_undef, iinterp ):
+ f = open( path, "w" )
+ tf = open( hydro_solver_root+"/interpolz_b.template", "r" )
+ templ = tf.readlines()
+
+ replace( templ, "<bathy_name_from_dlg>", bathy_name )
+ replace( templ, "<MED_file_path_from_dlg>", med_file )
+ replace( templ, "<MED_Group>", group_name )
+ replace( templ, "<z_undef_value_from_dlg>", z_undef )
+ replace( templ, "<interpolation_method>", iinterp )
+
+ for line in templ:
+ f.write( line )
+ f.close()
if __name__=='__main__':
generate( "test_interpolz.py", "case_1", "mesh.med", {"group_1":"reg_1", "group_2":"reg_2"}, -9999, {"reg_1" : 0, "reg_2": 1} )
<rect>
<x>0</x>
<y>0</y>
- <width>800</width>
- <height>580</height>
+ <width>850</width>
+ <height>651</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
- <item row="0" column="0">
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="1">
- <widget class="QLabel" name="lblCalcCase">
- <property name="text">
- <string>Calculation case:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="2">
- <widget class="QLineEdit" name="CalcCase"/>
- </item>
- </layout>
- </item>
- <item row="1" column="0">
- <widget class="QGroupBox" name="grpPaths">
- <property name="title">
- <string>Paths</string>
- </property>
- <layout class="QGridLayout" name="gridLayout_4">
- <item row="0" column="0">
- <layout class="QGridLayout" name="gridLayout_3">
- <item row="0" column="0">
- <widget class="QLabel" name="lblOutputPath">
- <property name="text">
- <string>Output path:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="2">
- <widget class="QLineEdit" name="OutputPath"/>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="lblMEDFile">
- <property name="text">
- <string>MED file:</string>
- </property>
- </widget>
- </item>
- <item row="1" column="2">
- <widget class="QLineEdit" name="MEDFile"/>
- </item>
- <item row="0" column="3">
- <widget class="QToolButton" name="btnOutputPath">
- <property name="text">
- <string>...</string>
- </property>
- </widget>
- </item>
- <item row="1" column="3">
- <widget class="QToolButton" name="btnMEDFile">
- <property name="text">
- <string>...</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- </item>
<item row="2" column="0">
- <widget class="QGroupBox" name="grpParams">
- <property name="title">
- <string>Parameters</string>
- </property>
- <layout class="QGridLayout" name="gridLayout_6">
- <item row="0" column="0">
- <layout class="QGridLayout" name="gridLayout_5">
- <item row="0" column="0">
- <widget class="QLabel" name="lblUndefZ">
- <property name="text">
- <string>Undefined Z:</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="lblInterpMethod">
- <property name="text">
- <string>Interpolation method:</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QComboBox" name="InterpMethod"/>
- </item>
- <item row="0" column="1">
- <widget class="QDoubleSpinBox" name="UndefZ"/>
- </item>
- </layout>
- </item>
- <item row="1" column="0">
- <widget class="QTableWidget" name="Groups">
- <attribute name="horizontalHeaderDefaultSectionSize">
- <number>250</number>
- </attribute>
- <column>
- <property name="text">
- <string>MED group</string>
- </property>
- </column>
- <column>
- <property name="text">
- <string>Region</string>
- </property>
- </column>
- <column>
- <property name="text">
- <string>Interpolation method</string>
- </property>
- </column>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item row="3" column="0">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</layout>
</widget>
</item>
+ <item row="1" column="0">
+ <widget class="QGroupBox" name="grpPaths">
+ <property name="title">
+ <string>Paths</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_4">
+ <item row="0" column="0">
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="1" column="3">
+ <widget class="QToolButton" name="btnMEDFile">
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3">
+ <widget class="QToolButton" name="btnOutputPath">
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QLineEdit" name="OutputPath"/>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="lblOutputPath">
+ <property name="text">
+ <string>Output path:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QLineEdit" name="MEDFile"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="lblMEDFile">
+ <property name="text">
+ <string>MED file:</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>1</number>
+ </property>
+ <widget class="QWidget" name="caclcase_tab">
+ <attribute name="title">
+ <string>Calculation Case</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="1">
+ <widget class="QLabel" name="lblCalcCase">
+ <property name="text">
+ <string>Calculation case:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QLineEdit" name="CalcCase"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="grpParams">
+ <property name="title">
+ <string>Parameters</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_6">
+ <item row="0" column="0">
+ <layout class="QGridLayout" name="gridLayout_5">
+ <item row="0" column="0">
+ <widget class="QLabel" name="lblUndefZ">
+ <property name="text">
+ <string>Undefined Z:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="lblInterpMethod">
+ <property name="text">
+ <string>Interpolation method:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="InterpMethod"/>
+ </item>
+ <item row="0" column="1">
+ <widget class="QDoubleSpinBox" name="UndefZ"/>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0">
+ <widget class="QTableWidget" name="Groups">
+ <attribute name="horizontalHeaderDefaultSectionSize">
+ <number>250</number>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>MED group</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Region</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Interpolation method</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="bathy_tab">
+ <attribute name="title">
+ <string>Bathymetry</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_14">
+ <item row="2" column="0">
+ <widget class="QGroupBox" name="grpParams_2">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Parameters</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_10">
+ <item row="0" column="0">
+ <layout class="QGridLayout" name="gridLayout_11">
+ <item row="1" column="0">
+ <widget class="QLabel" name="lblInterpMethod_2">
+ <property name="text">
+ <string>Interpolation method:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QDoubleSpinBox" name="UndefZ_B"/>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="lblUndefZ_2">
+ <property name="text">
+ <string>Undefined Z:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="InterpMethod_B"/>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <layout class="QGridLayout" name="gridLayout_13">
+ <item row="0" column="2">
+ <widget class="QComboBox" name="medGroupNames"/>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="lblMedGroup">
+ <property name="text">
+ <string>MED Group:</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="0" column="0">
+ <layout class="QGridLayout" name="gridLayout_9">
+ <item row="0" column="1">
+ <widget class="QLabel" name="lblBathy">
+ <property name="text">
+ <string>Bathymetry:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QLineEdit" name="BathyName"/>
+ </item>
+ </layout>
+ </item>
+ <item row="3" column="0">
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>
--- /dev/null
+# Z interpolation with HYDRO
+from salome.hydrotools.interpolZ import interpolZ_B
+
+# Bathymetry name in HYDRO
+bathyName = <bathy_name_from_dlg>
+
+# MED file 2D(x,y) of the case produced by SMESH
+medFile = <MED_file_path_from_dlg>
+
+# med group name
+med_group_name = <MED_Group>
+
+# Value to use for undefined Z (used to detect problems)
+zUndef = <z_undef_value_from_dlg>
+
+# Interpolation method
+im = <interpolation_method>
+
+# Z interpolation on the bathymetry on the mesh nodes of given group
+statZ = interpolZ_B(bathyName, medFile, med_group_name, zUndef, im)
+
import libSALOME_Swig
salome_gui = libSALOME_Swig.SALOMEGUI_Swig()
-from generate_interpolz import generate
+from generate_interpolz import generate, generate_B
def get_med_groups( file_path ):
#print "get_med_groups", file_path
return name
return None
+def get_selected_bathy():
+ ind = SalomePyQt.SalomePyQt.getObjectBrowser().selectionModel().selectedIndexes()
+ aStudyId = salome.myStudyId
+ doc = HYDROPy.HYDROData_Document.Document( aStudyId )
+ for i in ind:
+ if i.column()==0:
+ name = str(i.data())
+ case = doc.FindObjectByName( name )
+ if isinstance(case, HYDROPy.HYDROData_Bathymetry):
+ return name
+ return None
+
class InterpolzDlg( QDialog ):
def __init__(self, parent = None):
QDialog.__init__( self, parent )
self.btnOutputPath.clicked.connect(self.onOutputFile)
self.btnMEDFile.clicked.connect(self.onMEDFile)
self.CalcCase.textChanged.connect(self.onCalcCaseChanged)
+ #self.BathyName.textChanged.connect(self.onBathyNameChanged)
self.MEDFile.textChanged.connect(self.onMEDChanged)
self.UndefZ.setRange( -100000, 100000 )
self.UndefZ.setValue( -9999 )
+ self.UndefZ_B.setRange( -100000, 100000 )
+ self.UndefZ_B.setValue( -9999 )
+ self.InterpMethod_B.addItem( "Interpolation at the nearest point" )
+ self.InterpMethod_B.addItem( "Linear interpolation on a cloud triangulation" )
self.InterpMethod.addItem( "Interpolation at the nearest point" )
self.InterpMethod.addItem( "Linear interpolation on a cloud triangulation" )
self.InterpMethod.currentIndexChanged.connect(self.onInterpChanged)
self.Close.clicked.connect(self.onClose)
self.Help.clicked.connect(self.onHelp)
self.onSelectionChanged()
+ self.tabWidget.setCurrentIndex(0)
+ self.regions = [] #to avoid attrib error
def onSelectionChanged( self ):
calc_case_name = get_selected_calc_case()
if calc_case_name is not None:
self.CalcCase.setText( calc_case_name )
+ bathy_name = get_selected_bathy()
+ if bathy_name is not None:
+ self.BathyName.setText( bathy_name )
def onOutputFile( self ):
caption = "Python file"
def onCalcCaseChanged( self ):
self.regions = get_hydro_regions( str(self.CalcCase.text()) )
self.onMEDChanged()
+
+ #def onBathyNameChanged( 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
n = len( self.med_groups )
self.Groups.setRowCount( n )
+ self.medGroupNames.clear()
+ for i in range( 0, n ):
+ self.medGroupNames.addItem(self.med_groups[i])
+
for i in range( 0, n ):
if self.Groups.item( i, 0 ) is None:
self.Groups.setItem( i, 0, QTableWidgetItem() )
icb.addItem( 'Linear interpolation on a cloud triangulation' )
self.Groups.setCellWidget( i, 2, icb )
icb.currentIndexChanged.connect(self.onCBInterpChanged)
-
+
+
def onCBInterpChanged( self ):
ind_set = set()
for i in range( 0, self.Groups.rowCount() ):
def onApply( self ):
path = str(self.OutputPath.text())
- calc_case = str(self.CalcCase.text())
med_file = str(self.MEDFile.text())
- med_groups_regions = {}
- regions_interp_method = {}
- for i in range( 0, self.Groups.rowCount() ):
- med_group = str( self.Groups.item( i, 0 ).text() )
- hydro_reg = str( self.Groups.cellWidget( i, 1 ).currentText() )
- if len(med_group)>0 and len(hydro_reg)>0 and hydro_reg != 'None' :
- med_groups_regions[med_group] = hydro_reg
- interp_ind = str( self.Groups.cellWidget( i, 2 ).currentIndex() )
- regions_interp_method[hydro_reg] = interp_ind
- z_undef = self.UndefZ.value()
- #interp = str(self.InterpMethod.currentText())
-
- msg = ""
- if len(path)==0:
- msg = "Please input the output path"
- elif len(calc_case)==0:
- msg = "Please choose the calculation case"
- elif len(med_file)==0:
- msg = "Please choose the MED file"
- elif len(med_groups_regions)==0:
- msg = "Please fill groups table"
- #elif len(interp)==0:
- # msg = "Please choose interpolation method"
-
- result = False
- if len(msg)==0:
- iinterp = 0
- #if 'Linear' in interp:
- # iinterp = 1
- #generate( path, calc_case, med_file, med_groups_regions, z_undef, iinterp )
- generate( path, calc_case, med_file, med_groups_regions, z_undef, regions_interp_method )
- msg = "InterpolZ script is successfully generated"
- result = True
-
- QMessageBox.information( self, "", msg )
- return result
+ print 'current TAB = ', self.tabWidget.currentIndex()
+ if self.tabWidget.currentIndex() == 0: #calc case tab
+ calc_case = str(self.CalcCase.text())
+ med_groups_regions = {}
+ regions_interp_method = {}
+ for i in range( 0, self.Groups.rowCount() ):
+ med_group = str( self.Groups.item( i, 0 ).text() )
+ hydro_reg = str( self.Groups.cellWidget( i, 1 ).currentText() )
+ if len(med_group)>0 and len(hydro_reg)>0 and hydro_reg != 'None' :
+ med_groups_regions[med_group] = hydro_reg
+ interp_ind = str( self.Groups.cellWidget( i, 2 ).currentIndex() )
+ regions_interp_method[hydro_reg] = interp_ind
+ z_undef = self.UndefZ.value()
+ #interp = str(self.InterpMethod.currentText())
+
+ msg = ""
+ if len(path)==0:
+ msg = "Please input the output path"
+ elif len(calc_case)==0:
+ msg = "Please choose the calculation case"
+ elif len(med_file)==0:
+ msg = "Please choose the MED file"
+ elif len(med_groups_regions)==0:
+ msg = "Please fill groups table"
+ #elif len(interp)==0:
+ # msg = "Please choose interpolation method"
+
+ result = False
+ if len(msg)==0:
+ #iinterp = 0
+ #if 'Linear' in interp:
+ # iinterp = 1
+ #generate( path, calc_case, med_file, med_groups_regions, z_undef, iinterp )
+ generate( path, calc_case, med_file, med_groups_regions, z_undef, regions_interp_method )
+ msg = "InterpolZ script is successfully generated"
+ result = True
+
+ QMessageBox.information( self, "", msg )
+ return result
+
+ elif self.tabWidget.currentIndex() == 1: #bathymetry tab
+ bathy_name = str(self.BathyName.text())
+ group_name = str(self.medGroupNames.currentText())
+ interp = str(self.InterpMethod_B.currentText())
+ z_undef = self.UndefZ_B.value()
+
+ msg = ""
+ if len(path)==0:
+ msg = "Please input the output path"
+ elif len(bathy_name)==0:
+ msg = "Please choose the bathymetry"
+ elif len(med_file)==0:
+ msg = "Please choose the MED file"
+ elif len(group_name)==0:
+ msg = "Please choose MED group"
+ elif len(interp)==0:
+ msg = "Please choose interpolation method"
+
+ result = False
+
+ if len(msg)==0:
+ iinterp = 0
+ if 'Linear' in interp:
+ iinterp = 1
+ generate_B( path, bathy_name, med_file, group_name, z_undef, iinterp )
+ msg = "InterpolZ_B script is successfully generated"
+ result = True
+
+ QMessageBox.information( self, "", msg )
+ return result
def onClose( self ):
self.close()