-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathExportEvLogDlg.cpp
223 lines (180 loc) · 6.86 KB
/
ExportEvLogDlg.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// ExportEvLogDlg.cpp : implementation file
#include "stdafx.h"
#include "DMSpec.h"
#include "ExportEvLogDlg.h"
#include "Common.h"
#include <math.h>
using namespace Dialogs;
const enum COLUMNS {
COL_NOTHING,
COL_TIME,
COL_LAT,
COL_LONG,
COL_ALT,
COL_INT_PEAK,
COL_COLUMN,
COL_COLUMN_OFFSET,
COL_COLUMN_ERR,
N_STRINGS
};
// CExportEvLogDlg dialog
IMPLEMENT_DYNAMIC(CExportEvLogDlg, CDialog)
CExportEvLogDlg::CExportEvLogDlg(CWnd* pParent /*=NULL*/)
: CDialog(CExportEvLogDlg::IDD, pParent)
{
m_nStrings = N_STRINGS;
m_strings = new CString[N_STRINGS]();
m_strings[COL_NOTHING].Format("Nothing");
m_strings[COL_TIME].Format("Time");
m_strings[COL_LAT].Format("Latitude");
m_strings[COL_LONG].Format("Longitude");
m_strings[COL_ALT].Format("Altitude");
m_strings[COL_INT_PEAK].Format("Intensity");
m_strings[COL_COLUMN].Format("Column");
m_strings[COL_COLUMN_OFFSET].Format("Offset Corrected Column");
m_strings[COL_COLUMN_ERR].Format("Column Error");
m_traverse = nullptr;
}
CExportEvLogDlg::~CExportEvLogDlg()
{
m_traverse = nullptr;
delete[] m_strings;
}
void CExportEvLogDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COLUMNS_FRAME, m_columnFrame);
DDX_Control(pDX, IDC_STATIC_1, m_labelModel);
DDX_Control(pDX, IDC_COMBO1, m_comboModel);
// The export file
DDX_Text(pDX, IDC_EDIT_EXPORTFILE, m_exportFileName);
}
BEGIN_MESSAGE_MAP(CExportEvLogDlg, CDialog)
ON_BN_CLICKED(IDC_BROWSE_BUTTON, OnBrowseOutputFile)
END_MESSAGE_MAP()
// CExportEvLogDlg message handlers
BOOL CExportEvLogDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString string;
CFont* font = new CFont();
// There are Nx combo boxes in one line and Ny lines of boxes
int margin = 20;
int space = 5;
int Nx = (int)max(5, ceil(sqrt(MAX_N_EXPORT_COLUMNS)));
// Get the size of the main rect
CRect totalRect, smallRect, labelRect, comboRect;
m_columnFrame.GetWindowRect(&totalRect);
m_labelModel.GetWindowRect(&labelRect);
m_comboModel.GetWindowRect(&comboRect);
int totalWidth = max(labelRect.Width(), comboRect.Width()) + space;
int totalHeight = labelRect.Height() + comboRect.Height() + space;
// The font to use
font->CreateFont(14, 0, 0, 0, FW_NORMAL,
FALSE, FALSE, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH | FF_SWISS, "Serif");
// Intitialize the labels and the combo-boxes
for (int it = 0; it < MAX_N_EXPORT_COLUMNS; ++it) {
// 1. ---- The labels -------
smallRect.left = (it % Nx) * (totalWidth + space) + margin;
smallRect.right = smallRect.left + totalWidth;
smallRect.top = (it / Nx) * (totalHeight + space) + margin;
smallRect.bottom = smallRect.top + totalHeight;
string.Format("Column %d", it + 1);
m_labels[it].Create(string, WS_VISIBLE | WS_CHILD, smallRect, &m_columnFrame);
m_labels[it].SetFont(font);
// 2. ---- The combo-boxes -----
smallRect.left = (it % Nx) * (totalWidth + space) + margin;
smallRect.right = smallRect.left + totalWidth;
smallRect.top = (it / Nx) * (totalHeight + space) + margin + labelRect.Height();
smallRect.bottom = smallRect.top + totalHeight;
m_combo[it].Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST, smallRect, &m_columnFrame, 1);
m_combo[it].SetFont(font);
// Add the strings
for (int it2 = 0; it2 < m_nStrings; ++it2) {
m_combo[it].AddString(m_strings[it2]);
}
if (it + 1 >= m_nStrings)
m_combo[it].SetCurSel(0);
else
m_combo[it].SetCurSel(it + 1);
// Finally adjust the size of the list
int nLines = min(m_nStrings, 10);
CRect lprect;
m_combo[it].GetWindowRect(&lprect);
lprect.bottom = lprect.top + nLines * m_combo[it].GetItemHeight(-1) + lprect.Height();
m_combo[it].SetWindowPos(NULL, 0, 0, lprect.Width(), lprect.Height(), SWP_NOMOVE | SWP_NOZORDER);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CExportEvLogDlg::OnOK()
{
UpdateData(TRUE); // Save the data in the dialog
if (strlen(m_exportFileName) < 3) {
MessageBox("Please choose where to save data by pressing the 'Browse' button");
return; // don't close the dialog
}
FILE* f = fopen(this->m_exportFileName, "w");
if (f == nullptr) {
MessageBox("Cannot open given output-file for writing. Please check settings and try again", "Error");
return; // don't close the dialog
}
for (int row = 0; row < m_traverse->m_recordNum; ++row) {
for (int col = 0; col < MAX_N_EXPORT_COLUMNS; ++col) {
int index = m_combo[col].GetCurSel();
if (index < 0 || index == COL_NOTHING)
continue;
if (index == COL_TIME) {
// Time
fprintf(f, "%02d:%02d:%02d\t", m_traverse->time[row].hour, m_traverse->time[row].minute, m_traverse->time[row].second);
}
else if (index == COL_LAT) {
// Latitude
fprintf(f, "%.6lf\t", m_traverse->latitude[row]);
}
else if (index == COL_LONG) {
// Longitude
fprintf(f, "%.6lf\t", m_traverse->longitude[row]);
}
else if (index == COL_ALT) {
// Altitude
fprintf(f, "%.0lf\t", m_traverse->altitude[row]);
}
else if (index == COL_INT_PEAK) {
// Peak intensity
fprintf(f, "%.0lf\t", m_traverse->intensArray[row]);
}
else if (index == COL_COLUMN) {
// Column
fprintf(f, "%.6lf\t", m_traverse->columnArray[row]);
}
else if (index == COL_COLUMN_OFFSET) {
// Offset Corrected Column
fprintf(f, "%.6lf\t", m_traverse->columnArray[row] - m_traverse->m_Offset);
}
else if (index == COL_COLUMN_ERR) {
// Column Error
fprintf(f, "%.6lf\t", 0.0);
}
}
fprintf(f, "\n");
}
fclose(f);
MessageBox("Export Successful");
CDialog::OnOK();
}
void CExportEvLogDlg::OnCancel()
{
this->m_traverse = nullptr;
CDialog::OnCancel();
}
void CExportEvLogDlg::OnBrowseOutputFile()
{
Common::BrowseForFile_SaveAs("*.txt", this->m_exportFileName);
// Fill in the data in the dialog
UpdateData(FALSE);
}