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

📄 setcoordinatedlg.cpp

📁 在windows下对Flock of Bird 跟踪器编程的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SetCoordinateDlg.cpp : implementation file
//

#include "stdafx.h"

#include "SetCoordinate.h"
#include "SetCoordinateDlg.h"
#include <dos.h>
#include <math.h>

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetCoordinateDlg dialog

CSetCoordinateDlg::CSetCoordinateDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSetCoordinateDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSetCoordinateDlg)
	m_iIndex = 0;
	m_fLength = 0.0f;
	m_fWidth = 0.0f;
	m_cSendChar = _T("");
	m_strReceive = _T("");
	m_nPortNumber = 0;
	m_fAzimuth = 0.0f;
	m_fElevation = 0.0f;
	m_fRoll = 0.0f;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSetCoordinateDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetCoordinateDlg)
	DDX_Control(pDX, IDC_COMBO_UINT, m_ctrlUint);
	DDX_Control(pDX, IDC_LIST_REFERPOINT, m_ctrlReferPoint);
	DDX_Control(pDX, IDC_COMBO_HEMISPHERE, m_ctrlHemisphere);
	DDX_Control(pDX, IDC_COMBO_BAUD, m_ctrlBaud);
	DDX_Control(pDX, IDC_COMBO_OUTPUTMODE, m_ctrlOptputMode);
	DDX_Control(pDX, IDC_COMBO_DATAMODE, m_ctrlDataMode);
	DDX_Control(pDX, IDC_COMBO_TYPE, m_ctrlType);
	DDX_Text(pDX, IDC_INDEX, m_iIndex);
	DDX_Text(pDX, IDC_LENGTH, m_fLength);
	DDX_Text(pDX, IDC_WIDTH, m_fWidth);
	DDX_Control(pDX, IDC_MSCOMM, m_com);
	DDX_Text(pDX, IDC_EDIT_SEND, m_cSendChar);
	DDX_Text(pDX, IDC_EDIT_RECEIVE, m_strReceive);
	DDX_Text(pDX, IDC_PORTNUMBER, m_nPortNumber);
	DDX_Text(pDX, IDC_EDIT_AZIMUTH, m_fAzimuth);
	DDX_Text(pDX, IDC_EDIT_ELEVATION, m_fElevation);
	DDX_Text(pDX, IDC_EDIT_ROLL, m_fRoll);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSetCoordinateDlg, CDialog)
	//{{AFX_MSG_MAP(CSetCoordinateDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_ADD_INDICATOR, OnAddIndicator)
	ON_BN_CLICKED(IDC_INITFOB, OnInitFob)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_CMDSEND, OnCmdSend)
	ON_BN_CLICKED(IDC_CMDSTOPRECEIVE, OnCmdStopReceive)
	ON_BN_CLICKED(IDC_CMDCLEARRECEIVE, OnCmdClearReceive)
	ON_BN_CLICKED(IDC_CMDSETHEMISPHERE, OnCmdSetHemisphere)
	ON_BN_CLICKED(IDC_CMDANGLEALIGN, OnCmdAngleAlign)
	ON_BN_CLICKED(IDC_BTN_INSERTREFERPOINT, OnBtnInsertReferPoint)
	ON_BN_CLICKED(IDC_BTN_CLEARREFERPOINT, OnBtnClearReferPoint)
	ON_BN_CLICKED(IDC_BTN_DELETEREFERPOINT, OnBtnDeleteReferPoint)
	ON_BN_CLICKED(IDC_BTN_GETPLANEPARA, OnBtnGetPlanePara)
	ON_BN_CLICKED(IDC_BTN_METAL, OnBtnMetal)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetCoordinateDlg message handlers

BOOL CSetCoordinateDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	m_ctrlType.SetCurSel( 0 );
	m_ctrlDataMode.SetCurSel( 4 );
	m_ctrlOptputMode.SetCurSel( 0 );
	m_ctrlBaud.SetCurSel(3);
	m_ctrlHemisphere.SetCurSel( 0 );
	m_ctrlUint.SetCurSel( 2 );

	m_sIniFilename = "f:\\qyj\\fob\\indicator.ini";
	m_iIndex = ::GetPrivateProfileInt( "number of indicators", "count", 0, m_sIniFilename );
	m_iIndex++;

	count = 0;
	times = 0;

	m_nPortNumber = 1;


	m_ctrlReferPoint.InsertColumn ( 0, "类型", LVCFMT_CENTER, 52 );
	m_ctrlReferPoint.InsertColumn ( 1, "X坐标", LVCFMT_RIGHT, 55 );
	m_ctrlReferPoint.InsertColumn ( 2, "Y坐标", LVCFMT_RIGHT, 55 );
	m_ctrlReferPoint.InsertColumn ( 3, "Z坐标", LVCFMT_RIGHT, 55 );
	m_ctrlReferPoint.InsertColumn ( 4, "方位角", LVCFMT_RIGHT, 55 );
	m_ctrlReferPoint.InsertColumn ( 5, "仰角", LVCFMT_RIGHT, 55 );
	m_ctrlReferPoint.InsertColumn ( 6, "转角", LVCFMT_RIGHT, 55 );

	UpdateData( FALSE );

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSetCoordinateDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CSetCoordinateDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSetCoordinateDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}



void CSetCoordinateDlg::OnAddIndicator() 
{
	// TODO: Add your control notification handler code here
	int		nCount = 0;
	CString	sIndex,sTemp;
	float	fValue;

	UpdateData( TRUE );

	//仪表数目
	nCount = ::GetPrivateProfileInt( "number of indicators", "count", 0, m_sIniFilename );
	
	nCount++;
	sTemp.Format( "%d", nCount );
	::WritePrivateProfileString("number of indicators","count",sTemp,m_sIniFilename);

	//仪表名称
	sIndex.Format("indicator %d",nCount);
	::WritePrivateProfileString(sIndex,"name","高度表",m_sIniFilename);
	
	//仪表类型
	sTemp.Format( "%d", m_ctrlType.GetCurSel() );
	::WritePrivateProfileString(sIndex,"type",sTemp,m_sIniFilename);

	//仪表尺寸
	sTemp.Format("%.2f",m_fLength);
	::WritePrivateProfileString(sIndex,"length",sTemp,m_sIniFilename);
	sTemp.Format("%.2f",m_fWidth);
	::WritePrivateProfileString(sIndex,"width",sTemp,m_sIniFilename);

	//仪表方位坐标
	fValue = 0.1;
	sTemp.Format("%.2f",fValue);
	::WritePrivateProfileString(sIndex,"X",sTemp,m_sIniFilename);
	fValue = 0.1;
	sTemp.Format("%.2f",fValue);
	::WritePrivateProfileString(sIndex,"Y",sTemp,m_sIniFilename);
	fValue = 0.1;
	sTemp.Format("%.2f",fValue);
	::WritePrivateProfileString(sIndex,"Z",sTemp,m_sIniFilename);
	fValue = 0.1;
	sTemp.Format("%.2f",fValue);
	::WritePrivateProfileString(sIndex,"A",sTemp,m_sIniFilename);
	fValue = 0.1;
	sTemp.Format("%.2f",fValue);
	::WritePrivateProfileString(sIndex,"E",sTemp,m_sIniFilename);
	fValue = 0.1;
	sTemp.Format("%.2f",fValue);
	::WritePrivateProfileString(sIndex,"R",sTemp,m_sIniFilename);
	
}



void CSetCoordinateDlg::OnInitFob() 
{
	CString str;
	
	bSend = FALSE;
	bReceive = TRUE;
	
	UpdateData(TRUE);
	
	m_ctrlBaud.GetLBText( m_ctrlBaud.GetCurSel(), str );
	m_strSettings.Format( "%s,n,8,1", str );// = _T("19200,n,8,1");
	m_strSendString = _T("");

	/*===========================================*/

	m_com.SetCommPort(m_nPortNumber);       //选择端口
	if( !m_com.GetPortOpen())
		m_com.SetPortOpen(TRUE);			//打开串口
	else
		AfxMessageBox("cannot open serial port");
	
	//波特率1,校验位,数据位,停止位
	m_com.SetSettings(m_strSettings); 
	
	//参数1表示每当串口接收缓冲区中有多于或等于1个字符时将引发一个接收数据的OnComm事件
	m_com.SetRThreshold(1); 
	
	m_com.SetInputMode(1);

	//设置当前接收区数据长度为0
	m_com.SetInputLen(0);  
	
	//先预读缓冲区以清除残留数据
	m_com.GetInput();
	
	return;
}

void CSetCoordinateDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here

}

void CSetCoordinateDlg::DispData()
{
	CString str;
	
	float * data;

	switch(1)
	{
	case POS:
		str.Format( "position:\nX:%8.2fY:%8.2fZ:%8.2f",
			data[0], data[1], data[2]);
		break;		

	case ANGLE:
		str.Format( "angle:\nA:%8.2fE:%8.2fR:%8.2ff",
			data[0], data[1], data[2]);
		break;
	
	case MATRIX:
		str.Format( "matrix:\n%8.2ff%8.2f%8.2f\n%8.2f%8.2f%8.2f\n%8.2f%8.2f%8.2f",
			data[0], data[1], data[2], data[3], data[4], 
			data[5], data[6], data[7], data[8] );
		break;		
	
	case POSANGLE:
		str.Format( "position:\nX:%8.2fY:%8.2fZ:%8.2f\nangle:\ncA:%8.2fE:%8.2fR:%8.2f\n",
			data[0], data[1], data[2], data[3], data[4], data[5] );
		break;
	
	case POSMATRIX:
		str.Format( "position:\n%8.2ff%8.2f%8.2f\nmatrix:\n%8.2f%8.2f%8.2f\n%8.2f%8.2f%8.2f\n%8.2f%8.2f%8.2f",
			data[0], data[1], data[2], data[3], data[4], data[5], 
			data[6], data[7], data[8], data[9], data[10], data[11] );
		break;		
	}
	
	SetDlgItemText(IDC_COORDINATE, str);

	return;
}


void CSetCoordinateDlg::ShowInfo(CString str)
{
	SetDlgItemText(IDC_STATUS, str);
}

void CSetCoordinateDlg::OnCmdSend() 
{
	// TODO: Add your control notification handler code here

	CString str;
	unsigned char outputmode = m_ctrlOptputMode.GetCurSel();

	SetCmdSize();
	
	str.Format("%c",fob_posorientcmd);
	m_com.SetOutput(COleVariant(str));

	start = clock();

	if ( outputmode == 0 )
		m_com.SetOutput(COleVariant("B"));
	if ( outputmode == 2 )

⌨️ 快捷键说明

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