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, see <https://www.gnu.org/licenses/>.
20 */
21
26
27#ifndef VALIDATORS_H
28#define VALIDATORS_H
29
30#include <memory>
31
32#include <wx/valtext.h>
33#include <wx/grid.h>
34#include <wx/regex.h>
35
36#include <lib_id.h>
37#include <template_fieldnames.h>
38
39
48class FOOTPRINT_NAME_VALIDATOR : public wxTextValidator
49{
50public:
51 FOOTPRINT_NAME_VALIDATOR( wxString* aValue = nullptr );
52};
53
54
64class ENV_VAR_NAME_VALIDATOR : public wxTextValidator
65{
66public:
67 ENV_VAR_NAME_VALIDATOR( wxString* aValue = nullptr );
69
71
72 // Make a clone of this validator (or return nullptr) - currently necessary
73 // if you're passing a reference to a validator.
74 virtual wxObject *Clone() const override
75 {
76 return new ENV_VAR_NAME_VALIDATOR( *this );
77 }
78
79 void OnChar( wxKeyEvent& event );
80
81 void OnTextChanged( wxCommandEvent& event );
82};
83
84
85class NETNAME_VALIDATOR : public wxTextValidator
86{
87public:
88 NETNAME_VALIDATOR( wxString* aVal = nullptr );
89
90 NETNAME_VALIDATOR( bool aAllowSpaces );
91
92 NETNAME_VALIDATOR( const NETNAME_VALIDATOR& aValidator );
93
94 virtual wxObject* Clone() const override { return new NETNAME_VALIDATOR( *this ); }
95
96 virtual bool TransferToWindow() override { return true; }
97
98 virtual bool TransferFromWindow() override { return true; }
99
100 virtual bool Validate( wxWindow *aParent ) override;
101
103 wxString IsValid( const wxString& aVal ) const override;
104
105private:
107};
108
109
110namespace KIUI
111{
125void ValidatorTransferToWindowWithoutEvents( wxValidator& aValidator );
126
127} // namespace KIUI
128
129
137class FIELD_VALIDATOR : public wxTextValidator
138{
139public:
140 FIELD_VALIDATOR( FIELD_T aFieldId, wxString* aValue = nullptr );
141
142 FIELD_VALIDATOR( const FIELD_VALIDATOR& aValidator );
143
144 virtual wxObject* Clone() const override { return new FIELD_VALIDATOR( *this ); }
145
153 virtual bool Validate( wxWindow* aParent ) override;
154
155 bool DoValidate( const wxString& aValue, wxWindow* aParent );
156
157private:
159};
160
165wxString GetFieldValidationErrorMessage( FIELD_T aFieldId, const wxString& aValue );
166
167
168#endif // #ifndef VALIDATORS_H
virtual ~ENV_VAR_NAME_VALIDATOR()
void OnChar(wxKeyEvent &event)
ENV_VAR_NAME_VALIDATOR(wxString *aValue=nullptr)
void OnTextChanged(wxCommandEvent &event)
virtual wxObject * Clone() const override
Definition validators.h:74
virtual wxObject * Clone() const override
Definition validators.h:144
virtual bool Validate(wxWindow *aParent) override
Override the default Validate() function provided by wxTextValidator to provide better error messages...
bool DoValidate(const wxString &aValue, wxWindow *aParent)
FIELD_VALIDATOR(FIELD_T aFieldId, wxString *aValue=nullptr)
FIELD_T m_fieldId
Definition validators.h:158
FOOTPRINT_NAME_VALIDATOR(wxString *aValue=nullptr)
wxString IsValid(const wxString &aVal) const override
virtual wxObject * Clone() const override
Definition validators.h:94
virtual bool Validate(wxWindow *aParent) override
virtual bool TransferToWindow() override
Definition validators.h:96
NETNAME_VALIDATOR(wxString *aVal=nullptr)
virtual bool TransferFromWindow() override
Definition validators.h:98
void ValidatorTransferToWindowWithoutEvents(wxValidator &aValidator)
Call a text validator's TransferDataToWindow method without firing a text change event.
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
wxString GetFieldValidationErrorMessage(FIELD_T aFieldId, const wxString &aValue)
Return the error message if aValue is invalid for aFieldId.