/
SideInOutFlowSetForm .cs
346 lines (309 loc) · 13.2 KB
/
SideInOutFlowSetForm .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
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;
namespace RiverSimulationApplication
{
public partial class SideInOutFlowSetForm : Form
{
public SideInOutFlowSetForm()
{
InitializeComponent();
}
private void GetTypeAndCount(int index, ref int type, ref int count)
{
type = (sideOutObjects != null && index < sideOutObjects.Length) ? 0 : 1;
count = (type == 0) ? index : index - ((sideOutObjects == null) ? 0 : sideOutObjects.Length);
}
//const int SideFlowNumber = (int)RiverSimulationProfile.SideFlowType.SideFlowSize;
private string title;
//private string[] sideFlowName = new string[SideFlowNumber];
//private int[] sideFlowNum = new int[SideFlowNumber];
public RiverSimulationProfile.SideFlowObject[] sideOutObjects = null;
public RiverSimulationProfile.SideFlowObject[] sideInObjects = null;
//private bool onlySelectMode = false;
//private RiverSimulationProfile.SideFlowType[] typeIndex = null;
public void SetFormMode(string title, RiverSimulationProfile.SideFlowObject[] outObjs, string inName, RiverSimulationProfile.SideFlowObject[] inObjs, string outName)
{
this.title = title;
//從RiverSimulationProfile複製一份資料來編輯
if (outObjs != null && outObjs.Length > 0)
{
sideOutObjects = new RiverSimulationProfile.SideFlowObject[outObjs.Length];
for(int i = 0; i < outObjs.Length; ++i)
{
if (outObjs[i] != null)
{
sideOutObjects[i] = outObjs[i].Clone();
}
else
{
sideOutObjects[i] = new RiverSimulationProfile.SideFlowObject(RiverSimulationProfile.SideFlowType.SideOutFlow);
}
}
}
if (inObjs != null && inObjs.Length > 0)
{
sideInObjects = new RiverSimulationProfile.SideFlowObject[inObjs.Length];
for (int i = 0; i < inObjs.Length; ++i)
{
if (inObjs[i] != null)
{
sideInObjects[i] = inObjs[i].Clone();
}
else
{
sideInObjects[i] = new RiverSimulationProfile.SideFlowObject(RiverSimulationProfile.SideFlowType.SideInFlow);
}
}
}
}
private void StructureSetForm_Load(object sender, EventArgs e)
{
this.Text = title;
if (sideOutObjects != null)
{
for (int i = 0; i < sideOutObjects.Length; ++i)
{
listBox.Items.Add("側出流" + (i + 1).ToString());
}
}
if (sideInObjects != null)
{
for (int i = 0; i < sideInObjects.Length; ++i)
{
listBox.Items.Add("側入流" + (i + 1).ToString());
}
}
listBox.SelectedIndex = 0;
ControllerUtility.InitialGridPictureBoxByProfile(ref mapPicBox, RiverSimulationProfile.profile);
}
private void SetPicBoxGrid(int index, bool alert)
{
int type = 0, count = 0;
GetTypeAndCount(index, ref type, ref count);
mapPicBox.SelectGroup = true;
mapPicBox.SetSelectedGrid((sideOutObjects==null) ? null : SideFlowtUtility.GetSideFlowSets(sideOutObjects), (sideInObjects == null) ? null : SideFlowtUtility.GetSideFlowSets(sideInObjects), null, null, type, count, alert);
if (type == 0)
{
if (sideOutObjects[count].criticalFlowType == RiverSimulationProfile.CriticalFlowType.SubCriticalFlow)
subTypeRdo.Checked = true;
else
superTypeRdo.Checked = true;
}
else
{
if (sideInObjects[count].criticalFlowType == RiverSimulationProfile.CriticalFlowType.SubCriticalFlow)
subTypeRdo.Checked = true;
else
superTypeRdo.Checked = true;
}
}
private void listBox_SelectedIndexChanged(object sender, EventArgs e)
{
SetPicBoxGrid((sender as ListBox).SelectedIndex, false);
}
private void UpdateSelectedGroup(List<Point> pts, bool alert = false)
{
RiverSimulationProfile p = RiverSimulationProfile.profile;
int index = listBox.SelectedIndex;
int type = 0, count = 0;
GetTypeAndCount(index, ref type, ref count);
if (type == 0)
{
sideOutObjects[count].sideFlowPoints = pts;
}
else
{
sideInObjects[count].sideFlowPoints = pts;
}
mapPicBox.SetSelectedGrid((sideOutObjects == null) ? null : SideFlowtUtility.GetSideFlowSets(sideOutObjects), (sideInObjects==null) ? null : SideFlowtUtility.GetSideFlowSets(sideInObjects), null, null, type, count, alert);
}
private bool CheckOverlapping(List<Point> pl, List<Point>[] rg, int count)
{
if (rg == null)
{
return true;
}
if (SideFlowtUtility.IsOverlapping(rg, pl, count))
{
UpdateSelectedGroup(pl, true);
if (DialogResult.Yes == MessageBox.Show("圈選到重覆區域,是否刪減重複範圍(選「否」將放棄此次圈選)", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation))
{
SideFlowtUtility.RemoveOverlapping(ref pl, rg, count);
if (!SideFlowtUtility.IsContinuous(pl))
{
UpdateSelectedGroup(pl, true);
MessageBox.Show("刪減後不是連續區域,請重新選取!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
UpdateSelectedGroup(null);
return false;
}
}
else
{
UpdateSelectedGroup(null);
return false;
}
}
return true;
}
public List<Point> selectedPl = null;
public string selectedValue = "";
private void mapPicBox_SelectedGroupChangedEvent(List<Point> pl)
{
RiverSimulationProfile p = RiverSimulationProfile.profile;
int index = listBox.SelectedIndex;
if (!SideFlowtUtility.TrimToEdge(ref pl, p.inputGrid.GetI, p.inputGrid.GetJ))
{
UpdateSelectedGroup(pl, true);
MessageBox.Show("請圈選邊界!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
UpdateSelectedGroup(null);
return;
}
int type = 0, count = 0;
GetTypeAndCount(index, ref type, ref count);
//檢查連續
if (!SideFlowtUtility.IsContinuous(pl))
{
UpdateSelectedGroup(pl, true);
MessageBox.Show("請圈選連續區域!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
UpdateSelectedGroup(null);
return;
}
//檢查重疊
if(!CheckOverlapping(pl, SideFlowtUtility.GetSideFlowSets(sideOutObjects), count))
{
return;
}
if(!CheckOverlapping(pl, SideFlowtUtility.GetSideFlowSets(sideInObjects), count))
{
return;
}
//最後確認 [20141121]更新客製化需求 回報問題 新增規格
if (DialogResult.OK == MessageBox.Show("請確認以此次圈選範圍取代原先資料。", "確認", MessageBoxButtons.OKCancel, MessageBoxIcon.None))
{
UpdateSelectedGroup(pl);
}
//StructureSetUtility.EditBottomElevation(p, "編輯" + structureName[type] + (1 + count).ToString() + "高程", type, count);
//if (StructureSetUtility.IsOverlapping(rg, pl, index))
//{
// UpdateSelectedGroup(pl, true);
// if (DialogResult.Yes == MessageBox.Show("圈選到重覆區域,是否刪減重複範圍(選「否」將放棄此次圈選)", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation))
// {
// StructureSetUtility.RemoveOverlapping(ref pl, rg, index);
// if (!StructureSetUtility.IsContinuous(pl))
// {
// UpdateSelectedGroup(pl, true);
// MessageBox.Show("刪減後不是連續區域,請重新選取!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// UpdateSelectedGroup(null);
// return;
// }
// }
// else
// {
// UpdateSelectedGroup(null);
// return;
// }
//}
//UpdateSelectedGroup(pl);
}
private void editBtn_Click(object sender, EventArgs e)
{
//var p = RiverSimulationProfile.profile;
int index = listBox.SelectedIndex;
String[] sideObjNames = new String[listBox.Items.Count];
for(int i = 0; i < listBox.Items.Count; ++i)
{
sideObjNames[i] = listBox.Items[i].ToString();
}
SideFlowSetTableForm form = new SideFlowSetTableForm();
form.SetGroupColors(mapPicBox.GetGroupColors());
form.SetColorTable(mapPicBox.GetColorTable());
form.SetSelectionItems(listBox, sideObjNames);
form.SetFormMode("編輯側出/入流", "", sideOutObjects, sideInObjects);
if (DialogResult.OK == form.ShowDialog())
{
//if (index < sideOutObjects.Length)
//{
// //p.boundaryUpVerticalDistribution.SetArrayObject(form.VerticalVelocityDistributionData().Clone());
// sideOutObjects[index].flowData = form.
//}
//else
//{
// sideInObjects[index - sideOutObjects.Length].criticalFlowType = RiverSimulationProfile.CriticalFlowType.SuperCriticalFlow;
//}
}
// SetPicBoxGrid(listBox.SelectedIndex, false);
}
private void superTypeRdo_CheckedChanged(object sender, EventArgs e)
{
if ((sender as RadioButton).Checked)
{
int index = listBox.SelectedIndex;
int type = 0, count = 0;
GetTypeAndCount(index, ref type, ref count);
if (type == 0)
{
sideOutObjects[count].criticalFlowType = RiverSimulationProfile.CriticalFlowType.SuperCriticalFlow;
}
else
{
sideInObjects[count].criticalFlowType = RiverSimulationProfile.CriticalFlowType.SuperCriticalFlow;
}
}
}
private void subTypeRdo_CheckedChanged(object sender, EventArgs e)
{
if ((sender as RadioButton).Checked)
{
int index = listBox.SelectedIndex;
int type = 0, count = 0;
GetTypeAndCount(index, ref type, ref count);
if (type == 0)
{
sideOutObjects[count].criticalFlowType = RiverSimulationProfile.CriticalFlowType.SubCriticalFlow;
}
else
{
sideInObjects[count].criticalFlowType = RiverSimulationProfile.CriticalFlowType.SubCriticalFlow;
}
}
}
private void ok_Click(object sender, EventArgs e)
{
bool allInputFinished = true;
if (sideOutObjects != null)
{
foreach (RiverSimulationProfile.SideFlowObject obj in sideOutObjects)
{
if (obj == null || obj.sideFlowPoints == null || obj.sideFlowPoints.Count == 0)
{
allInputFinished = false;
}
}
}
if (sideInObjects != null)
{
foreach (RiverSimulationProfile.SideFlowObject obj in sideInObjects)
{
if (obj == null || obj.sideFlowPoints == null || obj.sideFlowPoints.Count == 0)
{
allInputFinished = false;
}
}
}
if (!allInputFinished)
{
MessageBox.Show("輸入未完成!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}