-
Notifications
You must be signed in to change notification settings - Fork 1
/
ParamForm.cs
175 lines (167 loc) · 6.04 KB
/
ParamForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ArcSWAT3
{
public partial class ParamForm : Form
{
private GlobalVars gv;
public ParamForm(GlobalVars gv, string SWATEditorDir, string mpiexecDir)
{
InitializeComponent();
this.gv = gv;
this.checkUseMPI.Checked = Directory.Exists(mpiexecDir);
this.MPIBox.Text = mpiexecDir;
this.editorBox.Text = SWATEditorDir;
if (gv is not null)
{
gv.parametersPos = this.Location;
}
}
private void editorButton_Click(object sender, EventArgs e)
{
var title = Utils.trans("Select SWAT Editor directory");
string startDir;
if (editorBox.Text != "")
{
startDir = Path.GetDirectoryName(editorBox.Text);
}
else if (Directory.Exists(gv.SWATExeDir))
{
startDir = Path.GetDirectoryName(gv.SWATExeDir);
}
else
{
startDir = null;
}
folderBrowserDialog1.ShowNewFolderButton = false;
folderBrowserDialog1.Description = title;
if (startDir is not null)
{
folderBrowserDialog1.SelectedPath = startDir;
}
// Show the FolderBrowserDialog.
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
editorBox.Text = folderBrowserDialog1.SelectedPath;
}
}
private void MPIButton_Click(object sender, EventArgs e)
{
var title = Utils.trans("Select MPI bin directory");
string startDir;
if (MPIBox.Text != "")
{
startDir = Path.GetDirectoryName(MPIBox.Text);
}
else if (File.Exists(gv.mpiexecPath))
{
startDir = Path.GetDirectoryName(gv.mpiexecPath);
}
else
{
startDir = null;
}
folderBrowserDialog1.ShowNewFolderButton = false;
folderBrowserDialog1.Description = title;
if (startDir is not null)
{
folderBrowserDialog1.SelectedPath = startDir;
}
// Show the FolderBrowserDialog.
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
MPIBox.Text = folderBrowserDialog1.SelectedPath;
}
}
private void saveButton_Click(object sender, EventArgs e)
{
var SWATEditorDir = this.editorBox.Text;
if (SWATEditorDir == "" || !Directory.Exists(SWATEditorDir))
{
Utils.error("Please select the SWAT editor directory", gv.isBatch);
return;
}
var editor = Parameters._SWATEDITOR;
var SWATEditorPath = Utils.join(SWATEditorDir, editor);
if (!File.Exists(SWATEditorPath))
{
Utils.error(String.Format("Cannot find the SWAT editor {0}", SWATEditorPath), gv.isBatch);
return;
}
var dbProjTemplate = Utils.join(Utils.join(SWATEditorDir, Parameters._DBDIR), Parameters._DBPROJ);
if (!File.Exists(dbProjTemplate))
{
Utils.error(String.Format("Cannot find the default project database {0}", dbProjTemplate), gv.isBatch);
return;
}
var dbRefTemplate = Utils.join(Utils.join(SWATEditorDir, Parameters._DBDIR), Parameters._DBREF);
if (!File.Exists(dbRefTemplate))
{
Utils.error(String.Format("Cannot find the SWAT parameter database {0}", dbRefTemplate), gv.isBatch);
return;
}
var TauDEMDir = Utils.join(SWATEditorDir, Parameters._TAUDEM539DIR);
if (!Directory.Exists(TauDEMDir))
{
Utils.error(String.Format("Cannot find the TauDEM directory {0}", TauDEMDir), gv.isBatch);
return;
}
string mpiexecPath = "";
if (this.checkUseMPI.Checked)
{
var mpiexecDir = this.MPIBox.Text;
if (mpiexecDir == "" || !Directory.Exists(mpiexecDir))
{
Utils.error("Please select the MPI bin directory", gv.isBatch);
return;
}
var mpiexec = Parameters._MPIEXEC;
mpiexecPath = Utils.join(mpiexecDir, mpiexec);
if (!File.Exists(mpiexecPath))
{
Utils.error(String.Format("Cannot find mpiexec program {0}", mpiexecPath), gv.isBatch);
return;
}
}
// no problems - save parameters
if (this.gv is not null)
{
this.gv.dbProjTemplate = dbProjTemplate;
this.gv.dbRefTemplate = dbRefTemplate;
this.gv.TauDEMDir = TauDEMDir;
this.gv.mpiexecPath = mpiexecPath;
this.gv.SWATEditorPath = SWATEditorPath;
}
this.Close();
}
private void cancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void checkUseMPI_CheckedChanged(object sender, EventArgs e)
{
if (this.checkUseMPI.Checked)
{
this.MPIBox.Enabled = true;
this.MPIButton.Enabled = true;
this.MPILabel.Enabled = true;
}
else
{
this.MPIBox.Enabled = false;
this.MPIButton.Enabled = false;
this.MPILabel.Enabled = false;
}
}
}
}