summaryrefslogtreecommitdiffstats
path: root/Project/GeneratorForm.cpp
blob: e8cc332ef65c64c0ca3402250530a776d833c5bc (plain)
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
#include "GeneratorForm.h"
#include "GeneratorStabForm.h"
#include "SyncGenerator.h"

GeneratorForm::GeneratorForm(wxWindow* parent, SyncGenerator* syncGenerator) : GeneratorFormBase(parent)
{
    SetSize(GetBestSize());
    ReplaceStaticTextLabelChar(m_staticTextPosResistance, L'\u2081');
    ReplaceStaticTextLabelChar(m_staticTextPosReactance, L'\u2081');
    ReplaceStaticTextLabelChar(m_staticTextNegResistance, L'\u2082');
    ReplaceStaticTextLabelChar(m_staticTextNegReactance, L'\u2082');
    ReplaceStaticTextLabelChar(m_staticTextZeroResistance, L'\u2080');
    ReplaceStaticTextLabelChar(m_staticTextZeroReactance, L'\u2080');
    Layout();
    m_syncGenerator = syncGenerator;
    m_parent = parent;

    SyncGeneratorElectricalData data = syncGenerator->GetElectricalData();

    m_textCtrlName->SetValue(data.name);

    m_textCtrlnominalPower->SetValue(wxString::FromDouble(data.nominalPower));
    switch(data.nominalPowerUnit)
	{
	    case UNIT_VA:
		m_choiceNominalPower->SetSelection(0);
		break;
	    case UNIT_kVA:
		m_choiceNominalPower->SetSelection(1);
		break;
	    case UNIT_MVA:
		m_choiceNominalPower->SetSelection(2);
		break;
	    default:
		break;
	}

    m_textCtrlActivePower->SetValue(wxString::FromDouble(data.activePower));
    switch(data.activePowerUnit)
	{
	    case UNIT_PU:
		m_choiceActivePower->SetSelection(0);
		break;
	    case UNIT_W:
		m_choiceActivePower->SetSelection(1);
		break;
	    case UNIT_kW:
		m_choiceActivePower->SetSelection(2);
		break;
	    case UNIT_MW:
		m_choiceActivePower->SetSelection(3);
		break;
	    default:
		break;
	}

    m_textCtrlReactivePower->SetValue(wxString::FromDouble(data.reactivePower));
    switch(data.reactivePowerUnit)
	{
	    case UNIT_PU:
		m_choiceReactivePower->SetSelection(0);
		break;
	    case UNIT_VAr:
		m_choiceReactivePower->SetSelection(1);
		break;
	    case UNIT_kVAr:
		m_choiceReactivePower->SetSelection(2);
		break;
	    case UNIT_MVAr:
		m_choiceReactivePower->SetSelection(3);
		break;
	    default:
		break;
	}
    m_checkBoxMaxReactive->SetValue(data.haveMaxReactive);

    m_textCtrlMaxRectivePower->SetValue(wxString::FromDouble(data.maxReactive));
    switch(data.maxReactiveUnit)
	{
	    case UNIT_PU:
		m_choiceMaxRectivePower->SetSelection(0);
		break;
	    case UNIT_VAr:
		m_choiceMaxRectivePower->SetSelection(1);
		break;
	    case UNIT_kVAr:
		m_choiceMaxRectivePower->SetSelection(2);
		break;
	    case UNIT_MVAr:
		m_choiceMaxRectivePower->SetSelection(3);
		break;
	    default:
		break;
	}
    m_textCtrlMaxRectivePower->Enable(data.haveMaxReactive);
    m_choiceMaxRectivePower->Enable(data.haveMaxReactive);

    m_checkBoxMinReactive->SetValue(data.haveMinReactive);
    m_textCtrlMinRectivePower->SetValue(wxString::FromDouble(data.minReactive));
    switch(data.minReactiveUnit)
	{
	    case UNIT_PU:
		m_choiceMinRectivePower->SetSelection(0);
		break;
	    case UNIT_VAr:
		m_choiceMinRectivePower->SetSelection(1);
		break;
	    case UNIT_kVAr:
		m_choiceMinRectivePower->SetSelection(2);
		break;
	    case UNIT_MVAr:
		m_choiceMinRectivePower->SetSelection(3);
		break;
	    default:
		break;
	}
    m_textCtrlMinRectivePower->Enable(data.haveMinReactive);
    m_choiceMinRectivePower->Enable(data.haveMinReactive);

    m_checkBoxUseMachinePower->SetValue(data.useMachineBase);

    m_textCtrlPosResistance->SetValue(wxString::FromDouble(data.positiveResistance));
    m_textCtrlPosReactance->SetValue(wxString::FromDouble(data.positiveReactance));
    m_textCtrlNegResistance->SetValue(wxString::FromDouble(data.negativeResistance));
    m_textCtrlNegReactance->SetValue(wxString::FromDouble(data.negativeReactance));
    m_textCtrlZeroResistance->SetValue(wxString::FromDouble(data.zeroResistance));
    m_textCtrlZeroReactance->SetValue(wxString::FromDouble(data.zeroReactance));
    m_textCtrlGrdResistance->SetValue(wxString::FromDouble(data.groundResistance));
    m_textCtrlGrdReactance->SetValue(wxString::FromDouble(data.groundReactance));
    m_checkBoxGroundNeutral->SetValue(data.groundNeutral);
}
GeneratorForm::~GeneratorForm() {}
void GeneratorForm::OnCancelButtonClick(wxCommandEvent& event) { EndModal(wxID_CANCEL); }
void GeneratorForm::OnCheckMaxReactive(wxCommandEvent& event)
{
    m_textCtrlMaxRectivePower->Enable(m_checkBoxMaxReactive->GetValue());
    m_choiceMaxRectivePower->Enable(m_checkBoxMaxReactive->GetValue());
}

void GeneratorForm::OnCheckMinReactive(wxCommandEvent& event)
{
    m_textCtrlMinRectivePower->Enable(m_checkBoxMinReactive->GetValue());
    m_choiceMinRectivePower->Enable(m_checkBoxMinReactive->GetValue());
}

void GeneratorForm::OnOKButtonClick(wxCommandEvent& event)
{
    if(!ValidateData()) return;
    EndModal(wxID_OK);
}
void GeneratorForm::OnStabilityButtonClick(wxCommandEvent& event)
{
    if(!ValidateData()) return;
    GeneratorStabForm* stabForm = new GeneratorStabForm(m_parent, m_syncGenerator);
    if(stabForm->ShowModal() == wxID_OK) {
	    stabForm->Destroy();
	    EndModal(wxID_OK);
	}

    stabForm->Destroy();
    EndModal(wxID_CANCEL);
}

void GeneratorForm::ReplaceStaticTextLabelChar(wxStaticText* staticText, wchar_t newChar)
{
    wxString label = staticText->GetLabel();
    label[label.length() - 2] = newChar;
    staticText->SetLabel(label);
}

bool GeneratorForm::ValidateData()
{
    SyncGeneratorElectricalData data = m_syncGenerator->GetElectricalData();
    data.name = m_textCtrlName->GetValue();

    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlnominalPower->GetValue(), data.nominalPower,
                                          _("Value entered incorrectly in the field \"Nominal power\".")))
	return false;
    switch(m_choiceNominalPower->GetSelection())
	{
	    case 0:
		data.nominalPowerUnit = UNIT_VA;
		break;
	    case 1:
		data.nominalPowerUnit = UNIT_kVA;
		break;
	    case 2:
		data.nominalPowerUnit = UNIT_MVA;
		break;
	}

    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlActivePower->GetValue(), data.activePower,
                                          _("Value entered incorrectly in the field \"Active power\".")))
	return false;
    switch(m_choiceActivePower->GetSelection())
	{
	    case 0:
		data.activePowerUnit = UNIT_PU;
		break;
	    case 1:
		data.activePowerUnit = UNIT_W;
		break;
	    case 2:
		data.activePowerUnit = UNIT_kW;
		break;
	    case 3:
		data.activePowerUnit = UNIT_MW;
		break;
	}

    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlReactivePower->GetValue(), data.reactivePower,
                                          _("Value entered incorrectly in the field \"Reactive power\".")))
	return false;
    switch(m_choiceReactivePower->GetSelection())
	{
	    case 0:
		data.reactivePowerUnit = UNIT_PU;
		break;
	    case 1:
		data.reactivePowerUnit = UNIT_VAr;
		break;
	    case 2:
		data.reactivePowerUnit = UNIT_kVAr;
		break;
	    case 3:
		data.reactivePowerUnit = UNIT_MVAr;
		break;
	}

    data.haveMaxReactive = m_checkBoxMaxReactive->GetValue();
    if(data.haveMaxReactive) {
	    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlMaxRectivePower->GetValue(), data.maxReactive,
	                                          _("Value entered incorrectly in the field \"Max reactive power\".")))
		return false;
	    switch(m_choiceMaxRectivePower->GetSelection())
		{
		    case 0:
			data.maxReactiveUnit = UNIT_PU;
			break;
		    case 1:
			data.maxReactiveUnit = UNIT_VAr;
			break;
		    case 2:
			data.maxReactiveUnit = UNIT_kVAr;
			break;
		    case 3:
			data.maxReactiveUnit = UNIT_MVAr;
			break;
		}
	}

    data.haveMinReactive = m_checkBoxMinReactive->GetValue();
    if(data.haveMinReactive) {
	    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlMinRectivePower->GetValue(), data.minReactive,
	                                          _("Value entered incorrectly in the field \"Min reactive power\".")))
		return false;
	    switch(m_choiceMinRectivePower->GetSelection())
		{
		    case 0:
			data.minReactiveUnit = UNIT_PU;
			break;
		    case 1:
			data.minReactiveUnit = UNIT_VAr;
			break;
		    case 2:
			data.minReactiveUnit = UNIT_kVAr;
			break;
		    case 3:
			data.minReactiveUnit = UNIT_MVAr;
			break;
		}
	}

    data.useMachineBase = m_checkBoxUseMachinePower->GetValue();

    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlPosResistance->GetValue(), data.positiveResistance,
                                          _("Value entered incorrectly in the field \"Positive resistance\".")))
	return false;

    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlPosReactance->GetValue(), data.positiveReactance,
                                          _("Value entered incorrectly in the field \"Positive reactance\".")))
	return false;

    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlNegResistance->GetValue(), data.negativeResistance,
                                          _("Value entered incorrectly in the field \"Negative resistance\".")))
	return false;

    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlNegReactance->GetValue(), data.negativeReactance,
                                          _("Value entered incorrectly in the field \"Negative reactance\".")))
	return false;

    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlZeroResistance->GetValue(), data.zeroResistance,
                                          _("Value entered incorrectly in the field \"Zero resistance\".")))
	return false;

    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlZeroReactance->GetValue(), data.zeroReactance,
                                          _("Value entered incorrectly in the field \"Zero reactance\".")))
	return false;

    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlGrdResistance->GetValue(), data.groundResistance,
                                          _("Value entered incorrectly in the field \"Ground resistance\".")))
	return false;

    if(!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlGrdReactance->GetValue(), data.groundReactance,
                                          _("Value entered incorrectly in the field \"Ground reactance\".")))
	return false;

    data.groundNeutral = m_checkBoxGroundNeutral->GetValue();

    m_syncGenerator->SetElectricalData(data);
    return true;
}