-
Notifications
You must be signed in to change notification settings - Fork 7
/
CCreateStandardReferencesDialog.cpp
152 lines (121 loc) · 4.31 KB
/
CCreateStandardReferencesDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// CCreateStandardReferencesDialog.cpp : implementation file
//
#include "StdAfx.h"
#include "CCreateStandardReferencesDialog.h"
#include "afxdialogex.h"
#include "resource.h"
#include "Common.h"
#include <SpectralEvaluation/Calibration/StandardCrossSectionSetup.h>
#include <SpectralEvaluation/File/File.h>
#include <sstream>
// CCreateStandardReferencesDialog dialog
IMPLEMENT_DYNAMIC(CCreateStandardReferencesDialog, CDialog)
CCreateStandardReferencesDialog::CCreateStandardReferencesDialog(CWnd* pParent /*=nullptr*/)
: CDialog(IDD_CALIBRATE_STANDARD_REFERENCES, pParent)
, m_outputdirectory(_T(""))
, m_instrumentName(_T(""))
, m_fileNameSuffix(_T(""))
, m_outputFileNamesExplanation(_T(""))
{
}
CCreateStandardReferencesDialog::~CCreateStandardReferencesDialog()
{
}
void CCreateStandardReferencesDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_STANDARD_REFERENCES_OUTPUT_DIRECTORY, m_outputdirectory);
DDX_Text(pDX, IDC_EDIT_INSTRUMENT_NAME, m_instrumentName);
DDX_Text(pDX, IDC_EDIT_FILE_SUFFIX, m_fileNameSuffix);
DDX_Control(pDX, IDOK, m_okButton);
DDX_Text(pDX, IDC_STATIC_STANDARD_REFERENCES_OUTPUT_FILENAMES, m_outputFileNamesExplanation);
}
BEGIN_MESSAGE_MAP(CCreateStandardReferencesDialog, CDialog)
ON_BN_CLICKED(IDC_BUTTON_BROWSE_STANDARD_REFERENCES_DIRECTORY, &CCreateStandardReferencesDialog::OnClickedButtonBrowseOutputDirectory)
ON_EN_CHANGE(IDC_EDIT_INSTRUMENT_NAME, &CCreateStandardReferencesDialog::OnChangeInstrumentName)
ON_EN_CHANGE(IDC_EDIT_FILE_SUFFIX, &CCreateStandardReferencesDialog::OnChangeFileSuffix)
END_MESSAGE_MAP()
// CCreateStandardReferencesDialog message handlers
bool CCreateStandardReferencesDialog::IsSetupCorrectly() const
{
if (m_outputdirectory.GetLength() == 0)
{
return false;
}
return true;
}
std::string CCreateStandardReferencesDialog::ReferenceFileName(const std::string& nameOfReference, bool includFilteringInfix, bool includeDirectory) const
{
std::stringstream dstFileNameStream;
if (includeDirectory)
{
dstFileNameStream << m_outputdirectory << "\\";
}
if (m_instrumentName.GetLength() > 0)
{
dstFileNameStream << m_instrumentName << "_";
}
dstFileNameStream << nameOfReference;
if (includFilteringInfix)
{
dstFileNameStream << m_fileNameFilteringInfix;
}
if (m_fileNameSuffix.GetLength() > 0)
{
dstFileNameStream << "_" << m_fileNameSuffix;
}
dstFileNameStream << ".txt";
return dstFileNameStream.str();
}
std::string CCreateStandardReferencesDialog::FraunhoferReferenceName(bool includeDirectory) const
{
return ReferenceFileName("Fraunhofer", false, includeDirectory);
}
std::string CCreateStandardReferencesDialog::ReferenceName(size_t referenceIdx, bool includFilteringInfix, bool includeDirectory) const
{
return ReferenceFileName(m_standardCrossSections->ReferenceSpecieName(referenceIdx), includFilteringInfix, includeDirectory);
}
void CCreateStandardReferencesDialog::OnClickedButtonBrowseOutputDirectory()
{
if (!Common::BrowseForDirectory(m_outputdirectory))
{
return;
}
if (IsSetupCorrectly())
{
m_okButton.EnableWindow(TRUE);
}
else
{
m_okButton.EnableWindow(FALSE);
}
UpdateOutputFileNamesExplanation();
}
void CCreateStandardReferencesDialog::OnChangeInstrumentName()
{
UpdateData(TRUE); // Get the values from the UI
UpdateOutputFileNamesExplanation();
}
void CCreateStandardReferencesDialog::OnChangeFileSuffix()
{
UpdateData(TRUE); // Get the values from the UI
UpdateOutputFileNamesExplanation();
}
void CCreateStandardReferencesDialog::UpdateOutputFileNamesExplanation()
{
std::stringstream message;
message << "This will save the following files: ";
// Regular references
for (size_t referenceIdx = 0; referenceIdx < m_standardCrossSections->NumberOfReferences(); ++referenceIdx)
{
message << std::endl;
message << ReferenceName(referenceIdx, !m_standardCrossSections->IsAdditionalAbsorber(referenceIdx), false);
}
// Fraunhofer reference
{
message << std::endl;
message << FraunhoferReferenceName(false);
}
m_outputFileNamesExplanation.Format("%s", message.str().c_str());
UpdateData(FALSE); // Update the UI
}