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 The 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
61class FOOTPRINT_NAME_VALIDATOR : public wxTextValidator
62{
63public:
64 FOOTPRINT_NAME_VALIDATOR( wxString* aValue = nullptr );
65};
66
67
75class FILE_NAME_WITH_PATH_CHAR_VALIDATOR : public wxTextValidator
76{
77public:
78 FILE_NAME_WITH_PATH_CHAR_VALIDATOR( wxString* aValue = nullptr );
79};
80
81
91class ENV_VAR_NAME_VALIDATOR : public wxTextValidator
92{
93public:
94 ENV_VAR_NAME_VALIDATOR( wxString* aValue = nullptr );
96
98
99 // Make a clone of this validator (or return nullptr) - currently necessary
100 // if you're passing a reference to a validator.
101 virtual wxObject *Clone() const override
102 {
103 return new ENV_VAR_NAME_VALIDATOR( *this );
104 }
105
106 void OnChar( wxKeyEvent& event );
107
108 void OnTextChanged( wxCommandEvent& event );
109};
110
111
115class REGEX_VALIDATOR : public wxTextValidator
116{
117public:
122 REGEX_VALIDATOR( const wxString& aRegEx, wxString* aValue = nullptr )
123 : wxTextValidator( wxFILTER_NONE, aValue )
124 {
125 compileRegEx( aRegEx, wxRE_DEFAULT );
126 }
127
133 REGEX_VALIDATOR( const wxString& aRegEx, int aFlags, wxString* aValue = nullptr )
134 : wxTextValidator( wxFILTER_NONE, aValue )
135 {
136 compileRegEx( aRegEx, aFlags );
137 }
138
139 REGEX_VALIDATOR( const REGEX_VALIDATOR& aOther ) : wxTextValidator( aOther )
140 {
141 compileRegEx( aOther.m_regExString, aOther.m_regExFlags );
142 }
143
144 virtual wxObject* Clone() const override
145 {
146 return new REGEX_VALIDATOR( *this );
147 }
148
149 bool Validate( wxWindow* aParent ) override;
150
151 const wxString& GetRegEx() const
152 {
153 return m_regExString;
154 }
155
156protected:
158 void compileRegEx( const wxString& aRegEx, int aFlags );
159
162
165
167 wxRegEx m_regEx;
168};
169
170class NETNAME_VALIDATOR : public wxTextValidator
171{
172public:
173 NETNAME_VALIDATOR( wxString* aVal = nullptr );
174
175 NETNAME_VALIDATOR( bool aAllowSpaces );
176
177 NETNAME_VALIDATOR( const NETNAME_VALIDATOR& aValidator );
178
179 virtual wxObject* Clone() const override { return new NETNAME_VALIDATOR( *this ); }
180
181 virtual bool TransferToWindow() override { return true; }
182
183 virtual bool TransferFromWindow() override { return true; }
184
185 virtual bool Validate( wxWindow *aParent ) override;
186
187protected:
189 wxString IsValid( const wxString& aVal ) const override;
190
191private:
193};
194
195
196namespace KIUI
197{
211void ValidatorTransferToWindowWithoutEvents( wxValidator& aValidator );
212
213} // namespace KIUI
214
215
223class FIELD_VALIDATOR : public wxTextValidator
224{
225public:
226 FIELD_VALIDATOR( int aFieldId, wxString* aValue = nullptr );
227
228 FIELD_VALIDATOR( const FIELD_VALIDATOR& aValidator );
229
230 virtual wxObject* Clone() const override { return new FIELD_VALIDATOR( *this ); }
231
239 virtual bool Validate( wxWindow* aParent ) override;
240
241 bool DoValidate( const wxString& aValue, wxWindow* aParent );
242
243private:
245};
246
247
248#endif // #ifndef VALIDATORS_H
Provide a custom wxValidator object for limiting the allowable characters when defining an environmen...
Definition: validators.h:92
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:101
A text control validator used for validating the text allowed in fields.
Definition: validators.h:224
virtual wxObject * Clone() const override
Definition: validators.h:230
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:365
Provide a custom wxValidator object for limiting the allowable characters when defining file names wi...
Definition: validators.h:76
Provide a custom wxValidator object for limiting the allowable characters when defining footprint nam...
Definition: validators.h:62
wxString IsValid(const wxString &aVal) const override
Definition: validators.cpp:290
virtual wxObject * Clone() const override
Definition: validators.h:179
virtual bool Validate(wxWindow *aParent) override
Definition: validators.cpp:266
virtual bool TransferToWindow() override
Definition: validators.h:181
virtual bool TransferFromWindow() override
Definition: validators.h:183
Custom validator that checks verifies that a string exactly matches a regular expression.
Definition: validators.h:116
virtual wxObject * Clone() const override
Definition: validators.h:144
wxRegEx m_regEx
Compiled regular expression.
Definition: validators.h:167
REGEX_VALIDATOR(const REGEX_VALIDATOR &aOther)
Definition: validators.h:139
const wxString & GetRegEx() const
Definition: validators.h:151
bool Validate(wxWindow *aParent) override
Definition: validators.cpp:194
wxString m_regExString
Original regular expression (for copy constructor).
Definition: validators.h:161
REGEX_VALIDATOR(const wxString &aRegEx, wxString *aValue=nullptr)
Definition: validators.h:122
int m_regExFlags
Original compilation flags (for copy constructor).
Definition: validators.h:164
REGEX_VALIDATOR(const wxString &aRegEx, int aFlags, wxString *aValue=nullptr)
Definition: validators.h:133
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