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

📄 dlalogsurvey.cpp

📁 能够实现一些常用的地图转换
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// DlalogSurvey.cpp : implementation file
//

#include "stdafx.h"
#include "CalSurBase.h"
#include "DlalogSurvey.h"
#include "afx.h"
#include "Survey.h"
#include "stdlib.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlalogSurvey dialog


CDlalogSurvey::CDlalogSurvey(CWnd* pParent /*=NULL*/)
	: CDialog(CDlalogSurvey::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlalogSurvey)
	m_dhbegin = FALSE;
	m_dhlast = FALSE;
	m_rfarst = -1;
	m_rlast = -1;
	m_rref = -1;
	//}}AFX_DATA_INIT
}


void CDlalogSurvey::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlalogSurvey)
	DDX_Control(pDX, IDC_COMBO_LAST, m_cmb_last);
	DDX_Control(pDX, IDC_COMBO_FARST, m_cmb_farst);
	DDX_Check(pDX, IDC_CHECK_BEGIN, m_dhbegin);
	DDX_Check(pDX, IDC_CHECK_LAST, m_dhlast);
	DDX_Control(pDX, IDC_MSFLEXGRID_FARST, m_grid_begin);
	DDX_Control(pDX, IDC_MSFLEXGRID_LAST, m_grid_last);
	DDX_Control(pDX, IDC_MSFLEXGRID2, m_grid_sd);
	DDX_Radio(pDX, IDC_RADIO_FARST, m_rfarst);
	DDX_Radio(pDX, IDC_RADIO_LAST6, m_rlast);
	DDX_Radio(pDX, IDC_RADIO_REF54, m_rref);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlalogSurvey, CDialog)
	//{{AFX_MSG_MAP(CDlalogSurvey)
	ON_BN_CLICKED(ID_CASEDDATA, OnCaseddata)
	ON_BN_CLICKED(ID_EMPTYDATA, OnEmptydata)
	ON_BN_CLICKED(ID_COUNT, OnCount)
	ON_BN_CLICKED(ID_SAVEDATA, OnSavedata)
	ON_BN_CLICKED(ID_EXIT, OnExit)
	ON_BN_CLICKED(IDC_RADIO_FARST, OnRadioFarst)
	ON_BN_CLICKED(IDC_RADIO_FARST3, OnRadioFarst3)
	ON_BN_CLICKED(IDC_RADIO_FARSTn, OnRADIOFARSTn)
	ON_BN_CLICKED(IDC_RADIO_LAST6, OnRadioLast6)
	ON_BN_CLICKED(IDC_RADIO_LAST3, OnRadioLast3)
	ON_BN_CLICKED(IDC_RADIO_LASTn, OnRADIOLASTn)
	ON_BN_CLICKED(IDC_CHECK_BEGIN, OnCheckBegin)
	ON_BN_CLICKED(IDC_CHECK_LAST, OnCheckLast)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlalogSurvey message handlers
int CDlalogSurvey::CheckFile(CString strline)  //检查文件是否有高程   0 文件错误  1无高程  2有高程
{
	CString strgd;
	if(strline.GetLength()>3)
	{
		strgd=strline.Left(4);
        strgd.TrimRight();
		if(strgd=="@XYZ")
			return 2;
		else
			return 1;
	}
	else
	{   return 0;}
}

void CDlalogSurvey::OnCaseddata() 
{
	CString strfilename;
	CStdioFile n_File;
	CString Line_Str;
	double* dlinearray;
    strfilename=GetFileName("文本文件(*.txt;*.hd)|*.txt;*.hd|所有文件(*.*)|*.*|");
	//-------------------------------------------
	CFileException e;
	if(!n_File.Open(strfilename,CFile::modeRead,&e)) 
	{
	    AfxMessageBox("文件没有打开");
		return;
	}
	
	n_File.SeekToBegin();          //将文件指针放置文件首部
	n_File.ReadString(Line_Str);   //按行读取
	int bf=CheckFile(Line_Str);
	if(bf==0)  
	{   
		AfxMessageBox("文件错误!");
	    return;
	}
	dlinearray=new double(5);
	long colnumadd=0;
	CString strwritegrid;
	long colnum=0,rownum=0;
	while(n_File.ReadString(Line_Str)!=false)
	{
		//n_File.ReadString(Line_Str);
		Line_Str.TrimLeft();
		Line_Str.TrimRight();
		
		if(Line_Str.IsEmpty())
		{continue;}
		
		colnumadd++;
//		ReadLine(Line_Str,' ',dlinearray);   //函数错误
		//按行读取数据/////////////////////////////////////////////
        CString strRightSet;
		CString strHead;
		int setj=0;
		setj = Line_Str.Find(' ');
		if(setj!=0)
		{   strHead=Line_Str.Left(setj);}   //点号
		strRightSet=Line_Str.Right(Line_Str.GetLength()-setj);
		Line_Str=strRightSet;
		Line_Str.TrimLeft();Line_Str.TrimRight();
		
		for(int j =0;j<3;j++)
		{
			setj = Line_Str.Find(' ');
			if(setj!=-1)
			{   *(dlinearray+j)=atof(Line_Str.Left(setj));}   //点号
			else
			{	
				*(dlinearray+j)=atof(Line_Str); 
				break;
			}
			strRightSet=Line_Str.Right(Line_Str.GetLength()-setj);
			Line_Str=strRightSet;
			Line_Str.TrimLeft();Line_Str.TrimRight();
		}
		/////////////////////////////////////////////////////////////
		colnum++;
		m_grid_begin.SetRow(colnum);
		m_grid_begin.SetCol(0);
		//int idj=Line_Str.Find(' ');
		strwritegrid= strHead;
		//strwritegrid.Format("%i",int(*dlinearray));
		m_grid_begin.SetText(strwritegrid);
		
    	if(bf==1)
		{
			for(int j=0;j<2;j++)
			{
				m_grid_begin.SetCol(j+1);
				strwritegrid.Format("%.3f",*(dlinearray+j));
				m_grid_begin.SetText(strwritegrid);
			}
		}
		else if(bf==2)
		{
			for(int j=0;j<3;j++)
			{
				m_grid_begin.SetCol(j+1);
				strwritegrid.Format("%.3f",*(dlinearray+j));
				m_grid_begin.SetText(strwritegrid);
			}
		}
		if(colnumadd>=m_grid_begin.GetRows()-1)
		{
			m_grid_begin.SetRows(colnumadd+100);
			m_grid_last.SetRows(colnumadd+100);
			m_grid_sd.SetRows(colnumadd+100);
		}
		
		//rownum++;
	}
	//AfxMessageBox(Line_Str);
	n_File.Close();
	return;
	delete []dlinearray;
}

void CDlalogSurvey::OnEmptydata() 
{
	m_grid_begin.Clear();
	m_grid_last.Clear();
    CString StrTxt;
    m_grid_begin.SetCol(0);
	m_grid_begin.SetRow(0);
	StrTxt = "<   点号 >|<       坐标X       >|<      坐标Y      >";
    m_grid_begin.SetFormatString(StrTxt);
	m_grid_begin.Refresh();

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

void CDlalogSurvey::OnCount() 
{
	CString strtext;
	CSurvey survey;
	UpdateData(true);
	int sel = m_cmb_farst.GetCurSel();
	int setmer=0,setdh=0;
	if(sel>=0)   //设置中央子午线及带号。
	{
		m_cmb_farst.GetLBText(sel,strtext);
		GetDhMeridian(strtext,&setmer,&setdh);
	    survey.dmerl=setmer;
		survey.fdh=setdh;
	}
	sel = m_cmb_last.GetCurSel();
	setmer=0,setdh=0;
	if(sel>=0)
	{
		m_cmb_last.GetLBText(sel,strtext);
		GetDhMeridian(strtext,&setmer,&setdh);
	    survey.dmeil_last=setmer;
		survey.fdh_last=setdh;
	}
	survey.GetSysDat(m_rref+1);    //设置坐标系参数
	//设置坐标
	CString strx;
    for(long k=1;k<m_grid_begin.GetRows();k++)
	{
		m_grid_begin.SetRow(k);
		m_grid_begin.SetCol(1);
		strx=m_grid_begin.GetText();
		if(strx.IsEmpty()){break;}
		survey.dsetx=atof(strx);
		m_grid_begin.SetCol(2);
		strx=m_grid_begin.GetText();
		survey.dsety=atof(strx);
		if(m_rfarst==0)	{survey.dudai=6;}    //设置分带
		else if(m_rfarst==1)	{survey.dudai=3;}
		else	{survey.dudai=0;}
		if(survey.dsety/10000000>=1)//去掉带号
		{
			BOOL th=survey.GetFdh();  //计算中央子午线
			survey.dsety=survey.dsety-(double)survey.fdh*1000000;
		}

		BOOL set=survey.XyToBl();  //坐标计算经纬度
		
		if(m_rlast==0)	{survey.dudai=6;}    //设置分带
		else if(m_rlast==1)	{survey.dudai=3;}
		else	{survey.dudai=0;}
		set=survey.BlToXy();

		m_grid_last.SetRow(k);		m_grid_begin.SetRow(k);
		m_grid_last.SetCol(0);		m_grid_begin.SetCol(0);
		m_grid_last.SetText(m_grid_begin.GetText());

		m_grid_last.SetCol(1);		strtext.Format("%.3f",survey.dgetx);
		m_grid_last.SetText(strtext);
		m_grid_last.SetCol(2);		strtext.Format("%.3f",survey.dgety);
		m_grid_last.SetText(strtext);

		m_grid_last.SetCol(3);
		m_grid_begin.SetCol(3);
		m_grid_last.SetText(m_grid_begin.GetText());
		m_grid_sd.SetRow(k);  m_grid_sd.SetCol(0);
		strtext.Format("%.6f",survey.dgetsd);
		m_grid_sd.SetText(strtext);
	}

	//strtext.Format("%f,%f",survey.dgetx,survey.dgety);
	//AfxMessageBox(strtext);	
}

void CDlalogSurvey::OnSavedata() 
{
	UpdateData(true);
	CString strport;
	CString strgd;
    CString strfilename;
	CStdioFile n_File;
	strfilename=GetFileName("文本文件(*.txt;*.hd)|*.txt;*.hd|所有文件(*.*)|*.*|");
	//-------------------------------------------
	CFileException e;
	if(!n_File.Open(strfilename,CFile::modeCreate | CFile::modeWrite,&e)) 
	{
	    AfxMessageBox("文件没有打开");
		return;
	}

	int sel = m_cmb_farst.GetCurSel();
	CString strtext;
	if(sel>=0)   //设置中央子午线及带号。
	{
		m_cmb_farst.GetLBText(sel,strtext);
	}
	strgd=strtext;
	sel = m_cmb_last.GetCurSel();
	if(sel>=0)   //设置中央子午线及带号。
	{
		m_cmb_last.GetLBText(sel,strtext);
	}
	CString zbx;
	if(m_rref==0)	{zbx="54坐标系";}
	else if(m_rref==1) 	{zbx="80坐标系";}
	else {zbx="GPS坐标系";}

	strgd="     "+strgd+"      "+strtext+"      "+zbx;
	strgd+="\n";
	n_File.WriteString(strgd);

	for(long k=1;k<m_grid_last.GetRows();k++)
	{
		m_grid_last.SetRow(k);
		m_grid_last.SetCol(0);
		
		strport.Format("%10s",m_grid_last.GetText());
		if(m_grid_last.GetText().IsEmpty()) {break;}
        strgd=strport;
		for(long j=1;j<m_grid_last.GetCols();j++)
		{
			m_grid_last.SetCol(j);
			strport.Format("%15s",m_grid_last.GetText());
			strgd=strgd+strport;
		}
		strgd+="\n";
		n_File.WriteString(strgd);
		//break;
	}
	n_File.Close();
	AfxMessageBox("保存完成");	
}

void CDlalogSurvey::OnExit() 
{
	//_exit(0);
	CDialog::OnCancel();
}

BOOL CDlalogSurvey::OnInitDialog() 
{
	
	CDialog::OnInitDialog();
    CString StrTxt;
    m_grid_begin.SetCol(0);

⌨️ 快捷键说明

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