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

📄 transfromdlg.cpp

📁 能够实现一些常用的地图转换
💻 CPP
字号:
// Transfromdlg.cpp : implementation file
//

#include "stdafx.h"
#include "CalSurBase.h"
#include "Transfromdlg.h"
#include "Survey.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTransfromdlg dialog


CTransfromdlg::CTransfromdlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTransfromdlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTransfromdlg)
	m_newfirx = 0.0;
	m_newfiry = 0.0;
	m_newscnx = 0.0;
	m_newscny = 0.0;
	m_oldfiry = 0.0;
	m_oldfirx = 0.0;
	m_oldscnx = 0.0;
	m_oldscny = 0.0;
    //}}AFX_DATA_INIT
}


void CTransfromdlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTransfromdlg)
	DDX_Text(pDX, IDC_EDIT_NEWFIRSTX, m_newfirx);
	DDX_Text(pDX, IDC_EDIT_NEWFIRSTY, m_newfiry);
	DDX_Text(pDX, IDC_EDIT_NEWSCNX, m_newscnx);
	DDX_Text(pDX, IDC_EDIT_NEWSCNY, m_newscny);
	DDX_Text(pDX, IDC_EDIT_OLDFIRSTY, m_oldfiry);
	DDX_Text(pDX, IDC_EDIT_OLDFIRSTX, m_oldfirx);
	DDX_Text(pDX, IDC_EDIT_OLDSCNX, m_oldscnx);
	DDX_Text(pDX, IDC_EDIT_OLDSCNY, m_oldscny);
	DDX_Control(pDX, IDC_MSFLEXGRID_NEW, m_gridnew);
	DDX_Control(pDX, IDC_MSFLEXGRID_OLD, m_gridold);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTransfromdlg, CDialog)
	//{{AFX_MSG_MAP(CTransfromdlg)
	ON_BN_CLICKED(IDCLEARDATA, OnCleardata)
	ON_BN_CLICKED(ID_SAVEDATA, OnSavedata)
	ON_BN_CLICKED(ID_INPUTDATA, OnInputdata)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTransfromdlg message handlers

BEGIN_EVENTSINK_MAP(CTransfromdlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CTransfromdlg)
	ON_EVENT(CTransfromdlg, IDC_MSFLEXGRID_OLD, -603 /* KeyPress */, OnKeyPressMsflexgridOld, VTS_PI2)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CTransfromdlg::OnKeyPressMsflexgridOld(short FAR* KeyAscii) 
{
	CString getdata;CString strport;
	getdata=m_gridold.GetText();
	getdata.TrimLeft();
    getdata.TrimRight();
	if(*KeyAscii==8)
	{
        strport=getdata.Left(getdata.GetLength()-1);
		m_gridold.SetText(strport);
	}
    else if(*KeyAscii==32)
	{
		long scol=0;
		scol=m_gridold.GetCol();
		if(scol>=2)
		{
            m_gridold.SetRow(m_gridold.GetRow()+1);
			m_gridold.SetCol(0);
		}
		else
		{
		    m_gridold.SetCol(scol+1);
		}
	}
	else
	{
		strport.Format("%c",*KeyAscii);
		getdata=getdata+strport;
		m_gridold.SetText(getdata);
	}			
}

BOOL CTransfromdlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CString StrTxt;
	m_gridold.SetCol(0);
	m_gridold.SetRow(0);
	StrTxt = "< 点号 >|<   坐标(X)   >|<  坐标(Y)   >";
	m_gridold.SetFormatString(StrTxt);
	m_gridold.Refresh();	//m_gridold

	m_gridnew.SetCol(0);
	m_gridnew.SetRow(0);
	StrTxt = "< 点号 >|<   坐标(X)   >|<  坐标(Y)   >";
	m_gridnew.SetFormatString(StrTxt);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CTransfromdlg::OnCleardata() 
{
    m_gridold.Clear();
	m_gridnew.Clear();
	CString StrTxt;
	m_gridold.SetCol(0);
	m_gridold.SetRow(0);
	StrTxt = "< 点号 >|<   坐标(X)   >|<  坐标(Y)   >";
	m_gridold.SetFormatString(StrTxt);
	m_gridold.Refresh();	//m_gridold

	m_gridnew.SetCol(0);
	m_gridnew.SetRow(0);
	StrTxt = "< 点号 >|<   坐标(X)   >|<  坐标(Y)   >";
	m_gridnew.SetFormatString(StrTxt);
	m_gridnew.Refresh();	//m_gridold
}

void CTransfromdlg::OnSavedata() 
{
	UpdateData(true);
	CString strport;
	CString strgd;
    CString strfilename;
	CStdioFile n_File;
	CFileDialog gldOpenFile(true,"*.*",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|",NULL);
	gldOpenFile.DoModal();
    strfilename=gldOpenFile.GetPathName();
	//-------------------------------------------
	CFileException e;
	if(!n_File.Open(strfilename,CFile::modeCreate | CFile::modeWrite,&e)) 
	{
		return;
	}

	for(long k=1;k<m_gridnew.GetRows();k++)
	{
		m_gridnew.SetRow(k);
		m_gridnew.SetCol(0);
		
		strport.Format("%10s",m_gridnew.GetText());
		if(m_gridnew.GetText().IsEmpty()) {break;}
        strgd=strport;
		for(long j=1;j<m_gridnew.GetCols();j++)
		{
			m_gridnew.SetCol(j);
			strport.Format("%15s",m_gridnew.GetText());
			strgd=strgd+strport;
		}
		strgd+="\n";
		n_File.WriteString(strgd);
	}
	n_File.Close();
    ShellExecute(::GetDesktopWindow(), _T("open"), strfilename, NULL, NULL, SW_NORMAL);		
}

void CTransfromdlg::OnOK() 
{	
	UpdateData(true);
	CSurvey survey;
	typePoint oldp1;	typePoint oldp2;
	typePoint newp1;	typePoint newp2;
	oldp1.x = m_oldfirx;	oldp1.y = m_oldfiry;
	oldp2.x = m_oldscnx;	oldp2.y = m_oldscny;

	newp1.x = m_newfirx;	newp1.y = m_newfiry;
	newp2.x = m_newscnx;	newp2.y = m_newscny;

	double cs1=0,cs2=0,cs3=0,cs4=0;
	BOOL bf;
    bf=survey.TransTwoContrlXy(oldp1,oldp2,newp1,newp2,&cs1,&cs2,&cs3,&cs4);
	if(!bf)
	{
		AfxMessageBox("控制点错误");
		return;
	}
	typePoint oldpoint;typePoint tanspoint;
	CString strport;
	for(int j=1;j<m_gridold.GetRows();j++)
	{
		m_gridold.SetRow(j);
		m_gridold.SetCol(1);
		if(m_gridold.GetText().IsEmpty()) {  break; }
		oldpoint.x =atof(m_gridold.GetText());
		m_gridold.SetCol(2);
		oldpoint.y =atof(m_gridold.GetText());
		survey.TransXy(oldpoint,&tanspoint,cs1,cs2,cs3,cs4);
		m_gridnew.SetRow(j);
		m_gridnew.SetCol(1);
		strport.Format("%.3f",tanspoint.x);
		m_gridnew.SetText(strport);
		m_gridnew.SetCol(2);
		strport.Format("%.3f",tanspoint.y);
		m_gridnew.SetText(strport);
		m_gridnew.SetCol(0);
		m_gridold.SetCol(0);
		m_gridnew.SetText(m_gridold.GetText());
	}
}

void CTransfromdlg::OnInputdata() 
{
    CString strfilename;
	CStdioFile n_File;
	CFileDialog gldOpenFile(true,"*.*",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|",NULL);
	gldOpenFile.DoModal();
    strfilename=gldOpenFile.GetPathName();
	//-------------------------------------------
	CFileException e;
	if(!n_File.Open(strfilename,CFile::modeRead,&e)) 
	{		return;	}
	CString cstrLine;
	CString strgd;
	n_File.ReadString(cstrLine);
	strgd=cstrLine.Left(4);
	strgd.TrimLeft();strgd.TrimRight();
	int setj=0;
	int colnum=0;
	if(strgd=="@XY")
	{
		while(n_File.ReadString(cstrLine)!=false)
		{
			cstrLine.TrimLeft(); cstrLine.TrimRight();
			if(cstrLine.IsEmpty())  {  continue; }
			colnum=colnum+1;
			if(colnum>=m_gridold.GetRows())
			{
				m_gridold.SetRows(colnum+100);
				m_gridnew.SetRows(colnum+100);
				//AfxMessageBox("错误!文件长度超过100行");
				//return;
			}
			
			setj=cstrLine.Find(' ');
			strgd=cstrLine.Left(setj);
			strgd.TrimLeft();strgd.TrimRight();
			m_gridold.SetRow(colnum);
			m_gridold.SetCol(0);
			m_gridold.SetText(strgd);
			strgd=cstrLine.Right(cstrLine.GetLength()-setj);
			strgd.TrimLeft();strgd.TrimRight();
			cstrLine=strgd;
			setj=cstrLine.Find(' ');
			strgd=cstrLine.Left(setj);
			strgd.TrimLeft();strgd.TrimRight();
			m_gridold.SetCol(1);
			m_gridold.SetText(strgd);
			strgd=cstrLine.Right(cstrLine.GetLength()-setj);
			strgd.TrimLeft();strgd.TrimRight();
			m_gridold.SetCol(2);
			m_gridold.SetText(strgd);
		}
	}
	else
	{
		AfxMessageBox("文件错误!");
		return;
	}	
}

⌨️ 快捷键说明

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