diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index e73fce831b..f5c2836273 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -185,6 +185,58 @@ int SIM_PLOT_FRAME::getNodeNumber( const wxString& aNetName ) } +void SIM_PLOT_FRAME::menuSaveImage( wxCommandEvent& event ) +{ + wxFileDialog saveDlg( this, wxT( "Save plot as image" ), "", "", + "PNG file (*.png)|*.png", wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + + if( saveDlg.ShowModal() == wxID_CANCEL ) + return; + + CurrentPlot()->SaveScreenshot( saveDlg.GetPath(), wxBITMAP_TYPE_PNG ); +} + + +void SIM_PLOT_FRAME::menuSaveCsv( wxCommandEvent& event ) +{ + const wxChar SEPARATOR = ';'; + + wxFileDialog saveDlg( this, wxT( "Save plot data" ), "", "", + "CSV file (*.csv)|*.csv", wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + + if( saveDlg.ShowModal() == wxID_CANCEL ) + return; + + wxFile out( saveDlg.GetPath(), wxFile::write ); + bool timeWritten = false; + + for( const auto& t : CurrentPlot()->GetTraces() ) + { + const TRACE* trace = t.second; + + if( !timeWritten ) + { + out.Write( wxString::Format( "Time%c", SEPARATOR ) ); + + for( double v : trace->GetDataX() ) + out.Write( wxString::Format( "%f%c", v, SEPARATOR ) ); + + out.Write( "\r\n" ); + timeWritten = true; + } + + out.Write( wxString::Format( "%s%c", t.first, SEPARATOR ) ); + + for( double v : trace->GetDataY() ) + out.Write( wxString::Format( "%f%c", v, SEPARATOR ) ); + + out.Write( "\r\n" ); + } + + out.Close(); +} + + void SIM_PLOT_FRAME::menuZoomIn( wxCommandEvent& event ) { CurrentPlot()->ZoomIn(); diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index be3a664256..b46e556dda 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -92,6 +92,8 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE } // Event handlers + void menuSaveImage( wxCommandEvent& event ) override; + void menuSaveCsv( wxCommandEvent& event ) override; void menuZoomIn( wxCommandEvent& event ) override; void menuZoomOut( wxCommandEvent& event ) override; void menuZoomFit( wxCommandEvent& event ) override; diff --git a/eeschema/sim/sim_plot_frame_base.cpp b/eeschema/sim/sim_plot_frame_base.cpp index a13990e4b1..75a1544d48 100644 --- a/eeschema/sim/sim_plot_frame_base.cpp +++ b/eeschema/sim/sim_plot_frame_base.cpp @@ -15,25 +15,35 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const m_mainMenu = new wxMenuBar( 0 ); m_fileMenu = new wxMenu(); - wxMenuItem* m_menuItem7; - m_menuItem7 = new wxMenuItem( m_fileMenu, wxID_NEW, wxString( _("New Plot") ) , wxEmptyString, wxITEM_NORMAL ); - m_fileMenu->Append( m_menuItem7 ); + wxMenuItem* m_newPlot; + m_newPlot = new wxMenuItem( m_fileMenu, wxID_NEW, wxString( _("New Plot") ) , wxEmptyString, wxITEM_NORMAL ); + m_fileMenu->Append( m_newPlot ); m_fileMenu->AppendSeparator(); - wxMenuItem* m_menuItem8; - m_menuItem8 = new wxMenuItem( m_fileMenu, wxID_OPEN, wxString( _("Open Workbook") ) , wxEmptyString, wxITEM_NORMAL ); - m_fileMenu->Append( m_menuItem8 ); + wxMenuItem* m_openWorkbook; + m_openWorkbook = new wxMenuItem( m_fileMenu, wxID_OPEN, wxString( _("Open Workbook") ) , wxEmptyString, wxITEM_NORMAL ); + m_fileMenu->Append( m_openWorkbook ); - wxMenuItem* m_menuItem2; - m_menuItem2 = new wxMenuItem( m_fileMenu, wxID_SAVE, wxString( _("Save Workbook") ) , wxEmptyString, wxITEM_NORMAL ); - m_fileMenu->Append( m_menuItem2 ); + wxMenuItem* m_saveWorkbook; + m_saveWorkbook = new wxMenuItem( m_fileMenu, wxID_SAVE, wxString( _("Save Workbook") ) , wxEmptyString, wxITEM_NORMAL ); + m_fileMenu->Append( m_saveWorkbook ); m_fileMenu->AppendSeparator(); - wxMenuItem* m_menuItem1; - m_menuItem1 = new wxMenuItem( m_fileMenu, wxID_CLOSE, wxString( _("Exit Simulation") ) , wxEmptyString, wxITEM_NORMAL ); - m_fileMenu->Append( m_menuItem1 ); + wxMenuItem* m_saveImage; + m_saveImage = new wxMenuItem( m_fileMenu, wxID_ANY, wxString( _("Save as image") ) , wxEmptyString, wxITEM_NORMAL ); + m_fileMenu->Append( m_saveImage ); + + wxMenuItem* m_saveCsv; + m_saveCsv = new wxMenuItem( m_fileMenu, wxID_ANY, wxString( _("Save as .csv file") ) , wxEmptyString, wxITEM_NORMAL ); + m_fileMenu->Append( m_saveCsv ); + + m_fileMenu->AppendSeparator(); + + wxMenuItem* m_exitSim; + m_exitSim = new wxMenuItem( m_fileMenu, wxID_CLOSE, wxString( _("Exit Simulation") ) , wxEmptyString, wxITEM_NORMAL ); + m_fileMenu->Append( m_exitSim ); m_mainMenu->Append( m_fileMenu, _("File") ); @@ -132,10 +142,12 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const this->Centre( wxBOTH ); // Connect Events - this->Connect( m_menuItem7->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuNewPlot ) ); - this->Connect( m_menuItem8->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuOpenWorkbook ) ); - this->Connect( m_menuItem2->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuSaveWorkbook ) ); - this->Connect( m_menuItem1->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuExit ) ); + this->Connect( m_newPlot->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuNewPlot ) ); + this->Connect( m_openWorkbook->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuOpenWorkbook ) ); + this->Connect( m_saveWorkbook->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuSaveWorkbook ) ); + this->Connect( m_saveImage->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuSaveImage ) ); + this->Connect( m_saveCsv->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuSaveCsv ) ); + this->Connect( m_exitSim->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuExit ) ); this->Connect( m_zoomIn->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomIn ) ); this->Connect( m_zoomOut->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomOut ) ); this->Connect( m_zoomFit->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomFit ) ); @@ -159,6 +171,8 @@ SIM_PLOT_FRAME_BASE::~SIM_PLOT_FRAME_BASE() this->Disconnect( wxID_NEW, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuNewPlot ) ); this->Disconnect( wxID_OPEN, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuOpenWorkbook ) ); this->Disconnect( wxID_SAVE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuSaveWorkbook ) ); + this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuSaveImage ) ); + this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuSaveCsv ) ); this->Disconnect( wxID_CLOSE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuExit ) ); this->Disconnect( wxID_ZOOM_IN, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomIn ) ); this->Disconnect( wxID_ZOOM_OUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomOut ) ); diff --git a/eeschema/sim/sim_plot_frame_base.fbp b/eeschema/sim/sim_plot_frame_base.fbp index 9c941424c4..92a27ad63a 100644 --- a/eeschema/sim/sim_plot_frame_base.fbp +++ b/eeschema/sim/sim_plot_frame_base.fbp @@ -133,7 +133,7 @@ - + File m_fileMenu protected @@ -145,7 +145,7 @@ wxID_NEW wxITEM_NORMAL New Plot - m_menuItem7 + m_newPlot none @@ -164,7 +164,7 @@ wxID_OPEN wxITEM_NORMAL Open Workbook - m_menuItem8 + m_openWorkbook none @@ -179,7 +179,7 @@ wxID_SAVE wxITEM_NORMAL Save Workbook - m_menuItem2 + m_saveWorkbook none @@ -190,6 +190,40 @@ m_separator1 none + + + 0 + 1 + + wxID_ANY + wxITEM_NORMAL + Save as image + m_saveImage + none + + + menuSaveImage + + + + + 0 + 1 + + wxID_ANY + wxITEM_NORMAL + Save as .csv file + m_saveCsv + none + + + menuSaveCsv + + + + m_separator4 + none + 0 @@ -198,7 +232,7 @@ wxID_CLOSE wxITEM_NORMAL Exit Simulation - m_menuItem1 + m_exitSim none @@ -274,7 +308,7 @@ menuShowGrid menuShowGridUpdate - + 0 1 @@ -289,7 +323,7 @@ menuShowLegend menuShowLegendUpdate - + 0 1 diff --git a/eeschema/sim/sim_plot_frame_base.h b/eeschema/sim/sim_plot_frame_base.h index 2aba38d4e9..ded6aa5aab 100644 --- a/eeschema/sim/sim_plot_frame_base.h +++ b/eeschema/sim/sim_plot_frame_base.h @@ -60,6 +60,8 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER virtual void menuNewPlot( wxCommandEvent& event ) { event.Skip(); } virtual void menuOpenWorkbook( wxCommandEvent& event ) { event.Skip(); } virtual void menuSaveWorkbook( wxCommandEvent& event ) { event.Skip(); } + virtual void menuSaveImage( wxCommandEvent& event ) { event.Skip(); } + virtual void menuSaveCsv( wxCommandEvent& event ) { event.Skip(); } virtual void menuExit( wxCommandEvent& event ) { event.Skip(); } virtual void menuZoomIn( wxCommandEvent& event ) { event.Skip(); } virtual void menuZoomOut( wxCommandEvent& event ) { event.Skip(); }