www.pudn.com > 3DEDITOR.rar > IMPORTPROGRESS.CPP


// ImportProgress.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "3DEditor.h" 
#include "ImportProgress.h" 
#include "3DEditorDoc.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// ImportProgress dialog 
 
 
ImportProgress::ImportProgress(CWnd* pParent /*=NULL*/) 
	: CDialog(ImportProgress::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(ImportProgress) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
 
void ImportProgress::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(ImportProgress) 
	DDX_Control(pDX, IDC_PROGRESS, m_progress); 
	DDX_Control(pDX, IDC_OBJ, m_obj); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(ImportProgress, CDialog) 
	//{{AFX_MSG_MAP(ImportProgress) 
	ON_WM_CLOSE() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// ImportProgress message handlers 
UINT ImportThread( LPVOID pParam ) 
{ 
	ImportProgress *ip=(ImportProgress *)pParam; 
	scene *doc=ip->doc; 
	object *o=doc->obj0; 
 
	while( o ) 
	{ 
		if (o->elem==0) 
		{ 
		ip->m_obj.SetWindowText(o->name); 
		ip->m_progress.SetRange(0,1?10:8); 
		ip->m_progress.SetPos(1); 
		ip->m_progress.SetStep(1); 
 
			o->DelDupVert(); 
			if (ip->stop) break; 
			ip->m_progress.StepIt(); 
		 
		o->DelInvFace(); 
		if (ip->stop) break; 
		ip->m_progress.StepIt(); 
 
		o->DelDupFace(); 
		if (ip->stop) break; 
		ip->m_progress.StepIt(); 
 
		o->compute_normals(); 
		if (ip->stop) break; 
 
		o->Explode(); 
		if (ip->stop) break; 
		ip->m_progress.StepIt(); 
 
		o->Implode(); 
		if (ip->stop) break; 
		ip->m_progress.StepIt(); 
 
		o->ApagaVertNaAresta(); 
		if (ip->stop) break; 
		ip->m_progress.StepIt(); 
 
		o->CompactHoles(); 
		if (ip->stop) break; 
		ip->m_progress.StepIt(); 
 
		o->count_elements(); 
		if (ip->stop) break; 
		o->fix_normals(); 
		if (ip->stop) break; 
		o->compute_normals(); 
		if (ip->stop) break; 
		ip->m_progress.StepIt(); 
 
		o->Compress(); 
		if (ip->stop) break; 
		ip->m_progress.StepIt(); 
		} 
 
		o=o->next; 
	} 
	ip->importthread=0; 
	ip->PostMessage(0xC000+(o==0),0,0); 
	return 1; 
} 
void ImportProgress::OnCancel()  
{ 
	// TODO: Add extra cleanup here 
	stop=1; 
	GetDlgItem(IDC_CANCEL)->EnableWindow(0);	 
	CDialog::OnCancel(); 
} 
 
void ImportProgress::OnClose()  
{ 
	// TODO: Add your message handler code here and/or call default 
	stop=1; 
	GetDlgItem(IDC_CANCEL)->EnableWindow(0);	 
	CDialog::OnClose(); 
} 
 
BOOL ImportProgress::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	doc->inuse=1; 
	stop=0; 
	 
	importthread=AfxBeginThread(ImportThread, this);	 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
LRESULT ImportProgress::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	if (message==0xC000) 
		{ 
		doc->inuse=0; 
 
		if(doc->ncamlib_ant==0) 
		{ 
			if(doc->camlib) 
				delete doc->camlib; 
 
			doc->camlib=0; 
		} 
		else 
		{ 
			camera *tmp=new camera[doc->ncamlib_ant]; 
			memcpy(tmp, doc->camlib, sizeof(camera)*doc->ncamlib_ant); 
			delete doc->camlib; 
			doc->camlib=tmp; 
		} 
		doc->ncamlib=doc->ncamlib_ant; 
 
		if(doc->nlights_ant==0) 
		{ 
			if(doc->lightlib) 
				delete doc->lightlib; 
 
			doc->lightlib=0; 
		} 
		else 
		{ 
		 	light *tmp=new light[doc->nlights_ant]; 
			memcpy(tmp, doc->lightlib, sizeof(light)*doc->nlights_ant); 
			delete doc->lightlib; 
			doc->lightlib=tmp; 
		} 
		doc->nlights=doc->nlights_ant; 
 
		if(doc->nmatlib_ant==0) 
		{ 
			if(doc->matlib) 
				delete doc->matlib; 
 
			doc->matlib=0; 
		} 
		else 
		{ 
		 	material *tmp=new material[doc->nmatlib_ant]; 
			memcpy(tmp, doc->matlib, sizeof(material)*doc->nmatlib_ant); 
			delete doc->matlib; 
			doc->matlib=tmp; 
		} 
		doc->nmatlib=doc->nmatlib_ant; 
 
		if(doc->nobj_ant==0) 
		{ 
			if(doc->obj0) 
				delete doc->obj0; 
 
			doc->obj0=NULL; 
		} 
		else if(doc->nobj!=doc->nobj_ant) 
		{ 
			object *tmp1, *tmp2; 
			 
			tmp1=tmp2=doc->obj0; 
			 
			for(int i=0;inobj-doc->nobj_ant-1;i++) 
				tmp1=tmp1->next; 
 
			doc->obj0=tmp1->next; 
 
			tmp1->next=NULL; 
 
			delete tmp2; 
		} 
		doc->nobj=doc->nobj_ant; 
		((CMy3DEditorDoc *)doc)->UpdateAllViews(0); 
		EndDialog(0); 
		} 
	else 
	if (message==0xC000+1) 
		{ 
		doc->inuse=0; 
		if (doc->oc) 
		{ 
			delete doc->oc; 
			doc->oc=0; 
		} 
		((CMy3DEditorDoc *)doc)->UpdateAllViews(0); 
		EndDialog(1); 
		}	 
	return CDialog::WindowProc(message, wParam, lParam); 
}