⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mappinggraph.cpp

📁 基于AS-R的避障小车 由南京航空航天大学编制
💻 CPP
字号:
// MappingGraph.cpp : implementation file
//


#include "stdafx.h"
#include <math.h>
#include "MotionDemo.h"
#include "MappingGraph.h"
#include "MotionDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMappingGraph

CMappingGraph::CMappingGraph()
{
	 Clear();
}

CMappingGraph::~CMappingGraph()
{
	 Clear();
}


BEGIN_MESSAGE_MAP(CMappingGraph, CStatic)
	//{{AFX_MSG_MAP(CMappingGraph)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMappingGraph message handlers

void CMappingGraph::SampleData(MAP_DATA data)
{
    static double arc = 0.0;

	arc = data.dArc;
	/*
	if( arc >=(PI*5/6))
	{
		Clear();
	}
	*/
	MAP_DATA* pData = new MAP_DATA;
	pData->dArc = arc;
	pData->dData = data.dData;

	map_list.AddTail(pData);

    static int i=0;
	
	if(i==4)
	{
		Invalidate();
		i=0;
		Clear();
		return;
	}
	i++;
	
//	Clear();
	/*
	if((i>20) && (i<26))
	{
		if(i==21)
		{
        	Clear();
		}
		if(i==25)
		{
			i=0;
		}
	    Invalidate();
		
	}
	*/
}

void CMappingGraph::Clear()
{
    POSITION pos = map_list.GetHeadPosition();

	while( pos )
	{
		MAP_DATA* pData = map_list.GetNext(pos);
		delete pData;
		pData = NULL;
	}
	map_list.RemoveAll();
}

void CMappingGraph::OnPaint()
{
    int  RADIUS = 1;
	CPaintDC dc(this); // device context for painting
	CRect  rc,rcEllips;
	CPen   pen,penLine;
	MAP_DATA* pData = NULL;
	MAP_DATA* pOldData = NULL;
	CPoint ptCenter,pt;
	int    x = 0,y = 0;
	double  xratio = 1.0;
	double  yratio = 1.0;
	
	GetClientRect(&rc);

	ptCenter.x = rc.Width()/2;
	ptCenter.y = rc.Height()-25;

	dc.SelectStockObject(WHITE_BRUSH);
	dc.PatBlt(0,0,rc.right-rc.left,rc.bottom - rc.top,PATCOPY);
		
	xratio = (rc.Width()/2.0)/MAX_DIS;
	yratio = (rc.Height())/MAX_DIS;
    RADIUS =0.21*xratio;
	//draw the text at the left_top corner
	x = 0;
	y+= 10;
	CString str = "比例尺1:100(1厘米相当于1米)";
	dc.TextOut(x,y,str);
	CSize sz = dc.GetOutputTextExtent(str);
	y += sz.cy;
	pt.x = x;
	pt.y = y;
    dc.MoveTo(pt);
	pt.x += sz.cx;
	dc.LineTo(pt);

	//draw direction tips
	CString strText;
	x = rc.Width()/2;
    y = 0;
	strText.Format("%s","前");
	dc.TextOut(x,y,strText,strText.GetLength());
	x = 0;
    y = rc.Height()-25;
	strText.Format("%s","左");
	dc.TextOut(x,y,strText,strText.GetLength());
    x = rc.Width()-15;
    y = rc.Height()-25;
	strText.Format("%s","右");
	dc.TextOut(x,y,strText,strText.GetLength());
    
    
	//draw the ellips at the center
	rcEllips.left = ptCenter.x - RADIUS;
	rcEllips.right = rcEllips.left + 2*RADIUS;
	rcEllips.top = ptCenter.y - RADIUS;
	rcEllips.bottom = rcEllips.top + 2 * RADIUS;
	
	pen.CreatePen(PS_DASHDOTDOT,1,RGB(128,128,128));
	penLine.CreatePen(PS_SOLID,3,RGB(255,0,0));
	dc.SelectObject(&penLine);
	dc.Ellipse(&rcEllips);

	int nLastX = 0,nLastY=0;
	BOOL bFirst = TRUE;

	//draw the object mapping
	dc.SelectObject(&penLine);
	POSITION pos = map_list.GetHeadPosition();
//	int ii=0;
	while( pos )
	{
		pData = map_list.GetNext(pos);

		x = (int)(ptCenter.x+xratio*(pData->dData+0.1)*cos(PI-(pData->dArc)));
		y = (int)(ptCenter.y-yratio*(pData->dData+0.1)*sin(PI-(pData->dArc)));

		if( bFirst )
		{
		
			bFirst = FALSE;
		    dc.MoveTo(x,y);
		}
		else
		{	
			static int ii=0;
			ii++;
			dc.MoveTo(nLastX,nLastY);
			dc.LineTo(x,y);
			if(ii==4)
			{
              bFirst = TRUE;
			  ii=0;

			}
		}	
		nLastX = x;
		nLastY = y;
//		SetDlgItemInt(IDC_EDIT_DIS,x);
//        SetDlgItemInt(IDC_EDIT_DIS1,y);
	}

/*
	//draw the connect line
	dc.SelectObject(&pen);
	pos = map_list.GetHeadPosition();
	int x0,y0;
	while( pos )
	{
		pData = map_list.GetNext(pos);
		
		x0 = (int)(ptCenter.x + RADIUS * cos(pData->dArc));
		y0 = (int)(ptCenter.y + RADIUS * sin(pData->dArc));

		x = (int)(ptCenter.x+xratio*(pData->dData+0.1)*cos(pData->dArc-PI/2));
		y = (int)(ptCenter.y-yratio*(pData->dData+0.1)*sin(pData->dArc-PI/2));
		
		dc.MoveTo(x0,y0);
		dc.LineTo(x,y);	
	}
*/
	dc.SelectStockObject(WHITE_BRUSH);
	pen.DeleteObject();
	penLine.DeleteObject();
	//	Clear();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -