Revert "libngspice is linked at compile time"
This reverts commit 75f8b20493
.
In case of problems, ngspice demands to be detached which is not
possible when it is linked at compile time.
This commit is contained in:
parent
dfd2a8fc48
commit
33620ecc85
|
@ -316,7 +316,6 @@ target_link_libraries( eeschema_kiface
|
|||
gal
|
||||
${wxWidgets_LIBRARIES}
|
||||
${GDI_PLUS_LIBRARIES}
|
||||
${NGSPICE_LIBRARY}
|
||||
)
|
||||
set_target_properties( eeschema_kiface PROPERTIES
|
||||
# Decorate OUTPUT_NAME with PREFIX and SUFFIX, creating something like
|
||||
|
|
|
@ -29,24 +29,33 @@
|
|||
#include <common.h> // LOCALE_IO
|
||||
#include <wx/stdpaths.h>
|
||||
#include <wx/dir.h>
|
||||
#include <wx/dynlib.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace std;
|
||||
|
||||
NGSPICE::NGSPICE()
|
||||
{
|
||||
init();
|
||||
init_dll();
|
||||
}
|
||||
|
||||
|
||||
NGSPICE::~NGSPICE()
|
||||
{
|
||||
delete m_dll;
|
||||
}
|
||||
|
||||
|
||||
void NGSPICE::Init()
|
||||
{
|
||||
if( m_error )
|
||||
{
|
||||
delete m_dll;
|
||||
init_dll();
|
||||
}
|
||||
|
||||
Command( "reset" );
|
||||
}
|
||||
|
||||
|
@ -55,7 +64,7 @@ vector<COMPLEX> NGSPICE::GetPlot( const string& aName, int aMaxLen )
|
|||
{
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
vector<COMPLEX> data;
|
||||
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
||||
vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
|
||||
|
||||
if( vi )
|
||||
{
|
||||
|
@ -82,7 +91,7 @@ vector<double> NGSPICE::GetRealPlot( const string& aName, int aMaxLen )
|
|||
{
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
vector<double> data;
|
||||
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
||||
vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
|
||||
|
||||
if( vi )
|
||||
{
|
||||
|
@ -114,7 +123,7 @@ vector<double> NGSPICE::GetImagPlot( const string& aName, int aMaxLen )
|
|||
{
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
vector<double> data;
|
||||
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
||||
vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
|
||||
|
||||
if( vi )
|
||||
{
|
||||
|
@ -138,7 +147,7 @@ vector<double> NGSPICE::GetMagPlot( const string& aName, int aMaxLen )
|
|||
{
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
vector<double> data;
|
||||
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
||||
vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
|
||||
|
||||
if( vi )
|
||||
{
|
||||
|
@ -165,7 +174,7 @@ vector<double> NGSPICE::GetPhasePlot( const string& aName, int aMaxLen )
|
|||
{
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
vector<double> data;
|
||||
vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() );
|
||||
vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
|
||||
|
||||
if( vi )
|
||||
{
|
||||
|
@ -205,8 +214,7 @@ bool NGSPICE::LoadNetlist( const string& aNetlist )
|
|||
}
|
||||
|
||||
lines.push_back( nullptr );
|
||||
|
||||
ngSpice_Circ( lines.data() );
|
||||
m_ngSpice_Circ( lines.data() );
|
||||
|
||||
for( auto line : lines )
|
||||
free( line );
|
||||
|
@ -232,15 +240,14 @@ bool NGSPICE::Stop()
|
|||
bool NGSPICE::IsRunning()
|
||||
{
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
return ngSpice_running();
|
||||
return m_ngSpice_Running();
|
||||
}
|
||||
|
||||
|
||||
bool NGSPICE::Command( const string& aCmd )
|
||||
{
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
ngSpice_Command( (char*) aCmd.c_str() );
|
||||
|
||||
m_ngSpice_Command( (char*) aCmd.c_str() );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -270,13 +277,34 @@ string NGSPICE::GetXAxis( SIM_TYPE aType ) const
|
|||
}
|
||||
|
||||
|
||||
void NGSPICE::init()
|
||||
void NGSPICE::init_dll()
|
||||
{
|
||||
if( m_initialized )
|
||||
return;
|
||||
|
||||
LOCALE_IO c_locale; // ngspice works correctly only with C locale
|
||||
ngSpice_Init( &cbSendChar, &cbSendStat, &cbControlledExit, NULL, NULL, &cbBGThreadRunning, this );
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
m_dll = new wxDynamicLibrary( "libngspice-0.dll" );
|
||||
#else
|
||||
m_dll = new wxDynamicLibrary( wxDynamicLibrary::CanonicalizeName( "ngspice" ) );
|
||||
#endif
|
||||
|
||||
if( !m_dll || !m_dll->IsLoaded() )
|
||||
throw std::runtime_error( "Missing ngspice shared library" );
|
||||
|
||||
m_error = false;
|
||||
|
||||
// Obtain function pointers
|
||||
m_ngSpice_Init = (ngSpice_Init) m_dll->GetSymbol( "ngSpice_Init" );
|
||||
m_ngSpice_Circ = (ngSpice_Circ) m_dll->GetSymbol( "ngSpice_Circ" );
|
||||
m_ngSpice_Command = (ngSpice_Command) m_dll->GetSymbol( "ngSpice_Command" );
|
||||
m_ngGet_Vec_Info = (ngGet_Vec_Info) m_dll->GetSymbol( "ngGet_Vec_Info" );
|
||||
m_ngSpice_AllPlots = (ngSpice_AllPlots) m_dll->GetSymbol( "ngSpice_AllPlots" );
|
||||
m_ngSpice_AllVecs = (ngSpice_AllVecs) m_dll->GetSymbol( "ngSpice_AllVecs" );
|
||||
m_ngSpice_Running = (ngSpice_Running) m_dll->GetSymbol( "ngSpice_running" ); // it is not a typo
|
||||
|
||||
m_ngSpice_Init( &cbSendChar, &cbSendStat, &cbControlledExit, NULL, NULL, &cbBGThreadRunning, this );
|
||||
|
||||
// Load a custom spinit file, to fix the problem with loading .cm files
|
||||
// Switch to the executable directory, so the relative paths are correct
|
||||
|
@ -321,8 +349,8 @@ void NGSPICE::init()
|
|||
// Restore the working directory
|
||||
wxSetWorkingDirectory( cwd );
|
||||
|
||||
// Workarounds to avoid hang ups on certain errors,
|
||||
// they have to be called, no matter what is in the spinit file
|
||||
// Workarounds to avoid hang ups on certain errors
|
||||
// These commands have to be called, no matter what is in the spinit file
|
||||
Command( "unset interactive" );
|
||||
Command( "set noaskquit" );
|
||||
Command( "set nomoremode" );
|
||||
|
|
|
@ -79,6 +79,30 @@ public:
|
|||
private:
|
||||
void init();
|
||||
|
||||
// Performs DLL initialization, obtains function pointers
|
||||
void init_dll();
|
||||
|
||||
// ngspice library functions
|
||||
typedef void (*ngSpice_Init)( SendChar*, SendStat*, ControlledExit*,
|
||||
SendData*, SendInitData*, BGThreadRunning*, void* );
|
||||
typedef int (*ngSpice_Circ)( char** circarray );
|
||||
typedef int (*ngSpice_Command)( char* command );
|
||||
typedef pvector_info (*ngGet_Vec_Info)( char* vecname );
|
||||
typedef char** (*ngSpice_AllPlots)( void );
|
||||
typedef char** (*ngSpice_AllVecs)( char* plotname );
|
||||
typedef bool (*ngSpice_Running)( void );
|
||||
|
||||
///> Handles to DLL functions
|
||||
ngSpice_Init m_ngSpice_Init;
|
||||
ngSpice_Circ m_ngSpice_Circ;
|
||||
ngSpice_Command m_ngSpice_Command;
|
||||
ngGet_Vec_Info m_ngGet_Vec_Info;
|
||||
ngSpice_AllPlots m_ngSpice_AllPlots;
|
||||
ngSpice_AllVecs m_ngSpice_AllVecs;
|
||||
ngSpice_Running m_ngSpice_Running;
|
||||
|
||||
wxDynamicLibrary* m_dll;
|
||||
|
||||
///> Executes commands from a file
|
||||
bool loadSpinit( const std::string& aFileName );
|
||||
|
||||
|
@ -97,6 +121,9 @@ private:
|
|||
|
||||
void dump();
|
||||
|
||||
///> Error flag, meaning ngspice needs to be reloaded
|
||||
bool m_error;
|
||||
|
||||
///> NGspice should be initialized only once
|
||||
static bool m_initialized;
|
||||
|
||||
|
|
Loading…
Reference in New Issue