From 75f8b20493100ac103476d3d3d33c140d92a0b15 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 15 Aug 2016 13:52:13 +0200 Subject: [PATCH] libngspice is linked at compile time --- eeschema/CMakeLists.txt | 1 + eeschema/sim/ngspice.cpp | 50 +++++++++++----------------------------- eeschema/sim/ngspice.h | 24 +------------------ 3 files changed, 15 insertions(+), 60 deletions(-) diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index b9e4faada6..59e714e68c 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -288,6 +288,7 @@ 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 diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index 0d5f456ca7..73d701d88b 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -26,32 +26,25 @@ #include "ngspice.h" #include "spice_reporter.h" -#include -#include #include -#include using namespace std; NGSPICE::NGSPICE() { - init_dll(); + init(); } NGSPICE::~NGSPICE() { - delete m_dll; } void NGSPICE::Init() { if( m_error ) - { - delete m_dll; - init_dll(); - } + init(); Command( "reset" ); } @@ -61,7 +54,7 @@ vector NGSPICE::GetPlot( const string& aName, int aMaxLen ) { vector data; setlocale( LC_ALL, "C" ); - vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() ); + vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() ); setlocale( LC_ALL, "" ); if( vi ) @@ -89,7 +82,7 @@ vector NGSPICE::GetRealPlot( const string& aName, int aMaxLen ) { vector data; setlocale( LC_ALL, "C" ); - vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() ); + vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() ); setlocale( LC_ALL, "" ); if( vi ) @@ -123,7 +116,7 @@ vector NGSPICE::GetImagPlot( const string& aName, int aMaxLen ) vector data; setlocale( LC_ALL, "C" ); - vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() ); + vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() ); setlocale( LC_ALL, "" ); if( vi ) @@ -149,7 +142,7 @@ vector NGSPICE::GetMagPlot( const string& aName, int aMaxLen ) vector data; setlocale( LC_ALL, "C" ); - vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() ); + vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() ); setlocale( LC_ALL, "" ); if( vi ) @@ -178,7 +171,7 @@ vector NGSPICE::GetPhasePlot( const string& aName, int aMaxLen ) vector data; setlocale( LC_ALL, "C" ); - vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() ); + vector_info* vi = ngGet_Vec_Info( (char*) aName.c_str() ); setlocale( LC_ALL, "" ); if( vi ) @@ -217,7 +210,7 @@ bool NGSPICE::LoadNetlist( const string& aNetlist ) lines.push_back( nullptr ); setlocale( LC_ALL, "C" ); - m_ngSpice_Circ( lines.data() ); + ngSpice_Circ( lines.data() ); setlocale( LC_ALL, "" ); for( auto line : lines ) @@ -248,7 +241,7 @@ bool NGSPICE::Stop() bool NGSPICE::IsRunning() { setlocale( LC_ALL, "C" ); - bool rv = m_ngSpice_Running(); + bool rv = ngSpice_running(); setlocale( LC_ALL, "" ); return rv; } @@ -257,7 +250,7 @@ bool NGSPICE::IsRunning() bool NGSPICE::Command( const string& aCmd ) { setlocale( LC_ALL, "C" ); - m_ngSpice_Command( (char*) aCmd.c_str() ); + ngSpice_Command( (char*) aCmd.c_str() ); setlocale( LC_ALL, "" ); return true; @@ -289,30 +282,13 @@ string NGSPICE::GetXAxis( SIM_TYPE aType ) const } -void NGSPICE::init_dll() +void NGSPICE::init() { -#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 - setlocale( LC_ALL, "C" ); - m_ngSpice_Init( &cbSendChar, &cbSendStat, &cbControlledExit, NULL, NULL, &cbBGThreadRunning, this ); + ngSpice_Init( &cbSendChar, &cbSendStat, &cbControlledExit, NULL, NULL, &cbBGThreadRunning, this ); + // Workaround to avoid hang ups on certain errors Command( "unset interactive" ); setlocale( LC_ALL, "" ); diff --git a/eeschema/sim/ngspice.h b/eeschema/sim/ngspice.h index 7877811b8d..c62fab6947 100644 --- a/eeschema/sim/ngspice.h +++ b/eeschema/sim/ngspice.h @@ -76,29 +76,7 @@ public: private: bool m_error; - // 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; + void init(); // Callback functions static int cbSendChar( char* what, int id, void* user );