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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
25
26#include <wx/combo.h>
27#include <wx/msgdlg.h>
28
29#include <sch_connection.h>
30#include <sch_validators.h>
32
33
34// Match opening curly brace, preceeded by start-of-line or by a character not including $_^~
35wxRegEx SCH_NETNAME_VALIDATOR::m_busGroupRegex( R"((^|[^$_\^~]){)", wxRE_ADVANCED );
36
37
38wxString SCH_NETNAME_VALIDATOR::IsValid( const wxString& str ) const
39{
40 wxString msg = NETNAME_VALIDATOR::IsValid( str );
41
42 if( !msg.IsEmpty() )
43 return msg;
44
45 // We don't do single-character validation here
46 if( str.Length() == 1 )
47 return wxString();
48
49 // Figuring out if the user "meant" to make a bus group is somewhat tricky because curly
50 // braces are also used for formatting and variable expansion
51
52 if( m_busGroupRegex.Matches( str ) && str.Contains( '}' ) )
53 {
54 if( !NET_SETTINGS::ParseBusGroup( str, nullptr, nullptr ) )
55 return _( "Signal name contains '{' and '}' but is not a valid bus name" );
56 }
57 else if( str.Contains( '[' ) || str.Contains( ']' ) )
58 {
59 if( !NET_SETTINGS::ParseBusVector( str, nullptr, nullptr ) )
60 return _( "Signal name contains '[' or ']' but is not a valid bus name." );
61 }
62
63 return wxString();
64}
wxString IsValid(const wxString &aVal) const override
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.