-
Notifications
You must be signed in to change notification settings - Fork 2
/
ColorEyeIDoc.cpp
357 lines (296 loc) · 9.25 KB
/
ColorEyeIDoc.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
// ColorEyeIDoc.cpp : implementation of the CColorEyeIDoc class
//
#include "stdafx.h"
#include "ColorEyeI.h"
#include "ColorEyeIDoc.h"
#include "FileDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CColorEyeIDoc
IMPLEMENT_DYNCREATE(CColorEyeIDoc, CDocument)
BEGIN_MESSAGE_MAP(CColorEyeIDoc, CDocument)
//{{AFX_MSG_MAP(CColorEyeIDoc)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CColorEyeIDoc, CDocument)
//{{AFX_DISPATCH_MAP(CColorEyeIDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_IColorEyeI to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {103A7CC5-072F-4C0A-9681-F1B5DF57C9E1}
static const IID IID_IColorEyeI =
{ 0x103a7cc5, 0x72f, 0x4c0a, { 0x96, 0x81, 0xf1, 0xb5, 0xdf, 0x57, 0xc9, 0xe1 } };
BEGIN_INTERFACE_MAP(CColorEyeIDoc, CDocument)
INTERFACE_PART(CColorEyeIDoc, IID_IColorEyeI, Dispatch)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CColorEyeIDoc construction/destruction
CColorEyeIDoc::CColorEyeIDoc()
{
// TODO: add one-time construction code here
EnableAutomation();
AfxOleLockApp();
}
CColorEyeIDoc::~CColorEyeIDoc()
{
AfxOleUnlockApp();
}
/////////////////////////////////////////////////////////////////////////////
// CColorEyeIDoc serialization
void CColorEyeIDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CColorEyeIDoc diagnostics
#ifdef _DEBUG
void CColorEyeIDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CColorEyeIDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif
/////////////////////////////////////////////////////////////////////////////
// CColorEyeIDoc commands
void CColorEyeIDoc::OnFileNew()
{
// TODO: Add your command handler code here
//開新檔案
CDocument::OnNewDocument(); //開新檔後的存檔,判斷它是不是空字串,決定要不要SaveAs
SetTitle("新的Omd檔");
m_docFileHead.Empty();
// m_docDNA.Empty();
m_docRNA.Empty();
SetModifiedFlag(FALSE);
UpdateAllViews(NULL); //更新畫面
}
BOOL CColorEyeIDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
//第一次執行時會執行這個
CColorEyeIDoc::OnFileNew();
return TRUE;
}
BOOL CColorEyeIDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
//點兩下會執行這個
OnNewDocument();
// OpenOmdFile(lpszPathName);
SetPathName(lpszPathName);
SetTitle(lpszPathName);
SetModifiedFlag(FALSE);
UpdateAllViews(NULL); //更新畫面
return TRUE;
}
//////////////////////////////////////////////////////////////////////////
// Txt and Omd file process
//////////////////////////////////////////////////////////////////////////
void CColorEyeIDoc::OnFileOpen()
{
// TODO: Add your command handler code here
// openTxtDlg("Text File(*.txt)|*.txt|All Files (*.*)|*.* ||");
openOmdDlg("OrigMsrData Files (*.omd)|*.omd|Text File(*.txt)|*.txt|All Files (*.*)|*.* ||");
}
void CColorEyeIDoc::OnFileSaveAs()
{
// TODO: Add your command handler code here
// saveTxtDlg("Text File(*.txt)|*.txt|All Files (*.*)|*.* ||");
saveOmdDlg("OrigMsrData Files (*.omd)|*.omd|Text File(*.txt)|*.txt|All Files (*.*)|*.* ||");
}
//////////////////////////////////////////////////////////////////////////
void CColorEyeIDoc::openTxtDlg(LPCTSTR FileFilter)
{
CFileDlg aFileDialog (TRUE, "txt", "*.txt", OFN_SHAREAWARE | OFN_OVERWRITEPROMPT, FileFilter);
int nID = aFileDialog.DoModal();
if (nID == IDOK)
{
// m_docDNA.Empty();
m_docRNA.Empty();
m_docFileHead.Empty();
SetModifiedFlag(FALSE);
UpdateAllViews(NULL);
openTxtFile(aFileDialog.GetPathName());
SetPathName(aFileDialog.GetPathName());
SetTitle(aFileDialog.GetFileName());
}
}
void CColorEyeIDoc::saveTxtDlg(LPCTSTR FileFilter)
{
CFileDlg aFileDialog (FALSE, "txt", "*.txt", OFN_SHAREAWARE, FileFilter);
int nID = aFileDialog.DoModal();
if (nID == IDOK)
{
saveTxtFile(aFileDialog.GetPathName());
SetPathName(aFileDialog.GetPathName());
SetTitle(aFileDialog.GetFileName());
SetModifiedFlag(FALSE);
}
}
void CColorEyeIDoc::openTxtFile(LPCTSTR FilePathName)
{
CTxtFile f_txt;
if(!f_txt.Open(FilePathName, m_ErrorFx))
AfxMessageBox("檔案開啟錯誤!!");
else
{
f_txt.oTxtData(m_TextData);
f_txt.Close();
}
}
void CColorEyeIDoc::saveTxtFile(LPCTSTR FilePathName)
{
CTxtFile f_txt;
if (!f_txt.Save(FilePathName, m_ErrorFx))
AfxMessageBox("路徑有問題!!!");
else
{
f_txt.iTxtData(m_TextData);
f_txt.Close();
}
}
//////////////////////////////////////////////////////////////////////////
void CColorEyeIDoc::openOmdDlg(LPCTSTR FileFilter)
{
CFileDialog aFileDialog (TRUE, NULL, NULL, OFN_SHAREAWARE | OFN_OVERWRITEPROMPT, FileFilter);
int nID = aFileDialog.DoModal();
if (nID == IDOK)
{
// m_docDNA.Empty();
m_docRNA.Empty();
m_docFileHead.Empty();
openOmdFile(aFileDialog.GetPathName());
SetPathName(aFileDialog.GetPathName());
SetTitle(aFileDialog.GetFileName());
SetModifiedFlag(FALSE);
UpdateAllViews(NULL);
}
}
void CColorEyeIDoc::saveOmdDlg(LPCTSTR FileFilter)
{
CFileDialog aFileDialog (FALSE, "omd", "*.omd", OFN_SHAREAWARE, FileFilter);
int nID = aFileDialog.DoModal();
if (nID == IDOK)
{
saveOmdFile(aFileDialog.GetPathName());
debugByTxt(aFileDialog.GetPathName());
SetPathName(aFileDialog.GetPathName());
SetTitle(aFileDialog.GetFileName());
SetModifiedFlag(FALSE);
}
}
void CColorEyeIDoc::openOmdFile(LPCTSTR FilePathName)
{
BeginWaitCursor();
COmdFile0 ft_Omd;
if(!ft_Omd.Open(FilePathName, m_ErrorFx))
AfxMessageBox("路徑有問題");
else
{
m_docRNA = ft_Omd.oOmdData();
m_docFileHead = ft_Omd.GetFileHead();
ft_Omd.Close();
}
EndWaitCursor();
}
void CColorEyeIDoc::saveOmdFile(LPCTSTR FilePathName)
{
COmdFile0 f_Omd;
if(!f_Omd.Save(FilePathName, m_ErrorFx, m_docRNA))
AfxMessageBox("路徑有問題!!");
else
{
f_Omd.SetFileHead(m_docFileHead);
f_Omd.iOmdData (m_docRNA);
f_Omd.Close();
}
}
//////////////////////////////////////////////////////////////////////////
void CColorEyeIDoc::OnFileSave()
{
// TODO: Add your command handler code here
// SetPathName()
if (GetPathName().IsEmpty()) //若還沒有存過的檔
OnFileSaveAs(); //就另存新檔
else
{
SetModifiedFlag(FALSE);
// saveTxtFile(GetPathName());
saveOmdFile(GetPathName());
}
SetModifiedFlag(FALSE);
}
void CColorEyeIDoc::debugByTxt(CString pathName)
{
std::vector<CString> vStr;
CString str;
str.IsEmpty();
vStr.clear();
str.Format("點位描述\tLv\tx\ty\tdu\tdv\tT\tDuv\tX\tY\tZ\t量測時間\n");
vStr.push_back(str);
for (std::vector<Cartridge2>::iterator iter = m_docRNA.Begin(); iter != m_docRNA.End(); ++iter)
{
str.Format("%s\t%s\t%s\t\n", iter->GetDescrip(), iter->GetBullet().ShowData(), iter->GetBullet().GetLastTime());
vStr.push_back(str);
}
CStdioFile file;
CFileException fx;
pathName.Format("%s_debug.omd", pathName.Left(pathName.GetLength()-4));
if (!file.Open(pathName, CFile::modeCreate | CFile::modeWrite | CFile::typeText, &fx))
{
TCHAR buf[255];
fx.GetErrorMessage(buf, 255);
CString strPrompt(buf);
AfxMessageBox(strPrompt);
}
else
{
if (!vStr.empty())
for (std::vector<CString>::iterator it = vStr.begin(); it != vStr.end(); ++it)
file.WriteString(it->GetBuffer(0));
file.Close();
}
}
//////////////////////////////////////////////////////////////////////////
void CColorEyeIDoc::UpdateDocRNA(const RNA& _docRNA)
{
m_docRNA.CutEqualCell(_docRNA);
m_docRNA.AddCell(_docRNA);
}
void CColorEyeIDoc::UpdateMsrRNA(const RNA& _msrRNA)
{ m_MsrRNA.Empty(); m_MsrRNA.AddCell(_msrRNA); }
void CColorEyeIDoc::UpdateDocDNA(const DNA& _docDNA)
{ m_docFileHead.iDNA(_docDNA); }
OmdHead& CColorEyeIDoc::GetFileHead()
{ return m_docFileHead; };
const OmdHead CColorEyeIDoc::GetFileHead() const
{ return m_docFileHead; };
void CColorEyeIDoc::SetFileHead(const OmdHead& _H)
{ m_docFileHead = _H; };