Скачиваний:
10
Добавлен:
01.05.2014
Размер:
4.75 Кб
Скачать
// lab22Doc.cpp : implementation of the CLab22Doc class
//

#include "stdafx.h"
#include "lab22.h"

#include "lab22Doc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLab22Doc

IMPLEMENT_DYNCREATE(CLab22Doc, CDocument)

BEGIN_MESSAGE_MAP(CLab22Doc, CDocument)
	//{{AFX_MSG_MAP(CLab22Doc)
	ON_COMMAND(ID_ELEMENTS_TEXT, OnElementsText)
	ON_UPDATE_COMMAND_UI(ID_ELEMENTS_TEXT, OnUpdateElementsText)
	ON_COMMAND(ID_ELEMENTS_TRAPEZIUM, OnElementsTrapezium)
	ON_UPDATE_COMMAND_UI(ID_ELEMENTS_TRAPEZIUM, OnUpdateElementsTrapezium)
	ON_COMMAND(ID_ELEMENTS_TRAPEZIUMWITHTEXT, OnElementsTrapeziumwithtext)
	ON_UPDATE_COMMAND_UI(ID_ELEMENTS_TRAPEZIUMWITHTEXT, OnUpdateElementsTrapeziumwithtext)
	ON_COMMAND(ID_ELEMENTS_TRIANGLE, OnElementsTriangle)
	ON_UPDATE_COMMAND_UI(ID_ELEMENTS_TRIANGLE, OnUpdateElementsTriangle)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLab22Doc construction/destruction

CLab22Doc::CLab22Doc()
{
	// TODO: add one-time construction code here
	c_TypeName=TRIANGLE;
	is_TextEnter=false;
	m_DocSize = CSize(3000,3000);
	index1=1;
	index2=1;
}

CLab22Doc::~CLab22Doc()
{
}

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

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CLab22Doc serialization

void CLab22Doc::Serialize(CArchive& ar)
{									//сериализация в поток и из потока
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		ar<<set1.count();

		ArSetIterator<Shape*> it(set1);
	
		while(!it.end())
		{
			ar << it.currentItem();

			it.next();
		}

		ar<<set2.count();

		ArSetIterator<Shape*> it2(set2);
	
		while(!it2.end())
		{
			ar << it2.currentItem();

			it2.next();
		}
	}
	else
	{
		// TODO: add loading code here
		int _Cnt;
		int _type;
		Shape* sh;
		ar>>_Cnt;

		for (int i=0;i<_Cnt;i++)
		{
			ar>>_type;
			
			sh=CreateElemByType(_type);

			ar>>sh;

			set1.insertEl(i,sh);
		}

		int _Cnt2;

		ar>>_Cnt2;

		for (i=0;i<_Cnt2;i++)
		{
			ar>>_type;
			
			sh=CreateElemByType(_type);

			ar>>sh;

			set2.insertEl(i,sh);
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
// CLab22Doc diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CLab22Doc commands

void CLab22Doc::OnElementsText() 
{
	// TODO: Add your command handler code here
	c_TypeName=TEXT;
	is_TextEnter=true;
}

void CLab22Doc::OnUpdateElementsText(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(c_TypeName==TEXT);
}

void CLab22Doc::OnElementsTrapezium() 
{
	// TODO: Add your command handler code here
	c_TypeName=TRAPEZ;
	is_TextEnter=false;
}

void CLab22Doc::OnUpdateElementsTrapezium(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(c_TypeName==TRAPEZ);
}

void CLab22Doc::OnElementsTrapeziumwithtext() 
{
	// TODO: Add your command handler code here
	c_TypeName=TRAPEZTEXT;
	is_TextEnter=true;
}

void CLab22Doc::OnUpdateElementsTrapeziumwithtext(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(c_TypeName==TRAPEZTEXT);
}

void CLab22Doc::OnElementsTriangle() 
{
	// TODO: Add your command handler code here
	c_TypeName=TRIANGLE;
	is_TextEnter=false;
}

void CLab22Doc::OnUpdateElementsTriangle(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(c_TypeName==TRIANGLE);
}

WORD CLab22Doc::GetElementType()        // Get the element type
	{
		return c_TypeName;
	}

CSize CLab22Doc::GetDocSize()                        // Retrieve the document size
	  { return m_DocSize; }

	Shape* CLab22Doc::CreateElemByType(int type)
	{													//создание фигуры по номеру типа (для сериализации
	 switch(type)
		{
		case 1:
			return new CTriangleEntity(0,0);
     
		case 2:
			return new CTrapeziumEntity(0,0,0);

		case 3:
			return new CTextEntity("");

		case 4:
			return new CTextTrapeziumEntity("",0,0,0);

		default:
			AfxMessageBox("Bad Element code", MB_OK);
			AfxAbort();
			return 0;
		}
	}
Соседние файлы в папке lab22