Files
geomative/GeomativeStudio/cpp/logging/CDialogLoggingLithologicWnd.cpp
coco df489d5640 a
2026-07-03 16:05:30 +08:00

304 lines
9.7 KiB
C++

// D:\zm\GeomativeV2.5\cpp\logging\CDialogLoggingLithologicWnd.cpp : 实现文件
//
#include "stdafx.h"
#include "GeoMative.h"
#include "logging\CLoggingDataOper.h"
#include "logging\CDialogLoggingLithologicWnd.h"
#include "logging\CDialogLoggingSymbolEditor.h"
#include "afxdialogex.h"
// CDialogLoggingLithologicWnd 对话框
extern CGeoMativeApp theApp;
IMPLEMENT_DYNAMIC(CDialogLoggingLithologicWnd, CDialog)
CDialogLoggingLithologicWnd::CDialogLoggingLithologicWnd(CWnd* pParent /*=NULL*/)
: CDialog(CDialogLoggingLithologicWnd::IDD, pParent)
{
m_strCurPicPath.Empty();
}
CDialogLoggingLithologicWnd::~CDialogLoggingLithologicWnd()
{
}
void CDialogLoggingLithologicWnd::SetStartEndDepth(float fStartDepth, float fEndDepth)
{
m_fStartDepth = fStartDepth;
m_fEndDepth = fEndDepth;
}
void CDialogLoggingLithologicWnd::SetProfileList(std::vector<STLithologyProfile> vecProfileList)
{
m_vecProfileList = vecProfileList;
}
vector<STLithologyProfile> CDialogLoggingLithologicWnd::GetProfileList()
{
return m_vecProfileList;
}
void CDialogLoggingLithologicWnd::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_PROFILE, m_listProfile);
DDX_Control(pDX, IDC_COMBO_LITHOLOGY_NAME, m_comLithologyName);
}
BEGIN_MESSAGE_MAP(CDialogLoggingLithologicWnd, CDialog)
ON_BN_CLICKED(IDC_BTN_LITHOLOGY_EDITOR, &CDialogLoggingLithologicWnd::OnBnClickedBtnLithologyEditor)
ON_BN_CLICKED(IDC_BTN_ADD_PROFILE, &CDialogLoggingLithologicWnd::OnBnClickedBtnAddProfile)
ON_BN_CLICKED(IDC_BTN_DELETE_PROFILE, &CDialogLoggingLithologicWnd::OnBnClickedBtnDeleteProfile)
ON_BN_CLICKED(IDOK, &CDialogLoggingLithologicWnd::OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, &CDialogLoggingLithologicWnd::OnBnClickedCancel)
ON_CBN_SELCHANGE(IDC_COMBO_LITHOLOGY_NAME, &CDialogLoggingLithologicWnd::OnCbnSelchangeComboLithologyName)
ON_WM_PAINT()
ON_WM_DESTROY()
END_MESSAGE_MAP()
// CDialogLoggingLithologicWnd 消息处理程序
BOOL CDialogLoggingLithologicWnd::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在此添加额外的初始化
RECT rcList;
m_listProfile.GetClientRect(&rcList);
int iWidth = rcList.right - rcList.left;
DWORD dwStyle = m_listProfile.GetExtendedStyle();
dwStyle |= LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT;
m_listProfile.SetExtendedStyle(dwStyle);
if (LANG_ZHCN == g_iUILanguage)
{
SetWindowText(_T("岩性剖面窗口"));
SetDlgItemText(IDC_STATIC_SELECT_LITHOLOGY, _T("选择岩性"));
SetDlgItemText(IDC_STATIC_PREVIEW, _T("预览:"));
SetDlgItemText(IDC_BTN_LITHOLOGY_EDITOR, _T("岩性编辑"));
SetDlgItemText(IDC_STATIC_DEPTH_RANGE, _T("深度范围"));
SetDlgItemText(IDC_STATIC_START_DEPTH, _T("从"));
SetDlgItemText(IDC_STATIC_END_DEPTH, _T("到"));
SetDlgItemText(IDC_BTN_ADD_PROFILE, _T("添加剖面"));
SetDlgItemText(IDC_BTN_DELETE_PROFILE, _T("删除剖面"));
SetDlgItemText(IDC_STATIC_PROFILE_LIST, _T("剖面列表"));
SetDlgItemText(IDOK, _T("确定"));
SetDlgItemText(IDCANCEL, _T("取消"));
m_listProfile.InsertColumn(0, _T("起始深度"));
m_listProfile.InsertColumn(1, _T("终止深度"));
m_listProfile.InsertColumn(2, _T("岩性"));
m_listProfile.InsertColumn(3, _T(""));//岩性图片
}
else
{
m_listProfile.InsertColumn(0, _T("Start Depth"));
m_listProfile.InsertColumn(1, _T("End Depth"));
m_listProfile.InsertColumn(2, _T("Lithology"));
m_listProfile.InsertColumn(3, _T(""));//岩性图片
}
QueryLithologyNameFromDB();
m_listProfile.SetColumnWidth(0, iWidth / 3);
m_listProfile.SetColumnWidth(1, iWidth / 3);
m_listProfile.SetColumnWidth(2, iWidth - iWidth / 3 - iWidth / 3);
m_listProfile.SetColumnWidth(3, 0);
CString strText;
strText.Format(_T("%.1f"), m_fStartDepth);
SetDlgItemText(IDC_EDIT_START_DEPTH, strText);
strText.Format(_T("%.1f"), m_fEndDepth);
SetDlgItemText(IDC_EDIT_END_DEPTH, strText);
//初始化列表数据
int iItemCount = m_vecProfileList.size();
if (iItemCount > 0)
{
for (int i = 0; i < iItemCount; i++)
{
m_listProfile.InsertItem(i, _T(""));
strText.Format(_T("%.1f"), m_vecProfileList[i].fStartDepth);
m_listProfile.SetItemText(i, 0, strText);
strText.Format(_T("%.1f"), m_vecProfileList[i].fEndDepth);
m_listProfile.SetItemText(i, 1, strText);
m_listProfile.SetItemText(i, 2, m_vecProfileList[i].szLithologyName);
m_listProfile.SetItemText(i, 3, m_vecProfileList[i].szLithologyPic);
}
}
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CDialogLoggingLithologicWnd::ReleaseComboBox()
{
int iItemCount = m_comLithologyName.GetCount();
char* pszLithologyPic = NULL;
for (int i = 0; i < iItemCount; i++)
{
pszLithologyPic = (char*)m_comLithologyName.GetItemData(i);
if (pszLithologyPic != NULL)
{
delete[] pszLithologyPic;
pszLithologyPic = NULL;
}
}
m_comLithologyName.ResetContent();
}
void CDialogLoggingLithologicWnd::QueryLithologyNameFromDB()
{
ReleaseComboBox();
m_mapLithologyInfo.clear();
m_mapLithologyInfo = CLoggingDataOper::GetInstance()->QueryLithologyInfo();
int iItemCount = m_mapLithologyInfo.size();
if (iItemCount > 0)
{
map<CString, STLoggingLithologyInfo>::iterator iter = m_mapLithologyInfo.begin();
int iLength = 0;
char* pszLithologyPic = NULL;
for (int i = 0; iter != m_mapLithologyInfo.end(), i < iItemCount; iter++, i++)
{
m_comLithologyName.AddString(iter->second.szLithologyName);
iLength = sizeof(iter->second.szLithologyPic);
pszLithologyPic = new char[iLength];
strcpy(pszLithologyPic, iter->second.szLithologyPic);
m_comLithologyName.SetItemData(i, (DWORD_PTR)pszLithologyPic);
}
m_comLithologyName.SetCurSel(0);
OnCbnSelchangeComboLithologyName();
}
}
void CDialogLoggingLithologicWnd::OnBnClickedBtnLithologyEditor()
{
// TODO: 在此添加控件通知处理程序代码
CDialogLoggingSymbolEditor dlgSymbolEditor;
dlgSymbolEditor.DoModal();
QueryLithologyNameFromDB();
}
void CDialogLoggingLithologicWnd::OnBnClickedBtnAddProfile()
{
CString strStartDepth, strEndDepth, strLithologyName, strLithologyPic;
GetDlgItemTextA(IDC_EDIT_START_DEPTH, strStartDepth);
GetDlgItemTextA(IDC_EDIT_END_DEPTH, strEndDepth);
strStartDepth.Format(_T("%.1f"), atof(strStartDepth));
strEndDepth.Format(_T("%.1f"), atof(strEndDepth));
int iItemCount = m_listProfile.GetItemCount();
CString strListStartDepth, strListEndDepth;
for (int i = 0; i < iItemCount; i++)
{
strListStartDepth.Format(_T("%.1f"), atof(m_listProfile.GetItemText(i, 0)));
strListEndDepth.Format(_T("%.1f"), atof(m_listProfile.GetItemText(i, 1)));
if ((atof(strStartDepth) > atof(strListStartDepth) && atof(strStartDepth) < atof(strListEndDepth))
|| (atof(strEndDepth) > atof(strListStartDepth) && atof(strEndDepth) < atof(strListEndDepth))
|| (atof(strListStartDepth) == atof(strStartDepth) && atof(strListEndDepth) == atof(strEndDepth)))
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("输入的深度范围和之前的岩性图范围有交叠,请重新输入!"));
else
MessageBoxEx(NULL, _T("Input depth range overlaps with the previous lithology map range, please re-enter!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return;
}
}
int iSel = m_comLithologyName.GetCurSel();
m_comLithologyName.GetWindowTextA(strLithologyName);
strLithologyPic = (char*)m_comLithologyName.GetItemData(iSel);
m_listProfile.InsertItem(iItemCount, _T(""));
m_listProfile.SetItemText(iItemCount, 0, strStartDepth);
m_listProfile.SetItemText(iItemCount, 1, strEndDepth);
m_listProfile.SetItemText(iItemCount, 2, strLithologyName);
m_listProfile.SetItemText(iItemCount, 3, strLithologyPic);
}
void CDialogLoggingLithologicWnd::OnBnClickedBtnDeleteProfile()
{
int iItem = -1;
while (m_listProfile.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED) != -1)
{
iItem = m_listProfile.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
m_listProfile.DeleteItem(iItem);
}
}
void CDialogLoggingLithologicWnd::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
m_vecProfileList.clear();
STLithologyProfile stProfile;
int iItemCount = m_listProfile.GetItemCount();
for (int i = 0; i < iItemCount; i++)
{
stProfile.fStartDepth = atof(m_listProfile.GetItemText(i, 0));
stProfile.fEndDepth = atof(m_listProfile.GetItemText(i, 1));
strcpy(stProfile.szLithologyName,m_listProfile.GetItemText(i, 2));
strcpy(stProfile.szLithologyPic, m_listProfile.GetItemText(i, 3));
m_vecProfileList.push_back(stProfile);
}
CDialog::OnOK();
}
void CDialogLoggingLithologicWnd::OnBnClickedCancel()
{
// TODO: 在此添加控件通知处理程序代码
CDialog::OnCancel();
}
void CDialogLoggingLithologicWnd::OnCbnSelchangeComboLithologyName()
{
// TODO: 在此添加控件通知处理程序代码
int iCurSel = m_comLithologyName.GetCurSel();
if (iCurSel != -1)
{
m_strCurPicPath = (char*)m_comLithologyName.GetItemData(iCurSel);
RECT rcPic;
GetDlgItem(IDC_STATIC_PIC_LITHOLOGY)->GetWindowRect(&rcPic);
ScreenToClient(&rcPic);
RedrawWindow(&rcPic);
}
}
void CDialogLoggingLithologicWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
CBitmap bmp;
CDC dcMem;
dcMem.CreateCompatibleDC(&dc); //创建与对话框dc兼容的内存dc
RECT rcPic;
GetDlgItem(IDC_STATIC_PIC_LITHOLOGY)->GetWindowRect(&rcPic);
ScreenToClient(&rcPic);
HBITMAP hBmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(), m_strCurPicPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (bmp.Attach(hBmp))
{
BITMAP bitMap;
bmp.GetBitmap(&bitMap);
CBitmap* pBmp = dcMem.SelectObject(&bmp);
dc.StretchBlt(rcPic.left, rcPic.top, rcPic.right-rcPic.left, rcPic.bottom - rcPic.top, &dcMem, 0, 0, bitMap.bmWidth, bitMap.bmHeight, SRCCOPY);
dc.SelectObject(pBmp);
}
}
void CDialogLoggingLithologicWnd::OnDestroy()
{
ReleaseComboBox();
CDialog::OnDestroy();
// TODO: 在此处添加消息处理程序代码
}