Home | Products | Download | Purchase | Support 


   

TestLine Sample

 

 

The TestLine sample demonstrates how to custom the default shapes in E-XD++ Library, this sample shows how to create new style link line, new style line with label, new style bezier line, and new style composite shape.

Steps:

1. Create new line class CLineLabelShape that use CFOLineShape as base class.

2. Override the OnDraw3d and OnDrawFlat methods to draw a label around the line.

3. Create a new class CMyDoubleBezierLineShape that use CFOBezierLineShape as base class, override the drawing methods to draw a new look.

4. Create a new class CMyDoubleLineShape that use CFOLineShape as base class, override the drawing methods to draw double line.

5. Create a new class CMyLinkShape that use CFOLinkShape as base class, and override the drawing methods to draw a new look.

6. Create a new class CMySymbol that use CFOCompositeShape as base class.

7. Override the following methods of CExtDataModel to create these new shapes:


void CExtDataModel::AddBezierShape(UINT m_drawshape,CArray<CPoint,CPoint> *arPoints,BOOL bArrow)
{
	CString strCaption;
	CString strName;
	strCaption = _T("");
	strName = _T("");

	switch(m_drawshape)
	{
	case MY_DOUBLEBEZIERLINE_SHAPE:	// CMyDoubleBezierLineShape
		{
			CMyDoubleBezierLineShape *pReturn = new CMyDoubleBezierLineShape;
			pReturn->AddRef();
			pReturn->Create(arPoints);
			pReturn->UpdatePosition();
			strCaption = GetUniqueCaption(m_drawshape);
			strName = GetUniqueName(m_drawshape);
			pReturn->SetObjectCaption(strCaption);
			pReturn->SetObjectName(strName);
			if(bArrow)
			{
				int nType;
				nType = fo_DefaultArrowType;
				pReturn->SetEndArrowType(nType);
			}
			
			DoInitCreateShape(pReturn);
			
			InsertShape(pReturn);
			pReturn->Release();
			pReturn=NULL;
			SetModifiedFlag(TRUE);
		}
		break;
	
	default:
		{
			CFODataModel::AddBezierShape(m_drawshape,arPoints,bArrow);
		}
		break;
	}
}

void CExtDataModel::AddLinkShape(UINT m_drawshape,
									CArray<CPoint,CPoint> *arPoints,
									CFOPortShape *pFrom,
									CFOPortShape *pTo,
									int nArrowType)
{
	CString strCaption;
	CString strName;
	strCaption = _T("");
	strName = _T("");
	switch(m_drawshape)
	{
	case MY_LINK_SHAPE:	//CMyLinkShape
		{
			CMyLinkShape *pLink = new CMyLinkShape;
			pLink->AddRef();
			pLink->Create(arPoints,pFrom,pTo);
			pLink->UpdatePosition();
			strCaption = GetUniqueCaption(m_drawshape);
			strName = GetUniqueName(m_drawshape);
			pLink->SetObjectCaption(_T(""));
			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:
		{
			CFODataModel::AddLinkShape(m_drawshape,arPoints,pFrom,pTo,nArrowType);
		}
		break;

	}
}

void CExtDataModel::AddLineShape(UINT m_drawshape,LPPOINT pptPoints, int nCount,BOOL bArrow)
{
	switch(m_drawshape)
	{
	case MY_DLINE_SHAPE:
		{
			CString strCaption;
			CString strName;
			strCaption = _T("");
			strName = _T("");
			
			CMyDoubleLineShape *pReturn = new CMyDoubleLineShape;
			pReturn->AddRef();
			pReturn->Create(pptPoints,nCount);
			pReturn->UpdatePosition();
			strCaption = GetUniqueCaption(m_drawshape);
			strName = GetUniqueName(m_drawshape);
			pReturn->SetObjectCaption(strCaption);
			pReturn->SetObjectName(strName);
			if(bArrow)
			{
				int nType = fo_DefaultArrowType;
				pReturn->SetEndArrowType(nType);
			}
			
			DoInitCreateShape(pReturn);
			
			InsertShape(pReturn);
			pReturn->Release();
			pReturn=NULL;
			SetModifiedFlag(TRUE);
		}
		break;

	case MY_LABELLINE_SHAPE:
		{
			CString strCaption;
			CString strName;
			strCaption = _T("");
			strName = _T("");
			
			CLineLabelShape *pReturn = new CLineLabelShape;
			pReturn->AddRef();
			pReturn->Create(pptPoints,nCount);
			pReturn->UpdatePosition();
			strCaption = GetUniqueCaption(m_drawshape);
			strName = GetUniqueName(m_drawshape);
			pReturn->SetObjectCaption(strCaption);
			pReturn->SetObjectName(strName);
			if(bArrow)
			{
				int nType = fo_DefaultArrowType;
				pReturn->SetEndArrowType(nType);
			}
			
			DoInitCreateShape(pReturn);
			
			InsertShape(pReturn);
			pReturn->Release();
			pReturn=NULL;
			SetModifiedFlag(TRUE);
		}
		break;

	default:
		{
			CFODataModel::AddLineShape(m_drawshape,pptPoints,nCount,bArrow);
		}
	}
}

8. Drawing these new shapes on the canvas:

BOOL CTestLineView::DoPickShapeSpot(UINT nFlags, CPoint point, UINT nButton)
{
	nButton;
	BOOL bDesign = GetCurrentModel()->IsDesignMode();
	if(!bDesign)
	{
		return FALSE;
	}

	if (nFlags & MK_CONTROL)
	{
		CFOArea rgn;
		CFODrawShape* pShapePick = NULL;
		CFODrawShape* pObj = NULL;

		POSITION pos = m_listSelectComp.GetTailPosition();
		while (pos != NULL)
		{
			pObj = m_listSelectComp.GetPrev(pos);
			if(pObj != NULL)
			{
				rgn = pObj->GetShapeArea();
				
				if (rgn.PickInArea(point, 8)&& !pObj->IsKindOf(RUNTIME_CLASS(CLineLabelShape)))
				{
					pShapePick = pObj;
				}
			}
		}

		if(pShapePick != NULL)
		{
			if((pShapePick->IsKindOf(RUNTIME_CLASS(CFOPolygonShape)) || 
				pShapePick->IsKindOf(RUNTIME_CLASS(CFOFreeLineShape))) && m_bEditSpot)
			{
				int nIndexSpot = -1;
				for (int i=0; i< pShapePick->GetBorderArea().GetMultiPointCount(); i++)
				{
					if (pShapePick->GetBorderArea().GetMultiAreaAt(i).PickInArea(point, 8))
					{
						nIndexSpot = i;
						break;
					}
				}

				if(nIndexSpot >= 0)
				{
					m_pCurHitShape = pShapePick;

					CPoint pt1, pt0, ptInsert;
					pt0 = m_pCurHitShape->GetPointAt(nIndexSpot);

					if (nIndexSpot+1 >= m_pCurHitShape->GetSpotCount())
					{
						pt1 = m_pCurHitShape->GetPointAt(0);
					}
					else
					{
						pt1 = m_pCurHitShape->GetPointAt(nIndexSpot+1);
					}

					int dx = pt1.x - pt0.x;
					int dy = pt1.y - pt0.y;
					double dLength = (double)sqrt(double(dx*dx + dy*dy));
					double dValue = double((pt0.y-point.y) * (pt0.y-pt1.y) - (pt0.x-point.x) * (pt1.x-pt0.x)) / (dLength*dLength);
					
					CPoint ptLine;
					ptLine.x = CFODrawHelper::RoundValue(pt0.x + dValue * dx);
					ptLine.y = CFODrawHelper::RoundValue(pt0.y + dValue * dy);
					
					ptInsert = ptLine;

					DoAddSpotAction(pShapePick,nIndexSpot + 1,ptInsert);
					
					if(!m_pCurHitShape->IsLock())
					{
						m_action_state = State_MoveSpotBegin;
						ClearSelectionHandles();
						m_nCurHitHandle = nIndexSpot + 1;
					}

					return TRUE;
				}
			}
			else if(pShapePick->IsKindOf(RUNTIME_CLASS(CFOLineShape)) || 
				pShapePick->IsKindOf(RUNTIME_CLASS(CFODimLineShape)) || 
				pShapePick->IsKindOf(RUNTIME_CLASS(CFOLinkShape)))
			{
				int nIndexSpot = -1;
				for (int i=0; i<pShapePick->GetBorderArea().GetMultiPointCount(); i++)
				{
					if (pShapePick->GetBorderArea().GetMultiAreaAt(i).PickInArea(point, 8))
					{
						nIndexSpot = i;
						break;
					}
				}

				if(nIndexSpot >= 0)
				{
					m_pCurHitShape = pShapePick;
					CPoint pt1, pt0, ptInsert;
					pt0 = m_pCurHitShape->GetPointAt(nIndexSpot);

					if (nIndexSpot+1 >= m_pCurHitShape->GetSpotCount())
					{
						pt1 = m_pCurHitShape->GetPointAt(0);
					}
					else
					{
						pt1 = m_pCurHitShape->GetPointAt(nIndexSpot+1);
					}

					int dx = pt1.x - pt0.x;
					int dy = pt1.y - pt0.y;
					double dLength = (double)sqrt(double(dx*dx + dy*dy));
					double dValue = double((pt0.y-point.y) * (pt0.y-pt1.y) - (pt0.x-point.x) * (pt1.x-pt0.x)) / (dLength*dLength);
					
					CPoint ptLine;
					ptLine.x = CFODrawHelper::RoundValue(pt0.x + dValue * dx);
					ptLine.y = CFODrawHelper::RoundValue(pt0.y + dValue * dy);
					
					ptInsert = ptLine;
					DoAddSpotAction(pShapePick,nIndexSpot + 1,ptInsert);

					if(!m_pCurHitShape->IsLock())
					{
						m_action_state = State_MoveSpotBegin;
						ClearSelectionHandles();
						m_nCurHitHandle = nIndexSpot + 1;
					}
					return TRUE;
				}
			}
		}
	}
	return FALSE;
}

void CTestLineView::OnDrawMylink() 
{
	// TODO: Add your command handler code here
	CMyLinkShape* pLinkComp = new CMyLinkShape();
	if(pLinkComp != NULL)
	{
		pLinkComp->AddRef();
		CPoint ptPoints[2];
		ptPoints[0] = CPoint(0,0);
		ptPoints[1] = CPoint(0,0);
		pLinkComp->Create(ptPoints,2);

		if (m_pCurLinkShape != NULL)
			m_pCurLinkShape->Release();

		if (pLinkComp != NULL)
			pLinkComp->AddRef();

		m_pCurLinkShape = pLinkComp;
		
		m_action_state = State_LinkReady;
		m_pStartLinkPort = NULL;
		m_pEndLinkPort = NULL;
		m_pCurrentMovePort = pLinkComp->GetToPort();
		m_arPointsPolygon.RemoveAll();

		pLinkComp->Release();

		m_drawshape = MY_LINK_SHAPE;
		m_bUpRightMode = FALSE;
		m_nNumberArrow	= 1;
		SetCurrentDrawingCursor(IDC_FO_DRAWLINK_CURSOR);
	}
}

void CTestLineView::OnUpdateDrawMylink(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	BOOL bDesign = GetCurrentModel()->IsDesignMode();
	pCmdUI->Enable(bDesign);

	pCmdUI->SetCheck(m_drawshape == MY_LINK_SHAPE && (m_nNumberArrow	== 1));

}

void CTestLineView::OnDrawDoublebeizerline() 
{
	// TODO: Add your command handler code here
	m_drawshape = MY_DOUBLEBEZIERLINE_SHAPE;
	SetCurrentDrawingCursor(IDC_FO_DRAWBEZIERLINE_CURSOR);
	m_action_state = State_DrawBezier;
	m_bUpRightMode = FALSE;
}

void CTestLineView::OnUpdateDrawDoublebeizerline(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	BOOL bDesign = GetCurrentModel()->IsDesignMode();
	pCmdUI->Enable(bDesign);

	pCmdUI->SetCheck(m_drawshape == MY_DOUBLEBEZIERLINE_SHAPE);
}

void CTestLineView::OnDrawSymbol() 
{
	// TODO: Add your command handler code here
	StartCustomShapeID(IDR_COMPSRES1);
}

void CTestLineView::OnUpdateDrawSymbol(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI;
}

void CTestLineView::OnLabelLine() 
{
	// TODO: Add your command handler code here
	m_drawshape = MY_LABELLINE_SHAPE;
	SetCurrentDrawingCursor(IDC_FO_DRAWLINE_CURSOR);
	m_action_state = State_DrawLine;
	m_bUpRightMode = FALSE;
}

void CTestLineView::OnUpdateLabelLine(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	BOOL bDesign = GetCurrentModel()->IsDesignMode();
	pCmdUI->Enable(bDesign);

	pCmdUI->SetCheck(m_drawshape == MY_LABELLINE_SHAPE);
}



[ 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