Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
LoadForm.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 "LoadForm.h"
19#include "SwitchingForm.h"
20#include "../elements/powerElement/Load.h"
21
22LoadForm::LoadForm(wxWindow* parent, Load* load) : LoadFormBase(parent)
23{
24 SetSize(GetBestSize());
25 LoadElectricalData data = load->GetElectricalData();
26
27 m_textCtrlName->SetValue(data.name);
28
29 m_textCtrlActivePower->SetValue(Load::StringFromDouble(data.activePower));
30 switch(data.activePowerUnit) {
32 m_choiceActivePower->SetSelection(0);
33 } break;
35 m_choiceActivePower->SetSelection(1);
36 } break;
38 m_choiceActivePower->SetSelection(2);
39 } break;
41 m_choiceActivePower->SetSelection(3);
42 } break;
43 default:
44 break;
45 }
46
47 m_textCtrlReactivePower->SetValue(Load::StringFromDouble(data.reactivePower));
48 switch(data.reactivePowerUnit) {
50 m_choiceReactivePower->SetSelection(0);
51 } break;
53 m_choiceReactivePower->SetSelection(1);
54 } break;
56 m_choiceReactivePower->SetSelection(2);
57 } break;
59 m_choiceReactivePower->SetSelection(3);
60 } break;
61 default:
62 break;
63 }
64
65 switch(data.loadType) {
66 case CONST_POWER: {
67 m_choiceType->SetSelection(0);
68 } break;
69 case CONST_IMPEDANCE: {
70 m_choiceType->SetSelection(1);
71 } break;
72 }
73
74 m_checkBoxPlotData->SetValue(data.plotLoad);
75
76 m_checkBoxUseCompLoad->SetValue(data.useCompLoad);
77
78 m_textCtrlActivePowerImp->SetValue(Element::StringFromDouble(data.constImpedanceActive));
79 m_textCtrlActivePowerCur->SetValue(Element::StringFromDouble(data.constCurrentActive));
80 m_textCtrlActivePowerPow->SetValue(Element::StringFromDouble(data.constPowerActive));
81 m_textCtrlReactivePowerImp->SetValue(Element::StringFromDouble(data.constImpedanceReactive));
82 m_textCtrlReactivePowerCur->SetValue(Element::StringFromDouble(data.constCurrentReactive));
83 m_textCtrlReactivePowerPow->SetValue(Element::StringFromDouble(data.constPowerReactive));
84
85 m_parent = parent;
86 m_load = load;
87
88 UpdateZIPLoadFieldStatus();
89}
90
91LoadForm::~LoadForm() {}
92void LoadForm::OnOnButtonClick(wxCommandEvent& event)
93{
94 if(ValidateData()) EndModal(wxID_OK);
95}
96
97void LoadForm::OnStabilityButtonClick(wxCommandEvent& event)
98{
99 if(ValidateData()) {
100 SwitchingForm swForm(m_parent, m_load);
101 swForm.SetTitle(_("Load: Switching"));
102 swForm.ShowModal();
103 EndModal(wxID_OK);
104 }
105}
106
107bool LoadForm::ValidateData()
108{
110
111 data.name = m_textCtrlName->GetValue();
112
113 if(!m_load->DoubleFromString(m_parent, m_textCtrlActivePower->GetValue(), data.activePower,
114 _("Value entered incorrectly in the field \"Active power\".")))
115 return false;
116 switch(m_choiceActivePower->GetSelection()) {
117 case 0: {
118 data.activePowerUnit = ElectricalUnit::UNIT_PU;
119 } break;
120 case 1: {
121 data.activePowerUnit = ElectricalUnit::UNIT_W;
122 } break;
123 case 2: {
124 data.activePowerUnit = ElectricalUnit::UNIT_kW;
125 } break;
126 case 3: {
127 data.activePowerUnit = ElectricalUnit::UNIT_MW;
128 } break;
129 }
130
131 if(!m_load->DoubleFromString(m_parent, m_textCtrlReactivePower->GetValue(), data.reactivePower,
132 _("Value entered incorrectly in the field \"Reactive power\".")))
133 return false;
134 switch(m_choiceReactivePower->GetSelection()) {
135 case 0: {
136 data.reactivePowerUnit = ElectricalUnit::UNIT_PU;
137 } break;
138 case 1: {
139 data.reactivePowerUnit = ElectricalUnit::UNIT_var;
140 } break;
141 case 2: {
142 data.reactivePowerUnit = ElectricalUnit::UNIT_kvar;
143 } break;
144 case 3: {
145 data.reactivePowerUnit = ElectricalUnit::UNIT_Mvar;
146 } break;
147 }
148
149 switch(m_choiceType->GetSelection()) {
150 case 0: {
151 data.loadType = CONST_POWER;
152 } break;
153 case 1: {
154 data.loadType = CONST_IMPEDANCE;
155 } break;
156 }
157
158 data.plotLoad = m_checkBoxPlotData->GetValue();
159
160 data.useCompLoad = m_checkBoxUseCompLoad->GetValue();
161
163 this, m_textCtrlActivePowerImp->GetValue(), data.constImpedanceActive,
164 _("Value entered incorrectly in the field \"Constant impedance portion of active power\".")))
165 return false;
167 this, m_textCtrlActivePowerCur->GetValue(), data.constCurrentActive,
168 _("Value entered incorrectly in the field \"Constant current portion of active power\".")))
169 return false;
171 this, m_textCtrlActivePowerPow->GetValue(), data.constPowerActive,
172 _("Value entered incorrectly in the field \"Constant power portion of active power\".")))
173 return false;
175 this, m_textCtrlReactivePowerImp->GetValue(), data.constImpedanceReactive,
176 _("Value entered incorrectly in the field \"Constant impedance portion of reactive power\".")))
177 return false;
179 this, m_textCtrlReactivePowerCur->GetValue(), data.constCurrentReactive,
180 _("Value entered incorrectly in the field \"Constant current portion of reactive power\".")))
181 return false;
183 this, m_textCtrlReactivePowerPow->GetValue(), data.constPowerReactive,
184 _("Value entered incorrectly in the field \"Constant power portion of reactive power\".")))
185 return false;
186
187 double sum = data.constImpedanceActive + data.constCurrentActive + data.constPowerActive;
188 if(sum > 100.01 || sum < 99.99) {
189 wxMessageDialog msgDialog(this, _("The sum of active power load composition must be 100%."), _("Error"),
190 wxOK | wxCENTRE | wxICON_ERROR);
191 msgDialog.ShowModal();
192 return false;
193 }
194 sum = data.constImpedanceReactive + data.constCurrentReactive + data.constPowerReactive;
195 if(sum > 100.01 || sum < 99.99) {
196 wxMessageDialog msgDialog(this, _("The sum of reactive power load composition must be 100%."), _("Error"),
197 wxOK | wxCENTRE | wxICON_ERROR);
198 msgDialog.ShowModal();
199 return false;
200 }
201
202 m_load->SetElectricalData(data);
203 return true;
204}
205
206void LoadForm::UpdateZIPLoadFieldStatus()
207{
208 m_textCtrlActivePowerImp->Enable(m_checkBoxUseCompLoad->GetValue());
209 m_textCtrlActivePowerCur->Enable(m_checkBoxUseCompLoad->GetValue());
210 m_textCtrlActivePowerPow->Enable(m_checkBoxUseCompLoad->GetValue());
211 m_textCtrlReactivePowerImp->Enable(m_checkBoxUseCompLoad->GetValue());
212 m_textCtrlReactivePowerCur->Enable(m_checkBoxUseCompLoad->GetValue());
213 m_textCtrlReactivePowerPow->Enable(m_checkBoxUseCompLoad->GetValue());
214}
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
Loas shunt power element.
Definition Load.h:74
Form to edit the switching data of power elements for electromechanical transient studies.