Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
ConstantForm.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 "ConstantForm.h"
19#include "../elements/controlElement/Constant.h"
20
21ConstantForm::ConstantForm(wxWindow* parent, Constant* constant) : ConstantFormBase(parent)
22{
23 SetSize(GetBestSize());
24
25 m_parent = parent;
26 m_constant = constant;
27
28 m_textCtrlValue->SetValue(m_constant->StringFromDouble(m_constant->GetValue()));
29}
30
31ConstantForm::~ConstantForm() {}
32void ConstantForm::OnOKButtonClick(wxCommandEvent& event)
33{
34 if(ValidateData()) EndModal(wxID_OK);
35}
36
37bool ConstantForm::ValidateData()
38{
39 double value;
40 if(!m_constant->DoubleFromString(this, m_textCtrlValue->GetValue(), value,
41 _("Value entered incorrectly in the field \"Constant value\".")))
42 return false;
43
44 m_constant->SetValue(value);
45 return true;
46}
A control element that provides a constant value.
Definition Constant.h:37
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.
Definition Element.cpp:505