26#include <wx/filedlg.h>
29#include <wx/stc/stc.h>
44#include <wx/clipbrd.h>
45#include <wx/dataobj.h>
46#include <wx/mstream.h>
108 if( openDlg.ShowModal() == wxID_CANCEL )
118 wxFileName filename =
m_simulator->Settings()->GetWorkbookFilename();
120 if( filename.GetName().IsEmpty() )
124 filename.SetName(
_(
"noname" ) );
134 return filename.GetFullName();
143 return path.GetPath();
152 filename =
m_simulator->Settings()->GetWorkbookFilename();
154 if( filename.IsEmpty() )
158 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
162 if( saveAsDlg.ShowModal() == wxID_CANCEL )
165 filename = saveAsDlg.GetPath();
178 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
182 if( saveDlg.ShowModal() == wxID_CANCEL )
186 plotTab->GetPlotWin()->SaveScreenshot( screenImage );
187 screenImage.SaveFile( saveDlg.GetPath(), wxBITMAP_TYPE_PNG );
199 plotTab->GetPlotWin()->SaveScreenshot( screenImage );
201 if( wxTheClipboard->Open() )
203 wxBitmap bm( screenImage );
205 wxTheClipboard->SetData(
new wxBitmapDataObject( bm ) );
206 wxTheClipboard->Flush();
207 wxTheClipboard->Close();
224 if( blocking_dialog )
225 blocking_dialog->Close(
true );
228 plotTab->GetPlotWin()->SaveScreenshot( screenImage );
230 if( wxTheClipboard->Open() )
233 wxMemoryOutputStream stream;
234 screenImage.SaveFile( stream, wxBITMAP_TYPE_PNG );
239 string <<
"(image (at 0 0)\n";
240 string <<
" (data\n";
243 buff.GetWriteBuf( stream.GetLength() );
244 stream.CopyTo( buff.GetData(), stream.GetLength() );
245 buff.SetDataLen( stream.GetLength() );
248 out << wxBase64Encode( buff );
250#define MIME_BASE64_LENGTH 76
253 while( first < out.Length() )
261 wxTheClipboard->SetData(
new wxTextDataObject(
string ) );
262 wxTheClipboard->Close();
286 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
290 if( saveDlg.ShowModal() == wxID_CANCEL )
293 wxFFile out( saveDlg.GetPath(),
"wb" );
295 std::map<wxString, TRACE*> traces = plotTab->GetTraces();
297 if( traces.size() == 0 )
300 SIM_TYPE simType = plotTab->GetSimType();
302 if( plotTab->IsSmithMode() )
305 std::vector<SMITH_TRACE*> smithTraces;
307 for(
const auto& [
name, trace] : traces )
310 smithTraces.push_back( smithTrace );
313 if( smithTraces.empty() )
316 const std::vector<double>& freqs = smithTraces[0]->GetFrequencies();
318 out.Write( wxString::Format( wxT(
"%s%c" ), wxS(
"frequency" ),
SEPARATOR ) );
322 out.Write( wxString::Format( wxT(
"%s Re%c%s Im%c" ), trace->GetDisplayName(),
SEPARATOR,
326 out.Write( wxS(
"\r\n" ) );
328 for( std::size_t curRow = 0; curRow < freqs.size(); curRow++ )
330 out.Write( wxString::Format( wxT(
"%g%c" ), freqs[curRow],
SEPARATOR ) );
334 double re = curRow < trace->GetDataX().size() ? trace->GetDataX()[curRow] : 0.0;
335 double im = curRow < trace->GetDataY().size() ? trace->GetDataY()[curRow] : 0.0;
340 out.Write( wxS(
"\r\n" ) );
347 std::size_t rowCount = traces.begin()->second->GetDataX().size();
350 wxString xAxisName(
m_simulator->GetXAxis( simType ) );
351 out.Write( wxString::Format( wxT(
"%s%c" ), xAxisName,
SEPARATOR ) );
353 for(
const auto& [
name, trace] : traces )
354 out.Write( wxString::Format( wxT(
"%s%c" ), trace->GetDisplayName(),
SEPARATOR ) );
356 out.Write( wxS(
"\r\n" ) );
359 for( std::size_t curRow = 0; curRow < rowCount; curRow++ )
361 double xAxisValue = traces.begin()->second->GetDataX().at( curRow );
362 out.Write( wxString::Format( wxT(
"%g%c" ), xAxisValue,
SEPARATOR ) );
364 for(
const auto& [
name, trace] : traces )
366 double yAxisValue = trace->GetDataY().at( curRow );
367 out.Write( wxString::Format( wxT(
"%g%c" ), yAxisValue,
SEPARATOR ) );
370 out.Write( wxS(
"\r\n" ) );
395 SIM_VIEW* defaultView = plotTab->GetDefaultView();
396 const std::vector<SIM_VIEW*>& views = plotTab->GetViews();
401 if( plotTab->IsSmithMode() )
408 plotTab->SmithZoomAt(
center, 1.5 );
412 plotTab->SmithZoomAt(
center, 1.0 / 1.5 );
416 plotTab->ResetSmithView();
428 if( view != defaultView )
438 if( view != defaultView )
462 wxCommandEvent
dummy;
465 view->OnFit(
dummy );
478 if( !plotTab->IsSmithMode() )
479 plotTab->GetPlotWin()->ZoomUndo();
490 if( !plotTab->IsSmithMode() )
491 plotTab->GetPlotWin()->ZoomRedo();
520 plotTab->ShowGrid( !plotTab->IsGridShown() );
532 plotTab->ShowLegend( !plotTab->IsLegendShown() );
544 plotTab->SetDottedSecondary( !plotTab->GetDottedSecondary() );
600 if( blocking_dialog )
601 blocking_dialog->Close(
true );
617 if( blocking_dialog )
618 blocking_dialog->Close(
true );
637 wxPostEvent(
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL ) );
641 DIALOG_SHIM( parent, wxID_ANY,
_(
"SPICE Netlist" ), wxDefaultPosition, wxSize( 800, 800 ),
642 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
646 m_splitter =
new wxSplitterWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
647 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
650 m_splitter->SetExtraStyle( wxWS_EX_TRANSIENT );
655 m_textCtrl->StyleSetForeground( wxSTC_STYLE_LINENUMBER, wxColour( 75, 75, 75 ) );
656 m_textCtrl->StyleSetBackground( wxSTC_STYLE_LINENUMBER, wxColour( 220, 220, 220 ) );
661 for(
int i = 0; i < wxSTC_STYLE_MAX; ++i )
680 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
681 sizer->Add(
m_splitter, 1, wxEXPAND | wxALL, 5 );
713 std::map<int, wxString> userSignals =
m_simulatorFrame->UserDefinedSignals();
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
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER, const wxString &name=wxDialogNameStr)
void SetSimCommand(const wxString &aCommand)
void ApplySettings(SIM_TAB *aTab)
void SetSimOptions(int aOptions)
const wxString & GetSimCommand() const
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
A pure virtual class used to derive REPORTER objects from.
static TOOL_ACTION toggleSimConsole
static TOOL_ACTION exportPlotToClipboard
static TOOL_ACTION saveWorkbookAs
static TOOL_ACTION toggleSimSidePanel
static TOOL_ACTION exportPlotAsCSV
static TOOL_ACTION simAnalysisProperties
static TOOL_ACTION toggleSmithChart
static TOOL_ACTION toggleDottedSecondary
static TOOL_ACTION simTune
static TOOL_ACTION toggleDarkModePlots
static TOOL_ACTION exportPlotAsPNG
static TOOL_ACTION exportPlotToSchematic
static TOOL_ACTION runSimulation
static TOOL_ACTION editUserDefinedSignals
static TOOL_ACTION newAnalysisTab
static TOOL_ACTION simProbe
static TOOL_ACTION showNetlist
static TOOL_ACTION openWorkbook
static TOOL_ACTION saveWorkbook
static TOOL_ACTION toggleLegend
static TOOL_ACTION stopSimulation
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 ToggleSmithChart(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 ToggleSimConsolePanel(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 ToggleSimSidePanel(const TOOL_EVENT &aEvent)
int NewAnalysisTab(const TOOL_EVENT &aEvent)
int Close(const TOOL_EVENT &aEvent)
A single stacked plot area within a SIM_PLOT_TAB.
Cursor that snaps along a Smith chart locus, keyed by frequency.
A slimmed down version of WX_HTML_REPORT_PANEL.
A wrapper for reporting to a wxString object.
int GetScrX() const
Get current view's X dimension in device context units.
int GetScrY() const
Get current view's Y dimension in device context units.
void ZoomIn(const wxPoint ¢erPoint=wxDefaultPosition)
Zoom into current view and refresh display.
void ZoomOut(const wxPoint ¢erPoint=wxDefaultPosition)
Zoom out current view and refresh display.
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.
static const std::string WorkbookFileExtension
static wxString PngFileWildcard()
static wxString CsvFileWildcard()
static wxString WorkbookFileWildcard()
KICOMMON_API wxFont GetMonospacedUIFont(int aRelativeSize=0)
SIM_TYPE
< Possible simulation types
#define MIME_BASE64_LENGTH
std::vector< FAB_LAYER_COLOR > dummy
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
IbisParser parser & reporter
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().