Commit 4a26d543 authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew: Add a minimal test for illegal chars in footprints libname (like space and dir separtor)

Also a minor cosmetic enhancement
parent 926dec84
......@@ -338,6 +338,7 @@ set( BMAPS_MID
library_browse
library_update
library
library_table
libview
lines90
load_module_board
......
This diff is collapsed.
This diff is collapsed.
......@@ -260,6 +260,7 @@ EXTERN_BITMAP( lib_previous_xpm )
EXTERN_BITMAP( library_browse_xpm )
EXTERN_BITMAP( library_update_xpm )
EXTERN_BITMAP( library_xpm )
EXTERN_BITMAP( library_table_xpm )
EXTERN_BITMAP( libview_xpm )
EXTERN_BITMAP( lines90_xpm )
EXTERN_BITMAP( load_module_board_xpm )
......
......@@ -139,7 +139,7 @@ MODULE::MODULE( const MODULE& aModule ) :
break;
default:
wxMessageBox( wxT( "MODULE::Copy() Internal Err: unknown type" ) );
wxLogMessage( wxT( "MODULE::Copy() Internal Err: unknown type" ) );
break;
}
}
......@@ -262,7 +262,7 @@ void MODULE::Copy( MODULE* aModule )
break;
default:
wxMessageBox( wxT( "MODULE::Copy() Internal Err: unknown type" ) );
wxLogMessage( wxT( "MODULE::Copy() Internal Err: unknown type" ) );
break;
}
}
......@@ -698,6 +698,41 @@ EDA_ITEM* MODULE::Clone() const
return new MODULE( *this );
}
/* Test for validity of the name in a library of the footprint
* ( no spaces, dir separators ... )
* return true if the given name is valid
* static function
*/
bool MODULE::IsLibNameValid( const wxString & aName )
{
const wxChar * invalids = ReturnStringLibNameInvalidChars( false );
if( aName.find_first_of( invalids ) != std::string::npos )
return false;
return true;
}
/* Test for validity of the name of a footprint to be used in a footprint library
* ( no spaces, dir separators ... )
* param bool aUserReadable = false to get the list of invalid chars
* true to get a readable form (i.e ' ' = 'space' '\t'= 'tab')
* return a constant string giving the list of invalid chars in lib name
* static function
*/
const wxChar* MODULE::ReturnStringLibNameInvalidChars( bool aUserReadable )
{
static const wxChar invalidChars[] = wxT("\t \"\\/");
static const wxChar invalidCharsReadable[] = wxT("'tab' 'space' \\ \" /");
if( aUserReadable )
return invalidCharsReadable;
else
return invalidChars;
}
#if defined(DEBUG)
......
......@@ -361,6 +361,25 @@ public:
EDA_ITEM* Clone() const;
/**
* static function IsLibNameValid
* Test for validity of a name of a footprint to be used in a footprint library
* ( no spaces, dir separators ... )
* @param aName = the name in library to validate
* @return true if the given name is valid
*/
static bool IsLibNameValid( const wxString & aName );
/**
* static function ReturnStringLibNameInvalidChars
* Test for validity of the name in a library of the footprint
* ( no spaces, dir separators ... )
* @param bool aUserReadable = false to get the list of invalid chars
* true to get a readable form (i.e ' ' = 'space' '\t'= 'tab')
* @return a constant std::string giving the list of invalid chars in lib name
*/
static const wxChar* ReturnStringLibNameInvalidChars( bool aUserReadable );
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const; // overload
#endif
......
......@@ -17,12 +17,12 @@ class DIALOG_MODULE_MODULE_EDITOR : public DIALOG_MODULE_MODULE_EDITOR_BASE
{
private:
FOOTPRINT_EDIT_FRAME* m_Parent;
MODULE* m_CurrentModule;
TEXTE_MODULE* m_ReferenceCopy;
TEXTE_MODULE* m_ValueCopy;
std::vector <S3D_MASTER*> m_Shapes3D_list;
int m_LastSelected3DShapeIndex;
FOOTPRINT_EDIT_FRAME* m_parent;
MODULE* m_currentModule;
TEXTE_MODULE* m_referenceCopy;
TEXTE_MODULE* m_valueCopy;
std::vector <S3D_MASTER*> m_shapes3D_list;
int m_lastSelected3DShapeIndex;
VERTEX_VALUE_CTRL * m_3D_Scale;
VERTEX_VALUE_CTRL * m_3D_Offset;
VERTEX_VALUE_CTRL * m_3D_Rotation;
......@@ -34,7 +34,7 @@ public:
~DIALOG_MODULE_MODULE_EDITOR();
private:
void InitModeditProperties();
void initModeditProperties();
void Transfert3DValuesToDisplay( S3D_MASTER * aStruct3DSource );
void TransfertDisplayTo3DValues( int aIndexSelection );
void OnEditValue( wxCommandEvent& event );
......
......@@ -566,6 +566,17 @@ bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibPath,
if( footprintName.IsEmpty() )
return false;
if( ! MODULE::IsLibNameValid( footprintName ) )
{
wxString msg;
msg.Printf( _("Error:\none of invalid chars <%s> found\nin <%s>" ),
MODULE::ReturnStringLibNameInvalidChars( true ),
GetChars( footprintName ) );
DisplayError( NULL, msg );
return false;
}
aModule->SetLibRef( footprintName );
}
......
......@@ -428,7 +428,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
AddMenuItem( configmenu, ID_PCB_LIB_TABLE_EDIT,
_( "Li&brary Tables" ), _( "Setup footprint libraries" ),
KiBitmap( library_xpm ) );
KiBitmap( library_table_xpm ) );
// Colors and Visibility are also handled by the layers manager toolbar
AddMenuItem( configmenu, ID_MENU_PCB_SHOW_HIDE_LAYERS_MANAGER_DIALOG,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment