Power System Platform  2026w10a-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
20#include "../editors/ControlEditor.h"
21
22#include "SwitchingForm.h"
23
24#include "../elements/controlElement/ControlElementContainer.h"
25#include "../elements/powerElement/SyncGenerator.h"
26
27GeneratorStabForm::GeneratorStabForm(wxWindow* parent, SyncGenerator* syncGenerator, int plotLib)
28 : GeneratorStabFormBase(parent), m_parent(parent), m_syncGenerator(syncGenerator), m_plotLib(plotLib)
29{
30 SetSize(GetBestSize());
31 //m_syncGenerator = syncGenerator;
32 //m_parent = parent;
33 //m_sharedGLContext = sharedGLContext;
34
35 SyncGeneratorElectricalData data = syncGenerator->GetElectricalData();
36
37 m_checkBoxPlotSyncMachine->SetValue(data.plotSyncMachine);
38
39 m_textCtrlInertia->SetValue(SyncGenerator::StringFromDouble(data.inertia));
40 m_textCtrlDamping->SetValue(SyncGenerator::StringFromDouble(data.damping));
41
42 m_checkBoxUseAVR->SetValue(data.useAVR);
43 m_buttonEditAVR->Enable(data.useAVR);
44
45 m_checkBoxUseSG->SetValue(data.useSpeedGovernor);
46 m_buttonEditSG->Enable(data.useSpeedGovernor);
47
48 m_textCtrlRa->SetValue(SyncGenerator::StringFromDouble(data.armResistance));
49 m_textCtrlXp->SetValue(SyncGenerator::StringFromDouble(data.potierReactance));
50 m_textCtrlSat->SetValue(SyncGenerator::StringFromDouble(data.satFactor));
51 m_textCtrlOCFreq->SetValue(SyncGenerator::StringFromDouble(data.ocFrequency));
52
53 m_textCtrlSyncXd->SetValue(SyncGenerator::StringFromDouble(data.syncXd));
54 m_textCtrlSyncXq->SetValue(SyncGenerator::StringFromDouble(data.syncXq));
55
56 m_textCtrlTranXd->SetValue(SyncGenerator::StringFromDouble(data.transXd));
57 m_textCtrlTranXq->SetValue(SyncGenerator::StringFromDouble(data.transXq));
58 m_textCtrlTranTd0->SetValue(SyncGenerator::StringFromDouble(data.transTd0));
59 m_textCtrlTranTq0->SetValue(SyncGenerator::StringFromDouble(data.transTq0));
60
61 m_textCtrlSubXd->SetValue(SyncGenerator::StringFromDouble(data.subXd));
62 m_textCtrlSubXq->SetValue(SyncGenerator::StringFromDouble(data.subXq));
63 m_textCtrlSubTd0->SetValue(SyncGenerator::StringFromDouble(data.subTd0));
64 m_textCtrlSubTq0->SetValue(SyncGenerator::StringFromDouble(data.subTq0));
65}
66
67GeneratorStabForm::~GeneratorStabForm()
68{
69}
70void GeneratorStabForm::OnCancelButtonClick(wxCommandEvent& event)
71{
72 EndModal(wxID_CANCEL);
73}
74void GeneratorStabForm::OnEditAVRButtonClick(wxCommandEvent& event)
75{
76 if (ValidateData()) {
77 SyncGeneratorElectricalData data = m_syncGenerator->GetElectricalData();
78 if (!data.avr) {
79 data.avr = new ControlElementContainer();
80 m_syncGenerator->SetElectricalData(data);
81 }
82
83 ControlEditor* cEditor = nullptr;
84
85 //if (m_sharedGLContext) {
86 // cEditor = new ControlEditor(nullptr, m_sharedGLContext, 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 //}
91 //else {
92 // cEditor = new ControlEditorDC(nullptr, IOControl::IN_TERMINAL_VOLTAGE | IOControl::IN_ACTIVE_POWER |
93 // IOControl::IN_REACTIVE_POWER | IOControl::IN_INITIAL_TERMINAL_VOLTAGE | IOControl::IN_VELOCITY |
94 // IOControl::IN_INITIAL_VELOCITY | IOControl::IN_DELTA_VELOCITY | IOControl::IN_DELTA_ACTIVE_POWER |
95 // IOControl::OUT_FIELD_VOLTAGE);
96 //}
97 cEditor = new ControlEditor(nullptr, IOControl::IN_TERMINAL_VOLTAGE | IOControl::IN_ACTIVE_POWER |
98 IOControl::IN_REACTIVE_POWER | IOControl::IN_INITIAL_TERMINAL_VOLTAGE | IOControl::IN_VELOCITY |
99 IOControl::IN_INITIAL_VELOCITY | IOControl::IN_DELTA_VELOCITY | IOControl::IN_DELTA_ACTIVE_POWER |
100 IOControl::OUT_FIELD_VOLTAGE);
101
102 cEditor->SetElementsList(data.avr->GetControlElementsList());
103 cEditor->SetConnectionsList(data.avr->GetConnectionLineList());
104 cEditor->SetControlContainer(data.avr);
105 cEditor->SetPlotLib(m_plotLib);
106 cEditor->Show();
107 cEditor->SetJustOpened(true);
108#ifdef __WXGTK__
109 EndModal(wxID_OK);
110#endif
111 }
112}
113
114void GeneratorStabForm::OnOKButtonClick(wxCommandEvent& event)
115{
116 if (ValidateData())
117 EndModal(wxID_OK);
118}
119
120void GeneratorStabForm::OnSpeedGovernorButtonClick(wxCommandEvent& event)
121{
122 if (ValidateData()) {
123 SyncGeneratorElectricalData data = m_syncGenerator->GetElectricalData();
124 if (!data.speedGov) {
125 data.speedGov = new ControlElementContainer();
126 m_syncGenerator->SetElectricalData(data);
127 }
128 ControlEditor* cEditor = nullptr;
129
130 //if (m_sharedGLContext) {
131 // cEditor = new ControlEditor(nullptr, m_sharedGLContext, IOControl::IN_VELOCITY | IOControl::IN_ACTIVE_POWER | IOControl::IN_REACTIVE_POWER |
132 // IOControl::IN_INITIAL_VELOCITY | IOControl::IN_INITIAL_MEC_POWER | IOControl::OUT_MEC_POWER);
133 //}
134 //else {
135 // cEditor = new ControlEditorDC(nullptr, IOControl::IN_VELOCITY | IOControl::IN_ACTIVE_POWER | IOControl::IN_REACTIVE_POWER |
136 // IOControl::IN_INITIAL_VELOCITY | IOControl::IN_INITIAL_MEC_POWER | IOControl::OUT_MEC_POWER);
137 //}
138 cEditor = new ControlEditor(nullptr, IOControl::IN_VELOCITY | IOControl::IN_ACTIVE_POWER | IOControl::IN_REACTIVE_POWER |
139 IOControl::IN_INITIAL_VELOCITY | IOControl::IN_INITIAL_MEC_POWER | IOControl::OUT_MEC_POWER);
140
141 cEditor->SetElementsList(data.speedGov->GetControlElementsList());
142 cEditor->SetConnectionsList(data.speedGov->GetConnectionLineList());
143 cEditor->SetControlContainer(data.speedGov);
144 cEditor->SetPlotLib(m_plotLib);
145 cEditor->Show();
146 cEditor->SetJustOpened(true);
147#ifdef __WXGTK__
148 EndModal(wxID_OK);
149#endif
150 }
151}
152
153void GeneratorStabForm::OnSwitchingButtonClick(wxCommandEvent& event)
154{
155 if (ValidateData()) {
156 SwitchingForm swForm(m_parent, m_syncGenerator);
157 swForm.SetTitle(_("Synchronous generator: Switching"));
158 swForm.ShowModal();
159 EndModal(wxID_OK);
160 }
161}
162
163bool GeneratorStabForm::ValidateData()
164{
165 SyncGeneratorElectricalData data = m_syncGenerator->GetElectricalData();
166
167 data.plotSyncMachine = m_checkBoxPlotSyncMachine->GetValue();
168
169 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlInertia->GetValue(), data.inertia,
170 _("Value entered incorrectly in the field \"Inertia\".")))
171 return false;
172
173 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlDamping->GetValue(), data.damping,
174 _("Value entered incorrectly in the field \"Damping factor\".")))
175 return false;
176
177 data.useAVR = m_checkBoxUseAVR->GetValue();
178 data.useSpeedGovernor = m_checkBoxUseSG->GetValue();
179
180 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlRa->GetValue(), data.armResistance,
181 _("Value entered incorrectly in the field \"Armature resistance\".")))
182 return false;
183
184 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlXp->GetValue(), data.potierReactance,
185 _("Value entered incorrectly in the field \"Potier reactance\".")))
186 return false;
187
188 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSat->GetValue(), data.satFactor,
189 _("Value entered incorrectly in the field \"Saturation factor\".")))
190 return false;
191
192 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlOCFreq->GetValue(), data.ocFrequency,
193 _("Value entered incorrectly in the field \"Open-circuit frequency\".")))
194 return false;
195
196 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSyncXd->GetValue(), data.syncXd,
197 _("Value entered incorrectly in the field \"Synchronous direct-axis reactance\".")))
198 return false;
199
200 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSyncXq->GetValue(), data.syncXq,
201 _("Value entered incorrectly in the field \"Synchronous quadrature-axis reactance\".")))
202 return false;
203
204 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlTranXd->GetValue(), data.transXd,
205 _("Value entered incorrectly in the field \"Transitory direct-axis reactance\".")))
206 return false;
207
208 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlTranXq->GetValue(), data.transXq,
209 _("Value entered incorrectly in the field \"Transitory quadrature-axis reactance\".")))
210 return false;
211
212 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlTranTd0->GetValue(), data.transTd0,
213 _("Value entered incorrectly in the field \"Transitory direct-axis time constant\".")))
214 return false;
215
216 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlTranTq0->GetValue(), data.transTq0,
217 _("Value entered incorrectly in the field \"Transitory quadrature-axis time constant\".")))
218 return false;
219
220 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSubXd->GetValue(), data.subXd,
221 _("Value entered incorrectly in the field \"Subtransitory direct-axis reactance\".")))
222 return false;
223
224 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSubXq->GetValue(), data.subXq,
225 _("Value entered incorrectly in the field \"Subtransitory quadrature-axis reactance\".")))
226 return false;
227
228 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSubTd0->GetValue(), data.subTd0,
229 _("Value entered incorrectly in the field \"Subtransitory direct-axis time constant\".")))
230 return false;
231
232 if (!m_syncGenerator->DoubleFromString(m_parent, m_textCtrlSubTq0->GetValue(), data.subTq0,
233 _("Value entered incorrectly in the field \"Subtransitory quadrature-axis time constant\".")))
234 return false;
235
236 m_syncGenerator->SetElectricalData(data);
237
238 return true;
239}
240void GeneratorStabForm::UseAVRClick(wxCommandEvent& event)
241{
242 m_buttonEditAVR->Enable(m_checkBoxUseAVR->GetValue());
243}
244void GeneratorStabForm::UseSGClick(wxCommandEvent& event)
245{
246 m_buttonEditSG->Enable(m_checkBoxUseSG->GetValue());
247}
Class that can contain all control elements. Can identify (using RTTI) the elements from a generic li...
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 switching data of power elements for electromechanical transient studies.
Synchronous generator power element.