KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_validators.cpp
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, [email protected]
5 * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.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#include <wx/combo.h>
31#include <wx/msgdlg.h>
32
33#include <sch_connection.h>
34#include <sch_validators.h>
36
37
38// Match opening curly brace, preceeded by start-of-line or by a character not including $_^~
39wxRegEx SCH_NETNAME_VALIDATOR::m_busGroupRegex( R"((^|[^$_\^~]){)", wxRE_ADVANCED );
40
41
42wxString SCH_NETNAME_VALIDATOR::IsValid( const wxString& str ) const
43{
44 wxString msg = NETNAME_VALIDATOR::IsValid( str );
45
46 if( !msg.IsEmpty() )
47 return msg;
48
49 // We don't do single-character validation here
50 if( str.Length() == 1 )
51 return wxString();
52
53 // Figuring out if the user "meant" to make a bus group is somewhat tricky because curly
54 // braces are also used for formatting and variable expansion
55
56 if( m_busGroupRegex.Matches( str ) && str.Contains( '}' ) )
57 {
58 if( !NET_SETTINGS::ParseBusGroup( str, nullptr, nullptr ) )
59 return _( "Signal name contains '{' and '}' but is not a valid bus name" );
60 }
61 else if( str.Contains( '[' ) || str.Contains( ']' ) )
62 {
63 if( !NET_SETTINGS::ParseBusVector( str, nullptr, nullptr ) )
64 return _( "Signal name contains '[' or ']' but is not a valid bus name." );
65 }
66
67 return wxString();
68}
wxString IsValid(const wxString &aVal) const override
Definition: validators.cpp:290
static bool ParseBusGroup(const wxString &aGroup, wxString *name, std::vector< wxString > *aMemberList)
Parse a bus group label into the name and a list of components.
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parse a bus vector (e.g.
static wxRegEx m_busGroupRegex
wxString IsValid(const wxString &aVal) const override
#define _(s)
Definitions of control validators for schematic dialogs.