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
|
// vtkSDIView.cpp : implementation of the CvtkSDIView class
//
#include "stdafx.h"
#include "vtkSDI.h"
#include "vtkSDIDoc.h"
#include "vtkSDIView.h"
#include "vtkCallbackCommand.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CvtkSDIView
IMPLEMENT_DYNCREATE(CvtkSDIView, CView)
BEGIN_MESSAGE_MAP(CvtkSDIView, CView)
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_ERASEBKGND()
ON_WM_SIZE()
END_MESSAGE_MAP()
// CvtkSDIView construction/destruction
CvtkSDIView::CvtkSDIView()
{
this->pvtkMFCWindow = NULL;
// Create the the renderer, window and interactor objects.
this->pvtkRenderer = vtkRenderer::New();
}
CvtkSDIView::~CvtkSDIView()
{
// delete generic vtk window
if (this->pvtkMFCWindow) delete this->pvtkMFCWindow;
}
void CvtkSDIView::OnDraw(CDC* pDC)
{
CvtkSDIDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (this->pvtkMFCWindow)
{
if (pDC->IsPrinting())
this->pvtkMFCWindow->DrawDC(pDC);
}
}
// CvtkSDIView printing
BOOL CvtkSDIView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CvtkSDIView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CvtkSDIView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
// CvtkSDIView diagnostics
#ifdef _DEBUG
void CvtkSDIView::AssertValid() const
{
CView::AssertValid();
}
void CvtkSDIView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CvtkSDIDoc* CvtkSDIView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CvtkSDIDoc)));
return (CvtkSDIDoc*)m_pDocument;
}
#endif //_DEBUG
// CvtkSDIView message handlers
int CvtkSDIView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
void CvtkSDIView::OnDestroy()
{
// Delete the the renderer, window and interactor objects.
if (this->pvtkRenderer) this->pvtkRenderer->Delete();
// destroy base
CView::OnDestroy();
}
BOOL CvtkSDIView::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
void CvtkSDIView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if (this->pvtkMFCWindow)
this->pvtkMFCWindow->MoveWindow(0, 0, cx, cy);
}
static void handle_double_click(vtkObject* obj, unsigned long,
void*, void*)
{
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::SafeDownCast(obj);
if(iren && iren->GetRepeatCount())
{
AfxMessageBox("Double Click");
}
}
void CvtkSDIView::OnInitialUpdate()
{
CView::OnInitialUpdate();
if (this->pvtkMFCWindow) delete this->pvtkMFCWindow;
this->pvtkMFCWindow = new vtkMFCWindow(this);
this->pvtkMFCWindow->GetRenderWindow()->AddRenderer(this->pvtkRenderer);
// get double click events
vtkCallbackCommand* callback = vtkCallbackCommand::New();
callback->SetCallback(handle_double_click);
this->pvtkMFCWindow->GetInteractor()->AddObserver(vtkCommand::LeftButtonPressEvent, callback, 1.0);
callback->Delete();
}
|