Simulation plot CSV & PNG export
This commit is contained in:
parent
1d4fe279db
commit
17294aaf6a
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 ) );
|
||||
|
|
|
@ -133,7 +133,7 @@
|
|||
<event name="OnSetFocus"></event>
|
||||
<event name="OnSize"></event>
|
||||
<event name="OnUpdateUI"></event>
|
||||
<object class="wxMenu" expanded="0">
|
||||
<object class="wxMenu" expanded="1">
|
||||
<property name="label">File</property>
|
||||
<property name="name">m_fileMenu</property>
|
||||
<property name="permission">protected</property>
|
||||
|
@ -145,7 +145,7 @@
|
|||
<property name="id">wxID_NEW</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">New Plot</property>
|
||||
<property name="name">m_menuItem7</property>
|
||||
<property name="name">m_newPlot</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
|
@ -164,7 +164,7 @@
|
|||
<property name="id">wxID_OPEN</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Open Workbook</property>
|
||||
<property name="name">m_menuItem8</property>
|
||||
<property name="name">m_openWorkbook</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
|
@ -179,7 +179,7 @@
|
|||
<property name="id">wxID_SAVE</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Save Workbook</property>
|
||||
<property name="name">m_menuItem2</property>
|
||||
<property name="name">m_saveWorkbook</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
|
@ -190,6 +190,40 @@
|
|||
<property name="name">m_separator1</property>
|
||||
<property name="permission">none</property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Save as image</property>
|
||||
<property name="name">m_saveImage</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
<event name="OnMenuSelection">menuSaveImage</event>
|
||||
<event name="OnUpdateUI"></event>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help"></property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Save as .csv file</property>
|
||||
<property name="name">m_saveCsv</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
<event name="OnMenuSelection">menuSaveCsv</event>
|
||||
<event name="OnUpdateUI"></event>
|
||||
</object>
|
||||
<object class="separator" expanded="1">
|
||||
<property name="name">m_separator4</property>
|
||||
<property name="permission">none</property>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="0">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
|
@ -198,7 +232,7 @@
|
|||
<property name="id">wxID_CLOSE</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Exit Simulation</property>
|
||||
<property name="name">m_menuItem1</property>
|
||||
<property name="name">m_exitSim</property>
|
||||
<property name="permission">none</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
|
@ -274,7 +308,7 @@
|
|||
<event name="OnMenuSelection">menuShowGrid</event>
|
||||
<event name="OnUpdateUI">menuShowGridUpdate</event>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<object class="wxMenuItem" expanded="0">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
|
@ -289,7 +323,7 @@
|
|||
<event name="OnMenuSelection">menuShowLegend</event>
|
||||
<event name="OnUpdateUI">menuShowLegendUpdate</event>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<object class="wxMenuItem" expanded="0">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
|
|
|
@ -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(); }
|
||||
|
|
Loading…
Reference in New Issue