KiCad PCB EDA Suite
sch_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) 2016 Wayne Stambaugh, stambaughw@gmail.com
5  * Copyright (C) 2016-2019 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #ifndef _SCH_VALIDATORS_H_
31 #define _SCH_VALIDATORS_H_
32 
33 #include <wx/valtext.h>
34 
35 
36 #define FIELD_NAME -1
37 #define FIELD_VALUE -2
38 
39 
48 class SCH_FIELD_VALIDATOR : public wxTextValidator
49 {
50  int m_fieldId;
52 
53 public:
54  SCH_FIELD_VALIDATOR( bool aIsLibEditor, int aFieldId, wxString* aValue = NULL );
55 
56  SCH_FIELD_VALIDATOR( const SCH_FIELD_VALIDATOR& aValidator );
57 
58  virtual wxObject* Clone() const override { return new SCH_FIELD_VALIDATOR( *this ); }
59 
67  virtual bool Validate( wxWindow *aParent ) override;
68 };
69 
70 
71 class SCH_NETNAME_VALIDATOR : public wxValidator
72 {
73 public:
74  SCH_NETNAME_VALIDATOR( wxString *aVal = nullptr );
75 
76  SCH_NETNAME_VALIDATOR( bool aAllowSpaces );
77 
78  SCH_NETNAME_VALIDATOR( const SCH_NETNAME_VALIDATOR& aValidator );
79 
80  void SetAllowSpaces( bool aAllowSpaces = true ) { m_allowSpaces = aAllowSpaces; }
81 
82  bool GetAllowSpaces() const { return m_allowSpaces; }
83 
84  bool Copy( const SCH_NETNAME_VALIDATOR& val );
85 
86  virtual wxObject* Clone() const override { return new SCH_NETNAME_VALIDATOR( *this ); }
87 
88  virtual bool TransferToWindow() override { return true; }
89 
90  virtual bool TransferFromWindow() override { return true; }
91 
92  wxTextEntry* GetTextEntry();
93 
94  virtual bool Validate( wxWindow *aParent ) override;
95 
96 protected:
97 
98  // returns the error message if the contents of 'val' are invalid
99  virtual wxString IsValid( const wxString& aVal ) const;
100 
101 private:
103 };
104 
105 #endif // _SCH_VALIDATORS_H_
void SetAllowSpaces(bool aAllowSpaces=true)
bool GetAllowSpaces() const
virtual wxObject * Clone() const override
SCH_NETNAME_VALIDATOR(wxString *aVal=nullptr)
virtual wxObject * Clone() const override
virtual wxString IsValid(const wxString &aVal) const
virtual bool TransferFromWindow() override
SCH_FIELD_VALIDATOR(bool aIsLibEditor, int aFieldId, wxString *aValue=NULL)
wxTextEntry * GetTextEntry()
bool Copy(const SCH_NETNAME_VALIDATOR &val)
virtual bool TransferToWindow() override
A text control validator used for validating the text allowed in library and schematic component fiel...
virtual bool Validate(wxWindow *aParent) override
virtual bool Validate(wxWindow *aParent) override
Override the default Validate() function provided by wxTextValidator to provide better error messages...