Home | Products | Download | Purchase | Support 


   

WeatherSample Sample

 

The WeatherSample sample demonstrates how to build a map based weather application with complex diagram, as below.

With this application, you can draw double line, double paralle line and paralle spline line.

Steps:

1. Design any symbols with ShapeDesigner.

2. Create a new line class CLineLabelShape.

3. Create a new bezier shape, class CMyDoubleBezierLineShape:

4. Create a new paralle line shape, class CMyParallelLine.

5. Create a new paralle spline line shape, class CMyParallelSplineLine.

6. Design map with DiagramEditor and loading with codes:


void CWeatherSampleView::OnInitialUpdate()
{
	SetCurrentModel(GetDocument()->m_pDataModel);
	CFODrawView::OnInitialUpdate();
	LoadXdgFromResource(IDR_MAIN, _T("XdgRes"), FALSE);
	this->SetZoomScale(50);
//	GetCurrentModel()->SetBkColor(RGB(160,224,255));
//	GetCurrentModel()->SetDesignMode(FALSE);
	m_bEditSpot = TRUE;
	CSize szPrint = GetCurrentModel()->GetPrintPosition().Size();
	CSize szCanvas = GetCurrentModel()->GetPagePosition().Size();
	GetCurrentModel()->SetPrintXScale((float)szCanvas.cx / (float)szPrint.cx + 0.01f);
	GetCurrentModel()->SetPrintYScale((float)szCanvas.cy / (float)szPrint.cy + 0.01f);
}

5. Drawing with new style of lines:


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

void CWeatherSampleView::OnMyClosebezier() 
{
	// TODO: Add your command handler code here
	m_drawshape = MY_CLOSELINE_SHAPE;
	SetCurrentDrawingCursor(IDC_FO_DRAWBEZIERLINE_CURSOR);
	m_action_state = State_DrawCloseBezier;
	m_bUpRightMode = FALSE;
}

void CWeatherSampleView::OnUpdateMyClosebezier(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	BOOL bDesign = GetCurrentModel()->IsDesignMode();
	pCmdUI->Enable(bDesign);
	
	pCmdUI->SetCheck(m_drawshape == MY_CLOSELINE_SHAPE);
}

void CWeatherSampleView::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 CWeatherSampleView::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 CWeatherSampleView::OnDrawTrackBezier(CPoint ptTrackDev)
{
	if(m_drawshape != FO_COMP_EXT_BEZIERLINE && m_drawshape != MY_DOUBLEBEZIERLINE_SHAPE && m_drawshape != MY_PARALLEL_SPLINE_SHAPE)
	{
		OnDrawTrackPolyLine(ptTrackDev);
	}

	m_ptMouseDown = ptTrackDev;

	CPoint ptTrack = m_ptMouseDown;
	FODPtoLP(&ptTrack, 1);
	LimitDrawShapeTrackPoint(&m_ptCurrentLog, &ptTrack, 1);
	LimitDrawShapeTrackPoint(&m_ptCurrentLog, &(m_arPointsPolygon[(m_arPointsPolygon.GetSize()-1)]), 1);
	FOLPtoDP(&ptTrack, 1);

	// Prepare dc.
	CFOWndDC dc(this,FALSE);
	PrepareTrackLineDC(&dc);
	
	CRect rcTemp = CFODrawHelper::GetBoundRect(&m_arPointsPolygon);
	m_crSaveUpdate = CFODrawHelper::GetMaxRectExt(rcTemp,m_crSaveUpdate);

	if(m_drawshape == FO_COMP_EXT_BEZIERLINE)
	{
		int nNumPts = m_arPointsPolygon.GetSize();
		
		LPPOINT pTempPts = new POINT[nNumPts + 1];
		
		for ( int ptIdx = 0; ptIdx < nNumPts; ptIdx++ )
		{
			pTempPts[ptIdx] = m_arPointsPolygon.GetAt( ptIdx );
		}

		FODPtoLP(&ptTrack, 1);
		pTempPts[nNumPts] = ptTrack;

		LPPOINT lpSplinePts;
		int nSplinePoints;
		
		CFODrawHelper::GenSplinePoints(pTempPts, nNumPts+1, lpSplinePts, nSplinePoints);
		
		FOLPtoDP(lpSplinePts, nSplinePoints);
		dc.Polyline(lpSplinePts, nSplinePoints);

		delete [] lpSplinePts;
		delete[] pTempPts;

	}
	else if(m_drawshape == MY_DOUBLEBEZIERLINE_SHAPE)
	{
		int nNumPts = m_arPointsPolygon.GetSize();
		
		LPPOINT pTempPts = new POINT[nNumPts + 1];
		
		for ( int ptIdx = 0; ptIdx < nNumPts; ptIdx++ )
		{
			pTempPts[ptIdx] = m_arPointsPolygon.GetAt( ptIdx );
		}
		
		FODPtoLP(&ptTrack, 1);
		pTempPts[nNumPts] = ptTrack;
		
		LPPOINT lpSplinePts;
		int nSplinePoints;
		
		CFODrawHelper::GenSplinePoints(pTempPts, nNumPts+1, lpSplinePts, nSplinePoints);
		
		FOLPtoDP(lpSplinePts, nSplinePoints);
		dc.Polyline(lpSplinePts, nSplinePoints);
		
		delete [] lpSplinePts;
		delete[] pTempPts;
	}
	else if(m_drawshape == MY_PARALLEL_SPLINE_SHAPE)
	{
		int nNumPts = m_arPointsPolygon.GetSize();
		
		LPPOINT pTempPts = new POINT[nNumPts + 1];
		
		for ( int ptIdx = 0; ptIdx < nNumPts; ptIdx++ )
		{
			pTempPts[ptIdx] = m_arPointsPolygon.GetAt( ptIdx );
		}
		
		FODPtoLP(&ptTrack, 1);
		pTempPts[nNumPts] = ptTrack;
		
		LPPOINT lpSplinePts;
		int nSplinePoints;
		
		CFODrawHelper::GenSplinePoints(pTempPts, nNumPts+1, lpSplinePts, nSplinePoints);
		
		FOLPtoDP(lpSplinePts, nSplinePoints);
		dc.Polyline(lpSplinePts, nSplinePoints);
		
		LPPOINT pTempRadCompPts;
		CFODrawHelper::CreateParallelSpline(lpSplinePts, nSplinePoints, pTempRadCompPts, 10);
		dc.Polyline((CPoint *)pTempRadCompPts, nSplinePoints);
		delete pTempRadCompPts; 

		delete [] lpSplinePts;
		delete[] pTempPts;
	}
	else
	{
		CArray<CPoint,CPoint> m_arPointsTemp;
		// Hapy:Changed
		int ptIdx = 0;
		for (ptIdx = 0; ptIdx < m_arPointsPolygon.GetSize(); ptIdx++ )
		{
			m_arPointsTemp.Add(m_arPointsPolygon.GetAt( ptIdx ));
		}

		int nRemain = ( m_arPointsTemp.GetSize() - 1 ) % 3;
		if(m_arPointsTemp.GetSize() > 0)
		{
			switch(nRemain)
			{			
			case 2:
				{
					CPoint ptEnd = m_arPointsTemp.GetAt(m_arPointsTemp.GetSize() - 1);
					CPoint ptMiddle = m_arPointsTemp.GetAt(m_arPointsTemp.GetSize() - 2);
					CPoint ptStart = m_arPointsTemp.GetAt(m_arPointsTemp.GetSize() - 3);
					
					CPoint ptPoints[2];
					CPoint ptTemp = CPoint(ptStart.x + (ptMiddle.x - ptStart.x)*2/3,ptStart.y + (ptMiddle.y - ptStart.y)*2/3);
					ptPoints[0] = ptTemp;
					
					ptTemp = CPoint(ptMiddle.x + (ptEnd.x - ptMiddle.x)*2/3,ptMiddle.y + (ptEnd.y - ptMiddle.y)*2/3);
					ptPoints[1] = ptTemp;
					
					m_arPointsTemp.SetAt(m_arPointsTemp.GetSize() - 2,ptPoints[0]);
					m_arPointsTemp.SetAt(m_arPointsTemp.GetSize() - 1,ptPoints[1]);
					m_arPointsTemp.Add(ptEnd);
				}
				break;
			}
		}
		int numSplines = ( ( m_arPointsTemp.GetSize() - 1 ) / 3 );
		int numBezier = ( numSplines * 3 ) + 1;
		
		LPPOINT pBezierPts = new POINT[numBezier];
		
		for (ptIdx = 0; ptIdx < numBezier; ptIdx++ )
		{
			pBezierPts[ptIdx] = m_arPointsTemp.GetAt( ptIdx );
		}
		
		FOLPtoDP(pBezierPts, numBezier);
		
		dc.PolyBezier(pBezierPts, numBezier);
		
		delete[] pBezierPts;

		m_arPointsPolygon.RemoveAll();
		for (ptIdx = 0; ptIdx < m_arPointsTemp.GetSize(); ptIdx++ )
		{
			m_arPointsPolygon.Add(m_arPointsTemp.GetAt( ptIdx ));
		}
		
		m_arPointsTemp.RemoveAll();
	}

	// Clear dc.
	ClearTrackLineDC(&dc);
}

BOOL CWeatherSampleView::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 CWeatherSampleView::OnNewDesign() 
{
	// TODO: Add your command handler code here
	CFOPCanvasCore::OnFOPFoDesign();
	CMainFrame *pParent = STATIC_DOWNCAST(CMainFrame,AfxGetMainWnd());
	ASSERT_VALID(pParent);

	BOOL bDesign = GetCurrentModel()->IsDesignMode();
	if(bDesign)
	{
//		pParent->m_FileBar.ShowWindow(SW_SHOW);
//		pParent->m_wndPanBar.ShowWindow(SW_SHOW);
	}
	else
	{
//		pParent->m_FileBar.ShowWindow(SW_HIDE);
		pParent->m_wndPanBar.ShowWindow(SW_HIDE);
	}
	pParent->RecalcLayout();
}

void CWeatherSampleView::OnUpdateNewDesign(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	BOOL bDesign = GetCurrentModel()->IsDesignMode();
	pCmdUI->SetCheck(bDesign);
}

void CWeatherSampleView::OnParallelLine() 
{
	// TODO: Add your command handler code here
	m_drawshape = MY_PARALLEL_SHAPE;
	SetCurrentDrawingCursor(IDC_FO_DRAWLINE_CURSOR);
	m_action_state = State_DrawPLine;
	m_bUpRightMode = FALSE;
}

void CWeatherSampleView::OnUpdateParallelLine(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	BOOL bDesign = GetCurrentModel()->IsDesignMode();
	pCmdUI->Enable(bDesign);
	
	pCmdUI->SetCheck(m_drawshape == MY_PARALLEL_SHAPE);
}

void CWeatherSampleView::OnDrawParallelSpline() 
{
	// TODO: Add your command handler code here
	m_drawshape = MY_PARALLEL_SPLINE_SHAPE;
	SetCurrentDrawingCursor(IDC_FO_DRAWBEZIERLINE_CURSOR);
	m_action_state = State_DrawBezier;
	m_bUpRightMode = FALSE;
}

void CWeatherSampleView::OnUpdateDrawParallelSpline(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	BOOL bDesign = GetCurrentModel()->IsDesignMode();
	pCmdUI->Enable(bDesign);
	
	pCmdUI->SetCheck(m_drawshape == MY_PARALLEL_SPLINE_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