You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.4 KiB

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