KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 <stambaughw@gmail.com>
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#include <template_fieldnames.h>
42
43
52class FOOTPRINT_NAME_VALIDATOR : public wxTextValidator
53{
54public:
55 FOOTPRINT_NAME_VALIDATOR( wxString* aValue = nullptr );
56};
57
58
68class ENV_VAR_NAME_VALIDATOR : public wxTextValidator
69{
70public:
71 ENV_VAR_NAME_VALIDATOR( wxString* aValue = nullptr );
73
75
76 // Make a clone of this validator (or return nullptr) - currently necessary
77 // if you're passing a reference to a validator.
78 virtual wxObject *Clone() const override
79 {
80 return new ENV_VAR_NAME_VALIDATOR( *this );
81 }
82
83 void OnChar( wxKeyEvent& event );
84
85 void OnTextChanged( wxCommandEvent& event );
86};
87
88
89class NETNAME_VALIDATOR : public wxTextValidator
90{
91public:
92 NETNAME_VALIDATOR( wxString* aVal = nullptr );
93
94 NETNAME_VALIDATOR( bool aAllowSpaces );
95
96 NETNAME_VALIDATOR( const NETNAME_VALIDATOR& aValidator );
97
98 virtual wxObject* Clone() const override { return new NETNAME_VALIDATOR( *this ); }
99
100 virtual bool TransferToWindow() override { return true; }
101
102 virtual bool TransferFromWindow() override { return true; }
103
104 virtual bool Validate( wxWindow *aParent ) override;
105
107 wxString IsValid( const wxString& aVal ) const override;
108
109private:
111};
112
113
114namespace KIUI
115{
129void ValidatorTransferToWindowWithoutEvents( wxValidator& aValidator );
130
131} // namespace KIUI
132
133
141class FIELD_VALIDATOR : public wxTextValidator
142{
143public:
144 FIELD_VALIDATOR( FIELD_T aFieldId, wxString* aValue = nullptr );
145
146 FIELD_VALIDATOR( const FIELD_VALIDATOR& aValidator );
147
148 virtual wxObject* Clone() const override { return new FIELD_VALIDATOR( *this ); }
149
157 virtual bool Validate( wxWindow* aParent ) override;
158
159 bool DoValidate( const wxString& aValue, wxWindow* aParent );
160
161private:
163};
164
165
166#endif // #ifndef VALIDATORS_H
Provide a custom wxValidator object for limiting the allowable characters when defining an environmen...
Definition: validators.h:69
virtual ~ENV_VAR_NAME_VALIDATOR()
Definition: validators.cpp:72
void OnChar(wxKeyEvent &event)
Definition: validators.cpp:78
void OnTextChanged(wxCommandEvent &event)
Definition: validators.cpp:149
virtual wxObject * Clone() const override
Definition: validators.h:78
A text control validator used for validating the text allowed in fields.
Definition: validators.h:142
virtual wxObject * Clone() const override
Definition: validators.h:148
virtual bool Validate(wxWindow *aParent) override
Override the default Validate() function provided by wxTextValidator to provide better error messages...
Definition: validators.cpp:275
bool DoValidate(const wxString &aValue, wxWindow *aParent)
Definition: validators.cpp:292
FIELD_T m_fieldId
Definition: validators.h:162
Provide a custom wxValidator object for limiting the allowable characters when defining footprint nam...
Definition: validators.h:53
wxString IsValid(const wxString &aVal) const override
Definition: validators.cpp:213
virtual wxObject * Clone() const override
Definition: validators.h:98
virtual bool Validate(wxWindow *aParent) override
Definition: validators.cpp:189
virtual bool TransferToWindow() override
Definition: validators.h:100
virtual bool TransferFromWindow() override
Definition: validators.h:102
void ValidatorTransferToWindowWithoutEvents(wxValidator &aValidator)
Call a text validator's TransferDataToWindow method without firing a text change event.
Definition: validators.cpp:225
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...