Home | Products | Download | Purchase | Support 


   

NewNetwork Sample

 

The NewNetwork sample demonstrates how to build a network diagram with E-XD++, as below.

Steps:

1. Design any symbols with ShapeDesigner.

2. Create a new up - right link line class CNewUpRightLinkShape.

3. Create a new mather shape, class CFOMatherLineShape:

4. Create link with new link line typer:

void CNewNetworkView::InitLinkShape()
{
	m_drawshape = FO_NETWORK_LINK;
	m_bUpRightMode = FALSE;
	SetCurrentDrawingCursor(IDC_FO_DRAWLINK_CURSOR);
	m_nNumberArrow			=	0;
}

5. Limit before link line is created:

BOOL CNewNetworkView::DoBeforeLinkCreated(CFOPortShape *pFrom,CFOPortShape *pTo)
{
	BOOL bNeedLink = FALSE;
	if(pFrom != NULL && pTo != NULL)
	{
		if(pFrom->IsKindOf(RUNTIME_CLASS(CFOPortShape)) && 
			pTo->IsKindOf(RUNTIME_CLASS(CFOPortShape)))
		{
			CFOPortShape *pStart = static_cast<CFOPortShape *>(pFrom);
			CFOPortShape *pEnd = static_cast<CFOPortShape *>(pTo);
			
			CFOMatherLineShape *pNode1 = (CFOMatherLineShape *)pStart->GetParentComp();
			CFOMatherLineShape *pNode2 = (CFOMatherLineShape *)pEnd->GetParentComp();
			
			BOOL bLinked = FALSE;
			if(pStart->IsLinked(pEnd) || 
				pEnd->IsLinked(pStart))
			{
				bLinked = TRUE;
			}
			
			if(pNode1 != NULL && pNode2 != NULL)
			{
				if(pNode1 == pNode2)
				{
					bLinked = TRUE;
				}
			}
			
			if(!bLinked)
			{
				bNeedLink = TRUE;
			}
		}
		else
		{
			bNeedLink = TRUE;
		}
	}
	
	if(!bNeedLink)
	{
		return FALSE;
	}
	return TRUE;
}
6. Override the DoCreateShapeByType and AddLinkShape of CFODataModel to handle new shapes:

void CExtTabModel::AddLinkShape(UINT m_drawshape,
									CArray<CPoint,CPoint> *arPoints,
									CFOPortShape *pFrom,
									CFOPortShape *pTo,
									int nArrowType)
{
	BOOL bNeedLink = FALSE;
	if(pFrom != NULL && pTo != NULL)
	{
		if(pFrom->IsKindOf(RUNTIME_CLASS(CFOPortShape)) && 
			pTo->IsKindOf(RUNTIME_CLASS(CFOPortShape)))
		{
			CFOPortShape *pStart = static_cast<CFOPortShape *>(pFrom);
			CFOPortShape *pEnd = static_cast<CFOPortShape *>(pTo);
			
			CFOMatherLineShape *pNode1 = (CFOMatherLineShape *)pStart->GetParentComp();
			CFOMatherLineShape *pNode2 = (CFOMatherLineShape *)pEnd->GetParentComp();
			
			BOOL bLinked = FALSE;
			if(pStart->IsLinked(pEnd) || 
				pEnd->IsLinked(pStart))
			{
				bLinked = TRUE;
			}
			
			if(pNode1 != NULL && pNode2 != NULL)
			{
				if(pNode1 == pNode2)
				{
					bLinked = TRUE;
				}
			}
			
			if(!bLinked)
			{
				bNeedLink = TRUE;
			}
		}
		else
		{
			bNeedLink = TRUE;
		}
	}

	if(!bNeedLink)
	{
		return;
	}

	CString strCaption;
	CString strName;
	strCaption = _T("");
	strName = _T("");
	switch(m_drawshape)
	{

	case FO_NETWORK_LINK:	//CNewUpRightLinkShape
		{
			CNewUpRightLinkShape *pLink = new CNewUpRightLinkShape;
			pLink->AddRef();
			pLink->Create(arPoints,pFrom,pTo);
			pLink->UpdatePosition();
			strCaption = GetUniqueCaption(m_drawshape);
			strName = GetUniqueName(m_drawshape);
			pLink->SetObjectCaption(strCaption);
			pLink->SetObjectName(strName);
			
			switch(nArrowType)
			{
			case 1:
				{
					int nType = fo_DefaultArrowType;
					pLink->SetEndArrowType(nType);
				}
				break;
				
			case 2:
				{
					int nType = fo_DefaultArrowType;
					pLink->SetEndArrowType(nType);
					pLink->SetStartArrowType(nType);
				}
				break;
			}
			DoInitCreateShape(pLink);
			CFOAddLinkAction* pAction = new CFOAddLinkAction(this, pLink);
			pAction->SetToPort(pTo);
			pAction->SetFromPort(pFrom);
			
			Do(pAction,TRUE);
			
			SetModifiedFlag();
			pLink->Release();
			pLink=NULL;
		}
		break;


	default:
		{
			CFOTabPageModel::AddLinkShape(m_drawshape,arPoints,pFrom,pTo,nArrowType);
		}
		break;

	}
}

CFODrawShape *CExtTabModel::DoCreateShapeByType(UINT m_drawshape,
												 CRect &rcCreate,
												 CString strFileName,
												 CFOToolBoxItem *pCurItem)
{
	pCurItem;
	CFODrawShape *pReturn = NULL;
	CString strCaption;
	CString strName;
	strCaption = "";
	strName = "";
	CPoint ptTrack = rcCreate.TopLeft();
	if(m_drawshape != FO_COMP_NONE)
	{
		CRect rc(rcCreate);
		rc.NormalizeRect();
		if(rc.IsRectEmpty()||(rc.Width()<=10 && rc.Height()<20))
		{
			switch(m_drawshape)
			{
				
			case MY_MATHER_LINE_SHAPE:
				{
					rc = CRect(ptTrack.x-180,ptTrack.y-11,ptTrack.x+180,ptTrack.y+11);
				}
				break;
				
			default:
				{
				}
				break;
			}
		}
		
		switch(m_drawshape)
		{
		case MY_MATHER_LINE_SHAPE:
			{
				pReturn = new CFOMatherLineShape;
				pReturn->AddRef();
				pReturn->Create(rc,"");
				pReturn->UpdatePosition();
				strCaption = GetUniqueCaption(pReturn->GetType());
				strName = GetUniqueName(pReturn->GetType());
				pReturn->SetObjectCaption(strCaption);
				pReturn->SetObjectName(strName);
			}
			break;
			
		default:
			{
				pReturn = CFOTabPageModel::DoCreateShapeByType(m_drawshape,rcCreate,strFileName);
			}
			break;
		}
	}
	return pReturn;
}

 


[ 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