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

📄 testresltime2dlg.cpp

📁 一个测试STK与VC接口的实时数据驱动
💻 CPP
字号:
// TestReslTime2Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "TestReslTime2.h"
#include "TestReslTime2Dlg.h"
#include "AgConnect.h"//add myself

#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()

/////////////////////////////////////////////////////////////////////////////
// CTestReslTime2Dlg dialog

CTestReslTime2Dlg::CTestReslTime2Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestReslTime2Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestReslTime2Dlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestReslTime2Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestReslTime2Dlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestReslTime2Dlg, CDialog)
	//{{AFX_MSG_MAP(CTestReslTime2Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestReslTime2Dlg message handlers

BOOL CTestReslTime2Dlg::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
	initFileName = NULL;               //初始化文件名,初始化为NULL
    connection1  = NULL;                //连接使用标志,初始化为NULL
	AlreadyRunSTK= false;
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTestReslTime2Dlg::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 CTestReslTime2Dlg::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 CTestReslTime2Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
/************************STk组网演示***************************************/
//void CTestReslTime2Dlg::OnStkButton() 
//{
	// TODO: Add your control notification handler code here
//	if(AlreadyRunSTK==false) OnRunSTK();
//	
//}
void CTestReslTime2Dlg::OnOK() 
{
	// TODO: Add extra validation here
//	if(AlreadyRunSTK==false) OnRunSTK();
	OnSetstk();	
//	CDialog::OnOK();

}
void CTestReslTime2Dlg::OnRunSTK()
{
	UINT m_result=WinExec("C:\\Program Files\\AGI\\stk\\4.3\\bin4.3\\STK.exe",SW_SHOW);
	
	if(m_result>31)  AlreadyRunSTK=true;	
	else 
	{ 
		if(m_result==0)  	MessageBox("The system is out of memory or resources.\n+Please reload STK!\n","Warning",MB_OK|MB_ICONWARNING);
		else if(m_result==ERROR_BAD_FORMAT)     
			    MessageBox("The .EXE file is invalid (non-Win32 .EXE or error in .EXE image)!\n","Warning",MB_OK|MB_ICONWARNING);
		else if(m_result==ERROR_FILE_NOT_FOUND) 
			    MessageBox("The specified file was not found!\n","Warning",MB_OK|MB_ICONWARNING);
	   	else if(m_result==ERROR_PATH_NOT_FOUND) 
		    	MessageBox("The specified path was not found!\n","Warning",MB_OK|MB_ICONWARNING);
		else 	MessageBox("Unclear erorr!\n","Warning",MB_OK|MB_ICONWARNING);
		
		AlreadyRunSTK= false;
	} 	
}
void CTestReslTime2Dlg::OnSetstk() //设置STK
{
	CString str;

     /////////////////////////// 连接STK///////////////////////////////////
		str="localhost:5001";    //本地连接
	//	str=Stkadress+":"+Stkport; //远程连接
		str=Stkadress+":5001"; //远程连接
        LPTSTR cmdstring=str.GetBuffer(str.GetLength());  //"localhost:"+"5001"; 
		
        AgConInit(initFileName);   //初始化
        AgConOpenSTK(&connection1,  cmdstring);	  //Open a connection to STK */
		////////////////////////////////////////////////////////////////////////
        command="Unload / Scenario/*";
		cmdstring=command.GetBuffer(command.GetLength());//指定打开连接的类型
        AgConProcessSTKCmd(connection1, cmdstring, &returnInfo);
		/////////////////////////////////////////////////////////////////
		//starttime   = " ^1 Nov 2007 04:01:00.00^";  //场景开始时间
//		endtime     = " ^"+m_STKSetupDLg.m_simendtime+"^";    //场景结束时间
//		stkshowstep = m_STKSetupDLg.m_animationstep;
//		OrbitEpoch=m_STKSetupDLg.m_simstarttime;
		//STK连接设置
//		Stkadress=m_STKSetupDLg.m_IPAddress;  
//		Scenarioname=m_STKSetupDLg.m_InstanceName;
		//		stksjpath=m_STKSetupDLg.m_PlanPath;
   
		command="New / Scenario TestRealTime";//添加新场景
        cmdstring=command.GetBuffer(command.GetLength());
        AgConProcessSTKCmd(connection1, cmdstring, &returnInfo);
		
		command="SetTimePeriod Scenario/TestRealTime ^1 May 2008 00:00:00.00^ ^2 May 2008 00:00:00.00^";
		command.Replace('^','"'); 
		cmdstring=command.GetBuffer(command.GetLength());
		AgConProcessSTKCmd(connection1, cmdstring, &returnInfo);	

		command="SetEpoch Scenario/TestRealTime ^1 May 2008 00:00:00.00^";
		command.Replace('^','"');
		cmdstring=command.GetBuffer(command.GetLength());
		AgConProcessSTKCmd(connection1, cmdstring, &returnInfo);
	
		command="New / Scenario/ TestRealTime/AreaTarget TaiHai";
        cmdstring=command.GetBuffer(command.GetLength());
        AgConProcessSTKCmd(connection1, cmdstring, &returnInfo);
	
		AgConGetAsync(connection1, &returnInfo); 

		command="New / Scenario/ TestRealTime/Satellite Sat01";//在新建的场景中添加一颗卫星
		command.Replace('^','"');
		cmdstring=command.GetBuffer(command.GetLength());
		AgConProcessSTKCmd(connection1, cmdstring, &returnInfo);


		
//		command="SetEpoch Scenario/"+Scenarioname+" " +OrbitEpoch;
//		command.Replace('^','"');
//		cmdstring=command.GetBuffer(command.GetLength());
//		AgConProcessSTKCmd(connection1, cmdstring, &returnInfo);
        /////////////////////////设置目标区域///////////////////////////////
//     	CString Jd1,Jd2,Wd1,Wd2;
//		Jd1.Format("%f",m_TargetJd1);
//		Jd2.Format("%f",m_TargetJd2);
//		Wd1.Format("%f",m_TargetWd1);
//		Wd2.Format("%f",m_TargetWd2);
	
//		command="New / Scenario/"+Scenarioname+"/AreaTarget TaiHai";
//      cmdstring=command.GetBuffer(command.GetLength());
//       AgConProcessSTKCmd(connection1, cmdstring, &returnInfo);
		
//	    command="SetBoundary */AreaTarget/TaiHai Pattern 4 "+Wd1+" "+Jd1+" "+Wd1+" "+Jd2+" "+Wd2+" "+Jd2+" "+Wd2+" "+Jd1;
//       cmdstring=command.GetBuffer(command.GetLength());
//       AgConProcessSTKCmd(connection1, cmdstring, &returnInfo);
		
//		command="Graphics */AreaTarget/TaiHai SetColor 4 Marker";
//       cmdstring=command.GetBuffer(command.GetLength());
//       AgConProcessSTKCmd(connection1, cmdstring, &returnInfo);
	
    LoadObjetParameter();
}
void CTestReslTime2Dlg::LoadObjetParameter()
{
//    CStringArray   STKInfo;
	CString str;
	CString  command;
	LPTSTR   cmdstring;

	string OrbitFileName;
	OrbitFileName = "C:\CEOrbit.txt";

	OrbitData.RemoveAll();
    ParseOrbit(OrbitFileName);

	long NUM=OrbitData.GetSize();//
	if(NUM<0)
	{
	  AfxMessageBox("表中没有数据!");
	  return;
	}
	
 /* 	strID=m_List1.GetItemText(NUM,0);
    int id=atoi(strID)-1;//获取要分析的卫星的标示
	str=m_List1.GetItemText(NUM,3);
    int SatNum=atoi(str);
*/	long second=0;
	NUM=(NUM+1)/3;
	for(long i=0;i<NUM;i++)
	{
/*		STKInfo.RemoveAll();
		str.Format("sat%d%d",id,i);
		STKInfo.Add(str);//航天器名称
		str.Format("%f",sat[id][i].A);
		STKInfo.Add(str);  //半长轴
		str.Format("%f",sat[id][i].E);
		STKInfo.Add(str);  //偏心率
		str.Format("%f",sat[id][i].I);
		STKInfo.Add(str); //轨道倾角
		str.Format("%f",sat[id][i].AOP);
		STKInfo.Add(str);//近地点幅角
		str.Format("%f",sat[id][i].RAAN);
		STKInfo.Add(str);//升交点赤经
		str.Format("%f",sat[id][i].MA);
		STKInfo.Add(str); //平近地角
		STKInfo.Add("^C:/Program Files/AGI/stk/4.3/STKData/VO/Models/Space/Military/sbr.mdl^");//航天器模型名称
		STKInfo.Add("10000");      //航天器模型的放大倍数
		STKInfo.Add("698107170.55");//labal放大倍数
		//		CString temp=ChangeMonth(sat[id][i].orbitTime.nMonth);
		//        str.Format("%02d %s %04d %02d:%02d:%02f",sat[id][i].orbitTime.nDay,temp,sat[id][i].orbitTime.nYear,sat[id][i].orbitTime.nHour,sat[id][i].orbitTime.nMinute,sat[id][i].orbitTime.nSecond);
		STKInfo.Add(OrbitEpoch);    //历元时间,开始时间	
		SetSateToSTK(STKInfo,Scenarioname,true,true);         //请求STK添加一颗卫星实例
*/		//添加一颗卫星
		CString DataTime;
		//DataTime="1 May 2008 00:00:00.00"
		
		int realsecond=second%60;
		int realmin=int((second-(second%60))/60)%60;
		int realhor=int(second/3600)%24;
		int realday=int(int(second/3600)/24)+1;
		DataTime.Format("%d May 2008 %d:%d:%d.00",realday,realhor,realmin,realsecond);
		
		CString adsd;
		adsd= OrbitData.GetAt(i*3+0);
		adsd=OrbitData.GetAt(i*3+1);
		adsd=OrbitData.GetAt(i*3+2);
		command="SetPosition Scenario/TestRealTime/Satellite Sat01 LLA ^"+DataTime+"^ "+OrbitData[i*3+0]+" "+OrbitData[i*3+1]+" "+OrbitData[i*3+2]+" 0. 0. 0.";
		command.Replace('^','"');
		cmdstring=command.GetBuffer(command.GetLength());
		AgConProcessSTKCmd(connection1, cmdstring, &returnInfo);

		second++;
	}
	
    
}

CString CTestReslTime2Dlg::ChangeMonth(int month)
{
    CString strmonth;
	switch(month)
	{
	case  1:  strmonth="Jan";break; 
	case  2:  strmonth="Feb";break; 
	case  3:  strmonth="Mar";break; 
	case  4:  strmonth="Apr";break; 
	case  5:  strmonth="May";break; 
	case  6:  strmonth="Jun";break; 
	case  7:  strmonth="Jul";break; 
	case  8:  strmonth="Aug";break; 
	case  9:  strmonth="Sep";break; 
	case  10:  strmonth="Oct";break; 
	case  11:  strmonth="Nov";break; 
	case  12:  strmonth="Dec";break; 
		
	}
	return strmonth;
	
}
//文件格式:纬度\t经度\t高度\t纬度变化率\t经度变化率\t高度变化率
void CTestReslTime2Dlg::ParseOrbit(string OrbitDataFileName)
{
	FILE * fp_XYZ;
	
	fp_XYZ=fopen(OrbitDataFileName.c_str(),"r");
		
	if ((fp_XYZ == NULL) )
	{
		throw("Fail to Open File!\n");
		return;
	}
    
   float t,x,y,z,vx,vy,vz,h,v,l,b;

	//读文件,获取弹道数据
	while(1)
	{
		if( fscanf( fp_XYZ,  "%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n",&t,&x,&y,&z,&vx,&vy,&vz,&h,&v,&l,&b)==EOF)
        {
			break;
		}
		else
		{
		/*	DandaoDatum d;
			d.first =0;
			d.second.x=0;
			d.second.y=0;
			d.second.z=0;
			d.second.vx=0;
			d.second.vy=0;
			d.second.vz=0;
			d.second.height=h;
			d.second.longitude=l;
			d.second.latitude=b;*/
//			OrbitArray.Add(0.);
//			OrbitArray.Add(0.);			
//			OrbitArray.Add(0.);			
//			OrbitArray.Add(0.);			
//			OrbitArray.Add(0.);			
//			OrbitArray.Add(0.);			
			CString ttt;
			ttt.Format("%f",b);
			OrbitData.Add(ttt);	
			
			ttt.Format("%f",l);
			OrbitData.Add(ttt);
			
			ttt.Format("%f",h);
			OrbitData.Add(ttt);			
		}
	}
    fclose(fp_XYZ);

}

⌨️ 快捷键说明

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