KiCad PCB EDA Suite
SCH_NETNAME_VALIDATOR Class Reference

#include <sch_validators.h>

Inheritance diagram for SCH_NETNAME_VALIDATOR:
NETNAME_VALIDATOR

Public Member Functions

 SCH_NETNAME_VALIDATOR (wxString *aVal=nullptr)
 
 SCH_NETNAME_VALIDATOR (bool aAllowSpaces)
 
 SCH_NETNAME_VALIDATOR (const SCH_NETNAME_VALIDATOR &aValidator)
 
virtual wxObject * Clone () const override
 
virtual bool TransferToWindow () override
 
virtual bool TransferFromWindow () override
 
virtual bool Validate (wxWindow *aParent) override
 

Protected Member Functions

wxString IsValid (const wxString &aVal) const override
 

Static Private Attributes

static wxRegEx m_busGroupRegex
 

Detailed Description

Definition at line 78 of file sch_validators.h.

Constructor & Destructor Documentation

◆ SCH_NETNAME_VALIDATOR() [1/3]

SCH_NETNAME_VALIDATOR::SCH_NETNAME_VALIDATOR ( wxString *  aVal = nullptr)
inline

Definition at line 81 of file sch_validators.h.

81  :
82  NETNAME_VALIDATOR( aVal )
83  { }
NETNAME_VALIDATOR(wxString *aVal=nullptr)
Definition: validators.cpp:319

Referenced by Clone().

◆ SCH_NETNAME_VALIDATOR() [2/3]

SCH_NETNAME_VALIDATOR::SCH_NETNAME_VALIDATOR ( bool  aAllowSpaces)
inline

Definition at line 85 of file sch_validators.h.

85  :
86  NETNAME_VALIDATOR( aAllowSpaces )
87  { }
NETNAME_VALIDATOR(wxString *aVal=nullptr)
Definition: validators.cpp:319

◆ SCH_NETNAME_VALIDATOR() [3/3]

SCH_NETNAME_VALIDATOR::SCH_NETNAME_VALIDATOR ( const SCH_NETNAME_VALIDATOR aValidator)
inline

Definition at line 89 of file sch_validators.h.

89  :
90  NETNAME_VALIDATOR( aValidator )
91  { }
NETNAME_VALIDATOR(wxString *aVal=nullptr)
Definition: validators.cpp:319

Member Function Documentation

◆ Clone()

virtual wxObject* SCH_NETNAME_VALIDATOR::Clone ( ) const
inlineoverridevirtual

Reimplemented from NETNAME_VALIDATOR.

Definition at line 93 of file sch_validators.h.

93 { return new SCH_NETNAME_VALIDATOR( *this ); }
SCH_NETNAME_VALIDATOR(wxString *aVal=nullptr)

References SCH_NETNAME_VALIDATOR().

◆ IsValid()

wxString SCH_NETNAME_VALIDATOR::IsValid ( const wxString &  aVal) const
overrideprotected
Returns
the error message if the contents of aVal are invalid.

Definition at line 209 of file sch_validators.cpp.

210 {
211  wxString msg = NETNAME_VALIDATOR::IsValid( str );
212 
213  if( !msg.IsEmpty() )
214  return msg;
215 
216  // We don't do single-character validation here
217  if( str.Length() == 1 )
218  return wxString();
219 
220  // Figuring out if the user "meant" to make a bus group is somewhat tricky because curly
221  // braces are also used for formatting and variable expansion
222 
223  if( m_busGroupRegex.Matches( str ) && str.Contains( '}' ) )
224  {
225  if( !NET_SETTINGS::ParseBusGroup( str, nullptr, nullptr ) )
226  return _( "Signal name contains '{' and '}' but is not a valid bus name" );
227  }
228  else if( str.Contains( '[' ) || str.Contains( ']' ) )
229  {
230  if( !NET_SETTINGS::ParseBusVector( str, nullptr, nullptr ) )
231  return _( "Signal name contains '[' or ']' but is not a valid bus name." );
232  }
233 
234  return wxString();
235 }
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 wxRegEx m_busGroupRegex
#define _(s)
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parse a bus vector (e.g.
wxString IsValid(const wxString &aVal) const override
Definition: validators.cpp:364

References _, NETNAME_VALIDATOR::IsValid(), m_busGroupRegex, NET_SETTINGS::ParseBusGroup(), and NET_SETTINGS::ParseBusVector().

◆ TransferFromWindow()

virtual bool NETNAME_VALIDATOR::TransferFromWindow ( )
inlineoverridevirtualinherited

Definition at line 207 of file validators.h.

207 { return true; }

◆ TransferToWindow()

virtual bool NETNAME_VALIDATOR::TransferToWindow ( )
inlineoverridevirtualinherited

Definition at line 205 of file validators.h.

205 { return true; }

◆ Validate()

bool NETNAME_VALIDATOR::Validate ( wxWindow *  aParent)
overridevirtualinherited

Definition at line 340 of file validators.cpp.

341 {
342  // If window is disabled, simply return
343  if ( !m_validatorWindow->IsEnabled() )
344  return true;
345 
346  wxTextEntry * const text = GetTextEntry();
347 
348  if ( !text )
349  return false;
350 
351  const wxString& errormsg = IsValid( text->GetValue() );
352 
353  if( !errormsg.empty() )
354  {
355  m_validatorWindow->SetFocus();
356  wxMessageBox( errormsg, _( "Invalid signal name" ), wxOK | wxICON_EXCLAMATION, aParent );
357  return false;
358  }
359 
360  return true;
361 }
#define _(s)
wxString IsValid(const wxString &aVal) const override
Definition: validators.cpp:364

References _, NETNAME_VALIDATOR::IsValid(), and text.

Member Data Documentation

◆ m_busGroupRegex

wxRegEx SCH_NETNAME_VALIDATOR::m_busGroupRegex
staticprivate

Definition at line 100 of file sch_validators.h.

Referenced by IsValid().


The documentation for this class was generated from the following files: