Power System Platform  2026w34a-beta
Loading...
Searching...
No Matches
GeneratorStabForm.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
23
24#include "SwitchingForm.h"
25
29
30GeneratorStabForm::GeneratorStabForm(wxWindow* parent, SyncGenerator* syncGenerator, Workspace* workspace)
31 : GeneratorStabFormBase(parent), m_parent(parent), m_syncGenerator(syncGenerator), m_workspace(workspace)
32{
33 SetSize(GetBestSize());
34 //m_syncGenerator = syncGenerator;
35 //m_parent = parent;
36 //m_sharedGLContext = sharedGLContext;
37
38 SyncGeneratorElectricalData data = syncGenerator->GetElectricalData();
39
40 m_checkBoxPlotSyncMachine->SetValue(data.plotSyncMachine);
41
42 m_textCtrlInertia->SetValue(SyncGenerator::StringFromDouble(data.inertia));
43 m_textCtrlDamping->SetValue(SyncGenerator::StringFromDouble(data.damping));
44
45 m_checkBoxUseAVR->SetValue(data.useAVR);
46 m_buttonEditAVR->Enable(data.useAVR);
47
48 m_checkBoxUseSG->SetValue(data.useSpeedGovernor);
49 m_buttonEditSG->Enable(data.useSpeedGovernor);
50
51 m_textCtrlRa->SetValue(SyncGenerator::StringFromDouble(data.armResistance));
52 m_textCtrlXp->SetValue(SyncGenerator::StringFromDouble(data.potierReactance));
53 m_textCtrlSat->SetValue(SyncGenerator::StringFromDouble(data.satFactor));
54 m_textCtrlOCFreq->SetValue(SyncGenerator::StringFromDouble(data.ocFrequency));
55
56 m_textCtrlSyncXd->SetValue(SyncGenerator::StringFromDouble(data.syncXd));
57 m_textCtrlSyncXq->SetValue(SyncGenerator::StringFromDouble(data.syncXq));
58
59 m_textCtrlTranXd->SetValue(SyncGenerator::StringFromDouble(data.transXd));
60 m_textCtrlTranXq->SetValue(SyncGenerator::StringFromDouble(data.transXq));
61 m_textCtrlTranTd0->SetValue(SyncGenerator::StringFromDouble(data.transTd0));
62 m_textCtrlTranTq0->SetValue(SyncGenerator::StringFromDouble(data.transTq0));
63
64 m_textCtrlSubXd->SetValue(SyncGenerator::StringFromDouble(data.subXd));
65 m_textCtrlSubXq->SetValue(SyncGenerator::StringFromDouble(data.subXq));
66 m_textCtrlSubTd0->SetValue(SyncGenerator::StringFromDouble(data.subTd0));
67 m_textCtrlSubTq0->SetValue(SyncGenerator::StringFromDouble(data.subTq0));
68}
69
70GeneratorStabForm::~GeneratorStabForm()
71{
72}
73void GeneratorStabForm::OnCancelButtonClick(wxCommandEvent& event)
74{
75 EndModal(wxID_CANCEL);
76}
77void GeneratorStabForm::OnEditAVRButtonClick(wxCommandEvent& event)
78{
79 if (ValidateData()) {
80 SyncGeneratorElectricalData data = m_syncGenerator->GetElectricalData();
81 if (!data.avr) {
82 data.avr = new ControlElementContainer();
83 m_syncGenerator->SetElectricalData(data);
84 }
85
86 int ioFlags = IOControl::IN_TERMINAL_VOLTAGE | IOControl::IN_ACTIVE_POWER |
87 IOControl::IN_REACTIVE_POWER | IOControl::IN_INITIAL_TERMINAL_VOLTAGE | IOControl::IN_VELOCITY |
88 IOControl::IN_INITIAL_VELOCITY | IOControl::IN_DELTA_VELOCITY | IOControl::IN_DELTA_ACTIVE_POWER |
89 IOControl::OUT_FIELD_VOLTAGE;
90 auto& ceManager = m_workspace->GetControlEditorManager();
91 ceManager.Open(data.avr, static_cast<int>(m_workspace->GetProperties()->GetGeneralPropertiesData().plotLib), ioFlags);
92
93#ifdef __WXGTK__
94 EndModal(wxID_OK);
95#endif
96 }
97}
98
99void GeneratorStabForm::OnOKButtonClick(wxCommandEvent& event)
100{
101 if (ValidateData())
102 EndModal(wxID_OK);
103}
104
105void GeneratorStabForm::OnSpeedGovernorButtonClick(wxCommandEvent& event)
106{
107 if (ValidateData()) {
108 SyncGeneratorElectricalData data = m_syncGenerator->GetElectricalData();
109 if (!data.speedGov) {
110 data.speedGov = new ControlElementContainer();
111 m_syncGenerator->SetElectricalData(data);
112 }
113
114 int ioFlags = IOControl::IN_VELOCITY | IOControl::IN_ACTIVE_POWER | IOControl::IN_REACTIVE_POWER |
115 IOControl::IN_INITIAL_VELOCITY | IOControl::IN_INITIAL_MEC_POWER | IOControl::OUT_MEC_POWER;
116 auto& ceManager = m_workspace->GetControlEditorManager();
117 ceManager.Open(data.speedGov, static_cast<int>(m_workspace->GetProperties()->GetGeneralPropertiesData().plotLib), ioFlags);
118
119#ifdef __WXGTK__
120 EndModal(wxID_OK);
121#endif
122 }
123}
124
125void GeneratorStabForm::OnSwitchingButtonClick(wxCommandEvent& event)
126{
127 if (ValidateData()) {
128 SwitchingForm swForm(m_parent, m_syncGenerator);
129 swForm.SetTitle(_("Synchronous generator: Switching"));
130 swForm.ShowModal();
131 EndModal(wxID_OK);
132 }
133}
134
135bool GeneratorStabForm::ValidateData()
136{
137 SyncGeneratorElectricalData data = m_syncGenerator->GetElectricalData();
138
139 data.plotSyncMachine = m_checkBoxPlotSyncMachine->GetValue();
140
141 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlInertia->GetValue(), data.inertia,
142 _("Value entered incorrectly in the field \"Inertia\".")))
143 return false;
144
145 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlDamping->GetValue(), data.damping,
146 _("Value entered incorrectly in the field \"Damping factor\".")))
147 return false;
148
149 data.useAVR = m_checkBoxUseAVR->GetValue();
150 data.useSpeedGovernor = m_checkBoxUseSG->GetValue();
151
152 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlRa->GetValue(), data.armResistance,
153 _("Value entered incorrectly in the field \"Armature resistance\".")))
154 return false;
155
156 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlXp->GetValue(), data.potierReactance,
157 _("Value entered incorrectly in the field \"Potier reactance\".")))
158 return false;
159
160 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSat->GetValue(), data.satFactor,
161 _("Value entered incorrectly in the field \"Saturation factor\".")))
162 return false;
163
164 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlOCFreq->GetValue(), data.ocFrequency,
165 _("Value entered incorrectly in the field \"Open-circuit frequency\".")))
166 return false;
167
168 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSyncXd->GetValue(), data.syncXd,
169 _("Value entered incorrectly in the field \"Synchronous direct-axis reactance\".")))
170 return false;
171
172 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSyncXq->GetValue(), data.syncXq,
173 _("Value entered incorrectly in the field \"Synchronous quadrature-axis reactance\".")))
174 return false;
175
176 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlTranXd->GetValue(), data.transXd,
177 _("Value entered incorrectly in the field \"Transitory direct-axis reactance\".")))
178 return false;
179
180 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlTranXq->GetValue(), data.transXq,
181 _("Value entered incorrectly in the field \"Transitory quadrature-axis reactance\".")))
182 return false;
183
184 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlTranTd0->GetValue(), data.transTd0,
185 _("Value entered incorrectly in the field \"Transitory direct-axis time constant\".")))
186 return false;
187
188 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlTranTq0->GetValue(), data.transTq0,
189 _("Value entered incorrectly in the field \"Transitory quadrature-axis time constant\".")))
190 return false;
191
192 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSubXd->GetValue(), data.subXd,
193 _("Value entered incorrectly in the field \"Subtransitory direct-axis reactance\".")))
194 return false;
195
196 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSubXq->GetValue(), data.subXq,
197 _("Value entered incorrectly in the field \"Subtransitory quadrature-axis reactance\".")))
198 return false;
199
200 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSubTd0->GetValue(), data.subTd0,
201 _("Value entered incorrectly in the field \"Subtransitory direct-axis time constant\".")))
202 return false;
203
204 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSubTq0->GetValue(), data.subTq0,
205 _("Value entered incorrectly in the field \"Subtransitory quadrature-axis time constant\".")))
206 return false;
207
208 m_syncGenerator->SetElectricalData(data);
209
210 return true;
211}
212void GeneratorStabForm::UseAVRClick(wxCommandEvent& event)
213{
214 m_buttonEditAVR->Enable(m_checkBoxUseAVR->GetValue());
215}
216void GeneratorStabForm::UseSGClick(wxCommandEvent& event)
217{
218 m_buttonEditSG->Enable(m_checkBoxUseSG->GetValue());
219}
static wxString StringFromDouble(double value, int minDecimal=1, int maxDecimals=13)
Convert a double value to string.
Definition Element.cpp:548
Synchronous generator power element.
This class manages the graphical and power elements. It is responsible for handling the user's intera...
Definition Workspace.h:105