-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainForm.cs
More file actions
395 lines (351 loc) · 16.1 KB
/
MainForm.cs
File metadata and controls
395 lines (351 loc) · 16.1 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using Inaprop;
namespace Inaprop
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
InitializedataGridView1();
InitializedataGridView2();
InitializePlot();
//TEST
Airfoils Airfoilstest = new Airfoils();
List<WingSection> WingSection1 = new List<WingSection>();
//List<Airfoil> Airfoil2 = new List<Airfoil>();
WingSection1.Add(new WingSection(0.0)); WingSection1.Add(new WingSection(1.0));
//Prop Proptest = Airfoilstest.Transration(WingSection1);
}
[STAThread]
public static void Main()
{
Application.Run(new MainForm());
}
private void quitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
//クラス宣言
Airfoil DAE51 = new Airfoil();
List<WingSection> WingSections = new List<WingSection>();
List<WingSection> SortedWingSections = new List<WingSection>();
List<Prop> Props = new List<Prop>();
public Prop SelectedProp = new Prop();
int number_of_Prop = 0;
// Culcボタン
private void button4_Click(object sender, EventArgs e)
{
//SortedWingSectionsはdataGridView1_validCellで定義
Airfoils Airfoilstest = new Airfoils();
//if (SortedWingSections.Count > 2)
//{
Airfoilstest.Transration(ref SelectedProp, SortedWingSections);
//}
//Props.Add(new Prop());
SelectedProp.Name = textBox1.Text;
SelectedProp.Blade = (double)numericUpDown1.Value;
SelectedProp.Uinf = (double)numericUpDown2.Value;
SelectedProp.Rpm = (double)numericUpDown3.Value;
SelectedProp.Radius = (double)numericUpDown4.Value;
SelectedProp.Radius_in = (double)numericUpDown5.Value;
//SelectedProp.Lambda = (double)numericUpDown5.Value;
SelectedProp.Power = (double)numericUpDown6.Value;
SelectedProp.Rho = (double)numericUpDown7.Value;
SelectedProp.Nu = (double)numericUpDown8.Value;
//半径より内側半径が大きい時はエラー
if (SelectedProp.Radius <= SelectedProp.Radius_in)
{
MessageBox.Show("Radius must be larger than Radius_INNER", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
SelectedProp.Show = true;
if (radioButton1.Checked == true) //Harada
{
button4.Text = "Now Calcurating...";
button4.Enabled = false;
backgroundWorker1.RunWorkerAsync();
}
if (radioButton2.Checked == true) //Larrabee
{
SelectedProp.CulcLarrabee();
label13.Text = SelectedProp.T_.ToString("F2") + "[N]";
label14.Text = SelectedProp.P_.ToString("F2") + "[W]";
label15.Text = SelectedProp.Efficiency.ToString("F2") + "%";
//ShowPlot(SelectedProp);
ShowPlot2();
}
if (radioButton3.Checked == true) //BEM
{
SelectedProp.CulcBEM();
label13.Text = SelectedProp.T_.ToString("F2") + "[N]";
label14.Text = SelectedProp.P_.ToString("F2") + "[W]";
label15.Text = SelectedProp.Efficiency.ToString("F2") + "%";
ShowPlot2();
}
updata_dataGridView2();
PlotDetect();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
SelectedProp.CalcHarada(worker, e);
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
label12.Text = "Power:" + SelectedProp.P_.ToString("F1");
progressBar1.Value = e.ProgressPercentage;
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
button4.Text = "Calcuration";
button4.Enabled = true;
label12.Text = "Progress";
label13.Text = SelectedProp.T_.ToString("F2") + "[N]";
label14.Text = SelectedProp.P_.ToString("F2") + "[W]";
label15.Text = SelectedProp.Efficiency.ToString("F2") + "%";
ShowPlot2();
updata_dataGridView2();
}
/// <summary>
/// dataGridView1のメソッド
/// </summary>
public void InitializedataGridView1()
{
WingSections.Add(new WingSection(0.0));
WingSections.Add(new WingSection(1.0));
IEnumerable<WingSection> subWingSections = from WingSection aWingSection in WingSections
orderby aWingSection.Position ascending
select aWingSection;
dataGridView1.DataSource = subWingSections.ToList<WingSection>();
//位置r/RでソートされたWingSectionリスト。これからAirfoilsクラスを用いてPropを生成できる
SortedWingSections = new List<WingSection>(subWingSections);
//テスト
//List<WingSection> SortedWingSetions = new List<WingSection>(subWingSections);
//読み取り専用(ReadOnly)にはならない
//dataGridView1[0, 0].ReadOnly = true;
//dataGridView1[0, dataGridView1.Rows.Count - 1].ReadOnly = true;
}
public void InitializedataGridView2()
{
Props.Add(new Prop());
Props[0].Name = "Prop" + number_of_Prop;
SelectedProp = Props[0];
SelectedProp.dataGridView_index = 0;
updata_dataGridView2();
}
// New Propellerボタン
// PropsリストにPropコンストラクタを新規製作追加。リストをソート、表示
private void button6_Click(object sender, EventArgs e)
{
Props.Add(new Prop());
number_of_Prop++;
Props[Props.Count - 1].Name = "Prop" + number_of_Prop;
updata_dataGridView2();
}
//Delete Propellerボタン
//1行づつ選択行を削除。並び替え後表示。もし全部削除なら一つだけ残るようにAddして表示。
private void button8_Click(object sender, EventArgs e)
{
exportCSVprop(SelectedProp, 10);
foreach (DataGridViewRow selectedRow in dataGridView2.SelectedRows)
{
Props.RemoveAt(selectedRow.Index);
}
updata_dataGridView2();
if (dataGridView2.RowCount == 0)
{
Props.Add(new Prop());
number_of_Prop++;
Props[Props.Count - 1].Name = "Prop" + number_of_Prop;
}
updata_dataGridView2();
reload_dataGridView2();
}
//WingSection部分
//Insertボタンクリック
private void button2_Click(object sender, EventArgs e)
{
WingSections.Add(new WingSection(0.1));
IEnumerable<WingSection> subWingSections = from WingSection aWingSection in WingSections
orderby aWingSection.Position ascending
select aWingSection;
dataGridView1.DataSource = subWingSections.ToList<WingSection>();
}
//Deleteボタンクリック
private void button3_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow selectedRow in dataGridView1.SelectedRows)
{
if (selectedRow.Index == 0 || selectedRow.Index == dataGridView1.Rows.Count - 1)
{
MessageBox.Show("This row is NOT removable", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
WingSections.RemoveAt(selectedRow.Index);
}
}
IEnumerable<WingSection> subWingSections = from WingSection aWingSection in WingSections
orderby aWingSection.Position ascending
select aWingSection;
dataGridView1.DataSource = subWingSections.ToList<WingSection>();
}
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
DataGridView dgv = (DataGridView)sender;
////セルに入力されているのが数字の場合result = true,
double output;
bool result = Double.TryParse(e.FormattedValue.ToString(), out output);
//文字が入力されている時
if (result == false && dgv.Columns[e.ColumnIndex].Name != "nameDataGridViewTextBoxColumn")
{
dgv.Rows[e.RowIndex].ErrorText = "Input valid value";
dgv.CancelEdit();
e.Cancel = true;
}
else
{
//r/Rのセル内容が上下と値が被っていたら値変更
if (e.RowIndex == dgv.Rows.Count - 1 || e.RowIndex == 0) { }
else
{
dgv["dataGridViewTextBoxColumn1", e.RowIndex].Value =
Convert.ToDouble(dgv["dataGridViewTextBoxColumn1", e.RowIndex].Value);
if ((double)dgv["dataGridViewTextBoxColumn1", e.RowIndex].Value ==
(double)dgv["dataGridViewTextBoxColumn1", e.RowIndex + 1].Value ||
(double)dgv["dataGridViewTextBoxColumn1", e.RowIndex].Value ==
(double)dgv["dataGridViewTextBoxColumn1", e.RowIndex - 1].Value)
{
dgv["dataGridViewTextBoxColumn1", e.RowIndex].Value =
(double)dgv["dataGridViewTextBoxColumn1", e.RowIndex + 1].Value + 0.01;
//dgv.Update();
}
}
//r/Rのセル内容が変更されている時
if (dgv.Columns[e.ColumnIndex].Name == "dataGridViewTextBoxColumn1" &&
(output < 0.0 || output > 1.0))
{
dgv.Rows[e.RowIndex].ErrorText = "r/R value is only 0.0 to 1.0";
dgv.CancelEdit();
e.Cancel = true;
}
//CLのセル内容が変更されている時
if (dgv.Columns[e.ColumnIndex].Name == "clDataGridViewTextBoxColumn" &&
(output < 0.0 || output > 2.0))
{
dgv.Rows[e.RowIndex].ErrorText = "CL value is only 0.0 to Max. CL";
dgv.CancelEdit();
e.Cancel = true;
}
//r/Rの最後は必ず1になるように
if (dgv.RowCount != 0)
dgv["dataGridViewTextBoxColumn1", dgv.RowCount - 1].Value = 1.0;
}
}
private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
{
//エラーを消去
DataGridView dgv = (DataGridView)sender;
dgv.Rows[e.RowIndex].ErrorText = null;
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//Validの確認が終わったらソート
IEnumerable<WingSection> subWingSections = from WingSection aWingSection in WingSections
orderby aWingSection.Position ascending
select aWingSection;
dataGridView1.DataSource = subWingSections.ToList<WingSection>();
//位置r/RでソートされたWingSectionリスト。これからAirfoilsクラスを用いてPropを生成できる
SortedWingSections = new List<WingSection>(subWingSections);
}
//dataGridView2
private void dataGridView2_Click(object sender, EventArgs e)
{
reload_dataGridView2();
}
private void dataGridView2_KeyPress(object sender, KeyPressEventArgs e)
{
reload_dataGridView2();
}
private void dataGridView2_KeyUp(object sender, KeyEventArgs e)
{
reload_dataGridView2();
}
private void dataGridView2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
reload_dataGridView2();
}
//dataGridView2の選択行をSelecedPropに代入
private void reload_dataGridView2()
{
foreach (DataGridViewRow r in dataGridView2.SelectedRows)
{
SelectedProp = Props[r.Index];
SelectedProp.dataGridView_index = r.Index;
}
textBox1.Text = SelectedProp.Name;
numericUpDown1.Value = (decimal)SelectedProp.Blade;
numericUpDown2.Value = (decimal)SelectedProp.Uinf;
numericUpDown3.Value = (decimal)SelectedProp.Rpm;
numericUpDown4.Value = (decimal)SelectedProp.Radius;
numericUpDown5.Value = (decimal)SelectedProp.Radius_in;
numericUpDown6.Value = (decimal)SelectedProp.Power;
numericUpDown7.Value = (decimal)SelectedProp.Rho;
numericUpDown8.Value = (decimal)SelectedProp.Nu;
//半径より内側半径が大きい時はエラー
if (SelectedProp.Radius <= SelectedProp.Radius_in)
{
MessageBox.Show("Radius must be larger than Radius_INNER", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//グラフ書き換え
ShowPlot2();
}
// dataGridView2のデータの表示の更新
private void updata_dataGridView2()
{
IEnumerable<Prop> subProps = from Prop aProp in Props
//orderby aProp.Name ascending
select aProp;
dataGridView2.DataSource = subProps.ToList<Prop>();
if (dataGridView2.Rows.Count != SelectedProp.dataGridView_index)
{
dataGridView2.Rows[SelectedProp.dataGridView_index].Selected = true;
}
else
{
SelectedProp.dataGridView_index = 0;
}
}
/// <summary>
/// Analysisボタンクリック。解析フォームが出る。選択中のPropが選ばれる
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button7_Click(object sender, EventArgs e)
{
AnalysisForm analysisForm = new AnalysisForm(SelectedProp);
analysisForm.ShowDialog();
}
private void exportToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show(SelectedProp.Name + "をCSV形式で出力します", "Export CSV file",
MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
{
exportCSVprop(SelectedProp, Prop.n);
}
}
}
}