This commit is contained in:
Tomasz Wlostowski 2016-08-11 14:41:01 +02:00 committed by Maciej Suminski
parent f1f69979e6
commit 095af6e77a
9 changed files with 187 additions and 90 deletions

View File

@ -521,7 +521,7 @@ set( INC_AFTER
#if ( KICAD_SPICE )
# find_package(MathGL2 2.3.4 COMPONENTS wx REQUIRED )
#find_package(MathGL2 2.1 COMPONENTS wx REQUIRED )
#endif ()
# Find Python and other scripting resources

View File

@ -249,7 +249,7 @@ set_source_files_properties( ../common/single_top.cpp PROPERTIES
)
#if (KICAD_SPICE)
set ( EESCHEMA_LINK_LIBS ${wxWidgets_LIBRARIES} mgl mgl-wx)
set ( EESCHEMA_LINK_LIBS ${wxWidgets_LIBRARIES} mgl-wx mgl mgl-wx)
#else()
# set ( EESCHEMA_LINK_LIBS ${wxWidgets_LIBRARIES} )
#endif()

View File

@ -126,18 +126,7 @@ F 6 "R" V 5750 4000 60 0001 C CNN "Spice_Primitive"
-1 0 0 1
$EndComp
Text Notes 4300 4900 0 60 ~ 0
*.tran 1u 10m\n
$Comp
L SPICE_PROBE U1
U 1 1 573367CB
P 4400 3700
F 0 "U1" H 4400 3700 60 0001 C CNN
F 1 "SPICE_PROBE" H 4400 3700 60 0001 C CNN
F 2 "" H 4400 3700 60 0000 C CNN
F 3 "" H 4400 3700 60 0000 C CNN
1 4400 3700
1 0 0 -1
$EndComp
.tran 1u 10m\n
Wire Wire Line
4400 4350 4400 4250
Wire Wire Line
@ -162,36 +151,12 @@ Wire Wire Line
4400 3850 4400 3700
Wire Wire Line
4400 3700 4500 3700
Connection ~ 5650 3700
Connection ~ 4400 3700
Text Notes 4300 4800 0 60 ~ 0
.include diodes.lib\n
Text Label 4400 3800 0 60 ~ 0
in
$Comp
L SPICE_PROBE U?
U 1 1 5734D78F
P 4900 3700
F 0 "U?" H 4900 3700 60 0001 C CNN
F 1 "SPICE_PROBE" H 4900 3700 60 0001 C CNN
F 2 "" H 4900 3700 60 0000 C CNN
F 3 "" H 4900 3700 60 0000 C CNN
1 4900 3700
1 0 0 -1
$EndComp
$Comp
L SPICE_PROBE U?
U 1 1 5734D7B3
P 5400 3700
F 0 "U?" H 5400 3700 60 0001 C CNN
F 1 "SPICE_PROBE" H 5400 3700 60 0001 C CNN
F 2 "" H 5400 3700 60 0000 C CNN
F 3 "" H 5400 3700 60 0000 C CNN
1 5400 3700
1 0 0 -1
$EndComp
Text Label 5550 3700 0 60 ~ 0
rect
Text Notes 4300 5000 0 60 ~ 0
.ac dec 10 1 1Meg\n
*.ac dec 10 1 1Meg\n
$EndSCHEMATC

View File

@ -28,6 +28,8 @@ public:
const vector<double> GetPlot( std::string name, int max_len = -1);
void dump();
private:
@ -155,13 +157,12 @@ bool NGSPICE::LoadNetlist(const string& netlist)
bool NGSPICE::Command(const string& cmd )
{
m_ngSpice_Command( (char*)(cmd + string("\n")).c_str());
dump();
return true;
}
#if 0
bool NGSPICE::Run()
void NGSPICE::dump()
{
// m_ngSpice_Command("run\n");
char **plots = m_ngSpice_AllPlots();
@ -189,7 +190,7 @@ bool NGSPICE::Run()
}
#endif
NGSPICE::~NGSPICE()
{

View File

@ -76,6 +76,9 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY *aKiway, wxWindow* parent )
{
m_exporter = NULL;
m_simulator = NULL;
m_currentPlot = NULL;
NewPlot();
}
SIM_PLOT_FRAME::~SIM_PLOT_FRAME()
@ -101,7 +104,7 @@ void SIM_PLOT_FRAME::StartSimulation()
STRING_FORMATTER formatter;
m_exporter->Format( &formatter, GNL_ALL );
m_plotPanel->DeleteTraces();
//m_plotPanel->DeleteTraces();
printf("*******************\n%s\n", (const char *)formatter.GetString().c_str());
@ -109,7 +112,7 @@ void SIM_PLOT_FRAME::StartSimulation()
m_simulator->Command("run\n");
auto mapping = m_exporter->GetNetIndexMap();
auto data_t = m_simulator->GetPlot("time");
// auto data_t = m_simulator->GetPlot("time");
for(auto name : m_exporter->GetProbeList())
{
@ -117,14 +120,20 @@ void SIM_PLOT_FRAME::StartSimulation()
sprintf(spiceName,"V(%d)", mapping[name] );
//printf("probe %s->%s\n", (const char *) name.c_str(), spiceName);
auto data_y = m_simulator->GetPlot(spiceName);
// auto data_y = m_simulator->GetPlot(spiceName);
//printf("%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);
}
delete m_simulator;
m_simulator = NULL;
//m_simulator->Command("quit\n");
}
void SIM_PLOT_FRAME::NewPlot()
{
SIM_PLOT_PANEL *plot = new SIM_PLOT_PANEL ( this, wxID_ANY );
m_plotNotebook->AddPage ( plot, wxT("Plot1"), true );
m_currentPlot = plot;
}

View File

@ -15,6 +15,7 @@ Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder.
class SPICE_SIMULATOR;
class NETLIST_EXPORTER_PSPICE;
class SIM_PLOT_PANEL;
/** Implementing SIM_PLOT_FRAME_BASE */
class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
@ -24,6 +25,8 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
SIM_PLOT_FRAME(KIWAY *aKiway, wxWindow* parent );
~SIM_PLOT_FRAME();
void SetSchFrame( SCH_EDIT_FRAME* schFrame )
{
m_schematicFrame = schFrame;
@ -31,8 +34,15 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
void StartSimulation();
void NewPlot();
private:
virtual void onNewPlot( wxCommandEvent& event ) { NewPlot(); }
SIM_PLOT_PANEL *m_currentPlot;
SCH_EDIT_FRAME *m_schematicFrame;
NETLIST_EXPORTER_PSPICE *m_exporter;
SPICE_SIMULATOR *m_simulator;

View File

@ -5,8 +5,6 @@
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "sim_plot_panel.h"
#include "sim_plot_frame_base.h"
///////////////////////////////////////////////////////////////////////////
@ -16,61 +14,156 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( KIWAY* aKiway, wxWindow* aParent ) :
wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, wxT("Spice Simulation" ) )
{
this->SetSizeHints( wxSize( 1920,1000 ), wxSize( 1920,1000 ) );
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
m_menubar1 = new wxMenuBar( 0 );
m_menu1 = new wxMenu();
wxMenuItem* m_menuItem2;
m_menuItem2 = new wxMenuItem( m_menu1, wxID_ANY, wxString( wxT("Save Plot") ) , wxEmptyString, wxITEM_NORMAL );
m_menu1->Append( m_menuItem2 );
wxMenuItem* m_menuItem7;
m_menuItem7 = new wxMenuItem( m_menu1, wxID_ANY, wxString( wxT("New Plot") ) , wxEmptyString, wxITEM_NORMAL );
m_menu1->Append( m_menuItem7 );
m_menu1->AppendSeparator();
wxMenuItem* m_menuItem8;
m_menuItem8 = new wxMenuItem( m_menu1, wxID_ANY, wxString( wxT("Open Workbook") ) , wxEmptyString, wxITEM_NORMAL );
m_menu1->Append( m_menuItem8 );
wxMenuItem* m_menuItem2;
m_menuItem2 = new wxMenuItem( m_menu1, wxID_ANY, wxString( wxT("Save Workbook") ) , wxEmptyString, wxITEM_NORMAL );
m_menu1->Append( m_menuItem2 );
m_menu1->AppendSeparator();
wxMenuItem* m_menuItem1;
m_menuItem1 = new wxMenuItem( m_menu1, wxID_ANY, wxString( wxT("Exit Simulation") ) , wxEmptyString, wxITEM_NORMAL );
m_menu1->Append( m_menuItem1 );
m_menubar1->Append( m_menu1, wxT("File") );
m_menubar1->Append( m_menu1, wxT("File") );
m_menu2 = new wxMenu();
wxMenuItem* m_menuItem3;
m_menuItem3 = new wxMenuItem( m_menu2, wxID_ANY, wxString( wxT("Zoom In") ) , wxEmptyString, wxITEM_NORMAL );
m_menu2->Append( m_menuItem3 );
wxMenuItem* m_menuItem4;
m_menuItem4 = new wxMenuItem( m_menu2, wxID_ANY, wxString( wxT("Zoom Out") ) , wxEmptyString, wxITEM_NORMAL );
m_menu2->Append( m_menuItem4 );
wxMenuItem* m_menuItem5;
m_menuItem5 = new wxMenuItem( m_menu2, wxID_ANY, wxString( wxT("Fit on Screen") ) , wxEmptyString, wxITEM_NORMAL );
m_menu2->Append( m_menuItem5 );
m_menu2->AppendSeparator();
wxMenuItem* m_menuItem6;
m_menuItem6 = new wxMenuItem( m_menu2, wxID_ANY, wxString( wxT("Show grid") ) , wxEmptyString, wxITEM_CHECK );
m_menu2->Append( m_menuItem6 );
m_menubar1->Append( m_menu2, wxT("View") );
this->SetMenuBar( m_menubar1 );
wxBoxSizer* bSizer1;
bSizer1 = new wxBoxSizer( wxVERTICAL );
m_auiToolBar1 = new wxAuiToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_TB_HORZ_LAYOUT );
m_toolZoomIn = m_auiToolBar1->AddTool( wxID_ANY, wxT("Zoom In"), wxNullBitmap /*wxBitmap( wxT("zoom.png"), wxBITMAP_TYPE_ANY )*/, wxNullBitmap, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL );
m_auiToolBar1->Realize();
bSizer1->Add( m_auiToolBar1, 0, wxALL, 5 );
m_splitter1 = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3D );
m_splitter1 = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_BORDER );
m_splitter1->SetSashGravity( 0.2 );
m_splitter1->SetSashSize( 0 );
m_splitter1->Connect( wxEVT_IDLE, wxIdleEventHandler( SIM_PLOT_FRAME_BASE::m_splitter1OnIdle ), NULL, this );
m_plotPanel = new SIM_PLOT_PANEL( m_splitter1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
m_panel31 = new wxPanel( m_splitter1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* bSizer5;
bSizer5 = new wxBoxSizer( wxVERTICAL );
m_splitter2 = new wxSplitterWindow( m_panel31, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3DBORDER );
m_splitter2->Connect( wxEVT_IDLE, wxIdleEventHandler( SIM_PLOT_FRAME_BASE::m_splitter2OnIdle ), NULL, this );
m_panel61 = new wxPanel( m_splitter2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
m_panel61->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
wxBoxSizer* bSizer6;
bSizer6 = new wxBoxSizer( wxVERTICAL );
m_plotNotebook = new wxAuiNotebook( m_panel61, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_DEFAULT_STYLE );
m_plotNotebook->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
bSizer6->Add( m_plotNotebook, 1, wxEXPAND, 5 );
m_panel61->SetSizer( bSizer6 );
m_panel61->Layout();
bSizer6->Fit( m_panel61 );
m_panel7 = new wxPanel( m_splitter2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* bSizer7;
bSizer7 = new wxBoxSizer( wxVERTICAL );
m_staticText2 = new wxStaticText( m_panel7, wxID_ANY, wxT("Signals"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
m_staticText2->Wrap( -1 );
bSizer7->Add( m_staticText2, 0, wxALL|wxEXPAND, 5 );
m_signals = new wxListBox( m_panel7, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_MULTIPLE|wxLB_SORT );
bSizer7->Add( m_signals, 0, wxALL|wxEXPAND, 5 );
m_staticText21 = new wxStaticText( m_panel7, wxID_ANY, wxT("Parameters"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
m_staticText21->Wrap( -1 );
bSizer7->Add( m_staticText21, 0, wxALL|wxEXPAND, 5 );
m_signals1 = new wxListBox( m_panel7, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_MULTIPLE|wxLB_SORT );
bSizer7->Add( m_signals1, 0, wxALL|wxEXPAND, 5 );
wxFlexGridSizer* fgSizer1;
fgSizer1 = new wxFlexGridSizer( 1, 3, 0, 0 );
fgSizer1->SetFlexibleDirection( wxBOTH );
fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_button1 = new wxButton( m_panel7, wxID_ANY, wxT("Probe"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer1->Add( m_button1, 0, wxALL, 5 );
m_button2 = new wxButton( m_panel7, wxID_ANY, wxT("Tune"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer1->Add( m_button2, 0, wxALL, 5 );
bSizer7->Add( fgSizer1, 0, wxEXPAND, 5 );
m_panel7->SetSizer( bSizer7 );
m_panel7->Layout();
bSizer7->Fit( m_panel7 );
m_splitter2->SplitVertically( m_panel61, m_panel7, 0 );
bSizer5->Add( m_splitter2, 1, wxEXPAND, 5 );
m_panel31->SetSizer( bSizer5 );
m_panel31->Layout();
bSizer5->Fit( m_panel31 );
m_panel3 = new wxPanel( m_splitter1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* bSizer3;
bSizer3 = new wxBoxSizer( wxVERTICAL );
m_simConsole = new wxRichTextCtrl( m_panel3, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY|wxVSCROLL|wxHSCROLL|wxNO_BORDER|wxWANTS_CHARS );
bSizer3->Add( m_simConsole, 1, wxEXPAND | wxALL, 5 );
m_panel3->SetSizer( bSizer3 );
m_panel3->Layout();
bSizer3->Fit( m_panel3 );
m_splitter1->SplitHorizontally( m_plotPanel, m_panel3, 700 );
m_splitter1->SplitHorizontally( m_panel31, m_panel3, 700 );
bSizer1->Add( m_splitter1, 1, wxEXPAND, 5 );
this->SetSizer( bSizer1 );
this->Layout();
this->Centre( wxBOTH );
// Connect Events
this->Connect( m_menuItem7->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onNewPlot ) );
}
SIM_PLOT_FRAME_BASE::~SIM_PLOT_FRAME_BASE()
{
// Disconnect Events
this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onNewPlot ) );
}

View File

@ -11,7 +11,6 @@
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
class KIWAY_PLAYER;
class SIM_PLOT_PANEL;
#include "kiway_player.h"
#include <wx/string.h>
@ -23,12 +22,14 @@ class SIM_PLOT_PANEL;
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/aui/aui.h>
#include <wx/aui/auibar.h>
#include <wx/panel.h>
#include <wx/richtext/richtextctrl.h>
#include <wx/aui/auibook.h>
#include <wx/sizer.h>
#include <wx/panel.h>
#include <wx/stattext.h>
#include <wx/listbox.h>
#include <wx/button.h>
#include <wx/splitter.h>
#include <wx/richtext/richtextctrl.h>
#include <wx/frame.h>
///////////////////////////////////////////////////////////////////////////
@ -44,12 +45,25 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER
protected:
wxMenuBar* m_menubar1;
wxMenu* m_menu1;
wxAuiToolBar* m_auiToolBar1;
wxAuiToolBarItem* m_toolZoomIn;
wxMenu* m_menu2;
wxSplitterWindow* m_splitter1;
SIM_PLOT_PANEL* m_plotPanel;
wxPanel* m_panel31;
wxSplitterWindow* m_splitter2;
wxPanel* m_panel61;
wxAuiNotebook* m_plotNotebook;
wxPanel* m_panel7;
wxStaticText* m_staticText2;
wxListBox* m_signals;
wxStaticText* m_staticText21;
wxListBox* m_signals1;
wxButton* m_button1;
wxButton* m_button2;
wxPanel* m_panel3;
wxRichTextCtrl* m_simConsole;
// Virtual event handlers, overide them in your derived class
virtual void onNewPlot( wxCommandEvent& event ) { event.Skip(); }
public:
SIM_PLOT_FRAME_BASE( KIWAY* aKiway, wxWindow* aParent );
@ -60,8 +74,13 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER
m_splitter1->SetSashPosition( 700 );
m_splitter1->Disconnect( wxEVT_IDLE, wxIdleEventHandler( SIM_PLOT_FRAME_BASE::m_splitter1OnIdle ), NULL, this );
}
void m_splitter2OnIdle( wxIdleEvent& )
{
m_splitter2->SetSashPosition( 0 );
m_splitter2->Disconnect( wxEVT_IDLE, wxIdleEventHandler( SIM_PLOT_FRAME_BASE::m_splitter2OnIdle ), NULL, this );
}
};
#endif //__SIM_PLOT_FRAME_BASE_H__

View File

@ -12,7 +12,7 @@ static int drawPlotFunc( mglGraph *graph )
//graph->SetRanges(-10e-3,10e-3,-2,2);
graph->Axis("x");
graph->Label('x',"Time",0);
graph->AddRange('x', 0, 10e-3);
graph->SetRange('x', 0, 10e-3);
graph->Axis("y");
graph->Label('y',"Voltage",0);
@ -47,7 +47,7 @@ SIM_PLOT_PANEL::SIM_PLOT_PANEL( wxWindow * parent,
AutoResize = true;
SetDraw( drawPlotFunc );
Update();
// Update();
}