KiCad PCB EDA Suite
Loading...
Searching...
No Matches
validators.h
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) 2013 Wayne Stambaugh <[email protected]>
5 * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 * Copyright (C) 2018 CERN
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
31#ifndef VALIDATORS_H
32#define VALIDATORS_H
33
34#include <memory>
35
36#include <wx/valtext.h>
37#include <wx/grid.h>
38#include <wx/regex.h>
39
40#include <lib_id.h>
41
42
43#define FIELD_NAME -1
44#define FIELD_VALUE -2
45
46#define SHEETNAME_V 100 // We can't use SHEETNAME and SHEETFILENAME because they
47#define SHEETFILENAME_V 101 // overlap with REFERENCE_FIELD and VALUE_FIELD
48#define SHEETUSERFIELD_V 102
49
50#define LABELUSERFIELD_V 200
51
52
59class FOOTPRINT_NAME_VALIDATOR : public wxTextValidator
60{
61public:
62 FOOTPRINT_NAME_VALIDATOR( wxString* aValue = nullptr );
63};
64
65
72class FILE_NAME_WITH_PATH_CHAR_VALIDATOR : public wxTextValidator
73{
74public:
75 FILE_NAME_WITH_PATH_CHAR_VALIDATOR( wxString* aValue = nullptr );
76};
77
78
87class ENV_VAR_NAME_VALIDATOR : public wxTextValidator
88{
89public:
90 ENV_VAR_NAME_VALIDATOR( wxString* aValue = nullptr );
92
94
95 // Make a clone of this validator (or return nullptr) - currently necessary
96 // if you're passing a reference to a validator.
97 virtual wxObject *Clone() const override
98 {
99 return new ENV_VAR_NAME_VALIDATOR( *this );
100 }
101
102 void OnChar( wxKeyEvent& event );
103
104 void OnTextChanged( wxCommandEvent& event );
105};
106
107
112class REGEX_VALIDATOR : public wxTextValidator
113{
114public:
119 REGEX_VALIDATOR( const wxString& aRegEx, wxString* aValue = nullptr )
120 : wxTextValidator( wxFILTER_NONE, aValue )
121 {
122 compileRegEx( aRegEx, wxRE_DEFAULT );
123 }
124
130 REGEX_VALIDATOR( const wxString& aRegEx, int aFlags, wxString* aValue = nullptr )
131 : wxTextValidator( wxFILTER_NONE, aValue )
132 {
133 compileRegEx( aRegEx, aFlags );
134 }
135
136 REGEX_VALIDATOR( const REGEX_VALIDATOR& aOther ) : wxTextValidator( aOther )
137 {
138 compileRegEx( aOther.m_regExString, aOther.m_regExFlags );
139 }
140
141 virtual wxObject* Clone() const override
142 {
143 return new REGEX_VALIDATOR( *this );
144 }
145
146 bool Validate( wxWindow* aParent ) override;
147
148 const wxString& GetRegEx() const
149 {
150 return m_regExString;
151 }
152
153protected:
155 void compileRegEx( const wxString& aRegEx, int aFlags );
156
159
162
164 wxRegEx m_regEx;
165};
166
167class NETNAME_VALIDATOR : public wxTextValidator
168{
169public:
170 NETNAME_VALIDATOR( wxString* aVal = nullptr );
171
172 NETNAME_VALIDATOR( bool aAllowSpaces );
173
174 NETNAME_VALIDATOR( const NETNAME_VALIDATOR& aValidator );
175
176 virtual wxObject* Clone() const override { return new NETNAME_VALIDATOR( *this ); }
177
178 virtual bool TransferToWindow() override { return true; }
179
180 virtual bool TransferFromWindow() override { return true; }
181
182 virtual bool Validate( wxWindow *aParent ) override;
183
184protected:
185 // returns the error message if the contents of 'val' are invalid
186 wxString IsValid( const wxString& aVal ) const override;
187
188private:
190};
191
192
193namespace KIUI
194{
208void ValidatorTransferToWindowWithoutEvents( wxValidator& aValidator );
209
210} // namespace KIUI
211
212
220class FIELD_VALIDATOR : public wxTextValidator
221{
222public:
223 FIELD_VALIDATOR( int aFieldId, wxString* aValue = nullptr );
224
225 FIELD_VALIDATOR( const FIELD_VALIDATOR& aValidator );
226
227 virtual wxObject* Clone() const override { return new FIELD_VALIDATOR( *this ); }
228
236 virtual bool Validate( wxWindow* aParent ) override;
237
238 bool DoValidate( const wxString& aValue, wxWindow* aParent );
239
240private:
242};
243
244
245#endif // #ifndef VALIDATORS_H
This class provides a custom wxValidator object for limiting the allowable characters when defining a...
Definition: validators.h:88
virtual ~ENV_VAR_NAME_VALIDATOR()
Definition: validators.cpp:98
void OnChar(wxKeyEvent &event)
Definition: validators.cpp:104
void OnTextChanged(wxCommandEvent &event)
Definition: validators.cpp:175
virtual wxObject * Clone() const override
Definition: validators.h:97
A text control validator used for validating the text allowed in fields.
Definition: validators.h:221
virtual wxObject * Clone() const override
Definition: validators.h:227
virtual bool Validate(wxWindow *aParent) override
Override the default Validate() function provided by wxTextValidator to provide better error messages...
Definition: validators.cpp:348
bool DoValidate(const wxString &aValue, wxWindow *aParent)
Definition: validators.cpp:364
This class provides a custom wxValidator object for limiting the allowable characters when defining f...
Definition: validators.h:73
This class provides a custom wxValidator object for limiting the allowable characters when defining f...
Definition: validators.h:60
wxString IsValid(const wxString &aVal) const override
Definition: validators.cpp:290
virtual wxObject * Clone() const override
Definition: validators.h:176
virtual bool Validate(wxWindow *aParent) override
Definition: validators.cpp:266
virtual bool TransferToWindow() override
Definition: validators.h:178
virtual bool TransferFromWindow() override
Definition: validators.h:180
Custom validator that checks verifies that a string exactly matches a regular expression.
Definition: validators.h:113
virtual wxObject * Clone() const override
Definition: validators.h:141
wxRegEx m_regEx
Definition: validators.h:164
REGEX_VALIDATOR(const REGEX_VALIDATOR &aOther)
Definition: validators.h:136
const wxString & GetRegEx() const
Definition: validators.h:148
bool Validate(wxWindow *aParent) override
Definition: validators.cpp:194
wxString m_regExString
Original compilation flags (for copy constructor)
Definition: validators.h:158
REGEX_VALIDATOR(const wxString &aRegEx, wxString *aValue=nullptr)
Definition: validators.h:119
int m_regExFlags
Compiled regex.
Definition: validators.h:161
REGEX_VALIDATOR(const wxString &aRegEx, int aFlags, wxString *aValue=nullptr)
Definition: validators.h:130
void compileRegEx(const wxString &aRegEx, int aFlags)
< Compiles and stores a regular expression
Definition: validators.cpp:232
void ValidatorTransferToWindowWithoutEvents(wxValidator &aValidator)
Call a text validator's TransferDataToWindow method without firing a text change event.
Definition: validators.cpp:302