Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 24 / lab22 / lab22Doc
.cpp// 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_CIRCLE, OnElementsCircle)
ON_COMMAND(ID_ELEMENTS_ELLIPSE, OnElementsEllipse)
ON_COMMAND(ID_ELEMENTS_ELLIPSEWITHTEXT, OnElementsEllipsewithtext)
ON_COMMAND(ID_ELEMENTS_TEXT, OnElementsText)
ON_UPDATE_COMMAND_UI(ID_ELEMENTS_CIRCLE, OnUpdateElementsCircle)
ON_UPDATE_COMMAND_UI(ID_ELEMENTS_ELLIPSE, OnUpdateElementsEllipse)
ON_UPDATE_COMMAND_UI(ID_ELEMENTS_ELLIPSEWITHTEXT, OnUpdateElementsEllipsewithtext)
ON_UPDATE_COMMAND_UI(ID_ELEMENTS_TEXT, OnUpdateElementsText)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLab22Doc construction/destruction
CLab22Doc::CLab22Doc()
{
// TODO: add one-time construction code here
c_TypeName=CIRCLE;
is_TextEnter=false;
m_DocSize = CSize(3000,3000);
index=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<<graph.getCount();
GrIterator<Shape*> it(graph);
while(!it.isEnd())
{
ar << it.currentIndex();
ar << it.currentElement();
// lways=graph.getNextWays(it.currentIndex());
// ar<<lways.size();
// lwaysIt=lways.begin();
// while (lwaysIt!=lways.end())
// {
// ar<<*lwaysIt;
// lwaysIt++;
// }
it.goNext();
}
GrIterator<Shape*> itways(graph);
std::list<int> lways;
std::list<int>::iterator lwaysIt;
ar<<graph.getCount();
while (!itways.isEnd())
{
ar << itways.currentIndex();
lways=graph.getNextWays(itways.currentIndex());
ar<<lways.size();
lwaysIt=lways.begin();
while (lwaysIt!=lways.end())
{
ar<<*lwaysIt;
lwaysIt++;
}
itways.goNext();
}
}
else
{
// TODO: add loading code here
int _Cnt;
int _type;
Shape* sh;
int _CntWays;
int way;
int index;
ar>>_Cnt;
for (int i=0;i<_Cnt;i++)
{
ar>>index;
ar>>_type;
sh=CreateElemByType(_type);
ar>>sh;
graph.AddElement(sh,index);
}
ar>>_Cnt;
for (i=0;i<_Cnt;i++)
{
ar>>index;
ar>>_CntWays;
for (int j=0;j<_CntWays;j++)
{
ar>>way;
graph.AddLine(index,way);
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
// 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::OnElementsCircle()
{
// TODO: Add your command handler code here
c_TypeName=CIRCLE;
is_TextEnter=false;
}
void CLab22Doc::OnElementsEllipse()
{
// TODO: Add your command handler code here
c_TypeName=ELLIPSE;
is_TextEnter=false;
}
void CLab22Doc::OnElementsEllipsewithtext()
{
// TODO: Add your command handler code here
c_TypeName=ELLIPSETEXT;
is_TextEnter=true;
}
void CLab22Doc::OnElementsText()
{
// TODO: Add your command handler code here
c_TypeName=TEXT;
is_TextEnter=true;
}
void CLab22Doc::OnUpdateElementsCircle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(c_TypeName==CIRCLE);
}
void CLab22Doc::OnUpdateElementsEllipse(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(c_TypeName==ELLIPSE);
}
void CLab22Doc::OnUpdateElementsEllipsewithtext(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(c_TypeName==ELLIPSETEXT);
}
void CLab22Doc::OnUpdateElementsText(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(c_TypeName==TEXT);
}
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 CText();
case 2:
return new CCircle();
case 3:
return new CEllipse();
case 4:
return new CEllipseTxt();
default:
AfxMessageBox("Bad Element code", MB_OK);
AfxAbort();
return 0;
}
}
Соседние файлы в папке lab22