Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
LineForm.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 "LineForm.h"
19#include "SwitchingForm.h"
20#include "../elements/powerElement/Line.h"
21
22LineForm::LineForm(wxWindow* parent, Line* line) : LineFormBase(parent)
23{
24 SetSize(GetBestSize());
25 m_choiceResistance->SetString(1, L'\u03A9');
26 m_choiceResistance->SetString(2, (wxString)L'\u03A9' + "/km");
27 m_choiceResistance->SetInitialSize();
28 m_textCtrlResistance->SetInitialSize();
29
30 m_choiceReactance->SetString(1, L'\u03A9');
31 m_choiceReactance->SetString(2, (wxString)L'\u03A9' + "/km");
32 m_choiceReactance->SetInitialSize();
33 m_textCtrlReactance->SetInitialSize();
34
35 ReplaceStaticTextLabelChar(m_staticTextZeroResistance, L'\u2080');
36 ReplaceStaticTextLabelChar(m_staticTextZeroReactance, L'\u2080');
37 ReplaceStaticTextLabelChar(m_staticTextZeroSusceptance, L'\u2080');
38
39 SetSize(GetBestSize());
40 Layout();
41 m_parent = parent;
42 m_line = line;
43
44 LineElectricalData data = line->GetElectricalData();
45
46 m_textCtrlName->SetValue(data.name);
47
48 wxString nominalVoltageStr = Line::StringFromDouble(data.nominalVoltage);
49 switch(data.nominalVoltageUnit) {
51 nominalVoltageStr += " V";
52 } break;
54 nominalVoltageStr += " kV";
55 } break;
56 default:
57 break;
58 }
59 m_staticTextNominalVoltageValue->SetLabel(nominalVoltageStr);
60
61 m_textCtrlNominalPower->SetValue(Line::StringFromDouble(data.nominalPower));
62 switch(data.nominalPowerUnit) {
64 m_choiceNominalPower->SetSelection(0);
65 } break;
67 m_choiceNominalPower->SetSelection(1);
68 } break;
70 m_choiceNominalPower->SetSelection(2);
71 } break;
72 default:
73 break;
74 }
75
76 m_textCtrlResistance->SetValue(Line::StringFromDouble(data.resistance));
77 switch(data.resistanceUnit) {
79 m_choiceResistance->SetSelection(0);
80 } break;
82 m_choiceResistance->SetSelection(1);
83 } break;
85 m_choiceResistance->SetSelection(2);
86 } break;
87 default:
88 break;
89 }
90
91 m_textCtrlReactance->SetValue(Line::StringFromDouble(data.indReactance));
92 switch(data.indReactanceUnit) {
94 m_choiceReactance->SetSelection(0);
95 } break;
97 m_choiceReactance->SetSelection(1);
98 } break;
100 m_choiceReactance->SetSelection(2);
101 } break;
102 default:
103 break;
104 }
105
106 m_textCtrlSusceptance->SetValue(Line::StringFromDouble(data.capSusceptance));
107 switch(data.capSusceptanceUnit) {
109 m_choiceSusceptance->SetSelection(0);
110 } break;
112 m_choiceSusceptance->SetSelection(1);
113 } break;
115 m_choiceSusceptance->SetSelection(2);
116 } break;
117 default:
118 break;
119 }
120
121 m_textCtrlLineSize->SetValue(Line::StringFromDouble(data.lineSize));
122 m_checkUseLinePower->SetValue(data.useLinePower);
123
124 m_textCtrlZeroResistance->SetValue(Line::StringFromDouble(data.zeroResistance));
125 m_textCtrlZeroReactance->SetValue(Line::StringFromDouble(data.zeroIndReactance));
126 m_textCtrlZeroSusceptance->SetValue(Line::StringFromDouble(data.zeroCapSusceptance));
127}
128
129LineForm::~LineForm() {}
130void LineForm::OnCancelButtonClick(wxCommandEvent& event) { EndModal(wxID_CANCEL); }
131void LineForm::OnOKButtonClick(wxCommandEvent& event)
132{
133 if(ValidateData()) EndModal(wxID_OK);
134}
135
136void LineForm::OnStabilityButtonClick(wxCommandEvent& event)
137{
138 if(ValidateData()) {
139 SwitchingForm swForm(m_parent, m_line);
140 swForm.SetTitle(_("Line: Switching"));
141 swForm.ShowModal();
142 EndModal(wxID_OK);
143 }
144}
145
146void LineForm::ReplaceStaticTextLabelChar(wxStaticText* staticText, wchar_t newChar)
147{
148 wxString label = staticText->GetLabel();
149 label[label.length() - 2] = newChar;
150 staticText->SetLabel(label);
151}
152
153bool LineForm::ValidateData()
154{
155 LineElectricalData data = m_line->GetElectricalData();
156
157 data.name = m_textCtrlName->GetValue();
158
159 if(!m_line->DoubleFromString(m_parent, m_textCtrlNominalPower->GetValue(), data.nominalPower,
160 _("Value entered incorrectly in the field \"Nominal power\".")))
161 return false;
162 switch(m_choiceNominalPower->GetSelection()) {
163 case 0: {
164 data.nominalPowerUnit = ElectricalUnit::UNIT_VA;
165 } break;
166 case 1: {
167 data.nominalPowerUnit = ElectricalUnit::UNIT_kVA;
168 } break;
169 case 2: {
170 data.nominalPowerUnit = ElectricalUnit::UNIT_MVA;
171 } break;
172 }
173
174 if(!m_line->DoubleFromString(m_parent, m_textCtrlResistance->GetValue(), data.resistance,
175 _("Value entered incorrectly in the field \"Resistance\".")))
176 return false;
177 switch(m_choiceResistance->GetSelection()) {
178 case 0: {
179 data.resistanceUnit = ElectricalUnit::UNIT_PU;
180 } break;
181 case 1: {
182 data.resistanceUnit = ElectricalUnit::UNIT_OHM;
183 } break;
184 case 2: {
185 data.resistanceUnit = ElectricalUnit::UNIT_OHM_km;
186 } break;
187 }
188
189 if(!m_line->DoubleFromString(m_parent, m_textCtrlReactance->GetValue(), data.indReactance,
190 _("Value entered incorrectly in the field \"Indutive Reactance\".")))
191 return false;
192 switch(m_choiceReactance->GetSelection()) {
193 case 0: {
194 data.indReactanceUnit = ElectricalUnit::UNIT_PU;
195 } break;
196 case 1: {
197 data.indReactanceUnit = ElectricalUnit::UNIT_OHM;
198 } break;
199 case 2: {
200 data.indReactanceUnit = ElectricalUnit::UNIT_OHM_km;
201 } break;
202 }
203
204 if(!m_line->DoubleFromString(m_parent, m_textCtrlSusceptance->GetValue(), data.capSusceptance,
205 _("Value entered incorrectly in the field \"Capacitive Susceptance\".")))
206 return false;
207 switch(m_choiceSusceptance->GetSelection()) {
208 case 0: {
209 data.capSusceptanceUnit = ElectricalUnit::UNIT_PU;
210 } break;
211 case 1: {
212 data.capSusceptanceUnit = ElectricalUnit::UNIT_S;
213 } break;
214 case 2: {
215 data.capSusceptanceUnit = ElectricalUnit::UNIT_S_km;
216 } break;
217 }
218
219 if(!m_line->DoubleFromString(m_parent, m_textCtrlLineSize->GetValue(), data.lineSize,
220 _("Value entered incorrectly in the field \"Line size\".")))
221 return false;
222
223 data.useLinePower = m_checkUseLinePower->GetValue();
224
225 if(!m_line->DoubleFromString(m_parent, m_textCtrlZeroResistance->GetValue(), data.zeroResistance,
226 _("Value entered incorrectly in the field \"Zero-sequence resistance\".")))
227 return false;
228 if(!m_line->DoubleFromString(m_parent, m_textCtrlZeroReactance->GetValue(), data.zeroIndReactance,
229 _("Value entered incorrectly in the field \"Zero-sequence indutive reactance\".")))
230 return false;
231 if(!m_line->DoubleFromString(m_parent, m_textCtrlZeroSusceptance->GetValue(), data.zeroCapSusceptance,
232 _("Value entered incorrectly in the field \"Zero-sequence capacitive susceptance\".")))
233 return false;
234
235 m_line->SetElectricalData(data);
236
237 return true;
238}
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
Power line element.
Definition Line.h:64
Form to edit the switching data of power elements for electromechanical transient studies.