| | |
| | | using SimuTools.Tools; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Data; |
| | | using System.Drawing; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.IO; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace SimuTools |
| | | { |
| | | public partial class FrmMain : Form |
| | | { |
| | | private bool flag; |
| | | |
| | | public FrmMain() |
| | | { |
| | | InitializeComponent(); |
| | |
| | | |
| | | private void btnTerrainPath_Click(object sender, EventArgs e) |
| | | { |
| | | OpenFileDialog dialog = new OpenFileDialog(); |
| | | dialog.Filter = "Tif files(*.tif)|*.tif|Tiff files (*.tiff)|*.tiff"; |
| | | dialog.RestoreDirectory = true; |
| | | |
| | | string path = this.txtTerrainPath.Text.Trim(); |
| | | if (File.Exists(path)) |
| | | { |
| | | dialog.InitialDirectory = Path.GetDirectoryName(path); |
| | | } |
| | | |
| | | if (dialog.ShowDialog() == DialogResult.OK) |
| | | { |
| | | this.txtTerrainPath.Text = dialog.FileName; |
| | | } |
| | | } |
| | | |
| | | private void btnWaterPath_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | selectFolder(this.txtWaterPath, "水面"); |
| | | } |
| | | |
| | | private void btnFlowPath_Click(object sender, EventArgs e) |
| | | { |
| | | selectFolder(this.txtFlowPath, "流速"); |
| | | } |
| | | |
| | | private void btnOutPath_Click(object sender, EventArgs e) |
| | | { |
| | | selectFolder(this.txtOutPath, "输出"); |
| | | } |
| | | |
| | | private void selectFolder(TextBox tb, string title) |
| | | { |
| | | using (FolderBrowserDialog dialog = new FolderBrowserDialog()) |
| | | { |
| | | string path = tb.Text.Trim(); |
| | | if (Directory.Exists(path)) |
| | | { |
| | | dialog.SelectedPath = path; |
| | | } |
| | | |
| | | dialog.Description = "请选择" + title + "目录..."; |
| | | if (dialog.ShowDialog() == DialogResult.OK) |
| | | { |
| | | tb.Text = dialog.SelectedPath; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void btnRun_Click(object sender, EventArgs e) |
| | | { |
| | | string terrainFile = this.txtTerrainPath.Text.Trim(); |
| | | string waterPath = this.txtWaterPath.Text.Trim(); |
| | | string flowPath = this.txtFlowPath.Text.Trim(); |
| | | string outPath = this.txtOutPath.Text.Trim(); |
| | | |
| | | if (!File.Exists(terrainFile)) |
| | | { |
| | | ShowErr("地形文件,要求必须存在!"); |
| | | return; |
| | | } |
| | | if (!Directory.Exists(waterPath) || !Directory.Exists(flowPath) || !Directory.Exists(outPath)) |
| | | { |
| | | ShowErr("水面、流速和输出目录,要求必须存在!"); |
| | | return; |
| | | } |
| | | |
| | | if (flag) return; |
| | | try |
| | | { |
| | | flag = true; |
| | | LogOut.Info("开始运行 >>"); |
| | | Tools.Handle.Run(terrainFile, waterPath, flowPath, outPath); |
| | | LogOut.Info("运行结束 >>"); |
| | | flag = false; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | flag = false; |
| | | LogOut.Error(ex.StackTrace); |
| | | ShowErr("运行出错:" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | private void ShowErr(string message) |
| | | { |
| | | MessageBox.Show(message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); |
| | | } |
| | | } |
| | | } |