Fix file naming bug when importing Eagle projects with . in file name.

Fixes lp:1747470

https://bugs.launchpad.net/kicad/+bug/1747470
This commit is contained in:
Wayne Stambaugh 2018-03-03 08:34:46 -05:00
parent 3760b6820f
commit aeae32b1a2
3 changed files with 37 additions and 22 deletions

View File

@ -4,7 +4,7 @@
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2013 CERN (www.cern.ch) * Copyright (C) 2013 CERN (www.cern.ch)
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -783,7 +783,8 @@ bool SCH_EDIT_FRAME::ImportFile( const wxString& aFileName, int aFileType )
g_RootSheet = pi->Load( fullFileName, &Kiway() ); g_RootSheet = pi->Load( fullFileName, &Kiway() );
projectpath = Kiway().Prj().GetProjectPath(); projectpath = Kiway().Prj().GetProjectPath();
newfilename = Prj().AbsolutePath( Prj().GetProjectName() ); newfilename.SetPath( Prj().GetProjectPath() );
newfilename.SetName( Prj().GetProjectName() );
newfilename.SetExt( SchematicFileExtension ); newfilename.SetExt( SchematicFileExtension );
m_CurrentSheet->clear(); m_CurrentSheet->clear();
@ -801,7 +802,8 @@ bool SCH_EDIT_FRAME::ImportFile( const wxString& aFileName, int aFileType )
BreakSegmentsOnJunctions(); BreakSegmentsOnJunctions();
SchematicCleanUp( true ); SchematicCleanUp( true );
GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 ); GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 );
GetScreen()->TestDanglingEnds(); // Only perform the dangling end test on root sheet. // Only perform the dangling end test on root sheet.
GetScreen()->TestDanglingEnds();
GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
Zoom_Automatique( false ); Zoom_Automatique( false );

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2016-2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -841,16 +841,18 @@ bool PCB_EDIT_FRAME::ImportFile( const wxString& aFileName, int aFileType )
switch( (IO_MGR::PCB_FILE_T) aFileType ) switch( (IO_MGR::PCB_FILE_T) aFileType )
{ {
case IO_MGR::EAGLE: case IO_MGR::EAGLE:
if( OpenProjectFiles( std::vector<wxString>( 1, aFileName ), if( OpenProjectFiles( std::vector<wxString>( 1, aFileName ), KICTL_EAGLE_BRD ) )
KICTL_EAGLE_BRD ) )
{ {
wxString projectpath = Kiway().Prj().GetProjectPath(); wxString projectpath = Kiway().Prj().GetProjectPath();
wxFileName newfilename = Prj().AbsolutePath( Prj().GetProjectName() ); wxFileName newfilename;
newfilename.SetPath( Prj().GetProjectPath() );
newfilename.SetName( Prj().GetProjectName() );
newfilename.SetExt( KiCadPcbFileExtension ); newfilename.SetExt( KiCadPcbFileExtension );
GetBoard()->SetFileName( newfilename.GetFullPath() ); GetBoard()->SetFileName( newfilename.GetFullPath() );
UpdateTitle(); UpdateTitle();
OnModify();
wxString newLibPath; wxString newLibPath;
ArchiveModulesOnBoard( true, newfilename.GetName(), &newLibPath ); ArchiveModulesOnBoard( true, newfilename.GetName(), &newLibPath );
@ -865,9 +867,11 @@ bool PCB_EDIT_FRAME::ImportFile( const wxString& aFileName, int aFileType )
wxGetEnv( project_env, &env_path ); wxGetEnv( project_env, &env_path );
wxString result( newLibPath ); wxString result( newLibPath );
rel_path = result.Replace( env_path, wxString( "$(" + project_env + ")" ) ) ? result : "" ; rel_path = result.Replace( env_path,
wxString( "$(" + project_env + ")" ) ) ? result : "" ;
if( !rel_path.IsEmpty() ) newLibPath = rel_path; if( !rel_path.IsEmpty() )
newLibPath = rel_path;
FP_LIB_TABLE_ROW* row = new FP_LIB_TABLE_ROW( newfilename.GetName(), FP_LIB_TABLE_ROW* row = new FP_LIB_TABLE_ROW( newfilename.GetName(),
newLibPath, newLibPath,

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -129,7 +129,8 @@ static wxFileName getFootprintFilenameFromUser( wxWindow* aParent, const wxStrin
* @param aFileName - file name to be read * @param aFileName - file name to be read
* @param aName - wxString to receive the module name iff type is LEGACY * @param aName - wxString to receive the module name iff type is LEGACY
*/ */
static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName, wxString* aName ) static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFileName,
wxString* aName )
{ {
FILE_LINE_READER freader( aFile, aFileName.GetFullPath() ); FILE_LINE_READER freader( aFile, aFileName.GetFullPath() );
WHITESPACE_FILTER_READER reader( freader ); WHITESPACE_FILTER_READER reader( freader );
@ -148,6 +149,7 @@ static IO_MGR::PCB_FILE_T detect_file_type( FILE* aFile, const wxFileName& aFile
else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) ) else if( !strncasecmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
{ {
file_type = IO_MGR::LEGACY; file_type = IO_MGR::LEGACY;
while( reader.ReadLine() ) while( reader.ReadLine() )
{ {
if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) ) if( !strncasecmp( line, "$MODULE", strlen( "$MODULE" ) ) )
@ -469,9 +471,12 @@ wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary(const wxString& aLibName )
wxFileName fn = aLibName; wxFileName fn = aLibName;
if( !fn.IsAbsolute() ) if( !fn.IsAbsolute() )
{
fn.SetName( aLibName );
fn.MakeAbsolute( initialPath ); fn.MakeAbsolute( initialPath );
}
// Enforce the extension: // Enforce the .pretty extension:
fn.SetExt( KiCadFootprintLibPathExtension ); fn.SetExt( KiCadFootprintLibPathExtension );
libPath = fn.GetFullPath(); libPath = fn.GetFullPath();
@ -588,7 +593,8 @@ bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary()
} }
void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName, wxString* aLibPath ) void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName,
wxString* aLibPath )
{ {
if( GetBoard()->m_Modules == NULL ) if( GetBoard()->m_Modules == NULL )
{ {
@ -702,17 +708,20 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary( wxString activeLibrary, MODUL
wxSizer* mainSizer = dlg.GetSizer(); wxSizer* mainSizer = dlg.GetSizer();
wxStaticLine* separator = new wxStaticLine( &dlg, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); wxStaticLine* separator = new wxStaticLine( &dlg, wxID_ANY, wxDefaultPosition,
wxDefaultSize, wxLI_HORIZONTAL );
mainSizer->Prepend( separator, 0, wxEXPAND|wxBOTTOM|wxTOP, 10 ); mainSizer->Prepend( separator, 0, wxEXPAND|wxBOTTOM|wxTOP, 10 );
wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, footprintName, wxDefaultPosition, wxDefaultSize, 0 ); wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, footprintName,
wxDefaultPosition, wxDefaultSize, 0 );
mainSizer->Prepend( nameTextCtrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); mainSizer->Prepend( nameTextCtrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST ); wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
nameValidator.SetCharExcludes( MODULE::StringLibNameInvalidChars( true ) ); nameValidator.SetCharExcludes( MODULE::StringLibNameInvalidChars( true ) );
nameTextCtrl->SetValidator( nameValidator ); nameTextCtrl->SetValidator( nameValidator );
wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Footprint Name:" ), wxDefaultPosition, wxDefaultSize, 0 ); wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Footprint Name:" ),
wxDefaultPosition, wxDefaultSize, 0 );
mainSizer->Prepend( label, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); mainSizer->Prepend( label, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
// Move nameTextCtrl to the head of the tab-order // Move nameTextCtrl to the head of the tab-order