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-2018 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 <wx/stc/stc.h>
28 
29 #include <sch_edit_frame.h>
30 #include <eeschema_id.h>
31 #include <kiway.h>
32 #include <confirm.h>
33 #include <bitmaps.h>
35 
36 #include <widgets/tuner_slider.h>
39 #include <pgm_base.h>
40 
41 #include "sim_plot_frame.h"
42 #include "sim_plot_panel.h"
43 #include "spice_simulator.h"
44 #include "spice_reporter.h"
45 
46 #include <menus_helpers.h>
47 
49 {
50  int res = (int) aFirst | (int) aSecond;
51 
52  return (SIM_PLOT_TYPE) res;
53 }
54 
55 
57 {
58 public:
60  : m_parent( aParent )
61  {
62  }
63 
64  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override
65  {
66  wxCommandEvent* event = new wxCommandEvent( EVT_SIM_REPORT );
67  event->SetString( aText );
68  wxQueueEvent( m_parent, event );
69  return *this;
70  }
71 
72  bool HasMessage() const override
73  {
74  return false; // Technically "indeterminate" rather than false.
75  }
76 
77  void OnSimStateChange( SPICE_SIMULATOR* aObject, SIM_STATE aNewState ) override
78  {
79  wxCommandEvent* event = NULL;
80 
81  switch( aNewState )
82  {
83  case SIM_IDLE:
84  event = new wxCommandEvent( EVT_SIM_FINISHED );
85  break;
86 
87  case SIM_RUNNING:
88  event = new wxCommandEvent( EVT_SIM_STARTED );
89  break;
90 
91  default:
92  wxFAIL;
93  return;
94  }
95 
96  wxQueueEvent( m_parent, event );
97  }
98 
99 private:
101 };
102 
103 
104 TRACE_DESC::TRACE_DESC( const NETLIST_EXPORTER_PSPICE_SIM& aExporter, const wxString& aName,
105  SIM_PLOT_TYPE aType, const wxString& aParam )
106  : m_name( aName ), m_type( aType ), m_param( aParam )
107 {
108  // Title generation
109  m_title = wxString::Format( "%s(%s)", aParam, aName );
110 
111  if( aType & SPT_AC_MAG )
112  m_title += " (mag)";
113  else if( aType & SPT_AC_PHASE )
114  m_title += " (phase)";
115 }
116 
117 // Store the path of saved workbooks during the session
119 
120 SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent )
121  : SIM_PLOT_FRAME_BASE( aParent ), m_lastSimPlot( nullptr )
122 {
123  SetKiway( this, aKiway );
124  m_signalsIconColorList = NULL;
125 
127 
128  if( m_schematicFrame == NULL )
129  throw std::runtime_error( "There is no schematic window" );
130 
131  // Give an icon
132  wxIcon icon;
133  icon.CopyFromBitmap( KiBitmap( simulator_xpm ) );
134  SetIcon( icon );
135 
136  // Get the previous size and position of windows:
137  LoadSettings( config() );
138 
140 
141  if( !m_simulator )
142  {
143  throw std::runtime_error( "Could not create simulator instance" );
144  return;
145  }
146 
147  m_simulator->Init();
148 
149  if( m_savedWorkbooksPath.IsEmpty() )
150  {
152  }
153 
154  m_reporter = new SIM_THREAD_REPORTER( this );
155  m_simulator->SetReporter( m_reporter );
156 
158 
159  Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( SIM_PLOT_FRAME::onClose ), NULL, this );
160  Connect( EVT_SIM_UPDATE, wxCommandEventHandler( SIM_PLOT_FRAME::onSimUpdate ), NULL, this );
161  Connect( EVT_SIM_REPORT, wxCommandEventHandler( SIM_PLOT_FRAME::onSimReport ), NULL, this );
162  Connect( EVT_SIM_STARTED, wxCommandEventHandler( SIM_PLOT_FRAME::onSimStarted ), NULL, this );
163  Connect( EVT_SIM_FINISHED, wxCommandEventHandler( SIM_PLOT_FRAME::onSimFinished ), NULL, this );
164  Connect( EVT_SIM_CURSOR_UPDATE, wxCommandEventHandler( SIM_PLOT_FRAME::onCursorUpdate ), NULL, this );
165 
166  // Toolbar buttons
167  m_toolSimulate = m_toolBar->AddTool( ID_SIM_RUN, _( "Run/Stop Simulation" ),
168  KiBitmap( sim_run_xpm ), _( "Run Simulation" ), wxITEM_NORMAL );
169  m_toolAddSignals = m_toolBar->AddTool( ID_SIM_ADD_SIGNALS, _( "Add Signals" ),
170  KiBitmap( sim_add_signal_xpm ), _( "Add signals to plot" ), wxITEM_NORMAL );
171  m_toolProbe = m_toolBar->AddTool( ID_SIM_PROBE, _( "Probe" ),
172  KiBitmap( sim_probe_xpm ), _( "Probe signals on the schematic" ), wxITEM_NORMAL );
173  m_toolTune = m_toolBar->AddTool( ID_SIM_TUNE, _( "Tune" ),
174  KiBitmap( sim_tune_xpm ), _( "Tune component values" ), wxITEM_NORMAL );
175  m_toolSettings = m_toolBar->AddTool( wxID_ANY, _( "Settings" ),
176  KiBitmap( sim_settings_xpm ), _( "Simulation settings" ), wxITEM_NORMAL );
177 
178  Connect( m_toolSimulate->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
179  wxCommandEventHandler( SIM_PLOT_FRAME::onSimulate ), NULL, this );
180  Connect( m_toolAddSignals->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
181  wxCommandEventHandler( SIM_PLOT_FRAME::onAddSignal ), NULL, this );
182  Connect( m_toolProbe->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
183  wxCommandEventHandler( SIM_PLOT_FRAME::onProbe ), NULL, this );
184  Connect( m_toolTune->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
185  wxCommandEventHandler( SIM_PLOT_FRAME::onTune ), NULL, this );
186  Connect( m_toolSettings->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
187  wxCommandEventHandler( SIM_PLOT_FRAME::onSettings ), NULL, this );
188 
189  // Bind toolbar buttons event to existing menu event handlers, so they behave the same
190  Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onSimulate, this, m_runSimulation->GetId() );
191  Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onAddSignal, this, m_addSignals->GetId() );
192  Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onProbe, this, m_probeSignals->GetId() );
193  Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onTune, this, m_tuneValue->GetId() );
194  Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onShowNetlist, this, m_showNetlist->GetId() );
195  Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onSettings, this, m_settings->GetId() );
196 
197  m_toolBar->Realize();
198  m_plotNotebook->SetPageText( 0, _( "Welcome!" ) );
199 
200  // the settings dialog will be created later, on demand.
201  // if created in the ctor, for some obscure reason, there is an issue
202  // on Windows: when open it, the simulator frame is sent to the background.
203  // instead of being behind the dialog frame (as it does)
204  m_settingsDlg = NULL;
205 
206  SetSize( ConvertDialogToPixels( wxSize( 400, 300 ) ) );
207 
208  // resize the subwindows size. At least on Windows, calling wxSafeYield before
209  // resizing the subwindows forces the wxSplitWindows size events automatically generated
210  // by wxWidgets to be executed before our resize code.
211  // Otherwise, the changes made by setSubWindowsSashSize are overwritten by one these
212  // events
213  wxSafeYield();
215 }
216 
217 
219 {
220  m_simulator->SetReporter( nullptr );
221  delete m_reporter;
222  delete m_signalsIconColorList;
223 
224  if( m_settingsDlg )
225  m_settingsDlg->Destroy();
226 }
227 
228 #define PLOT_PANEL_WIDTH_ENTRY "SimPlotPanelWidth"
229 #define PLOT_PANEL_HEIGHT_ENTRY "SimPlotPanelHeight"
230 #define SIGNALS_PANEL_HEIGHT_ENTRY "SimSignalPanelHeight"
231 #define CURSORS_PANEL_HEIGHT_ENTRY "SimCursorsPanelHeight"
232 
233 void SIM_PLOT_FRAME::SaveSettings( wxConfigBase* aCfg )
234 {
235  // Save main frame size and position:
237 
238  // Save subwindows sizes
239  aCfg->Write( PLOT_PANEL_WIDTH_ENTRY, m_splitterLeftRight->GetSashPosition() );
240  aCfg->Write( PLOT_PANEL_HEIGHT_ENTRY, m_splitterPlotAndConsole->GetSashPosition() );
241  aCfg->Write( SIGNALS_PANEL_HEIGHT_ENTRY, m_splitterSignals->GetSashPosition() );
242  aCfg->Write( CURSORS_PANEL_HEIGHT_ENTRY, m_splitterTuneValues->GetSashPosition() );
243 }
244 
245 
246 void SIM_PLOT_FRAME::LoadSettings( wxConfigBase* aCfg )
247 {
248  // Read main frame size and position:
250  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
251 
252  // Read subwindows sizes (should be > 0 )
257 }
258 
259 
261 {
264 
267 
270 
273 }
274 
275 
277 {
278  STRING_FORMATTER formatter;
279  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
280 
281  if( !m_settingsDlg )
282  m_settingsDlg = new DIALOG_SIM_SETTINGS( this );
283 
284  m_simConsole->Clear();
286 
287  if( plotPanel )
288  m_exporter->SetSimCommand( m_plots[plotPanel].m_simCommand );
289 
290  if( !m_exporter->Format( &formatter, m_settingsDlg->GetNetlistOptions() ) )
291  {
292  DisplayError( this, _( "There were errors during netlist export, aborted." ) );
293  return;
294  }
295 
296  if( m_exporter->GetSimType() == ST_UNKNOWN )
297  {
298  DisplayInfoMessage( this, _( "You need to select the simulation settings first." ) );
299  return;
300  }
301 
302  m_simulator->LoadNetlist( formatter.GetString() );
303  updateTuners();
304  applyTuners();
305  m_simulator->Run();
306 }
307 
308 
310 {
311  m_simulator->Stop();
312 }
313 
314 
316 {
317  return m_simulator ? m_simulator->IsRunning() : false;
318 }
319 
320 
322 {
323  SIM_PLOT_PANEL* plotPanel = new SIM_PLOT_PANEL( aSimType, m_plotNotebook, wxID_ANY );
324 
325  if( m_welcomePanel )
326  {
327  m_plotNotebook->DeletePage( 0 );
328  m_welcomePanel = nullptr;
329  }
330 
331  m_plotNotebook->AddPage( plotPanel, wxString::Format( wxT( "Plot%u" ),
332  (unsigned int) m_plotNotebook->GetPageCount() + 1 ), true );
333 
334  m_plots[plotPanel] = PLOT_INFO();
335 
336  return plotPanel;
337 }
338 
339 
340 void SIM_PLOT_FRAME::AddVoltagePlot( const wxString& aNetName )
341 {
342  addPlot( aNetName, SPT_VOLTAGE, "V" );
343 }
344 
345 
346 void SIM_PLOT_FRAME::AddCurrentPlot( const wxString& aDeviceName, const wxString& aParam )
347 {
348  addPlot( aDeviceName, SPT_CURRENT, aParam );
349 }
350 
351 
353 {
354  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
355 
356  if( !plotPanel )
357  return;
358 
359  // For now limit the tuner tool to RLC components
360  char primitiveType = NETLIST_EXPORTER_PSPICE::GetSpiceField( SF_PRIMITIVE, aComponent, 0 )[0];
361 
362  if( primitiveType != SP_RESISTOR && primitiveType != SP_CAPACITOR && primitiveType != SP_INDUCTOR )
363  return;
364 
365  const wxString& componentName = aComponent->GetField( REFERENCE )->GetText();
366 
367  // Do not add multiple instances for the same component
368  auto tunerIt = std::find_if( m_tuners.begin(), m_tuners.end(), [&]( const TUNER_SLIDER* t )
369  {
370  return t->GetComponentName() == componentName;
371  }
372  );
373 
374  if( tunerIt != m_tuners.end() )
375  return; // We already have it
376 
377  try
378  {
379  TUNER_SLIDER* tuner = new TUNER_SLIDER( this, m_tunePanel, aComponent );
380  m_tuneSizer->Add( tuner );
381  m_tuners.push_back( tuner );
382  m_tunePanel->Layout();
383  }
384  catch( ... )
385  {
386  // Sorry, no bonus
387  }
388 }
389 
390 
391 void SIM_PLOT_FRAME::RemoveTuner( TUNER_SLIDER* aTuner, bool aErase )
392 {
393  if( aErase )
394  m_tuners.remove( aTuner );
395 
396  aTuner->Destroy();
397  m_tunePanel->Layout();
398 }
399 
400 
402 {
403  wxWindow* curPage = m_plotNotebook->GetCurrentPage();
404 
405  return ( curPage == m_welcomePanel ) ? nullptr : static_cast<SIM_PLOT_PANEL*>( curPage );
406 }
407 
408 
409 void SIM_PLOT_FRAME::addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam )
410 {
411  SIM_TYPE simType = m_exporter->GetSimType();
412 
413  if( !SIM_PLOT_PANEL::IsPlottable( simType ) )
414  return; // TODO else write out in console?
415 
416  // Create a new plot if the current one displays a different type
417  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
418 
419  if( !plotPanel || plotPanel->GetType() != simType )
420  plotPanel = NewPlotPanel( simType );
421 
422  TRACE_DESC descriptor( *m_exporter, aName, aType, aParam );
423 
424  bool updated = false;
425  SIM_PLOT_TYPE xAxisType = GetXAxisType( simType );
426 
427  if( xAxisType == SPT_LIN_FREQUENCY || xAxisType == SPT_LOG_FREQUENCY )
428  {
429  int baseType = descriptor.GetType() & ~( SPT_AC_MAG | SPT_AC_PHASE );
430 
431  // Add two plots: magnitude & phase
432  TRACE_DESC mag_desc( *m_exporter, descriptor, (SIM_PLOT_TYPE)( baseType | SPT_AC_MAG ) );
433  TRACE_DESC phase_desc( *m_exporter, descriptor, (SIM_PLOT_TYPE)( baseType | SPT_AC_PHASE ) );
434 
435  updated |= updatePlot( mag_desc, plotPanel );
436  updated |= updatePlot( phase_desc, plotPanel );
437  }
438  else
439  {
440  updated = updatePlot( descriptor, plotPanel );
441  }
442 
443  if( updated )
444  {
446  }
447 }
448 
449 
450 void SIM_PLOT_FRAME::removePlot( const wxString& aPlotName, bool aErase )
451 {
452  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
453 
454  if( !plotPanel )
455  return;
456 
457  if( aErase )
458  {
459  auto& traceMap = m_plots[plotPanel].m_traces;
460  auto traceIt = traceMap.find( aPlotName );
461  wxASSERT( traceIt != traceMap.end() );
462  traceMap.erase( traceIt );
463  }
464 
465  wxASSERT( plotPanel->TraceShown( aPlotName ) );
466  plotPanel->DeleteTrace( aPlotName );
467  plotPanel->Fit();
468 
470  updateCursors();
471 }
472 
473 
475 {
477 }
478 
479 
480 bool SIM_PLOT_FRAME::updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL* aPanel )
481 {
482  SIM_TYPE simType = m_exporter->GetSimType();
483  wxString spiceVector = m_exporter->GetSpiceVector( aDescriptor.GetName(),
484  aDescriptor.GetType(), aDescriptor.GetParam() );
485 
486  if( !SIM_PLOT_PANEL::IsPlottable( simType ) )
487  {
488  // There is no plot to be shown
489  m_simulator->Command( wxString::Format( "print %s", spiceVector ).ToStdString() );
490 
491  return false;
492  }
493 
494  // First, handle the x axis
495  wxString xAxisName( m_simulator->GetXAxis( simType ) );
496 
497  if( xAxisName.IsEmpty() )
498  return false;
499 
500  auto data_x = m_simulator->GetMagPlot( (const char*) xAxisName.c_str() );
501  unsigned int size = data_x.size();
502 
503  if( data_x.empty() )
504  return false;
505 
506  SIM_PLOT_TYPE plotType = aDescriptor.GetType();
507  std::vector<double> data_y;
508 
509  // Now, Y axis data
510  switch( m_exporter->GetSimType() )
511  {
512  case ST_AC:
513  {
514  wxASSERT_MSG( !( ( plotType & SPT_AC_MAG ) && ( plotType & SPT_AC_PHASE ) ),
515  "Cannot set both AC_PHASE and AC_MAG bits" );
516 
517  if( plotType & SPT_AC_MAG )
518  data_y = m_simulator->GetMagPlot( (const char*) spiceVector.c_str() );
519  else if( plotType & SPT_AC_PHASE )
520  data_y = m_simulator->GetPhasePlot( (const char*) spiceVector.c_str() );
521  else
522  wxASSERT_MSG( false, "Plot type missing AC_PHASE or AC_MAG bit" );
523  }
524  break;
525 
526  case ST_NOISE:
527  case ST_DC:
528  case ST_TRANSIENT:
529  {
530  data_y = m_simulator->GetMagPlot( (const char*) spiceVector.c_str() );
531  }
532  break;
533 
534  default:
535  wxASSERT_MSG( false, "Unhandled plot type" );
536  return false;
537  }
538 
539  if( data_y.size() != size )
540  return false;
541 
542  if( aPanel->AddTrace( aDescriptor.GetTitle(), size,
543  data_x.data(), data_y.data(), aDescriptor.GetType() ) )
544  {
545  m_plots[aPanel].m_traces.insert( std::make_pair( aDescriptor.GetTitle(), aDescriptor ) );
546  }
547 
548  return true;
549 }
550 
551 
553 {
554  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
555 
556  if( !plotPanel )
557  return;
558 
559  m_signals->ClearAll();
560 
561  wxSize size = m_signals->GetClientSize();
562  m_signals->AppendColumn( _( "Signal" ), wxLIST_FORMAT_LEFT, size.x );
563 
564  // Build an image list, to show the color of the corresponding trace
565  // in the plot panel
566  // This image list is used for trace and cursor lists
567  wxMemoryDC bmDC;
568  const int isize = bmDC.GetCharHeight();
569 
570  if( m_signalsIconColorList == NULL )
571  m_signalsIconColorList = new wxImageList( isize, isize, false );
572  else
573  m_signalsIconColorList->RemoveAll();
574 
575  for( const auto& trace : CurrentPlot()->GetTraces() )
576  {
577  wxBitmap bitmap( isize, isize );
578  bmDC.SelectObject( bitmap );
579  wxColour tcolor = trace.second->GetTraceColour();
580 
581  wxColour bgColor = m_signals->wxWindow::GetBackgroundColour();
582  bmDC.SetPen( wxPen( bgColor ) );
583  bmDC.SetBrush( wxBrush( bgColor ) );
584  bmDC.DrawRectangle( 0, 0, isize, isize ); // because bmDC.Clear() does not work in wxGTK
585 
586  bmDC.SetPen( wxPen( tcolor ) );
587  bmDC.SetBrush( wxBrush( tcolor ) );
588  bmDC.DrawRectangle( 0, isize / 4 + 1, isize, isize / 2 );
589 
590  bmDC.SelectObject( wxNullBitmap ); // Needed to initialize bitmap
591 
592  bitmap.SetMask( new wxMask( bitmap, *wxBLACK ) );
593  m_signalsIconColorList->Add( bitmap );
594  }
595 
596  if( bmDC.IsOk() )
597  {
598  bmDC.SetBrush( wxNullBrush );
599  bmDC.SetPen( wxNullPen );
600  }
601 
602  m_signals->SetImageList( m_signalsIconColorList, wxIMAGE_LIST_SMALL );
603 
604  // Fill the signals listctrl. Keep the order of names and
605  // the order of icon color identical, because the icons
606  // are also used in cursor list, and the color index is
607  // calculated from the trace name index
608  int imgidx = 0;
609 
610  for( const auto& trace : m_plots[plotPanel].m_traces )
611  {
612  m_signals->InsertItem( imgidx, trace.first, imgidx );
613  imgidx++;
614  }
615 }
616 
617 
619 {
620  wxQueueEvent( this, new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
621 }
622 
623 
625 {
626  const auto& spiceItems = m_exporter->GetSpiceItems();
627 
628  for( auto it = m_tuners.begin(); it != m_tuners.end(); /* iteration inside the loop */ )
629  {
630  const wxString& ref = (*it)->GetComponentName();
631 
632  if( std::find_if( spiceItems.begin(), spiceItems.end(), [&]( const SPICE_ITEM& item )
633  {
634  return item.m_refName == ref;
635  }) == spiceItems.end() )
636  {
637  // The component does not exist anymore, remove the associated tuner
638  TUNER_SLIDER* tuner = *it;
639  it = m_tuners.erase( it );
640  RemoveTuner( tuner, false );
641  }
642  else
643  {
644  ++it;
645  }
646  }
647 }
648 
649 
651 {
652  for( auto& tuner : m_tuners )
653  {
655  std::string command( "alter @" + tuner->GetSpiceName()
656  + "=" + tuner->GetValue().ToSpiceString() );
657 
658  m_simulator->Command( command );
659  }
660 }
661 
662 
663 bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath )
664 {
665  m_plots.clear();
666  m_plotNotebook->DeleteAllPages();
667 
668  wxTextFile file( aPath );
669 
670  if( !file.Open() )
671  return false;
672 
673  long plotsCount;
674 
675  if( !file.GetFirstLine().ToLong( &plotsCount ) ) // GetFirstLine instead of GetNextLine
676  return false;
677 
678  for( long i = 0; i < plotsCount; ++i )
679  {
680  long plotType, tracesCount;
681 
682  if( !file.GetNextLine().ToLong( &plotType ) )
683  return false;
684 
685  SIM_PLOT_PANEL* plotPanel = NewPlotPanel( (SIM_TYPE) plotType );
686  m_plots[plotPanel].m_simCommand = file.GetNextLine();
687  StartSimulation();
688 
689  // Perform simulation, so plots can be added with values
690  do
691  {
692  wxThread::This()->Sleep( 50 );
693  }
694  while( IsSimulationRunning() );
695 
696  if( !file.GetNextLine().ToLong( &tracesCount ) )
697  return false;
698 
699  for( long j = 0; j < tracesCount; ++j )
700  {
701  long traceType;
702  wxString name, param;
703 
704  if( !file.GetNextLine().ToLong( &traceType ) )
705  return false;
706 
707  name = file.GetNextLine();
708  param = file.GetNextLine();
709 
710  if( name.IsEmpty() || param.IsEmpty() )
711  return false;
712 
713  addPlot( name, (SIM_PLOT_TYPE) traceType, param );
714  }
715  }
716 
717  return true;
718 }
719 
720 
721 bool SIM_PLOT_FRAME::saveWorkbook( const wxString& aPath )
722 {
723 
724  wxString savePath = aPath;
725 
726  if( !savePath.Lower().EndsWith(".wbk"))
727  {
728  savePath += ".wbk";
729  };
730 
731 
732  wxTextFile file( savePath );
733 
734  if( file.Exists() )
735  {
736  if( !file.Open() )
737  return false;
738 
739  file.Clear();
740  }
741  else
742  {
743  file.Create();
744  }
745 
746  file.AddLine( wxString::Format( "%lu", m_plots.size() ) );
747 
748  for( const auto& plot : m_plots )
749  {
750  file.AddLine( wxString::Format( "%d", plot.first->GetType() ) );
751  file.AddLine( plot.second.m_simCommand );
752  file.AddLine( wxString::Format( "%lu", plot.second.m_traces.size() ) );
753 
754  for( const auto& trace : plot.second.m_traces )
755  {
756  file.AddLine( wxString::Format( "%d", trace.second.GetType() ) );
757  file.AddLine( trace.second.GetName() );
758  file.AddLine( trace.second.GetParam() );
759  }
760  }
761 
762  bool res = file.Write();
763  file.Close();
764 
765  return res;
766 }
767 
768 
770 {
771  switch( aType )
772  {
773  case ST_AC:
774  return SPT_LIN_FREQUENCY;
776 
777  case ST_DC:
778  return SPT_SWEEP;
779 
780  case ST_TRANSIENT:
781  return SPT_TIME;
782 
783  default:
784  wxASSERT_MSG( false, "Unhandled simulation type" );
785  return (SIM_PLOT_TYPE) 0;
786  }
787 }
788 
789 
790 void SIM_PLOT_FRAME::menuNewPlot( wxCommandEvent& aEvent )
791 {
792  SIM_TYPE type = m_exporter->GetSimType();
793 
794  if( SIM_PLOT_PANEL::IsPlottable( type ) )
795  {
796  SIM_PLOT_PANEL* prevPlot = CurrentPlot();
797  SIM_PLOT_PANEL* newPlot = NewPlotPanel( type );
798 
799  // If the previous plot had the same type, copy the simulation command
800  if( prevPlot )
801  m_plots[newPlot].m_simCommand = m_plots[prevPlot].m_simCommand;
802  }
803 }
804 
805 
806 void SIM_PLOT_FRAME::menuOpenWorkbook( wxCommandEvent& event )
807 {
808  wxFileDialog openDlg( this, _( "Open simulation workbook" ), m_savedWorkbooksPath, "",
809  WorkbookFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
810 
811  if( openDlg.ShowModal() == wxID_CANCEL )
812  return;
813 
814  m_savedWorkbooksPath = openDlg.GetDirectory();
815 
816  if( !loadWorkbook( openDlg.GetPath() ) )
817  DisplayError( this, _( "There was an error while opening the workbook file" ) );
818 }
819 
820 
821 void SIM_PLOT_FRAME::menuSaveWorkbook( wxCommandEvent& event )
822 {
823  if( !CurrentPlot() )
824  return;
825 
826  wxFileDialog saveDlg( this, _( "Save Simulation Workbook" ), m_savedWorkbooksPath, "",
827  WorkbookFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
828 
829  if( saveDlg.ShowModal() == wxID_CANCEL )
830  return;
831 
832  m_savedWorkbooksPath = saveDlg.GetDirectory();
833 
834  if( !saveWorkbook( saveDlg.GetPath() ) )
835  DisplayError( this, _( "There was an error while saving the workbook file" ) );
836 }
837 
838 
839 void SIM_PLOT_FRAME::menuSaveImage( wxCommandEvent& event )
840 {
841  if( !CurrentPlot() )
842  return;
843 
844  wxFileDialog saveDlg( this, _( "Save Plot as Image" ), "", "",
845  PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
846 
847  if( saveDlg.ShowModal() == wxID_CANCEL )
848  return;
849 
850  CurrentPlot()->SaveScreenshot( saveDlg.GetPath(), wxBITMAP_TYPE_PNG );
851 }
852 
853 
854 void SIM_PLOT_FRAME::menuSaveCsv( wxCommandEvent& event )
855 {
856  if( !CurrentPlot() )
857  return;
858 
859  const wxChar SEPARATOR = ';';
860 
861  wxFileDialog saveDlg( this, _( "Save Plot Data" ), "", "",
862  CsvFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
863 
864  if( saveDlg.ShowModal() == wxID_CANCEL )
865  return;
866 
867  wxFile out( saveDlg.GetPath(), wxFile::write );
868  bool timeWritten = false;
869 
870  for( const auto& t : CurrentPlot()->GetTraces() )
871  {
872  const TRACE* trace = t.second;
873 
874  if( !timeWritten )
875  {
876  out.Write( wxString::Format( "Time%c", SEPARATOR ) );
877 
878  for( double v : trace->GetDataX() )
879  out.Write( wxString::Format( "%f%c", v, SEPARATOR ) );
880 
881  out.Write( "\r\n" );
882  timeWritten = true;
883  }
884 
885  out.Write( wxString::Format( "%s%c", t.first, SEPARATOR ) );
886 
887  for( double v : trace->GetDataY() )
888  out.Write( wxString::Format( "%f%c", v, SEPARATOR ) );
889 
890  out.Write( "\r\n" );
891  }
892 
893  out.Close();
894 }
895 
896 
897 void SIM_PLOT_FRAME::menuZoomIn( wxCommandEvent& event )
898 {
899  if( CurrentPlot() )
900  CurrentPlot()->ZoomIn();
901 }
902 
903 
904 void SIM_PLOT_FRAME::menuZoomOut( wxCommandEvent& event )
905 {
906  if( CurrentPlot() )
907  CurrentPlot()->ZoomOut();
908 }
909 
910 
911 void SIM_PLOT_FRAME::menuZoomFit( wxCommandEvent& event )
912 {
913  if( CurrentPlot() )
914  CurrentPlot()->Fit();
915 }
916 
917 
918 void SIM_PLOT_FRAME::menuShowGrid( wxCommandEvent& event )
919 {
920  SIM_PLOT_PANEL* plot = CurrentPlot();
921 
922  if( plot )
923  plot->ShowGrid( !plot->IsGridShown() );
924 }
925 
926 
927 void SIM_PLOT_FRAME::menuShowGridUpdate( wxUpdateUIEvent& event )
928 {
929  SIM_PLOT_PANEL* plot = CurrentPlot();
930 
931  event.Check( plot ? plot->IsGridShown() : false );
932 }
933 
934 
935 void SIM_PLOT_FRAME::menuShowLegend( wxCommandEvent& event )
936 {
937  SIM_PLOT_PANEL* plot = CurrentPlot();
938 
939  if( plot )
940  plot->ShowLegend( !plot->IsLegendShown() );
941 }
942 
943 
944 void SIM_PLOT_FRAME::menuShowLegendUpdate( wxUpdateUIEvent& event )
945 {
946  SIM_PLOT_PANEL* plot = CurrentPlot();
947  event.Check( plot ? plot->IsLegendShown() : false );
948 }
949 
950 
951 void SIM_PLOT_FRAME::onPlotClose( wxAuiNotebookEvent& event )
952 {
953  int idx = event.GetSelection();
954 
955  if( idx == wxNOT_FOUND )
956  return;
957 
958  SIM_PLOT_PANEL* plotPanel = dynamic_cast<SIM_PLOT_PANEL*>( m_plotNotebook->GetPage( idx ) );
959 
960  if( !plotPanel )
961  return;
962 
963  m_plots.erase( plotPanel );
965  updateCursors();
966 }
967 
968 
969 void SIM_PLOT_FRAME::onPlotChanged( wxAuiNotebookEvent& event )
970 {
972  updateCursors();
973 }
974 
975 
976 void SIM_PLOT_FRAME::onSignalDblClick( wxMouseEvent& event )
977 {
978  // Remove signal from the plot panel when double clicked
979  long idx = m_signals->GetFocusedItem();
980 
981  if( idx != wxNOT_FOUND )
982  removePlot( m_signals->GetItemText( idx, 0 ) );
983 }
984 
985 
986 void SIM_PLOT_FRAME::onSignalRClick( wxListEvent& event )
987 {
988  int idx = event.GetIndex();
989 
990  if( idx != wxNOT_FOUND )
991  m_signals->Select( idx );
992 
993  idx = m_signals->GetFirstSelected();
994 
995  if( idx != wxNOT_FOUND )
996  {
997  const wxString& netName = m_signals->GetItemText( idx, 0 );
998  SIGNAL_CONTEXT_MENU ctxMenu( netName, this );
999  m_signals->PopupMenu( &ctxMenu );
1000  }
1001 }
1002 
1003 
1004 void SIM_PLOT_FRAME::onSimulate( wxCommandEvent& event )
1005 {
1006  if( IsSimulationRunning() )
1007  StopSimulation();
1008  else
1009  StartSimulation();
1010 }
1011 
1012 
1013 void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event )
1014 {
1015  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
1016 
1017  // Initial processing is required to e.g. display a list of power sources
1019 
1020  if( !m_exporter->ProcessNetlist( NET_ALL_FLAGS ) )
1021  {
1022  DisplayError( this, _( "There were errors during netlist export, aborted." ) );
1023  return;
1024  }
1025 
1026  if( !m_settingsDlg )
1027  m_settingsDlg = new DIALOG_SIM_SETTINGS( this );
1028 
1029  if( plotPanel )
1030  m_settingsDlg->SetSimCommand( m_plots[plotPanel].m_simCommand );
1031 
1033 
1034  if( m_settingsDlg->ShowModal() == wxID_OK )
1035  {
1036  wxString newCommand = m_settingsDlg->GetSimCommand();
1037  SIM_TYPE newSimType = NETLIST_EXPORTER_PSPICE_SIM::CommandToSimType( newCommand );
1038 
1039  // If it is a new simulation type, open a new plot
1040  if( !plotPanel || ( plotPanel && plotPanel->GetType() != newSimType ) )
1041  {
1042  plotPanel = NewPlotPanel( newSimType );
1043  }
1044 
1045  m_plots[plotPanel].m_simCommand = newCommand;
1046  }
1047 }
1048 
1049 
1050 void SIM_PLOT_FRAME::onAddSignal( wxCommandEvent& event )
1051 {
1052  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
1053 
1054  if( !plotPanel || !m_exporter || plotPanel->GetType() != m_exporter->GetSimType() )
1055  {
1056  DisplayInfoMessage( this, _( "You need to run simulation first." ) );
1057  return;
1058  }
1059 
1060  DIALOG_SIGNAL_LIST dialog( this, m_exporter.get() );
1061  dialog.ShowModal();
1062 }
1063 
1064 
1065 void SIM_PLOT_FRAME::onProbe( wxCommandEvent& event )
1066 {
1067  if( m_schematicFrame == NULL )
1068  return;
1069 
1070  wxQueueEvent( m_schematicFrame, new wxCommandEvent( wxEVT_TOOL, ID_SIM_PROBE ) );
1071  m_schematicFrame->Raise();
1072 }
1073 
1074 
1075 void SIM_PLOT_FRAME::onTune( wxCommandEvent& event )
1076 {
1077  if( m_schematicFrame == NULL )
1078  return;
1079 
1080  wxQueueEvent( m_schematicFrame, new wxCommandEvent( wxEVT_TOOL, ID_SIM_TUNE ) );
1081  m_schematicFrame->Raise();
1082 }
1083 
1084 void SIM_PLOT_FRAME::onShowNetlist( wxCommandEvent& event )
1085 {
1086  class NETLIST_VIEW_DIALOG : public wxDialog
1087  {
1088  public:
1089  enum
1090  {
1091  MARGIN_LINE_NUMBERS
1092  };
1093 
1094  void onClose( wxCloseEvent& evt )
1095  {
1096  EndModal( GetReturnCode() );
1097  }
1098 
1099  NETLIST_VIEW_DIALOG(wxWindow* parent, wxString source) :
1100  wxDialog(parent, wxID_ANY, "SPICE Netlist",
1101  wxDefaultPosition, wxSize(1500,900),
1102  wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
1103  {
1104  wxStyledTextCtrl* text = new wxStyledTextCtrl( this, wxID_ANY );
1105 
1106  text->SetMarginWidth( MARGIN_LINE_NUMBERS, 50 );
1107  text->StyleSetForeground( wxSTC_STYLE_LINENUMBER, wxColour( 75, 75, 75 ) );
1108  text->StyleSetBackground( wxSTC_STYLE_LINENUMBER, wxColour( 220, 220, 220 ) );
1109  text->SetMarginType( MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER );
1110 
1111  text->SetWrapMode( wxSTC_WRAP_WORD );
1112 
1113  text->SetText( source );
1114 
1115  text->StyleClearAll();
1116  text->SetLexer( wxSTC_LEX_SPICE );
1117 
1118  wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
1119  sizer->Add( text, 1, wxEXPAND );
1120  SetSizer( sizer );
1121 
1122  Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( NETLIST_VIEW_DIALOG::onClose ), NULL,
1123  this );
1124  }
1125  };
1126 
1127  if( m_schematicFrame == NULL || m_simulator == NULL )
1128  return;
1129 
1130  NETLIST_VIEW_DIALOG dlg( this, m_simulator->GetNetlist() );
1131  dlg.ShowModal();
1132 }
1133 
1134 
1135 void SIM_PLOT_FRAME::onClose( wxCloseEvent& aEvent )
1136 {
1137  SaveSettings( config() );
1138 
1139  if( IsSimulationRunning() )
1140  m_simulator->Stop();
1141 
1142  Destroy();
1143 }
1144 
1145 
1146 void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& event )
1147 {
1148  wxSize size = m_cursors->GetClientSize();
1149  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
1150  m_cursors->ClearAll();
1151 
1152  if( !plotPanel )
1153  return;
1154 
1156  m_cursors->SetImageList(m_signalsIconColorList, wxIMAGE_LIST_SMALL);
1157 
1158  // Fill the signals listctrl
1159  m_cursors->AppendColumn( _( "Signal" ), wxLIST_FORMAT_LEFT, size.x / 2 );
1160  const long X_COL = m_cursors->AppendColumn( plotPanel->GetLabelX(), wxLIST_FORMAT_LEFT, size.x / 4 );
1161 
1162  wxString labelY1 = plotPanel->GetLabelY1();
1163  wxString labelY2 = plotPanel->GetLabelY2();
1164  wxString labelY;
1165 
1166  if( !labelY2.IsEmpty() )
1167  labelY = labelY1 + " / " + labelY2;
1168  else
1169  labelY = labelY1;
1170 
1171  const long Y_COL = m_cursors->AppendColumn( labelY, wxLIST_FORMAT_LEFT, size.x / 4 );
1172 
1173  // Update cursor values
1174  int itemidx = 0;
1175  for( const auto& trace : plotPanel->GetTraces() )
1176  {
1177  if( CURSOR* cursor = trace.second->GetCursor() )
1178  {
1179  // Find the right icon color in list.
1180  // It is the icon used in m_signals list for the same trace
1181  long iconColor = m_signals->FindItem( -1, trace.first );
1182 
1183  const wxRealPoint coords = cursor->GetCoords();
1184  long idx = m_cursors->InsertItem( itemidx++, trace.first, iconColor );
1185  m_cursors->SetItem( idx, X_COL, SPICE_VALUE( coords.x ).ToSpiceString() );
1186  m_cursors->SetItem( idx, Y_COL, SPICE_VALUE( coords.y ).ToSpiceString() );
1187  }
1188  }
1189 }
1190 
1191 
1192 void SIM_PLOT_FRAME::onSimStarted( wxCommandEvent& aEvent )
1193 {
1194  m_toolBar->SetToolNormalBitmap( ID_SIM_RUN, KiBitmap( sim_stop_xpm ) );
1195  SetCursor( wxCURSOR_ARROWWAIT );
1196 }
1197 
1198 
1199 void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent )
1200 {
1201  m_toolBar->SetToolNormalBitmap( ID_SIM_RUN, KiBitmap( sim_run_xpm ) );
1202  SetCursor( wxCURSOR_ARROW );
1203 
1204  SIM_TYPE simType = m_exporter->GetSimType();
1205 
1206  if( simType == ST_UNKNOWN )
1207  return;
1208 
1209  SIM_PLOT_PANEL* plotPanel = CurrentPlot();
1210 
1211  if( !plotPanel || plotPanel->GetType() != simType )
1212  plotPanel = NewPlotPanel( simType );
1213 
1214  if( IsSimulationRunning() )
1215  return;
1216 
1217  // If there are any signals plotted, update them
1218  if( SIM_PLOT_PANEL::IsPlottable( simType ) )
1219  {
1220  TRACE_MAP& traceMap = m_plots[plotPanel].m_traces;
1221 
1222  for( auto it = traceMap.begin(); it != traceMap.end(); /* iteration occurs in the loop */)
1223  {
1224  if( !updatePlot( it->second, plotPanel ) )
1225  {
1226  removePlot( it->first, false );
1227  it = traceMap.erase( it ); // remove a plot that does not exist anymore
1228  }
1229  else
1230  {
1231  ++it;
1232  }
1233  }
1234 
1235  updateSignalList();
1236  plotPanel->UpdateAll();
1237  plotPanel->ResetScales();
1238  }
1239  else
1240  {
1242  for( const auto& net : m_exporter->GetNetIndexMap() )
1243  {
1244  int node = net.second;
1245 
1246  if( node > 0 )
1247  m_simulator->Command( wxString::Format( "print v(%d)", node ).ToStdString() );
1248  }
1249  }
1250 }
1251 
1252 
1253 void SIM_PLOT_FRAME::onSimUpdate( wxCommandEvent& aEvent )
1254 {
1255  if( IsSimulationRunning() )
1256  StopSimulation();
1257 
1258  if( CurrentPlot() != m_lastSimPlot )
1259  {
1260  // We need to rerun simulation, as the simulator currently stores
1261  // results for another plot
1262  StartSimulation();
1263  }
1264  else
1265  {
1266  // Incremental update
1267  m_simConsole->Clear();
1268  // Do not export netlist, it is already stored in the simulator
1269  applyTuners();
1270  m_simulator->Run();
1271  }
1272 }
1273 
1274 
1275 void SIM_PLOT_FRAME::onSimReport( wxCommandEvent& aEvent )
1276 {
1277  m_simConsole->AppendText( aEvent.GetString() + "\n" );
1278  m_simConsole->SetInsertionPointEnd();
1279 }
1280 
1281 
1283  SIM_PLOT_FRAME* aPlotFrame )
1284  : m_signal( aSignal ), m_plotFrame( aPlotFrame )
1285 {
1287 
1288  AddMenuItem( this, HIDE_SIGNAL, _( "Hide Signal" ),
1289  _( "Erase the signal from plot screen" ),
1290  KiBitmap( delete_xpm ) );
1291 
1292  TRACE* trace = plot->GetTrace( m_signal );
1293 
1294  if( trace->HasCursor() )
1295  AddMenuItem( this, HIDE_CURSOR, _( "Hide Cursor" ),
1296  wxEmptyString, KiBitmap( pcb_target_xpm ) );
1297  else
1298  AddMenuItem( this, SHOW_CURSOR, _( "Show Cursor" ),
1299  wxEmptyString, KiBitmap( pcb_target_xpm ) );
1300 
1301  Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( SIGNAL_CONTEXT_MENU::onMenuEvent ), NULL, this );
1302 }
1303 
1304 
1306 {
1308 
1309  switch( aEvent.GetId() )
1310  {
1311  case HIDE_SIGNAL:
1313  break;
1314 
1315  case SHOW_CURSOR:
1316  plot->EnableCursor( m_signal, true );
1317  break;
1318 
1319  case HIDE_CURSOR:
1320  plot->EnableCursor( m_signal, false );
1321  break;
1322  }
1323 }
1324 
1325 wxDEFINE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
1326 wxDEFINE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
1327 
1328 wxDEFINE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
1329 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
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)
Create 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
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.
This file is part of the common library.
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:174
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. ...
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...
void AddCurrentPlot(const wxString &aDeviceName, const wxString &aParam)
Adds a current plot for a particular device.
Trace descriptor class
Schematic editor (Eeschema) main window.
wxString CsvFileWildcard()
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
std::shared_ptr< SPICE_SIMULATOR > m_simulator
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:78
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
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.
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:300
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:128
virtual void LoadSettings(wxConfigBase *aCfg)
Function LoadSettings loads common frame parameters from a configuration file.
void onSimFinished(wxCommandEvent &aEvent)
Interface to receive simulation updates from SPICE_SIMULATOR class.
bool AddTrace(const wxString &aName, int aPoints, const double *aX, const double *aY, SIM_PLOT_TYPE aFlags)
The common library.
void onShowNetlist(wxCommandEvent &event)
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:258
wxToolBarToolBase * m_toolAddSignals
Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder.
int m_splitterTuneValuesSashPosition
static std::shared_ptr< SPICE_SIMULATOR > CreateInstance(const std::string &aName)
Creates a simulator instance of particular type (currently only ngspice is handled) ...
TRACE_DESC(const NETLIST_EXPORTER_PSPICE_SIM &aExporter, const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam)
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()
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
wxString PngFileWildcard()
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
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
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)
const char * name
Definition: DXF_plotter.cpp:61
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
size_t i
Definition: json11.cpp:597
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:100
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)
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
int m_splitterLeftRightSashPosition
const std::vector< double > & GetDataX() const
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.
wxString WorkbookFileWildcard()
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
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
void menuSaveWorkbook(wxCommandEvent &event) override
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:216
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:185
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.
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.