Home | Products | Download | Purchase | Support 


   

PipeDemo Sample

 

The PipeDemo sample demonstrates how to build an dynamic link line, it likes water flowing, as below.

Steps:

1. Design any symbols with ShapeDesigner.

2. Create diagram with DiagramEditor and save it to a xdg file.

3. Load Xdg file to the canvas by call:

#define ID_TIMER_ID 1123

void CPipeDemoView::OnInitialUpdate()
{
	SetCurrentModel(GetDocument()->m_pDataModel);
	CFODrawView::OnInitialUpdate();

	LoadXdgFromResource(IDR_MAIN, _T("XdgRes"), FALSE);
	GetCurrentModel()->SetDesignMode(FALSE);

	CFODrawShape *pShape = (CFODrawShape *)GetCurrentModel()->FindShapeWithKey1(_T("2000"));
	m_PipeList1.AddTail(pShape);
	pShape->SetBkColor(RGB(255,255,255));


	pShape = (CFODrawShape *)GetCurrentModel()->FindShapeWithKey1(_T("2001"));
	m_PipeList1.AddTail(pShape);
	pShape->SetBkColor(RGB(255,255,255));

	pShape = (CFODrawShape *)GetCurrentModel()->FindShapeWithKey1(_T("2002"));
	m_PipeList1.AddTail(pShape);
	pShape->SetBkColor(RGB(255,255,255));

	pShape = (CFODrawShape *)GetCurrentModel()->FindShapeWithKey1(_T("2003"));
	m_PipeList1.AddTail(pShape);
	pShape->SetBkColor(RGB(255,255,255));

	pShape = (CFODrawShape *)GetCurrentModel()->FindShapeWithKey1(_T("2004"));
	m_PipeList1.AddTail(pShape);
	pShape->SetBkColor(RGB(255,255,255));

	pShape = (CFODrawShape *)GetCurrentModel()->FindShapeWithKey1(_T("2005"));
	m_PipeList1.AddTail(pShape);
	pShape->SetBkColor(RGB(255,255,255));

	pShape = (CFODrawShape *)GetCurrentModel()->FindShapeWithKey1(_T("2006"));
	m_PipeList1.AddTail(pShape);
	pShape->SetBkColor(RGB(255,255,255));

	pShape = (CFODrawShape *)GetCurrentModel()->FindShapeWithKey1(_T("2007"));
	m_PipeList1.AddTail(pShape);
	pShape->SetBkColor(RGB(255,255,255));

	SetTimer(ID_TIMER_ID, 500, NULL);
}

4.  Do animate with timer:


void CPipeDemoView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent == ID_TIMER_ID)
	{
		if(m_PipeList1.GetCount() > 0)
		{
			POSITION pos = m_PipeList1.GetHeadPosition();
			while(pos != NULL)
			{
				CFODrawShape *pLink = (CFODrawShape *)m_PipeList1.GetNext(pos);
				if(pLink->IsKindOf(RUNTIME_CLASS(CMyNewPipeShape)))
				{
					CMyNewPipeShape *pipe = static_cast<CMyNewPipeShape *>(pLink);
					pipe->DoAnimate();
				}
			}
			
			UpdateShapes(&m_PipeList1);
		}
	}
	else
	{
		CFODrawView::OnTimer(nIDEvent);
	}
}

void CPipeDemoView::OnChangeColor() 
{
	// TODO: Add your command handler code here
	KillTimer(ID_TIMER_ID);
	CLinePropDlg dlg;
	CMyNewPipeShape *pShape = (CMyNewPipeShape *)GetCurrentModel()->FindShapeWithKey1(_T("2000"));
	dlg.m_crLine = pShape->GetPipeLineColor();
	dlg.m_nLineWidth = pShape->GetPipeLineWidth();
	if(dlg.DoModal() == IDOK)
	{
		POSITION pos = m_PipeList1.GetHeadPosition();
		while(pos != NULL)
		{
			CFODrawShape *pLink = (CFODrawShape *)m_PipeList1.GetNext(pos);
			if(pLink->IsKindOf(RUNTIME_CLASS(CMyNewPipeShape)))
			{
				CMyNewPipeShape *pipe = static_cast<CMyNewPipeShape *>(pLink);
				pipe->SetPipeLineColor(dlg.m_crLine);
				pipe->SetPipeLineWidth(dlg.m_nLineWidth);
			}
		}
	}
	SetTimer(ID_TIMER_ID, 50, NULL);
}

void CPipeDemoView::OnStart() 
{
	// TODO: Add your command handler code here
	SetTimer(ID_TIMER_ID, 500, NULL);
}

void CPipeDemoView::OnStop() 
{
	// TODO: Add your command handler code here
	KillTimer(ID_TIMER_ID);
}
5. Create a CMyNewPipeShape class that using CFOLineShape as base class.


[ Home | Products | Download Area | Purchase | SupportContact us ]


Copyright ?1998-2007 UCanCode.Net Software, all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.com