KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_validator_min_preferred_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
24 wxTextCtrl* aPreferredCtrl,
25 wxTextCtrl* aMaxCtrl ) :
26 m_minCtrl( aMinCtrl ),
27 m_preferredCtrl( aPreferredCtrl ),
28 m_maxCtrl( aMaxCtrl ),
29 m_minCtrlName( aMinCtrl->GetName() ),
30 m_preferredCtrlName( aPreferredCtrl->GetName() ),
31 m_maxCtrlName( aMaxCtrl->GetName() ),
33{
34}
35
36
41
42
44{
45 // Assume two text controls: one for min and one for max
46 wxTextCtrl* minCtrl = wxDynamicCast( aParent->FindWindowByName( m_minCtrlName ), wxTextCtrl );
47 wxTextCtrl* preferredCtrl =
48 wxDynamicCast( aParent->FindWindowByName( m_preferredCtrlName ), wxTextCtrl );
49 wxTextCtrl* maxCtrl = wxDynamicCast( aParent->FindWindowByName( m_maxCtrlName ), wxTextCtrl );
50
51 if( !minCtrl || !maxCtrl || !preferredCtrl )
52 {
53 return false; // Controls not properly set
54 }
55
56 wxString minValueStr = minCtrl->GetValue();
57 wxString preferredValueStr = preferredCtrl->GetValue();
58 wxString maxValueStr = maxCtrl->GetValue();
59
60 double minValue, preferredValue, maxValue;
61 minValueStr.ToDouble( &minValue );
62 preferredValueStr.ToDouble( &preferredValue );
63 maxValueStr.ToDouble( &maxValue );
64
65 if( minValue > preferredValue )
66 {
68 return false;
69 }
70
71 if( preferredValue > maxValue )
72 {
74 return false;
75 }
76
77 if( minValue > maxValue )
78 {
80 return false;
81 }
82
84 return true;
85}
86
87
virtual bool Validate(wxWindow *aParent) override
VALIDATE_MIN_PREFERRED_MAX_CTRL(wxTextCtrl *aMinCtrl, wxTextCtrl *aPreferredCtrl, wxTextCtrl *aMaxCtrl)