Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
SyncMachineForm.cpp
1/*
2 * Copyright (C) 2017 Thales Lima Oliveira <thales@ufu.br>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#include "GeneratorStabForm.h"
19#include "SyncMachineForm.h"
20#include "../elements/powerElement/SyncGenerator.h"
21#include "../elements/powerElement/SyncMotor.h"
22
23SyncMachineForm::SyncMachineForm(wxWindow* parent, SyncGenerator* syncGenerator, int plotLib) : SyncMachineFormBase(parent), m_parent(parent), m_syncGenerator(syncGenerator), m_plotLib(plotLib)
24{
25 SetSize(GetBestSize());
26 ReplaceStaticTextLabelChar(m_staticTextPosResistance, L'\u2081');
27 ReplaceStaticTextLabelChar(m_staticTextPosReactance, L'\u2081');
28 ReplaceStaticTextLabelChar(m_staticTextNegResistance, L'\u2082');
29 ReplaceStaticTextLabelChar(m_staticTextNegReactance, L'\u2082');
30 ReplaceStaticTextLabelChar(m_staticTextZeroResistance, L'\u2080');
31 ReplaceStaticTextLabelChar(m_staticTextZeroReactance, L'\u2080');
32 Layout();
33 //m_syncGenerator = syncGenerator;
34 //m_parent = parent;
35 //m_sharedGLContext = sharedGLContext;
36
37 SyncGeneratorElectricalData data = syncGenerator->GetElectricalData();
38
39 m_textCtrlName->SetValue(data.name);
40
41 m_textCtrlnominalPower->SetValue(SyncGenerator::StringFromDouble(data.nominalPower));
42 switch (data.nominalPowerUnit) {
44 m_choiceNominalPower->SetSelection(0);
45 break;
47 m_choiceNominalPower->SetSelection(1);
48 break;
50 m_choiceNominalPower->SetSelection(2);
51 break;
52 default:
53 break;
54 }
55
56 m_textCtrlActivePower->SetValue(SyncGenerator::StringFromDouble(data.activePower));
57 switch (data.activePowerUnit) {
59 m_choiceActivePower->SetSelection(0);
60 break;
62 m_choiceActivePower->SetSelection(1);
63 break;
65 m_choiceActivePower->SetSelection(2);
66 break;
68 m_choiceActivePower->SetSelection(3);
69 break;
70 default:
71 break;
72 }
73
74 m_textCtrlReactivePower->SetValue(SyncGenerator::StringFromDouble(data.reactivePower));
75 switch (data.reactivePowerUnit) {
77 m_choiceReactivePower->SetSelection(0);
78 break;
80 m_choiceReactivePower->SetSelection(1);
81 break;
83 m_choiceReactivePower->SetSelection(2);
84 break;
86 m_choiceReactivePower->SetSelection(3);
87 break;
88 default:
89 break;
90 }
91 m_checkBoxMaxReactive->SetValue(data.haveMaxReactive);
92
93 m_textCtrlMaxRectivePower->SetValue(SyncGenerator::StringFromDouble(data.maxReactive));
94 switch (data.maxReactiveUnit) {
96 m_choiceMaxRectivePower->SetSelection(0);
97 break;
99 m_choiceMaxRectivePower->SetSelection(1);
100 break;
102 m_choiceMaxRectivePower->SetSelection(2);
103 break;
105 m_choiceMaxRectivePower->SetSelection(3);
106 break;
107 default:
108 break;
109 }
110 m_textCtrlMaxRectivePower->Enable(data.haveMaxReactive);
111 m_choiceMaxRectivePower->Enable(data.haveMaxReactive);
112
113 m_checkBoxMinReactive->SetValue(data.haveMinReactive);
114 m_textCtrlMinRectivePower->SetValue(SyncGenerator::StringFromDouble(data.minReactive));
115 switch (data.minReactiveUnit) {
117 m_choiceMinRectivePower->SetSelection(0);
118 break;
120 m_choiceMinRectivePower->SetSelection(1);
121 break;
123 m_choiceMinRectivePower->SetSelection(2);
124 break;
126 m_choiceMinRectivePower->SetSelection(3);
127 break;
128 default:
129 break;
130 }
131 m_textCtrlMinRectivePower->Enable(data.haveMinReactive);
132 m_choiceMinRectivePower->Enable(data.haveMinReactive);
133
134 m_checkBoxUseMachinePower->SetValue(data.useMachineBase);
135
136 m_textCtrlPosResistance->SetValue(SyncGenerator::StringFromDouble(data.positiveResistance));
137 m_textCtrlPosReactance->SetValue(SyncGenerator::StringFromDouble(data.positiveReactance));
138 m_textCtrlNegResistance->SetValue(SyncGenerator::StringFromDouble(data.negativeResistance));
139 m_textCtrlNegReactance->SetValue(SyncGenerator::StringFromDouble(data.negativeReactance));
140 m_textCtrlZeroResistance->SetValue(SyncGenerator::StringFromDouble(data.zeroResistance));
141 m_textCtrlZeroReactance->SetValue(SyncGenerator::StringFromDouble(data.zeroReactance));
142 m_textCtrlGrdResistance->SetValue(SyncGenerator::StringFromDouble(data.groundResistance));
143 m_textCtrlGrdReactance->SetValue(SyncGenerator::StringFromDouble(data.groundReactance));
144 m_checkBoxGroundNeutral->SetValue(data.groundNeutral);
145}
146
147SyncMachineForm::SyncMachineForm(wxWindow* parent, SyncMotor* syncMotor) : SyncMachineFormBase(parent)
148{
149 m_buttonStab->Enable(false);
150 SetSize(GetBestSize());
151 ReplaceStaticTextLabelChar(m_staticTextPosResistance, L'\u2081');
152 ReplaceStaticTextLabelChar(m_staticTextPosReactance, L'\u2081');
153 ReplaceStaticTextLabelChar(m_staticTextNegResistance, L'\u2082');
154 ReplaceStaticTextLabelChar(m_staticTextNegReactance, L'\u2082');
155 ReplaceStaticTextLabelChar(m_staticTextZeroResistance, L'\u2080');
156 ReplaceStaticTextLabelChar(m_staticTextZeroReactance, L'\u2080');
157 Layout();
158 m_syncMotor = syncMotor;
159 m_parent = parent;
160
161 SyncMotorElectricalData data = syncMotor->GetElectricalData();
162
163 m_textCtrlName->SetValue(data.name);
164
165 m_textCtrlnominalPower->SetValue(SyncMotor::StringFromDouble(data.nominalPower));
166 switch (data.nominalPowerUnit) {
168 m_choiceNominalPower->SetSelection(0);
169 break;
171 m_choiceNominalPower->SetSelection(1);
172 break;
174 m_choiceNominalPower->SetSelection(2);
175 break;
176 default:
177 break;
178 }
179
180 m_textCtrlActivePower->SetValue(SyncMotor::StringFromDouble(data.activePower));
181 switch (data.activePowerUnit) {
183 m_choiceActivePower->SetSelection(0);
184 break;
186 m_choiceActivePower->SetSelection(1);
187 break;
189 m_choiceActivePower->SetSelection(2);
190 break;
192 m_choiceActivePower->SetSelection(3);
193 break;
194 default:
195 break;
196 }
197
198 m_textCtrlReactivePower->SetValue(SyncMotor::StringFromDouble(data.reactivePower));
199 switch (data.reactivePowerUnit) {
201 m_choiceReactivePower->SetSelection(0);
202 break;
204 m_choiceReactivePower->SetSelection(1);
205 break;
207 m_choiceReactivePower->SetSelection(2);
208 break;
210 m_choiceReactivePower->SetSelection(3);
211 break;
212 default:
213 break;
214 }
215 m_checkBoxMaxReactive->SetValue(data.haveMaxReactive);
216
217 m_textCtrlMaxRectivePower->SetValue(SyncMotor::StringFromDouble(data.maxReactive));
218 switch (data.maxReactiveUnit) {
220 m_choiceMaxRectivePower->SetSelection(0);
221 break;
223 m_choiceMaxRectivePower->SetSelection(1);
224 break;
226 m_choiceMaxRectivePower->SetSelection(2);
227 break;
229 m_choiceMaxRectivePower->SetSelection(3);
230 break;
231 default:
232 break;
233 }
234 m_textCtrlMaxRectivePower->Enable(data.haveMaxReactive);
235 m_choiceMaxRectivePower->Enable(data.haveMaxReactive);
236
237 m_checkBoxMinReactive->SetValue(data.haveMinReactive);
238 m_textCtrlMinRectivePower->SetValue(SyncMotor::StringFromDouble(data.minReactive));
239 switch (data.minReactiveUnit) {
241 m_choiceMinRectivePower->SetSelection(0);
242 break;
244 m_choiceMinRectivePower->SetSelection(1);
245 break;
247 m_choiceMinRectivePower->SetSelection(2);
248 break;
250 m_choiceMinRectivePower->SetSelection(3);
251 break;
252 default:
253 break;
254 }
255 m_textCtrlMinRectivePower->Enable(data.haveMinReactive);
256 m_choiceMinRectivePower->Enable(data.haveMinReactive);
257
258 m_checkBoxUseMachinePower->SetValue(data.useMachineBase);
259
260 m_textCtrlPosResistance->SetValue(SyncMotor::StringFromDouble(data.positiveResistance));
261 m_textCtrlPosReactance->SetValue(SyncMotor::StringFromDouble(data.positiveReactance));
262 m_textCtrlNegResistance->SetValue(SyncMotor::StringFromDouble(data.negativeResistance));
263 m_textCtrlNegReactance->SetValue(SyncMotor::StringFromDouble(data.negativeReactance));
264 m_textCtrlZeroResistance->SetValue(SyncMotor::StringFromDouble(data.zeroResistance));
265 m_textCtrlZeroReactance->SetValue(SyncMotor::StringFromDouble(data.zeroReactance));
266 m_textCtrlGrdResistance->SetValue(SyncMotor::StringFromDouble(data.groundResistance));
267 m_textCtrlGrdReactance->SetValue(SyncMotor::StringFromDouble(data.groundReactance));
268 m_checkBoxGroundNeutral->SetValue(data.groundNeutral);
269}
270
271SyncMachineForm::~SyncMachineForm() {}
272void SyncMachineForm::OnCheckMaxReactive(wxCommandEvent& event)
273{
274 m_textCtrlMaxRectivePower->Enable(m_checkBoxMaxReactive->GetValue());
275 m_choiceMaxRectivePower->Enable(m_checkBoxMaxReactive->GetValue());
276}
277void SyncMachineForm::OnCheckMinReactive(wxCommandEvent& event)
278{
279 m_textCtrlMinRectivePower->Enable(m_checkBoxMinReactive->GetValue());
280 m_choiceMinRectivePower->Enable(m_checkBoxMinReactive->GetValue());
281}
282void SyncMachineForm::OnOKButtonClick(wxCommandEvent& event)
283{
284 if (ValidateData()) EndModal(wxID_OK);
285}
286void SyncMachineForm::OnStabilityButtonClick(wxCommandEvent& event)
287{
288 if (ValidateData()) {
289 if (m_syncGenerator) {
290 GeneratorStabForm stabForm(m_parent, m_syncGenerator, m_plotLib);
291 stabForm.CenterOnParent();
292 if (stabForm.ShowModal() == wxID_OK) {
293 EndModal(wxID_OK);
294 }
295 EndModal(wxID_CANCEL);
296 }
297 }
298}
299
300bool SyncMachineForm::ValidateData()
301{
302 if (m_syncGenerator) {
303 SyncGeneratorElectricalData data = m_syncGenerator->GetElectricalData();
304 data.name = m_textCtrlName->GetValue();
305
306 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlnominalPower->GetValue(), data.nominalPower,
307 _("Value entered incorrectly in the field \"Nominal power\".")))
308 return false;
309 switch (m_choiceNominalPower->GetSelection()) {
310 case 0:
311 data.nominalPowerUnit = ElectricalUnit::UNIT_VA;
312 break;
313 case 1:
314 data.nominalPowerUnit = ElectricalUnit::UNIT_kVA;
315 break;
316 case 2:
317 data.nominalPowerUnit = ElectricalUnit::UNIT_MVA;
318 break;
319 }
320
321 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlActivePower->GetValue(), data.activePower,
322 _("Value entered incorrectly in the field \"Active power\".")))
323 return false;
324 switch (m_choiceActivePower->GetSelection()) {
325 case 0:
326 data.activePowerUnit = ElectricalUnit::UNIT_PU;
327 break;
328 case 1:
329 data.activePowerUnit = ElectricalUnit::UNIT_W;
330 break;
331 case 2:
332 data.activePowerUnit = ElectricalUnit::UNIT_kW;
333 break;
334 case 3:
335 data.activePowerUnit = ElectricalUnit::UNIT_MW;
336 break;
337 }
338
339 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlReactivePower->GetValue(), data.reactivePower,
340 _("Value entered incorrectly in the field \"Reactive power\".")))
341 return false;
342 switch (m_choiceReactivePower->GetSelection()) {
343 case 0:
344 data.reactivePowerUnit = ElectricalUnit::UNIT_PU;
345 break;
346 case 1:
347 data.reactivePowerUnit = ElectricalUnit::UNIT_var;
348 break;
349 case 2:
350 data.reactivePowerUnit = ElectricalUnit::UNIT_kvar;
351 break;
352 case 3:
353 data.reactivePowerUnit = ElectricalUnit::UNIT_Mvar;
354 break;
355 }
356
357 data.haveMaxReactive = m_checkBoxMaxReactive->GetValue();
358 if (data.haveMaxReactive) {
359 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlMaxRectivePower->GetValue(), data.maxReactive,
360 _("Value entered incorrectly in the field \"Max reactive power\".")))
361 return false;
362 switch (m_choiceMaxRectivePower->GetSelection()) {
363 case 0:
364 data.maxReactiveUnit = ElectricalUnit::UNIT_PU;
365 break;
366 case 1:
367 data.maxReactiveUnit = ElectricalUnit::UNIT_var;
368 break;
369 case 2:
370 data.maxReactiveUnit = ElectricalUnit::UNIT_kvar;
371 break;
372 case 3:
373 data.maxReactiveUnit = ElectricalUnit::UNIT_Mvar;
374 break;
375 }
376 }
377
378 data.haveMinReactive = m_checkBoxMinReactive->GetValue();
379 if (data.haveMinReactive) {
380 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlMinRectivePower->GetValue(), data.minReactive,
381 _("Value entered incorrectly in the field \"Min reactive power\".")))
382 return false;
383 switch (m_choiceMinRectivePower->GetSelection()) {
384 case 0:
385 data.minReactiveUnit = ElectricalUnit::UNIT_PU;
386 break;
387 case 1:
388 data.minReactiveUnit = ElectricalUnit::UNIT_var;
389 break;
390 case 2:
391 data.minReactiveUnit = ElectricalUnit::UNIT_kvar;
392 break;
393 case 3:
394 data.minReactiveUnit = ElectricalUnit::UNIT_Mvar;
395 break;
396 }
397 }
398
399 data.useMachineBase = m_checkBoxUseMachinePower->GetValue();
400
401 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlPosResistance->GetValue(), data.positiveResistance,
402 _("Value entered incorrectly in the field \"Positive resistance\".")))
403 return false;
404
405 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlPosReactance->GetValue(), data.positiveReactance,
406 _("Value entered incorrectly in the field \"Positive reactance\".")))
407 return false;
408
409 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlNegResistance->GetValue(), data.negativeResistance,
410 _("Value entered incorrectly in the field \"Negative resistance\".")))
411 return false;
412
413 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlNegReactance->GetValue(), data.negativeReactance,
414 _("Value entered incorrectly in the field \"Negative reactance\".")))
415 return false;
416
417 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlZeroResistance->GetValue(), data.zeroResistance,
418 _("Value entered incorrectly in the field \"Zero resistance\".")))
419 return false;
420
421 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlZeroReactance->GetValue(), data.zeroReactance,
422 _("Value entered incorrectly in the field \"Zero reactance\".")))
423 return false;
424
425 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlGrdResistance->GetValue(), data.groundResistance,
426 _("Value entered incorrectly in the field \"Ground resistance\".")))
427 return false;
428
429 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlGrdReactance->GetValue(), data.groundReactance,
430 _("Value entered incorrectly in the field \"Ground reactance\".")))
431 return false;
432
433 data.groundNeutral = m_checkBoxGroundNeutral->GetValue();
434
435 m_syncGenerator->SetElectricalData(data);
436 }
437 else if (m_syncMotor) {
438 SyncMotorElectricalData data = m_syncMotor->GetElectricalData();
439 data.name = m_textCtrlName->GetValue();
440
441 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlnominalPower->GetValue(), data.nominalPower,
442 _("Value entered incorrectly in the field \"Nominal power\".")))
443 return false;
444 switch (m_choiceNominalPower->GetSelection()) {
445 case 0:
446 data.nominalPowerUnit = ElectricalUnit::UNIT_VA;
447 break;
448 case 1:
449 data.nominalPowerUnit = ElectricalUnit::UNIT_kVA;
450 break;
451 case 2:
452 data.nominalPowerUnit = ElectricalUnit::UNIT_MVA;
453 break;
454 }
455
456 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlActivePower->GetValue(), data.activePower,
457 _("Value entered incorrectly in the field \"Active power\".")))
458 return false;
459 switch (m_choiceActivePower->GetSelection()) {
460 case 0:
461 data.activePowerUnit = ElectricalUnit::UNIT_PU;
462 break;
463 case 1:
464 data.activePowerUnit = ElectricalUnit::UNIT_W;
465 break;
466 case 2:
467 data.activePowerUnit = ElectricalUnit::UNIT_kW;
468 break;
469 case 3:
470 data.activePowerUnit = ElectricalUnit::UNIT_MW;
471 break;
472 }
473
474 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlReactivePower->GetValue(), data.reactivePower,
475 _("Value entered incorrectly in the field \"Reactive power\".")))
476 return false;
477 switch (m_choiceReactivePower->GetSelection()) {
478 case 0:
479 data.reactivePowerUnit = ElectricalUnit::UNIT_PU;
480 break;
481 case 1:
482 data.reactivePowerUnit = ElectricalUnit::UNIT_var;
483 break;
484 case 2:
485 data.reactivePowerUnit = ElectricalUnit::UNIT_kvar;
486 break;
487 case 3:
488 data.reactivePowerUnit = ElectricalUnit::UNIT_Mvar;
489 break;
490 }
491
492 data.haveMaxReactive = m_checkBoxMaxReactive->GetValue();
493 if (data.haveMaxReactive) {
494 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlMaxRectivePower->GetValue(), data.maxReactive,
495 _("Value entered incorrectly in the field \"Max reactive power\".")))
496 return false;
497 switch (m_choiceMaxRectivePower->GetSelection()) {
498 case 0:
499 data.maxReactiveUnit = ElectricalUnit::UNIT_PU;
500 break;
501 case 1:
502 data.maxReactiveUnit = ElectricalUnit::UNIT_var;
503 break;
504 case 2:
505 data.maxReactiveUnit = ElectricalUnit::UNIT_kvar;
506 break;
507 case 3:
508 data.maxReactiveUnit = ElectricalUnit::UNIT_Mvar;
509 break;
510 }
511 }
512
513 data.haveMinReactive = m_checkBoxMinReactive->GetValue();
514 if (data.haveMinReactive) {
515 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlMinRectivePower->GetValue(), data.minReactive,
516 _("Value entered incorrectly in the field \"Min reactive power\".")))
517 return false;
518 switch (m_choiceMinRectivePower->GetSelection()) {
519 case 0:
520 data.minReactiveUnit = ElectricalUnit::UNIT_PU;
521 break;
522 case 1:
523 data.minReactiveUnit = ElectricalUnit::UNIT_var;
524 break;
525 case 2:
526 data.minReactiveUnit = ElectricalUnit::UNIT_kvar;
527 break;
528 case 3:
529 data.minReactiveUnit = ElectricalUnit::UNIT_Mvar;
530 break;
531 }
532 }
533
534 data.useMachineBase = m_checkBoxUseMachinePower->GetValue();
535
536 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlPosResistance->GetValue(), data.positiveResistance,
537 _("Value entered incorrectly in the field \"Positive resistance\".")))
538 return false;
539
540 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlPosReactance->GetValue(), data.positiveReactance,
541 _("Value entered incorrectly in the field \"Positive reactance\".")))
542 return false;
543
544 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlNegResistance->GetValue(), data.negativeResistance,
545 _("Value entered incorrectly in the field \"Negative resistance\".")))
546 return false;
547
548 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlNegReactance->GetValue(), data.negativeReactance,
549 _("Value entered incorrectly in the field \"Negative reactance\".")))
550 return false;
551
552 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlZeroResistance->GetValue(), data.zeroResistance,
553 _("Value entered incorrectly in the field \"Zero resistance\".")))
554 return false;
555
556 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlZeroReactance->GetValue(), data.zeroReactance,
557 _("Value entered incorrectly in the field \"Zero reactance\".")))
558 return false;
559
560 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlGrdResistance->GetValue(), data.groundResistance,
561 _("Value entered incorrectly in the field \"Ground resistance\".")))
562 return false;
563
564 if (!m_syncMotor->DoubleFromString(m_parent, m_textCtrlGrdReactance->GetValue(), data.groundReactance,
565 _("Value entered incorrectly in the field \"Ground reactance\".")))
566 return false;
567
568 data.groundNeutral = m_checkBoxGroundNeutral->GetValue();
569
570 m_syncMotor->SetElectricalData(data);
571 }
572 return true;
573}
574
575void SyncMachineForm::ReplaceStaticTextLabelChar(wxStaticText* staticText, wchar_t newChar)
576{
577 wxString label = staticText->GetLabel();
578 label[label.length() - 2] = newChar;
579 staticText->SetLabel(label);
580}
static bool DoubleFromString(wxWindow *parent, wxString strValue, double &value, wxString errorMsg)
Get a double value from a string. Show a error message if the conversion fail.
Definition Element.cpp:505
static wxString StringFromDouble(double value, int minDecimal=1, int maxDecimals=13)
Convert a double value to string.
Definition Element.cpp:533
Form to edit the synchronous generator data for electromechanical studies.
Synchronous generator power element.
Synchronous motor (synchronous compensator) power element.
Definition SyncMotor.h:135