📄 trafficdlg.cpp
字号:
// TrafficDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Traffic.h"
#include "TrafficDlg.h"
#include <process.h>
#include "afxctl.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()
/////////////////////////////////////////////////////////////////////////////
// CTrafficDlg dialog
CTrafficDlg::CTrafficDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTrafficDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTrafficDlg)
// 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);
//获得当前位置的绝对路径
char szPath[MAX_PATH];
GetModuleFileName( NULL, szPath, MAX_PATH );
CString strPath = szPath;
int nFind = strPath.ReverseFind( '\\' );
strcpy( szPath, strPath.Left( nFind + 1 ) );
m_strAbsoluteDir = szPath;
}
CTrafficDlg::~CTrafficDlg()
{
if(m_pTerraExplorer)
{
//将调用Unadvise()
AfxConnectionUnadvise(m_pTerraExplorer,
DIID__ITerraExplorerEvents ,
GetIDispatch(FALSE),
FALSE,
m_dwCookie );
m_pTerraExplorer.Release();//release the object...stops any threads internal to object...
m_pTerraExplorer = NULL;
}
//unload com libraries...
CoUninitialize();
}
void CTrafficDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTrafficDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTrafficDlg, CDialog)
ON_MESSAGE(WM_CHANGETRAFFICLAMPSTATUS,ChangeTrafficLampStatus)
//{{AFX_MSG_MAP(CTrafficDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDLoad, OnLoad)
ON_BN_CLICKED(IDOODemo, OnOODemo)
ON_BN_CLICKED(IDC_RedGreen, OnRedGreen)
ON_BN_CLICKED(IDC_Pause, OnPause)
ON_BN_CLICKED(IDC_Test, OnTest)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CTrafficDlg, CDialog)
DISP_FUNCTION_ID(CTrafficDlg, "LoadFinished", 1, OnLoadFinished, VT_EMPTY, NULL)
DISP_FUNCTION_ID(CTrafficDlg, "FileClosing", 2, OnFileClosing, VT_EMPTY, NULL)
DISP_FUNCTION_ID(CTrafficDlg, "Frame", 3, OnFrame, VT_EMPTY, NULL)
DISP_FUNCTION_ID(CTrafficDlg, "TerraExplorerMessage", 4, OnTerraExplorerMessage,VT_EMPTY, VTS_BSTR VTS_BSTR VTS_VARIANT)
DISP_FUNCTION_ID(CTrafficDlg, "ObjectAction", 5, OnObjectAction, VT_EMPTY, VTS_BSTR VTS_I4)
DISP_FUNCTION_ID(CTrafficDlg, "FileSave", 6, OnFileSave, VT_EMPTY, NULL)
DISP_FUNCTION_ID(CTrafficDlg, "RenderQualityChanged", 7, OnRenderQualityChanged, VT_EMPTY, VTS_I4)
DISP_FUNCTION_ID(CTrafficDlg, "InputModeChanged", 8, OnInputModeChanged, VT_EMPTY, VTS_I4)
DISP_FUNCTION_ID(CTrafficDlg, "LButtonDown", 9, OnLButtonDown, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4 VTS_VARIANT)
DISP_FUNCTION_ID(CTrafficDlg, "LButtonUp", 10, OnLButtonUp, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4 VTS_VARIANT)
DISP_FUNCTION_ID(CTrafficDlg, "MButtonDown", 11, OnMButtonDown, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4 VTS_VARIANT)
DISP_FUNCTION_ID(CTrafficDlg, "MButtonUp", 12, OnMButtonUp, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4 VTS_VARIANT)
DISP_FUNCTION_ID(CTrafficDlg, "RButtonDown", 13, OnRButtonDown, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4 VTS_VARIANT)
DISP_FUNCTION_ID(CTrafficDlg, "RButtonUp", 14, OnRButtonUp, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4 VTS_VARIANT)
DISP_FUNCTION_ID(CTrafficDlg, "MouseWheel", 15, OnMouseWheel, VT_EMPTY, VTS_I4 VTS_I2 VTS_I4 VTS_I4 VTS_VARIANT)
DISP_FUNCTION_ID(CTrafficDlg, "InfoTreeAction", 16, OnInfoTreeAction, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4)
DISP_FUNCTION_ID(CTrafficDlg, "TerraExplorer", 17, OnTerraExplorer, VT_EMPTY, VTS_I4 VTS_I4)
DISP_FUNCTION_ID(CTrafficDlg, "DrawHUD", 18, OnDrawHUD, VT_EMPTY, NULL)
DISP_FUNCTION_ID(CTrafficDlg, "LButtonDblClk", 19, OnLButtonDblClk, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4 VTS_VARIANT)
DISP_FUNCTION_ID(CTrafficDlg, "RButtonDblClk", 20, OnRButtonDblClk, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4 VTS_VARIANT)
DISP_FUNCTION_ID(CTrafficDlg, "MButtonDblClk", 21, OnMButtonDblClk, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4 VTS_VARIANT)
END_DISPATCH_MAP()
BEGIN_INTERFACE_MAP( CTrafficDlg, CDialog)
INTERFACE_PART(CTrafficDlg, DIID__ITerraExplorerEvents5, Dispatch)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTrafficDlg message handlers
BOOL CTrafficDlg::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_pTerraExplorer = NULL;
//Initialize COM libraries...create MTA...
CoInitialize(NULL);
EnableAutomation();
//creat the instance of the calculator server...
HRESULT hr = m_pTerraExplorer.CreateInstance(CLSID_TerraExplorer);
//advise the server that this (mainframe) is the sink for events...
//这个函数内部将进行QueryInterface(IConnectionPointContainer,..)、FindConnectionPoint()、Advise()等一系列调用
BOOL Ret = AfxConnectionAdvise(
m_pTerraExplorer, //可连接对象的接口指针
DIID__ITerraExplorerEvents5, //连接接口ID
GetIDispatch(FALSE), //把内嵌的IDispatch实现类的一个对象实例m_xDispatch传了出去
FALSE, //donod addref
&m_dwCookie ); //cookie to break connection later...
if (!Ret)
{
AfxMessageBox("创建事件连接点失败!");
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CTrafficDlg::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 CTrafficDlg::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 CTrafficDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTrafficDlg::OnLoadFinished ( ) //Disid:1
{
CString str = _T("Message:OnLoadFinished.");
//TRACE("%s\n", str);
}
void CTrafficDlg::OnFileClosing ( ) //Disid:2
{
CString str = _T("Message:OnFileClosing.");
//TRACE("%s\n", str);
}
void CTrafficDlg::OnFrame ( ) //Disid:3
{
long itemID ;
_bstr_t pathName = "Tracks";
unsigned short* pObjectID;
m_pIInformationTree->FindItem(pathName,&itemID);
m_pIInformationTree->GetTerraObjectID(itemID , &pObjectID);
ITerraExplorerObject2Ptr pTEO2;
m_pIObmager->GetObject(pObjectID , &pTEO2);
ITerrainDynamicObject3Ptr pDOTracks = (ITerrainDynamicObject3Ptr)pTEO2;
pathName = "TrafficLamp";
m_pIInformationTree->FindItem(pathName,&itemID);
m_pIInformationTree->GetTerraObjectID(itemID , &pObjectID);
ITerraExplorerObject2Ptr pTrafficLamp;
m_pIObmager->GetObject(pObjectID , &pTrafficLamp);
ITerrainImageLabel2Ptr pILTrafficLamp = (ITerrainImageLabel2Ptr)pTrafficLamp;
VARIANT vX,vY,vZ,vYaw,vPitch,vRoll,vSpeed;
pDOTracks->GetPosition(&vX , &vY , &vZ , &vYaw , &vPitch , &vRoll);
double dXTracks = vX.dblVal;
double dYTracks = vY.dblVal;
pILTrafficLamp->GetPosition(&vX , &vY , &vZ , &vYaw , &vPitch , &vRoll);
double dXLamp = vX.dblVal;
double dYLamp = vY.dblVal;
double dblCurrentDistance = sqrt(pow(dXLamp-dXTracks , 2) + pow(dYLamp-dYTracks , 2));
if(dblCurrentDistance < 100)
{
_bstr_t greenPath = "E:\\workspace\\Traffic\\Demo\\绿灯.bmp";
pILTrafficLamp->put_ImageFileName(greenPath);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -