Commit 945354ed authored by Clinton Stimpson's avatar Clinton Stimpson

STYLE: Update examples with vtkMFCWindow changes and other changes provided by Ingo.

parent 70cd557f
/*=========================================================================
Program: Visualization Toolkit
Module: MainFrm.cpp
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "vtkSDI.h"
......@@ -20,21 +8,15 @@
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
......@@ -45,19 +27,19 @@ static UINT indicators[] =
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
......@@ -78,9 +60,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
// TODO: Delete these three lines if you don't want the toolbar to be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
......@@ -98,7 +78,7 @@ BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
......@@ -114,6 +94,6 @@ void CMainFrame::Dump(CDumpContext& dc) const
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
/*=========================================================================
// MainFrm.h : interface of the CMainFrame class
//
Program: Visualization Toolkit
Module: MainFrm.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#if !defined(AFX_MAINFRM_H__6554D958_881A_4AB6_878D_2B284B8A8440__INCLUDED_)
#define AFX_MAINFRM_H__6554D958_881A_4AB6_878D_2B284B8A8440__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMainFrame : public CFrameWnd
{
......@@ -34,10 +17,8 @@ public:
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainFrame)
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL
// Implementation
public:
......@@ -53,17 +34,8 @@ protected: // control bar embedded members
// Generated message map functions
protected:
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MAINFRM_H__6554D958_881A_4AB6_878D_2B284B8A8440__INCLUDED_)
// stdafx.cpp : source file that includes just the standard includes
// vtkSDI.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
// vtkSDI.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
......@@ -40,3 +40,14 @@
#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>
//
// VTKSDI.RC2 - resources Microsoft Visual C++ does not edit directly
// vtkSDI.RC2 - resources Microsoft Visual C++ does not edit directly
//
#ifdef APSTUDIO_INVOKED
#error this file is not editable by Microsoft Visual C++
#error this file is not editable by Microsoft Visual C++
#endif //APSTUDIO_INVOKED
......
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Microsoft Visual C++ generated include file.
// Used by vtkSDI.rc
//
#define IDD_ABOUTBOX 100
#define IDR_MAINFRAME 128
#define IDR_VTKSDITYPE 129
#define IDD_ABOUTBOX 100
#define IDP_OLE_INIT_FAILED 100
#define IDR_MAINFRAME 128
#define IDR_vtkSDITYPE 129
#define IDR_MANIFEST CREATEPROCESS_MANIFEST_RESOURCE_ID
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 32771
#endif
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSDI.cpp
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// vtkSDI.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "vtkSDI.h"
#include "MainFrm.h"
#include "vtkSDIDoc.h"
#include "vtkSDIView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVtkSDIApp
BEGIN_MESSAGE_MAP(CVtkSDIApp, CWinApp)
//{{AFX_MSG_MAP(CVtkSDIApp)
// CvtkSDIApp
BEGIN_MESSAGE_MAP(CvtkSDIApp, CWinApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
......@@ -42,68 +24,75 @@ BEGIN_MESSAGE_MAP(CVtkSDIApp, CWinApp)
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVtkSDIApp construction
CVtkSDIApp::CVtkSDIApp()
// CvtkSDIApp construction
CvtkSDIApp::CvtkSDIApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CVtkSDIApp object
CVtkSDIApp theApp;
// The one and only CvtkSDIApp object
CvtkSDIApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CVtkSDIApp initialization
// CvtkSDIApp initialization
BOOL CVtkSDIApp::InitInstance()
BOOL CvtkSDIApp::InitInstance()
{
AfxEnableControlContainer();
// 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();
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
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.
// 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.
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
// serve as the connection between documents, frame windows and views
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CVtkSDIDoc),
RUNTIME_CLASS(CvtkSDIDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CVtkSDIView));
RUNTIME_CLASS(CvtkSDIView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
// Dispatch commands specified on the command line. Will return FALSE if
// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
// The one and only window has been initialized, so show and update it
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->SetWindowText("Visualizing a Sphere");
m_pMainWnd->UpdateWindow();
// call DragAcceptFiles only if there's a suffix
// In an SDI app, this should occur after ProcessShellCommand
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
......@@ -112,50 +101,35 @@ public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CVtkSDIApp::OnAppAbout()
void CvtkSDIApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CVtkSDIApp message handlers
// CvtkSDIApp message handlers
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSDI.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#if !defined(AFX_VTKSDI_H__FE4E2671_2C39_45E4_A10E_DB8A4E94441D__INCLUDED_)
#define AFX_VTKSDI_H__FE4E2671_2C39_45E4_A10E_DB8A4E94441D__INCLUDED_
#if _MSC_VER > 1000
// vtkSDI.h : main header file for the vtkSDI application
//
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
......@@ -26,36 +8,24 @@
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CVtkSDIApp:
// CvtkSDIApp:
// See vtkSDI.cpp for the implementation of this class
//
class CVtkSDIApp : public CWinApp
class CvtkSDIApp : public CWinApp
{
public:
CVtkSDIApp();
CvtkSDIApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CVtkSDIApp)
public:
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CVtkSDIApp)
afx_msg void OnAppAbout();
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_VTKSDI_H__FE4E2671_2C39_45E4_A10E_DB8A4E94441D__INCLUDED_)
extern CvtkSDIApp theApp;
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSDIDoc.cpp
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// vtkSDIDoc.cpp : implementation of the CvtkSDIDoc class
//
#include "stdafx.h"
#include "vtkSDI.h"
#include "vtkSDIDoc.h"
#include "vtkSDIView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVtkSDIDoc
IMPLEMENT_DYNCREATE(CVtkSDIDoc, CDocument)
// CvtkSDIDoc
IMPLEMENT_DYNCREATE(CvtkSDIDoc, CDocument)
BEGIN_MESSAGE_MAP(CVtkSDIDoc, CDocument)
//{{AFX_MSG_MAP(CVtkSDIDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
BEGIN_MESSAGE_MAP(CvtkSDIDoc, CDocument)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVtkSDIDoc construction/destruction
CVtkSDIDoc::CVtkSDIDoc()
// CvtkSDIDoc construction/destruction
CvtkSDIDoc::CvtkSDIDoc()
{
// TODO: add one-time construction code here
this->pvtkDataSetReader = NULL;
// 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();
}
CVtkSDIDoc::~CVtkSDIDoc()
CvtkSDIDoc::~CvtkSDIDoc()
{
}
BOOL CVtkSDIDoc::OnNewDocument()
BOOL CvtkSDIDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
// remove old actors
RemoveActors();
// execute object pipeline
ExecutePipeline();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CVtkSDIDoc serialization
void CVtkSDIDoc::Serialize(CArchive& ar)
// CvtkSDIDoc serialization
void CvtkSDIDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
......@@ -77,20 +68,117 @@ void CVtkSDIDoc::Serialize(CArchive& ar)
}
}
/////////////////////////////////////////////////////////////////////////////
// CVtkSDIDoc diagnostics
// CvtkSDIDoc diagnostics
#ifdef _DEBUG
void CVtkSDIDoc::AssertValid() const
void CvtkSDIDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CVtkSDIDoc::Dump(CDumpContext& dc) const
void CvtkSDIDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CVtkSDIDoc commands
// CvtkSDIDoc commands
void CvtkSDIDoc::RemoveActors()
{
// get our renderer first
POSITION pos = this->GetFirstViewPosition();
CvtkSDIView *pcvtkSDIView = NULL;
if (pos)
{
pcvtkSDIView = (CvtkSDIView *)GetNextView(pos);
}
else // return
{
ASSERT(FALSE);
return;
}
// remove old actors
pcvtkSDIView->GetRenderer()->RemoveActor(this->pvtkActor);
pcvtkSDIView->GetRenderer()->RemoveActor(this->pvtkActor2D);
}
BOOL CvtkSDIDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// remove old actors
RemoveActors();
// create new data reader
this->pvtkDataSetReader = vtkDataSetReader::New();
this->pvtkDataSetReader->SetFileName(lpszPathName);
// execute object pipeline
ExecutePipeline();
return TRUE;
}
void CvtkSDIDoc::OnCloseDocument()
{
// delete data
if (this->pvtkDataSetReader) this->pvtkDataSetReader->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();
CDocument::OnCloseDocument();
}
void CvtkSDIDoc::ExecutePipeline()
{
// get our renderer first
POSITION pos = this->GetFirstViewPosition();
CvtkSDIView *pcvtkSDIView = NULL;
if (pos)
{
pcvtkSDIView = (CvtkSDIView *)GetNextView(pos);
}
else // return
{
ASSERT(FALSE);
return;
}
if (pvtkDataSetReader) // have file
{
this->pvtkDataSetMapper->SetInput(this->pvtkDataSetReader->GetOutput());
this->pvtkActor->SetMapper(this->pvtkDataSetMapper);
this->pvtkTextMapper->SetInput(this->pvtkDataSetReader->GetFileName());
this->pvtkTextMapper->GetTextProperty()->SetFontSize(12);
this->pvtkActor2D->SetMapper(this->pvtkTextMapper);
pcvtkSDIView->GetRenderer()->SetBackground(0.0,0.0,0.4);
pcvtkSDIView->GetRenderer()->AddActor(this->pvtkActor);
pcvtkSDIView->GetRenderer()->AddActor(this->pvtkActor2D);
pcvtkSDIView->GetRenderer()->ResetCamera();
pvtkDataSetReader->Delete();
pvtkDataSetReader = NULL;
}
else // have no file
{
this->pvtkTextMapper->SetInput("Hello World");
this->pvtkTextMapper->GetTextProperty()->SetFontSize(24);
this->pvtkActor2D->SetMapper(this->pvtkTextMapper);
pcvtkSDIView->GetRenderer()->SetBackground(0.0,0.0,0.4);
pcvtkSDIView->GetRenderer()->AddActor(this->pvtkActor2D);
pcvtkSDIView->GetRenderer()->ResetCamera();
}
}
/*=========================================================================
// vtkSDIDoc.h : interface of the CvtkSDIDoc class
//
Program: Visualization Toolkit
Module: vtkSDIDoc.h