Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
ReactiveShuntElementForm.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
19#include "SwitchingForm.h"
20#include "../elements/powerElement/Capacitor.h"
21#include "../elements/powerElement/Inductor.h"
22
23ReactiveShuntElementForm::ReactiveShuntElementForm(wxWindow* parent, Capacitor* capacitor)
24 : ReactiveShuntElementFormBase(parent)
25{
26 SetSize(GetBestSize());
27 CapacitorElectricalData data = capacitor->GetElectricalData();
28
29 m_textCtrlName->SetValue(data.name);
30
31 m_textCtrlReactivePower->SetValue(Capacitor::StringFromDouble(data.reactivePower));
32 switch(data.reactivePowerUnit) {
34 m_choiceReactivePower->SetSelection(0);
35 } break;
37 m_choiceReactivePower->SetSelection(1);
38 } break;
40 m_choiceReactivePower->SetSelection(2);
41 } break;
43 m_choiceReactivePower->SetSelection(3);
44 } break;
45 default:
46 break;
47 }
48
49 m_parent = parent;
50 m_capacitor = capacitor;
51}
52
53ReactiveShuntElementForm::ReactiveShuntElementForm(wxWindow* parent, Inductor* inductor)
54 : ReactiveShuntElementFormBase(parent)
55{
56 InductorElectricalData data = inductor->GetElectricalData();
57
58 m_textCtrlName->SetValue(data.name);
59
60 m_textCtrlReactivePower->SetValue(Inductor::StringFromDouble(data.reactivePower));
61 switch(data.reactivePowerUnit) {
63 m_choiceReactivePower->SetSelection(0);
64 } break;
66 m_choiceReactivePower->SetSelection(1);
67 } break;
69 m_choiceReactivePower->SetSelection(2);
70 } break;
72 m_choiceReactivePower->SetSelection(3);
73 } break;
74 default:
75 break;
76 }
77
78 m_parent = parent;
79 m_inductor = inductor;
80}
81
82ReactiveShuntElementForm::~ReactiveShuntElementForm() {}
83void ReactiveShuntElementForm::OnOKButtonClick(wxCommandEvent& event)
84{
85 if(ValidateData()) EndModal(wxID_OK);
86}
87
88void ReactiveShuntElementForm::OnStabilityButtonClick(wxCommandEvent& event)
89{
90 if(ValidateData()) {
91 if(m_capacitor) {
92 SwitchingForm swForm(m_parent, m_capacitor);
93 swForm.SetTitle(_("Capacitor: Switching"));
94 swForm.ShowModal();
95 } else if(m_inductor) {
96 SwitchingForm swForm(m_parent, m_inductor);
97 swForm.SetTitle(_("Inductor: Switching"));
98 swForm.ShowModal();
99 }
100
101 EndModal(wxID_OK);
102 }
103}
104
105bool ReactiveShuntElementForm::ValidateData()
106{
107 if(m_capacitor) {
109
110 data.name = m_textCtrlName->GetValue();
111
112 if(!m_capacitor->DoubleFromString(m_parent, m_textCtrlReactivePower->GetValue(), data.reactivePower,
113 _("Value entered incorrectly in the field \"Reactive power\".")))
114 return false;
115 switch(m_choiceReactivePower->GetSelection()) {
116 case 0: {
117 data.reactivePowerUnit = ElectricalUnit::UNIT_PU;
118 } break;
119 case 1: {
120 data.reactivePowerUnit = ElectricalUnit::UNIT_var;
121 } break;
122 case 2: {
123 data.reactivePowerUnit = ElectricalUnit::UNIT_kvar;
124 } break;
125 case 3: {
126 data.reactivePowerUnit = ElectricalUnit::UNIT_Mvar;
127 } break;
128 }
129
130 m_capacitor->SetElectricalData(data);
131 } else if(m_inductor) {
133
134 data.name = m_textCtrlName->GetValue();
135
136 if(!m_inductor->DoubleFromString(m_parent, m_textCtrlReactivePower->GetValue(), data.reactivePower,
137 _("Value entered incorrectly in the field \"Reactive power\".")))
138 return false;
139 switch(m_choiceReactivePower->GetSelection()) {
140 case 0: {
141 data.reactivePowerUnit = ElectricalUnit::UNIT_PU;
142 } break;
143 case 1: {
144 data.reactivePowerUnit = ElectricalUnit::UNIT_var;
145 } break;
146 case 2: {
147 data.reactivePowerUnit = ElectricalUnit::UNIT_kvar;
148 } break;
149 case 3: {
150 data.reactivePowerUnit = ElectricalUnit::UNIT_Mvar;
151 } break;
152 }
153
154 m_inductor->SetElectricalData(data);
155 }
156 return true;
157}
Shunt capactior power element.
Definition Capacitor.h:39
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
Inductor shunt power element.
Definition Inductor.h:39
Form to edit the switching data of power elements for electromechanical transient studies.