home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
VRML Tools for 3D Cyberspace
/
VRML_Tools_For_3D_Cyberspace.iso
/
amber
/
demos
/
framed
/
mfc20
/
framedoc.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-01
|
4KB
|
185 lines
// framedoc.cpp : implementation of the CFramedDoc class
//
#include "stdafx.h"
#include "framed.h"
#include "framedoc.h"
#include "amber.hpp"
#include "geometry.hpp"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
static char BASED_CODE szFilter[] =
"VRML Files (*.wrl) | *.wrl | WTK Files (*.nff) | *.nff | All Files (*.*) | *.* ||";
/////////////////////////////////////////////////////////////////////////////
// CFramedDoc
IMPLEMENT_DYNCREATE(CFramedDoc, CDocument)
BEGIN_MESSAGE_MAP(CFramedDoc, CDocument)
//{{AFX_MSG_MAP(CFramedDoc)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFramedDoc construction/destruction
CFramedDoc::CFramedDoc()
{
// TODO: add one-time construction code here
}
CFramedDoc::~CFramedDoc()
{
}
BOOL CFramedDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CFramedDoc serialization
void CFramedDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CFramedDoc diagnostics
#ifdef _DEBUG
void CFramedDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CFramedDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFramedDoc commands
BOOL CFramedDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
universeClass *univ = amber->getCurrentUniverse();
univ->removeAllGeo();
amber->deleteAllGeos();
amber->deleteAllTextures();
amber->deleteAllMaterials();
geometryClass *geo = new geometryClass((char *)lpszPathName);
return TRUE;
}
void CFramedDoc::OnFileSave()
{
// TODO: Add your command handler code here
CFileDialog *dlg;
geometryClass *geo;
universeClass *univ = amber->getCurrentUniverse();
char name[255];
geo = univ->getGeo(1);
strcpy(name, geo->getFilename());
if (strstr(name, "wrl") || strstr(name, "WRL")) {
geo->save(name, _VRML_FILE);
}
else if (strstr(name, "nff") || strstr(name, "NFF")) {
geo->save(name, _NFF_FILE);
}
}
void CFramedDoc::OnUpdateFileSave(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
geometryClass *geo;
universeClass *univ = amber->getCurrentUniverse();
geo = univ->getGeo(1);
if (!geo)
pCmdUI->Enable(FALSE);
else
pCmdUI->Enable(TRUE);
}
void CFramedDoc::OnFileSaveAs()
{
// TODO: Add your command handler code here
CFileDialog *dlg;
geometryClass *geo;
universeClass *univ = amber->getCurrentUniverse();
geo = univ->getGeo(1);
dlg = new CFileDialog(FALSE, "wrl", geo->getFilename(),
OFN_OVERWRITEPROMPT, szFilter);
if (dlg->DoModal()) {
switch(dlg->m_ofn.nFilterIndex) {
case 1:
geo->save(dlg->m_ofn.lpstrFile, _VRML_FILE);
break;
case 2:
geo->save(dlg->m_ofn.lpstrFile, _NFF_FILE);
break;
default:
geo->save(dlg->m_ofn.lpstrFile, _VRML_FILE);
break;
}
}
delete dlg;
}
void CFramedDoc::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
geometryClass *geo;
universeClass *univ = amber->getCurrentUniverse();
geo = univ->getGeo(1);
if (!geo)
pCmdUI->Enable(FALSE);
else
pCmdUI->Enable(TRUE);
}