-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNewDocPropertyPages.cpp
360 lines (296 loc) · 10.8 KB
/
NewDocPropertyPages.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2005-2011 Association Homecinema Francophone. All rights reserved.
/////////////////////////////////////////////////////////////////////////////
//
// This file is subject to the terms of the GNU General Public License as
// published by the Free Software Foundation. A copy of this license is
// included with this software distribution in the file COPYING.htm. If you
// do not have a copy, you may obtain a copy by writing to the Free
// Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details
/////////////////////////////////////////////////////////////////////////////
// Author(s):
// François-Xavier CHABOUD
/////////////////////////////////////////////////////////////////////////////
// NewDocPropertyPages.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "ColorHCFR.h"
#include "NewDocPropertyPages.h"
#include "ArgyllMeterWrapper.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CSensorSelectionPropPage, CPropertyPageWithHelp)
IMPLEMENT_DYNCREATE(CGeneratorSelectionPropPage, CPropertyPageWithHelp)
/////////////////////////////////////////////////////////////////////////////
// CGeneratorSelectionPropPage property page
CGeneratorSelectionPropPage::CGeneratorSelectionPropPage() : CPropertyPageWithHelp(CGeneratorSelectionPropPage::IDD)
{
//{{AFX_DATA_INIT(CGeneratorSelectionPropPage)
m_generatorChoice = 0;
//}}AFX_DATA_INIT
// Init selection with previoulsy stored value
m_generatorChoice = GetConfig()->GetGeneratorType();
}
CGeneratorSelectionPropPage::~CGeneratorSelectionPropPage()
{
// save current selection in the registry to be the next default value
GetConfig()->SetGeneratorType((CColorHCFRConfig::GeneratorType)m_generatorChoice);
}
void CGeneratorSelectionPropPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPageWithHelp::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGeneratorSelectionPropPage)
DDX_Control(pDX, IDC_GENERATORCHOICE_COMBO, m_generatorChoiceCtrl);
DDX_CBIndex(pDX, IDC_GENERATORCHOICE_COMBO, m_generatorChoice);
//}}AFX_DATA_MAP
if(pDX->m_bSaveAndValidate != 0) // 0=init 1=save
m_currentID=m_generatorChoiceCtrl.GetCurSel();
if (m_currentID == 1) m_currentID++; //KiGen removed, 2nd choice id needs to be incremented
else
{
// In case of language changing, the default name can be incorrect
if ( m_generatorChoiceCtrl.GetCurSel() < 0 )
m_generatorChoiceCtrl.SetCurSel(0);
}
GetConfig()->SetGeneratorType((CColorHCFRConfig::GeneratorType)m_generatorChoice);
}
BEGIN_MESSAGE_MAP(CGeneratorSelectionPropPage, CPropertyPageWithHelp)
//{{AFX_MSG_MAP(CGeneratorSelectionPropPage)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CGeneratorSelectionPropPage::OnSetActive()
{
CPropertySheetWithHelp * psheet = (CPropertySheetWithHelp*) GetParent();
psheet->SetWizardButtons(PSWIZB_NEXT);
return CPropertyPageWithHelp::OnSetActive();
}
BOOL CGeneratorSelectionPropPage::OnWizardFinish()
{
UpdateData(TRUE); // To update string
return CPropertyPageWithHelp::OnWizardFinish();
}
UINT CGeneratorSelectionPropPage::GetHelpId ( LPSTR lpszTopic )
{
return HID_SELECT_GENERATOR;
}
/////////////////////////////////////////////////////////////////////////////
// CSensorSelectionPropPage property page
CSensorSelectionPropPage::CSensorSelectionPropPage() : CPropertyPageWithHelp(CSensorSelectionPropPage::IDD)
{
//{{AFX_DATA_INIT(CSensorSelectionPropPage)
m_sensorChoice = _T("");
m_trainingFileName = _T("");
m_sensorTrainingMode = -1;
//}}AFX_DATA_INIT
// Init selection with previoulsy stored value
m_sensorChoice = GetConfig()->GetProfileString("Defaults","Sensor","");
m_trainingFileName = GetConfig()->GetProfileString("Defaults","Training FileName","");
m_sensorTrainingMode = GetConfig()->GetProfileInt("Defaults","Training Mode",1);
}
CSensorSelectionPropPage::~CSensorSelectionPropPage()
{
// save current selection in the registry to be the next default value
GetConfig()->WriteProfileString("Defaults","Sensor",m_sensorChoice);
GetConfig()->WriteProfileString("Defaults","Training FileName",m_trainingFileName);
GetConfig()->WriteProfileInt("Defaults","Training Mode",m_sensorTrainingMode);
}
void CSensorSelectionPropPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPageWithHelp::DoDataExchange(pDX);
DDX_Control(pDX, IDC_SENSORTRAININGFILE_COMBO, m_trainingFileCombo);
DDX_Control(pDX, IDC_SENSORCHOICE_COMBO, m_sensorChoiceCtrl);
if(m_sensorChoiceCtrl.GetCount() == 0)
{
std::string errorMessage;
ArgyllMeterWrapper::ArgyllMeterWrappers argyllMeters = ArgyllMeterWrapper::getDetectedMeters(errorMessage);
if(!errorMessage.empty())
{
GetColorApp()->InMeasureMessageBox(errorMessage.c_str(), "Argyll Error", MB_OK | MB_ICONEXCLAMATION);
}
for(size_t i(0); i < argyllMeters.size(); ++i)
{
AddSensor(argyllMeters[i]->getMeterName().c_str(), (int)argyllMeters[i]);
}
AddSensor(_T("Simulated sensor"), 1);
#ifdef USE_NON_FREE_CODE //all should run under ArgyllCMS license
AddSensor(_T("Spyder II"), 2);
AddSensor(_T("Eye One"), 4);
AddSensor(_T("Mazet MTCS-C2"), 5);
AddSensor(_T("Spyder 3"), 6);
AddSensor(_T("DTP-94"), 3);
AddSensor(_T("HCFR Sensor"), 0);
#endif
}
DDX_CBString(pDX, IDC_SENSORCHOICE_COMBO, m_sensorChoice);
DDX_Radio(pDX, IDC_SENSORTRAININGMODE_RADIO1, m_sensorTrainingMode);
if(pDX->m_bSaveAndValidate != 0) // 0=init 1=save
m_currentID=m_sensorChoiceCtrl.GetItemData(m_sensorChoiceCtrl.GetCurSel());
else
{
// In case of language changing, the default name can be incorrect
if ( m_sensorChoiceCtrl.GetCurSel() < 0 )
m_sensorChoiceCtrl.SetCurSel(0);
}
}
BEGIN_MESSAGE_MAP(CSensorSelectionPropPage, CPropertyPageWithHelp)
//{{AFX_MSG_MAP(CSensorSelectionPropPage)
ON_CBN_SELCHANGE(IDC_SENSORCHOICE_COMBO, OnSelchangeSensorchoiceCombo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CSensorSelectionPropPage::OnSetActive()
{
CPropertySheetWithHelp* psheet = (CPropertySheetWithHelp*) GetParent();
psheet->SetWizardButtons(PSWIZB_BACK |PSWIZB_FINISH);
BOOL bRet = CPropertyPageWithHelp::OnSetActive();
OnSelchangeSensorchoiceCombo();
return bRet;
}
void CSensorSelectionPropPage::OnOK()
{
OnWizardFinish();
}
void CSensorSelectionPropPage::AddSensor(LPCTSTR name, int id)
{
int index = m_sensorChoiceCtrl.AddString(name);
m_sensorChoiceCtrl.SetItemData(index, id);
}
BOOL CSensorSelectionPropPage::OnInitDialog()
{
BOOL result = CPropertyPageWithHelp::OnInitDialog();
return result;
}
BOOL CSensorSelectionPropPage::OnWizardFinish()
{
int nSel;
CString strPath;
CString strSubDir;
CString strFileName;
UpdateData(TRUE); // To update values
strPath = GetConfig () -> m_ApplicationPath;
strSubDir = GetFileSubDir ();
if ( ! strSubDir.IsEmpty () )
{
strPath += strSubDir;
strPath += '\\';
}
nSel = m_trainingFileCombo.GetCurSel ();
if ( nSel >= 0 )
{
m_trainingFileCombo.GetLBText ( nSel, strFileName );
m_trainingFileName = strPath + strFileName + ".thc";
}
else
m_trainingFileName.Empty ();
return CPropertyPageWithHelp::OnWizardFinish();
}
UINT CSensorSelectionPropPage::GetHelpId ( LPSTR lpszTopic )
{
return HID_SELECT_SENSOR;
}
LPCSTR CSensorSelectionPropPage::GetThcFileSubDir ( int nSensorID )
{
switch ( nSensorID )
{
case 0:
return "Etalon_HCFR";
case 1:
return "Etalon_Simulation";
case 2:
return "Etalon_S2";
case 3:
return "Etalon_DTP94";
case 4:
return "Etalon_I1";
case 5:
return "Etalon_MTCS";
case 6:
return "Etalon_S3";
default:
return "Etalon_Argyll";
}
}
void CSensorSelectionPropPage::OnSelchangeSensorchoiceCombo()
{
int i, nSel = -1;
BOOL bFileFound;
char szBuf [ 256 ];
LPSTR lpStr;
CString str;
CString strPath;
CString strSubDir;
CString strSearch;
CString strFileName;
HANDLE hFind;
WIN32_FIND_DATA wfd;
UpdateData(TRUE); // To update values
m_trainingFileCombo.ResetContent ();
strPath = GetConfig () -> m_ApplicationPath;
strSubDir = GetFileSubDir ();
if ( ! strSubDir.IsEmpty () )
{
if ( m_currentID < 2)
{
// Sensor needing calibration file
str.LoadString ( IDS_CREATE_CALIBRATION_FILE );
}
else
{
// Sensor accepting calibration file
CheckRadioButton ( IDC_SENSORTRAININGMODE_RADIO2, IDC_SENSORTRAININGMODE_RADIO1, IDC_SENSORTRAININGMODE_RADIO2 );
str.LoadString ( IDS_DONOTUSE_CALIBRATION );
}
GetDlgItem (IDC_SENSORTRAININGMODE_RADIO2) -> SetWindowText ( str );
GetDlgItem (IDC_SENSORTRAININGMODE_RADIO1) -> EnableWindow ( TRUE );
GetDlgItem (IDC_SENSORTRAININGMODE_RADIO2) -> EnableWindow ( TRUE );
m_trainingFileCombo.EnableWindow ( TRUE );
strPath += strSubDir;
strPath += '\\';
GetConfig () -> EnsurePathExists ( strPath );
bFileFound = FALSE;
strSearch = strPath + "*.thc";
hFind = FindFirstFile ( (LPCSTR) strSearch, & wfd );
if ( hFind != INVALID_HANDLE_VALUE )
{
do
{
strcpy ( szBuf, wfd.cFileName );
lpStr = strrchr ( szBuf, '.' );
if ( lpStr )
lpStr [ 0 ] = '\0';
i = m_trainingFileCombo.AddString ( szBuf );
strFileName = strPath + wfd.cFileName;
if ( strFileName == m_trainingFileName )
nSel = i;
bFileFound = TRUE;
} while ( FindNextFile ( hFind, & wfd ) );
FindClose ( hFind );
}
m_trainingFileCombo.SetCurSel ( nSel >= 0 ? nSel : 0 );
if ( ! bFileFound && m_currentID >= 2 && m_currentID < 7)
{
// No calibration file
GetDlgItem (IDC_SENSORTRAININGMODE_RADIO1) -> EnableWindow ( FALSE );
GetDlgItem (IDC_SENSORTRAININGMODE_RADIO2) -> EnableWindow ( FALSE );
m_trainingFileCombo.EnableWindow ( FALSE );
}
}
else
{
str.LoadString ( IDS_DONOTUSE_CALIBRATION );
GetDlgItem (IDC_SENSORTRAININGMODE_RADIO2) -> SetWindowText ( str );
CheckRadioButton ( IDC_SENSORTRAININGMODE_RADIO2, IDC_SENSORTRAININGMODE_RADIO1, IDC_SENSORTRAININGMODE_RADIO2 );
GetDlgItem (IDC_SENSORTRAININGMODE_RADIO1) -> EnableWindow ( FALSE );
GetDlgItem (IDC_SENSORTRAININGMODE_RADIO2) -> EnableWindow ( FALSE );
m_trainingFileCombo.SetCurSel ( -1 );
m_trainingFileCombo.EnableWindow ( FALSE );
}
}