20#include "../elements/powerElement/SyncGenerator.h"
21#include "../elements/powerElement/SyncMotor.h"
23SyncMachineForm::SyncMachineForm(wxWindow* parent,
SyncGenerator* syncGenerator,
Workspace* workspace) : SyncMachineFormBase(parent), m_parent(parent), m_syncGenerator(syncGenerator), m_workspace(workspace)
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');
39 m_textCtrlName->SetValue(data.name);
42 switch (data.nominalPowerUnit) {
43 case ElectricalUnit::UNIT_VA:
44 m_choiceNominalPower->SetSelection(0);
46 case ElectricalUnit::UNIT_kVA:
47 m_choiceNominalPower->SetSelection(1);
49 case ElectricalUnit::UNIT_MVA:
50 m_choiceNominalPower->SetSelection(2);
57 switch (data.activePowerUnit) {
58 case ElectricalUnit::UNIT_PU:
59 m_choiceActivePower->SetSelection(0);
61 case ElectricalUnit::UNIT_W:
62 m_choiceActivePower->SetSelection(1);
64 case ElectricalUnit::UNIT_kW:
65 m_choiceActivePower->SetSelection(2);
67 case ElectricalUnit::UNIT_MW:
68 m_choiceActivePower->SetSelection(3);
75 switch (data.reactivePowerUnit) {
76 case ElectricalUnit::UNIT_PU:
77 m_choiceReactivePower->SetSelection(0);
79 case ElectricalUnit::UNIT_var:
80 m_choiceReactivePower->SetSelection(1);
82 case ElectricalUnit::UNIT_kvar:
83 m_choiceReactivePower->SetSelection(2);
85 case ElectricalUnit::UNIT_Mvar:
86 m_choiceReactivePower->SetSelection(3);
91 m_checkBoxMaxReactive->SetValue(data.haveMaxReactive);
94 switch (data.maxReactiveUnit) {
95 case ElectricalUnit::UNIT_PU:
96 m_choiceMaxRectivePower->SetSelection(0);
98 case ElectricalUnit::UNIT_var:
99 m_choiceMaxRectivePower->SetSelection(1);
101 case ElectricalUnit::UNIT_kvar:
102 m_choiceMaxRectivePower->SetSelection(2);
104 case ElectricalUnit::UNIT_Mvar:
105 m_choiceMaxRectivePower->SetSelection(3);
110 m_textCtrlMaxRectivePower->Enable(data.haveMaxReactive);
111 m_choiceMaxRectivePower->Enable(data.haveMaxReactive);
113 m_checkBoxMinReactive->SetValue(data.haveMinReactive);
115 switch (data.minReactiveUnit) {
116 case ElectricalUnit::UNIT_PU:
117 m_choiceMinRectivePower->SetSelection(0);
119 case ElectricalUnit::UNIT_var:
120 m_choiceMinRectivePower->SetSelection(1);
122 case ElectricalUnit::UNIT_kvar:
123 m_choiceMinRectivePower->SetSelection(2);
125 case ElectricalUnit::UNIT_Mvar:
126 m_choiceMinRectivePower->SetSelection(3);
131 m_textCtrlMinRectivePower->Enable(data.haveMinReactive);
132 m_choiceMinRectivePower->Enable(data.haveMinReactive);
134 m_checkBoxUseMachinePower->SetValue(data.useMachineBase);
144 m_checkBoxGroundNeutral->SetValue(data.groundNeutral);
147SyncMachineForm::SyncMachineForm(wxWindow* parent,
SyncMotor* syncMotor) : SyncMachineFormBase(parent)
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');
158 m_syncMotor = syncMotor;
163 m_textCtrlName->SetValue(data.name);
166 switch (data.nominalPowerUnit) {
167 case ElectricalUnit::UNIT_VA:
168 m_choiceNominalPower->SetSelection(0);
170 case ElectricalUnit::UNIT_kVA:
171 m_choiceNominalPower->SetSelection(1);
173 case ElectricalUnit::UNIT_MVA:
174 m_choiceNominalPower->SetSelection(2);
181 switch (data.activePowerUnit) {
182 case ElectricalUnit::UNIT_PU:
183 m_choiceActivePower->SetSelection(0);
185 case ElectricalUnit::UNIT_W:
186 m_choiceActivePower->SetSelection(1);
188 case ElectricalUnit::UNIT_kW:
189 m_choiceActivePower->SetSelection(2);
191 case ElectricalUnit::UNIT_MW:
192 m_choiceActivePower->SetSelection(3);
199 switch (data.reactivePowerUnit) {
200 case ElectricalUnit::UNIT_PU:
201 m_choiceReactivePower->SetSelection(0);
203 case ElectricalUnit::UNIT_var:
204 m_choiceReactivePower->SetSelection(1);
206 case ElectricalUnit::UNIT_kvar:
207 m_choiceReactivePower->SetSelection(2);
209 case ElectricalUnit::UNIT_Mvar:
210 m_choiceReactivePower->SetSelection(3);
215 m_checkBoxMaxReactive->SetValue(data.haveMaxReactive);
218 switch (data.maxReactiveUnit) {
219 case ElectricalUnit::UNIT_PU:
220 m_choiceMaxRectivePower->SetSelection(0);
222 case ElectricalUnit::UNIT_var:
223 m_choiceMaxRectivePower->SetSelection(1);
225 case ElectricalUnit::UNIT_kvar:
226 m_choiceMaxRectivePower->SetSelection(2);
228 case ElectricalUnit::UNIT_Mvar:
229 m_choiceMaxRectivePower->SetSelection(3);
234 m_textCtrlMaxRectivePower->Enable(data.haveMaxReactive);
235 m_choiceMaxRectivePower->Enable(data.haveMaxReactive);
237 m_checkBoxMinReactive->SetValue(data.haveMinReactive);
239 switch (data.minReactiveUnit) {
240 case ElectricalUnit::UNIT_PU:
241 m_choiceMinRectivePower->SetSelection(0);
243 case ElectricalUnit::UNIT_var:
244 m_choiceMinRectivePower->SetSelection(1);
246 case ElectricalUnit::UNIT_kvar:
247 m_choiceMinRectivePower->SetSelection(2);
249 case ElectricalUnit::UNIT_Mvar:
250 m_choiceMinRectivePower->SetSelection(3);
255 m_textCtrlMinRectivePower->Enable(data.haveMinReactive);
256 m_choiceMinRectivePower->Enable(data.haveMinReactive);
258 m_checkBoxUseMachinePower->SetValue(data.useMachineBase);
268 m_checkBoxGroundNeutral->SetValue(data.groundNeutral);
271SyncMachineForm::~SyncMachineForm() {}
272void SyncMachineForm::OnCheckMaxReactive(wxCommandEvent& event)
274 m_textCtrlMaxRectivePower->Enable(m_checkBoxMaxReactive->GetValue());
275 m_choiceMaxRectivePower->Enable(m_checkBoxMaxReactive->GetValue());
277void SyncMachineForm::OnCheckMinReactive(wxCommandEvent& event)
279 m_textCtrlMinRectivePower->Enable(m_checkBoxMinReactive->GetValue());
280 m_choiceMinRectivePower->Enable(m_checkBoxMinReactive->GetValue());
282void SyncMachineForm::OnOKButtonClick(wxCommandEvent& event)
284 if (ValidateData()) EndModal(wxID_OK);
286void SyncMachineForm::OnStabilityButtonClick(wxCommandEvent& event)
288 if (ValidateData()) {
289 if (m_syncGenerator) {
291 stabForm.CenterOnParent();
292 if (stabForm.ShowModal() == wxID_OK) {
295 EndModal(wxID_CANCEL);
300bool SyncMachineForm::ValidateData()
302 if (m_syncGenerator) {
304 data.name = m_textCtrlName->GetValue();
306 if (!m_syncGenerator->
DoubleFromString(m_parent, m_textCtrlnominalPower->GetValue(), data.nominalPower,
307 _(
"Value entered incorrectly in the field \"Nominal power\".")))
309 switch (m_choiceNominalPower->GetSelection()) {
311 data.nominalPowerUnit = ElectricalUnit::UNIT_VA;
314 data.nominalPowerUnit = ElectricalUnit::UNIT_kVA;
317 data.nominalPowerUnit = ElectricalUnit::UNIT_MVA;
321 if (!m_syncGenerator->
DoubleFromString(m_parent, m_textCtrlActivePower->GetValue(), data.activePower,
322 _(
"Value entered incorrectly in the field \"Active power\".")))
324 switch (m_choiceActivePower->GetSelection()) {
326 data.activePowerUnit = ElectricalUnit::UNIT_PU;
329 data.activePowerUnit = ElectricalUnit::UNIT_W;
332 data.activePowerUnit = ElectricalUnit::UNIT_kW;
335 data.activePowerUnit = ElectricalUnit::UNIT_MW;
339 if (!m_syncGenerator->
DoubleFromString(m_parent, m_textCtrlReactivePower->GetValue(), data.reactivePower,
340 _(
"Value entered incorrectly in the field \"Reactive power\".")))
342 switch (m_choiceReactivePower->GetSelection()) {
344 data.reactivePowerUnit = ElectricalUnit::UNIT_PU;
347 data.reactivePowerUnit = ElectricalUnit::UNIT_var;
350 data.reactivePowerUnit = ElectricalUnit::UNIT_kvar;
353 data.reactivePowerUnit = ElectricalUnit::UNIT_Mvar;
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\".")))
362 switch (m_choiceMaxRectivePower->GetSelection()) {
364 data.maxReactiveUnit = ElectricalUnit::UNIT_PU;
367 data.maxReactiveUnit = ElectricalUnit::UNIT_var;
370 data.maxReactiveUnit = ElectricalUnit::UNIT_kvar;
373 data.maxReactiveUnit = ElectricalUnit::UNIT_Mvar;
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\".")))
383 switch (m_choiceMinRectivePower->GetSelection()) {
385 data.minReactiveUnit = ElectricalUnit::UNIT_PU;
388 data.minReactiveUnit = ElectricalUnit::UNIT_var;
391 data.minReactiveUnit = ElectricalUnit::UNIT_kvar;
394 data.minReactiveUnit = ElectricalUnit::UNIT_Mvar;
399 data.useMachineBase = m_checkBoxUseMachinePower->GetValue();
401 if (!m_syncGenerator->
DoubleFromString(m_parent, m_textCtrlPosResistance->GetValue(), data.positiveResistance,
402 _(
"Value entered incorrectly in the field \"Positive resistance\".")))
405 if (!m_syncGenerator->
DoubleFromString(m_parent, m_textCtrlPosReactance->GetValue(), data.positiveReactance,
406 _(
"Value entered incorrectly in the field \"Positive reactance\".")))
409 if (!m_syncGenerator->
DoubleFromString(m_parent, m_textCtrlNegResistance->GetValue(), data.negativeResistance,
410 _(
"Value entered incorrectly in the field \"Negative resistance\".")))
413 if (!m_syncGenerator->
DoubleFromString(m_parent, m_textCtrlNegReactance->GetValue(), data.negativeReactance,
414 _(
"Value entered incorrectly in the field \"Negative reactance\".")))
417 if (!m_syncGenerator->
DoubleFromString(m_parent, m_textCtrlZeroResistance->GetValue(), data.zeroResistance,
418 _(
"Value entered incorrectly in the field \"Zero resistance\".")))
421 if (!m_syncGenerator->
DoubleFromString(m_parent, m_textCtrlZeroReactance->GetValue(), data.zeroReactance,
422 _(
"Value entered incorrectly in the field \"Zero reactance\".")))
425 if (!m_syncGenerator->
DoubleFromString(m_parent, m_textCtrlGrdResistance->GetValue(), data.groundResistance,
426 _(
"Value entered incorrectly in the field \"Ground resistance\".")))
429 if (!m_syncGenerator->
DoubleFromString(m_parent, m_textCtrlGrdReactance->GetValue(), data.groundReactance,
430 _(
"Value entered incorrectly in the field \"Ground reactance\".")))
433 data.groundNeutral = m_checkBoxGroundNeutral->GetValue();
435 m_syncGenerator->SetElectricalData(data);
437 else if (m_syncMotor) {
439 data.name = m_textCtrlName->GetValue();
441 if (!m_syncMotor->
DoubleFromString(m_parent, m_textCtrlnominalPower->GetValue(), data.nominalPower,
442 _(
"Value entered incorrectly in the field \"Nominal power\".")))
444 switch (m_choiceNominalPower->GetSelection()) {
446 data.nominalPowerUnit = ElectricalUnit::UNIT_VA;
449 data.nominalPowerUnit = ElectricalUnit::UNIT_kVA;
452 data.nominalPowerUnit = ElectricalUnit::UNIT_MVA;
456 if (!m_syncMotor->
DoubleFromString(m_parent, m_textCtrlActivePower->GetValue(), data.activePower,
457 _(
"Value entered incorrectly in the field \"Active power\".")))
459 switch (m_choiceActivePower->GetSelection()) {
461 data.activePowerUnit = ElectricalUnit::UNIT_PU;
464 data.activePowerUnit = ElectricalUnit::UNIT_W;
467 data.activePowerUnit = ElectricalUnit::UNIT_kW;
470 data.activePowerUnit = ElectricalUnit::UNIT_MW;
474 if (!m_syncMotor->
DoubleFromString(m_parent, m_textCtrlReactivePower->GetValue(), data.reactivePower,
475 _(
"Value entered incorrectly in the field \"Reactive power\".")))
477 switch (m_choiceReactivePower->GetSelection()) {
479 data.reactivePowerUnit = ElectricalUnit::UNIT_PU;
482 data.reactivePowerUnit = ElectricalUnit::UNIT_var;
485 data.reactivePowerUnit = ElectricalUnit::UNIT_kvar;
488 data.reactivePowerUnit = ElectricalUnit::UNIT_Mvar;
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\".")))
497 switch (m_choiceMaxRectivePower->GetSelection()) {
499 data.maxReactiveUnit = ElectricalUnit::UNIT_PU;
502 data.maxReactiveUnit = ElectricalUnit::UNIT_var;
505 data.maxReactiveUnit = ElectricalUnit::UNIT_kvar;
508 data.maxReactiveUnit = ElectricalUnit::UNIT_Mvar;
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\".")))
518 switch (m_choiceMinRectivePower->GetSelection()) {
520 data.minReactiveUnit = ElectricalUnit::UNIT_PU;
523 data.minReactiveUnit = ElectricalUnit::UNIT_var;
526 data.minReactiveUnit = ElectricalUnit::UNIT_kvar;
529 data.minReactiveUnit = ElectricalUnit::UNIT_Mvar;
534 data.useMachineBase = m_checkBoxUseMachinePower->GetValue();
536 if (!m_syncMotor->
DoubleFromString(m_parent, m_textCtrlPosResistance->GetValue(), data.positiveResistance,
537 _(
"Value entered incorrectly in the field \"Positive resistance\".")))
540 if (!m_syncMotor->
DoubleFromString(m_parent, m_textCtrlPosReactance->GetValue(), data.positiveReactance,
541 _(
"Value entered incorrectly in the field \"Positive reactance\".")))
544 if (!m_syncMotor->
DoubleFromString(m_parent, m_textCtrlNegResistance->GetValue(), data.negativeResistance,
545 _(
"Value entered incorrectly in the field \"Negative resistance\".")))
548 if (!m_syncMotor->
DoubleFromString(m_parent, m_textCtrlNegReactance->GetValue(), data.negativeReactance,
549 _(
"Value entered incorrectly in the field \"Negative reactance\".")))
552 if (!m_syncMotor->
DoubleFromString(m_parent, m_textCtrlZeroResistance->GetValue(), data.zeroResistance,
553 _(
"Value entered incorrectly in the field \"Zero resistance\".")))
556 if (!m_syncMotor->
DoubleFromString(m_parent, m_textCtrlZeroReactance->GetValue(), data.zeroReactance,
557 _(
"Value entered incorrectly in the field \"Zero reactance\".")))
560 if (!m_syncMotor->
DoubleFromString(m_parent, m_textCtrlGrdResistance->GetValue(), data.groundResistance,
561 _(
"Value entered incorrectly in the field \"Ground resistance\".")))
564 if (!m_syncMotor->
DoubleFromString(m_parent, m_textCtrlGrdReactance->GetValue(), data.groundReactance,
565 _(
"Value entered incorrectly in the field \"Ground reactance\".")))
568 data.groundNeutral = m_checkBoxGroundNeutral->GetValue();
570 m_syncMotor->SetElectricalData(data);
575void SyncMachineForm::ReplaceStaticTextLabelChar(wxStaticText* staticText,
wchar_t newChar)
577 wxString label = staticText->GetLabel();
578 label[label.length() - 2] = newChar;
579 staticText->SetLabel(label);
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.
static wxString StringFromDouble(double value, int minDecimal=1, int maxDecimals=13)
Convert a double value to string.
Synchronous generator power element.
Synchronous motor (synchronous compensator) power element.
This class manages the graphical and power elements. It is responsible for handling the user's intera...