843 lines
28 KiB
C++
843 lines
28 KiB
C++
// DialCfgTerrain.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "geomative.h"
|
|
#include "DialCfgTerrain.h"
|
|
#include "floatedit.h"
|
|
#include "FileOperTools.h"
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
#define STR_INTERVAL _T(" ")
|
|
|
|
extern bool bIsInteger(CString strTxt);
|
|
extern bool bIsFloat(CString strTxt);
|
|
extern void SplitterString(CStringArray &szArray,const CString& szSource, const CString& szSplitter);
|
|
extern int g_iUILanguage;
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CDialCfgTerrain dialog
|
|
|
|
|
|
CDialCfgTerrain::CDialCfgTerrain(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CDialCfgTerrain::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CDialCfgTerrain)
|
|
//}}AFX_DATA_INIT
|
|
m_iExplainStartIndex = 0;
|
|
m_strDatFilePath = _T("");
|
|
}
|
|
|
|
|
|
void CDialCfgTerrain::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CDialCfgTerrain)
|
|
DDX_Control(pDX, IDC_EDIT_1ST_ELECT_PT_NUMBER, m_edit1stPtIndex);
|
|
// DDX_Control(pDX, IDC_EDIT_Y_DATA, m_fEditYData);
|
|
// DDX_Control(pDX, IDC_EDIT_X_DATA, m_fEditXData);
|
|
DDX_Control(pDX, IDC_COMBO_TERRAIN_DATA_FLAG, m_cmbTerrainDataFlag);
|
|
DDX_Control(pDX, IDC_LIST_TERRAIN_DATA, m_ctrlTerrainData);
|
|
DDX_Control(pDX, IDC_LIST_REMARK_HEAD, m_ctrlRemarkHeader);
|
|
DDX_Control(pDX, IDC_LIST_REMARK_END, m_ctrlRemarkEnd);
|
|
DDX_Control(pDX, IDC_LIST_REMARK_DETAIL, m_ctrlRemarkDetail);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CDialCfgTerrain, CDialog)
|
|
//{{AFX_MSG_MAP(CDialCfgTerrain)
|
|
ON_NOTIFY(NM_CLICK, IDC_LIST_TERRAIN_DATA, OnClickListTerrainData)
|
|
ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
|
|
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
|
|
ON_BN_CLICKED(IDC_BUTTON_MODIFY, OnButtonModify)
|
|
ON_CBN_SELCHANGE(IDC_COMBO_TERRAIN_DATA_FLAG, OnSelchangeComboTerrainDataFlag)
|
|
ON_EN_KILLFOCUS(IDC_EDIT_1ST_ELECT_PT_NUMBER, OnKillfocusEdit1stElectPtNumber)
|
|
ON_BN_CLICKED(IDC_BUTTON_IMP_FILE, OnButtonImpFile)
|
|
ON_BN_CLICKED(IDC_BUTTON_SAVE_DATA, OnButtonSaveData)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CDialCfgTerrain message handlers
|
|
|
|
BOOL CDialCfgTerrain::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
// TODO: Add extra initialization here
|
|
InitUIByLanguage(g_iUILanguage);
|
|
// m_fEditXData.SetIntLimitLen(5);
|
|
// m_fEditXData.SetDecLimitLen(2);
|
|
// m_fEditYData.SetIntLimitLen(5);
|
|
// m_fEditYData.SetDecLimitLen(2);
|
|
m_ctrlTerrainData.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_GRIDLINES);
|
|
m_ctrlTerrainData.InsertColumn(0, _T("ID"), LVCFMT_LEFT, 70);
|
|
m_ctrlTerrainData.InsertColumn(1, _T("X"), LVCFMT_CENTER, 100);
|
|
m_ctrlTerrainData.InsertColumn(2, _T("Y"), LVCFMT_CENTER, 100);
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
{
|
|
m_ctrlRemarkHeader.InsertColumn(0, _T("地形格式"), LVCFMT_LEFT, 270);
|
|
m_ctrlRemarkHeader.InsertColumn(1, _T("描述"), LVCFMT_LEFT, 310);
|
|
}
|
|
else
|
|
{
|
|
m_ctrlRemarkHeader.InsertColumn(0, _T("Topography Format"), LVCFMT_LEFT, 270);
|
|
m_ctrlRemarkHeader.InsertColumn(1, _T("Description"), LVCFMT_LEFT, 310);
|
|
}
|
|
|
|
|
|
m_ctrlRemarkDetail.InsertColumn(0, _T(""), LVCFMT_LEFT, 270);
|
|
m_ctrlRemarkDetail.InsertColumn(1, _T(""), LVCFMT_LEFT, 310);
|
|
|
|
m_ctrlRemarkEnd.InsertColumn(0, _T(""), LVCFMT_LEFT, 270);
|
|
m_ctrlRemarkEnd.InsertColumn(1, _T(""), LVCFMT_LEFT, 310);
|
|
|
|
m_cmbTerrainDataFlag.ResetContent();
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
{
|
|
// //取消排序属性
|
|
// DWORD dwStyle = m_cmbTerrainDataFlag.GetStyle();
|
|
// dwStyle = dwStyle & (~LVS_SORTASCENDING); //确保升序位为0
|
|
// dwStyle = dwStyle & (~LVS_SORTDESCENDING); //确保降序位为0
|
|
// SetWindowLong(m_cmbTerrainDataFlag.m_hWnd,GWL_STYLE,dwStyle); //修改列表属性
|
|
m_cmbTerrainDataFlag.AddString(_T("水平距离: 1"));
|
|
m_cmbTerrainDataFlag.AddString(_T("垂直距离: 2"));
|
|
}
|
|
else
|
|
{
|
|
m_cmbTerrainDataFlag.AddString(_T("Horizontal space: 1"));
|
|
m_cmbTerrainDataFlag.AddString(_T("Vertical space: 2"));
|
|
}
|
|
|
|
m_cmbTerrainDataFlag.SetCurSel(0);
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
m_ctrlRemarkHeader.InsertItem(i, _T(""));
|
|
}
|
|
m_iExplainStartIndex = 3;
|
|
CString strText = _T("");
|
|
strText.Format(_T("%s1"),STR_INTERVAL);
|
|
m_ctrlRemarkHeader.SetItemText(m_iExplainStartIndex, 0, strText);
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
m_ctrlRemarkHeader.SetItemText(m_iExplainStartIndex, 1, _T("地形数据标志"));
|
|
else
|
|
m_ctrlRemarkHeader.SetItemText(m_iExplainStartIndex, 1, _T("Topography Data Flag"));
|
|
strText.Empty();
|
|
strText.Format(_T("%s0"),STR_INTERVAL);
|
|
m_ctrlRemarkHeader.SetItemText(m_iExplainStartIndex+1, 0, strText);
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
m_ctrlRemarkHeader.SetItemText(m_iExplainStartIndex+1, 1, _T("地形数据点的数目"));
|
|
else
|
|
m_ctrlRemarkHeader.SetItemText(m_iExplainStartIndex+1, 1, _T("Number of topography data points"));
|
|
|
|
//设置地形文件末尾
|
|
GetDlgItem(IDC_EDIT_1ST_ELECT_PT_NUMBER)->SetWindowText(_T("0"));
|
|
m_ctrlRemarkEnd.InsertItem(0, strText);
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
m_ctrlRemarkEnd.SetItemText(0, 1, _T("第一个电极对应的地形数据点编号"));
|
|
else
|
|
m_ctrlRemarkEnd.SetItemText(0, 1, _T("Topography point number with first electrode"));
|
|
m_ctrlRemarkEnd.InsertItem(1, strText);
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
m_ctrlRemarkEnd.SetItemText(1, 1, _T("文件末尾的零结束符"));
|
|
else
|
|
m_ctrlRemarkEnd.SetItemText(1, 1, _T("A few zeros to end the file"));
|
|
m_ctrlRemarkEnd.InsertItem(2, strText);
|
|
m_ctrlRemarkEnd.InsertItem(3, strText);
|
|
m_ctrlRemarkEnd.InsertItem(4, strText);
|
|
((CEdit*)GetDlgItem(IDC_EDIT_X_DATA))->SetLimitText(15);
|
|
((CEdit*)GetDlgItem(IDC_EDIT_Y_DATA))->SetLimitText(15);
|
|
|
|
/* m_fEditXData.SetIsMinus();*/
|
|
// m_fEditYData.SetIsMinus();
|
|
m_edit1stPtIndex.SetLimitText(6);
|
|
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CDialCfgTerrain::OnClickListTerrainData(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
int iCurSel = m_ctrlTerrainData.GetSelectionMark();
|
|
GetDlgItem(IDC_EDIT_X_DATA)->SetWindowText(m_ctrlTerrainData.GetItemText(iCurSel, 1));
|
|
GetDlgItem(IDC_EDIT_Y_DATA)->SetWindowText(m_ctrlTerrainData.GetItemText(iCurSel, 2));
|
|
*pResult = 0;
|
|
}
|
|
|
|
void CDialCfgTerrain::OnButtonDelete()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
int iIndex = m_ctrlTerrainData.GetSelectionMark();
|
|
if (-1 == iIndex)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请先选择数据."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please select data firstly."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
m_ctrlTerrainData.DeleteItem(iIndex);
|
|
m_ctrlRemarkDetail.DeleteItem(iIndex);
|
|
CString strText = _T("");
|
|
strText.Format(_T("%s%d"), STR_INTERVAL,m_ctrlTerrainData.GetItemCount());
|
|
m_ctrlRemarkHeader.SetItemText(m_iExplainStartIndex+1, 0, strText);
|
|
//重新对地形数据进行编号
|
|
CString strTerDataID;
|
|
for (int i = 0; i < m_ctrlTerrainData.GetItemCount(); i++)
|
|
{
|
|
strTerDataID.Empty();
|
|
strTerDataID.Format(_T("%d"),i+1);
|
|
m_ctrlTerrainData.SetItemText(i, 0, strTerDataID);
|
|
}
|
|
//如果删除的是前2个地形数据点,则需要对备注那块进行同步更新
|
|
if (iIndex >= 0 && iIndex < 2)
|
|
{
|
|
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
{
|
|
m_ctrlRemarkDetail.SetItemText(0, 1, _T("第一个点的水平、垂直坐标"));
|
|
m_ctrlRemarkDetail.SetItemText(1, 1, _T("第二个点的水平、垂直坐标"));
|
|
}
|
|
else
|
|
{
|
|
m_ctrlRemarkDetail.SetItemText(0, 1, _T("1st topography data point"));
|
|
m_ctrlRemarkDetail.SetItemText(1, 1, _T("2st topography data point"));
|
|
}
|
|
}
|
|
|
|
if (m_ctrlTerrainData.GetItemCount() > 2)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
m_ctrlRemarkDetail.SetItemText(m_ctrlTerrainData.GetItemCount()-1, 1, _T("最后的地形数据点"));
|
|
else
|
|
m_ctrlRemarkDetail.SetItemText(m_ctrlTerrainData.GetItemCount()-1, 1, _T("Last topography data point"));
|
|
}
|
|
|
|
}
|
|
|
|
void CDialCfgTerrain::OnButtonAdd()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
if (!UpdateData(TRUE))
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("撤回数据失败."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Retire data failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
CString strText = _T("");
|
|
float fXData = 0, fYData = 0;
|
|
GetDlgItem(IDC_EDIT_X_DATA)->GetWindowText(strText);
|
|
// m_fEditXData.GetWindowText(strText);
|
|
if (strText.IsEmpty())
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请输入水平坐标的值."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please inpit number on Horizontal coordinate(x)"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
if (!bIsFloat(strText) || 100000 <= fabs(atof(strText)))
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请在水平坐标处输入绝对值小于100000的数值."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please input an floating number that absolute value less than 100000 on Horizontal coordinate(x)."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
fXData = atof(strText);
|
|
strText.Empty();
|
|
//m_fEditYData.GetWindowText(strText);
|
|
GetDlgItem(IDC_EDIT_Y_DATA)->GetWindowText(strText);
|
|
if (strText.IsEmpty())
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请输入垂直坐标的值."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please inpit number on Vertical coordinate(y)"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
if (!bIsFloat(strText) || 100000 <= fabs(atof(strText)))
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请在垂直坐标处输入绝对值小于100000的数值."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please input an floating number that absolute value less than 100000 on Vertical coordinate(y)."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
fYData = atof(strText);
|
|
|
|
int iIndex = m_ctrlTerrainData.GetItemCount();
|
|
strText.Empty();
|
|
strText.Format(_T("%d"),iIndex+1);
|
|
m_ctrlTerrainData.InsertItem(iIndex, strText);
|
|
m_ctrlRemarkDetail.InsertItem(iIndex, _T(""));
|
|
|
|
strText.Empty();
|
|
strText.Format(_T("%.2f"),fXData);
|
|
m_ctrlTerrainData.SetItemText(iIndex, 1, strText);
|
|
|
|
|
|
strText.Empty();
|
|
strText.Format(_T("%.2f"),fYData);
|
|
m_ctrlTerrainData.SetItemText(iIndex, 2, strText);
|
|
|
|
strText.Empty();
|
|
strText.Format(_T("%s%.2f %.2f"), STR_INTERVAL, fXData, fYData);
|
|
m_ctrlRemarkDetail.SetItemText(iIndex, 0, strText);
|
|
if (0 == iIndex)
|
|
{
|
|
strText.Empty();
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
strText.Format(_T("第一个点的水平、垂直坐标"));
|
|
else
|
|
strText.Format(_T("1st topography data point"));
|
|
m_ctrlRemarkDetail.SetItemText(iIndex, 1, strText);
|
|
}
|
|
if (1 == iIndex)
|
|
{
|
|
strText.Empty();
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
strText.Format(_T("第二个点的水平、垂直坐标"));
|
|
else
|
|
strText.Format(_T("2nd topography data point"));
|
|
m_ctrlRemarkDetail.SetItemText(iIndex, 1, strText);
|
|
}
|
|
if (iIndex >= 2)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
m_ctrlRemarkDetail.SetItemText(iIndex, 1, _T("最后的地形数据点"));
|
|
else
|
|
m_ctrlRemarkDetail.SetItemText(iIndex, 1, _T("Last topography data point"));
|
|
if (iIndex-1 > 1)
|
|
{
|
|
m_ctrlRemarkDetail.SetItemText(iIndex-1, 1, _T(""));
|
|
}
|
|
|
|
}
|
|
//更改标题头部中的测点数量信息
|
|
strText.Empty();
|
|
strText.Format(_T("%s%d"), STR_INTERVAL, m_ctrlTerrainData.GetItemCount());
|
|
m_ctrlRemarkHeader.SetItemText(m_iExplainStartIndex+1, 0, strText);
|
|
}
|
|
|
|
void CDialCfgTerrain::OnButtonModify()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
int iIndex = m_ctrlTerrainData.GetSelectionMark();
|
|
if (-1 == iIndex)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请先选择数据."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please select data firstly."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
if (!UpdateData(TRUE))
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("撤回数据失败."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Retire data failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
float fXData = 0, fYData = 0;
|
|
CString strText = _T("");
|
|
GetDlgItem(IDC_EDIT_X_DATA)->GetWindowText(strText);
|
|
// m_fEditXData.GetWindowText(strText);
|
|
if (strText.IsEmpty())
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请先输入水平坐标值."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please inpit number on Horizontal coordinate(x)"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
if (!bIsFloat(strText) || 100000 <= fabs(atof(strText)))
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请在水平坐标处输入绝对值小于100000的数值."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please input an floating number that absolute value less than 100000 on Horizontal coordinate(x)."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
|
|
fXData = atof(strText);
|
|
strText.Empty();
|
|
// m_fEditYData.GetWindowText(strText);
|
|
GetDlgItem(IDC_EDIT_Y_DATA)->GetWindowText(strText);
|
|
if (strText.IsEmpty())
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请先输入垂直坐标值."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please inpit number on Vertical coordinate(y)"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
if (!bIsFloat(strText) || 100000 <= fabs(atof(strText)))
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请在垂直坐标处输入绝对值小于100000的数值."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please input an floating number that absolute value less than 100000 on Vertical coordinate(y)."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
fYData = atof(strText);
|
|
|
|
strText.Empty();
|
|
strText.Format(_T("%.2f"),fXData);
|
|
m_ctrlTerrainData.SetItemText(iIndex, 1, strText);
|
|
|
|
strText.Empty();
|
|
strText.Format(_T("%.2f"),fYData);
|
|
m_ctrlTerrainData.SetItemText(iIndex, 2, strText);
|
|
|
|
strText.Empty();
|
|
strText.Format(_T("%s%.2f %.2f"), STR_INTERVAL, fXData, fYData);
|
|
m_ctrlRemarkDetail.SetItemText(iIndex, 0, strText);
|
|
|
|
}
|
|
|
|
void CDialCfgTerrain::OnSelchangeComboTerrainDataFlag()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
int iSel = m_cmbTerrainDataFlag.GetCurSel();
|
|
if (-1 == iSel)
|
|
{
|
|
return;
|
|
}
|
|
|
|
CString str = _T("");
|
|
str.Format(_T("%s%d"), STR_INTERVAL, iSel + 1);
|
|
m_ctrlRemarkHeader.SetItemText(m_iExplainStartIndex, 0, str);
|
|
|
|
}
|
|
|
|
void CDialCfgTerrain::OnKillfocusEdit1stElectPtNumber()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
CString strText = _T("");
|
|
GetDlgItem(IDC_EDIT_1ST_ELECT_PT_NUMBER)->GetWindowText(strText);
|
|
strText.TrimLeft();
|
|
strText.TrimRight();
|
|
if (strText.IsEmpty())
|
|
{
|
|
return;
|
|
}
|
|
if (!bIsInteger(strText))
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请先输入一个正整数."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please input an postive integer."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
strText = STR_INTERVAL+strText;
|
|
m_ctrlRemarkEnd.SetItemText(0, 0, strText);
|
|
// int i
|
|
|
|
}
|
|
|
|
void CDialCfgTerrain::OnButtonImpFile()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
CString strCaption = _T("");
|
|
CString strFileName = _T("");
|
|
CString strText = _T("");
|
|
strCaption.LoadString(IDS_OPEN);
|
|
CFileDialog *pDlgOpenFile = NULL;
|
|
pDlgOpenFile = new CFileDialog (TRUE , NULL, NULL, OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_NOCHANGEDIR,
|
|
_T("dat file(*.dat)|*.dat||"),this);
|
|
pDlgOpenFile->m_ofn.lpstrTitle = strCaption;
|
|
if (IDOK != pDlgOpenFile->DoModal())
|
|
{
|
|
return;
|
|
}
|
|
strFileName = pDlgOpenFile->GetPathName();
|
|
delete pDlgOpenFile;
|
|
m_strDatFilePath = strFileName;
|
|
int iIndex = m_strDatFilePath.ReverseFind(_T('\\'));
|
|
GetDlgItem(IDC_STATIC_IMP_FILE_INFO)->SetWindowText(strFileName.Mid(iIndex+1,strFileName.GetLength()-iIndex));
|
|
|
|
}
|
|
|
|
bool CDialCfgTerrain::CheckValidBeforSave()
|
|
{
|
|
if (m_strDatFilePath.IsEmpty())
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请先导入dat文件."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please import dat file firstly."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return false;
|
|
}
|
|
|
|
if ( -1 == m_cmbTerrainDataFlag.GetCurSel())
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请先选择地形数据标志."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please select topography data flag."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return false;
|
|
}
|
|
|
|
if (0 == m_ctrlTerrainData.GetItemCount())
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请输入地形数据."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please input topography data."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return false;
|
|
}
|
|
CString strText = _T("");
|
|
GetDlgItem(IDC_EDIT_1ST_ELECT_PT_NUMBER)->GetWindowText(strText);
|
|
strText.TrimLeft();
|
|
strText.TrimRight();
|
|
if (strText.IsEmpty())
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请在第一个电极对应的地形数据点编号处输入正整数."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please input an postive integer on Data point number with the first electrode."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return false;
|
|
}
|
|
if (!bIsInteger(strText))
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("请在第一个电极对应的地形数据点编号处输入正整数."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Please input an postive integer on Data point number with the first electrode."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return false;
|
|
}
|
|
int iVal = atoi(strText);
|
|
if (iVal < 1 || iVal > m_ctrlTerrainData.GetItemCount())
|
|
{
|
|
CString str = _T("");
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
{
|
|
str.Format(_T("请在第一个电极对应的地形数据点编号处输入从 1 到 %d 之间的正整数."), m_ctrlTerrainData.GetItemCount());
|
|
AfxMessageBox(str);
|
|
}
|
|
else
|
|
{
|
|
str.Format(_T("Please input an postive integer from 1 to %d on Data point number with the first electrode."), m_ctrlTerrainData.GetItemCount());
|
|
MessageBoxEx(NULL, str, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void CDialCfgTerrain::OnButtonSaveData()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
if (!CheckValidBeforSave())
|
|
{
|
|
return;
|
|
}
|
|
int iDataCount = m_ctrlTerrainData.GetItemCount();
|
|
FILE* pFile = fopen(m_strDatFilePath,"rb+");
|
|
CString strErr = _T("");
|
|
if (NULL == pFile)
|
|
{
|
|
strErr.Format(_T("Open file failed.file path = %s,error code = %d"),m_strDatFilePath, GetLastError());
|
|
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("打开dat文件失败."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Open dat file failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return;
|
|
}
|
|
fseek(pFile, 0, SEEK_SET);
|
|
fseek(pFile, 0, SEEK_END);
|
|
int iFileLen = ftell(pFile);
|
|
CString strText= _T("");
|
|
char chBuffer[61];
|
|
memset(chBuffer, 0, 61);
|
|
fseek(pFile, 0, SEEK_SET);
|
|
//在这里最多只读取60个字节,还要留一个字节作为结束符
|
|
int iReadLen = iFileLen >= 60 ? 60 : iFileLen;
|
|
int iActuralReadLen = fread(chBuffer, 1, iReadLen, pFile);
|
|
if ( iActuralReadLen != iReadLen)
|
|
{
|
|
strErr.Empty();
|
|
strErr.Format(_T("read file_begin data failed.real_read_number = %d,need_read_number = %d, error_code= %d,file_path = %s"),
|
|
iActuralReadLen, iReadLen, GetLastError(), m_strDatFilePath);
|
|
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("读取数据失败."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Read data failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
fclose(pFile);
|
|
return;
|
|
}
|
|
strText.Empty();
|
|
strText.Format(_T("%s"),chBuffer);
|
|
int iArr = GetDevArrayFromText(strText);
|
|
if (iArr < 0)
|
|
{
|
|
fclose(pFile);
|
|
return;
|
|
}
|
|
//经过讨论,Wenner(gamma)也需要添加地形文件
|
|
// if (3 == iArr)
|
|
// {
|
|
// if (LANG_ZHCN == g_iUILanguage)
|
|
// AfxMessageBox(_T("Wenner(gamma)装置不需要添加地形数据."));
|
|
// else
|
|
// AfxMessageBox(_T("There is no need to add topographt data to Wenner(gamma) array."));
|
|
// fclose(pFile);
|
|
// return;
|
|
// }
|
|
if (iArr >= 17 && iArr <= 21) //1D脚本装置类型
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("1D装置不需要添加地形数据."));
|
|
else
|
|
MessageBoxEx(NULL, _T("There is no need to add topographt data to 1D array."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
fclose(pFile);
|
|
return;
|
|
}
|
|
int iZeroCnt = 0;
|
|
switch (iArr)
|
|
{
|
|
case 2:
|
|
case 11:
|
|
iZeroCnt = 6;
|
|
break;
|
|
case 25:
|
|
case 26:
|
|
case 27:
|
|
iZeroCnt = 5;
|
|
break;
|
|
default:
|
|
iZeroCnt = 4;
|
|
}
|
|
memset(chBuffer, 0, 61);
|
|
fseek(pFile, -1*iReadLen, SEEK_END);
|
|
iActuralReadLen = fread(chBuffer,1, iReadLen, pFile);
|
|
if ( iActuralReadLen != iReadLen)
|
|
{
|
|
strErr.Empty();
|
|
strErr.Format(_T("read file_end data failed.real_read_number = %d,need_read_number = %d, error_code= %d,file_path = %s"),
|
|
iActuralReadLen, iReadLen, GetLastError(), m_strDatFilePath);
|
|
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("读取数据失败."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Read data failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
fclose(pFile);
|
|
return;
|
|
}
|
|
strText.Empty();
|
|
strText.Format(_T("%s"),chBuffer);
|
|
//查找文件文件的结束位置,从文件末尾开始读取60个字符,在这60个字符里,查找一行里只有一个0的
|
|
//如果遇到了不是这种情况,则记录当前位置信息,并从这个位置开始写地形文件
|
|
int iWritePos = GetWriteIndexFromEndTxt(strText, iZeroCnt);
|
|
if (iWritePos <= 0)
|
|
{
|
|
fclose(pFile);
|
|
return;
|
|
}
|
|
fseek(pFile, -1*iWritePos, SEEK_END);
|
|
//开始写文件
|
|
strText.Empty();
|
|
strText.Format(_T("%d\r\n%d"), m_cmbTerrainDataFlag.GetCurSel()+1, m_ctrlTerrainData.GetItemCount());
|
|
CString strTmp = _T("");
|
|
int i = 0;
|
|
for (i = 0; i < iDataCount; i++)
|
|
{
|
|
strTmp.Empty();
|
|
strTmp.Format(_T("\r\n%s %s"),m_ctrlTerrainData.GetItemText(i, 1), m_ctrlTerrainData.GetItemText(i, 2));
|
|
strText = strText + strTmp;
|
|
}
|
|
CString strPolePt = _T("");
|
|
GetDlgItem(IDC_EDIT_1ST_ELECT_PT_NUMBER)->GetWindowText(strPolePt);
|
|
strTmp.Empty();
|
|
strTmp.Format(_T("\r\n%s"),strPolePt);
|
|
strText = strText + strTmp;
|
|
//写文件末尾结束符0
|
|
for (i = 0; i < iZeroCnt; i++)
|
|
{
|
|
strText = strText + _T("\r\n0");
|
|
}
|
|
//将地形文件
|
|
iActuralReadLen = fwrite(strText.GetBuffer(0), 1, strText.GetLength(), pFile);
|
|
if (iActuralReadLen != strText.GetLength())
|
|
{
|
|
strErr.Empty();
|
|
strErr.Format(_T("Write topography data to file failed.real_wirte_number = %d,need_write_number = %d, error_code= %d,file_path = %s"),
|
|
iActuralReadLen, strText.GetLength(), GetLastError(), m_strDatFilePath);
|
|
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("写地形数据到原文件错误."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Write topography data to original file failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
fclose(pFile);
|
|
return;
|
|
}
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("保存地形信息到原文件成功."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Write topography data to original file success."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
fclose(pFile);
|
|
return;
|
|
}
|
|
|
|
int CDialCfgTerrain::GetDevArrayFromText(const CString& strInfo)
|
|
{
|
|
CStringArray strArray;
|
|
strArray.RemoveAll();
|
|
CString strErr = _T("");
|
|
SplitterString(strArray, strInfo, _T("\n"));
|
|
int iSzie = strArray.GetSize();
|
|
if (strArray.GetSize() < 3)
|
|
{
|
|
strErr.Format(_T("Parser file error,file_content = %s"), strInfo);
|
|
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
|
return -1;
|
|
}
|
|
int iArr = atoi(strArray.GetAt(2));
|
|
if (iArr < 1 || iArr > 40 )
|
|
{
|
|
return -1;
|
|
}
|
|
return iArr;
|
|
}
|
|
|
|
int CDialCfgTerrain::GetWriteIndexFromEndTxt(CString strInfo, int& iEndZeroCnt)
|
|
{
|
|
strInfo.MakeReverse();
|
|
int iEnterCnt = 0;
|
|
int iFindZeroCnt = 0;
|
|
int iZeroMapEnterCnt = -1; //0所对应换行符的位置,在这里是为了防止2个0在同一行里
|
|
char ch;
|
|
CString strErr = _T("");
|
|
bool bIsFindFlag = false;//是否找齐了所有的0结尾符
|
|
int iPos = -1;
|
|
for (int i = 0; i < strInfo.GetLength(); i++)
|
|
{
|
|
ch = strInfo.GetAt(i);
|
|
if (_T(' ') == ch)
|
|
{
|
|
continue;
|
|
}
|
|
else if (_T('\r') == ch || _T('\n') == ch)
|
|
{
|
|
//记录换行符的位置
|
|
iPos = i;
|
|
iEnterCnt++;
|
|
}
|
|
else if (_T('0') == ch)
|
|
{
|
|
if (iEnterCnt == iZeroMapEnterCnt)
|
|
{
|
|
strErr.Empty();
|
|
strErr.Format(_T("Two zero appears in the same row"));
|
|
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
|
return -1;
|
|
}
|
|
iZeroMapEnterCnt = iEnterCnt;
|
|
iFindZeroCnt++;
|
|
}
|
|
else
|
|
{
|
|
//如果解析到不是非0,也不是空格或者换行符的话,则认为寻找结束,直接返回
|
|
iEndZeroCnt = iFindZeroCnt;
|
|
return iPos;
|
|
}
|
|
}
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("未找到结束符."));
|
|
else
|
|
MessageBoxEx(NULL, _T("Unfound end part flag in the file."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return -1;
|
|
}
|
|
/*
|
|
int CDialCfgTerrain::GetWriteIndexFromEndTxt(CString strInfo, int iEndZeroCnt)
|
|
{
|
|
strInfo.MakeReverse();
|
|
int iEnterCnt = 0;
|
|
int iFindZeroCnt = 0;
|
|
int iZeroMapEnterCnt = -1; //0所对应换行符的位置,在这里是为了防止2个0在同一行里
|
|
char ch;
|
|
CString strErr = _T("");
|
|
bool bIsFindFlag = false;//是否找齐了所有的0结尾符
|
|
for (int i = 0; i < strInfo.GetLength(); i++)
|
|
{
|
|
ch = strInfo.GetAt(i);
|
|
if (_T('\r') == ch || _T(' ') == ch)
|
|
{
|
|
continue;
|
|
}
|
|
else if (_T('\n') == ch)
|
|
{
|
|
if (bIsFindFlag)
|
|
{
|
|
return i;
|
|
}
|
|
iEnterCnt++;
|
|
}
|
|
else if (_T('0') == ch)
|
|
{
|
|
if (iEnterCnt == iZeroMapEnterCnt)
|
|
{
|
|
strErr.Empty();
|
|
strErr.Format(_T("Two zero appears in the same row"));
|
|
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
|
AfxMessageBox(_T("Parser file error."));
|
|
return -1;
|
|
}
|
|
iZeroMapEnterCnt = iEnterCnt;
|
|
iFindZeroCnt++;
|
|
if (iFindZeroCnt == iEndZeroCnt)
|
|
{
|
|
bIsFindFlag = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
strErr.Empty();
|
|
strErr.Format(_T("Parser file_end error.unexpected char = %c"),ch);
|
|
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
|
AfxMessageBox(_T("Parser file_end error."));
|
|
return -1;
|
|
}
|
|
}
|
|
AfxMessageBox(_T("Unfound end part flag in the file."));
|
|
return -1;
|
|
}
|
|
*/
|
|
|
|
void CDialCfgTerrain::InitUIByLanguage(int iLanguage)
|
|
{
|
|
if (LANG_ZHCN == iLanguage)
|
|
{
|
|
SetWindowText(_T("地形文件信息配置"));
|
|
GetDlgItem(IDC_BUTTON_IMP_FILE)->SetWindowText(_T("导入数据"));
|
|
GetDlgItem(IDC_STATIC_IMP_FILE_INFO)->SetWindowText(_T("请导入dat文件"));
|
|
GetDlgItem(IDC_STATIC_TERRAIN_DATA_DETAIL_INFO)->SetWindowText(_T("地形数据明细"));
|
|
GetDlgItem(IDC_STATIC_TERRAIN_DATA_FLAG)->SetWindowText(_T("地形数据\r\n标志:"));
|
|
|
|
GetDlgItem(IDC_STATIC_HOR_COORD_X)->SetWindowText(_T("水平坐标(x):"));
|
|
GetDlgItem(IDC_STATIC_VER_COORD_Y)->SetWindowText(_T("垂直坐标(Y):"));
|
|
GetDlgItem(IDC_BUTTON_ADD)->SetWindowText(_T("增加"));
|
|
GetDlgItem(IDC_BUTTON_MODIFY)->SetWindowText(_T("修改"));
|
|
GetDlgItem(IDC_BUTTON_DELETE)->SetWindowText(_T("删除"));
|
|
GetDlgItem(IDC_STATIC_FIRST_ELEC_DATA_NUM)->SetWindowText(_T("第一个电极对应的\r\n地形数据点编号"));
|
|
|
|
GetDlgItem(IDC_BUTTON_SAVE_DATA)->SetWindowText(_T("保存数据"));
|
|
GetDlgItem(IDC_STATIC_SAVE_DATA_INFO)->SetWindowText(_T("保存地形数据到文件"));
|
|
|
|
}
|
|
|
|
}
|