SCH_LEGACY_PLUGIN::loadHierarchy() uses a stack to maintain sheet paths
Path keeping stack copes well with paths pointing outside the project directory (e.g. "../path"). The so far used wxFileName::GetDirCount() and wxFileName::RemoveLastDir() remove too many directories, as ".." is also counted as a directory. Fixes: lp:1769746 * https://bugs.launchpad.net/kicad/+bug/1769746
This commit is contained in:
parent
6866c0c8a5
commit
194c57133c
|
@ -615,6 +615,7 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
|
||||||
m_path = aKiway->Prj().GetProjectPath();
|
m_path = aKiway->Prj().GetProjectPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_currentPath.push( m_path );
|
||||||
init( aKiway, aProperties );
|
init( aKiway, aProperties );
|
||||||
|
|
||||||
if( aAppendToMe == NULL )
|
if( aAppendToMe == NULL )
|
||||||
|
@ -636,6 +637,8 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
|
||||||
loadHierarchy( sheet );
|
loadHierarchy( sheet );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
|
||||||
|
|
||||||
return sheet;
|
return sheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -652,20 +655,17 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet )
|
||||||
// stores the file name and extension. Add the project path to the file name and
|
// stores the file name and extension. Add the project path to the file name and
|
||||||
// extension to compare when calling SCH_SHEET::SearchHierarchy().
|
// extension to compare when calling SCH_SHEET::SearchHierarchy().
|
||||||
wxFileName fileName = aSheet->GetFileName();
|
wxFileName fileName = aSheet->GetFileName();
|
||||||
size_t dirCount = 0;
|
|
||||||
|
|
||||||
if( !fileName.IsAbsolute() )
|
if( !fileName.IsAbsolute() )
|
||||||
{
|
fileName.MakeAbsolute( m_currentPath.top() );
|
||||||
dirCount = fileName.GetDirCount();
|
|
||||||
fileName.MakeAbsolute( m_path );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the current path so that it gets restored when decending and ascending the
|
// Save the current path so that it gets restored when decending and ascending the
|
||||||
// sheet hierarchy which allows for sheet schematic files to be nested in folders
|
// sheet hierarchy which allows for sheet schematic files to be nested in folders
|
||||||
// relative to the last path a schematic was loaded from.
|
// relative to the last path a schematic was loaded from.
|
||||||
m_path = fileName.GetPath();
|
wxLogTrace( traceSchLegacyPlugin, "Saving path \"%s\"", m_currentPath.top() );
|
||||||
|
m_currentPath.push( fileName.GetPath() );
|
||||||
wxLogTrace( traceSchLegacyPlugin, "Saving last path \"%s\"", m_path );
|
wxLogTrace( traceSchLegacyPlugin, "Current path \"%s\"", m_currentPath.top() );
|
||||||
|
wxLogTrace( traceSchLegacyPlugin, "Loading \"%s\"", fileName.GetFullPath() );
|
||||||
|
|
||||||
m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
|
m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
|
||||||
|
|
||||||
|
@ -720,15 +720,8 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Back out any relative paths so the last sheet file path is correct.
|
m_currentPath.pop();
|
||||||
while( dirCount )
|
wxLogTrace( traceSchLegacyPlugin, "Restoring path \"%s\"", m_currentPath.top() );
|
||||||
{
|
|
||||||
fileName.RemoveLastDir();
|
|
||||||
dirCount--;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxLogTrace( traceSchLegacyPlugin, "Restoring last path \"%s\"", fileName.GetPath() );
|
|
||||||
m_path = fileName.GetPath();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sch_io_mgr.h>
|
#include <sch_io_mgr.h>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
|
|
||||||
class KIWAY;
|
class KIWAY;
|
||||||
|
@ -162,6 +163,7 @@ protected:
|
||||||
wxString m_error;
|
wxString m_error;
|
||||||
|
|
||||||
wxString m_path; ///< Root project path for loading child sheets.
|
wxString m_path; ///< Root project path for loading child sheets.
|
||||||
|
std::stack<wxString> m_currentPath; ///< Stack to maintain nested sheet paths
|
||||||
const PROPERTIES* m_props; ///< Passed via Save() or Load(), no ownership, may be NULL.
|
const PROPERTIES* m_props; ///< Passed via Save() or Load(), no ownership, may be NULL.
|
||||||
KIWAY* m_kiway; ///< Required for path to legacy component libraries.
|
KIWAY* m_kiway; ///< Required for path to legacy component libraries.
|
||||||
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded..
|
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded..
|
||||||
|
|
Loading…
Reference in New Issue