Commit 7a8702ed authored by Clinton Stimpson's avatar Clinton Stimpson

ENH: Add dialog example application.

parent 3f9bfc86
......@@ -9,4 +9,5 @@ INCLUDE(${VTK_USE_FILE})
SUBDIRS(
vtkMDI
vtkSDI
vtkDLG
)
SET( vtkDLG_SRCS
StdAfx
vtkDLG
vtkDLGDlg
vtkDLG.rc
res/vtkDLG.ico
res/vtkDLG.rc2
)
LINK_LIBRARIES(
vtkMFC
vtkRendering
vtkGraphics
vtkImaging
vtkIO
vtkFiltering
vtkCommon
)
# add stuff to use MFC in this executable
ADD_DEFINITIONS(-D_AFXDLL)
SET(CMAKE_MFC_FLAG 6)
ADD_EXECUTABLE(vtkDLG WIN32 ${vtkDLG_SRCS})
//
// vtkDLG.RC2 - resources Microsoft Visual C++ does not edit directly
//
#ifdef APSTUDIO_INVOKED
#error this file is not editable by Microsoft Visual C++
#endif //APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
// Add manually edited resources here...
/////////////////////////////////////////////////////////////////////////////
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by vtkDLG.rc
//
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDD_VTKDLG_DIALOG 102
#define ID_LOADFILE 103
#define ID_LOADFILE2 104
#define ID_RESETSCENE 105
#define IDR_MAINFRAME 128
#define IDC_MAIN_WND 1000
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 106
#endif
#endif
// stdafx.cpp : source file that includes just the standard includes
// vtkDLG.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later.
#endif
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
// turns off MFC's hiding of some common and often safely ignored warning messages
#define _AFX_ALL_WARNINGS
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
// Include the required header files for the vtk classes we are using
#include <vtkDataSetReader.h>
#include <vtkDataSetMapper.h>
#include <vtkActor.h>
#include <vtkActor2D.h>
#include <vtkTextMapper.h>
#include <vtkRenderer.h>
#include <vtkWin32OpenGLRenderWindow.h>
#include <vtkWin32RenderWindowInteractor.h>
#include <vtkTextProperty.h>
// vtkDLG.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "vtkDLG.h"
#include "vtkDLGDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CvtkDLGApp
BEGIN_MESSAGE_MAP(CvtkDLGApp, CWinApp)
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
// CvtkDLGApp construction
CvtkDLGApp::CvtkDLGApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CvtkDLGApp object
CvtkDLGApp theApp;
// CvtkDLGApp initialization
BOOL CvtkDLGApp::InitInstance()
{
// InitCommonControls() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
InitCommonControls();
CWinApp::InitInstance();
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need
// Change the registry key under which our settings are stored
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
CvtkDLGDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
// vtkDLG.h : main header file for the PROJECT_NAME application
//
#pragma once
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
// CvtkDLGApp:
// See vtkDLG.cpp for the implementation of this class
//
class CvtkDLGApp : public CWinApp
{
public:
CvtkDLGApp();
// Overrides
public:
virtual BOOL InitInstance();
// Implementation
DECLARE_MESSAGE_MAP()
};
extern CvtkDLGApp theApp;
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// German (Germany) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU)
#ifdef _WIN32
LANGUAGE LANG_GERMAN, SUBLANG_GERMAN
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#include ""res\\vtkDLG.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#endif\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDR_MAINFRAME ICON "res\\vtkDLG.ico"
#endif // German (Germany) resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_ABOUTBOX DIALOGEX 0, 0, 235, 55
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
WS_SYSMENU
CAPTION "About vtkDLG"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
LTEXT "vtkDLG Version 1.0",IDC_STATIC,40,10,119,8,SS_NOPREFIX
LTEXT "Copyright (C) 2004",IDC_STATIC,40,25,119,8
DEFPUSHBUTTON "OK",IDOK,178,7,50,16,WS_GROUP
END
IDD_VTKDLG_DIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP |
WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW
CAPTION "vtkDLG"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,7,7,50,16
CONTROL "",IDC_MAIN_WND,"Static",SS_OWNERDRAW,65,7,248,186
PUSHBUTTON "Load File",ID_LOADFILE,7,36,50,16
PUSHBUTTON "Reset Scene",ID_RESETSCENE,7,65,50,16
END
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "CompanyName", "TODO: <Company name>"
VALUE "FileDescription", "TODO: <File description>"
VALUE "FileVersion", "1.0.0.1"
VALUE "InternalName", "vtkDLG.exe"
VALUE "LegalCopyright", "TODO: (c) <Company name>. All rights reserved."
VALUE "OriginalFilename", "vtkDLG.exe"
VALUE "ProductName", "TODO: <Product name>"
VALUE "ProductVersion", "1.0.0.1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1252
END
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 228
TOPMARGIN, 7
BOTTOMMARGIN, 48
END
IDD_VTKDLG_DIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 313
TOPMARGIN, 7
BOTTOMMARGIN, 193
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_ABOUTBOX "&About vtkDLG..."
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#pragma code_page(1252)
#include "res\vtkDLG.rc2" // non-Microsoft Visual C++ edited resources
#include "afxres.rc" // Standard components
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
<
// vtkDLGDlg.cpp : implementation file
//
#include "stdafx.h"
#include "vtkDLG.h"
#include "vtkDLGDlg.h"
#include "vtkCallbackCommand.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CvtkDLGDlg dialog
CvtkDLGDlg::CvtkDLGDlg(CWnd* pParent /*=NULL*/)
: CDialog(CvtkDLGDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
this->pvtkMFCWindow = NULL;
// set data reader to null
this->pvtkDataSetReader = NULL;
// Create the the renderer, window and interactor objects.
this->pvtkRenderer = vtkRenderer::New();
// Create the the objects used to form the visualisation.
this->pvtkDataSetMapper = vtkDataSetMapper::New();
this->pvtkActor = vtkActor::New();
this->pvtkActor2D = vtkActor2D::New();
this->pvtkTextMapper = vtkTextMapper::New();
this->ptBorder = CPoint(0,0);
}
void CvtkDLGDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CvtkDLGDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_WM_DESTROY()
ON_WM_SIZE()
ON_BN_CLICKED(ID_LOADFILE, OnBtnLoadFile)
ON_BN_CLICKED(ID_RESETSCENE, OnBtnResetScene)
END_MESSAGE_MAP()
// CvtkDLGDlg message handlers
void CvtkDLGDlg::ExecutePipeline()
{
if (pvtkDataSetReader) // have file
{
this->pvtkDataSetMapper->SetInput(pvtkDataSetReader->GetOutput());
this->pvtkActor->SetMapper(this->pvtkDataSetMapper);
this->pvtkTextMapper->SetInput(pvtkDataSetReader->GetFileName());
this->pvtkTextMapper->GetTextProperty()->SetFontSize(12);
this->pvtkActor2D->SetMapper(this->pvtkTextMapper);
this->pvtkRenderer->SetBackground(0.0,0.0,0.4);
this->pvtkRenderer->AddActor(this->pvtkActor);
this->pvtkRenderer->AddActor(this->pvtkActor2D);
}
else // have no file
{
this->pvtkTextMapper->SetInput("Hello World");
this->pvtkTextMapper->GetTextProperty()->SetFontSize(24);
this->pvtkActor2D->SetMapper(this->pvtkTextMapper);
this->pvtkRenderer->SetBackground(0.0,0.0,0.4);
this->pvtkRenderer->AddActor(this->pvtkActor2D);
}
this->pvtkRenderer->ResetCamera();
}
static void handle_double_click(vtkObject* obj, unsigned long,
void*, void*)
{
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::SafeDownCast(obj);
if(iren && iren->GetRepeatCount())
{
AfxMessageBox("Double Click");
}
}
BOOL CvtkDLGDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// adjust dialog & window size
this->pvtkMFCWindow = new vtkMFCWindow(this->GetDlgItem(IDC_MAIN_WND));
// get double click events
vtkCallbackCommand* callback = vtkCallbackCommand::New();
callback->SetCallback(handle_double_click);
this->pvtkMFCWindow->GetInteractor()->AddObserver(vtkCommand::LeftButtonPressEvent, callback, 1.0);
CRect cRectVTK;
this->pvtkMFCWindow->GetClientRect(&cRectVTK);
CRect cRectClient;
GetClientRect(&cRectClient);
this->ptBorder.x = cRectClient.Width() - cRectVTK.Width();
this->ptBorder.y = cRectClient.Height() - cRectVTK.Height();
// set the vtk renderer, windows, etc
this->pvtkMFCWindow->GetRenderWindow()->AddRenderer(this->pvtkRenderer);
// execute object pipeline
ExecutePipeline();
return TRUE; // return TRUE unless you set the focus to a control
}
void CvtkDLGDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CvtkDLGDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CvtkDLGDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CvtkDLGDlg::OnDestroy()
{
// delete data
if (this->pvtkDataSetReader) this->pvtkDataSetReader->Delete();
// Delete the the renderer, window and interactor objects.
if (this->pvtkRenderer) this->pvtkRenderer->Delete();
// Delete the the objects used to form the visualisation.
if (this->pvtkDataSetMapper) this->pvtkDataSetMapper->Delete();
if (this->pvtkActor) this->pvtkActor->Delete();
if (this->pvtkActor2D) this->pvtkActor2D->Delete();
if (this->pvtkTextMapper) this->pvtkTextMapper->Delete();
if (this->pvtkMFCWindow)
{
delete this->pvtkMFCWindow;
}
CDialog::OnDestroy();
}
void CvtkDLGDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (::IsWindow(this->GetSafeHwnd()))
{
if (this->pvtkMFCWindow)
{
cx -= ptBorder.x;
cy -= ptBorder.y;
this->GetDlgItem(IDC_MAIN_WND)->SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
this->pvtkMFCWindow->SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
}
}
}
void CvtkDLGDlg::OnBtnLoadFile()
{
static char BASED_CODE szFilter[] = "VTK Files (*.vtk)|*.vtk|All Files (*.*)|*.*||";