2016-08-11 12:41:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2016-08-11 12:41:43 +00:00
|
|
|
* as published by the Free Software Foundation; either version 3
|
2016-08-11 12:41:07 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
2016-08-11 12:41:43 +00:00
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
2016-08-11 12:41:07 +00:00
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2016-08-11 12:41:01 +00:00
|
|
|
#ifndef __sim_plot_frame__
|
|
|
|
#define __sim_plot_frame__
|
|
|
|
|
|
|
|
/**
|
2016-08-11 12:41:19 +00:00
|
|
|
@file Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder. */
|
2016-08-11 12:41:01 +00:00
|
|
|
|
|
|
|
#include "sim_plot_frame_base.h"
|
2016-08-11 12:41:35 +00:00
|
|
|
#include "sim_types.h"
|
2016-08-11 12:41:41 +00:00
|
|
|
|
|
|
|
#include <kiway_player.h>
|
2016-08-11 12:41:29 +00:00
|
|
|
#include <dialogs/dialog_sim_settings.h>
|
2016-08-11 12:41:19 +00:00
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
#include <wx/event.h>
|
2016-08-11 12:41:45 +00:00
|
|
|
|
|
|
|
#include <list>
|
2016-08-11 12:41:41 +00:00
|
|
|
#include <memory>
|
2016-08-11 12:41:45 +00:00
|
|
|
#include <map>
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2016-08-11 12:41:41 +00:00
|
|
|
class SCH_EDIT_FRAME;
|
2016-08-11 12:41:45 +00:00
|
|
|
class SCH_COMPONENT;
|
|
|
|
|
2016-08-11 12:41:01 +00:00
|
|
|
class SPICE_SIMULATOR;
|
2016-08-11 12:41:29 +00:00
|
|
|
class NETLIST_EXPORTER_PSPICE_SIM;
|
2016-08-11 12:41:01 +00:00
|
|
|
class SIM_PLOT_PANEL;
|
2016-08-11 12:41:45 +00:00
|
|
|
class TUNER_SLIDER;
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
/// @todo description
|
|
|
|
class TRACE_DESC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TRACE_DESC( const NETLIST_EXPORTER_PSPICE_SIM& aExporter, const wxString& aName,
|
|
|
|
SIM_PLOT_TYPE aType, const wxString& aParam );
|
|
|
|
|
|
|
|
///> Modifies an existing TRACE_DESC simulation type
|
|
|
|
TRACE_DESC( const NETLIST_EXPORTER_PSPICE_SIM& aExporter,
|
|
|
|
const TRACE_DESC& aDescription, SIM_PLOT_TYPE aNewType )
|
|
|
|
: TRACE_DESC( aExporter, aDescription.GetName(), aNewType, aDescription.GetParam() )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const wxString& GetTitle() const
|
|
|
|
{
|
|
|
|
return m_title;
|
|
|
|
}
|
|
|
|
|
|
|
|
const wxString& GetName() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const wxString& GetParam() const
|
|
|
|
{
|
|
|
|
return m_param;
|
|
|
|
}
|
|
|
|
|
|
|
|
SIM_PLOT_TYPE GetType() const
|
|
|
|
{
|
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
const wxString& GetSpiceVector() const
|
|
|
|
{
|
|
|
|
return m_spiceVector;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Three basic parameters
|
|
|
|
///> Name of the measured net/device
|
|
|
|
wxString m_name;
|
|
|
|
|
|
|
|
///> Type of the signal
|
|
|
|
SIM_PLOT_TYPE m_type;
|
|
|
|
|
|
|
|
///> Name of the signal parameter
|
|
|
|
wxString m_param;
|
|
|
|
|
|
|
|
// Generated data
|
|
|
|
///> Title displayed in the signal list/plot legend
|
|
|
|
wxString m_title;
|
|
|
|
|
|
|
|
///> Spice vector name
|
|
|
|
wxString m_spiceVector;
|
|
|
|
};
|
|
|
|
|
2016-08-11 12:41:01 +00:00
|
|
|
/** Implementing SIM_PLOT_FRAME_BASE */
|
|
|
|
class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
|
|
|
|
{
|
2016-08-11 12:41:07 +00:00
|
|
|
public:
|
|
|
|
/** Constructor */
|
|
|
|
SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent );
|
|
|
|
~SIM_PLOT_FRAME();
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
void StartSimulation();
|
2016-08-11 12:41:07 +00:00
|
|
|
void StopSimulation();
|
2016-08-11 12:41:45 +00:00
|
|
|
bool IsSimulationRunning();
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2016-08-11 12:41:42 +00:00
|
|
|
/**
|
|
|
|
* @brief Creates a new plot panel for a given simulation type and adds it to the main
|
|
|
|
* notebook.
|
|
|
|
* @param aSimType is requested simulation type.
|
|
|
|
* @return The new plot panel.
|
|
|
|
*/
|
|
|
|
SIM_PLOT_PANEL* NewPlotPanel( SIM_TYPE aSimType );
|
|
|
|
|
2016-08-11 12:41:11 +00:00
|
|
|
void AddVoltagePlot( const wxString& aNetName );
|
2016-08-11 12:41:52 +00:00
|
|
|
void AddCurrentPlot( const wxString& aDeviceName, const wxString& aParam );
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2016-08-11 12:41:45 +00:00
|
|
|
void AddTuner( SCH_COMPONENT* aComponent );
|
|
|
|
void RemoveTuner( TUNER_SLIDER* aTuner );
|
|
|
|
|
2016-08-11 12:41:25 +00:00
|
|
|
SIM_PLOT_PANEL* CurrentPlot() const;
|
2016-08-11 12:41:21 +00:00
|
|
|
|
2016-08-11 12:41:25 +00:00
|
|
|
private:
|
2016-08-11 12:41:52 +00:00
|
|
|
void addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam );
|
|
|
|
|
2016-08-11 12:41:30 +00:00
|
|
|
void updateNetlistExporter();
|
|
|
|
|
2016-08-11 12:41:18 +00:00
|
|
|
/**
|
|
|
|
* @brief Updates plot in a particular SIM_PLOT_PANEL. If the panel does not contain
|
|
|
|
* the plot, it will be added.
|
2016-08-11 12:41:52 +00:00
|
|
|
* @param aName is the net/device name.
|
|
|
|
* @param aType is the plot type (@see SIM_PLOT_TYPES).
|
2016-08-11 12:41:18 +00:00
|
|
|
* @param aPanel is the panel that should receive the update.
|
2016-08-11 12:41:41 +00:00
|
|
|
* @return True if a plot was successfully added/updated.
|
2016-08-11 12:41:52 +00:00
|
|
|
* TODO update description
|
2016-08-11 12:41:41 +00:00
|
|
|
*/
|
2016-08-11 12:41:52 +00:00
|
|
|
bool updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL* aPanel );
|
2016-08-11 12:41:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Updates the list of currently plotted signals.
|
2016-08-11 12:41:18 +00:00
|
|
|
*/
|
2016-08-11 12:41:42 +00:00
|
|
|
void updateSignalList();
|
2016-08-11 12:41:18 +00:00
|
|
|
|
2016-08-11 12:41:45 +00:00
|
|
|
/**
|
|
|
|
* @brief Fills the tuners area with the ones related to the current plot.
|
|
|
|
*/
|
|
|
|
void updateTuners();
|
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
SIM_PLOT_TYPE GetXAxisType( SIM_TYPE aType ) const;
|
2016-08-11 12:41:18 +00:00
|
|
|
|
2016-08-11 12:41:22 +00:00
|
|
|
// Menu handlers
|
2016-08-11 12:41:35 +00:00
|
|
|
void menuNewPlot( wxCommandEvent& aEvent ) override;
|
2016-08-11 12:41:16 +00:00
|
|
|
|
2016-08-11 12:41:22 +00:00
|
|
|
void menuExit( wxCommandEvent& event ) override
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:28 +00:00
|
|
|
void menuSaveImage( wxCommandEvent& event ) override;
|
|
|
|
void menuSaveCsv( wxCommandEvent& event ) override;
|
2016-08-11 12:41:22 +00:00
|
|
|
void menuZoomIn( wxCommandEvent& event ) override;
|
|
|
|
void menuZoomOut( wxCommandEvent& event ) override;
|
|
|
|
void menuZoomFit( wxCommandEvent& event ) override;
|
|
|
|
void menuShowGrid( wxCommandEvent& event ) override;
|
2016-08-11 12:41:27 +00:00
|
|
|
void menuShowGridUpdate( wxUpdateUIEvent& event ) override;
|
|
|
|
void menuShowLegend( wxCommandEvent& event ) override;
|
|
|
|
void menuShowLegendUpdate( wxUpdateUIEvent& event ) override;
|
|
|
|
void menuShowCoords( wxCommandEvent& event ) override;
|
|
|
|
void menuShowCoordsUpdate( wxUpdateUIEvent& event ) override;
|
2016-08-11 12:41:22 +00:00
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
// Event handlers
|
2016-08-11 12:41:27 +00:00
|
|
|
void onPlotChanged( wxNotebookEvent& event ) override;
|
|
|
|
|
2016-08-11 12:41:16 +00:00
|
|
|
void onSignalDblClick( wxCommandEvent& event ) override;
|
2016-08-11 12:41:25 +00:00
|
|
|
void onSignalRClick( wxMouseEvent& event ) override;
|
2016-08-11 12:41:26 +00:00
|
|
|
|
2016-08-11 12:41:16 +00:00
|
|
|
void onSimulate( wxCommandEvent& event ) override;
|
2016-08-11 12:41:29 +00:00
|
|
|
void onSettings( wxCommandEvent& event ) override;
|
2016-08-11 12:41:42 +00:00
|
|
|
void onAddSignal( wxCommandEvent& event ) override;
|
|
|
|
void onProbe( wxCommandEvent& event ) override;
|
2016-08-11 12:41:45 +00:00
|
|
|
void onTune( wxCommandEvent& event ) override;
|
2016-08-11 12:41:16 +00:00
|
|
|
|
|
|
|
void onClose( wxCloseEvent& aEvent );
|
2016-08-11 12:41:19 +00:00
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
void onCursorUpdate( wxCommandEvent& aEvent );
|
2016-08-11 12:41:45 +00:00
|
|
|
void onSimUpdate( wxCommandEvent& aEvent );
|
|
|
|
void onSimReport( wxCommandEvent& aEvent );
|
2016-08-11 12:41:19 +00:00
|
|
|
void onSimStarted( wxCommandEvent& aEvent );
|
|
|
|
void onSimFinished( wxCommandEvent& aEvent );
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
SCH_EDIT_FRAME* m_schematicFrame;
|
2016-08-11 12:41:29 +00:00
|
|
|
std::unique_ptr<NETLIST_EXPORTER_PSPICE_SIM> m_exporter;
|
|
|
|
std::unique_ptr<SPICE_SIMULATOR> m_simulator;
|
2016-08-11 12:41:52 +00:00
|
|
|
|
|
|
|
typedef std::map<wxString, TRACE_DESC> TRACE_MAP;
|
|
|
|
typedef std::list<TUNER_SLIDER*> TUNER_LIST;
|
|
|
|
|
|
|
|
struct PLOT_INFO
|
|
|
|
{
|
|
|
|
TUNER_LIST m_tuners;
|
|
|
|
TRACE_MAP m_traces;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map<SIM_PLOT_PANEL*, PLOT_INFO> m_plots;
|
2016-08-11 12:41:29 +00:00
|
|
|
|
|
|
|
// Trick to preserve settings between runs
|
|
|
|
DIALOG_SIM_SETTINGS m_settingsDlg;
|
2016-08-11 12:41:25 +00:00
|
|
|
|
|
|
|
// Right click context menu for signals in the listbox
|
|
|
|
class SIGNAL_CONTEXT_MENU : public wxMenu
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SIGNAL_CONTEXT_MENU( const wxString& aSignal, SIM_PLOT_FRAME* aPlotFrame );
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onMenuEvent( wxMenuEvent& aEvent );
|
|
|
|
|
|
|
|
const wxString& m_signal;
|
|
|
|
SIM_PLOT_FRAME* m_plotFrame;
|
|
|
|
|
|
|
|
enum SIGNAL_CONTEXT_MENU_EVENTS
|
|
|
|
{
|
|
|
|
HIDE_SIGNAL,
|
|
|
|
SHOW_CURSOR,
|
|
|
|
HIDE_CURSOR
|
|
|
|
};
|
|
|
|
};
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2016-08-11 12:41:01 +00:00
|
|
|
};
|
|
|
|
|
2016-08-11 12:41:45 +00:00
|
|
|
// Commands
|
|
|
|
wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
|
2016-08-11 12:41:27 +00:00
|
|
|
wxDECLARE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
|
2016-08-11 12:41:45 +00:00
|
|
|
|
|
|
|
// Notifications
|
2016-08-11 12:41:27 +00:00
|
|
|
wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
|
|
|
|
wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2016-08-11 12:41:01 +00:00
|
|
|
#endif // __sim_plot_frame__
|