20#include "../elements/powerElement/SyncGenerator.h"
21#include "../elements/powerElement/SyncMotor.h"
23SyncMachineForm::SyncMachineForm(wxWindow* parent,
SyncGenerator* syncGenerator,
int plotLib) : SyncMachineFormBase(parent), m_parent(parent), m_syncGenerator(syncGenerator), m_plotLib(plotLib)
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) {
44 m_choiceNominalPower->SetSelection(0);
47 m_choiceNominalPower->SetSelection(1);
50 m_choiceNominalPower->SetSelection(2);
57 switch (data.activePowerUnit) {
59 m_choiceActivePower->SetSelection(0);
62 m_choiceActivePower->SetSelection(1);
65 m_choiceActivePower->SetSelection(2);
68 m_choiceActivePower->SetSelection(3);
75 switch (data.reactivePowerUnit) {
77 m_choiceReactivePower->SetSelection(0);
80 m_choiceReactivePower->SetSelection(1);
83 m_choiceReactivePower->SetSelection(2);
86 m_choiceReactivePower->SetSelection(3);
91 m_checkBoxMaxReactive->SetValue(data.haveMaxReactive);
94 switch (data.maxReactiveUnit) {
96 m_choiceMaxRectivePower->SetSelection(0);
99 m_choiceMaxRectivePower->SetSelection(1);
102 m_choiceMaxRectivePower->SetSelection(2);
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) {
117 m_choiceMinRectivePower->SetSelection(0);
120 m_choiceMinRectivePower->SetSelection(1);
123 m_choiceMinRectivePower->SetSelection(2);
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) {
168 m_choiceNominalPower->SetSelection(0);
171 m_choiceNominalPower->SetSelection(1);
174 m_choiceNominalPower->SetSelection(2);
181 switch (data.activePowerUnit) {
183 m_choiceActivePower->SetSelection(0);
186 m_choiceActivePower->SetSelection(1);
189 m_choiceActivePower->SetSelection(2);
192 m_choiceActivePower->SetSelection(3);
199 switch (data.reactivePowerUnit) {
201 m_choiceReactivePower->SetSelection(0);
204 m_choiceReactivePower->SetSelection(1);
207 m_choiceReactivePower->SetSelection(2);
210 m_choiceReactivePower->SetSelection(3);
215 m_checkBoxMaxReactive->SetValue(data.haveMaxReactive);
218 switch (data.maxReactiveUnit) {
220 m_choiceMaxRectivePower->SetSelection(0);
223 m_choiceMaxRectivePower->SetSelection(1);
226 m_choiceMaxRectivePower->SetSelection(2);
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) {
241 m_choiceMinRectivePower->SetSelection(0);
244 m_choiceMinRectivePower->SetSelection(1);
247 m_choiceMinRectivePower->SetSelection(2);
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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()) {
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.