30#include <wx/filedlg.h>
32#include <wx/stc/stc.h>
47#include <wx/clipbrd.h>
48#include <wx/dataobj.h>
49#include <wx/mstream.h>
112 if( openDlg.ShowModal() == wxID_CANCEL )
122 wxFileName filename =
m_simulator->Settings()->GetWorkbookFilename();
124 if( filename.GetName().IsEmpty() )
128 filename.SetName(
_(
"noname" ) );
138 return filename.GetFullName();
148 return path.GetPath();
157 filename =
m_simulator->Settings()->GetWorkbookFilename();
159 if( filename.IsEmpty() )
164 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
166 if( saveAsDlg.ShowModal() == wxID_CANCEL )
169 filename = saveAsDlg.GetPath();
184 if( saveDlg.ShowModal() == wxID_CANCEL )
188 plotTab->GetPlotWin()->SaveScreenshot( screenImage );
189 screenImage.SaveFile( saveDlg.GetPath(), wxBITMAP_TYPE_PNG );
201 plotTab->GetPlotWin()->SaveScreenshot( screenImage );
203 if( wxTheClipboard->Open() )
205 wxBitmap bm( screenImage );
207 wxTheClipboard->SetData(
new wxBitmapDataObject( bm ) );
208 wxTheClipboard->Flush();
209 wxTheClipboard->Close();
226 if( blocking_dialog )
227 blocking_dialog->Close(
true );
230 plotTab->GetPlotWin()->SaveScreenshot( screenImage );
232 if( wxTheClipboard->Open() )
235 wxMemoryOutputStream stream;
236 screenImage.SaveFile( stream, wxBITMAP_TYPE_PNG );
241 string <<
"(image (at 0 0)\n";
242 string <<
" (data\n";
245 buff.GetWriteBuf( stream.GetLength() );
246 stream.CopyTo( buff.GetData(), stream.GetLength() );
247 buff.SetDataLen( stream.GetLength() );
250 out << wxBase64Encode( buff );
252 #define MIME_BASE64_LENGTH 76
255 while( first < out.Length() )
263 wxTheClipboard->SetData(
new wxTextDataObject(
string ) );
264 wxTheClipboard->Close();
289 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
291 if( saveDlg.ShowModal() == wxID_CANCEL )
294 wxFFile out( saveDlg.GetPath(),
"wb" );
296 std::map<wxString, TRACE*> traces = plotTab->GetTraces();
298 if( traces.size() == 0 )
301 SIM_TYPE simType = plotTab->GetSimType();
303 std::size_t rowCount = traces.begin()->second->GetDataX().size();
306 wxString xAxisName(
m_simulator->GetXAxis( simType ) );
307 out.Write( wxString::Format( wxT(
"%s%c" ), xAxisName,
SEPARATOR ) );
309 for(
const auto& [
name, trace] : traces )
310 out.Write( wxString::Format( wxT(
"%s%c" ), trace->GetDisplayName(),
SEPARATOR ) );
312 out.Write( wxS(
"\r\n" ) );
315 for ( std::size_t curRow=0; curRow < rowCount; curRow++ )
317 double xAxisValue = traces.begin()->second->GetDataX().at( curRow );
318 out.Write( wxString::Format( wxT(
"%g%c" ), xAxisValue,
SEPARATOR ) );
320 for(
const auto& [
name, trace] : traces )
322 double yAxisValue = trace->GetDataY().at( curRow );
323 out.Write( wxString::Format( wxT(
"%g%c" ), yAxisValue,
SEPARATOR ) );
326 out.Write( wxS(
"\r\n" ) );
375 wxCommandEvent
dummy;
387 plotTab->GetPlotWin()->ZoomUndo();
396 plotTab->GetPlotWin()->ZoomRedo();
406 plotTab->ShowGrid( !plotTab->IsGridShown() );
418 plotTab->ShowLegend( !plotTab->IsLegendShown() );
430 plotTab->SetDottedSecondary( !plotTab->GetDottedSecondary() );
479 if( blocking_dialog )
480 blocking_dialog->Close(
true );
496 if( blocking_dialog )
497 blocking_dialog->Close(
true );
516 wxPostEvent(
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL ) );
520 DIALOG_SHIM( parent, wxID_ANY,
_(
"SPICE Netlist" ), wxDefaultPosition,
521 wxSize( 800, 800 ), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
525 m_splitter =
new wxSplitterWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
526 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
529 m_splitter->SetExtraStyle( wxWS_EX_TRANSIENT );
534 m_textCtrl->StyleSetForeground( wxSTC_STYLE_LINENUMBER, wxColour( 75, 75, 75 ) );
535 m_textCtrl->StyleSetBackground( wxSTC_STYLE_LINENUMBER, wxColour( 220, 220, 220 ) );
540 for(
int i = 0; i < wxSTC_STYLE_MAX; ++i )
559 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
560 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.
bool HasMessageOfSeverity(int aSeverityMask) const override
Returns true if the reporter has one or more messages matching the specified severity mask.
const wxString & GetMessages() const
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 DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
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().