Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
ControlSystemTest.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 "ControlSystemTest.h"
19#include "ControlEditor.h"
20
21ControlSystemTest::ControlSystemTest(ControlEditor* parent,
22 std::vector<IOControl*> ioList,
23 int* inputType,
24 double* startTime,
25 double* slope,
26 double* timeStep,
27 double* simTime)
28 : ControlSystemTestBase(parent)
29{
30 SetSize(GetBestSize());
31
32 for (auto* io : ioList) {
33 if (io->GetType() == Node::NodeType::NODE_OUT) {
34 m_choiceInput->Append(io->GetName(), io);
35 }
36 }
37
38 m_inputType = inputType;
39 //m_startTime = startTime;
40 //m_slope = slope;
41 m_timeStep = timeStep;
42 m_simTime = simTime;
43
44 m_choiceInput->SetSelection(*m_inputType);
45 //m_textCtrlStartTime->SetValue(wxString::FromDouble(*m_startTime));
46 //m_textCtrlSlope->SetValue(wxString::FromDouble(*m_slope));
47 m_textCtrlTimeStep->SetValue(wxString::FromDouble(*m_timeStep));
48 m_textCtrlSimTime->SetValue(wxString::FromDouble(*m_simTime));
49
50 UpdatePGValues();
51}
52
53ControlSystemTest::~ControlSystemTest() {}
54void ControlSystemTest::OnRunButtonClick(wxCommandEvent& event)
55{
56 int inputType;
57 double timeStep, simTime;
58
59 inputType = m_choiceInput->GetSelection();
60
61 //if (!m_textCtrlStartTime->GetValue().ToDouble(&startTime)) {
62 // wxMessageDialog msgDialog(this, _("Value entered incorrectly in the field \"Start time\"."), _("Error"),
63 // wxOK | wxCENTRE | wxICON_ERROR);
64 // msgDialog.ShowModal();
65 // return;
66 //}
67 //
68 //if (!m_textCtrlSlope->GetValue().ToDouble(&slope)) {
69 // wxMessageDialog msgDialog(this, _("Value entered incorrectly in the field \"Slope\"."), _("Error"),
70 // wxOK | wxCENTRE | wxICON_ERROR);
71 // msgDialog.ShowModal();
72 // return;
73 //}
74
75 if (!m_textCtrlTimeStep->GetValue().ToDouble(&timeStep)) {
76 wxMessageDialog msgDialog(this, _("Value entered incorrectly in the field \"Time step\"."), _("Error"),
77 wxOK | wxCENTRE | wxICON_ERROR);
78 msgDialog.ShowModal();
79 return;
80 }
81
82 if (!m_textCtrlSimTime->GetValue().ToDouble(&simTime)) {
83 wxMessageDialog msgDialog(this, _("Value entered incorrectly in the field \"Simulation time\"."), _("Error"),
84 wxOK | wxCENTRE | wxICON_ERROR);
85 msgDialog.ShowModal();
86 return;
87 }
88
89 *m_inputType = inputType;
90 //*m_startTime = startTime;
91 //*m_slope = slope;
92 *m_timeStep = timeStep;
93 *m_simTime = simTime;
94
95 EndModal(wxID_OK);
96}
97
98void ControlSystemTest::OnInputSelected(wxCommandEvent& event)
99{
100 UpdatePGValues();
101}
102void ControlSystemTest::OnPGValueChange(wxPropertyGridEvent& event)
103{
104 IOControl* io = static_cast<IOControl*>(m_choiceInput->GetClientData(m_choiceInput->GetSelection()));
105 if (io == nullptr) return;
106
107 SimTestData simTestData = io->GetSimTestData();
108 if (event.GetProperty() == m_pgPropStartTime) {
109 simTestData.startTime = m_pgPropStartTime->GetValue();
110 }
111 else if (event.GetProperty() == m_pgPropInitialValue) {
112 simTestData.initialValue = m_pgPropInitialValue->GetValue();
113 }
114 else if (event.GetProperty() == m_pgPropSlope) {
115 simTestData.slope = m_pgPropSlope->GetValue();
116 }
117 else if (event.GetProperty() == m_pgPropInputType) {
118 simTestData.type = m_pgPropInputType->GetValue().GetInteger();
119 }
120 io->SetSimTestData(simTestData);
121}
122
123void ControlSystemTest::UpdatePGValues()
124{
125 IOControl* io = static_cast<IOControl*>(m_choiceInput->GetClientData(m_choiceInput->GetSelection()));
126 if (io != nullptr) {
127 SimTestData simTestData = io->GetSimTestData();
128 m_pgMgr->ChangePropertyValue(m_pgPropStartTime, wxString::FromDouble(simTestData.startTime));
129 m_pgMgr->ChangePropertyValue(m_pgPropInitialValue, wxString::FromDouble(simTestData.initialValue));
130 m_pgMgr->ChangePropertyValue(m_pgPropSlope, wxString::FromDouble(simTestData.slope));
131 m_pgMgr->ChangePropertyValue(m_pgPropInputType, simTestData.type);
132 }
133}
Provides the communication with the power element.
Definition IOControl.h:43