提交 28370859 编写于 作者: 丁劲犇's avatar 丁劲犇 😸

we finished the demo app, for all apis.

the c# app provides most function demos,
the MFC app demos antimation drawing effect.
上级 8781cc81
......@@ -1113,6 +1113,11 @@ QMap<QString, QVariant> qtvplugin_geomarker::func_load_xml (const QMap<QStrin
bool ok = this->xml_load(name);
res ["return"] = ok;
if (ok)
{
scheduleRefreshMarks();
scheduleUpdateMap();
}
return res;
}
/**
......
......@@ -49,7 +49,7 @@ BOOL CMFC_ContainerApp::InitInstance()
// Change the registry key under which our settings are stored
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
SetRegistryKey(_T("QPlanetOSM windows activex container demo"));
CMFC_ContainerDlg dlg;
m_pMainWnd = &dlg;
......
B// Microsoft Visual C++ generated resource script.
......
......@@ -210,6 +210,7 @@
<None Include="res\MFC_Container.rc2" />
</ItemGroup>
<ItemGroup>
<Image Include="res\mark.png" />
<Image Include="res\MFC_Container.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
......@@ -65,5 +65,8 @@
<Image Include="res\MFC_Container.ico">
<Filter>资源文件</Filter>
</Image>
<Image Include="res\mark.png">
<Filter>资源文件</Filter>
</Image>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -3,6 +3,11 @@
//
#include "stdafx.h"
#include <unordered_map>
#include <vector>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#include "MFC_Container.h"
#include "MFC_ContainerDlg.h"
#include "afxdialogex.h"
......@@ -10,7 +15,10 @@
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//! convert string key-value pairs to map.
std::unordered_map<_tstring, _tstring> string2map(LPCTSTR str);
//!export a PNG file to temp folder
_tstring export_res();
// CMFC_ContainerDlg dialog
......@@ -18,19 +26,32 @@
CMFC_ContainerDlg::CMFC_ContainerDlg(CWnd* pParent /*=NULL*/)
: CDialog(IDD_MFC_CONTAINER_DIALOG, pParent)
, m_currentLat(0)
, m_currentLon(0)
, m_direct (0)
, m_nTimer(1)
, m_bInited (false)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
srand((unsigned int)time(0));
m_direct = rand() % 360;
}
void CMFC_ContainerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_QTAXVIEWER_PLANETOSM, m_map);
DDX_Control(pDX, IDC_LIST_MSG, m_list_msg);
DDX_Control(pDX, IDC_STATIC_MOUSEMOVE, m_static_msg);
}
BEGIN_MESSAGE_MAP(CMFC_ContainerDlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_SIZE()
ON_BN_CLICKED(IDC_BUTTON_PLAY, &CMFC_ContainerDlg::OnBnClickedButtonPlay)
ON_BN_CLICKED(IDC_BUTTON_PAUSE, &CMFC_ContainerDlg::OnBnClickedButtonPause)
ON_WM_TIMER()
END_MESSAGE_MAP()
......@@ -45,7 +66,7 @@ BOOL CMFC_ContainerDlg::OnInitDialog()
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
GetDlgItem(IDC_BUTTON_PAUSE)->EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
......@@ -86,3 +107,268 @@ HCURSOR CMFC_ContainerDlg::OnQueryDragIcon()
return static_cast<HCURSOR>(m_hIcon);
}
//MFC framework is old enough, that it does not support automatically size-management.
void CMFC_ContainerDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (cx && cy)
{
if (IsWindow(this->GetSafeHwnd()))
{
if (IsWindow(this->m_map.GetSafeHwnd()))
{
m_map.MoveWindow(0, 80, cx, cy-80);
CWnd * w = GetDlgItem(IDC_LIST_MSG);
CRect rect;
w->GetWindowRect(&rect);
ScreenToClient(&rect);
if (w)
w->MoveWindow(rect.left, rect.top, cx - rect.left-4, rect.Height());
}
}
}
}
BEGIN_EVENTSINK_MAP(CMFC_ContainerDlg, CDialog)
ON_EVENT(CMFC_ContainerDlg, IDC_QTAXVIEWER_PLANETOSM, 9, CMFC_ContainerDlg::evt_MessageQtaxviewerPlanetosm, VTS_BSTR)
END_EVENTSINK_MAP()
void CMFC_ContainerDlg::evt_MessageQtaxviewerPlanetosm(LPCTSTR p0)
{
std::unordered_map<_tstring, _tstring> paras = string2map(p0);
CString add_msg = p0;
if (paras[_T("name")] == _T("MOUSE_MOVE"))
{
m_static_msg.SetWindowText(add_msg);
}
else
{
int ct = m_list_msg.GetCount();
m_list_msg.InsertString(ct, add_msg);
m_list_msg.SetCurSel(ct);
while (m_list_msg.GetCount() >= 1024)
m_list_msg.DeleteString(0);
}
}
void CMFC_ContainerDlg::OnBnClickedButtonPlay()
{
//if not inited, load icons
if (m_bInited == false)
{
m_bInited = true;
//load png
_tstring fm = export_res();
if (fm.size())
{
CString cmd;
cmd.Format(_T("function=add_resource;name=arrow;"
"filename=%s;centerx=31;centery=31;"
),
fm.c_str()
);
m_map.osm_layer_call_function(_T("geomarker1"), cmd);
}
}
this->SetTimer(m_nTimer, 200, 0);
GetDlgItem(IDC_BUTTON_PLAY)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_PAUSE)->EnableWindow(TRUE);
}
void CMFC_ContainerDlg::OnBnClickedButtonPause()
{
this->KillTimer(m_nTimer);
GetDlgItem(IDC_BUTTON_PLAY)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_PAUSE)->EnableWindow(FALSE);
}
void CMFC_ContainerDlg::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == m_nTimer)
{
this->KillTimer(m_nTimer);
const double pi = 3.14159265355;
double s = 180 * (30.0 / 6300) / pi;
double dx = s * cos(m_direct/180.0*pi) / cos (m_currentLat * pi /180.0);
double dy = s * sin(m_direct / 180.0*pi);
m_currentLat += dy;
m_currentLon += dx;
if (m_currentLat <= -85)
{
m_currentLat = -85;
m_direct = rand() % 90 + 45;
}
else if (m_currentLat >= 85)
{
m_currentLat = 85;
m_direct = -(rand() % 90 + 45);
}
m_currentLon += 360 * 2;
m_currentLon = fmod(m_currentLon+180, 360)-180;
CString cmd;
cmd.Format(_T("function=update_icon;name=point1;"
"lat=%.8lf;lon=%.8lf;"
"icon=arrow;scale=0.5;rotate=%.2lf;smooth=1;"
),
m_currentLat, m_currentLon, 90-m_direct
);
m_map.osm_layer_call_function(_T("geomarker1"), cmd);
cmd.Format(_T("function=update_props;name=point1;"
"lat=%.8lf;lon=%.8lf;direct=%.8lf;"
),
m_currentLat, m_currentLon, m_direct
);
m_map.osm_layer_call_function(_T("geomarker1"), cmd);
//Lines
m_list_old_lats.push_front(m_currentLat);
m_list_old_lons.push_front(m_currentLon);
const int maxsz = 128;
while (m_list_old_lats.size() > maxsz)
{
m_list_old_lats.pop_back();
m_list_old_lons.pop_back();
}
int c = 0;
double lastlat = m_currentLat, lastlon = m_currentLon;
for (
std::list<double>::iterator latp = m_list_old_lats.begin(), lonp = m_list_old_lons.begin();
latp != m_list_old_lats.end() && lonp != m_list_old_lons.end();
++latp, ++lonp, ++c
)
{
cmd.Format(_T("function=update_line;name=line%d;"
"lat0=%.7lf;lon0=%.7lf;lat1=%.7lf;lon1=%.7lf;"
"style_pen=1;color_pen=255,0,0,%d;width_pen=%d;"
),
c,
lastlat, lastlon, *latp, *lonp,
int((1 - c * 1.0/ maxsz)*255),
int((1 - c * 1.0 / maxsz) * 6)+1
);
m_map.osm_layer_call_function(_T("geomarker1"), cmd);
lastlat = *latp, lastlon = *lonp;
}
if (rand()%10==1)
m_direct += rand()%100/10.0-5.0;
this->SetTimer(m_nTimer, 100, 0);
}
CDialog::OnTimer(nIDEvent);
}
//----------------------------------
std::unordered_map<_tstring, _tstring> string2map(LPCTSTR str)
{
std::unordered_map<_tstring, _tstring> res_map;
size_t szLen = _tcslen(str);
std::vector<TCHAR> pArrBuf;
pArrBuf.resize(szLen + 1);
_tcscpy_s(pArrBuf.data(), szLen + 1, str);
std::vector<size_t> vec_pairs;
//record each pairs' begin
vec_pairs.push_back(0);
for (int i = 0; i < szLen; ++i)
{
if (pArrBuf[i] == ';')
{
vec_pairs.push_back(i + 1);
pArrBuf[i] = 0;
}
}
//for each pairs, split by '='
size_t pairs = vec_pairs.size();
for (size_t i = 0; i < pairs; ++i)
{
size_t cur_pair = vec_pairs[i];
if (pArrBuf[cur_pair] == 0)
continue;
int pec = cur_pair;
while (pec < szLen)
{
if (pArrBuf[pec] == 0)
break;
if (pArrBuf[pec] == _T('='))
{
pArrBuf[pec] = 0;
_tstring key = &pArrBuf[cur_pair];
_tstring val = &pArrBuf[pec + 1];
res_map[key] = val;
}
else
++pec;
}
}
return std::move(res_map);
}
_tstring export_res()
{
_tstring fm;
HINSTANCE hInst = AfxGetResourceHandle();
HRSRC hRsrc = ::FindResource(hInst, MAKEINTRESOURCE(IDB_PNG_MARK), _T("PNG")); // type
if (!hRsrc)
return std::move(fm);
// load resource into memory
DWORD len = SizeofResource(hInst, hRsrc);
BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
if (!lpRsrc)
return std::move(fm);
// Allocate global memory on which to create stream
HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
memcpy(pmem, lpRsrc, len);
IStream* pstm;
CreateStreamOnHGlobal(m_hMem, FALSE, &pstm);
// save to file
const DWORD dwSize = MAX_PATH;
TCHAR tempPath[dwSize];
if (GetTempPath(dwSize, tempPath) < dwSize)
{
_tstring filename = tempPath;
filename += _T("\\qplanetosm_mfc_png.png");
CFile file;
if (file.Open(filename.c_str(), CFile::modeCreate | CFile::modeWrite))
{
file.Write(pmem, len);
file.Close();
fm = filename;
}
}
// free/release stuff
GlobalUnlock(m_hMem);
pstm->Release();
FreeResource(lpRsrc);
return std::move(fm);
}
\ No newline at end of file
......@@ -4,7 +4,8 @@
#pragma once
#include "qtaxviewer_planetosm.h"
#include "afxwin.h"
#include <list>
// CMFC_ContainerDlg dialog
class CMFC_ContainerDlg : public CDialog
......@@ -25,12 +26,27 @@ public:
// Implementation
protected:
HICON m_hIcon;
//we need to load a PNG to geomarker, when we want to draw icons on map first time;
std::list<double> m_list_old_lats;
std::list<double> m_list_old_lons;
bool m_bInited;
double m_currentLat;
double m_currentLon;
double m_direct;
int m_nTimer;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
DECLARE_EVENTSINK_MAP()
CQtaxviewer_planetosm m_map;
CListBox m_list_msg;
CStatic m_static_msg;
void evt_MessageQtaxviewerPlanetosm(LPCTSTR p0);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnBnClickedButtonPlay();
afx_msg void OnBnClickedButtonPause();
afx_msg void OnTimer(UINT_PTR nIDEvent);
};
......@@ -34,9 +34,14 @@
#include <afxcontrolbars.h> // MFC support for ribbons and control bars
#include <string>
//defines a _tstring type, for automaticlly unicode corresponding
#ifdef _UNICODE
typedef std::wstring _tstring;
#else
typedef std::string _tstring;
#endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册