Rewrite export of data in Contrast.cpp
This commit is contained in:
parent
700c3deba9
commit
cf5c18b9b3
|
@ -36,6 +36,8 @@
|
||||||
#include <wx/filedlg.h>
|
#include <wx/filedlg.h>
|
||||||
#include <wx/valtext.h>
|
#include <wx/valtext.h>
|
||||||
#include <wx/log.h>
|
#include <wx/log.h>
|
||||||
|
#include <wx/wfstream.h>
|
||||||
|
#include <wx/txtstrm.h>
|
||||||
|
|
||||||
#include "../PlatformCompatibility.h"
|
#include "../PlatformCompatibility.h"
|
||||||
|
|
||||||
|
@ -408,28 +410,29 @@ namespace {
|
||||||
// Should these variations in formats be collapsed further?
|
// Should these variations in formats be collapsed further?
|
||||||
|
|
||||||
// Pass nullptr when value is not yet defined
|
// Pass nullptr when value is not yet defined
|
||||||
wxString FormatRMSMessage( float *pValue )
|
TranslatableString FormatRMSMessage( float *pValue )
|
||||||
{
|
{
|
||||||
|
|
||||||
/* i18n-hint: RMS abbreviates root mean square, a certain averaging method */
|
/* i18n-hint: RMS abbreviates root mean square, a certain averaging method */
|
||||||
wxString format0{ _("RMS = %s.") };
|
auto format0 = XO("RMS = %s.");
|
||||||
|
|
||||||
/* i18n-hint: dB abbreviates decibels */
|
/* i18n-hint: dB abbreviates decibels */
|
||||||
wxString format1{ _("%s dB") };
|
auto format1 = XO("%s dB");
|
||||||
|
|
||||||
wxString value;
|
TranslatableString value;
|
||||||
|
|
||||||
if ( pValue )
|
if ( pValue ) {
|
||||||
if( fabs( *pValue ) != std::numeric_limits<float>::infinity() ) {
|
if( fabs( *pValue ) != std::numeric_limits<float>::infinity() ) {
|
||||||
auto number = wxString::Format( _("%.2f"), *pValue );
|
auto number = wxString::Format( wxT("%.2f"), *pValue );
|
||||||
value = wxString::Format( format1, number );
|
value = format1.Format( number );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
value = _("zero");
|
value = XO("zero");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
value = wxString::Format( format1, "" );
|
value = format1.Format( "" );
|
||||||
|
|
||||||
return wxString::Format( format0, value );
|
return format0.Format( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString FormatDifference( float diffdB )
|
wxString FormatDifference( float diffdB )
|
||||||
|
@ -447,19 +450,19 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString FormatDifferenceForExport( float diffdB )
|
TranslatableString FormatDifferenceForExport( float diffdB )
|
||||||
{
|
{
|
||||||
if( diffdB != diffdB ) //test for NaN, reliant on IEEE implementation
|
if( diffdB != diffdB ) //test for NaN, reliant on IEEE implementation
|
||||||
return _("Difference is indeterminate.");
|
return XO("Difference is indeterminate.");
|
||||||
else
|
else
|
||||||
if( fabs(diffdB) != std::numeric_limits<float>::infinity() )
|
if( fabs(diffdB) != std::numeric_limits<float>::infinity() )
|
||||||
/* i18n-hint: dB abbreviates decibels */
|
/* i18n-hint: dB abbreviates decibels */
|
||||||
/* i18n-hint: RMS abbreviates root mean square, a certain averaging method */
|
/* i18n-hint: RMS abbreviates root mean square, a certain averaging method */
|
||||||
return wxString::Format(_("Difference = %.2f RMS dB."), diffdB );
|
return XO("Difference = %.2f RMS dB.").Format( diffdB );
|
||||||
else
|
else
|
||||||
/* i18n-hint: dB abbreviates decibels */
|
/* i18n-hint: dB abbreviates decibels */
|
||||||
/* i18n-hint: RMS abbreviates root mean square, a certain averaging method */
|
/* i18n-hint: RMS abbreviates root mean square, a certain averaging method */
|
||||||
return _("Difference = infinite RMS dB.");
|
return XO("Difference = infinite RMS dB.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -540,58 +543,76 @@ void ContrastDialog::OnExport(wxCommandEvent & WXUNUSED(event))
|
||||||
if (fName.empty())
|
if (fName.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxTextFile f(fName);
|
wxFFileOutputStream ffStream{ fName };
|
||||||
f.Create();
|
|
||||||
f.Open();
|
if (!ffStream.IsOk()) {
|
||||||
if (!f.IsOpened()) {
|
|
||||||
AudacityMessageBox( XO("Couldn't write to file: %s").Format( fName ) );
|
AudacityMessageBox( XO("Couldn't write to file: %s").Format( fName ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
f.AddLine(wxT("==================================="));
|
wxTextOutputStream ss(ffStream);
|
||||||
|
|
||||||
|
ss
|
||||||
|
<< wxT("===================================") << '\n'
|
||||||
/* i18n-hint: WCAG abbreviates Web Content Accessibility Guidelines */
|
/* i18n-hint: WCAG abbreviates Web Content Accessibility Guidelines */
|
||||||
f.AddLine(_("WCAG 2.0 Success Criteria 1.4.7 Contrast Results"));
|
<< XO("WCAG 2.0 Success Criteria 1.4.7 Contrast Results") << '\n'
|
||||||
f.AddLine(wxT(""));
|
<< '\n'
|
||||||
f.AddLine(wxString::Format(_("Filename = %s."), project->GetFileName() ));
|
<< XO("Filename = %s.").Format( project->GetFileName() ) << '\n'
|
||||||
f.AddLine(wxT(""));
|
<< '\n'
|
||||||
f.AddLine(_("Foreground"));
|
<< XO("Foreground") << '\n';
|
||||||
|
|
||||||
float t = (float)mForegroundStartT->GetValue();
|
float t = (float)mForegroundStartT->GetValue();
|
||||||
int h = (int)(t/3600); // there must be a standard function for this!
|
int h = (int)(t/3600); // there must be a standard function for this!
|
||||||
int m = (int)((t - h*3600)/60);
|
int m = (int)((t - h*3600)/60);
|
||||||
float s = t - h*3600.0 - m*60.0;
|
float s = t - h*3600.0 - m*60.0;
|
||||||
f.AddLine(wxString::Format(_("Time started = %2d hour(s), %2d minute(s), %.2f seconds."), h, m, s ));
|
|
||||||
|
ss
|
||||||
|
<< XO("Time started = %2d hour(s), %2d minute(s), %.2f seconds.")
|
||||||
|
.Format( h, m, s ) << '\n';
|
||||||
|
|
||||||
t = (float)mForegroundEndT->GetValue();
|
t = (float)mForegroundEndT->GetValue();
|
||||||
h = (int)(t/3600);
|
h = (int)(t/3600);
|
||||||
m = (int)((t - h*3600)/60);
|
m = (int)((t - h*3600)/60);
|
||||||
s = t - h*3600.0 - m*60.0;
|
s = t - h*3600.0 - m*60.0;
|
||||||
f.AddLine(wxString::Format(_("Time ended = %2d hour(s), %2d minute(s), %.2f seconds."), h, m, s ));
|
|
||||||
f.AddLine( FormatRMSMessage( mForegroundIsDefined ? &foregrounddB : nullptr ) );
|
ss
|
||||||
f.AddLine(wxT(""));
|
<< XO("Time ended = %2d hour(s), %2d minute(s), %.2f seconds.")
|
||||||
f.AddLine(_("Background"));
|
.Format( h, m, s ) << '\n'
|
||||||
|
<< FormatRMSMessage( mForegroundIsDefined ? &foregrounddB : nullptr ) << '\n'
|
||||||
|
<< '\n'
|
||||||
|
<< XO("Background") << '\n';
|
||||||
|
|
||||||
t = (float)mBackgroundStartT->GetValue();
|
t = (float)mBackgroundStartT->GetValue();
|
||||||
h = (int)(t/3600);
|
h = (int)(t/3600);
|
||||||
m = (int)((t - h*3600)/60);
|
m = (int)((t - h*3600)/60);
|
||||||
s = t - h*3600.0 - m*60.0;
|
s = t - h*3600.0 - m*60.0;
|
||||||
f.AddLine(wxString::Format(_("Time started = %2d hour(s), %2d minute(s), %.2f seconds."), h, m, s ));
|
|
||||||
|
ss
|
||||||
|
<< XO("Time started = %2d hour(s), %2d minute(s), %.2f seconds.")
|
||||||
|
.Format( h, m, s ) << '\n';
|
||||||
|
|
||||||
t = (float)mBackgroundEndT->GetValue();
|
t = (float)mBackgroundEndT->GetValue();
|
||||||
h = (int)(t/3600);
|
h = (int)(t/3600);
|
||||||
m = (int)((t - h*3600)/60);
|
m = (int)((t - h*3600)/60);
|
||||||
s = t - h*3600.0 - m*60.0;
|
s = t - h*3600.0 - m*60.0;
|
||||||
f.AddLine(wxString::Format(_("Time ended = %2d hour(s), %2d minute(s), %.2f seconds."), h, m, s ));
|
|
||||||
f.AddLine( FormatRMSMessage( mBackgroundIsDefined ? &backgrounddB : nullptr ) );
|
ss
|
||||||
f.AddLine(wxT(""));
|
<< XO("Time ended = %2d hour(s), %2d minute(s), %.2f seconds.")
|
||||||
f.AddLine(_("Results"));
|
.Format( h, m, s ) << '\n'
|
||||||
|
<< FormatRMSMessage( mBackgroundIsDefined ? &backgrounddB : nullptr ) << '\n'
|
||||||
|
<< '\n'
|
||||||
|
<< XO("Results") << '\n';
|
||||||
|
|
||||||
float diffdB = foregrounddB - backgrounddB;
|
float diffdB = foregrounddB - backgrounddB;
|
||||||
|
|
||||||
f.AddLine( FormatDifferenceForExport( diffdB ) );
|
ss
|
||||||
if( diffdB > 20. )
|
<< FormatDifferenceForExport( diffdB ) << '\n'
|
||||||
f.AddLine(_("Success Criteria 1.4.7 of WCAG 2.0: Pass"));
|
<< (( diffdB > 20. )
|
||||||
else
|
? XO("Success Criteria 1.4.7 of WCAG 2.0: Pass")
|
||||||
f.AddLine(_("Success Criteria 1.4.7 of WCAG 2.0: Fail"));
|
: XO("Success Criteria 1.4.7 of WCAG 2.0: Fail")) << '\n'
|
||||||
|
<< '\n'
|
||||||
|
<< XO("Data gathered") << '\n';
|
||||||
|
|
||||||
f.AddLine(wxT(""));
|
|
||||||
f.AddLine(_("Data gathered"));
|
|
||||||
wxString sNow;
|
|
||||||
wxDateTime now = wxDateTime::Now();
|
wxDateTime now = wxDateTime::Now();
|
||||||
int year = now.GetYear();
|
int year = now.GetYear();
|
||||||
wxDateTime::Month month = now.GetMonth();
|
wxDateTime::Month month = now.GetMonth();
|
||||||
|
@ -600,15 +621,14 @@ void ContrastDialog::OnExport(wxCommandEvent & WXUNUSED(event))
|
||||||
int hour = now.GetHour();
|
int hour = now.GetHour();
|
||||||
int minute = now.GetMinute();
|
int minute = now.GetMinute();
|
||||||
int second = now.GetSecond();
|
int second = now.GetSecond();
|
||||||
sNow = wxString::Format(wxT("%d %s %02d %02dh %02dm %02ds"),
|
/* i18n-hint: day of month, month, year, hour, minute, second */
|
||||||
dom, monthName, year, hour, minute, second);
|
auto sNow = XO("%d %s %02d %02dh %02dm %02ds")
|
||||||
f.AddLine(sNow);
|
.Format( dom, monthName, year, hour, minute, second );
|
||||||
|
|
||||||
f.AddLine(wxT("==================================="));
|
ss <<
|
||||||
f.AddLine(wxT(""));
|
sNow << '\n'
|
||||||
|
<< wxT("===================================") << '\n'
|
||||||
f.Write();
|
<< '\n';
|
||||||
f.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContrastDialog::OnReset(wxCommandEvent & /*event*/)
|
void ContrastDialog::OnReset(wxCommandEvent & /*event*/)
|
||||||
|
|
Loading…
Reference in New Issue