/*=========================================================================== * * File: Dfto3dsdoc.CPP * Author: Dave Humphrey (uesp@m0use.net) * Created On: Saturday, June 23, 2001 * * Implements the CDfto3dsDoc document class. * *=========================================================================*/ /* Include Files */ #include "stdafx.h" #include "dfto3ds.h" #include "dfto3dsdoc.h" #include "uesp/dagger/df3dexpo.h" /*=========================================================================== * * Begin Local Variable Definitions * *=========================================================================*/ /* Debug variables and defines */ #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif IMPLEMENT_DYNCREATE(CDfto3dsDoc, CDocument) /*=========================================================================== * End of Local Variable Definitions *=========================================================================*/ /*=========================================================================== * * Class CDfto3dsDoc Message Map * *=========================================================================*/ BEGIN_MESSAGE_MAP(CDfto3dsDoc, CDocument) //{{AFX_MSG_MAP(CDfto3dsDoc) //}}AFX_MSG_MAP END_MESSAGE_MAP() /*=========================================================================== * End of CDfto3dsDoc Message Map *=========================================================================*/ /*=========================================================================== * * Class CDfto3dsDoc Constructor * *=========================================================================*/ CDfto3dsDoc::CDfto3dsDoc() { m_pCurrentObject = NULL; } /*=========================================================================== * End of Class CDfto3dsDoc Constructor *=========================================================================*/ /*=========================================================================== * * Class CDfto3dsDoc Destructor * *=========================================================================*/ CDfto3dsDoc::~CDfto3dsDoc() { DestroyPointer(m_pCurrentObject); } /*=========================================================================== * End of Class CDfto3dsDoc Destructor *=========================================================================*/ /*=========================================================================== * * Class CDfto3dsDoc Method - void DeleteContents (); * *=========================================================================*/ void CDfto3dsDoc::DeleteContents() { m_Arch3DFile.Destroy(); DestroyPointer(m_pCurrentObject); CDocument::DeleteContents(); } /*=========================================================================== * End of Class Method CDfto3dsDoc::DeleteContents() *=========================================================================*/ /*=========================================================================== * * Class CDfto3dsDoc Event - BOOL OnNewDocument(); * *=========================================================================*/ BOOL CDfto3dsDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; return TRUE; } /*=========================================================================== * End of Class Event CDfto3dsDoc::OnNewDocument() *=========================================================================*/ /*=========================================================================== * * Class CDfto3dsDoc Diagnostic Methods * *=========================================================================*/ #ifdef _DEBUG void CDfto3dsDoc::AssertValid() const { CDocument::AssertValid(); } void CDfto3dsDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif /*=========================================================================== * End of CDfto3dsDoc Diagnostic Methods *=========================================================================*/ /*=========================================================================== * * Class CDfto3dsDoc Method - boolean ExportAll3DS (ExportDialog); * * Attempt to export all the 3D objects to 3DS files. Returns FALSE * on any error. 3DS files are named by the 8 character hexadecimal ID * of each of the objects. An output file dialog is displayed and * updated as the files are exported. * *=========================================================================*/ boolean CDfto3dsDoc::ExportAll3DS (CDfExport3dsDialog& ExportDialog) { DEFINE_FUNCTION("CDfto3dsDoc::ExportAll3DS()"); boolean Result = TRUE; int LoopCounter; int FailedCount; char FileBuffer[_MAX_PATH+64]; /* Initialize the export dialog */ ExportDialog.InitDialog(m_Arch3DFile.GetNumRecords()); ExportDialog.Create(IDD_EXPORT3DS_DIALOG, NULL); ExportDialog.ShowWindow(SW_SHOW); FailedCount = 0; /* Load and export each 3D object in ARCH3D.BSA */ for (LoopCounter = 0; LoopCounter < m_Arch3DFile.GetNumRecords(); LoopCounter++) { /* Update export dialog */ sprintf (FileBuffer, "%s%08lX.3ds", (const char*)GetExport3DSPath(), m_Arch3DFile.GetRecordValue(LoopCounter)); Result = ExportDialog.UpdateProgress(FileBuffer, LoopCounter+1, FailedCount); ExportDialog.SendMessage(WM_ENTERIDLE, MSGF_DIALOGBOX, (long) ExportDialog.m_hWnd); /* Load and export object */ Result = LoadArch3DObject (LoopCounter); if (Result) Result = ExportDF3dObjectTo3DS(FileBuffer, *m_pCurrentObject); if (!Result) { //ErrorHandler.Notify("DFto3DS: 3DS Export Error!"); FailedCount++; } } ExportDialog.DestroyWindow(); return (Result); } /*=========================================================================== * End of Class Method CDfto3dsDoc::ExportAll3DS() *=========================================================================*/ /*=========================================================================== * * Class CDfto3dsDoc Method - boolean LoadArch3DObject (Index); * * Attempt to load the given indexed 3D object from the current Arch3D * file, storing the object in the m_pCurrentObject member variable. * The previous object, if any, is destroyed. Returns FALSE on any error. * *=========================================================================*/ boolean CDfto3dsDoc::LoadArch3DObject (const size_t Index) { DEFINE_FUNCTION("CDfto3dsDoc::LoadArch3DObject()"); boolean Result; /* Delete the current object, if any */ DestroyPointer(m_pCurrentObject); Result = m_Arch3DFile.LoadObject(&m_pCurrentObject, Index); return (Result); } /*=========================================================================== * End of Class Method CDfto3dsDoc::LoadArch3DObject() *=========================================================================*/ /*=========================================================================== * * Class CDfto3dsDoc Event - BOOL OnOpenDocument (lpszPathName); * *=========================================================================*/ BOOL CDfto3dsDoc::OnOpenDocument(LPCTSTR lpszPathName) { boolean Result; /* Delete the contents of the current file */ DeleteContents(); SetModifiedFlag(); /* Attempt to open the arch3d file */ Result = m_Arch3DFile.Open(lpszPathName, "rb"); SetModifiedFlag(FALSE); /* Inform user of any errors */ if (!Result) ErrorHandler.Notify("Arch3D File Error!"); else { char Buffer[_MAX_PATH+2]; ExtractPath(Buffer, lpszPathName, _MAX_PATH+1); SetDFArena2Path(Buffer); } return (Result); } /*=========================================================================== * End of Class Event CDfto3dsDoc::OnOpenDocument() *=========================================================================*/