📄 draw.cpp
字号:
// Draw.cpp : implementation file
//
#include "stdafx.h"
#include "GpsPoint.h"
#include "Draw.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDraw dialog
extern CGpsPointApp theApp;
CDraw::CDraw(CWnd* pParent /*=NULL*/)
: CDialog(CDraw::IDD, pParent)
{
//{{AFX_DATA_INIT(CDraw)
//}}AFX_DATA_INIT
}
void CDraw::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDraw)
DDX_Control(pDX, IDC_STATIC_MSG, m_Msg);
DDX_Control(pDX, IDC_COMBO_KEDU, m_Kd);
DDX_Control(pDX, IDC_BUTTON_JIANX, m_E);
DDX_Control(pDX, IDC_BUTTON_JIAX, m_W);
DDX_Control(pDX, IDC_BUTTON_CENTER, m_C);
DDX_Control(pDX, IDC_BUTTON_JIAY, m_N);
DDX_Control(pDX, IDC_BUTTON_JIANY, m_S);
DDX_Control(pDX, IDC_COMBO_iRD, m_iRD);
DDX_Control(pDX, IDC_COMBO_IT, m_T);
DDX_Control(pDX, IDC_COMBO_R, m_R);
DDX_Control(pDX, IDC_COMBO_BL, m_B);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDraw, CDialog)
//{{AFX_MSG_MAP(CDraw)
ON_BN_CLICKED(IDC_BUTTON_LOADSETPOINT, OnButtonLoadsetpoint)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BUTTON_JIAX, OnButtonJiax)
ON_BN_CLICKED(IDC_BUTTON_JIANX, OnButtonJianx)
ON_BN_CLICKED(IDC_BUTTON_JIAY, OnButtonJiay)
ON_BN_CLICKED(IDC_BUTTON_JIANY, OnButtonJiany)
ON_CBN_SELCHANGE(IDC_COMBO_R, OnSelchangeComboR)
ON_WM_TIMER()
ON_WM_MOUSEMOVE()
ON_CBN_SELCHANGE(IDC_COMBO_IT, OnSelchangeComboIt)
ON_CBN_SELCHANGE(IDC_COMBO_iRD, OnSelchangeCOMBOiRD)
ON_WM_SIZE()
ON_BN_CLICKED(IDC_BUTTON_CENTER, OnButtonCenter)
ON_CBN_SELCHANGE(IDC_COMBO_KEDU, OnSelchangeComboKedu)
ON_WM_LBUTTONDOWN()
ON_CBN_SELCHANGE(IDC_COMBO_BL, OnSelchangeComboBl)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDraw message handlers
BOOL CDraw::PreTranslateMessage(MSG* pMsg)
{
//避免回车键退出
if(pMsg->message == WM_KEYDOWN){
switch(pMsg->wParam){
case VK_RETURN://截获回车
return TRUE;
case VK_ESCAPE://截获ESC
return TRUE;
break;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
BOOL CDraw::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
int i;
for(i=1;i<=100;i++){
Point[i].dLate=0;
Point[i].dLong=0;
Point[i].lJiao=0;
Point[i].sDM="";
}
for(i=1;i<=3600;i++){
sPoint[i].dLate=0;
sPoint[i].dLong=0;
sPoint[i].lJiao=0;
sPoint[i].sDM="";
}
iPoint=0;
isPoint=0;
lJiao=-1;//角度
strFile=CCommFun::GetAppPath("point.ini");
strFile2=CCommFun::GetAppPath("setup.ini");
//加载画图配置
CString strTmp;
dX=atof(CCommFun::Getini("画图设置","X轴位移","0",strFile2));
dY=atof(CCommFun::Getini("画图设置","Y轴位移","0",strFile2));
strTmp=CCommFun::Getini("画图设置","缩放比例","0",strFile2);
iT=CCommFun::Getini("画图设置","调节单位",100,strFile2);
iB=atof(strTmp);
iR=CCommFun::Getini("GPS设置","定位一个点的误差范围(米)",1,strFile2);
iRD=CCommFun::Getini("画图设置","当前点半径",1,strFile2);
iKD=CCommFun::Getini("画图设置","刻度的值",10,strFile2);
//刻度
int iTmp=0;
for(i=0;i<=4;i++){
iTmp=(int)pow(10,i);
strTmp.Format("%d",iTmp);
m_Kd.InsertString(i,strTmp);
}
strTmp.Format("%d",iKD);
m_Kd.SetCurSel(strTmp.GetLength()-1);
//比率
for(i=1;i<=900;i++){
strTmp.Format("%d.%d",i/10,i%10);
m_B.InsertString(i-1,strTmp);
}
m_B.SetCurSel((int)(iB*10-1));
//半径
for(i=1;i<=50;i++){
strTmp.Format("%d",i);
m_R.InsertString(i-1,strTmp);
}
m_R.SetCurSel(iR-1);
//当前点半径
for(i=1;i<=50;i++){
strTmp.Format("%d",i);
m_iRD.InsertString(i-1,strTmp);
}
m_iRD.SetCurSel(iRD-1);
//微调
int j;
for(i=1;i<=1000;){
strTmp.Format("%d",i);
if(i>=10){
j=i/10;
i+=10;
}else{
j=0;
i+=9;
}
m_T.InsertString(j,strTmp);
}
if(iT>=10){
m_T.SetCurSel(iT/10);
}else{
m_T.SetCurSel(0);
}
bDraw0=FALSE;
//加载方向角图标
m_N.SetIcon(theApp.LoadIcon(IDI_ICON_N));
m_S.SetIcon(theApp.LoadIcon(IDI_ICON_S));
m_E.SetIcon(theApp.LoadIcon(IDI_ICON_E));
m_W.SetIcon(theApp.LoadIcon(IDI_ICON_W));
m_C.SetIcon(theApp.LoadIcon(IDI_ICON_C));
//初始化
dLate0=0;
dLong0=0;
//
PAI=3.1415926535898;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDraw::NewLateLong(double dLate, double dLong, long lJiao,double dV)
{
CString strTmp;
//关闭定时器
this->KillTimer(1);
dLate0=dLate;
dLong0=dLong;
//画
bDraw0=TRUE;
//保存画线数组
isPoint++;
sPoint[isPoint].dLate=dLate;
sPoint[isPoint].dLong=dLong;
//保存最后一个角度,以供显示
this->lJiao=lJiao;
//显示角度和速度
strTmp.Format(" 角度 %d 速度 %s",lJiao,ftoa(dV));
m_Msg.SetWindowText(strTmp);
//
this->RedrawWindow();
//清除定时器
this->SetTimer(1,m_iTimer,NULL);
}
//加载定点
void CDraw::OnButtonLoadsetpoint()
{
CString strTmp;
iPoint=CCommFun::Getini("定位点设置","定位点数目",0,strFile);
for(int i=1;i<=iPoint;i++){
strTmp.Format("定点%d",i);
Point[i].sDM=CCommFun::Getini(strTmp,"T1","",strFile);
Point[i].dLate=atof(CCommFun::Getini(strTmp,"T2","0",strFile));
Point[i].dLong=atof(CCommFun::Getini(strTmp,"T3","0",strFile));
}
if(iPoint>0){
this->RedrawWindow();
}
}
//double to CString
CString CDraw::ftoa(double dData)
{
COleVariant vt;
CString strTmp;
vt.vt=VT_R8;
vt.dblVal=dData;
vt.ChangeType(VT_BSTR);
strTmp=vt.bstrVal;
return strTmp;
}
//画图
void CDraw::OnPaint()
{
CPaintDC dc(this); // device context for painting
double X=0,Y=0;
double X2=0,Y2=0;
int i;
RECT rect2;
CPoint point0;//方向角原点
CPoint point1;//方向角转点
long lR; //半径
CString strTmp;
//画坐标
RECT rect;
this->GetWindowRect(&rect);
int iXWidth=39;
int iYWidth=10;
int iCount=1;
int iD=(int)(iKD*iB);
//X
for(i=0;i<(rect.right-rect.left);i+=iD){
dc.MoveTo(i,rect.bottom);
dc.LineTo(i,(rect.bottom-rect.top)-iXWidth);
/*if((i/iD)/iKD>0 && ((i/iD)%iKD)==0){//显示刻度
strTmp.Format("%d",(i/iD*iKD));
rect2.left=i;
rect2.right=i+30;
rect2.top=(rect.bottom-rect.top)-iXWidth-10;
rect2.bottom=(rect.bottom-rect.top)-iXWidth-10+50;
dc.DrawText(strTmp,strTmp.GetLength(),&rect2,DT_LEFT);
}*/
}
//Y
iCount=0;
for(i=(rect.bottom-rect.top)-29;i>0;i-=iD){
dc.MoveTo(0,i);
dc.LineTo(iYWidth,i);
/*if((iCount%iKD)==0){//显示刻度
strTmp.Format("%d",iCount*iKD);
rect2.left=iYWidth;
rect2.right=iYWidth+30;
rect2.top=i-5;
rect2.bottom=i+50-5;
dc.DrawText(strTmp,strTmp.GetLength(),&rect2,DT_LEFT);
}
iCount++;*/
}
//画方向圆
point0.x=49;//方向角原点
point0.y=49;
lR=23;
rect2.left=point0.x-lR;
rect2.right=point0.x+lR;
rect2.top=point0.y-lR;
rect2.bottom=point0.y+lR;
dc.Ellipse(&rect2);
//方向角转点
if(lJiao>=0){
point1.x=point0.x+(long)(lR*sin(lJiao*PAI/180));
point1.y=point0.y-(long)(lR*cos(lJiao*PAI/180));
//画线
dc.MoveTo(point0);
dc.LineTo(point1);
}
//画图
for(i=1;i<=iPoint;i++){
//确定一个范围
CGps::LLtoXY(Point[i].dLate,Point[i].dLong,&Y,&X);
X=(X+dX)*iB;
Y=(Y+dY)*iB;
Y=(rect.bottom-rect.top)-Y;
dc.Ellipse((int)(X-iR*iB),(int)(Y-iR*iB),(int)(X+iR*iB),(int)(Y+iR*iB));
//写文字
strTmp.Format("%d:%s",i,Point[i].sDM);
rect2.left=(int)(X+iR*iB);
rect2.right=(int)(X+iR*iB+100);
rect2.top=(int)Y;
rect2.bottom=(int)(Y+50);
dc.DrawText(strTmp,strTmp.GetLength(),&rect2,DT_LEFT);
}
//画线
if(isPoint>1){
for(i=1;i<isPoint;i++){
CGps::LLtoXY(sPoint[i].dLate,sPoint[i].dLong,&Y,&X);
X=(X+dX)*iB;
Y=(Y+dY)*iB;
Y=(rect.bottom-rect.top)-Y;
CGps::LLtoXY(sPoint[i+1].dLate,sPoint[i+1].dLong,&Y2,&X2);
X2=(X2+dX)*iB;
Y2=(Y2+dY)*iB;
Y2=(rect.bottom-rect.top)-Y2;
//画线
dc.MoveTo((int)X,(int)Y);
dc.LineTo((int)X2,(int)Y2);
}
}
//画当前点
if(bDraw0){
CGps::LLtoXY(dLate0,dLong0,&Y,&X);
X=(X+dX)*iB;
Y=(Y+dY)*iB;
Y=(rect.bottom-rect.top)-Y;
dc.Ellipse((int)(X-iRD*iB),(int)(Y-iRD*iB),(int)(X+iRD*iB),(int)(Y+iRD*iB));
}
//画光标十字
dc.MoveTo(0,point.y);
dc.LineTo(rect.right,point.y);
dc.MoveTo(point.x,0);
dc.LineTo(point.x,rect.bottom);
}
void CDraw::OnButtonJiax()
{
//X轴左移
dX-=iT;
this->RedrawWindow();
//保存
CCommFun::Writeini("画图设置","X轴位移",ftoa(dX),strFile2);
}
void CDraw::OnButtonJianx()
{
//X轴有移
dX+=iT;
this->RedrawWindow();
//保存
CCommFun::Writeini("画图设置","X轴位移",ftoa(dX),strFile2);
}
void CDraw::OnButtonJiay()
{
//Y轴上移
dY+=iT;
this->RedrawWindow();
//保存
CCommFun::Writeini("画图设置","Y轴位移",ftoa(dY),strFile2);
}
void CDraw::OnButtonJiany()
{
//Y轴下移
dY-=iT;
this->RedrawWindow();
//保存
CCommFun::Writeini("画图设置","Y轴位移",ftoa(dY),strFile2);
}
void CDraw::OnSelchangeComboBl()
{
//比率
iB=m_B.GetCurSel()+1;
iB/=10;
this->RedrawWindow();
//保存
CCommFun::Writeini("画图设置","缩放比例",ftoa(iB),strFile2);
}
void CDraw::OnSelchangeComboR()
{
//半径
iR=m_R.GetCurSel()+1;
this->RedrawWindow();
//保存
CCommFun::Writeini("GPS设置","定位一个点的误差范围(米)",ftoa(iR),strFile2);
}
void CDraw::OnSelchangeComboIt()
{
//微调
iT=m_T.GetCurSel()*10;
if(iT<=0)
iT=1;
//保存
CCommFun::Writeini("画图设置","调节单位",ftoa(iT),strFile2);
}
void CDraw::OnTimer(UINT nIDEvent)
{
bDraw0=FALSE;
this->RedrawWindow();
this->KillTimer(1);
CDialog::OnTimer(nIDEvent);
}
void CDraw::OnMouseMove(UINT nFlags, CPoint point)
{
this->point=point;
this->RedrawWindow();
CDialog::OnMouseMove(nFlags, point);
}
void CDraw::OnSelchangeCOMBOiRD()
{ //修改当前点半径
iRD=(m_iRD.GetCurSel()+1);
CCommFun::Writeini("画图设置","当前点半径",iRD,strFile2);
}
void CDraw::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
//窗体变化,重画
this->RedrawWindow();
}
//把当前点或者定位第一点置中
void CDraw::OnButtonCenter()
{
if(dLate0>0){//当前点
CenterPoint(dLate0,dLong0);
}else if(iPoint>0){//定为第一个点
CenterPoint(Point[0].dLate,Point[0].dLong);
}
}
//把一个点居中
void CDraw::CenterPoint(double dLate, double dLong)
{
double X=0;
double Y=0;
RECT rect;
this->GetWindowRect(&rect);
CGps::LLtoXY(dLate,dLong,&Y,&X);
dX=(rect.right-rect.left)/(iB*2)-X;
dY=(rect.bottom-rect.top)/(iB*2)-Y;
//保存
CCommFun::Writeini("画图设置","X轴位移",ftoa(dX),strFile2);
CCommFun::Writeini("画图设置","Y轴位移",ftoa(dY),strFile2);
this->RedrawWindow();
}
//刻度选择
void CDraw::OnSelchangeComboKedu()
{
//刻度
int iTmp=(int)pow(10,m_Kd.GetCurSel());
iKD=iTmp;
this->RedrawWindow();
CCommFun::Writeini("画图设置","刻度的值",iKD,strFile2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -