-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOnStationDoc.cpp
More file actions
241 lines (209 loc) · 5.1 KB
/
Copy pathOnStationDoc.cpp
File metadata and controls
241 lines (209 loc) · 5.1 KB
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
// OnStationDoc.cpp : implementation of the COnStationDoc class
//
#include "stdafx.h"
#include "OnStation.h"
#include "OnStationDoc.h"
#include "realfolder.h"
#include "surfacedata.h"
#include "surveyleg.h"
#include "colortool.h"
#include "nodetree.h"
#include "saveformattedtext.h"
#include "pagelayoutpreferences.h"
#include "overalldataview.h"
#include "mainfrm.h"
#include "filehelper.h"
#include "onstationview.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern COnStationApp theApp;
COnStationDoc * pDocument_G=NULL;
extern COnStationView * pView_G;
extern CSettings * pSettings_G;
/////////////////////////////////////////////////////////////////////////////
// COnStationDoc
IMPLEMENT_DYNCREATE(COnStationDoc, CDocument)
BEGIN_MESSAGE_MAP(COnStationDoc, CDocument)
//{{AFX_MSG_MAP(COnStationDoc)
ON_COMMAND(ID_FILE_IMPORT, OnFileImport)
ON_COMMAND(ID_FILE_EXPORTFORMATTEDTEXT, OnFileSaveFormattedText)
ON_COMMAND(ID_INSERT_FILE,OnInsertFile)
//}}AFX_MSG_MAP
ON_COMMAND(ID_FILE_SENDMAIL,OnFileSendMail)
ON_UPDATE_COMMAND_UI(ID_FILE_SENDMAIL,OnUpdateFileSendMail)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COnStationDoc construction/destruction
COnStationDoc::COnStationDoc()
{
#ifdef _DEBUG
ASSERT(AfxCheckMemory());
#endif
pDocument_G=this;
m_SurveyDataFolder=new CRealFolder(this);
CString CS;
CS.LoadString(IDS_SURVEYROOT);
m_SurveyDataFolder->SetName(CS);
m_SurfaceData=new CSurfaceData(this);
m_NodeTree=new CNodeTree(this);
#ifdef _DEBUG
ASSERT(AfxCheckMemory());
#endif
}
COnStationDoc::~COnStationDoc()
{
#ifdef _DEBUG
ASSERT(AfxCheckMemory());
#endif
delete m_SurveyDataFolder;
m_SurveyDataFolder=NULL;
delete m_SurfaceData;
m_SurfaceData=NULL;
delete m_NodeTree;
m_NodeTree=NULL;
}
void COnStationDoc::DeleteContents()
{
pSettings_G->ResetContents();
CMainFrame * pFrame=dynamic_cast<CMainFrame *>(AfxGetMainWnd());
if (pFrame)
{
pFrame->m_dataView.RemoveAll();
}
m_SurveyDataFolder->DeleteContents();
m_NodeTree->DeleteContents();
m_SurfaceData->DeleteContents();
if (pView_G!=NULL)
{
pView_G->DeleteContents();
}
CString CS;
CS.LoadString(IDS_SURVEYROOT);
m_SurveyDataFolder->SetName(CS);
}
/////////////////////////////////////////////////////////////////////////////
// COnStationDoc serialization
void COnStationDoc::Serialize(CArchive& ar)
{
try
{
CFileHelper f(&ar);
if (ar.IsStoring())
{
Write(&f);
}
else
{
Read(&f,FALSE);
}
}
catch (void *)
{
AfxMessageBox(IDS_UNABLETOOPENFILE);
DeleteContents();
CString CS;
CS.LoadString(IDS_UNTITLED);
SetTitle(CS);
}
}
void COnStationDoc::Write(CFileHelper *h)
{
h->WriteToken("FileVersion","2.0");
h->WriteToken("Program","On Station 3.0a");
m_SurveyDataFolder->Write(h);
m_SurfaceData->WriteFixedPoints(h);
m_SurfaceData->Write(h);
pSettings_G->Write(h);
}
void COnStationDoc::Read(CFileHelper * h,BOOL bInsertFile)
{
float fDataVersion=h->ReadTokenFloat("FileVersion");
h->m_fVersion=fDataVersion;
LPCSTR szProgram=h->ReadTokenString("Program");
if (lstrcmpi(szProgram,"On Station")==0)
{
AfxMessageBox(IDS_OLDFORMATUSETRANSLATOR);
return;
}
if (fDataVersion>CURRENT_VERSION)
{
AfxMessageBox(IDS_FILEOPENLATERVERSION);
}
if (bInsertFile)
{
CRealFolder * pNew=new CRealFolder(this);
pNew->Read(h);
pNew->SetParentFolder(m_SurveyDataFolder,NULL);
}
else
{
m_SurveyDataFolder->Read(h);
m_SurfaceData->ReadFixedPoints(h);
m_SurfaceData->ReadSurface(h);
pSettings_G->Read(h);
if (pView_G!=NULL)
{
pView_G->PostMessage(WM_COMMAND,ID_DRAWMODE_COLORSCHEME1,0l);
}
}
}
/////////////////////////////////////////////////////////////////////////////
// COnStationDoc diagnostics
#ifdef _DEBUG
void COnStationDoc::AssertValid() const
{
CDocument::AssertValid();
}
void COnStationDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
void COnStationDoc::OnFileImport()
{
if (WinExec("importapp.exe",SW_SHOW)==ERROR_FILE_NOT_FOUND)
{
AfxMessageBox(IDS_NO_IMPORT_EXE);
}
}
void COnStationDoc::OnFileSaveFormattedText()
{
CSaveFormattedText PSD(this);
PSD.DoModal();
}
BOOL COnStationDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
void COnStationDoc::OnInsertFile()
{
CFileDialog fd(TRUE,"*.cdi",NULL,OFN_FILEMUSTEXIST,"Cave Data Interchange|*.cdi||");
if (fd.DoModal()==IDOK)
{
try
{
CString Cs=fd.GetPathName();
CFile file(Cs,CFile::modeRead);
CArchive archive(&file,CArchive::load);
CFileHelper f(&archive);
Read(&f,TRUE);
CMainFrame * pFrame=dynamic_cast<CMainFrame *>(AfxGetMainWnd());
if (pFrame)
{
pFrame->m_dataView.OnChangedDocumentData();
}
}
catch (void *)
{
AfxMessageBox(IDS_UNABLETOOPENFILE);
SetTitle("Untitled");
}
}
}