Скачиваний:
7
Добавлен:
01.05.2014
Размер:
9.21 Кб
Скачать
// part31Doc.cpp : implementation of the CPart31Doc class
//

#include "stdafx.h"
#include "part31.h"

#include "part31Doc.h"
#include "CntrItem.h"
#include "SrvrItem.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPart31Doc

IMPLEMENT_DYNCREATE(CPart31Doc, COleServerDoc)

BEGIN_MESSAGE_MAP(CPart31Doc, COleServerDoc)
	//{{AFX_MSG_MAP(CPart31Doc)
	ON_COMMAND(ID_ELEMENTS_CIRCLE, OnElementsCircle)
	ON_UPDATE_COMMAND_UI(ID_ELEMENTS_CIRCLE, OnUpdateElementsCircle)
	ON_COMMAND(ID_ELEMENTS_ELLIPSE, OnElementsEllipse)
	ON_UPDATE_COMMAND_UI(ID_ELEMENTS_ELLIPSE, OnUpdateElementsEllipse)
	ON_COMMAND(ID_ELEMENTS_ELLIPSEWITHTEXT, OnElementsEllipsewithtext)
	ON_UPDATE_COMMAND_UI(ID_ELEMENTS_ELLIPSEWITHTEXT, OnUpdateElementsEllipsewithtext)
	ON_COMMAND(ID_ELEMENTS_TEXT, OnElementsText)
	ON_UPDATE_COMMAND_UI(ID_ELEMENTS_TEXT, OnUpdateElementsText)
	//}}AFX_MSG_MAP
	// Enable default OLE container implementation
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, COleServerDoc::OnUpdatePasteMenu)
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_LINK, COleServerDoc::OnUpdatePasteLinkMenu)
	ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_CONVERT, COleServerDoc::OnUpdateObjectVerbMenu)
	ON_COMMAND(ID_OLE_EDIT_CONVERT, COleServerDoc::OnEditConvert)
	ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, COleServerDoc::OnUpdateEditLinksMenu)
	ON_COMMAND(ID_OLE_EDIT_LINKS, COleServerDoc::OnEditLinks)
	ON_UPDATE_COMMAND_UI_RANGE(ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, COleServerDoc::OnUpdateObjectVerbMenu)
END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CPart31Doc, COleServerDoc)
	//{{AFX_DISPATCH_MAP(CPart31Doc)
	DISP_FUNCTION(CPart31Doc, "showWindow", showWindow, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION(CPart31Doc, "getCount", getCount, VT_I2, VTS_NONE)
	DISP_FUNCTION(CPart31Doc, "printCircle", printCircle, VT_EMPTY, VTS_I2 VTS_I2 VTS_I2)
	DISP_FUNCTION(CPart31Doc, "printEllipse", printEllipse, VT_EMPTY, VTS_I2 VTS_I2 VTS_I2 VTS_I2)
	DISP_FUNCTION(CPart31Doc, "printEllipseText", printEllipseText, VT_EMPTY, VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_BSTR)
	DISP_FUNCTION(CPart31Doc, "printText", printText, VT_EMPTY, VTS_I2 VTS_I2 VTS_BSTR)
	DISP_FUNCTION(CPart31Doc, "addLine", addLine, VT_EMPTY, VTS_I2 VTS_I2)
	DISP_FUNCTION(CPart31Doc, "delElem", delElem, VT_EMPTY, VTS_I2)
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

// Note: we add support for IID_IPart31 to support typesafe binding
//  from VBA.  This IID must match the GUID that is attached to the 
//  dispinterface in the .ODL file.

// {8DC04A7A-E92F-4C38-BB14-AB438E4B1367}
static const IID IID_IPart31 =
{ 0x8dc04a7a, 0xe92f, 0x4c38, { 0xbb, 0x14, 0xab, 0x43, 0x8e, 0x4b, 0x13, 0x67 } };

BEGIN_INTERFACE_MAP(CPart31Doc, COleServerDoc)
	INTERFACE_PART(CPart31Doc, IID_IPart31, Dispatch)
END_INTERFACE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPart31Doc construction/destruction

CPart31Doc::CPart31Doc()
{
	// Use OLE compound files
	EnableCompoundFile();

	// TODO: add one-time construction code here

	EnableAutomation();

	AfxOleLockApp();

	c_TypeName=CIRCLE;
	is_TextEnter=false;
	m_DocSize = CSize(3000,3000);
	index=1;
}

CPart31Doc::~CPart31Doc()
{
	AfxOleUnlockApp();
}

BOOL CPart31Doc::OnNewDocument()
{
	if (!COleServerDoc::OnNewDocument())
		return FALSE;

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

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CPart31Doc server implementation

COleServerItem* CPart31Doc::OnGetEmbeddedItem()
{
	// OnGetEmbeddedItem is called by the framework to get the COleServerItem
	//  that is associated with the document.  It is only called when necessary.

	CPart31SrvrItem* pItem = new CPart31SrvrItem(this);
	ASSERT_VALID(pItem);
	return pItem;
}



/////////////////////////////////////////////////////////////////////////////
// CPart31Doc serialization

void CPart31Doc::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
	{
		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);
			}
		}

	}

	// Calling the base class COleServerDoc enables serialization
	//  of the container document's COleClientItem objects.
	COleServerDoc::Serialize(ar);
}

/////////////////////////////////////////////////////////////////////////////
// CPart31Doc diagnostics

#ifdef _DEBUG
void CPart31Doc::AssertValid() const
{
	COleServerDoc::AssertValid();
}

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

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

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

Shape* CPart31Doc::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;
		}
	}

void CPart31Doc::OnElementsCircle() 
{
	// TODO: Add your command handler code here
	c_TypeName=CIRCLE;
	is_TextEnter=false;	
}

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

void CPart31Doc::OnElementsEllipse() 
{
	// TODO: Add your command handler code here
	c_TypeName=ELLIPSE;
	is_TextEnter=false;	
}

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

void CPart31Doc::OnElementsEllipsewithtext() 
{
	// TODO: Add your command handler code here
	c_TypeName=ELLIPSETEXT;
	is_TextEnter=true;	
}

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

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

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

void CPart31Doc::showWindow() 
{
 POSITION pos = GetFirstViewPosition();
 CView* pView = GetNextView(pos);
 if (pView != NULL)
 {
  CFrameWnd* pFrameWnd = pView->GetParentFrame();
  pFrameWnd->ActivateFrame(SW_SHOW);
  pFrameWnd = pFrameWnd->GetParentFrame();
  if (pFrameWnd != NULL)
   pFrameWnd->ActivateFrame(SW_SHOW);
 }
}

short CPart31Doc::getCount() 
{
	// TODO: Add your dispatch handler code here

	return graph.getCount();
}

void CPart31Doc::printCircle(short x, short y, short rad) 
{
	Shape* sh;
	sh=new CCircle(x,y,rad);

	graph.AddElement(sh,index++);

	UpdateAllViews(NULL);

}

void CPart31Doc::printEllipse(short x, short y, short frad, short srad) 
{
	Shape* sh;
	sh=new CEllipse(x,y,frad,srad);

	graph.AddElement(sh,index++);

	UpdateAllViews(NULL);
}

void CPart31Doc::printEllipseText(short x, short y, short frad, short srad, LPCTSTR text) 
{
	Shape* sh;
	sh=new CEllipseTxt(x,y,frad,srad,text);

	graph.AddElement(sh,index++);

	UpdateAllViews(NULL);
}

void CPart31Doc::printText(short x, short y, LPCTSTR Text) 
{
	Shape* sh;
	sh=new CText(x,y,Text);

	graph.AddElement(sh,index++);

	UpdateAllViews(NULL);
}

void CPart31Doc::addLine(short from, short to) 
{
	graph.AddLine(from,to);
	UpdateAllViews(NULL);
}

void CPart31Doc::delElem(short index) 
{
	graph.delElem(index);
	UpdateAllViews(NULL);
}
Соседние файлы в папке part31