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

📄 biancdlg.cpp

📁 商业测绘软件
💻 CPP
字号:
// BiancDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DeformAdj.h"
#include "BiancDlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CString directory;
extern CString projname;
extern CString m_TouygEdit;
extern CString m_GuancgEdit;
/////////////////////////////////////////////////////////////////////////////
// CBiancDlg dialog


CBiancDlg::CBiancDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBiancDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBiancDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CBiancDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBiancDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
	DDX_GridControl(pDX,IDC_BIANC_GRID,m_Grid);
}


BEGIN_MESSAGE_MAP(CBiancDlg, CDialog)
	//{{AFX_MSG_MAP(CBiancDlg)
	ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
	ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton)
	ON_BN_CLICKED(IDC_PRINT_BUTTON, OnPrintButton)
	ON_BN_CLICKED(IDC_SAVE_BUTTON, OnSaveButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBiancDlg message handlers

BOOL CBiancDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	modiflag = true;
	char ptitle[8][15]=
	{
		_T("序号"),_T("观测时间"),_T("点名1"),_T("点名2"),_T("斜边(m)"),
			_T("天顶距"),_T("温度"),_T("气压"),
	};
	CString fname;
	char m_Name1[20],m_Name2[20];
	long m_times;
	int m_id=0;
	int j=1;
	double m_azim;
	double m_length;
	double m_tempra;
	double m_pa;
	fname = directory + "bianc.szt" ;
	FILE *fp; 	
	fp=fopen(fname,"r");
	if (fp == NULL)
	{
		AfxMessageBox("无法找到已知数据文件,数据读入失败!");
		OnCancel();
		return false;
	}
	while(!feof(fp))
	{	
		fscanf(fp,"%d %d %s %s %lf %lf %lf %lf\n",&m_id,&m_times,&m_Name1,&m_Name2,&m_length,&m_azim,&m_tempra,&m_pa);
		j=j+1;
	}
	m_nRows = j;
	m_nCols = 8;
	if (m_id == 0)
	{
		m_nRows = 1;
	}
	m_Grid.SetRowCount(m_nRows);
	m_Grid.SetColumnCount(m_nCols);
	for (j=1;j<m_nRows;j++)
		m_Grid.SetRowHeight(j,17);
	m_Grid.SetFixedColumnCount(1); 
	m_Grid.SetFixedRowCount(1);
	m_Grid.SetEditable(true);
	m_Grid.SetTextBkColor(RGB(0xFF,0xFF,0xE0));
	m_Grid.SetColumnWidth(0,40);
	m_Grid.SetColumnWidth(1,60);
	m_Grid.SetColumnWidth(2,50);
	m_Grid.SetColumnWidth(3,50);
	m_Grid.SetColumnWidth(4,60);
	m_Grid.SetColumnWidth(5,80);
	m_Grid.SetColumnWidth(6,40);
	m_Grid.SetColumnWidth(7,40);
	for (int col=0;col<m_nCols;col++)
	{
		GV_ITEM item;
		item.mask=GVIF_TEXT|GVIF_FORMAT;
		item.nFormat=DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|ES_CENTER;
		item.row=0;
		item.col=col;
		item.szText.Format(_T("%s"),ptitle[col]);
		m_Grid.SetItem(&item);
	}
	fseek(fp,0L,SEEK_SET);
	int i=1;
	while(!feof(fp))
	{
		GV_ITEM item;
		item.mask=GVIF_TEXT|GVIF_FORMAT;
		item.nFormat=DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|ES_CENTER;
		fscanf(fp,"%d %d %s %s %lf %lf %lf %lf\n",&m_id,&m_times,&m_Name1,&m_Name2,&m_length,&m_azim,&m_tempra,&m_pa);
		item.row=i;
		item.col=0;
		item.szText.Format(_T("%d"),m_id);
		m_Grid.SetItem(&item);
		item.col=1;
		item.szText.Format(_T("%d"),m_times);
		m_Grid.SetItem(&item);
		item.col=2;
		item.szText.Format(_T("%s"),m_Name1);
		m_Grid.SetItem(&item);
		item.col=3;
		item.szText.Format(_T("%s"),m_Name2);
		m_Grid.SetItem(&item);
		item.col=4;
		item.szText.Format(_T("%.4lf"),m_length);
		m_Grid.SetItem(&item);
		item.col=5;
		item.szText.Format(_T("%.4lf"),m_azim);
		m_Grid.SetItem(&item);
		item.col=6;
		item.szText.Format(_T("%.4lf"),m_tempra);
		m_Grid.SetItem(&item);
		item.col=7;
		item.szText.Format(_T("%.4lf"),m_pa);
		m_Grid.SetItem(&item);
		i=i+1;
	}
	fclose(fp);		
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CBiancDlg::OnAddButton() 
{
	// TODO: Add your control notification handler code here
	CString heading;
	heading.Format(_T("%d"),m_nRows);
	m_Grid.InsertRow(heading,-1);
	m_Grid.SetRowHeight(m_nRows,17);
	m_Grid.Invalidate();
	m_nRows=m_nRows+1;
	m_Grid.SetFocusCell(m_nRows-1,1);
	m_Grid.SetScrollPos32(1,17*m_nRows);
	m_Grid.Invalidate();
	modiflag = false;
}

void CBiancDlg::OnDeleteButton() 
{
	// TODO: Add your control notification handler code here
	int row = m_Grid.GetFocusCell().row;
	if (row >= 0)
	{
		m_Grid.DeleteRow(row);
		m_nRows = m_nRows - 1;
		for (int i=1;i<m_nRows;i++)
		{
			GV_ITEM item;
			item.mask=GVIF_TEXT|GVIF_FORMAT;
			item.nFormat=DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|ES_CENTER;
			item.row = i;
			item.col=0;
			item.szText.Format(_T("%d"),i);
			m_Grid.SetItem(&item);
		}
		m_Grid.Invalidate();
	}
	else
	{
		AfxMessageBox("请选择要删除的行!");
		return;
	}
	modiflag = false;
}

void CBiancDlg::OnPrintButton() 
{
	// TODO: Add your control notification handler code here
	m_Grid.Print();
}

void CBiancDlg::OnSaveButton() 
{
	// TODO: Add your control notification handler code here
	double h1=atof(m_TouygEdit);
	double h2=atof(m_GuancgEdit);
	double jia =atof(m_cjj);    //加常数
	double cheng =atof(m_cjc);//乘常数
	CString fname,fnewname,text;
	CString m_Name1,m_Name2;
	int m_id;
	long m_times;
	double m_length;
	double m_azim;
	double m_tempra;
	double m_pa;
	double hs;          //平距
	fname = directory + "bianc.szt" ;
	fnewname = directory + "bianc.adj" ; 
	FILE *fp; 
	FILE *fpnew; 
	fp=fopen(fname,"w");
	if (fp == NULL)
	{
		AfxMessageBox("无法找到已知数据文件,数据写入失败!");
		return;
	}
	fpnew=fopen(fnewname,"w");
	if (fpnew == NULL)
	{
		AfxMessageBox("无法找到已知数据文件,数据写入失败!");
		return;
	}
	for (int row = 1; row < m_Grid.GetRowCount(); row++)
	{
		text = m_Grid.GetItemText(row,0);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_id = atoi(text);
		text = m_Grid.GetItemText(row,1);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_times = atol(text);
		text = m_Grid.GetItemText(row,2);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_Name1 = text;
		text = m_Grid.GetItemText(row,3);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_Name2 = text;
		text = m_Grid.GetItemText(row,4);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_length = atof(text);
		text = m_Grid.GetItemText(row,5);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_azim = atof(text);
		text = m_Grid.GetItemText(row,6);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_tempra = atof(text);
		text = m_Grid.GetItemText(row,7);
		if (text == "")
		{
			AfxMessageBox("请在单元格中输入数据!");
			fclose(fp);
			fclose(fpnew);
			return;
		}
		m_pa = atof(text);
		fprintf(fp,"%d %d %s %s %lf %lf %lf %lf\n",m_id,m_times,m_Name1,m_Name2,m_length,m_azim,m_tempra,m_pa);
		double pre;
		pre = jia + m_length*cheng/1000;
		hs = GetHDistance(m_length,m_azim,m_tempra,m_pa);
		hs = hs*(6378000+h1)/(6378000+h2);
		fprintf(fpnew,"%d %d %s %s %.4lf %.4lf\n",m_id,m_times,m_Name1,m_Name2,hs,pre);
	}
	fclose(fp);
	fclose(fpnew);
	modiflag = true;
}

void CBiancDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	if ( modiflag == false )
	{
		int retuvalu = AfxMessageBox("你需要保存数据吗?",MB_OK|MB_OKCANCEL);
		if (retuvalu == IDOK )
		{
			OnSaveButton();
		}			
	}
	CDialog::OnCancel();
}

double CBiancDlg::DmsToDegree(double x)
{
	int  kf;
	double d,m;
	double xx,s;
	if (x < 0)
	{kf = -1;x = -x;}
	else
		kf = 1;
	d = (double)floor(x);
	m = (double)floor((x - d) * 100 + 0.001);
	s = (x - d - m / 100.0) * 10000.0;
	xx=(d + m / 60.0 + s / 3600.0) * kf;
	return xx;
}

double CBiancDlg::GetHDistance(double x,double a,double t,double p)
{
	double temp=0,s ;
	double jia,cheng;
	temp = x;//*(p+1)/(1+0.2*t)+x;     气象改正
	jia = atof(m_jia);
	cheng = atof(m_cheng);
	temp = temp+jia/1000+cheng*temp/1000000;
	a = (DmsToDegree(a))*3.1415926535898/180;
	s = temp*sin(a);
	return s;
}

⌨️ 快捷键说明

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