Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
IOControlForm.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 "IOControlForm.h"
19
20IOControlForm::IOControlForm(wxWindow* parent, IOControl* ioControl) : IOControlFormBase(parent)
21{
22 SetSize(GetBestSize());
23
24 m_parent = parent;
25 m_ioControl = ioControl;
26
27 m_textCtrlName->SetValue(m_ioControl->GetName());
28
29 int ioFlags = m_ioControl->GetIOFlags();
30 int inChoiceNumber = -1;
31 int outChoiceNumber = -1;
32
33 if (ioFlags & IOControl::IN_TERMINAL_VOLTAGE) {
34 m_choiceInput->Append(_("Terminal voltage"));
35 m_inputFlags.push_back(IOControl::IN_TERMINAL_VOLTAGE);
36 if (m_ioControl->GetValue() == IOControl::IN_TERMINAL_VOLTAGE) inChoiceNumber = (int)m_inputFlags.size() - 1;
37 }
38 if (ioFlags & IOControl::IN_VELOCITY) {
39 m_choiceInput->Append(_("Velocity"));
40 m_inputFlags.push_back(IOControl::IN_VELOCITY);
41 if (m_ioControl->GetValue() == IOControl::IN_VELOCITY) inChoiceNumber = (int)m_inputFlags.size() - 1;
42 }
43 if (ioFlags & IOControl::IN_ACTIVE_POWER) {
44 m_choiceInput->Append(_("Active power"));
45 m_inputFlags.push_back(IOControl::IN_ACTIVE_POWER);
46 if (m_ioControl->GetValue() == IOControl::IN_ACTIVE_POWER) inChoiceNumber = (int)m_inputFlags.size() - 1;
47 }
48 if (ioFlags & IOControl::IN_REACTIVE_POWER) {
49 m_choiceInput->Append(_("Reactive power"));
50 m_inputFlags.push_back(IOControl::IN_REACTIVE_POWER);
51 if (m_ioControl->GetValue() == IOControl::IN_REACTIVE_POWER) inChoiceNumber = (int)m_inputFlags.size() - 1;
52 }
53 if (ioFlags & IOControl::OUT_FIELD_VOLTAGE) {
54 m_choiceOutput->Append(_("Field voltage"));
55 m_outputFlags.push_back(IOControl::OUT_FIELD_VOLTAGE);
56 if (m_ioControl->GetValue() == IOControl::OUT_FIELD_VOLTAGE) outChoiceNumber = (int)m_outputFlags.size() - 1;
57 }
58 if (ioFlags & IOControl::OUT_MEC_POWER) {
59 m_choiceOutput->Append(_("Mechanical power"));
60 m_outputFlags.push_back(IOControl::OUT_MEC_POWER);
61 if (m_ioControl->GetValue() == IOControl::OUT_MEC_POWER) outChoiceNumber = (int)m_outputFlags.size() - 1;
62 }
63
64 if (ioFlags & IOControl::IN_INITIAL_MEC_POWER) {
65 m_choiceInput->Append(_("Initial mechanical power"));
66 m_inputFlags.push_back(IOControl::IN_INITIAL_MEC_POWER);
67 if (m_ioControl->GetValue() == IOControl::IN_INITIAL_MEC_POWER) inChoiceNumber = (int)m_inputFlags.size() - 1;
68 }
69
70 if (ioFlags & IOControl::IN_INITIAL_TERMINAL_VOLTAGE) {
71 m_choiceInput->Append(_("Initial terminal voltage"));
72 m_inputFlags.push_back(IOControl::IN_INITIAL_TERMINAL_VOLTAGE);
73 if (m_ioControl->GetValue() == IOControl::IN_INITIAL_TERMINAL_VOLTAGE)
74 inChoiceNumber = (int)m_inputFlags.size() - 1;
75 }
76
77 if (ioFlags & IOControl::IN_INITIAL_VELOCITY) {
78 m_choiceInput->Append(_("Initial velocity"));
79 m_inputFlags.push_back(IOControl::IN_INITIAL_VELOCITY);
80 if (m_ioControl->GetValue() == IOControl::IN_INITIAL_VELOCITY) inChoiceNumber = (int)m_inputFlags.size() - 1;
81 }
82
83 if (ioFlags & IOControl::IN_DELTA_VELOCITY) {
84 m_choiceInput->Append(_("Velocity variation"));
85 m_inputFlags.push_back(IOControl::IN_DELTA_VELOCITY);
86 if (m_ioControl->GetValue() == IOControl::IN_DELTA_VELOCITY) inChoiceNumber = (int)m_inputFlags.size() - 1;
87 }
88
89 if (ioFlags & IOControl::IN_DELTA_ACTIVE_POWER) {
90 m_choiceInput->Append(_("Active power variation"));
91 m_inputFlags.push_back(IOControl::IN_DELTA_ACTIVE_POWER);
92 if (m_ioControl->GetValue() == IOControl::IN_DELTA_ACTIVE_POWER) inChoiceNumber = (int)m_inputFlags.size() - 1;
93 }
94
95 if (inChoiceNumber != -1) {
96 m_choiceInput->SetSelection(inChoiceNumber);
97 m_checkBoxInput->SetValue(true);
98 m_checkBoxOutput->SetValue(false);
99 m_choiceOutput->Enable(false);
100 }
101 else {
102 m_choiceOutput->SetSelection(outChoiceNumber);
103 m_checkBoxInput->SetValue(false);
104 m_checkBoxOutput->SetValue(true);
105 m_choiceInput->Enable(false);
106 }
107}
108
109IOControlForm::~IOControlForm() {}
110void IOControlForm::OnOKButtonClick(wxCommandEvent& event)
111{
112 if (ValidateData()) EndModal(wxID_OK);
113}
114
115bool IOControlForm::ValidateData()
116{
117 m_ioControl->SetName(m_textCtrlName->GetValue());
118
119 if (m_checkBoxInput->GetValue() && m_choiceInput->GetSelection() != -1) {
120 m_ioControl->SetValue(m_inputFlags[m_choiceInput->GetSelection()]);
121 return true;
122 }
123 else if (m_checkBoxOutput->GetValue() && m_choiceOutput->GetSelection() != -1) {
124 m_ioControl->SetValue(m_outputFlags[m_choiceOutput->GetSelection()]);
125 return true;
126 }
127
128 return false;
129}
130
131void IOControlForm::OnInputChecked(wxCommandEvent& event)
132{
133 m_checkBoxInput->SetValue(true);
134 m_checkBoxOutput->SetValue(false);
135 m_choiceOutput->Enable(false);
136 m_choiceInput->Enable(true);
137}
138
139void IOControlForm::OnOutputChecked(wxCommandEvent& event)
140{
141 m_checkBoxOutput->SetValue(true);
142 m_checkBoxInput->SetValue(false);
143 m_choiceOutput->Enable(true);
144 m_choiceInput->Enable(false);
145}
Provides the communication with the power element.
Definition IOControl.h:43