Initial version of simulator probe tool

This commit is contained in:
Maciej Suminski 2016-08-11 14:41:11 +02:00
parent aa3e251cdd
commit ac17165947
8 changed files with 68 additions and 14 deletions

View File

@ -28,9 +28,11 @@
*/ */
#include <fctsys.h> #include <fctsys.h>
#include <kiway.h>
#include <eeschema_id.h> #include <eeschema_id.h>
#include <class_drawpanel.h> #include <class_drawpanel.h>
#include <schframe.h> #include <schframe.h>
#include <sim/sim_plot_frame.h>
#include <menus_helpers.h> #include <menus_helpers.h>
#include <sch_bus_entry.h> #include <sch_bus_entry.h>
@ -43,6 +45,8 @@
#include <sch_sheet.h> #include <sch_sheet.h>
#include <sch_sheet_path.h> #include <sch_sheet_path.h>
#include <sch_bitmap.h> #include <sch_bitmap.h>
#include <class_netlist_object.h>
#include <class_library.h> // fo class SCHLIB_FILTER to filter power parts #include <class_library.h> // fo class SCHLIB_FILTER to filter power parts
@ -321,6 +325,31 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
} }
break; break;
case ID_SIM_ADD_PROBE:
{
const KICAD_T wiresAndComponents[] = { SCH_LINE_T, SCH_COMPONENT_T, SCH_SHEET_PIN_T };
item = LocateAndShowItem( aPosition, wiresAndComponents );
if( !item )
break;
NETLIST_OBJECT_LIST* netlist = BuildNetListBase();
for( NETLIST_OBJECT* obj : *netlist )
{
if( obj->m_Comp == item )
{
SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, false );
if( simFrame )
simFrame->AddVoltagePlot( obj->GetNetName() );
break;
}
}
}
break;
default: default:
SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick invalid tool ID <" ) + wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick invalid tool ID <" ) +

View File

@ -609,6 +609,10 @@ void SCH_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) ); SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
break; break;
case ID_SIM_ADD_PROBE:
SetToolID( id, wxCURSOR_BULLSEYE, _( "Add a simulator probe" ) );
break;
default: default:
SetRepeatItem( NULL ); SetRepeatItem( NULL );
} }

View File

@ -266,7 +266,6 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_TOOL( ID_UPDATE_PCB_FROM_SCH, SCH_EDIT_FRAME::OnUpdatePCB ) EVT_TOOL( ID_UPDATE_PCB_FROM_SCH, SCH_EDIT_FRAME::OnUpdatePCB )
EVT_TOOL( ID_SIM_RUN, SCH_EDIT_FRAME::OnSimulationRun ) EVT_TOOL( ID_SIM_RUN, SCH_EDIT_FRAME::OnSimulationRun )
EVT_TOOL( ID_SIM_STOP, SCH_EDIT_FRAME::OnSimulationStop ) EVT_TOOL( ID_SIM_STOP, SCH_EDIT_FRAME::OnSimulationStop )
EVT_TOOL( ID_SIM_ADD_PROBE, SCH_EDIT_FRAME::OnSimulationAddProbe )
EVT_TOOL( ID_GET_TOOLS, SCH_EDIT_FRAME::OnCreateBillOfMaterials ) EVT_TOOL( ID_GET_TOOLS, SCH_EDIT_FRAME::OnCreateBillOfMaterials )
EVT_TOOL( ID_FIND_ITEMS, SCH_EDIT_FRAME::OnFindItems ) EVT_TOOL( ID_FIND_ITEMS, SCH_EDIT_FRAME::OnFindItems )
EVT_TOOL( wxID_REPLACE, SCH_EDIT_FRAME::OnFindItems ) EVT_TOOL( wxID_REPLACE, SCH_EDIT_FRAME::OnFindItems )
@ -282,6 +281,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_TOOL( ID_ZOOM_SELECTION, SCH_EDIT_FRAME::OnSelectTool ) EVT_TOOL( ID_ZOOM_SELECTION, SCH_EDIT_FRAME::OnSelectTool )
EVT_TOOL_RANGE( ID_SCHEMATIC_VERTICAL_TOOLBAR_START, ID_SCHEMATIC_VERTICAL_TOOLBAR_END, EVT_TOOL_RANGE( ID_SCHEMATIC_VERTICAL_TOOLBAR_START, ID_SCHEMATIC_VERTICAL_TOOLBAR_END,
SCH_EDIT_FRAME::OnSelectTool ) SCH_EDIT_FRAME::OnSelectTool )
EVT_TOOL( ID_SIM_ADD_PROBE, SCH_EDIT_FRAME::OnSelectTool )
EVT_MENU( ID_CANCEL_CURRENT_COMMAND, SCH_EDIT_FRAME::OnCancelCurrentCommand ) EVT_MENU( ID_CANCEL_CURRENT_COMMAND, SCH_EDIT_FRAME::OnCancelCurrentCommand )
EVT_MENU( ID_SCH_DRAG_ITEM, SCH_EDIT_FRAME::OnDragItem ) EVT_MENU( ID_SCH_DRAG_ITEM, SCH_EDIT_FRAME::OnDragItem )

View File

@ -815,7 +815,6 @@ private:
void OnUpdatePCB( wxCommandEvent& event ); void OnUpdatePCB( wxCommandEvent& event );
void OnSimulationRun( wxCommandEvent& event ); void OnSimulationRun( wxCommandEvent& event );
void OnSimulationStop( wxCommandEvent& event ); void OnSimulationStop( wxCommandEvent& event );
void OnSimulationAddProbe( wxCommandEvent& event );
void OnCreateBillOfMaterials( wxCommandEvent& event ); void OnCreateBillOfMaterials( wxCommandEvent& event );
void OnFindItems( wxCommandEvent& event ); void OnFindItems( wxCommandEvent& event );
void OnFindDialogClose( wxFindDialogEvent& event ); void OnFindDialogClose( wxFindDialogEvent& event );

View File

@ -67,8 +67,10 @@ const vector<double> NGSPICE::GetPlot( const string& aName, int aMaxLen )
vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() ); vector_info* vi = m_ngGet_Vec_Info( (char*) aName.c_str() );
if( vi->v_realdata ) if( vi && vi->v_realdata )
{ {
data.reserve( vi->v_length );
for( int i = 0; i < vi->v_length; i++ ) for( int i = 0; i < vi->v_length; i++ )
data.push_back( vi->v_realdata[i] ); data.push_back( vi->v_realdata[i] );
} }

View File

@ -98,7 +98,6 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent )
{ {
m_exporter = NULL; m_exporter = NULL;
m_simulator = NULL; m_simulator = NULL;
m_pyConsole = NULL;
m_simThread = NULL; m_simThread = NULL;
Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( SIM_PLOT_FRAME::onClose ), NULL, this ); Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( SIM_PLOT_FRAME::onClose ), NULL, this );
@ -126,6 +125,7 @@ void SIM_PLOT_FRAME::StartSimulation()
m_simConsole->Clear(); m_simConsole->Clear();
/// @todo is it necessary to recreate simulator every time?
m_simulator = SPICE_SIMULATOR::CreateInstance( "ngspice" ); m_simulator = SPICE_SIMULATOR::CreateInstance( "ngspice" );
m_simulator->SetConsoleReporter( new SIM_THREAD_REPORTER( this ) ); m_simulator->SetConsoleReporter( new SIM_THREAD_REPORTER( this ) );
m_simulator->Init(); m_simulator->Init();
@ -201,6 +201,32 @@ void SIM_PLOT_FRAME::NewPlot()
} }
void SIM_PLOT_FRAME::AddVoltagePlot( const wxString& aNetName )
{
if( !m_exporter )
return;
const auto& netMapping = m_exporter->GetNetIndexMap();
if( netMapping.count( aNetName ) == 0 )
return;
wxString spiceName( wxString::Format( "V(%d)", netMapping.at( aNetName ) ) );
auto data_y = m_simulator->GetPlot( (const char*) spiceName.c_str() );
wxLogDebug( "probe %s", spiceName );
if( data_y.empty() )
return;
auto data_t = m_simulator->GetPlot( "time" );
wxLogDebug( "%lu - %lu data points", data_t.size(), data_y.size() );
SIM_PLOT_PANEL* plotPanel = static_cast<SIM_PLOT_PANEL*>( m_plotNotebook->GetCurrentPage() );
plotPanel->AddTrace( aNetName, data_t.size(), data_t.data(), data_y.data(), 0 );
}
void SIM_PLOT_FRAME::onClose( wxCloseEvent& aEvent ) void SIM_PLOT_FRAME::onClose( wxCloseEvent& aEvent )
{ {
{ {
@ -258,8 +284,8 @@ void SIM_PLOT_FRAME::onSimFinished( wxThreadEvent& aEvent )
m_signals->Append( net.first ); m_signals->Append( net.first );
} }
// auto data_t = m_simulator->GetPlot( "time" ); // TODO remove?
#if 0
for( auto& name : m_exporter->GetProbeList() ) for( auto& name : m_exporter->GetProbeList() )
{ {
char spiceName[1024]; char spiceName[1024];
@ -271,4 +297,5 @@ void SIM_PLOT_FRAME::onSimFinished( wxThreadEvent& aEvent )
//wxLogDebug( "%d - %d data points\n", data_t.size(), data_y.size() ); //wxLogDebug( "%d - %d data points\n", data_t.size(), data_y.size() );
// m_plotPanel->AddTrace(wxT("V(") + name + wxT(")"), data_t.size(), data_t.data(), data_y.data(), 0); // m_plotPanel->AddTrace(wxT("V(") + name + wxT(")"), data_t.size(), data_t.data(), data_y.data(), 0);
} }
#endif
} }

View File

@ -60,8 +60,7 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
void StopSimulation(); void StopSimulation();
void NewPlot(); void NewPlot();
void AddVoltagePlot( const wxString& aNetName );
void TogglePythonConsole();
private: private:
virtual void onClose( wxCloseEvent& aEvent ); virtual void onClose( wxCloseEvent& aEvent );
@ -72,7 +71,6 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
SCH_EDIT_FRAME* m_schematicFrame; SCH_EDIT_FRAME* m_schematicFrame;
NETLIST_EXPORTER_PSPICE* m_exporter; NETLIST_EXPORTER_PSPICE* m_exporter;
SPICE_SIMULATOR* m_simulator; SPICE_SIMULATOR* m_simulator;
wxWindow* m_pyConsole;
SIM_THREAD* m_simThread; SIM_THREAD* m_simThread;
wxCriticalSection m_simThreadCS; wxCriticalSection m_simThreadCS;

View File

@ -50,8 +50,3 @@ void SCH_EDIT_FRAME::OnSimulationRun( wxCommandEvent& event )
void SCH_EDIT_FRAME::OnSimulationStop( wxCommandEvent& event ) void SCH_EDIT_FRAME::OnSimulationStop( wxCommandEvent& event )
{ {
} }
void SCH_EDIT_FRAME::OnSimulationAddProbe( wxCommandEvent& event )
{
}