Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
LimiterForm.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 "LimiterForm.h"
19#include "../elements/controlElement/Limiter.h"
20
21LimiterForm::LimiterForm(wxWindow* parent, Limiter* limiter) : LimiterFormBase(parent)
22{
23 SetSize(GetBestSize());
24
25 m_limiter = limiter;
26 m_parent = parent;
27
28 m_textCtrlUpLimit->SetValue(m_limiter->StringFromDouble(m_limiter->GetUpLimit()));
29 m_textCtrlLowLimit->SetValue(m_limiter->StringFromDouble(m_limiter->GetLowLimit()));
30}
31
32LimiterForm::~LimiterForm() {}
33void LimiterForm::OnOKButtonClick(wxCommandEvent& event)
34{
35 if(ValidateData()) EndModal(wxID_OK);
36}
37
38bool LimiterForm::ValidateData()
39{
40 double upLimit;
41 double lowLimit;
42
43 if(!m_limiter->DoubleFromString(this, m_textCtrlUpLimit->GetValue(), upLimit,
44 _("Value entered incorrectly in the field \"Upper limit\".")))
45 return false;
46 if(!m_limiter->DoubleFromString(this, m_textCtrlLowLimit->GetValue(), lowLimit,
47 _("Value entered incorrectly in the field \"Lower limit\".")))
48 return false;
49
50 m_limiter->SetUpLimit(upLimit);
51 m_limiter->SetLowLimit(lowLimit);
52 return true;
53}
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
Limits the input value by superior and inferior values.
Definition Limiter.h:33