⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geditordoc.cpp

📁 一个复杂的画图系统
💻 CPP
字号:
// geditorDoc.cpp : implementation of the CGeditorDoc class
//

#include "stdafx.h"

#include "geditor.h"
#include "geditorDoc.h"
#include "prop.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGeditorDoc

IMPLEMENT_DYNCREATE(CGeditorDoc, CDocument)

BEGIN_MESSAGE_MAP(CGeditorDoc, CDocument)
	//{{AFX_MSG_MAP(CGeditorDoc)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_FILE_SAVE, OnFileSave)
	ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGeditorDoc construction/destruction

CGeditorDoc::CGeditorDoc()
{
	m_wToolType = 0;
	m_wToolles=0;
	m_curColor=0;
	Start=0;
	open=0;
	NumLine=0;
	NumPgn=0;
	NumRec=0;
	NumEls=0;
	NumBez=0;
	CurObj=NULL;
	CurObjNum=0;

}

CGeditorDoc::~CGeditorDoc()
{
	POSITION pos;
    //Release the objects stored in m_lineList
	CShape* pObj;
	pos = m_shapeList.GetHeadPosition( );
	while(pos != NULL)
	{
		pObj = m_shapeList.GetNext(pos);
		ASSERT_VALID(pObj);
		delete pObj;
	}//end of while()	
	m_shapeList.RemoveAll();
}

BOOL CGeditorDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	DeleteContents();  
	CString tempFileName("未命名.gc");
	SetPathName(tempFileName);
	SetTitle(tempFileName);
	UpdateAllViews(NULL);   
    objitems="";
	NumLine=0;
	NumPgn=0;
	NumRec=0;
	NumEls=0;
	NumBez=0;
	NumText=0;
	CurObj=NULL;
	CurObjNum=0;
	open=0;
	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CGeditorDoc serialization

void CGeditorDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		SaveFile(ar);
	}
	else
	{
		// TODO: add loading code here
		LoadFile(ar);
	}


}

/////////////////////////////////////////////////////////////////////////////
// CGeditorDoc diagnostics

#ifdef _DEBUG
void CGeditorDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CGeditorDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CGeditorDoc commands

void CGeditorDoc::SaveFile(CArchive &ar)
{
	
	ASSERT(ar.IsStoring());

	POSITION pos;
	int nObjectCount;
	CShape *obj;

	nObjectCount=m_shapeList.GetCount();
    ar<<nObjectCount;
	ar<<objitems;
    pos=m_shapeList.GetHeadPosition();
	while(pos!=NULL)
	{
		obj=m_shapeList.GetNext(pos);
		ASSERT_VALID(obj);
		obj->Serialize(ar);
	};

}

void CGeditorDoc::LoadFile(CArchive &ar)
{

		
	ASSERT(ar.IsLoading());

	POSITION pos;
	int i;

    CShape* obj;
	ar>>nObjectCount;
	ar>>objitems;
	pos = m_shapeList.GetHeadPosition( );
	TCHAR objtype;
//	Cprop *p=(Cprop*)AfxGetApp()->
//		m_pMainWnd->GetDescendantWindow(IDD_PRPTBAR);
//	for (i=0;i<p->m_name.GetCount();i++)
//		p->m_name.DeleteString(0);
	for(i=0;i<nObjectCount;i++)
	{
		objtype=objitems[i];
		switch (objtype)
		{
		case 'L':
			obj=new CLine;
			break;
		case 'R':
			obj=new CMyRect;
			break;
		case 'E':
			obj=new CEllipse;
			break;
		case 'P':
			obj=new CPolygon;
			break;
		case 'B':
			obj=new CBezier;
			break;
		case 'T':
			obj=new CText;
			break;
		case 'F':
			obj=new FillPat;
			break;
		default:
			AfxMessageBox("Can't Load Successfully");
			break;
		};
		obj->Serialize(ar);
		m_shapeList.AddTail(obj);
//		p->m_name.AddString(obj->name);
		if ((obj->dragmode>=1)&(obj->dragmode<=10))
		{
			CurObj=obj;
			CurObjNum=i;
		};
	};//end of for	
}

void CGeditorDoc::OnFileOpen() 
{
	// TODO: Add your command handler code here
	CString fileName;
	char szFileFilter[] = 
		"Graphic cell files(*.gc)|*.gc|"
		"All files(*.*)|*.*|";

	CFileDialog theFileDlg(TRUE,NULL,NULL,NULL,szFileFilter,NULL);
	if(theFileDlg.DoModal() == IDCANCEL)
		return;

	fileName = theFileDlg.GetPathName();
	AfxGetApp()->OpenDocumentFile(fileName);
	open=1;
}

void CGeditorDoc::OnFileSave() 
{
	// TODO: Add your command handler code here
	
	CString fileName = GetPathName();
	
	OnSaveDocument(fileName);
	
}

void CGeditorDoc::OnFileSaveAs() 
{
	// TODO: Add your command handler code here
	CString newFileName;
	char szFileFilter[] = 
		"Graphic Cell files(*.gc)|*.gc|"
		"All files(*.*)|*.*|";

	CFileDialog theFileDlg(FALSE,NULL,NULL,NULL,szFileFilter,NULL);
	if(theFileDlg.DoModal() == IDCANCEL)
		return;

	newFileName = theFileDlg.GetPathName();
	if(newFileName.Find(".gc") == -1)
		newFileName = newFileName + ".gc";

	DoSave(newFileName,TRUE);
	
}

void CGeditorDoc::DeleteContents() 
{
	// TODO: Add your specialized code here and/or call the base class

	POSITION pos;
    //Release the objects stored in m_shapeList
	CShape* pObj;
	pos = m_shapeList.GetHeadPosition( );
	while(pos != NULL)
	{
		pObj = m_shapeList.GetNext(pos);
		ASSERT_VALID(pObj);
		delete pObj;
	}//end of while()
	m_shapeList.RemoveAll();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -