KiCad PCB EDA Suite
sim_plot_frame.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016 CERN
5  * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 3
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * https://www.gnu.org/licenses/gpl-3.0.html
22  * or you may search the http://www.gnu.org website for the version 3 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #include <schframe.h>
28 #include <eeschema_id.h>
29 #include <kiway.h>
30 #include <confirm.h>
31 #include <bitmaps.h>
32 
33 #include <widgets/tuner_slider.h>
36 #include <pgm_base.h>
37 
38 #include "sim_plot_frame.h"
39 #include "sim_plot_panel.h"
40 #include "spice_simulator.h"
41 #include "spice_reporter.h"
42 
43 #include <menus_helpers.h>
44 
46 {
47  int res = (int) aFirst | (int) aSecond;
48 
49  return (SIM_PLOT_TYPE) res;
50 }
51 
52 
54 {
55 public:
57  : m_parent( aParent )
58  {
59  }
60 
61  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override
62  {
63  wxCommandEvent* event = new wxCommandEvent( EVT_SIM_REPORT );
64  event->SetString( aText );
65  wxQueueEvent( m_parent, event );
66  return *this;
67  }
68 
69  void OnSimStateChange( SPICE_SIMULATOR* aObject, SIM_STATE aNewState ) override
70  {
71  wxCommandEvent* event = NULL;
72 
73  switch( aNewState )
74  {
75  case SIM_IDLE:
76  event = new wxCommandEvent( EVT_SIM_FINISHED );
77  break;
78 
79  case SIM_RUNNING:
80  event = new wxCommandEvent( EVT_SIM_STARTED );
81  break;
82  }
83 
84  wxQueueEvent( m_parent, event );
85  }
86 
87 private:
89 };
90 
91 
92 TRACE_DESC::TRACE_DESC( const NETLIST_EXPORTER_PSPICE_SIM& aExporter, const wxString& aName,
93  SIM_PLOT_TYPE aType, const wxString& aParam )
94  : m_name( aName ), m_type( aType ), m_param( aParam )
95 {
96  // Title generation
97  m_title = wxString::Format( "%s(%s)", aParam, aName );
98 
99  if( aType & SPT_AC_MAG )
100  m_title += " (mag)";
101  else if( aType & SPT_AC_PHASE )
102  m_title += " (phase)";
103 }
104 
105 // Store the path of saved workbooks during the session
107 
108 SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent )
109  : SIM_PLOT_FRAME_BASE( aParent ), m_lastSimPlot( nullptr )
110 {
111  SetKiway( this, aKiway );
112  m_signalsIconColorList = NULL;
113 
115 
116  if( m_schematicFrame == NULL )
117  throw std::runtime_error( "There is no schematic window" );
118 
119  // Give an icon
120  wxIcon icon;
121  icon.CopyFromBitmap( KiBitmap( simulator_xpm ) );
122  SetIcon( icon );
123 
124  // Get the previous size and position of windows:
125  LoadSettings( config() );
126 
128 
129  if( !m_simulator )
130  {
131  throw std::runtime_error( "Could not create simulator instance" );
132  return;
133  }
134 
135  m_simulator->Init();
136 
137  if( m_savedWorkbooksPath.IsEmpty() )
138  {
140  }
141 
142  m_reporter = new SIM_THREAD_REPORTER( this );
144 
146 
147  Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( SIM_PLOT_FRAME::onClose ), NULL, this );
148  Connect( EVT_SIM_UPDATE, wxCommandEventHandler( SIM_PLOT_FRAME::onSimUpdate ), NULL, this );
149  Connect( EVT_SIM_REPORT, wxCommandEventHandler( SIM_PLOT_FRAME::onSimReport ), NULL, this );
150  Connect( EVT_SIM_STARTED, wxCommandEventHandler( SIM_PLOT_FRAME::onSimStarted ), NULL, this );
151  Connect( EVT_SIM_FINISHED, wxCommandEventHandler( SIM_PLOT_FRAME::onSimFinished ), NULL, this );
152  Connect( EVT_SIM_CURSOR_UPDATE, wxCommandEventHandler( SIM_PLOT_FRAME::onCursorUpdate ), NULL, this );
153 
154  // Toolbar buttons
155  m_toolSimulate = m_toolBar->AddTool( ID_SIM_RUN, _( "Run/Stop Simulation" ),
156  KiBitmap( sim_run_xpm ), _( "Run Simulation" ), wxITEM_NORMAL );
157  m_toolAddSignals = m_toolBar->AddTool( ID_SIM_ADD_SIGNALS, _( "Add Signals" ),
158  KiBitmap( sim_add_signal_xpm ), _( "Add signals to plot" ), wxITEM_NORMAL );
159  m_toolProbe = m_toolBar->AddTool( ID_SIM_PROBE, _( "Probe" ),
160  KiBitmap( sim_probe_xpm ), _( "Probe signals on the schematic" ), wxITEM_NORMAL );
161  m_toolTune = m_toolBar->AddTool( ID_SIM_TUNE, _( "Tune" ),
162  KiBitmap( sim_tune_xpm ), _( "Tune component values" ), wxITEM_NORMAL );
163  m_toolSettings = m_toolBar->AddTool( wxID_ANY, _( "Settings" ),
164  KiBitmap( sim_settings_xpm ), _( "Simulation settings" ), wxITEM_NORMAL );
165 
166  Connect( m_toolSimulate->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
167  wxCommandEventHandler( SIM_PLOT_FRAME::onSimulate ), NULL, this );
168  Connect( m_toolAddSignals->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
169  wxCommandEventHandler( SIM_PLOT_FRAME::onAddSignal ), NULL, this );
170  Connect( m_toolProbe->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
171  wxCommandEventHandler( SIM_PLOT_FRAME::onProbe ), NULL, this );
172  Connect( m_toolTune->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
173  wxCommandEventHandler( SIM_PLOT_FRAME::onTune ), NULL, this );
174  Connect( m_toolSettings->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
175  wxCommandEventHandler( SIM_PLOT_FRAME::onSettings ), NULL, this );
176 
177  // Bind toolbar buttons event to existing menu event handlers, so they behave the same
178  Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onSimulate, this, m_runSimulation->GetId() );
179  Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onAddSignal, this, m_addSignals->GetId() );
180  Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onProbe, this, m_probeSignals->GetId() );
181  Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onTune, this, m_tuneValue->GetId() );
182  Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onSettings, this, m_settings->GetId() );
183 
184  m_toolBar->Realize();
185  m_plotNotebook->SetPageText( 0, _( "Welcome!" ) );
186 
187  // the settings dialog will be created later, on demand.
188  // if created in the ctor, for some obscure reason, there is an issue
189  // on Windows: when open it, the simulator frame is sent to the background.
190  // instead of being behind the dialog frame (as it does)
191  m_settingsDlg = NULL;
192 
193  // resize the subwindows size. At least on Windows, calling wxSafeYield before
194  // resizing the subwindows forces the wxSplitWindows size events automatically generated
195  // by wxWidgets to be executed before our resize code.
196  // Otherwise, the changes made by setSubWindowsSashSize are overwritten by one these
197  // events
198  wxSafeYield();
200 }
201 
202 
204 {
205  m_simulator->SetReporter( nullptr );
206  delete m_reporter;
207  delete m_signalsIconColorList;
208 
209  if( m_settingsDlg )
210  m_settingsDlg->Destroy();
211 }
212 
213 #define PLOT_PANEL_WIDTH_ENTRY "SimPlotPanelWidth"
214 #define PLOT_PANEL_HEIGHT_ENTRY "SimPlotPanelHeight"
215 #define SIGNALS_PANEL_HEIGHT_ENTRY "SimSignalPanelHeight"
216 #define CURSORS_PANEL_HEIGHT_ENTRY "SimCursorsPanelHeight"
217 
218 void SIM_PLOT_FRAME::SaveSettings( wxConfigBase* aCfg )
219 {
220  // Save main frame size and position:
222 
223  // Save subwindows sizes
224  aCfg->Write( PLOT_PANEL_WIDTH_ENTRY, m_splitterLeftRight->GetSashPosition() );
225  aCfg->Write( PLOT_PANEL_HEIGHT_ENTRY, m_splitterPlotAndConsole->GetSashPosition() );
226  aCfg->Write( SIGNALS_PANEL_HEIGHT_ENTRY, m_splitterSignals->GetSashPosition() );
227  aCfg->Write( CURSORS_PANEL_HEIGHT_ENTRY, m_splitterTuneValues->GetSashPosition() );
228 }
229 
230 
231 void SIM_PLOT_FRAME::LoadSettings( wxConfigBase* aCfg )
232 {
233  // Read main frame size and position:
235  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
236 
237  // Read subwindows sizes (should be > 0 )
242 }
243 
244 
246 {
249 
252 
255 
258 }
259 
260 
262 {
263  STRING_FORMATTER formatter;
264  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
265 
266  if( !m_settingsDlg )
267  m_settingsDlg = new DIALOG_SIM_SETTINGS( this );
268 
269  m_simConsole->Clear();
271 
272  if( plotPanel )
273  m_exporter->SetSimCommand( m_plots[plotPanel].m_simCommand );
274 
275  if( !m_exporter->Format( &formatter, m_settingsDlg->GetNetlistOptions() ) )
276  {
277  DisplayError( this, _( "There were errors during netlist export, aborted." ) );
278  return;
279  }
280 
281  if( m_exporter->GetSimType() == ST_UNKNOWN )
282  {
283  DisplayInfoMessage( this, _( "You need to select the simulation settings first." ) );
284  return;
285  }
286 
287  m_simulator->LoadNetlist( formatter.GetString() );
288  updateTuners();
289  applyTuners();
290  m_simulator->Run();
291 }
292 
293 
295 {
296  m_simulator->Stop();
297 }
298 
299 
301 {
302  return m_simulator ? m_simulator->IsRunning() : false;
303 }
304 
305 
307 {
308  SIM_PLOT_PANEL* plotPanel = new SIM_PLOT_PANEL( aSimType, m_plotNotebook, wxID_ANY );
309 
310  if( m_welcomePanel )
311  {
312  m_plotNotebook->DeletePage( 0 );
313  m_welcomePanel = nullptr;
314  }
315 
316  m_plotNotebook->AddPage( plotPanel, wxString::Format( wxT( "Plot%u" ),
317  (unsigned int) m_plotNotebook->GetPageCount() + 1 ), true );
318 
319  m_plots[plotPanel] = PLOT_INFO();
320 
321  return plotPanel;
322 }
323 
324 
325 void SIM_PLOT_FRAME::AddVoltagePlot( const wxString& aNetName )
326 {
327  addPlot( aNetName, SPT_VOLTAGE, "V" );
328 }
329 
330 
331 void SIM_PLOT_FRAME::AddCurrentPlot( const wxString& aDeviceName, const wxString& aParam )
332 {
333  addPlot( aDeviceName, SPT_CURRENT, aParam );
334 }
335 
336 
338 {
339  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
340 
341  if( !plotPanel )
342  return;
343 
344  // For now limit the tuner tool to RLC components
345  char primitiveType = NETLIST_EXPORTER_PSPICE::GetSpiceField( SF_PRIMITIVE, aComponent, 0 )[0];
346 
347  if( primitiveType != SP_RESISTOR && primitiveType != SP_CAPACITOR && primitiveType != SP_INDUCTOR )
348  return;
349 
350  const wxString& componentName = aComponent->GetField( REFERENCE )->GetText();
351 
352  // Do not add multiple instances for the same component
353  auto tunerIt = std::find_if( m_tuners.begin(), m_tuners.end(), [&]( const TUNER_SLIDER* t )
354  {
355  return t->GetComponentName() == componentName;
356  }
357  );
358 
359  if( tunerIt != m_tuners.end() )
360  return; // We already have it
361 
362  try
363  {
364  TUNER_SLIDER* tuner = new TUNER_SLIDER( this, m_tunePanel, aComponent );
365  m_tuneSizer->Add( tuner );
366  m_tuners.push_back( tuner );
367  m_tunePanel->Layout();
368  }
369  catch( ... )
370  {
371  // Sorry, no bonus
372  }
373 }
374 
375 
376 void SIM_PLOT_FRAME::RemoveTuner( TUNER_SLIDER* aTuner, bool aErase )
377 {
378  if( aErase )
379  m_tuners.remove( aTuner );
380 
381  aTuner->Destroy();
382  m_tunePanel->Layout();
383 }
384 
385 
387 {
388  wxWindow* curPage = m_plotNotebook->GetCurrentPage();
389 
390  return ( curPage == m_welcomePanel ) ? nullptr : static_cast<SIM_PLOT_PANEL*>( curPage );
391 }
392 
393 
394 void SIM_PLOT_FRAME::addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam )
395 {
396  SIM_TYPE simType = m_exporter->GetSimType();
397 
398  if( !SIM_PLOT_PANEL::IsPlottable( simType ) )
399  return; // TODO else write out in console?
400 
401  // Create a new plot if the current one displays a different type
402  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
403 
404  if( !plotPanel || plotPanel->GetType() != simType )
405  plotPanel = NewPlotPanel( simType );
406 
407  TRACE_DESC descriptor( *m_exporter, aName, aType, aParam );
408 
409  bool updated = false;
410  SIM_PLOT_TYPE xAxisType = GetXAxisType( simType );
411 
412  if( xAxisType == SPT_LIN_FREQUENCY || xAxisType == SPT_LOG_FREQUENCY )
413  {
414  int baseType = descriptor.GetType() & ~( SPT_AC_MAG | SPT_AC_PHASE );
415 
416  // Add two plots: magnitude & phase
417  TRACE_DESC mag_desc( *m_exporter, descriptor, (SIM_PLOT_TYPE)( baseType | SPT_AC_MAG ) );
418  TRACE_DESC phase_desc( *m_exporter, descriptor, (SIM_PLOT_TYPE)( baseType | SPT_AC_PHASE ) );
419 
420  updated |= updatePlot( mag_desc, plotPanel );
421  updated |= updatePlot( phase_desc, plotPanel );
422  }
423  else
424  {
425  updated = updatePlot( descriptor, plotPanel );
426  }
427 
428  if( updated )
429  {
431  }
432 }
433 
434 
435 void SIM_PLOT_FRAME::removePlot( const wxString& aPlotName, bool aErase )
436 {
437  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
438 
439  if( !plotPanel )
440  return;
441 
442  if( aErase )
443  {
444  auto& traceMap = m_plots[plotPanel].m_traces;
445  auto traceIt = traceMap.find( aPlotName );
446  wxASSERT( traceIt != traceMap.end() );
447  traceMap.erase( traceIt );
448  }
449 
450  wxASSERT( plotPanel->TraceShown( aPlotName ) );
451  plotPanel->DeleteTrace( aPlotName );
452  plotPanel->Fit();
453 
455  updateCursors();
456 }
457 
458 
460 {
462  Prj().SchLibs(), Prj().SchSearchS() ) );
463 }
464 
465 
466 bool SIM_PLOT_FRAME::updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL* aPanel )
467 {
468  SIM_TYPE simType = m_exporter->GetSimType();
469  wxString spiceVector = m_exporter->GetSpiceVector( aDescriptor.GetName(),
470  aDescriptor.GetType(), aDescriptor.GetParam() );
471 
472  if( !SIM_PLOT_PANEL::IsPlottable( simType ) )
473  {
474  // There is no plot to be shown
475  m_simulator->Command( wxString::Format( "print %s", spiceVector ).ToStdString() );
476 
477  return false;
478  }
479 
480  // First, handle the x axis
481  wxString xAxisName( m_simulator->GetXAxis( simType ) );
482 
483  if( xAxisName.IsEmpty() )
484  return false;
485 
486  auto data_x = m_simulator->GetMagPlot( (const char*) xAxisName.c_str() );
487  unsigned int size = data_x.size();
488 
489  if( data_x.empty() )
490  return false;
491 
492  SIM_PLOT_TYPE plotType = aDescriptor.GetType();
493  std::vector<double> data_y;
494 
495  // Now, Y axis data
496  switch( m_exporter->GetSimType() )
497  {
498  case ST_AC:
499  {
500  wxASSERT_MSG( !( ( plotType & SPT_AC_MAG ) && ( plotType & SPT_AC_PHASE ) ),
501  "Cannot set both AC_PHASE and AC_MAG bits" );
502 
503  if( plotType & SPT_AC_MAG )
504  data_y = m_simulator->GetMagPlot( (const char*) spiceVector.c_str() );
505  else if( plotType & SPT_AC_PHASE )
506  data_y = m_simulator->GetPhasePlot( (const char*) spiceVector.c_str() );
507  else
508  wxASSERT_MSG( false, "Plot type missing AC_PHASE or AC_MAG bit" );
509  }
510  break;
511 
512  case ST_NOISE:
513  case ST_DC:
514  case ST_TRANSIENT:
515  {
516  data_y = m_simulator->GetMagPlot( (const char*) spiceVector.c_str() );
517  }
518  break;
519 
520  default:
521  wxASSERT_MSG( false, "Unhandled plot type" );
522  return false;
523  }
524 
525  if( data_y.size() != size )
526  return false;
527 
528  if( aPanel->AddTrace( aDescriptor.GetTitle(), size,
529  data_x.data(), data_y.data(), aDescriptor.GetType() ) )
530  {
531  m_plots[aPanel].m_traces.insert( std::make_pair( aDescriptor.GetTitle(), aDescriptor ) );
532  }
533 
534  return true;
535 }
536 
537 
539 {
540  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
541 
542  if( !plotPanel )
543  return;
544 
545  m_signals->ClearAll();
546 
547  wxSize size = m_signals->GetClientSize();
548  m_signals->AppendColumn( _( "Signal" ), wxLIST_FORMAT_LEFT, size.x );
549 
550  // Build an image list, to show the color of the corresponding trace
551  // in the plot panel
552  // This image list is used for trace and cursor lists
553  wxMemoryDC bmDC;
554  const int isize = bmDC.GetCharHeight();
555 
556  if( m_signalsIconColorList == NULL )
557  m_signalsIconColorList = new wxImageList( isize, isize, false );
558  else
559  m_signalsIconColorList->RemoveAll();
560 
561  for( const auto& trace : CurrentPlot()->GetTraces() )
562  {
563  wxBitmap bitmap( isize, isize );
564  bmDC.SelectObject( bitmap );
565  wxColour tcolor = trace.second->GetTraceColour();
566 
567  wxColour bgColor = m_signals->wxWindow::GetBackgroundColour();
568  bmDC.SetPen( wxPen( bgColor ) );
569  bmDC.SetBrush( wxBrush( bgColor ) );
570  bmDC.DrawRectangle( 0, 0, isize, isize ); // because bmDC.Clear() does not work in wxGTK
571 
572  bmDC.SetPen( wxPen( tcolor ) );
573  bmDC.SetBrush( wxBrush( tcolor ) );
574  bmDC.DrawRectangle( 0, isize / 4 + 1, isize, isize / 2 );
575 
576  bmDC.SelectObject( wxNullBitmap ); // Needed to initialize bitmap
577 
578  bitmap.SetMask( new wxMask( bitmap, *wxBLACK ) );
579  m_signalsIconColorList->Add( bitmap );
580  }
581 
582  if( bmDC.IsOk() )
583  {
584  bmDC.SetBrush( wxNullBrush );
585  bmDC.SetPen( wxNullPen );
586  }
587 
588  m_signals->SetImageList( m_signalsIconColorList, wxIMAGE_LIST_SMALL );
589 
590  // Fill the signals listctrl. Keep the order of names and
591  // the order of icon color identical, because the icons
592  // are also used in cursor list, and the color index is
593  // calculated from the trace name index
594  int imgidx = 0;
595 
596  for( const auto& trace : m_plots[plotPanel].m_traces )
597  {
598  m_signals->InsertItem( imgidx, trace.first, imgidx );
599  imgidx++;
600  }
601 }
602 
603 
605 {
606  wxQueueEvent( this, new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
607 }
608 
609 
611 {
612  const auto& spiceItems = m_exporter->GetSpiceItems();
613 
614  for( auto it = m_tuners.begin(); it != m_tuners.end(); /* iteration inside the loop */ )
615  {
616  const wxString& ref = (*it)->GetComponentName();
617 
618  if( std::find_if( spiceItems.begin(), spiceItems.end(), [&]( const SPICE_ITEM& item )
619  {
620  return item.m_refName == ref;
621  }) == spiceItems.end() )
622  {
623  // The component does not exist anymore, remove the associated tuner
624  TUNER_SLIDER* tuner = *it;
625  it = m_tuners.erase( it );
626  RemoveTuner( tuner, false );
627  }
628  else
629  {
630  ++it;
631  }
632  }
633 }
634 
635 
637 {
638  for( auto& tuner : m_tuners )
639  {
641  std::string command( "alter @" + tuner->GetSpiceName()
642  + "=" + tuner->GetValue().ToSpiceString() );
643 
644  m_simulator->Command( command );
645  }
646 }
647 
648 
649 bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath )
650 {
651  m_plots.clear();
652  m_plotNotebook->DeleteAllPages();
653 
654  wxTextFile file( aPath );
655 
656  if( !file.Open() )
657  return false;
658 
659  long plotsCount;
660 
661  if( !file.GetFirstLine().ToLong( &plotsCount ) ) // GetFirstLine instead of GetNextLine
662  return false;
663 
664  for( long i = 0; i < plotsCount; ++i )
665  {
666  long plotType, tracesCount;
667 
668  if( !file.GetNextLine().ToLong( &plotType ) )
669  return false;
670 
671  SIM_PLOT_PANEL* plotPanel = NewPlotPanel( (SIM_TYPE) plotType );
672  m_plots[plotPanel].m_simCommand = file.GetNextLine();
673  StartSimulation();
674 
675  // Perform simulation, so plots can be added with values
676  do
677  {
678  wxThread::This()->Sleep( 50 );
679  }
680  while( IsSimulationRunning() );
681 
682  if( !file.GetNextLine().ToLong( &tracesCount ) )
683  return false;
684 
685  for( long j = 0; j < tracesCount; ++j )
686  {
687  long traceType;
688  wxString name, param;
689 
690  if( !file.GetNextLine().ToLong( &traceType ) )
691  return false;
692 
693  name = file.GetNextLine();
694  param = file.GetNextLine();
695 
696  if( name.IsEmpty() || param.IsEmpty() )
697  return false;
698 
699  addPlot( name, (SIM_PLOT_TYPE) traceType, param );
700  }
701  }
702 
703  return true;
704 }
705 
706 
707 bool SIM_PLOT_FRAME::saveWorkbook( const wxString& aPath )
708 {
709  wxTextFile file( aPath );
710 
711  if( file.Exists() )
712  {
713  if( !file.Open() )
714  return false;
715 
716  file.Clear();
717  }
718  else
719  {
720  file.Create();
721  }
722 
723  file.AddLine( wxString::Format( "%lu", m_plots.size() ) );
724 
725  for( const auto& plot : m_plots )
726  {
727  file.AddLine( wxString::Format( "%d", plot.first->GetType() ) );
728  file.AddLine( plot.second.m_simCommand );
729  file.AddLine( wxString::Format( "%lu", plot.second.m_traces.size() ) );
730 
731  for( const auto& trace : plot.second.m_traces )
732  {
733  file.AddLine( wxString::Format( "%d", trace.second.GetType() ) );
734  file.AddLine( trace.second.GetName() );
735  file.AddLine( trace.second.GetParam() );
736  }
737  }
738 
739  bool res = file.Write();
740  file.Close();
741 
742  return res;
743 }
744 
745 
747 {
748  switch( aType )
749  {
750  case ST_AC:
751  return SPT_LIN_FREQUENCY;
753 
754  case ST_DC:
755  return SPT_SWEEP;
756 
757  case ST_TRANSIENT:
758  return SPT_TIME;
759 
760  default:
761  wxASSERT_MSG( false, "Unhandled simulation type" );
762  return (SIM_PLOT_TYPE) 0;
763  }
764 }
765 
766 
767 void SIM_PLOT_FRAME::menuNewPlot( wxCommandEvent& aEvent )
768 {
769  SIM_TYPE type = m_exporter->GetSimType();
770 
771  if( SIM_PLOT_PANEL::IsPlottable( type ) )
772  {
773  SIM_PLOT_PANEL* prevPlot = CurrentPlot();
774  SIM_PLOT_PANEL* newPlot = NewPlotPanel( type );
775 
776  // If the previous plot had the same type, copy the simulation command
777  if( prevPlot )
778  m_plots[newPlot].m_simCommand = m_plots[prevPlot].m_simCommand;
779  }
780 }
781 
782 
783 void SIM_PLOT_FRAME::menuOpenWorkbook( wxCommandEvent& event )
784 {
785  wxFileDialog openDlg( this, _( "Open simulation workbook" ), m_savedWorkbooksPath, "",
786  _( "Workbook file (*.wbk)|*.wbk" ), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
787 
788  if( openDlg.ShowModal() == wxID_CANCEL )
789  return;
790 
791  m_savedWorkbooksPath = openDlg.GetDirectory();
792 
793  if( !loadWorkbook( openDlg.GetPath() ) )
794  DisplayError( this, _( "There was an error while opening the workbook file" ) );
795 }
796 
797 
798 void SIM_PLOT_FRAME::menuSaveWorkbook( wxCommandEvent& event )
799 {
800  if( !CurrentPlot() )
801  return;
802 
803  wxFileDialog saveDlg( this, _( "Save simulation workbook" ), m_savedWorkbooksPath, "",
804  _( "Workbook file (*.wbk)|*.wbk" ), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
805 
806  if( saveDlg.ShowModal() == wxID_CANCEL )
807  return;
808 
809  m_savedWorkbooksPath = saveDlg.GetDirectory();
810 
811  if( !saveWorkbook( saveDlg.GetPath() ) )
812  DisplayError( this, _( "There was an error while saving the workbook file" ) );
813 }
814 
815 
816 void SIM_PLOT_FRAME::menuSaveImage( wxCommandEvent& event )
817 {
818  if( !CurrentPlot() )
819  return;
820 
821  wxFileDialog saveDlg( this, _( "Save plot as image" ), "", "",
822  _( "PNG file (*.png)|*.png" ), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
823 
824  if( saveDlg.ShowModal() == wxID_CANCEL )
825  return;
826 
827  CurrentPlot()->SaveScreenshot( saveDlg.GetPath(), wxBITMAP_TYPE_PNG );
828 }
829 
830 
831 void SIM_PLOT_FRAME::menuSaveCsv( wxCommandEvent& event )
832 {
833  if( !CurrentPlot() )
834  return;
835 
836  const wxChar SEPARATOR = ';';
837 
838  wxFileDialog saveDlg( this, _( "Save plot data" ), "", "",
839  "CSV file (*.csv)|*.csv", wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
840 
841  if( saveDlg.ShowModal() == wxID_CANCEL )
842  return;
843 
844  wxFile out( saveDlg.GetPath(), wxFile::write );
845  bool timeWritten = false;
846 
847  for( const auto& t : CurrentPlot()->GetTraces() )
848  {
849  const TRACE* trace = t.second;
850 
851  if( !timeWritten )
852  {
853  out.Write( wxString::Format( "Time%c", SEPARATOR ) );
854 
855  for( double v : trace->GetDataX() )
856  out.Write( wxString::Format( "%f%c", v, SEPARATOR ) );
857 
858  out.Write( "\r\n" );
859  timeWritten = true;
860  }
861 
862  out.Write( wxString::Format( "%s%c", t.first, SEPARATOR ) );
863 
864  for( double v : trace->GetDataY() )
865  out.Write( wxString::Format( "%f%c", v, SEPARATOR ) );
866 
867  out.Write( "\r\n" );
868  }
869 
870  out.Close();
871 }
872 
873 
874 void SIM_PLOT_FRAME::menuZoomIn( wxCommandEvent& event )
875 {
876  if( CurrentPlot() )
877  CurrentPlot()->ZoomIn();
878 }
879 
880 
881 void SIM_PLOT_FRAME::menuZoomOut( wxCommandEvent& event )
882 {
883  if( CurrentPlot() )
884  CurrentPlot()->ZoomOut();
885 }
886 
887 
888 void SIM_PLOT_FRAME::menuZoomFit( wxCommandEvent& event )
889 {
890  if( CurrentPlot() )
891  CurrentPlot()->Fit();
892 }
893 
894 
895 void SIM_PLOT_FRAME::menuShowGrid( wxCommandEvent& event )
896 {
897  SIM_PLOT_PANEL* plot = CurrentPlot();
898 
899  if( plot )
900  plot->ShowGrid( !plot->IsGridShown() );
901 }
902 
903 
904 void SIM_PLOT_FRAME::menuShowGridUpdate( wxUpdateUIEvent& event )
905 {
906  SIM_PLOT_PANEL* plot = CurrentPlot();
907 
908  if( plot )
909  event.Check( plot ? plot->IsGridShown() : false );
910 }
911 
912 
913 void SIM_PLOT_FRAME::menuShowLegend( wxCommandEvent& event )
914 {
915  SIM_PLOT_PANEL* plot = CurrentPlot();
916 
917  if( plot )
918  plot->ShowLegend( !plot->IsLegendShown() );
919 }
920 
921 
922 void SIM_PLOT_FRAME::menuShowLegendUpdate( wxUpdateUIEvent& event )
923 {
924  SIM_PLOT_PANEL* plot = CurrentPlot();
925  event.Check( plot ? plot->IsLegendShown() : false );
926 }
927 
928 
929 void SIM_PLOT_FRAME::onPlotClose( wxAuiNotebookEvent& event )
930 {
931  int idx = event.GetSelection();
932 
933  if( idx == wxNOT_FOUND )
934  return;
935 
936  SIM_PLOT_PANEL* plotPanel = dynamic_cast<SIM_PLOT_PANEL*>( m_plotNotebook->GetPage( idx ) );
937 
938  if( !plotPanel )
939  return;
940 
941  m_plots.erase( plotPanel );
943  updateCursors();
944 }
945 
946 
947 void SIM_PLOT_FRAME::onPlotChanged( wxAuiNotebookEvent& event )
948 {
950  updateCursors();
951 }
952 
953 
954 void SIM_PLOT_FRAME::onSignalDblClick( wxMouseEvent& event )
955 {
956  // Remove signal from the plot panel when double clicked
957  long idx = m_signals->GetFocusedItem();
958 
959  if( idx != wxNOT_FOUND )
960  removePlot( m_signals->GetItemText( idx, 0 ) );
961 }
962 
963 
964 void SIM_PLOT_FRAME::onSignalRClick( wxListEvent& event )
965 {
966  int idx = event.GetIndex();
967 
968  if( idx != wxNOT_FOUND )
969  m_signals->Select( idx );
970 
971  idx = m_signals->GetFirstSelected();
972 
973  if( idx != wxNOT_FOUND )
974  {
975  const wxString& netName = m_signals->GetItemText( idx, 0 );
976  SIGNAL_CONTEXT_MENU ctxMenu( netName, this );
977  m_signals->PopupMenu( &ctxMenu );
978  }
979 }
980 
981 
982 void SIM_PLOT_FRAME::onSimulate( wxCommandEvent& event )
983 {
984  if( IsSimulationRunning() )
985  StopSimulation();
986  else
987  StartSimulation();
988 }
989 
990 
991 void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event )
992 {
993  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
994 
995  // Initial processing is required to e.g. display a list of power sources
997 
998  if( !m_exporter->ProcessNetlist( NET_ALL_FLAGS ) )
999  {
1000  DisplayError( this, _( "There were errors during netlist export, aborted." ) );
1001  return;
1002  }
1003 
1004  if( !m_settingsDlg )
1005  m_settingsDlg = new DIALOG_SIM_SETTINGS( this );
1006 
1007  if( plotPanel )
1008  m_settingsDlg->SetSimCommand( m_plots[plotPanel].m_simCommand );
1009 
1011 
1012  if( m_settingsDlg->ShowModal() == wxID_OK )
1013  {
1014  wxString newCommand = m_settingsDlg->GetSimCommand();
1015  SIM_TYPE newSimType = NETLIST_EXPORTER_PSPICE_SIM::CommandToSimType( newCommand );
1016 
1017  // If it is a new simulation type, open a new plot
1018  if( !plotPanel || ( plotPanel && plotPanel->GetType() != newSimType ) )
1019  {
1020  plotPanel = NewPlotPanel( newSimType );
1021  }
1022 
1023  m_plots[plotPanel].m_simCommand = newCommand;
1024  }
1025 }
1026 
1027 
1028 void SIM_PLOT_FRAME::onAddSignal( wxCommandEvent& event )
1029 {
1030  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
1031 
1032  if( !plotPanel || !m_exporter || plotPanel->GetType() != m_exporter->GetSimType() )
1033  {
1034  DisplayInfoMessage( this, _( "You need to run simulation first." ) );
1035  return;
1036  }
1037 
1038  DIALOG_SIGNAL_LIST dialog( this, m_exporter.get() );
1039  dialog.ShowModal();
1040 }
1041 
1042 
1043 void SIM_PLOT_FRAME::onProbe( wxCommandEvent& event )
1044 {
1045  if( m_schematicFrame == NULL )
1046  return;
1047 
1048  wxQueueEvent( m_schematicFrame, new wxCommandEvent( wxEVT_TOOL, ID_SIM_PROBE ) );
1049  m_schematicFrame->Raise();
1050 }
1051 
1052 
1053 void SIM_PLOT_FRAME::onTune( wxCommandEvent& event )
1054 {
1055  if( m_schematicFrame == NULL )
1056  return;
1057 
1058  wxQueueEvent( m_schematicFrame, new wxCommandEvent( wxEVT_TOOL, ID_SIM_TUNE ) );
1059  m_schematicFrame->Raise();
1060 }
1061 
1062 
1063 void SIM_PLOT_FRAME::onClose( wxCloseEvent& aEvent )
1064 {
1065  SaveSettings( config() );
1066 
1067  if( IsSimulationRunning() )
1068  m_simulator->Stop();
1069 
1070  Destroy();
1071 }
1072 
1073 
1074 void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& event )
1075 {
1076  wxSize size = m_cursors->GetClientSize();
1077  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
1078  m_cursors->ClearAll();
1079 
1080  if( !plotPanel )
1081  return;
1082 
1084  m_cursors->SetImageList(m_signalsIconColorList, wxIMAGE_LIST_SMALL);
1085 
1086  // Fill the signals listctrl
1087  m_cursors->AppendColumn( _( "Signal" ), wxLIST_FORMAT_LEFT, size.x / 2 );
1088  const long X_COL = m_cursors->AppendColumn( plotPanel->GetLabelX(), wxLIST_FORMAT_LEFT, size.x / 4 );
1089 
1090  wxString labelY1 = plotPanel->GetLabelY1();
1091  wxString labelY2 = plotPanel->GetLabelY2();
1092  wxString labelY;
1093 
1094  if( !labelY2.IsEmpty() )
1095  labelY = labelY1 + " / " + labelY2;
1096  else
1097  labelY = labelY1;
1098 
1099  const long Y_COL = m_cursors->AppendColumn( labelY, wxLIST_FORMAT_LEFT, size.x / 4 );
1100 
1101  // Update cursor values
1102  int itemidx = 0;
1103  for( const auto& trace : plotPanel->GetTraces() )
1104  {
1105  if( CURSOR* cursor = trace.second->GetCursor() )
1106  {
1107  // Find the right icon color in list.
1108  // It is the icon used in m_signals list for the same trace
1109  long iconColor = m_signals->FindItem( -1, trace.first );
1110 
1111  const wxRealPoint coords = cursor->GetCoords();
1112  long idx = m_cursors->InsertItem( itemidx++, trace.first, iconColor );
1113  m_cursors->SetItem( idx, X_COL, SPICE_VALUE( coords.x ).ToSpiceString() );
1114  m_cursors->SetItem( idx, Y_COL, SPICE_VALUE( coords.y ).ToSpiceString() );
1115  }
1116  }
1117 }
1118 
1119 
1120 void SIM_PLOT_FRAME::onSimStarted( wxCommandEvent& aEvent )
1121 {
1122  m_toolBar->SetToolNormalBitmap( ID_SIM_RUN, KiBitmap( sim_stop_xpm ) );
1123  SetCursor( wxCURSOR_ARROWWAIT );
1124 }
1125 
1126 
1127 void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent )
1128 {
1129  m_toolBar->SetToolNormalBitmap( ID_SIM_RUN, KiBitmap( sim_run_xpm ) );
1130  SetCursor( wxCURSOR_ARROW );
1131 
1132  SIM_TYPE simType = m_exporter->GetSimType();
1133 
1134  if( simType == ST_UNKNOWN )
1135  return;
1136 
1137  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
1138 
1139  if( !plotPanel || plotPanel->GetType() != simType )
1140  plotPanel = NewPlotPanel( simType );
1141 
1142  if( IsSimulationRunning() )
1143  return;
1144 
1145  // If there are any signals plotted, update them
1146  if( SIM_PLOT_PANEL::IsPlottable( simType ) )
1147  {
1148  TRACE_MAP& traceMap = m_plots[plotPanel].m_traces;
1149 
1150  for( auto it = traceMap.begin(); it != traceMap.end(); /* iteration occurs in the loop */)
1151  {
1152  if( !updatePlot( it->second, plotPanel ) )
1153  {
1154  removePlot( it->first, false );
1155  it = traceMap.erase( it ); // remove a plot that does not exist anymore
1156  }
1157  else
1158  {
1159  ++it;
1160  }
1161  }
1162 
1163  updateSignalList();
1164  plotPanel->UpdateAll();
1165  plotPanel->ResetScales();
1166  }
1167  else
1168  {
1170  for( const auto& net : m_exporter->GetNetIndexMap() )
1171  {
1172  int node = net.second;
1173 
1174  if( node > 0 )
1175  m_simulator->Command( wxString::Format( "print v(%d)", node ).ToStdString() );
1176  }
1177  }
1178 }
1179 
1180 
1181 void SIM_PLOT_FRAME::onSimUpdate( wxCommandEvent& aEvent )
1182 {
1183  if( IsSimulationRunning() )
1184  StopSimulation();
1185 
1186  if( CurrentPlot() != m_lastSimPlot )
1187  {
1188  // We need to rerun simulation, as the simulator currently stores
1189  // results for another plot
1190  StartSimulation();
1191  }
1192  else
1193  {
1194  // Incremental update
1195  m_simConsole->Clear();
1196  // Do not export netlist, it is already stored in the simulator
1197  applyTuners();
1198  m_simulator->Run();
1199  }
1200 }
1201 
1202 
1203 void SIM_PLOT_FRAME::onSimReport( wxCommandEvent& aEvent )
1204 {
1205  m_simConsole->AppendText( aEvent.GetString() + "\n" );
1206  m_simConsole->SetInsertionPointEnd();
1207 }
1208 
1209 
1211  SIM_PLOT_FRAME* aPlotFrame )
1212  : m_signal( aSignal ), m_plotFrame( aPlotFrame )
1213 {
1215 
1216  AddMenuItem( this, HIDE_SIGNAL, _( "Hide signal" ),
1217  _( "Erase the signal from plot screen" ),
1218  KiBitmap( delete_xpm ) );
1219 
1220  TRACE* trace = plot->GetTrace( m_signal );
1221 
1222  if( trace->HasCursor() )
1223  AddMenuItem( this, HIDE_CURSOR, _( "Hide cursor" ),
1224  wxEmptyString, KiBitmap( mirepcb_xpm ) );
1225  else
1226  AddMenuItem( this, SHOW_CURSOR, _( "Show cursor" ),
1227  wxEmptyString, KiBitmap( mirepcb_xpm ) );
1228 
1229  Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( SIGNAL_CONTEXT_MENU::onMenuEvent ), NULL, this );
1230 }
1231 
1232 
1234 {
1235  SIM_PLOT_PANEL* plot = m_plotFrame->CurrentPlot();
1236 
1237  switch( aEvent.GetId() )
1238  {
1239  case HIDE_SIGNAL:
1240  m_plotFrame->removePlot( m_signal );
1241  break;
1242 
1243  case SHOW_CURSOR:
1244  plot->EnableCursor( m_signal, true );
1245  break;
1246 
1247  case HIDE_CURSOR:
1248  plot->EnableCursor( m_signal, false );
1249  break;
1250  }
1251 }
1252 
1253 wxDEFINE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
1254 wxDEFINE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
1255 
1256 wxDEFINE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
1257 wxDEFINE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
void onAddSignal(wxCommandEvent &event)
void ZoomOut(const wxPoint &centerPoint=wxDefaultPosition)
Zoom out current view and refresh display.
Definition: mathplot.cpp:2306
virtual std::string GetXAxis(SIM_TYPE aType) const =0
Returns X axis name for a given simulation type
bool saveWorkbook(const wxString &aPath)
Saves plot settings to a file.
void SetKiway(wxWindow *aDest, KIWAY *aKiway)
Function SetKiway.
wxToolBarToolBase * m_toolProbe
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
void onSimStarted(wxCommandEvent &aEvent)
NETLIST_OBJECT_LIST * BuildNetListBase(bool updateStatusText=true)
BuildNetListBase netlist generation: Creates a flat list which stores all connected objects...
void RemoveTuner(TUNER_SLIDER *aTuner, bool aErase=true)
Removes an existing tuner.
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:60
const wxString & GetName() const
wxImageList * m_signalsIconColorList
imagelists uset to add a small coloured icon to signal names and cursors name, the same color as the ...
SIM_PLOT_TYPE operator|(SIM_PLOT_TYPE aFirst, SIM_PLOT_TYPE aSecond)
void onPlotChanged(wxAuiNotebookEvent &event) override
virtual bool IsRunning()=0
Checks if simulation is running at the moment.
long trace
Definition: solve.cpp:232
SIM_PLOT_FRAME * m_parent
void onSignalDblClick(wxMouseEvent &event) override
bool SetSimCommand(const wxString &aCommand)
wxString ToSpiceString() const
Returns string value in Spice format (e.g.
virtual std::vector< double > GetPhasePlot(const std::string &aName, int aMaxLen=-1)=0
Returns a requested vector with phase values.
This file is part of the common library.
virtual void SetReporter(SPICE_REPORTER *aReporter)
Sets a SPICE_REPORTER object to receive the simulation log.
wxSplitterWindow * m_splitterSignals
SIM_PLOT_TYPE GetXAxisType(SIM_TYPE aType) const
Returns X axis for a given simulation type.
bool TraceShown(const wxString &aName) const
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:55
const std::vector< double > & GetDataY() const
#define SIGNALS_PANEL_HEIGHT_ENTRY
void ShowLegend(bool aEnable)
int m_splitterPlotAndConsoleSashPosition
wxString GetLabelX() const
void menuZoomFit(wxCommandEvent &event) override
Structure to represent a schematic component in the Spice simulation.
virtual void SaveSettings(wxConfigBase *aCfg)
Function SaveSettings saves common frame parameters to a configuration data file. ...
Definition: basicframe.cpp:316
static bool IsPlottable(SIM_TYPE aSimType)
SIM_PLOT_TYPE GetType() const
std::list< TUNER_SLIDER * > m_tuners
List of currently displayed tuners
wxString m_title
Title displayed in the signal list/plot legend
Class SIM_PLOT_FRAME_BASE.
const wxString & GetParam() const
void menuNewPlot(wxCommandEvent &aEvent) override
void applyTuners()
Applies component values specified using tunder sliders to the current netlist.
void AddVoltagePlot(const wxString &aNetName)
Adds a voltage plot for a given net name.
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
Definition: basicframe.cpp:361
void AddCurrentPlot(const wxString &aDeviceName, const wxString &aParam)
Adds a current plot for a particular device.
Trace descriptor class
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
void onSimUpdate(wxCommandEvent &aEvent)
void menuOpenWorkbook(wxCommandEvent &event) override
void menuShowGrid(wxCommandEvent &event) override
void menuZoomIn(wxCommandEvent &event) override
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
void menuZoomOut(wxCommandEvent &event) override
SIM_THREAD_REPORTER * m_reporter
void OnSimStateChange(SPICE_SIMULATOR *aObject, SIM_STATE aNewState) override
bool updatePlot(const TRACE_DESC &aDescriptor, SIM_PLOT_PANEL *aPanel)
Updates plot in a particular SIM_PLOT_PANEL.
Field Reference of part, i.e. "IC21".
void updateCursors()
Updates the cursor values list.
wxSplitterWindow * m_splitterTuneValues
static SIM_TYPE CommandToSimType(const wxString &aCmd)
Returns simulation type basing on a simulation command directive.
void menuSaveCsv(wxCommandEvent &event) override
void onPlotClose(wxAuiNotebookEvent &event) override
wxAuiNotebook * m_plotNotebook
SCH_EDIT_FRAME * m_schematicFrame
bool DeleteTrace(const wxString &aName)
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2814
bool IsGridShown() const
int GetNetlistOptions() const
void EnableCursor(const wxString &aName, bool aEnable)
Toggles cursor for a particular trace.
SIM_STATE
void setSubWindowsSashSize()
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
virtual void Init()=0
Intializes the simulator
bool IsLegendShown() const
#define PLOT_PANEL_WIDTH_ENTRY
SEVERITY
Severity of the reported messages.
Definition: reporter.h:65
wxString GetLabelY2() const
std::map< SIM_PLOT_PANEL *, PLOT_INFO > m_plots
Map of plot panels and associated data
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, KIWAY_PLAYER *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:302
SIM_PLOT_PANEL * m_lastSimPlot
Panel that was used as the most recent one for simulations
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
const std::map< wxString, TRACE * > & GetTraces() const
wxString GetLabelY1() const
Helper class to handle Spice way of expressing values (e.g. 10.5 Meg)
Definition: spice_value.h:32
wxSplitterWindow * m_splitterLeftRight
void ZoomIn(const wxPoint &centerPoint=wxDefaultPosition)
Zoom into current view and refresh display.
Definition: mathplot.cpp:2249
#define CURSORS_PANEL_HEIGHT_ENTRY
wxMenuItem * m_runSimulation
void onSimReport(wxCommandEvent &aEvent)
SIM_TYPE
Possible simulation types
Definition: sim_types.h:29
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
virtual void LoadSettings(wxConfigBase *aCfg)
Function LoadSettings loads common frame parameters from a configuration file.
Definition: basicframe.cpp:256
void onSimFinished(wxCommandEvent &aEvent)
Interface to receive simulation updates from SPICE_SIMULATOR class.
virtual bool Command(const std::string &aCmd)=0
Executes a Spice command as if it was typed into console.
bool AddTrace(const wxString &aName, int aPoints, const double *aX, const double *aY, SIM_PLOT_TYPE aFlags)
SIM_THREAD_REPORTER(SIM_PLOT_FRAME *aParent)
void menuShowLegendUpdate(wxUpdateUIEvent &event) override
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
wxToolBarToolBase * m_toolAddSignals
Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder.
int m_splitterTuneValuesSashPosition
wxPoint m_FramePos
Definition: wxstruct.h:134
TRACE_DESC(const NETLIST_EXPORTER_PSPICE_SIM &aExporter, const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam)
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString aExtraInfo)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:102
const std::string & GetString()
Definition: richio.h:475
void onSignalRClick(wxListEvent &event) override
void ResetScales()
Resets scale ranges to fit the current traces
bool IsSimulationRunning()
SPICE_SIMULATOR * m_simulator
void menuShowLegend(wxCommandEvent &event) override
#define PLOT_PANEL_HEIGHT_ENTRY
void ShowGrid(bool aEnable)
void onTune(wxCommandEvent &event)
wxToolBarToolBase * m_toolSimulate
SIM_TYPE GetType() const
void menuSaveImage(wxCommandEvent &event) override
Implementing SIM_PLOT_FRAME_BASE.
bool loadWorkbook(const wxString &aPath)
Loads plot settings from a file.
void SetNetlistExporter(NETLIST_EXPORTER_PSPICE_SIM *aExporter)
static wxString m_savedWorkbooksPath
A string to store the path of saved workbooks during a session
virtual bool LoadNetlist(const std::string &aNetlist)=0
void onCursorUpdate(wxCommandEvent &aEvent)
DIALOG_SIM_SETTINGS * m_settingsDlg
void Fit() override
Set view to fit global bounding box of all plot layers and refresh display.
Definition: mathplot.cpp:2006
virtual bool Run()=0
Executes the simulation with currently loaded netlist.
const wxString & GetSimCommand() const
bool HasCursor() const
std::unique_ptr< NETLIST_EXPORTER_PSPICE_SIM > m_exporter
void updateNetlistExporter()
Reloads the current schematic for the netlist exporter.
see class PGM_BASE
void onSimulate(wxCommandEvent &event)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
SIGNAL_CONTEXT_MENU(const wxString &aSignal, SIM_PLOT_FRAME *aPlotFrame)
void onProbe(wxCommandEvent &event)
void updateSignalList()
Updates the list of currently plotted signals.
TRACE * GetTrace(const wxString &aName) const
const wxString & GetTitle() const
static wxString GetSpiceField(SPICE_FIELD aField, SCH_COMPONENT *aComponent, unsigned aCtl)
Retrieves either the requested field value or the default value.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
int m_splitterSignalsSashPosition
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
SIM_PLOT_PANEL * CurrentPlot() const
Returns the currently opened plot panel (or NULL if there is none).
std::map< wxString, TRACE_DESC > TRACE_MAP
wxDEFINE_EVENT(EVT_SIM_UPDATE, wxCommandEvent)
const char * name
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
int m_splitterLeftRightSashPosition
virtual bool Stop()=0
Halts the simulation.
const std::vector< double > & GetDataX() const
wxSize m_FrameSize
Definition: wxstruct.h:135
void removePlot(const wxString &aPlotName, bool aErase=true)
Removes a plot with a specific title.
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
Custom widget to handle quick component values modification and simulation on the fly...
Definition: tuner_slider.h:40
void AddTuner(SCH_COMPONENT *aComponent)
Adds a tuner for a component.
bool SaveScreenshot(const wxString &filename, wxBitmapType type=wxBITMAP_TYPE_BMP, wxSize imageSize=wxDefaultSize, bool fit=false)
Draw the window on a wxBitmap, then save it to a file.
Definition: mathplot.cpp:3044
wxSplitterWindow * m_splitterPlotAndConsole
void menuShowGridUpdate(wxUpdateUIEvent &event) override
void menuSaveWorkbook(wxCommandEvent &event) override
Class STRING_FORMATTER implements OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:445
SIM_PLOT_TYPE
Possible plot types
Definition: sim_types.h:35
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
static SPICE_SIMULATOR * CreateInstance(const std::string &aName)
Creates a simulator instance of particular type (currently only ngspice is handled) ...
void addPlot(const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam)
Adds a new plot to the current panel.
void onSettings(wxCommandEvent &event)
void onClose(wxCloseEvent &aEvent)
wxToolBarToolBase * m_toolTune
void onMenuEvent(wxMenuEvent &aEvent)
SIM_PLOT_PANEL * NewPlotPanel(SIM_TYPE aSimType)
Creates a new plot panel for a given simulation type and adds it to the main notebook.
virtual std::vector< double > GetMagPlot(const std::string &aName, int aMaxLen=-1)=0
Returns a requested vector with magnitude values.
Cursor attached to a trace to follow its values:
Special netlist exporter flavor that allows to override simulation commands.
void updateTuners()
Filters out tuners for components that do not exist anymore.
wxToolBarToolBase * m_toolSettings
SIM_PLOT_FRAME(KIWAY *aKiway, wxWindow *aParent)
Constructor.