27#include <wx/filedlg.h>
29#include <wx/stc/stc.h>
45#include <wx/clipbrd.h>
46#include <wx/dataobj.h>
47#include <wx/mstream.h>
81 _(
"Errors during netlist generation.\n\n" ) + errors );
87 if( dlg.ShowModal() == wxID_OK )
103 if( openDlg.ShowModal() == wxID_CANCEL )
113 wxFileName filename =
m_simulator->Settings()->GetWorkbookFilename();
115 if( filename.GetName().IsEmpty() )
119 filename.SetName(
_(
"noname" ) );
129 return filename.GetFullName();
139 return path.GetPath();
148 filename =
m_simulator->Settings()->GetWorkbookFilename();
150 if( filename.IsEmpty() )
155 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
157 if( saveAsDlg.ShowModal() == wxID_CANCEL )
160 filename = saveAsDlg.GetPath();
175 if( saveDlg.ShowModal() == wxID_CANCEL )
179 plotTab->GetPlotWin()->SaveScreenshot( screenImage );
180 screenImage.SaveFile( saveDlg.GetPath(), wxBITMAP_TYPE_PNG );
192 plotTab->GetPlotWin()->SaveScreenshot( screenImage );
194 if( wxTheClipboard->Open() )
196 wxBitmap bm( screenImage );
198 wxTheClipboard->SetData(
new wxBitmapDataObject( bm ) );
199 wxTheClipboard->Flush();
200 wxTheClipboard->Close();
217 if( blocking_dialog )
218 blocking_dialog->Close(
true );
221 plotTab->GetPlotWin()->SaveScreenshot( screenImage );
223 if( wxTheClipboard->Open() )
226 wxMemoryOutputStream stream;
227 screenImage.SaveFile( stream, wxBITMAP_TYPE_PNG );
232 string <<
"(image (at 0 0)\n";
233 string <<
" (data\n";
236 buff.GetWriteBuf( stream.GetLength() );
237 stream.CopyTo( buff.GetData(), stream.GetLength() );
238 buff.SetDataLen( stream.GetLength() );
241 out << wxBase64Encode( buff );
243 #define MIME_BASE64_LENGTH 76
246 while( first < out.Length() )
254 wxTheClipboard->SetData(
new wxTextDataObject(
string ) );
255 wxTheClipboard->Close();
280 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
282 if( saveDlg.ShowModal() == wxID_CANCEL )
285 wxFFile out( saveDlg.GetPath(),
"wb" );
287 std::map<wxString, TRACE*> traces = plotTab->GetTraces();
289 if( traces.size() == 0 )
292 SIM_TYPE simType = plotTab->GetSimType();
294 std::size_t rowCount = traces.begin()->second->GetDataX().size();
297 wxString xAxisName(
m_simulator->GetXAxis( simType ) );
298 out.Write( wxString::Format( wxT(
"%s%c" ), xAxisName,
SEPARATOR ) );
300 for(
const auto& [
name, trace] : traces )
301 out.Write( wxString::Format( wxT(
"%s%c" ),
name,
SEPARATOR ) );
303 out.Write( wxS(
"\r\n" ) );
306 for ( std::size_t curRow=0; curRow < rowCount; curRow++ )
308 double xAxisValue = traces.begin()->second->GetDataX().at( curRow );
309 out.Write( wxString::Format( wxT(
"%g%c" ), xAxisValue,
SEPARATOR ) );
311 for(
const auto& [
name, trace] : traces )
313 double yAxisValue = trace->GetDataY().at( curRow );
314 out.Write( wxString::Format( wxT(
"%g%c" ), yAxisValue,
SEPARATOR ) );
317 out.Write( wxS(
"\r\n" ) );
366 wxCommandEvent
dummy;
378 plotTab->GetPlotWin()->ZoomUndo();
387 plotTab->GetPlotWin()->ZoomRedo();
397 plotTab->ShowGrid( !plotTab->IsGridShown() );
409 plotTab->ShowLegend( !plotTab->IsLegendShown() );
421 plotTab->SetDottedSecondary( !plotTab->GetDottedSecondary() );
470 if( blocking_dialog )
471 blocking_dialog->Close(
true );
487 if( blocking_dialog )
488 blocking_dialog->Close(
true );
507 wxPostEvent(
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL ) );
511 DIALOG_SHIM( parent, wxID_ANY,
_(
"SPICE Netlist" ), wxDefaultPosition,
512 wxSize( 800, 800 ), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
516 m_splitter =
new wxSplitterWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
517 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
520 m_splitter->SetExtraStyle( wxWS_EX_TRANSIENT );
525 m_textCtrl->StyleSetForeground( wxSTC_STYLE_LINENUMBER, wxColour( 75, 75, 75 ) );
526 m_textCtrl->StyleSetBackground( wxSTC_STYLE_LINENUMBER, wxColour( 220, 220, 220 ) );
531 for(
int i = 0; i < wxSTC_STYLE_MAX; ++i )
550 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
551 sizer->Add(
m_splitter, 1, wxEXPAND | wxALL, 5 );
static TOOL_ACTION toggleGrid
static TOOL_ACTION zoomOutCenter
static TOOL_ACTION zoomRedo
static TOOL_ACTION zoomOutHorizontally
static TOOL_ACTION zoomOutVertically
static TOOL_ACTION zoomInHorizontally
static TOOL_ACTION zoomFitScreen
static TOOL_ACTION zoomInCenter
static TOOL_ACTION zoomInVertically
static TOOL_ACTION zoomUndo
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void SetSimCommand(const wxString &aCommand)
void ApplySettings(SIM_TAB *aTab)
void SetSimOptions(int aOptions)
const wxString & GetSimCommand() const
static TOOL_ACTION simAnalysisProperties
static TOOL_ACTION editUserDefinedSignals
static TOOL_ACTION openWorkbook
static TOOL_ACTION stopSimulation
static TOOL_ACTION toggleLegend
static TOOL_ACTION saveWorkbook
static TOOL_ACTION saveWorkbookAs
static TOOL_ACTION exportPlotAsCSV
static TOOL_ACTION simTune
static TOOL_ACTION toggleDarkModePlots
static TOOL_ACTION exportPlotAsPNG
static TOOL_ACTION showNetlist
static TOOL_ACTION simProbe
static TOOL_ACTION toggleDottedSecondary
static TOOL_ACTION exportPlotToSchematic
static TOOL_ACTION runSimulation
static TOOL_ACTION newAnalysisTab
static TOOL_ACTION exportPlotToClipboard
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
WX_HTML_REPORT_BOX * m_reporter
void SetNetlist(const wxString &aSource)
std::unique_ptr< SCINTILLA_TRICKS > m_scintillaTricks
void onClose(wxCloseEvent &evt)
wxStyledTextCtrl * m_textCtrl
NETLIST_VIEW_DIALOG(wxWindow *parent)
wxSplitterWindow * m_splitter
virtual const wxString GetProjectPath() const
Return the full path of the project.
virtual const wxString GetProjectName() const
Return the short name of the project.
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
A pure virtual class used to derive REPORTER objects from.
int ExportPlotAsPNG(const TOOL_EVENT &aEvent)
wxString getDefaultPath()
Return the default path to be used in file browser dialog.
SCH_EDIT_FRAME * m_schematicFrame
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int ToggleLegend(const TOOL_EVENT &aEvent)
int RedoZoom(const TOOL_EVENT &aEvent)
int ShowNetlist(const TOOL_EVENT &aEvent)
int ExportPlotToClipboard(const TOOL_EVENT &aEvent)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int ToggleDarkModePlots(const TOOL_EVENT &aEvent)
int Tune(const TOOL_EVENT &aEvent)
wxString getDefaultFilename()
Return the default filename (with extension) to be used in file browser dialog.
SIMULATOR_FRAME * m_simulatorFrame
bool Init() override
Init() is called once upon a registration of the tool.
int SaveWorkbook(const TOOL_EVENT &aEvent)
int RunSimulation(const TOOL_EVENT &aEvent)
SIM_TAB * getCurrentSimTab()
Set up handlers for various events.
int OpenWorkbook(const TOOL_EVENT &aEvent)
int EditUserDefinedSignals(const TOOL_EVENT &aEvent)
std::shared_ptr< SPICE_CIRCUIT_MODEL > m_circuitModel
int ToggleGrid(const TOOL_EVENT &aEvent)
int Zoom(const TOOL_EVENT &aEvent)
int EditAnalysisTab(const TOOL_EVENT &aEvent)
int ToggleDottedSecondary(const TOOL_EVENT &aEvent)
std::shared_ptr< SPICE_SIMULATOR > m_simulator
int ExportPlotAsCSV(const TOOL_EVENT &aEvent)
int UndoZoom(const TOOL_EVENT &aEvent)
int ExportPlotToSchematic(const TOOL_EVENT &aEvent)
int Probe(const TOOL_EVENT &aEvent)
int NewAnalysisTab(const TOOL_EVENT &aEvent)
int Close(const TOOL_EVENT &aEvent)
SIM_TAB * GetCurrentSimTab() const
Return the current tab (or NULL if there is none).
wxString GetCurrentSimCommand() const
std::shared_ptr< SPICE_CIRCUIT_MODEL > GetCircuitModel() const
void OnModify() override
Must be called after a model change in order to set the "modify" flag and do other frame-specific pro...
bool SaveWorkbook(const wxString &aPath)
Save plot, signal, cursor, measurement, etc.
SCH_EDIT_FRAME * GetSchematicFrame() const
void ToggleDarkModePlots()
Toggle dark-mode of the plot tabs.
SIM_TAB * NewSimTab(const wxString &aSimCommand)
Create a new plot tab for a given simulation type.
bool EditAnalysis()
Shows a dialog for editing the current tab's simulation command, or creating a new tab with a differe...
int GetCurrentOptions() const
bool LoadWorkbook(const wxString &aPath)
Load plot, signal, cursor, measurement, etc.
const std::map< int, wxString > & UserDefinedSignals()
std::shared_ptr< SPICE_SIMULATOR > GetSimulator() const
void SetUserDefinedSignals(const std::map< int, wxString > &aSignals)
A slimmed down version of WX_HTML_REPORT_PANEL.
void Flush()
Build the HTML messages page.
A wrapper for reporting to a wxString object.
Canvas for plotting mpLayer implementations.
static double zoomIncrementalFactor
This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
#define MIME_BASE64_LENGTH
static const std::string WorkbookFileExtension
static wxString PngFileWildcard()
static wxString CsvFileWildcard()
static wxString WorkbookFileWildcard()
KICOMMON_API wxFont GetMonospacedUIFont()
SIM_TYPE
< Possible simulation types
std::vector< FAB_LAYER_COLOR > dummy
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().