?? fadlg.cpp
字號:
// FaDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Fa.h"
#include "FaDlg.h"
#include "math.h"
#include "dandao.hpp"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define socklen_t int
//#pragma comment(lib,"wsock32.lib")
/////////////////////////////////////////////////////////////////////////////
// CFaDlg dialog
rcdaodan daodan1;
rctbm target;
vtindex vt_index;
int n=0;
CFaDlg::CFaDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFaDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFaDlg)
m_dt1 = 0.0f;
m_tx1 = 0.0f;
m_ty1 = 0.0f;
m_tz1 = 0.0f;
m_tp1 = 0.0f;
m_th1 = 0.0f;
m_mx1 = 0.0f;
m_my1 = 0.0f;
m_mz1 = 0.0f;
m_mp1 = 0.0f;
m_mh1 = 0.0f;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
libmmfileInitialize();
libmwsglmInitialize();
mlfHGInitialize(NULL,NULL);
}
void CFaDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFaDlg)
// DDX_Control(pDX, IDC_PORT, m_port);
// DDX_Control(pDX, IDC_LIST2, m_list);
// DDX_Control(pDX, IDC_EDIT_ADDRESS, m_address);
DDX_Text(pDX, IDC_EDIT_tx, m_tx1);
DDX_Text(pDX, IDC_EDIT_ty, m_ty1);
DDX_Text(pDX, IDC_EDIT_tz, m_tz1);
DDX_Text(pDX, IDC_EDIT_tp, m_tp1);
DDX_Text(pDX, IDC_EDIT_th, m_th1);
DDX_Text(pDX, IDC_EDIT_mx, m_mx1);
DDX_Text(pDX, IDC_EDIT_my, m_my1);
DDX_Text(pDX, IDC_EDIT_mz, m_mz1);
DDX_Text(pDX, IDC_EDIT_mp, m_mp1);
DDX_Text(pDX, IDC_EDIT_mh, m_mh1);
DDX_Text(pDX, IDC_EDIT_dt, m_dt1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFaDlg, CDialog)
//{{AFX_MSG_MAP(CFaDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_SEND, OnButtonSend)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON_DD, OnButtonDd)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BTN_3d, OnBTN3d)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFaDlg message handlers
BOOL CFaDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
GenAxis2();
CWnd * pWndMatlabFrame=GetDlgItem(IDC_PLOT);
DockMatlabFigure(m_mwhFigure,pWndMatlabFrame);
mlfHGWaitForFiguresToDie();
view(m_mwhAxis,-24,24);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CFaDlg::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 CFaDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//DEL bool CFaDlg::Listen(int PortNum)
//DEL {
//DEL ListenSocket=socket(PF_INET,SOCK_DGRAM,0);
//DEL if(ListenSocket==INVALID_SOCKET)
//DEL {
//DEL AfxMessageBox("Error:Socket創建失??!");
//DEL return false;
//DEL }
//DEL
//DEL srv.sin_family = PF_INET;
//DEL srv.sin_addr.s_addr=htonl(INADDR_ANY);
//DEL srv.sin_port = htons(PortNum);
//DEL
//DEL if(bind(ListenSocket,(struct sockaddr *)&srv,sizeof(srv))!=0)
//DEL {
//DEL AfxMessageBox("Error:Socket綁定失?。?quot;);
//DEL closesocket(ListenSocket);
//DEL return false;
//DEL
//DEL }
//DEL int ThreadID; // 線程id
//DEL
//DEL DWORD thread;
//DEL //調用createthread創建線程
//DEL ThreadID = (int)CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ListenThread, (void *)this, 0, &thread);
//DEL ThreadID = ThreadID ? 0 : 1; // 如果成功,則返回為0
//DEL
//DEL if(ThreadID) // ThreadID如果不為0,則線程創建失敗
//DEL {
//DEL AfxMessageBox("Error:線程創建失敗!");
//DEL return false;
//DEL }
//DEL else
//DEL
//DEL return true;
//DEL }
//DEL void *CFaDlg::ListenThread(void *data)
//DEL {
//DEL char buf1[4096];
//DEL CString str;
//DEL CFaDlg *Comm = (CFaDlg *)data;
//DEL int len = sizeof(Comm->client);
//DEL while(1) // 一直循環
//DEL {
//DEL //接收數據
//DEL int result = recvfrom( Comm->ListenSocket, buf1, sizeof(buf1)-1, 0, (sockaddr *)&Comm->client, (socklen_t *)&len);
//DEL if ( result > 0 )
//DEL {
//DEL memcpy(&daodan1,buf1,sizeof(daodan1));
//DEL //buf1[result] = 0;
//DEL
//DEL str.Format("IP:%s(port:%f)>%s",inet_ntoa(Comm->client.sin_addr),ntohs(Comm->client.sin_port),daodan1.a);
//DEL Comm->m_list.AddString(str);
//DEL
//DEL }
//DEL }
//DEL
//DEL
//DEL }
void CFaDlg::OnButtonSend()
{
// TODO: Add your command handler code here
UpdateData(TRUE);
// m_address.GetWindowText(buf,40);//IP
// m_port.GetWindowText(port,40);
in_vm=dlg_cssd.m_vm;
in_vt=dlg_cssd.m_vt;
in_dt=dlg_cssd.m_dt;
vt_index.revt=10;
if (dlg_cssd.m_vt>0)
{
vt_index.m=0;
}
else vt_index.m=1;
// SendMsg((char*)&vt_index,sizeof(vt_index)+1,buf,atoi(port));
in_m=dlg_cssd.m_m;
in_tp=dlg_cssd.m_p;
in_th=dlg_cssd.m_h;
in_tx=dlg_cssd.m_tx;
in_ty=dlg_cssd.m_ty;
in_tz=dlg_cssd.m_tz;
in_mx=0;
in_my=0;
in_mz=0;
dout_r=sqrt((dlg_cssd.m_tx)*(dlg_cssd.m_tx)+(dlg_cssd.m_ty)*(dlg_cssd.m_ty)+(dlg_cssd.m_tz)*(dlg_cssd.m_tz));
SetTimer(1,0.01,NULL);
}
//DEL bool CFaDlg::SendMsg(char *Msg,int Len,char *host,short port)
//DEL {
//DEL signed int Sent;
//DEL hostent *hostdata;
//DEL if ( atoi(host) ) // 是否IP地址為標準形式
//DEL {
//DEL u_long ip = inet_addr( host );
//DEL hostdata = gethostbyaddr( (char *)&ip, sizeof(ip), PF_INET );
//DEL }
//DEL else // 否則則可能是機器名
//DEL {
//DEL hostdata = gethostbyname( host );
//DEL }
//DEL
//DEL if ( !hostdata )
//DEL {
//DEL AfxMessageBox("獲得機器名錯誤");
//DEL return false;
//DEL }
//DEL
//DEL sockaddr_in dest; // 發送目標地址
//DEL dest.sin_family = PF_INET;
//DEL dest.sin_addr = *(in_addr *)(hostdata->h_addr_list[0]);
//DEL dest.sin_port = htons( port );
//DEL CString str1;
//DEL str1.Format("數據已經被發送到主機 %s 端口為 %i\n", inet_ntoa(dest.sin_addr), ntohs(dest.sin_port));
//DEL
//DEL //
//DEL // SendMsg(buffer,strlen(buffer),buf,200);
//DEL m_list.AddString(str1);
//DEL //數據發送
//DEL Sent = sendto(ListenSocket, Msg, Len+1, 0, (sockaddr *)&dest, sizeof(sockaddr_in));
//DEL
//DEL if ( Sent != Len+1 )
//DEL {
//DEL AfxMessageBox("錯誤發送UDP信息");
//DEL
//DEL return false;
//DEL }
//DEL return true;
//DEL }
void CFaDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (nIDEvent==1)
{
if (dout_r>=30)
{
UpdateData(TRUE);
n=n+1;
DrawLine2();
m_dt1=daodan1.dn=n*0.01;
m_mx1=daodan1.x=dout_my;
m_my1=daodan1.y=dout_mx;
m_mz1=daodan1.z=dout_mz;
m_mp1=daodan1.a=dout_mp*180/3.14;
m_mh1=daodan1.b=dout_mh*180/3.14;
daodan1.r=dout_r;
m_tx1=target.x=dout_ty;
m_ty1=target.y=dout_tx;
m_tz1=target.z=dout_tz;
m_tp1=target.a=dlg_cssd.m_p;
m_th1=target.b=dlg_cssd.m_h;
UpdateData(FALSE);
}
else KillTimer(1);
}
CDialog::OnTimer(nIDEvent);
}
void CFaDlg::OnButtonDd()
{
// TODO: Add your control notification handler code here
dlg_cssd.DoModal();
}
void CFaDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
mlfHGTerminate();
libmmfileTerminate();
libmwsglmTerminate();
}
void CFaDlg::DrawLine2()
{
//調用dandao.m函數,這里的輸入值和輸出值與dandao.m函數相對應
out_tx=dandao(&out_ty,&out_tz,&out_mx,&out_my,&out_mz,&out_mp,&out_mh,&out_r,
in_tx,in_ty,in_tz,in_tp,in_th,in_mx,in_my,in_mz,in_vm,in_vt,in_dt,in_m);
//從mwArray型中取出double類型數據
dout_tx=out_tx.ExtractScalar(1);
dout_ty=out_ty.ExtractScalar(1);
dout_tz=out_tz.ExtractScalar(1);
dout_mx=out_mx.ExtractScalar(1);
dout_my=out_my.ExtractScalar(1);
dout_mz=out_mz.ExtractScalar(1);
dout_mp=out_mp.ExtractScalar(1);
dout_mh=out_mh.ExtractScalar(1);
dout_r=out_r.ExtractScalar(1);
//調用line函數以打點方式繪制彈目的當前坐標
m_hMissile=line("xdata",dout_my,"ydata",dout_mx,"zdata",dout_mz,
"visible","on","parent",m_mwhAxis,"color","b");
m_hTarget=line("xdata",dout_ty,"ydata",dout_tx,"zdata",dout_tz,
"visible","on","parent",m_mwhAxis,"color","r");
//保留當前圖上子對象和所有屬性不變,等待下一組數據
Vset(m_mwhAxis,"NextPlot","add");
//將輸出值賦給輸入值,進行迭代
in_tx=out_tx;
in_ty=out_ty;
in_tz=out_tz;
in_mx=out_mx;
in_my=out_my;
in_mz=out_mz;
}
void CFaDlg::GenAxis2()
{
double BKColor[]={0.925,0.914,0.847};
mwArray mwBkColor(1,3,BKColor);
m_mwhFigure = figure(
mwArray("DoubleBuffer"), mwArray("On"),
mwArray("NumberTitle"), mwArray("Off"),
mwArray("Name"), mwArray("__figure"),
mwArray("Color"), mwBkColor,
mwArray("Visible"), mwArray("off"),
mwArray("MenuBar"), mwArray("none")
);
m_mwhAxis= axes(mwArray("Parent"), m_mwhFigure,
mwArray("Box"), mwArray("On"),
mwArray("XGrid"), mwArray("On"),
mwArray("YGrid"), mwArray("On"),
mwArray("zGrid"), mwArray("On"));
mwArray xLabel=get(m_mwhAxis,"xlabel");
mwArray yLabel=get(m_mwhAxis,"ylabel");
mwArray zLabel=get(m_mwhAxis,"zlabel");
set(xLabel,"string","X/米","fontsize",8);
set(yLabel,"string","Y/米","fontsize",8);
set(zLabel,"string","Z/米","fontsize",8);
m_hMissile=line("xdata",0,"ydata",0,"zdata",0,"visible","off","parent",m_mwhAxis);
m_hTarget=line("xdata",0,"ydata",0,"zdata",0,"visible","off","parent",m_mwhAxis);
Vset(m_mwhAxis,"NextPlot","add");//hold on
}
void CFaDlg::DockMatlabFigure(mwArray mwhFigure,CWnd *pParentWnd)
{
mwArray mwFigName=get(mwhFigure,mwArray("name"));
char *pCharFigureName=strdup((char*)(mwFigName.ToString()));
HWND hFig = ::FindWindow(NULL,pCharFigureName);
if(hFig == NULL)
{
AfxMessageBox("未能產生Figure窗口,圖形繪制失?。?quot;);
return;
}
// 去掉Figure窗口的標題欄和邊框
long lStyle = ::GetWindowLong(hFig,GWL_STYLE);
::SetWindowLong(hFig,GWL_STYLE,lStyle & (~WS_CAPTION) & (~WS_THICKFRAME));
::SetWindowPos(hFig,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
// 獲取繪圖區域的位置和大小
long lOldStyle = ::GetWindowLong(hFig, GWL_STYLE);
long lNewStyle = lOldStyle & (~WS_OVERLAPPEDWINDOW) | WS_CHILD;
::SetWindowLong(hFig, GWL_STYLE, lNewStyle);
// 獲取繪圖區域的位置和大小
RECT PlotRect;
CWnd *pWndPlotArea = GetDlgItem(IDC_PLOT);
pWndPlotArea->GetWindowRect(&PlotRect);
ScreenToClient(&PlotRect);
// 設置Figure窗口為對話框窗口的子窗口并調整其位置
CWnd *pWndFig = CWnd::FromHandle(hFig);
pWndFig->SetParent(this);
pWndFig->MoveWindow(&PlotRect);
// DrawLine();
// 設置窗口可見
pWndFig->ShowWindow(SW_SHOW);
// MakeMatlabFiguresVisible();
// rotate3d(m_mwhAxis,"on");
// 刷新窗口
// mlfDrawnow(NULL);
}
void CFaDlg::OnBTN3d()
{
// TODO: Add your control notification handler code here
rotate3d(m_mwhAxis,"on");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -