19#include "../utils/PropertiesData.h"
20#include "../utils/Path.h"
21#include "../elements/Element.h"
23SimulationsSettingsForm::SimulationsSettingsForm(wxWindow* parent,
PropertiesData* properties, wxLocale* locale)
24 : SimulationsSettingsFormBase(parent)
26 m_properties = properties;
27 auto data = m_properties->GetSimulationPropertiesData();
30 switch (data.basePowerUnit) {
31 case ElectricalUnit::UNIT_VA: {
32 m_choiceBasePower->SetSelection(0);
34 case ElectricalUnit::UNIT_kVA: {
35 m_choiceBasePower->SetSelection(1);
37 case ElectricalUnit::UNIT_MVA: {
38 m_choiceBasePower->SetSelection(2);
41 m_choiceBasePower->SetSelection(wxNOT_FOUND);
44 m_checkBoxFaultAfterPF->SetValue(data.faultAfterPowerFlow);
45 m_checkBoxSCPowerAfterPF->SetValue(data.scPowerAfterPowerFlow);
46 m_checkBoxTHDAfterPF->SetValue(data.harmDistortionAfterPowerFlow);
47 switch (data.powerFlowMethod) {
48 case NEWTON_RAPHSON : {
49 m_choicePFMethod->SetSelection(0);
52 m_choicePFMethod->SetSelection(1);
55 m_choicePFMethod->SetSelection(2);
58 m_choicePFMethod->SetSelection(wxNOT_FOUND);
62 m_textCtrlPFTolerance->SetValue(wxString::Format(
"%g", data.powerFlowTolerance));
63 m_textCtrlPFMaxIterations->SetValue(wxString::Format(
"%d", data.powerFlowMaxIterations));
66 m_textCtrlPFGaussTolerance->SetValue(wxString::Format(
"%g", data.gaussTolerance));
67 m_textCtrlTimeStep->SetValue(wxString::Format(
"%g", data.timeStep));
70 m_textCtrlStabTolerance->SetValue(wxString::Format(
"%g", data.stabilityTolerance));
71 m_textCtrlStabMaxIterations->SetValue(wxString::Format(
"%d", data.stabilityMaxIterations));
72 m_textCtrlCtrlStepRatio->SetValue(wxString::Format(
"%d", data.controlTimeStepRatio));
73 m_textCtrlPrintTime->SetValue(wxString::Format(
"%g", data.plotTime));
75 m_checkBoxUseCOI->SetValue(data.useCOI);
77 m_checkBoxUseCompLoads->SetValue(data.useCompLoads);
89 m_radioBoxBusFreqEstimation->SetSelection(
static_cast<int>(data.busFreqEstimation));
90 m_checkBoxBusFreqIgnoreEvent->SetValue(data.ignoreBusFreqEventStep);
94 m_choiceHarmLoadConn->SetSelection(
static_cast<int>(data.harmLoadConnection));
96 if (locale->GetCanonicalName() == wxT(
"pt_BR")) {
98 wfDiagram.LoadFile(Paths::GetDataPath() +
"/images/WF-pt.png", wxBITMAP_TYPE_PNG);
99 m_staticBitmapDiagram->SetBitmap(wfDiagram);
102 UpdateZIPLoadFieldStatus();
103 UpdatePFFieldStatus();
104 UpdateBusFreqFieldStatus();
107SimulationsSettingsForm::~SimulationsSettingsForm() {}
108void SimulationsSettingsForm::OnButtonOKClick(wxCommandEvent& event)
110 if (ValidateData()) EndModal(wxID_OK);
113bool SimulationsSettingsForm::ValidateData()
115 auto data = m_properties->GetSimulationPropertiesData();
117 _(
"Value entered incorrectly in the field \"Base power\".")))
119 switch (m_choiceBasePower->GetSelection()) {
121 data.basePowerUnit = ElectricalUnit::UNIT_VA;
124 data.basePowerUnit = ElectricalUnit::UNIT_kVA;
127 data.basePowerUnit = ElectricalUnit::UNIT_MVA;
130 data.faultAfterPowerFlow = m_checkBoxFaultAfterPF->GetValue();
131 data.scPowerAfterPowerFlow = m_checkBoxSCPowerAfterPF->GetValue();
132 data.harmDistortionAfterPowerFlow = m_checkBoxTHDAfterPF->GetValue();
133 switch (m_choicePFMethod->GetSelection()) {
135 data.powerFlowMethod = NEWTON_RAPHSON;
138 data.powerFlowMethod = GAUSS_SEIDEL;
141 data.powerFlowMethod = GAUSS_NEWTON;
145 _(
"Value entered incorrectly in the field \"Acceleration factor\".")))
148 _(
"Value entered incorrectly in the field \"Tolerance (Power flow)\".")))
151 _(
"Value entered incorrectly in the field \"Max. iterations (Power flow)\".")))
154 _(
"Value entered incorrectly in the field \"Slack bus angle\".")))
157 _(
"Value entered incorrectly in the field \"Newton inertia (Power flow)\".")))
160 _(
"Value entered incorrectly in the field \"Gauss tolerance (Power flow)\".")))
163 _(
"Value entered incorrectly in the field \"Time step\".")))
166 _(
"Value entered incorrectly in the field \"Simulation time\".")))
169 _(
"Value entered incorrectly in the field \"System frequency\".")))
172 _(
"Value entered incorrectly in the field \"Tolerance (stability)\".")))
175 _(
"Value entered incorrectly in the field \"Max. iterations (stability)\".")))
178 _(
"Value entered incorrectly in the field \"Controls step ratio\".")))
181 _(
"Value entered incorrectly in the field \"Plot time\".")))
183 data.useCOI = m_checkBoxUseCOI->GetValue();
185 data.useCompLoads = m_checkBoxUseCompLoads->GetValue();
188 this, m_textCtrlActivePowerImp->GetValue(), data.constImpedanceActive,
189 _(
"Value entered incorrectly in the field \"Constant impedance portion of active power (ZIP load)\".")))
192 this, m_textCtrlActivePowerCur->GetValue(), data.constCurrentActive,
193 _(
"Value entered incorrectly in the field \"Constant current portion of active power (ZIP load)\".")))
196 this, m_textCtrlActivePowerPow->GetValue(), data.constPowerActive,
197 _(
"Value entered incorrectly in the field \"Constant power portion of active power (ZIP load)\".")))
200 this, m_textCtrlReactivePowerImp->GetValue(), data.constImpedanceReactive,
201 _(
"Value entered incorrectly in the field \"Constant impedance portion of reactive power (ZIP load)\".")))
204 this, m_textCtrlReactivePowerCur->GetValue(), data.constCurrentReactive,
205 _(
"Value entered incorrectly in the field \"Constant current portion of reactive power (ZIP load)\".")))
208 this, m_textCtrlReactivePowerPow->GetValue(), data.constPowerReactive,
209 _(
"Value entered incorrectly in the field \"Constant power portion of reactive power (ZIP load)\".")))
213 this, m_textCtrlUVCur->GetValue(), data.underVoltageConstCurrent,
214 _(
"Value entered incorrectly in the field \"Constant current undervoltage limit (ZIP load)\".")))
218 this, m_textCtrlUVPow->GetValue(), data.underVoltageConstPower,
219 _(
"Value entered incorrectly in the field \"Constant power undervoltage limit (ZIP load)\".")))
222 double sum = data.constImpedanceActive + data.constCurrentActive + data.constPowerActive;
223 if (sum > 100.01 || sum < 99.99) {
224 wxMessageDialog msgDialog(
this, _(
"The sum of active power load composition must be 100%."), _(
"Error"),
225 wxOK | wxCENTRE | wxICON_ERROR);
226 msgDialog.ShowModal();
229 sum = data.constImpedanceReactive + data.constCurrentReactive + data.constPowerReactive;
230 if (sum > 100.01 || sum < 99.99) {
231 wxMessageDialog msgDialog(
this, _(
"The sum of reactive power load composition must be 100%."), _(
"Error"),
232 wxOK | wxCENTRE | wxICON_ERROR);
233 msgDialog.ShowModal();
237 data.busFreqEstimation =
static_cast<BusFreqEstimation
>(m_radioBoxBusFreqEstimation->GetSelection());
239 if (m_checkBoxBusFreqIgnoreEvent->IsShown()) {
240 data.ignoreBusFreqEventStep = m_checkBoxBusFreqIgnoreEvent->GetValue();
243 if (m_textCtrlTf->IsShown()) {
245 this, m_textCtrlTf->GetValue(), data.tf,
246 _(
"Value entered incorrectly in the field \"Time constant Tf (Bus Frequency)\".")))
249 if (m_textCtrlTw->IsShown()) {
251 this, m_textCtrlTw->GetValue(), data.tw,
252 _(
"Value entered incorrectly in the field \"Time constant Tw (Bus Frequency)\".")))
256 data.harmLoadConnection =
static_cast<HarmLoadConnection
>(m_choiceHarmLoadConn->GetSelection());
258 m_properties->SetSimulationPropertiesData(data);
262void SimulationsSettingsForm::OnPFMethodChoiceSelected(wxCommandEvent& event) { UpdatePFFieldStatus(); }
264void SimulationsSettingsForm::UpdateZIPLoadFieldStatus()
266 m_textCtrlActivePowerImp->Enable(m_checkBoxUseCompLoads->GetValue());
267 m_textCtrlActivePowerCur->Enable(m_checkBoxUseCompLoads->GetValue());
268 m_textCtrlActivePowerPow->Enable(m_checkBoxUseCompLoads->GetValue());
269 m_textCtrlReactivePowerImp->Enable(m_checkBoxUseCompLoads->GetValue());
270 m_textCtrlReactivePowerCur->Enable(m_checkBoxUseCompLoads->GetValue());
271 m_textCtrlReactivePowerPow->Enable(m_checkBoxUseCompLoads->GetValue());
274void SimulationsSettingsForm::UpdatePFFieldStatus()
276 if (m_choicePFMethod->GetSelection() == 1 || m_choicePFMethod->GetSelection() == 2)
277 m_textCtrlAccFactor->Enable();
279 m_textCtrlAccFactor->Enable(
false);
280 if (m_choicePFMethod->GetSelection() == 2)
281 m_textCtrlPFGaussTolerance->Enable();
283 m_textCtrlPFGaussTolerance->Enable(
false);
284 if (m_choicePFMethod->GetSelection() == 0 || m_choicePFMethod->GetSelection() == 2)
285 m_textCtrlPFNewtonInertia->Enable();
287 m_textCtrlPFNewtonInertia->Enable(
false);
289void SimulationsSettingsForm::UpdateBusFreqFieldStatus()
292 if (m_radioBoxBusFreqEstimation->GetSelection() == 0) visible =
false;
293 m_checkBoxBusFreqIgnoreEvent->Show(!visible);
294 m_staticTextTf->Show(visible);
295 m_textCtrlTf->Show(visible);
296 m_staticTextTw->Show(visible);
297 m_textCtrlTw->Show(visible);
298 m_staticBitmapDiagram->Show(visible);
301void SimulationsSettingsForm::OnBusFreqEstimationSelect(wxCommandEvent& event)
303 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.