Fixed library path resolution in Spice netlist exporter
SEARCH_STACK is a deprecated method for getting the list of paths where one could look for a file. Instead it tries the project path and environmental variables.
This commit is contained in:
parent
31083a4060
commit
33cf082c41
|
@ -110,3 +110,43 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars
|
||||||
|
|
||||||
return normalizedFullPath;
|
return normalizedFullPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Create file path by appending path and file name. This approach allows the filename
|
||||||
|
// to contain a relative path, whereas wxFileName::SetPath() would replace the
|
||||||
|
// relative path
|
||||||
|
static wxString createFilePath( const wxString& aPath, const wxString& aFileName )
|
||||||
|
{
|
||||||
|
wxString path( aPath );
|
||||||
|
|
||||||
|
if( !path.EndsWith( wxFileName::GetPathSeparator() ) )
|
||||||
|
path.Append( wxFileName::GetPathSeparator() );
|
||||||
|
|
||||||
|
return path + aFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxString ResolveFile( const wxString& aFileName, const ENV_VAR_MAP* aEnvVars,
|
||||||
|
const PROJECT* aProject )
|
||||||
|
{
|
||||||
|
if( aProject )
|
||||||
|
{
|
||||||
|
wxFileName fn( createFilePath( aProject->GetProjectPath(), aFileName ) );
|
||||||
|
|
||||||
|
if( fn.Exists() )
|
||||||
|
return fn.GetFullPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
if( aEnvVars )
|
||||||
|
{
|
||||||
|
for( auto& entry : *aEnvVars )
|
||||||
|
{
|
||||||
|
wxFileName fn( createFilePath( entry.second.GetValue(), aFileName ) );
|
||||||
|
|
||||||
|
if( fn.Exists() )
|
||||||
|
return fn.GetFullPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return wxEmptyString;
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <netlist.h>
|
#include <netlist.h>
|
||||||
#include <sch_reference_list.h>
|
#include <sch_reference_list.h>
|
||||||
#include <class_netlist_object.h>
|
#include <class_netlist_object.h>
|
||||||
|
#include <env_paths.h>
|
||||||
|
|
||||||
#include <wx/tokenzr.h>
|
#include <wx/tokenzr.h>
|
||||||
#include <wx/regex.h>
|
#include <wx/regex.h>
|
||||||
|
@ -72,10 +73,10 @@ bool NETLIST_EXPORTER_PSPICE::Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl
|
||||||
{
|
{
|
||||||
wxString full_path;
|
wxString full_path;
|
||||||
|
|
||||||
if( ( aCtl & NET_ADJUST_INCLUDE_PATHS ) && m_paths )
|
if( ( aCtl & NET_ADJUST_INCLUDE_PATHS ) )
|
||||||
{
|
{
|
||||||
// Look for the library in known search locations
|
// Look for the library in known search locations
|
||||||
full_path = m_paths->FindValidPath( lib );
|
full_path = ResolveFile( lib, &Pgm().GetLocalEnvVariables(), m_project );
|
||||||
|
|
||||||
if( full_path.IsEmpty() )
|
if( full_path.IsEmpty() )
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class SEARCH_STACK;
|
class PROJECT;
|
||||||
|
|
||||||
/// Flags for Spice netlist generation (can be combined)
|
/// Flags for Spice netlist generation (can be combined)
|
||||||
enum SPICE_NETLIST_OPTIONS {
|
enum SPICE_NETLIST_OPTIONS {
|
||||||
|
@ -99,9 +99,9 @@ struct SPICE_ITEM
|
||||||
class NETLIST_EXPORTER_PSPICE : public NETLIST_EXPORTER
|
class NETLIST_EXPORTER_PSPICE : public NETLIST_EXPORTER
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NETLIST_EXPORTER_PSPICE( NETLIST_OBJECT_LIST* aMasterList, SEARCH_STACK* aPaths = NULL ) :
|
NETLIST_EXPORTER_PSPICE( NETLIST_OBJECT_LIST* aMasterList, PROJECT* aProject = NULL ) :
|
||||||
NETLIST_EXPORTER( aMasterList ),
|
NETLIST_EXPORTER( aMasterList ),
|
||||||
m_paths( aPaths )
|
m_project( aProject )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,8 +228,8 @@ private:
|
||||||
///> List of items representing schematic components in the Spice world
|
///> List of items representing schematic components in the Spice world
|
||||||
SPICE_ITEM_LIST m_spiceItems;
|
SPICE_ITEM_LIST m_spiceItems;
|
||||||
|
|
||||||
///> Paths to be searched for included Spice libraries
|
///> Project object to fetch its settings (e.g. paths)
|
||||||
SEARCH_STACK* m_paths;
|
PROJECT* m_project;
|
||||||
|
|
||||||
// Component fields that are processed during netlist export & simulation
|
// Component fields that are processed during netlist export & simulation
|
||||||
static const std::vector<wxString> m_spiceFields;
|
static const std::vector<wxString> m_spiceFields;
|
||||||
|
|
|
@ -36,8 +36,8 @@
|
||||||
class NETLIST_EXPORTER_PSPICE_SIM : public NETLIST_EXPORTER_PSPICE
|
class NETLIST_EXPORTER_PSPICE_SIM : public NETLIST_EXPORTER_PSPICE
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NETLIST_EXPORTER_PSPICE_SIM( NETLIST_OBJECT_LIST* aMasterList ) :
|
NETLIST_EXPORTER_PSPICE_SIM( NETLIST_OBJECT_LIST* aMasterList, PROJECT* aProject = nullptr ) :
|
||||||
NETLIST_EXPORTER_PSPICE( aMasterList )
|
NETLIST_EXPORTER_PSPICE( aMasterList, aProject )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -459,7 +459,7 @@ void SIM_PLOT_FRAME::removePlot( const wxString& aPlotName, bool aErase )
|
||||||
|
|
||||||
void SIM_PLOT_FRAME::updateNetlistExporter()
|
void SIM_PLOT_FRAME::updateNetlistExporter()
|
||||||
{
|
{
|
||||||
m_exporter.reset( new NETLIST_EXPORTER_PSPICE_SIM( m_schematicFrame->BuildNetListBase() ) );
|
m_exporter.reset( new NETLIST_EXPORTER_PSPICE_SIM( m_schematicFrame->BuildNetListBase(), &Prj() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalizes a file path to an environmental variable, if possible.
|
* Normalizes a file path to an environmental variable, if possible.
|
||||||
*
|
*
|
||||||
* @param aFilePath is the full file path (path and file name) to be normalized.
|
* @param aFilePath is the full file path (path and file name) to be normalized.
|
||||||
* @param aEnvVars is an optional map of environmental variables to try substition with.
|
* @param aEnvVars is an optional map of environmental variables to try substition with.
|
||||||
* @param aProject is an optional project, to normalize the file path to the project path.
|
* @param aProject is an optional project, to normalize the file path to the project path.
|
||||||
|
@ -39,4 +39,16 @@
|
||||||
wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars,
|
wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars,
|
||||||
const PROJECT* aProject );
|
const PROJECT* aProject );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches the default paths trying to find one with the requested file.
|
||||||
|
*
|
||||||
|
* @param aFileName is the name of the searched file. It might be a relative path.
|
||||||
|
* @param aEnvVars is an optional map of environmental variables that can contain paths.
|
||||||
|
* @param aProject is an optional project, to check the project path.
|
||||||
|
* @return Full path (apth and file name) if the file was found in one of the paths, otherwise
|
||||||
|
* an empty string.
|
||||||
|
*/
|
||||||
|
wxString ResolveFile( const wxString& aFileName, const ENV_VAR_MAP* aEnvVars,
|
||||||
|
const PROJECT* aProject );
|
||||||
|
|
||||||
#endif /* ENV_PATHS_H */
|
#endif /* ENV_PATHS_H */
|
||||||
|
|
Loading…
Reference in New Issue