Unify string lists of forbidden footprint chars

We have forbidden lists maintained in 3 separate locations.  This causes
a bit of confusion as to which is correct.

This makes the list uniform but remains to place the character set in a
single location.
This commit is contained in:
Seth Hillbrand 2019-06-29 13:31:11 -07:00
parent 7b2d6ab40e
commit 43768b71c0
7 changed files with 23 additions and 19 deletions

View File

@ -374,10 +374,16 @@ bool LIB_ID::isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType )
if( aUniChar < ' ' )
return false;
// This list of characters is also duplicated in validators.cpp and
// class_module.cpp
// TODO: Unify forbidden character lists
switch( aUniChar )
{
case ':':
case '/':
case '\t':
case '\n':
case '\r':
return false;
case '\\':

View File

@ -68,20 +68,14 @@ void GRID_CELL_TEXT_EDITOR::StartingKey( wxKeyEvent& event )
}
FILE_NAME_CHAR_VALIDATOR::FILE_NAME_CHAR_VALIDATOR( wxString* aValue ) :
MODULE_NAME_CHAR_VALIDATOR::MODULE_NAME_CHAR_VALIDATOR( wxString* aValue ) :
wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
{
// The Windows (DOS) file system forbidden characters already include the forbidden
// file name characters for both Posix and OSX systems. The characters \/:*?|"<> are
// illegal and filtered by the validator.
wxString illegalChars = wxFileName::GetForbiddenChars( wxPATH_DOS );
wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
wxArrayString illegalCharList;
for( unsigned i = 0; i < illegalChars.size(); i++ )
illegalCharList.Add( wxString( illegalChars[i] ) );
SetExcludes( illegalCharList );
// This list of characters follows the string from class_module.cpp
// which, in turn mimics the strings from lib_id.cpp
// TODO: Unify forbidden character lists
wxString illegalChars = "%$<>\t\n\r\"\\/:";
SetCharExcludes( illegalChars );
}

View File

@ -60,10 +60,10 @@ protected:
* footprint names cannot have any characters that would prevent file creation on any platform.
* The characters \/:*?|"<> are illegal and filtered by the validator.
*/
class FILE_NAME_CHAR_VALIDATOR : public wxTextValidator
class MODULE_NAME_CHAR_VALIDATOR : public wxTextValidator
{
public:
FILE_NAME_CHAR_VALIDATOR( wxString* aValue = NULL );
MODULE_NAME_CHAR_VALIDATOR( wxString* aValue = NULL );
};

View File

@ -43,6 +43,7 @@
#include <class_edge_mod.h>
#include <class_module.h>
#include <convert_basic_shapes_to_polygon.h>
#include <validators.h>
#include <view/view.h>
MODULE::MODULE( BOARD* parent ) :
@ -1025,8 +1026,11 @@ bool MODULE::IsLibNameValid( const wxString & aName )
const wxChar* MODULE::StringLibNameInvalidChars( bool aUserReadable )
{
static const wxChar invalidChars[] = wxT("%$\t\n\r \"\\/:");
static const wxChar invalidCharsReadable[] = wxT("% $ 'tab' 'return' 'line feed' 'space' \\ \" / :");
// This list of characters is also duplicated in validators.cpp and
// lib_id.cpp
// TODO: Unify forbidden character lists
static const wxChar invalidChars[] = wxT("%$<>\t\n\r\"\\/:");
static const wxChar invalidCharsReadable[] = wxT("% $ < > 'tab' 'return' 'line feed' \\ \" / :");
if( aUserReadable )
return invalidCharsReadable;

View File

@ -106,7 +106,7 @@ DIALOG_FOOTPRINT_FP_EDITOR::DIALOG_FOOTPRINT_FP_EDITOR( FOOTPRINT_EDIT_FRAME* aP
bLowerSizer3D->Add( m_PreviewPane, 1, wxEXPAND, 5 );
m_FootprintNameCtrl->SetValidator( FILE_NAME_CHAR_VALIDATOR() );
m_FootprintNameCtrl->SetValidator( MODULE_NAME_CHAR_VALIDATOR() );
// Set font sizes
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );

View File

@ -1046,7 +1046,7 @@ MODULE* PCB_BASE_FRAME::CreateNewModule( const wxString& aModuleName )
if( moduleName.IsEmpty() )
{
WX_TEXT_ENTRY_DIALOG dlg( this, FMT_MOD_REF, FMT_MOD_CREATE, moduleName );
dlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &moduleName ) );
dlg.SetTextValidator( MODULE_NAME_CHAR_VALIDATOR( &moduleName ) );
if( dlg.ShowModal() != wxID_OK )
return NULL; //Aborted by user

View File

@ -373,7 +373,7 @@ MODULE* MWAVE::CreateMicrowaveInductor( INDUCTOR_PATTERN& inductorPattern,
// Generate footprint. the value is also used as footprint name.
msg = "L";
WX_TEXT_ENTRY_DIALOG cmpdlg( aPcbFrame, _( "Component Value:" ), wxEmptyString, msg );
cmpdlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &msg ) );
cmpdlg.SetTextValidator( MODULE_NAME_CHAR_VALIDATOR( &msg ) );
if( ( cmpdlg.ShowModal() != wxID_OK ) || msg.IsEmpty() )
return nullptr; // Aborted by user