-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHDFPluginTreeView.cpp
More file actions
executable file
·443 lines (351 loc) · 11.4 KB
/
Copy pathHDFPluginTreeView.cpp
File metadata and controls
executable file
·443 lines (351 loc) · 11.4 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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
// HDFPluginTreeView.cpp : implementation of the CHDFPluginTreeView class
//
#include "stdafx.h"
#include "afxpriv.h" //WM_INITIALUPDATE
#include "HDFPlugin.h"
#include "HDFPluginDoc.h"
#include "HDFPluginTreeView.h"
#include "HDFPluginMainFrm.h"
#include "HdfObj.h"
#include "HdfObjDataset.h"
#include "HdfObjGroup.h"
#include "TableView.h"
#include "ImageView.h"
#include "TextView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHDFPluginTreeView
IMPLEMENT_DYNCREATE(CHDFPluginTreeView, CTreeView)
BEGIN_MESSAGE_MAP(CHDFPluginTreeView, CTreeView)
//{{AFX_MSG_MAP(CHDFPluginTreeView)
ON_WM_LBUTTONDBLCLK()
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CTreeView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CTreeView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CTreeView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHDFPluginTreeView construction/destruction
CHDFPluginTreeView::CHDFPluginTreeView()
{
// TODO: add construction code here
imgList = 0;
m_pCurrentFile = NULL;
m_pTableView = NULL;
m_pImageView = NULL;
m_pTextView = NULL;
}
CHDFPluginTreeView::~CHDFPluginTreeView()
{
if (imgList)
{
delete imgList;
imgList = 0;
}
}
BOOL CHDFPluginTreeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CTreeView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CHDFPluginTreeView drawing
void CHDFPluginTreeView::OnDraw(CDC* pDC)
{
CHDFPluginDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CHDFPluginTreeView printing
BOOL CHDFPluginTreeView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CHDFPluginTreeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CHDFPluginTreeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CHDFPluginTreeView diagnostics
#ifdef _DEBUG
void CHDFPluginTreeView::AssertValid() const
{
CTreeView::AssertValid();
}
void CHDFPluginTreeView::Dump(CDumpContext& dc) const
{
CTreeView::Dump(dc);
}
CHDFPluginDoc* CHDFPluginTreeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHDFPluginDoc)));
return (CHDFPluginDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHDFPluginTreeView message handlers
void CHDFPluginTreeView::LoadBitmaps()
{
// Create the CImageList. It's destroyed in the destructor.
imgList = new CImageList();
imgList->Create(BITMAP_WIDTH, BITMAP_HEIGHT, ILC_COLOR8, BITMAP_COUNT, 0);
CBitmap bitmap;
// Load the bitmaps and add them to the image list.
for (int i = 0; i < BITMAP_COUNT; i++)
{
bitmap.LoadBitmap(IDB_BITMAP_HDF+i);
imgList->Add(&bitmap, (COLORREF)0xFFFFFF);
bitmap.DeleteObject();
}
// Associate the image list with the tree control.
GetTreeCtrl().SetImageList(imgList, LVSIL_NORMAL);
}
void CHDFPluginTreeView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
GetTreeCtrl().ModifyStyle(NULL, TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
LoadBitmaps();
CDocument* pDoc = GetDocument();
if (pDoc != NULL)
{
CString strFile = pDoc->GetPathName();
if (strFile.GetLength()>0)
{
// close the old file
if (m_pCurrentFile)
m_pCurrentFile->Close();
CFileFormat* currentFile = CFileFormat::CreateInstance(strFile);
ShowFileTree(currentFile);
m_pCurrentFile = currentFile;
}
}
}
void CHDFPluginTreeView::TraverseInsertNodes(HTREEITEM parentNode, CGroup* pParentGroup)
{
CTreeCtrl & ctc = GetTreeCtrl();
HTREEITEM node;
CHObject* pObj;
oid_t* pOID = NULL;
if (!pParentGroup)
return;
int n = pParentGroup->GetSize();
for (int i=0; i<n; i++)
{
pOID = (oid_t*)malloc(sizeof(oid_t));
pObj = pParentGroup->Get(i);
*pOID = pObj->GetObjectID();
switch(pObj->GetType())
{
case CHObject::HDF_GROUP:
node = ctc.InsertItem(pObj->GetName(), BITMAP_INDEX_HDF_NODE_OPEN, BITMAP_INDEX_HDF_NODE_OPEN, parentNode);
TraverseInsertNodes(node, (CGroup *)pObj);
ctc.SetItemData(node, (DWORD)pOID);
break;
case CHObject::HDF_DATASET_ATOMIC:
node = ctc.InsertItem(pObj->GetName(), BITMAP_INDEX_HDF_DATASET, BITMAP_INDEX_HDF_DATASET, parentNode);
ctc.SetItemData(node, (DWORD)pOID);
break;
case CHObject::HDF_DATASET_COMPOUND:
node = ctc.InsertItem(pObj->GetName(), BITMAP_INDEX_HDF_TABLE, BITMAP_INDEX_HDF_TABLE, parentNode);
ctc.SetItemData(node, (DWORD)pOID);
break;
case CHObject::HDF_DATASET_IMAGE:
node = ctc.InsertItem(pObj->GetName(), BITMAP_INDEX_HDF_IMAGE, BITMAP_INDEX_HDF_IMAGE, parentNode);
ctc.SetItemData(node, (DWORD)pOID);
break;
}
}
ctc.Expand(parentNode, TVE_EXPAND); // expand all nodes
}
void CHDFPluginTreeView::ShowFileTree(CFileFormat* pFile)
{
if (!pFile)
return;
CTreeCtrl & ctc = GetTreeCtrl();
ctc.DeleteAllItems(); // delete all the old items. prepare for the new tree
HTREEITEM hSubTree = NULL;
CGroup* pRootGroup = pFile->GetRootGroup();
oid_t* pOID = (oid_t*)malloc(sizeof(oid_t));
if (pFile->GetFileType() == CFileFormat::SUPPORTED_FILE_TYPE_NCSA_HDF5)
hSubTree = ctc.InsertItem(pRootGroup->GetName(), BITMAP_INDEX_HDF_5, BITMAP_INDEX_HDF_5);
else
hSubTree = ctc.InsertItem(pRootGroup->GetName(), BITMAP_INDEX_HDF_4, BITMAP_INDEX_HDF_4);
*pOID = pRootGroup->GetObjectID();
ctc.SetItemData(hSubTree, (DWORD)pOID);
TraverseInsertNodes(hSubTree, pFile->GetRootGroup());
ctc.UpdateWindow();
}
void CHDFPluginTreeView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (!m_pCurrentFile)
return;
CGroup* pRootGroup = m_pCurrentFile->GetRootGroup();
if (!pRootGroup)
return;
CTreeCtrl &ctc = GetTreeCtrl();
HTREEITEM hitem = ctc.HitTest( point, &nFlags );;
if (hitem == NULL)
return;
oid_t* pOID = (oid_t*) ctc.GetItemData(hitem);
CHObject* pObj = pRootGroup->FindDown(*pOID);
if (pObj)
{
BeginWaitCursor();
switch (pObj->GetType())
{
case CHObject::HDF_DATASET_ATOMIC:
case CHObject::HDF_DATASET_COMPOUND:
ShowTableView((CDataset*)pObj);
break;
case CHObject::HDF_DATASET_IMAGE:
ShowImageView((CImageDS*)pObj);
break;
}
EndWaitCursor();
}
CTreeView::OnLButtonDblClk(nFlags, point);
}
void CHDFPluginTreeView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// TODO: Add your message handler code here and/or call default
if (!m_pCurrentFile)
return;
CGroup* pRootGroup = m_pCurrentFile->GetRootGroup();
if (!pRootGroup)
return;
UINT hitflags;
CTreeCtrl &ctc = GetTreeCtrl();
HTREEITEM hitem = ctc.HitTest( point, &hitflags ) ;
if (hitem == NULL)
return;
if ( hitflags & (TVHT_ONITEM | TVHT_ONITEMBUTTON ))
ctc.Select( hitem, TVGN_CARET );
oid_t* pOID = (oid_t*) ctc.GetItemData(hitem);
CHObject* pObj = pRootGroup->FindDown(*pOID);
if (pObj)
{
BeginWaitCursor();
ShowMetaData(pObj);
EndWaitCursor();
}
CTreeView::OnRButtonDown(nFlags, point);
}
void CHDFPluginTreeView::ShowTableView(CDataset* pDataset)
{
CSplitterWnd* pSplitter = (CSplitterWnd *)GetParent();
CHDFPluginDoc* pDoc = GetDocument();
if (!m_pTableView)
{
// create the new view
m_pTableView = new CTableView;
m_pTableView->Create(NULL, "Table View", AFX_WS_DEFAULT_VIEW,
CRect(0, 0, 0, 0), pSplitter, 0, NULL);
}
CHDFPluginMainFrame* pFrame = (CHDFPluginMainFrame *)((CHDFPluginApp*)AfxGetApp())->m_pMainWnd;
CView* pActiveView = (CView *)pFrame->GetRightPane();
if (pActiveView != m_pTableView)
{
SwitchRightPane(m_pTableView);
}
CDataset* pOldDataset = m_pTableView->GetDataset();
if (pOldDataset != pDataset)
{
m_pTableView->SetDataset(pDataset);
}
}
void CHDFPluginTreeView::ShowImageView(CImageDS* pDataset)
{
CSplitterWnd* pSplitter = (CSplitterWnd *)GetParent();
CHDFPluginDoc* pDoc = GetDocument();
if (!m_pImageView)
{
// create the new view
m_pImageView = new CImageView;
m_pImageView->Create(NULL, "Image View", AFX_WS_DEFAULT_VIEW,
CRect(0, 0, 0, 0), pSplitter, 0, NULL);
}
CHDFPluginMainFrame* pFrame = (CHDFPluginMainFrame *)((CHDFPluginApp*)AfxGetApp())->m_pMainWnd;
CView* pActiveView = (CView *)pFrame->GetRightPane();
if (pActiveView != m_pImageView)
{
SwitchRightPane(m_pImageView);
}
CImageDS* pOldDataset = m_pImageView->GetImageDS();
if (pOldDataset != pDataset)
{
m_pImageView->SetImageDS(pDataset);
}
}
void CHDFPluginTreeView::ShowMetaData(CHObject* pObj)
{
if (!pObj)
return;
CSplitterWnd* pSplitter = (CSplitterWnd *)GetParent();
CHDFPluginDoc* pDoc = GetDocument();
if (!m_pTextView)
{
// create the new view
m_pTextView = new CTextView;
m_pTextView->Create(NULL, "Text View", AFX_WS_DEFAULT_VIEW,
CRect(0, 0, 0, 0), pSplitter, 0, NULL);
}
CHDFPluginMainFrame* pFrame = (CHDFPluginMainFrame *)((CHDFPluginApp*)AfxGetApp())->m_pMainWnd;
CView* pActiveView = (CView *)pFrame->GetRightPane();
if (pActiveView != m_pTextView)
{
SwitchRightPane(m_pTextView);
}
CHObject* pOldObj = m_pTextView->GetObj();
if (pOldObj != pObj)
{
m_pTextView->SetObj(pObj);
}
}
CView* CHDFPluginTreeView::SwitchRightPane(CView *pNewView)
{
// modified from http://www.codeproject.com/docview/switchingviews.asp
CHDFPluginMainFrame* pFrame = (CHDFPluginMainFrame *)((CHDFPluginApp*)AfxGetApp())->m_pMainWnd;
CView* pOldActiveView = (CView *)pFrame->GetRightPane();
if (pOldActiveView == pNewView)
return pOldActiveView;
CSplitterWnd* pSplitter = (CSplitterWnd *)pOldActiveView->GetParent();
CDocument* pDoc = GetDocument();
// set flag so that document will not be deleted when view is destroyed
pDoc->m_bAutoDelete = FALSE;
// Dettach existing view
pDoc->RemoveView(pOldActiveView);
// set flag back to default
pDoc->m_bAutoDelete = TRUE;
/* Set the child window ID of the active view to the ID of the corresponding
pane. Set the child ID of the previously active view to some other ID.
*/
::SetWindowLong(pOldActiveView->m_hWnd, GWL_ID, 0);
::SetWindowLong(pNewView->m_hWnd, GWL_ID, pSplitter->IdFromRowCol(0, 1));
// Show the newly active view and hide the inactive view.
pNewView->ShowWindow(SW_SHOW);
pOldActiveView->ShowWindow(SW_HIDE);
// Attach new view
pDoc->AddView(pNewView);
// Set active
pSplitter->GetParentFrame()->SetActiveView(pNewView);
pSplitter->RecalcLayout();
pNewView->SendMessage(WM_INITIALUPDATE);
pNewView->SendMessage(WM_PAINT);
return pOldActiveView;
}