19#include "../utils/PropertiesData.h"
21SimulationsSettingsForm::SimulationsSettingsForm(wxWindow* parent,
PropertiesData* properties, wxLocale* locale)
22 : SimulationsSettingsFormBase(parent)
24 m_properties = properties;
25 auto data = m_properties->GetSimulationPropertiesData();
28 switch (data.basePowerUnit) {
30 m_choiceBasePower->SetSelection(0);
33 m_choiceBasePower->SetSelection(1);
36 m_choiceBasePower->SetSelection(2);
39 m_choiceBasePower->SetSelection(wxNOT_FOUND);
42 m_checkBoxFaultAfterPF->SetValue(data.faultAfterPowerFlow);
43 m_checkBoxSCPowerAfterPF->SetValue(data.scPowerAfterPowerFlow);
44 m_checkBoxTHDAfterPF->SetValue(data.harmDistortionAfterPowerFlow);
45 switch (data.powerFlowMethod) {
46 case NEWTON_RAPHSON : {
47 m_choicePFMethod->SetSelection(0);
50 m_choicePFMethod->SetSelection(1);
53 m_choicePFMethod->SetSelection(2);
56 m_choicePFMethod->SetSelection(wxNOT_FOUND);
60 m_textCtrlPFTolerance->SetValue(wxString::Format(
"%g", data.powerFlowTolerance));
61 m_textCtrlPFMaxIterations->SetValue(wxString::Format(
"%d", data.powerFlowMaxIterations));
64 m_textCtrlPFGaussTolerance->SetValue(wxString::Format(
"%g", data.gaussTolerance));
65 m_textCtrlTimeStep->SetValue(wxString::Format(
"%g", data.timeStep));
68 m_textCtrlStabTolerance->SetValue(wxString::Format(
"%g", data.stabilityTolerance));
69 m_textCtrlStabMaxIterations->SetValue(wxString::Format(
"%d", data.stabilityMaxIterations));
70 m_textCtrlCtrlStepRatio->SetValue(wxString::Format(
"%d", data.controlTimeStepRatio));
71 m_textCtrlPrintTime->SetValue(wxString::Format(
"%g", data.plotTime));
73 m_checkBoxUseCOI->SetValue(data.useCOI);
75 m_checkBoxUseCompLoads->SetValue(data.useCompLoads);
87 m_radioBoxBusFreqEstimation->SetSelection(
static_cast<int>(data.busFreqEstimation));
88 m_checkBoxBusFreqIgnoreEvent->SetValue(data.ignoreBusFreqEventStep);
92 m_choiceHarmLoadConn->SetSelection(
static_cast<int>(data.harmLoadConnection));
94 if (locale->GetCanonicalName() == wxT(
"pt_BR")) {
96 wfDiagram.LoadFile(wxT(
"../data/images/WF-pt.png"), wxBITMAP_TYPE_PNG);
97 m_staticBitmapDiagram->SetBitmap(wfDiagram);
100 UpdateZIPLoadFieldStatus();
101 UpdatePFFieldStatus();
102 UpdateBusFreqFieldStatus();
105SimulationsSettingsForm::~SimulationsSettingsForm() {}
106void SimulationsSettingsForm::OnButtonOKClick(wxCommandEvent& event)
108 if (ValidateData()) EndModal(wxID_OK);
111bool SimulationsSettingsForm::ValidateData()
113 auto data = m_properties->GetSimulationPropertiesData();
115 _(
"Value entered incorrectly in the field \"Base power\".")))
117 switch (m_choiceBasePower->GetSelection()) {
128 data.faultAfterPowerFlow = m_checkBoxFaultAfterPF->GetValue();
129 data.scPowerAfterPowerFlow = m_checkBoxSCPowerAfterPF->GetValue();
130 data.harmDistortionAfterPowerFlow = m_checkBoxTHDAfterPF->GetValue();
131 switch (m_choicePFMethod->GetSelection()) {
133 data.powerFlowMethod = NEWTON_RAPHSON;
136 data.powerFlowMethod = GAUSS_SEIDEL;
139 data.powerFlowMethod = GAUSS_NEWTON;
143 _(
"Value entered incorrectly in the field \"Acceleration factor\".")))
146 _(
"Value entered incorrectly in the field \"Tolerance (Power flow)\".")))
149 _(
"Value entered incorrectly in the field \"Max. iterations (Power flow)\".")))
152 _(
"Value entered incorrectly in the field \"Slack bus angle\".")))
155 _(
"Value entered incorrectly in the field \"Newton inertia (Power flow)\".")))
158 _(
"Value entered incorrectly in the field \"Gauss tolerance (Power flow)\".")))
161 _(
"Value entered incorrectly in the field \"Time step\".")))
164 _(
"Value entered incorrectly in the field \"Simulation time\".")))
167 _(
"Value entered incorrectly in the field \"System frequency\".")))
170 _(
"Value entered incorrectly in the field \"Tolerance (stability)\".")))
173 _(
"Value entered incorrectly in the field \"Max. iterations (stability)\".")))
176 _(
"Value entered incorrectly in the field \"Controls step ratio\".")))
179 _(
"Value entered incorrectly in the field \"Plot time\".")))
181 data.useCOI = m_checkBoxUseCOI->GetValue();
183 data.useCompLoads = m_checkBoxUseCompLoads->GetValue();
186 this, m_textCtrlActivePowerImp->GetValue(), data.constImpedanceActive,
187 _(
"Value entered incorrectly in the field \"Constant impedance portion of active power (ZIP load)\".")))
190 this, m_textCtrlActivePowerCur->GetValue(), data.constCurrentActive,
191 _(
"Value entered incorrectly in the field \"Constant current portion of active power (ZIP load)\".")))
194 this, m_textCtrlActivePowerPow->GetValue(), data.constPowerActive,
195 _(
"Value entered incorrectly in the field \"Constant power portion of active power (ZIP load)\".")))
198 this, m_textCtrlReactivePowerImp->GetValue(), data.constImpedanceReactive,
199 _(
"Value entered incorrectly in the field \"Constant impedance portion of reactive power (ZIP load)\".")))
202 this, m_textCtrlReactivePowerCur->GetValue(), data.constCurrentReactive,
203 _(
"Value entered incorrectly in the field \"Constant current portion of reactive power (ZIP load)\".")))
206 this, m_textCtrlReactivePowerPow->GetValue(), data.constPowerReactive,
207 _(
"Value entered incorrectly in the field \"Constant power portion of reactive power (ZIP load)\".")))
211 this, m_textCtrlUVCur->GetValue(), data.underVoltageConstCurrent,
212 _(
"Value entered incorrectly in the field \"Constant current undervoltage limit (ZIP load)\".")))
216 this, m_textCtrlUVPow->GetValue(), data.underVoltageConstPower,
217 _(
"Value entered incorrectly in the field \"Constant power undervoltage limit (ZIP load)\".")))
220 double sum = data.constImpedanceActive + data.constCurrentActive + data.constPowerActive;
221 if (sum > 100.01 || sum < 99.99) {
222 wxMessageDialog msgDialog(
this, _(
"The sum of active power load composition must be 100%."), _(
"Error"),
223 wxOK | wxCENTRE | wxICON_ERROR);
224 msgDialog.ShowModal();
227 sum = data.constImpedanceReactive + data.constCurrentReactive + data.constPowerReactive;
228 if (sum > 100.01 || sum < 99.99) {
229 wxMessageDialog msgDialog(
this, _(
"The sum of reactive power load composition must be 100%."), _(
"Error"),
230 wxOK | wxCENTRE | wxICON_ERROR);
231 msgDialog.ShowModal();
235 data.busFreqEstimation =
static_cast<BusFreqEstimation
>(m_radioBoxBusFreqEstimation->GetSelection());
237 if (m_checkBoxBusFreqIgnoreEvent->IsShown()) {
238 data.ignoreBusFreqEventStep = m_checkBoxBusFreqIgnoreEvent->GetValue();
241 if (m_textCtrlTf->IsShown()) {
243 this, m_textCtrlTf->GetValue(), data.tf,
244 _(
"Value entered incorrectly in the field \"Time constant Tf (Bus Frequency)\".")))
247 if (m_textCtrlTw->IsShown()) {
249 this, m_textCtrlTw->GetValue(), data.tw,
250 _(
"Value entered incorrectly in the field \"Time constant Tw (Bus Frequency)\".")))
254 data.harmLoadConnection =
static_cast<HarmLoadConnection
>(m_choiceHarmLoadConn->GetSelection());
256 m_properties->SetSimulationPropertiesData(data);
260void SimulationsSettingsForm::OnPFMethodChoiceSelected(wxCommandEvent& event) { UpdatePFFieldStatus(); }
262void SimulationsSettingsForm::UpdateZIPLoadFieldStatus()
264 m_textCtrlActivePowerImp->Enable(m_checkBoxUseCompLoads->GetValue());
265 m_textCtrlActivePowerCur->Enable(m_checkBoxUseCompLoads->GetValue());
266 m_textCtrlActivePowerPow->Enable(m_checkBoxUseCompLoads->GetValue());
267 m_textCtrlReactivePowerImp->Enable(m_checkBoxUseCompLoads->GetValue());
268 m_textCtrlReactivePowerCur->Enable(m_checkBoxUseCompLoads->GetValue());
269 m_textCtrlReactivePowerPow->Enable(m_checkBoxUseCompLoads->GetValue());
272void SimulationsSettingsForm::UpdatePFFieldStatus()
274 if (m_choicePFMethod->GetSelection() == 1 || m_choicePFMethod->GetSelection() == 2)
275 m_textCtrlAccFactor->Enable();
277 m_textCtrlAccFactor->Enable(
false);
278 if (m_choicePFMethod->GetSelection() == 2)
279 m_textCtrlPFGaussTolerance->Enable();
281 m_textCtrlPFGaussTolerance->Enable(
false);
282 if (m_choicePFMethod->GetSelection() == 0 || m_choicePFMethod->GetSelection() == 2)
283 m_textCtrlPFNewtonInertia->Enable();
285 m_textCtrlPFNewtonInertia->Enable(
false);
287void SimulationsSettingsForm::UpdateBusFreqFieldStatus()
290 if (m_radioBoxBusFreqEstimation->GetSelection() == 0) visible =
false;
291 m_checkBoxBusFreqIgnoreEvent->Show(!visible);
292 m_staticTextTf->Show(visible);
293 m_textCtrlTf->Show(visible);
294 m_staticTextTw->Show(visible);
295 m_textCtrlTw->Show(visible);
296 m_staticBitmapDiagram->Show(visible);
299void SimulationsSettingsForm::OnBusFreqEstimationSelect(wxCommandEvent& event)
301 UpdateBusFreqFieldStatus();
static bool IntFromString(wxWindow *parent, wxString strValue, int &value, wxString errorMsg)
Convert a string to int. Show a error message if the conversion fail.
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.
General and simulation data manager.