From 8b2b3ca79774aa31e2328911d00af46c094d6faf Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Sun, 4 Jul 2021 03:48:12 +0200 Subject: [PATCH] Define .wbk in wildcards_and_files.{cpp,h}, cosmetic code changes --- common/wildcards_and_files_ext.cpp | 1 + eeschema/sim/sim_plot_frame.cpp | 50 +++++++++++++++--------------- include/wildcards_and_files_ext.h | 1 + 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp index 09f75ed2c0..29ab3e0fde 100644 --- a/common/wildcards_and_files_ext.cpp +++ b/common/wildcards_and_files_ext.cpp @@ -161,6 +161,7 @@ const std::string GedaPcbFootprintLibFileExtension( "fp" ); // this is a fil const std::string KiCadFootprintFileExtension( "kicad_mod" ); const std::string SpecctraDsnFileExtension( "dsn" ); const std::string IpcD356FileExtension( "d356" ); +const std::string WorkbookFileExtension( "wbk" ); const std::string PngFileExtension( "png" ); const std::string JpegFileExtension( "jpg" ); diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 7bb20391d0..6b56832441 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -915,6 +915,9 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath ) wxTextFile file( aPath ); +#define DISPLAY_LOAD_ERROR( fmt ) DisplayErrorMessage( this, wxString::Format( _( fmt ), \ + file.GetCurrentLine()+1 ) ) + if( !file.Open() ) { updateFrame(); @@ -925,9 +928,8 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath ) if( !file.GetFirstLine().ToLong( &plotsCount ) ) // GetFirstLine instead of GetNextLine { + DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is not an integer." ); file.Close(); - DisplayErrorMessage( this, - _( "Error loading workbook: First line is not convertible to `long`." ) ); updateFrame(); return false; @@ -939,9 +941,8 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath ) if( !file.GetNextLine().ToLong( &plotType ) ) { + DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is not an integer." ); file.Close(); - DisplayErrorMessage( this, wxString::Format( - _( "Error loading workbook: Line %d is not convertible to `long`." ), 6*i+2 ) ); updateFrame(); return false; @@ -960,10 +961,8 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath ) if( !file.GetNextLine().ToLong( &tracesCount ) ) { + DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is not an integer." ); file.Close(); - DisplayErrorMessage( this, wxString::Format( - _( "Error loading workbook: Line %d is not convertible to `long`." ), 6*i+4 ) - ); updateFrame(); return false; @@ -976,10 +975,9 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath ) if( !file.GetNextLine().ToLong( &traceType ) ) { + DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is not an integer." + ); file.Close(); - DisplayErrorMessage( this, wxString::Format( - _( "Error loading workbook: Line %d is not convertible to `long`." ), 6*i+5 - ) ); updateFrame(); return false; @@ -989,9 +987,8 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath ) if( name.IsEmpty() ) { + DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is empty." ); file.Close(); - DisplayErrorMessage( this, wxString::Format( - _( "Error loading workbook: Line %d is empty" ), 6*i+6 ) ); updateFrame(); return false; @@ -1001,9 +998,8 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath ) if( param.IsEmpty() ) { + DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is empty." ); file.Close(); - DisplayErrorMessage( this, wxString::Format( - _( "Error loading workbook: Line %d is empty" ), 6*i+7 ) ); updateFrame(); return false; @@ -1025,12 +1021,10 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath ) bool SIM_PLOT_FRAME::saveWorkbook( const wxString& aPath ) { - wxString savePath = aPath; + wxFileName filename = aPath; + filename.SetExt( WorkbookFileExtension ); - if( !savePath.Lower().EndsWith(".wbk") ) - savePath += ".wbk"; - - wxTextFile file( savePath ); + wxTextFile file( filename.GetFullPath() ); if( file.Exists() ) { @@ -1083,7 +1077,7 @@ bool SIM_PLOT_FRAME::saveWorkbook( const wxString& aPath ) // Store the filename of the last saved workbook. It will be used to restore the simulation if // the frame is closed and then opened again. if( res ) - m_simulator->Settings()->SetWorkbookFilename( wxFileName( savePath ).GetFullName() ); + m_simulator->Settings()->SetWorkbookFilename( filename.GetFullName() ); m_workbook->ClrModified(); updateFrame(); @@ -1151,18 +1145,24 @@ void SIM_PLOT_FRAME::menuSaveWorkbook( wxCommandEvent& event ) void SIM_PLOT_FRAME::menuSaveWorkbookAs( wxCommandEvent& event ) { - wxString defaultFilename = m_simulator->Settings()->GetWorkbookFilename(); + wxFileName defaultFilename = m_simulator->Settings()->GetWorkbookFilename(); - if( defaultFilename.IsEmpty() ) + if( defaultFilename.GetName().IsEmpty() ) { if( Prj().GetProjectName().IsEmpty() ) - defaultFilename = wxT( "noname.wbk" ); + { + defaultFilename.SetName( _( "noname" ) ); + defaultFilename.SetExt( WorkbookFileExtension ); + } else - defaultFilename = Prj().GetProjectName() + wxT( ".wbk" ); + { + defaultFilename.SetName( Prj().GetProjectName() ); + defaultFilename.SetExt( WorkbookFileExtension ); + } } wxFileDialog saveAsDlg( this, _( "Save Simulation Workbook As" ), m_savedWorkbooksPath, - defaultFilename, WorkbookFileWildcard(), + defaultFilename.GetFullPath(), WorkbookFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); if( saveAsDlg.ShowModal() == wxID_CANCEL ) diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index 2b23ad0df1..3d7f538ce3 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -151,6 +151,7 @@ extern const std::string EagleFootprintLibPathExtension; extern const std::string DrawingSheetFileExtension; extern const std::string SpecctraDsnFileExtension; extern const std::string IpcD356FileExtension; +extern const std::string WorkbookFileExtension; extern const std::string PngFileExtension; extern const std::string JpegFileExtension;