forked from alcorlin/ResedUI
/
RiverSimulationForm.cs
426 lines (364 loc) · 16 KB
/
RiverSimulationForm.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
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.Windows.Forms;
using System.IO;
using System.Xml;
namespace RiverSimulationApplication
{
public partial class RiverSimulationForm : Form
{
public RiverSimulationForm()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
LoginForm form = new LoginForm();
if (DialogResult.OK != form.ShowDialog())
{
this.Close();
}
UpdateStatus();
}
private void eToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void waterModelingBtn_Click(object sender, EventArgs e)
{
if(!RiverSimulationProfile.profile.IsWaterModelingReady())
{
MessageBox.Show("請先完成前置設定", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
WaterModelingForm form = new WaterModelingForm();
if (DialogResult.OK == form.ShowDialog())
{
RiverSimulationProfile.profile.waterModelingFinished = true;
}
UpdateStatus();
}
private void simulationModuleBtn_Click(object sender, EventArgs e)
{
SimulationModuleForm form = new SimulationModuleForm();
if (DialogResult.OK == form.ShowDialog())
{
RiverSimulationProfile.profile.simulationModuleFinished = true;
}
UpdateStatus();
}
private void importBtn_Click(object sender, EventArgs e)
{
if (!RiverSimulationProfile.profile.IsImportReady())
{
MessageBox.Show("請先完成前置設定", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
ImportForm form = new ImportForm();
if (DialogResult.OK == form.ShowDialog())
{
RiverSimulationProfile.profile.importFinished = true;
}
UpdateStatus();
}
private void movableBedBtn_Click(object sender, EventArgs e)
{
if(!RiverSimulationProfile.profile.IsMovableBedReady())
{
MessageBox.Show("請先完成前置設定", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
MovableBedForm form = new MovableBedForm();
if (DialogResult.OK == form.ShowDialog())
{
RiverSimulationProfile.profile.movableBedFinished = true;
}
UpdateStatus();
}
private void initialConditionsBtn_Click(object sender, EventArgs e)
{
if(!RiverSimulationProfile.profile.IsInitialConditionsReady())
{
MessageBox.Show("請先完成前置設定", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
InitialConditionsForm form = new InitialConditionsForm();
if (DialogResult.OK == form.ShowDialog())
{
RiverSimulationProfile.profile.initialConditionsFinished = true;
}
UpdateStatus();
}
private void boundaryConditionsBtn_Click(object sender, EventArgs e)
{
if(!RiverSimulationProfile.profile.IsBoundaryConditionsReady())
{
MessageBox.Show("請先完成前置設定", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
BoundaryConditionsForm form = new BoundaryConditionsForm();
if (DialogResult.OK == form.ShowDialog())
{
RiverSimulationProfile.profile.boundaryConditionsFinished = true;
}
UpdateStatus();
}
private void UpdateStatus()
{
RiverSimulationProfile p = RiverSimulationProfile.profile;;
if(p == null)
{
return;
}
//RiverSimulationProfile p = RiverSimulationProfile.profile;
Color FinishedButton = Color.LimeGreen;
Color ReadyButton = Color.Gold;
Color DisableButton = Color.FromArgb(255, 174, 201); //20141117 客製化
sampleFinishedBtn.BackColor = FinishedButton;
sampleReadyBtn.BackColor = ReadyButton;
sampleDisableBtn.BackColor = DisableButton;
//importBtn.BackColor = (p.IsImportFinished()) ? FinishedButton : (p.IsImportReady()) ? ReadyButton : DisableButton;
//simulationModuleBtn.BackColor = (p.IsSimulationModuleFinished()) ? FinishedButton : (p.IsSimulationModuleReady()) ? ReadyButton : DisableButton;
simulationModuleBtn.BackColor = (p.IsSimulationModuleFinished()) ? FinishedButton : (p.IsSimulationModuleReady()) ? ReadyButton : DisableButton;
importBtn.BackColor = (p.IsImportFinished()) ? FinishedButton : (p.IsImportReady()) ? ReadyButton : DisableButton;
waterModelingBtn.BackColor = (p.IsWaterModelingFinished()) ? FinishedButton : (p.IsWaterModelingReady()) ? ReadyButton : DisableButton;
movableBedBtn.BackColor = (p.IsMovableBedFinished()) ? FinishedButton : (p.IsMovableBedReady()) ? ReadyButton : DisableButton;
//movableBedBtn.Enabled = p.IsMovableBedReady();
initialConditionsBtn.BackColor = (p.IsInitialConditionsFinished()) ? FinishedButton : (p.IsInitialConditionsReady()) ? ReadyButton : DisableButton;
//initialConditionsBtn.Enabled = p.IsInitialConditionsReady();
boundaryConditionsBtn.BackColor = (p.IsBoundaryConditionsFinished()) ? FinishedButton : (p.IsBoundaryConditionsReady()) ? ReadyButton : DisableButton;
//boundaryConditionsBtn.Enabled = p.IsBoundaryConditionsReady();
runSimulationBtn.BackColor = (p.IsRunSimulationFinished()) ? FinishedButton : (p.IsRunSimulationReady()) ? ReadyButton : DisableButton;
//runSimulationBtn.Enabled = p.IsRunSimulationReady();
simulationResultBtn.BackColor = (p.IsSimulationResultFinished()) ? FinishedButton : (p.IsSimulationResultReady()) ? ReadyButton : DisableButton;
//simulationResultBtn.Enabled = p.IsSimulationResultReady();
}
private void runSimulationBtn_Click(object sender, EventArgs e)
{
if (!RiverSimulationProfile.profile.IsRunSimulationReady())
{
String errStr = "尚有參數尚未完成:\r\n" +
"水理參數 - 物理參數尚未設定!";
MessageBox.Show(errStr, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
RunSimulationForm form = new RunSimulationForm();
if (DialogResult.OK == form.ShowDialog())
{
}
RiverSimulationProfile.profile.runSimulationFinished = true;
UpdateStatus();
}
SolidBrush lineBrush = new SolidBrush(Color.Blue);
Pen p = new Pen(Color.Black, 1);
Pen pp = new Pen(Color.Red, 3);
private void RiverSimulationForm_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
//int lineWidth = 3;
Button up, dn, lf, rt;
//line from importBtn to simulationModuleBtn
up = simulationModuleBtn;
dn = importBtn;
g.DrawLine(p, up.Left + up.Width / 2, up.Bottom,
up.Left + up.Width / 2, dn.Top);
//line under simulationModuleBtn
up = importBtn;
dn = waterModelingBtn;
g.DrawLine(p, up.Left + up.Width / 2, up.Bottom,
up.Left + up.Width / 2, (dn.Top + up.Bottom) / 2);
//lines upper waterModelingBtn and movableBedBtn
up = importBtn;
dn = waterModelingBtn;
lf = waterModelingBtn;
rt = movableBedBtn;
Point[] pts =
{
new Point(lf.Left + lf.Width / 2, lf.Top),
new Point(lf.Left + lf.Width / 2, (dn.Top + up.Bottom) / 2),
new Point(rt.Left + rt.Width / 2, (dn.Top + up.Bottom) / 2),
new Point(rt.Left + rt.Width / 2, rt.Top),
};
g.DrawLines(p, pts);
//lines under waterModelingBtn and movableBedBtn
up = waterModelingBtn;
dn = initialConditionsBtn;
lf = waterModelingBtn;
rt = movableBedBtn;
Point[] pts2 =
{
new Point(lf.Left + lf.Width / 2, lf.Bottom),
new Point(lf.Left + lf.Width / 2, (dn.Top + 2 * up.Bottom) / 3),
new Point(rt.Left + rt.Width / 2, (dn.Top + 2 * up.Bottom) / 3),
new Point(rt.Left + rt.Width / 2, rt.Bottom),
};
g.DrawLines(p, pts2);
//lines between waterModelingBtn and initialConditionsBtn
up = waterModelingBtn;
dn = initialConditionsBtn;
lf = initialConditionsBtn;
rt = boundaryConditionsBtn;
g.DrawLine(p, (lf.Left + rt.Left + rt.Width) / 2, (dn.Top + 2 * up.Bottom) / 3,
(lf.Left + rt.Left + rt.Width) / 2, (up.Bottom + 2 * dn.Top) / 3);
//lines upper initialConditionsBtn and boundaryConditionsBtn
up = waterModelingBtn;
dn = initialConditionsBtn;
lf = initialConditionsBtn;
rt = boundaryConditionsBtn;
Point[] pts3 =
{
new Point(lf.Left + lf.Width / 2, initialConditionsBtn.Top),
new Point(lf.Left + lf.Width / 2, (up.Bottom + 2 * dn.Top) / 3),
new Point(rt.Left + rt.Width / 2, (up.Bottom + 2 * dn.Top) / 3),
new Point(rt.Left + rt.Width / 2, rt.Top),
};
g.DrawLines(p, pts3);
//lines under initialConditionsBtn and boundaryConditionsBtn
up = initialConditionsBtn;
dn = runSimulationBtn;
lf = initialConditionsBtn;
rt = boundaryConditionsBtn;
Point[] pts4 =
{
new Point(lf.Left + lf.Width / 2, up.Bottom),
new Point(lf.Left + lf.Width / 2, (up.Bottom + dn.Top) / 2),
new Point(rt.Left + rt.Width / 2, (up.Bottom + dn.Top) / 2),
new Point(rt.Left + rt.Width / 2, rt.Bottom),
};
g.DrawLines(p, pts4);
//line upper runSimulationBtn
up = initialConditionsBtn;
dn = runSimulationBtn;
lf = initialConditionsBtn;
rt = boundaryConditionsBtn;
g.DrawLine(p, dn.Left + dn.Width / 2, (up.Bottom + dn.Top) / 2,
dn.Left + dn.Width / 2, dn.Top);
////line from dataVerifyBtn to runSimulationBtn
//up = dataVerifyBtn;
//dn = runSimulationBtn;
//g.DrawLine(p, up.Left + up.Width / 2, up.Bottom,
// up.Left + up.Width / 2, dn.Top);
//lines between runSimulationBtn and simulationResultBtn
up = runSimulationBtn;
dn = simulationResultBtn;
g.DrawLine(p, up.Left + up.Width / 2, up.Bottom,
up.Left + up.Width / 2, dn.Top);
}
private void runSimulationResultBtn_Click(object sender, EventArgs e)
{
if (!RiverSimulationProfile.profile.IsRunSimulationReady())
{
MessageBox.Show("請先完成前置設定", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
private void aboutMnuItem_Click(object sender, EventArgs e)
{
AboutForm form = new AboutForm();
if (DialogResult.OK == form.ShowDialog())
{
}
}
private void exitMnuItem_Click(object sender, EventArgs e)
{
FunctionlUtility.SaveProject(RiverSimulationProfile.profile);
this.Close();
}
private void feedMnuItem_Click(object sender, EventArgs e)
{
FeedbackForm form = new FeedbackForm();
if (DialogResult.OK == form.ShowDialog())
{
}
}
private void descriptionMnuItem_Click(object sender, EventArgs e)
{
InputForm dlg = new InputForm();
dlg.Text = "檔案敘述";
dlg.desc.Text = "請輸入檔案敘述";
if (File.Exists(Program.GetDescriptionFileFullPath()))
{
XmlDocument desc = new XmlDocument();
desc.Load(Program.GetDescriptionFileFullPath());
XmlNode files = desc.SelectSingleNode(@"Files/" + Program.projectFileName);
if (files != null)
{
XmlElement element = (XmlElement)files;
dlg.inputTxt.Text = element.GetAttribute("Text");
}
}
else
{
dlg.inputTxt.Text = "";
}
if (DialogResult.OK != dlg.ShowDialog())
{
return;
}
if (File.Exists(Program.GetDescriptionFileFullPath()))
{ //更新說明檔
XmlDocument desc = new XmlDocument();
desc.Load(Program.GetDescriptionFileFullPath());
XmlNode files = desc.SelectSingleNode(@"Files"); //選擇節點
XmlElement f = files.SelectSingleNode(Program.projectFileName) as XmlElement;
if (f != null)
{ //更新欄位
f.SetAttribute("Text", dlg.inputTxt.Text);
}
else
{ //新增欄位
XmlElement f2 = desc.CreateElement(Program.projectFileName);
f2.SetAttribute("Text", dlg.inputTxt.Text);
files.AppendChild(f2);
}
desc.Save(Program.GetDescriptionFileFullPath());
}
else
{ //建立說明檔
XmlDocument doc = new XmlDocument();
XmlNode files = doc.CreateElement(@"Files");//選擇節點
doc.AppendChild(files);
XmlElement description = doc.CreateElement(Program.projectFileName);
description.SetAttribute("Text", dlg.inputTxt.Text); //設定屬性
files.AppendChild(description);
doc.Save(Program.GetDescriptionFileFullPath());
}
}
private void userManualMenuItem_Click(object sender, EventArgs e)
{
Utility.ShellExecute(Environment.CurrentDirectory + "\\Manual.pdf");
}
private void RiverSimulationForm_FormClosed(object sender, FormClosedEventArgs e)
{
FunctionlUtility.SaveProject(RiverSimulationProfile.profile);
}
private void newMnuItem_Click(object sender, EventArgs e)
{
FunctionlUtility.SaveProject(RiverSimulationProfile.profile);
if (!FunctionlUtility.NewProjectFile(this, Program.GetProjectFullPath()))
{
return;
}
UpdateStatus();
}
private void openMnuItem_Click(object sender, EventArgs e)
{
FunctionlUtility.SaveProject(RiverSimulationProfile.profile);
if (!FunctionlUtility.OpenProjectFile(this, Program.GetProjectFileFullPath()))
{
return;
}
UpdateStatus();
}
private void saveMnuItem_Click(object sender, EventArgs e)
{
FunctionlUtility.SaveProject(RiverSimulationProfile.profile);
MessageBox.Show("檔案儲存完成。", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}