KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_validator_min_max_ctrl.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22
23VALIDATE_MIN_MAX_CTRL::VALIDATE_MIN_MAX_CTRL( wxTextCtrl* aMinCtrl, wxTextCtrl* aMaxCtrl ) :
24 m_minCtrl( aMinCtrl ), m_maxCtrl( aMaxCtrl ), m_minCtrlName( aMinCtrl->GetName() ),
25 m_maxCtrlName( aMaxCtrl->GetName() ), m_validationState( VALIDATION_STATE::Valid )
26{
27}
28
29
31{
33}
34
35
36bool VALIDATE_MIN_MAX_CTRL::Validate( wxWindow* aParent )
37{
38 wxTextCtrl* minCtrl = wxDynamicCast( aParent->FindWindowByName( m_minCtrlName ), wxTextCtrl );
39 wxTextCtrl* maxCtrl = wxDynamicCast( aParent->FindWindowByName( m_maxCtrlName ), wxTextCtrl );
40
41 if( !minCtrl || !maxCtrl )
42 {
43 return false;
44 }
45
46 wxString minValueStr = minCtrl->GetValue();
47 wxString maxValueStr = maxCtrl->GetValue();
48
49 double minValue, maxValue;
50 minValueStr.ToDouble( &minValue );
51 maxValueStr.ToDouble( &maxValue );
52
53 if( minValue > maxValue )
54 {
56 return false;
57 }
58
60 return true;
61}
62
63
VALIDATE_MIN_MAX_CTRL(wxTextCtrl *aMinCtrl, wxTextCtrl *aMaxCtrl)
virtual wxObject * Clone() const override
virtual bool Validate(wxWindow *aParent) override
VALIDATION_STATE GetValidationState() const