19#include "../utils/PropertiesData.h"
20#include "../utils/Path.h"
22SimulationsSettingsForm::SimulationsSettingsForm(wxWindow* parent,
PropertiesData* properties, wxLocale* locale)
23 : SimulationsSettingsFormBase(parent)
25 m_properties = properties;
26 auto data = m_properties->GetSimulationPropertiesData();
29 switch (data.basePowerUnit) {
31 m_choiceBasePower->SetSelection(0);
34 m_choiceBasePower->SetSelection(1);
37 m_choiceBasePower->SetSelection(2);
40 m_choiceBasePower->SetSelection(wxNOT_FOUND);
43 m_checkBoxFaultAfterPF->SetValue(data.faultAfterPowerFlow);
44 m_checkBoxSCPowerAfterPF->SetValue(data.scPowerAfterPowerFlow);
45 m_checkBoxTHDAfterPF->SetValue(data.harmDistortionAfterPowerFlow);
46 switch (data.powerFlowMethod) {
47 case NEWTON_RAPHSON : {
48 m_choicePFMethod->SetSelection(0);
51 m_choicePFMethod->SetSelection(1);
54 m_choicePFMethod->SetSelection(2);
57 m_choicePFMethod->SetSelection(wxNOT_FOUND);
61 m_textCtrlPFTolerance->SetValue(wxString::Format(
"%g", data.powerFlowTolerance));
62 m_textCtrlPFMaxIterations->SetValue(wxString::Format(
"%d", data.powerFlowMaxIterations));
65 m_textCtrlPFGaussTolerance->SetValue(wxString::Format(
"%g", data.gaussTolerance));
66 m_textCtrlTimeStep->SetValue(wxString::Format(
"%g", data.timeStep));
69 m_textCtrlStabTolerance->SetValue(wxString::Format(
"%g", data.stabilityTolerance));
70 m_textCtrlStabMaxIterations->SetValue(wxString::Format(
"%d", data.stabilityMaxIterations));
71 m_textCtrlCtrlStepRatio->SetValue(wxString::Format(
"%d", data.controlTimeStepRatio));
72 m_textCtrlPrintTime->SetValue(wxString::Format(
"%g", data.plotTime));
74 m_checkBoxUseCOI->SetValue(data.useCOI);
76 m_checkBoxUseCompLoads->SetValue(data.useCompLoads);
88 m_radioBoxBusFreqEstimation->SetSelection(
static_cast<int>(data.busFreqEstimation));
89 m_checkBoxBusFreqIgnoreEvent->SetValue(data.ignoreBusFreqEventStep);
93 m_choiceHarmLoadConn->SetSelection(
static_cast<int>(data.harmLoadConnection));
95 if (locale->GetCanonicalName() == wxT(
"pt_BR")) {
97 wfDiagram.LoadFile(Paths::GetDataPath() +
"/images/WF-pt.png", wxBITMAP_TYPE_PNG);
98 m_staticBitmapDiagram->SetBitmap(wfDiagram);
101 UpdateZIPLoadFieldStatus();
102 UpdatePFFieldStatus();
103 UpdateBusFreqFieldStatus();
106SimulationsSettingsForm::~SimulationsSettingsForm() {}
107void SimulationsSettingsForm::OnButtonOKClick(wxCommandEvent& event)
109 if (ValidateData()) EndModal(wxID_OK);
112bool SimulationsSettingsForm::ValidateData()
114 auto data = m_properties->GetSimulationPropertiesData();
116 _(
"Value entered incorrectly in the field \"Base power\".")))
118 switch (m_choiceBasePower->GetSelection()) {
129 data.faultAfterPowerFlow = m_checkBoxFaultAfterPF->GetValue();
130 data.scPowerAfterPowerFlow = m_checkBoxSCPowerAfterPF->GetValue();
131 data.harmDistortionAfterPowerFlow = m_checkBoxTHDAfterPF->GetValue();
132 switch (m_choicePFMethod->GetSelection()) {
134 data.powerFlowMethod = NEWTON_RAPHSON;
137 data.powerFlowMethod = GAUSS_SEIDEL;
140 data.powerFlowMethod = GAUSS_NEWTON;
144 _(
"Value entered incorrectly in the field \"Acceleration factor\".")))
147 _(
"Value entered incorrectly in the field \"Tolerance (Power flow)\".")))
150 _(
"Value entered incorrectly in the field \"Max. iterations (Power flow)\".")))
153 _(
"Value entered incorrectly in the field \"Slack bus angle\".")))
156 _(
"Value entered incorrectly in the field \"Newton inertia (Power flow)\".")))
159 _(
"Value entered incorrectly in the field \"Gauss tolerance (Power flow)\".")))
162 _(
"Value entered incorrectly in the field \"Time step\".")))
165 _(
"Value entered incorrectly in the field \"Simulation time\".")))
168 _(
"Value entered incorrectly in the field \"System frequency\".")))
171 _(
"Value entered incorrectly in the field \"Tolerance (stability)\".")))
174 _(
"Value entered incorrectly in the field \"Max. iterations (stability)\".")))
177 _(
"Value entered incorrectly in the field \"Controls step ratio\".")))
180 _(
"Value entered incorrectly in the field \"Plot time\".")))
182 data.useCOI = m_checkBoxUseCOI->GetValue();
184 data.useCompLoads = m_checkBoxUseCompLoads->GetValue();
187 this, m_textCtrlActivePowerImp->GetValue(), data.constImpedanceActive,
188 _(
"Value entered incorrectly in the field \"Constant impedance portion of active power (ZIP load)\".")))
191 this, m_textCtrlActivePowerCur->GetValue(), data.constCurrentActive,
192 _(
"Value entered incorrectly in the field \"Constant current portion of active power (ZIP load)\".")))
195 this, m_textCtrlActivePowerPow->GetValue(), data.constPowerActive,
196 _(
"Value entered incorrectly in the field \"Constant power portion of active power (ZIP load)\".")))
199 this, m_textCtrlReactivePowerImp->GetValue(), data.constImpedanceReactive,
200 _(
"Value entered incorrectly in the field \"Constant impedance portion of reactive power (ZIP load)\".")))
203 this, m_textCtrlReactivePowerCur->GetValue(), data.constCurrentReactive,
204 _(
"Value entered incorrectly in the field \"Constant current portion of reactive power (ZIP load)\".")))
207 this, m_textCtrlReactivePowerPow->GetValue(), data.constPowerReactive,
208 _(
"Value entered incorrectly in the field \"Constant power portion of reactive power (ZIP load)\".")))
212 this, m_textCtrlUVCur->GetValue(), data.underVoltageConstCurrent,
213 _(
"Value entered incorrectly in the field \"Constant current undervoltage limit (ZIP load)\".")))
217 this, m_textCtrlUVPow->GetValue(), data.underVoltageConstPower,
218 _(
"Value entered incorrectly in the field \"Constant power undervoltage limit (ZIP load)\".")))
221 double sum = data.constImpedanceActive + data.constCurrentActive + data.constPowerActive;
222 if (sum > 100.01 || sum < 99.99) {
223 wxMessageDialog msgDialog(
this, _(
"The sum of active power load composition must be 100%."), _(
"Error"),
224 wxOK | wxCENTRE | wxICON_ERROR);
225 msgDialog.ShowModal();
228 sum = data.constImpedanceReactive + data.constCurrentReactive + data.constPowerReactive;
229 if (sum > 100.01 || sum < 99.99) {
230 wxMessageDialog msgDialog(
this, _(
"The sum of reactive power load composition must be 100%."), _(
"Error"),
231 wxOK | wxCENTRE | wxICON_ERROR);
232 msgDialog.ShowModal();
236 data.busFreqEstimation =
static_cast<BusFreqEstimation
>(m_radioBoxBusFreqEstimation->GetSelection());
238 if (m_checkBoxBusFreqIgnoreEvent->IsShown()) {
239 data.ignoreBusFreqEventStep = m_checkBoxBusFreqIgnoreEvent->GetValue();
242 if (m_textCtrlTf->IsShown()) {
244 this, m_textCtrlTf->GetValue(), data.tf,
245 _(
"Value entered incorrectly in the field \"Time constant Tf (Bus Frequency)\".")))
248 if (m_textCtrlTw->IsShown()) {
250 this, m_textCtrlTw->GetValue(), data.tw,
251 _(
"Value entered incorrectly in the field \"Time constant Tw (Bus Frequency)\".")))
255 data.harmLoadConnection =
static_cast<HarmLoadConnection
>(m_choiceHarmLoadConn->GetSelection());
257 m_properties->SetSimulationPropertiesData(data);
261void SimulationsSettingsForm::OnPFMethodChoiceSelected(wxCommandEvent& event) { UpdatePFFieldStatus(); }
263void SimulationsSettingsForm::UpdateZIPLoadFieldStatus()
265 m_textCtrlActivePowerImp->Enable(m_checkBoxUseCompLoads->GetValue());
266 m_textCtrlActivePowerCur->Enable(m_checkBoxUseCompLoads->GetValue());
267 m_textCtrlActivePowerPow->Enable(m_checkBoxUseCompLoads->GetValue());
268 m_textCtrlReactivePowerImp->Enable(m_checkBoxUseCompLoads->GetValue());
269 m_textCtrlReactivePowerCur->Enable(m_checkBoxUseCompLoads->GetValue());
270 m_textCtrlReactivePowerPow->Enable(m_checkBoxUseCompLoads->GetValue());
273void SimulationsSettingsForm::UpdatePFFieldStatus()
275 if (m_choicePFMethod->GetSelection() == 1 || m_choicePFMethod->GetSelection() == 2)
276 m_textCtrlAccFactor->Enable();
278 m_textCtrlAccFactor->Enable(
false);
279 if (m_choicePFMethod->GetSelection() == 2)
280 m_textCtrlPFGaussTolerance->Enable();
282 m_textCtrlPFGaussTolerance->Enable(
false);
283 if (m_choicePFMethod->GetSelection() == 0 || m_choicePFMethod->GetSelection() == 2)
284 m_textCtrlPFNewtonInertia->Enable();
286 m_textCtrlPFNewtonInertia->Enable(
false);
288void SimulationsSettingsForm::UpdateBusFreqFieldStatus()
291 if (m_radioBoxBusFreqEstimation->GetSelection() == 0) visible =
false;
292 m_checkBoxBusFreqIgnoreEvent->Show(!visible);
293 m_staticTextTf->Show(visible);
294 m_textCtrlTf->Show(visible);
295 m_staticTextTw->Show(visible);
296 m_textCtrlTw->Show(visible);
297 m_staticBitmapDiagram->Show(visible);
300void SimulationsSettingsForm::OnBusFreqEstimationSelect(wxCommandEvent& event)
302 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.