-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEditorView.cs
More file actions
250 lines (209 loc) · 9.65 KB
/
Copy pathEditorView.cs
File metadata and controls
250 lines (209 loc) · 9.65 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
using FlowCalc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PumpDefinitionEditor
{
public partial class EditorView : Form
{
Controller m_Controller;
ChartView m_ChartView;
public string WindowTitle
{
get
{
var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);
return string.Concat(typeof(EditorView).Assembly.GetName().Name, " ", versionInfo.ProductVersion);
}
}
public EditorView()
{
InitializeComponent();
this.Text = WindowTitle; //Title
this.Icon = Properties.Resources.iconfinder_100_Pressure_Reading_183415;
m_Controller = new Controller();
}
private void btn_NewPump_Click(object sender, EventArgs e)
{
m_Controller.NewPump();
applyPumpDefinition();
}
private void btn_LoadPump_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Pumpendefinition laden";
openFileDialog1.Filter = "Pumpendefinition|*.xml";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
m_Controller.LoadPump(openFileDialog1.FileName);
applyPumpDefinition();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Laden fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void applyPumpDefinition()
{
propertyGrid1.SelectedObject = m_Controller.Pump;
if (m_Controller.PumpDefinitionPath != null)
{
this.Text = string.Concat(WindowTitle, " - ", m_Controller.PumpDefinitionPath.Split('/', '\\').Last());
btn_SaveCsv.Enabled = true;
btn_SaveJson.Enabled = true;
btn_SaveMat.Enabled = true;
btn_LoadMat.Enabled = true;
btn_ShowPerformanceCurve.Enabled = true;
}
else
{
btn_SaveCsv.Enabled = false;
btn_SaveJson.Enabled = false;
btn_SaveMat.Enabled = false;
btn_LoadMat.Enabled = false;
btn_ShowPerformanceCurve.Enabled = false;
}
}
private void btn_SaveCsv_Click(object sender, EventArgs e)
{
saveFileDialog1.Title = "Speichern im CSV Format";
saveFileDialog1.Filter = "CSV Datei | *.csv";
var path = m_Controller.PumpDefinitionPath.Replace(".xml", ".csv");
saveFileDialog1.FileName = path.Split('/', '\\').Last();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
m_Controller.Pump.ToCsvFile(saveFileDialog1.FileName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Speichern fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (MessageBox.Show("CSV Datei erfolgreich gespeichert.\n\nSoll die Datei geöffnet werden?", "Speichern erfolgreich",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
Process.Start(saveFileDialog1.FileName);
}
}
private void btn_SaveJson_Click(object sender, EventArgs e)
{
saveFileDialog1.Title = "Speichern im JSON Format";
saveFileDialog1.Filter = "JSON Datei | *.json";
var path = m_Controller.PumpDefinitionPath.Replace(".xml", ".json");
saveFileDialog1.FileName = path.Split('/', '\\').Last();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
m_Controller.Pump.ToJsonFile(saveFileDialog1.FileName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Speichern fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (MessageBox.Show("JSON Datei erfolgreich gespeichert.\n\nSoll die Datei geöffnet werden?", "Speichern erfolgreich",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
Process.Start(saveFileDialog1.FileName);
}
}
private void btn_SaveXml_Click(object sender, EventArgs e)
{
saveFileDialog1.Title = "Speichern im XML Format";
saveFileDialog1.Filter = "XML Datei | *.xml";
var path = string.Empty;
if (m_Controller.PumpDefinitionPath != null)
path = m_Controller.PumpDefinitionPath.Replace(".xml", "_neu.xml");
else
{
var safeModellName = m_Controller.Pump.ModellName;
foreach (var c in System.IO.Path.GetInvalidFileNameChars())
safeModellName = safeModellName.Replace(c.ToString(), "");
path = safeModellName;
}
saveFileDialog1.FileName = path.Split('/', '\\').Last();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
m_Controller.Pump.ToXmlFile(saveFileDialog1.FileName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Speichern fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (MessageBox.Show("XML Datei erfolgreich gespeichert.\n\nSoll die Datei extern geöffnet werden?", "Speichern erfolgreich",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
Process.Start(saveFileDialog1.FileName);
this.Text = string.Concat(WindowTitle, " - ", saveFileDialog1.FileName.Split('/', '\\').Last());
m_Controller.PumpDefinitionPath = saveFileDialog1.FileName.Split('/', '\\').Last();
}
}
private void btn_SaveMat_Click(object sender, EventArgs e)
{
saveFileDialog1.Title = "Matlab Export";
saveFileDialog1.Filter = "MAT File | *.mat";
var path = m_Controller.PumpDefinitionPath.Replace(".xml", ".mat");
saveFileDialog1.FileName = path.Split('/', '\\').Last();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
m_Controller.Pump.ToMatFile(saveFileDialog1.FileName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Speichern fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show("Mat File erfolgreich gespeichert.", "Speichern erfolgreich", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void btn_LoadMat_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Pumpenkennlinie importieren";
openFileDialog1.Filter = "MAT-File|*.mat";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
m_Controller.Pump.ImportMatCurve(openFileDialog1.FileName);
if (MessageBox.Show("Pumpenkennlinie wurde erfolgreich aus der MAT-File importiert.\n\nSoll die Pumpendefinitionsdatei gespeichert werden?",
"Import erfolgreich", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
btn_SaveXml_Click(sender, e);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Import fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void btn_ShowPerformanceCurve_Click(object sender, EventArgs e)
{
if (m_ChartView == null || !m_ChartView.Visible)
m_ChartView = new ChartView("Anzeige Pumpenkennlinie");
if (m_Controller.Pump.IsVarioPump)
{
//var performanceRange = m_Controller.Pump.GetPerformanceRange();
//m_ChartView.AddRange(m_Controller.Pump.ModellName, performanceRange.Item1, performanceRange.Item2);
foreach (var rpm in m_Controller.Pump.GetDefaultPresetValues())
m_ChartView.AddCurve(m_Controller.Pump.ModellName + $" ({rpm} min^-1)", m_Controller.Pump.GetPerformanceFlowValues(rpm), m_Controller.Pump.GetPerformanceHeadValues(rpm));
//Interpolierte Kennlinien ploten
//var stepwidth = (m_Controller.Pump.MaxRpm - m_Controller.Pump.MinRpm) / 17.0;
//for (double rpm = m_Controller.Pump.MinRpm; rpm < m_Controller.Pump.MaxRpm + 1; rpm += stepwidth)
// m_ChartView.AddCurve(m_Controller.Pump.ModellName + $" ({(int)rpm} min^-1)", m_Controller.Pump.GetPerformanceFlowValues((int)rpm), m_Controller.Pump.GetPerformanceHeadValues((int)rpm), false);
}
else
m_ChartView.AddCurve(m_Controller.Pump.ModellName, m_Controller.Pump.GetPerformanceFlowValues(), m_Controller.Pump.GetPerformanceHeadValues());
m_ChartView.Show();
}
}
}