20#include "../elements/powerElement/Transformer.h"
21#include "../elements/powerElement/Bus.h"
24TransformerForm::TransformerForm(wxWindow* parent,
Transformer* transformer) : TransformerFormBase(parent)
26 m_choiceResistance->SetString(1, L
'\u03A9');
27 m_choiceReactance->SetString(1, L
'\u03A9');
30 m_choiceConnection->SetString(0, _(
"Grounded Wye - Grounded Wye"));
31 m_choiceConnection->SetString(1, _(
"Wye - Grounded Wye"));
32 m_choiceConnection->SetString(2, _(
"Grounded Wye - Wye"));
33 m_choiceConnection->SetString(3, _(
"Wye - Wye"));
34 m_choiceConnection->SetString(4, _(
"Delta - Grounded Wye"));
35 m_choiceConnection->SetString(5, _(
"Delta - Wye"));
36 m_choiceConnection->SetString(6, _(
"Grounded Wye - Delta"));
37 m_choiceConnection->SetString(7, _(
"Wye - Delta"));
38 m_choiceConnection->SetString(8, _(
"Delta - Delta"));
40 SetSize(GetBestSize());
44 m_transformer = transformer;
48 m_textCtrlName->SetValue(data.name);
51 switch (data.primaryNominalVoltageUnit) {
52 case ElectricalUnit::UNIT_V: {
55 case ElectricalUnit::UNIT_kV: {
62 switch (data.secondaryNominalVoltageUnit) {
63 case ElectricalUnit::UNIT_V: {
66 case ElectricalUnit::UNIT_kV: {
72 m_staticTextNominalVoltageValue->SetLabel(wxString::Format(
"%s / %s", primVoltStr, secVoltStr));
74 m_choiceBaseVoltage->SetString(0, primVoltStr);
75 m_choiceBaseVoltage->SetString(1, secVoltStr);
76 m_choiceBaseVoltage->SetSelection(data.baseVoltage);
79 switch (data.nominalPowerUnit) {
80 case ElectricalUnit::UNIT_VA: {
81 m_choiceNominalPower->SetSelection(0);
83 case ElectricalUnit::UNIT_kVA: {
84 m_choiceNominalPower->SetSelection(1);
86 case ElectricalUnit::UNIT_MVA: {
87 m_choiceNominalPower->SetSelection(2);
94 switch (data.resistanceUnit) {
95 case ElectricalUnit::UNIT_PU: {
96 m_choiceResistance->SetSelection(0);
98 case ElectricalUnit::UNIT_OHM: {
99 m_choiceResistance->SetSelection(1);
106 switch (data.indReactanceUnit) {
107 case ElectricalUnit::UNIT_PU: {
108 m_choiceReactance->SetSelection(0);
110 case ElectricalUnit::UNIT_OHM: {
111 m_choiceReactance->SetSelection(1);
117 m_choiceConnection->SetSelection(data.connection);
122 m_checkUseTransformerPower->SetValue(data.useTransformerPower);
132 m_checkEnableTapChanger->SetValue(data.hasTapChanger);
134 wxArrayString busChoices;
135 wxString primLabel = _(
"Primary (Bus 1)");
136 wxString secLabel = _(
"Secondary (Bus 2)");
137 if (m_transformer->GetParentList().size() >= 2) {
138 Bus* b1 =
dynamic_cast<Bus*
>(m_transformer->GetParentList()[0]);
139 Bus* b2 =
dynamic_cast<Bus*
>(m_transformer->GetParentList()[1]);
140 if (b1) primLabel = wxString::Format(_(
"%s"), b1->GetElectricalData().name);
141 if (b2) secLabel = wxString::Format(_(
"%s"), b2->GetElectricalData().name);
143 busChoices.Add(primLabel);
144 busChoices.Add(secLabel);
145 m_choiceControlledBus->Append(busChoices);
146 m_choiceControlledBus->SetSelection(data.oltcControlledBus == 0 ? 0 : 1);
147 m_choiceControlledBus->SetMaxSize(wxSize(200, -1));
154 m_checkDiscreteTap->SetValue(data.oltcIsDiscrete);
156 UpdateTapChangerFields();
158 SetSize(GetBestSize());
162void TransformerForm::OnEnableTapChangerCheck(wxCommandEvent& event)
164 UpdateTapChangerFields();
167void TransformerForm::OnDiscreteTapCheck(wxCommandEvent& event)
169 UpdateTapChangerFields();
172void TransformerForm::UpdateTapChangerFields()
174 bool enable = m_checkEnableTapChanger->GetValue();
175 m_staticTextControlledBus->Enable(enable);
176 m_choiceControlledBus->Enable(enable);
177 m_staticTextTargetVoltage->Enable(enable);
178 m_textCtrlTargetVoltage->Enable(enable);
179 m_staticTextDeadband->Enable(enable);
180 m_textCtrlDeadband->Enable(enable);
181 m_staticTextMinTap->Enable(enable);
182 m_textCtrlMinTap->Enable(enable);
183 m_staticTextMaxTap->Enable(enable);
184 m_textCtrlMaxTap->Enable(enable);
185 m_checkDiscreteTap->Enable(enable);
187 m_textCtrlTurnRatio->Enable(!enable);
189 bool discrete = enable && m_checkDiscreteTap->GetValue();
191 m_textCtrlTapStep->Enable(discrete);
194TransformerForm::~TransformerForm() {}
195void TransformerForm::OnCancelButtonClick(wxCommandEvent& event) { EndModal(wxID_CANCEL); }
196void TransformerForm::OnOKButtonClick(wxCommandEvent& event)
198 if (ValidateData()) EndModal(wxID_OK);
200void TransformerForm::OnStabilityButtonClick(wxCommandEvent& event)
202 if (ValidateData()) {
204 swForm.SetTitle(_(
"Transfomer: Switching"));
210bool TransformerForm::ValidateData()
214 data.name = m_textCtrlName->GetValue();
215 data.baseVoltage = m_choiceBaseVoltage->GetSelection();
217 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlNominalPower->GetValue(), data.nominalPower,
218 _(
"Value entered incorrectly in the field \"Nominal power\".")))
220 switch (m_choiceNominalPower->GetSelection()) {
222 data.nominalPowerUnit = ElectricalUnit::UNIT_VA;
225 data.nominalPowerUnit = ElectricalUnit::UNIT_kVA;
228 data.nominalPowerUnit = ElectricalUnit::UNIT_MVA;
232 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlResistance->GetValue(), data.resistance,
233 _(
"Value entered incorrectly in the field \"Resistance\".")))
235 switch (m_choiceResistance->GetSelection()) {
237 data.resistanceUnit = ElectricalUnit::UNIT_PU;
240 data.resistanceUnit = ElectricalUnit::UNIT_OHM;
244 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlReactance->GetValue(), data.indReactance,
245 _(
"Value entered incorrectly in the field \"Indutive reactance\".")))
247 switch (m_choiceReactance->GetSelection()) {
249 data.indReactanceUnit = ElectricalUnit::UNIT_PU;
252 data.indReactanceUnit = ElectricalUnit::UNIT_OHM;
256 switch (m_choiceConnection->GetSelection()) {
258 data.connection = GWYE_GWYE;
261 data.connection = WYE_GWYE;
264 data.connection = GWYE_WYE;
267 data.connection = WYE_WYE;
270 data.connection = DELTA_GWYE;
273 data.connection = DELTA_WYE;
276 data.connection = GWYE_DELTA;
279 data.connection = WYE_DELTA;
282 data.connection = DELTA_DELTA;
286 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlTurnRatio->GetValue(), data.turnsRatio,
287 _(
"Value entered incorrectly in the field \"Turns ratio\".")))
290 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlPhaseShift->GetValue(), data.phaseShift,
291 _(
"Value entered incorrectly in the field \"Phase shift\".")))
294 data.useTransformerPower = m_checkUseTransformerPower->GetValue();
296 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlZeroResistance->GetValue(), data.zeroResistance,
297 _(
"Value entered incorrectly in the field \"Zero sequence resistance\".")))
301 m_parent, m_textCtrlZeroReactance->GetValue(), data.zeroIndReactance,
302 _(
"Value entered incorrectly in the field \"Zero sequence indutive reactance\".")))
305 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlPrimResistance->GetValue(), data.primaryGrndResistance,
306 _(
"Value entered incorrectly in the field \"Primary ground resistance\".")))
309 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlPrimReactance->GetValue(), data.primaryGrndReactance,
310 _(
"Value entered incorrectly in the field \"Primary ground reactance\".")))
313 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlSecResistance->GetValue(), data.secondaryGrndResistance,
314 _(
"Value entered incorrectly in the field \"Secondary ground resistance\".")))
317 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlSecReactance->GetValue(), data.secondaryGrndReactance,
318 _(
"Value entered incorrectly in the field \"Secondary ground reactance\".")))
321 data.hasTapChanger = m_checkEnableTapChanger->GetValue();
322 if (data.hasTapChanger) {
323 data.oltcControlledBus = (m_choiceControlledBus->GetSelection() == 0) ? 0 : 1;
325 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlTargetVoltage->GetValue(), data.oltcTargetVoltage,
326 _(
"Value entered incorrectly in the field \"Target voltage\".")))
328 if (data.oltcTargetVoltage <= 0.0) {
329 wxMessageBox(_(
"Target voltage must be greater than 0."), _(
"Error"), wxOK | wxICON_ERROR, m_parent);
333 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlDeadband->GetValue(), data.oltcVoltageDeadband,
334 _(
"Value entered incorrectly in the field \"Voltage deadband\".")))
336 if (data.oltcVoltageDeadband < 0.0) {
337 wxMessageBox(_(
"Voltage deadband cannot be negative."), _(
"Error"), wxOK | wxICON_ERROR, m_parent);
341 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlMinTap->GetValue(), data.oltcMinTap,
342 _(
"Value entered incorrectly in the field \"Minimum tap\".")))
344 if (data.oltcMinTap <= 0.0) {
345 wxMessageBox(_(
"Minimum tap must be greater than 0."), _(
"Error"), wxOK | wxICON_ERROR, m_parent);
349 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlMaxTap->GetValue(), data.oltcMaxTap,
350 _(
"Value entered incorrectly in the field \"Maximum tap\".")))
352 if (data.oltcMaxTap < data.oltcMinTap) {
353 wxMessageBox(_(
"Maximum tap must be greater than or equal to minimum tap."), _(
"Error"), wxOK | wxICON_ERROR, m_parent);
357 data.oltcIsDiscrete = m_checkDiscreteTap->GetValue();
359 if (!m_transformer->
DoubleFromString(m_parent, m_textCtrlTapStep->GetValue(), data.oltcTapStep,
360 _(
"Value entered incorrectly in the field \"Tap step size\".")))
362 if (data.oltcTapStep < 0.0) {
363 wxMessageBox(_(
"Tap step size cannot be negative."), _(
"Error"), wxOK | wxICON_ERROR, m_parent);
368 data.turnsRatio = std::clamp(data.turnsRatio, data.oltcMinTap, data.oltcMaxTap);
371 if (data.oltcIsDiscrete && data.oltcTapStep > 1e-4) {
372 data.turnsRatio = 1.0 + std::round((data.turnsRatio - 1.0) / data.oltcTapStep) * data.oltcTapStep;
373 data.turnsRatio = std::clamp(data.turnsRatio, data.oltcMinTap, data.oltcMaxTap);
376 data.nominalTurnsRatio = data.turnsRatio;
378 m_transformer->SetElectricaData(data);
Node for power elements. All others power elements are connected through this.
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.
static wxString StringFromDouble(double value, int minDecimal=1, int maxDecimals=13)
Convert a double value to string.