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

📄 freadwriteview.cpp

📁 针对激光扫描仪sick的扫描数据进行读取
💻 CPP
字号:
// FReadWriteView.cpp : implementation of the CFReadWriteView class
//

#include "stdafx.h"
#include "FReadWrite.h"
#include "MainFrm.h"
#include "FileSource.h"
#include "FileDestDlg.h"
#include "math.h"
#include "FReadWriteDoc.h"
#include "FReadWriteView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define PI 3.1415926
/////////////////////////////////////////////////////////////////////////////
// CFReadWriteView

IMPLEMENT_DYNCREATE(CFReadWriteView, CView)

BEGIN_MESSAGE_MAP(CFReadWriteView, CView)
	//{{AFX_MSG_MAP(CFReadWriteView)
	ON_COMMAND(ID_FILE_DESTINATION, OnFileDestination)
	ON_COMMAND(ID_FILE_SOURCE, OnFileSource)
	ON_WM_TIMER()
	ON_COMMAND(ID_STOP_TRANSLATE, OnStopTranslate)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFReadWriteView construction/destruction
static int pointNum=0,oldmedium;
CFReadWriteView::CFReadWriteView()
{
	// TODO: add construction code here
    //m_iarray.SetSize(1024);
	
}
CFReadWriteView::~CFReadWriteView()
{
	if(OUTSTREAM)
	{
		delete []OUTSTREAM;
	}	
}

BOOL CFReadWriteView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CFReadWriteView drawing

void CFReadWriteView::OnDraw(CDC* pDC)
{
	CFReadWriteDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	pDC->TextOut(0,0,"watch the status bar to get the information");
}

/////////////////////////////////////////////////////////////////////////////
// CFReadWriteView printing

BOOL CFReadWriteView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CFReadWriteView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CFReadWriteView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CFReadWriteView diagnostics

#ifdef _DEBUG
void CFReadWriteView::AssertValid() const
{
	CView::AssertValid();
}

void CFReadWriteView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CFReadWriteDoc* CFReadWriteView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFReadWriteDoc)));
	return (CFReadWriteDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFReadWriteView message handlers

void CFReadWriteView::OnFileDestination() 
{
	// TODO: Add your command handler code here
	CFileDestDlg DDlg;
	if (DDlg.DoModal()==IDOK)
	{
		if (DDlg.m_FileName==_T(""))
		{	
			m_fileDest="Hello.TXT";
		}
		else
		{
			m_fileDest=DDlg.m_FileName;
		}		
	    	
		if((OUTSTREAM=fopen(m_fileDest,"w"))==NULL)
		{
			MessageBox("dest file open failed");
		}
		/*else
		{
			MessageBox("dest file open finished");
		}*/
	}
}

void CFReadWriteView::OnFileSource() 
{
	// TODO: Add your command handler code here
	CFileSource SDlg;
	int i=0;
	if (SDlg.DoModal()==IDOK)
	{		 
		if(SDlg.m_FilePath==_T(""))
		{
			UpdateData(TRUE);
			MessageBox("you need enter or choose a file for translate!",NULL,MB_ICONEXCLAMATION );
			UpdateData(FALSE);
		} 
		else
		{
			m_filesource=SDlg.m_FilePath;
		}
		if (!m_sickDecode.Open(m_filesource))
		{
			MessageBox("source file open failed");
		}		
	}	
	m_bOpen=TRUE;
	SetTimer(1,200,NULL);
}
void CFReadWriteView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
    //设置状态栏的有关变量
	CString str;
	CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
	CStatusBar* pStatus=&pFrame->m_wndStatusBar;

	//定义数组存放扫描数据
    m_iarray=new float[401];
	float distance;		
	int scanindex,scancount,count=0,loop=0;
	char m_num[24576];
	
    //校验正确
	if(m_sickDecode.Decode(m_iarray))
	{ 
		m_count++;
		zindex+=0.6;
		scanindex=(int)m_iarray[401];
		if(scanindex>251 && scanindex<256)
				loop+=1;
		scancount=loop*256+scanindex;
	    for(int i=0;i<=401;i++)
		{	            
			distance=m_iarray[i]/1000;	
			vtheta=(double)((40.0+i*0.25)*PI/180.0);
			if(distance>=8.0)
			{	
				//vtheta=(double)((140.0-i*0.25)*PI/180.0);
				/*dx=(float)((m_iarray[i]*sin(htheta))+zindex-offset);
				count+=sprintf(m_num+count,"%u;",pointNum);
				count+=sprintf(m_num+count,"%f;",dx);
				count+=sprintf(m_num+count,"%f;",9999.0);
				count+=sprintf(m_num+count,"%f;",9999.0);		
				count+=sprintf(m_num+count,"%f;",9999.0);
				count+=sprintf(m_num+count,"%d\n",scancount);*/
				//continue;
			}
			else
			{					
				//dx=(float)((m_iarray[i]*sin(htheta))+zindex-offset);
				dx=2.0;
				count+=sprintf(m_num+count,"%u;",pointNum);
		        /*count+=sprintf(m_num+count,"%f;",dx);
				count+=sprintf(m_num+count,"%f;",distance*sin(vtheta));
				count+=sprintf(m_num+count,"%f;",distance*cos(vtheta));		
				count+=sprintf(m_num+count,"%f;",distance);	*/
				count+=sprintf(m_num+count,"%f;",distance*sin(vtheta));
				count+=sprintf(m_num+count,"%f;",distance*cos(vtheta));	
				count+=sprintf(m_num+count,"%f;",dx);
				count+=sprintf(m_num+count,"%d\n",scancount);				
			}
			pointNum++;
		}				
		fwrite(m_num,sizeof(char),count,OUTSTREAM);		
		count=0;

		if(pStatus)
		{
			str.Format("转换数量为:%d",m_count);
			pStatus->SetPaneText(0,str);
		}
	}
	else
	{
		dx+=0.6;
		m_errCount++;				
		if(pStatus)
		{
			str.Format("校验错误情况下转换数量为:%d",m_errCount);
			pStatus->SetPaneText(1,str);
		}
	}
	Invalidate(FALSE);
	CView::OnTimer(nIDEvent);
}

void CFReadWriteView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	m_count=0;
	m_errCount=0;	
	htheta=0.0;
	zindex=0.0;
	offset=0.0;
}


void CFReadWriteView::OnStopTranslate() 
{
	// TODO: Add your command handler code here
	KillTimer(1);
}

⌨️ 快捷键说明

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