You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
4.9 KiB
C++

1 month ago

// WinIDWDlg.cpp: 实现文件
//
#include "pch.h"
#include "framework.h"
#include "WinIDW.h"
#include "WinIDWDlg.h"
#include "afxdialogex.h"
#include <array>
#include <vector>
#include <fstream>
#include <iostream>
#include <string>
#include <omp.h>
//#include "IDWCalculation.h"
//#include "IDWHelper.h"
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CWinIDWDlg 对话框
typedef void(*CPPCallback)(LPCTSTR eventName, int someParamers);
extern "C" __declspec(dllimport)
int CalculateByFile(LPCTSTR layerFile, LPCTSTR wellFile, LPCTSTR outFile, CPPCallback callBack, double factor = 2);
extern "C" __declspec(dllimport)
int CalculateByMesh(CMesh* pMesh, double* wellDataX, double* wellDataY, double* wellDataZ, int wellCount, LPCTSTR outFile, CPPCallback callBack, double factor = 2);
CWinIDWDlg::CWinIDWDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_WINIDW_DIALOG, pParent)
, txtLayerFile(_T("C:\\GeoIntelligent\\测试\\构造图.dfg"))
, txtWellFile(_T("C:\\GeoIntelligent\\测试\\校正井1.csv"))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CWinIDWDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_LAYER, txtLayerFile);
DDX_Text(pDX, IDC_EDIT_WELL, txtWellFile);
}
BEGIN_MESSAGE_MAP(CWinIDWDlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_PLAY, &CWinIDWDlg::OnBnClickedBtnPlay)
END_MESSAGE_MAP()
// CWinIDWDlg 消息处理程序
BOOL CWinIDWDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CWinIDWDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CWinIDWDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CWinIDWDlg::OnBnClickedBtnPlay()
{
CString strResult = txtLayerFile;
strResult.Replace(".", "_idw.");
//IDWHelper idw;
//idw.Calculate(txtLayerFile, txtWellFile, strResult);
CalculateByFile(txtLayerFile, txtWellFile, strResult, nullptr);
AfxMessageBox("校正成功");
}
void CWinIDWDlg::ReadInToMatrix(string FilePath, vector<array<double, 3>>& data)
{
ifstream in;
in.open(FilePath, ios::in);//打开一个file
if (!in.is_open()) {
//cout << "Can not find " << FilePath << endl;
system("pause");
}
// 以‘,’为分隔符拆分字符串
char seps[] = " ,\t\n";;
string buff;
while (getline(in, buff)) {
array<double, 3> nums = {0};
// string->char *
char *s_input = (char *)buff.c_str();
char *token = strtok(s_input, seps);
double a;
int i = 0;//行数i
while (token != NULL) {
a = atof(token);
nums[i]=a;
i++;
if (i > 2) break;
token = strtok(NULL, seps);
}//end while
if (i < 2) continue;
data.push_back(nums);
}//end while
in.close();
//cout << "get data" << endl;
}
BOOL CWinIDWDlg::OpenFile(LPCTSTR lpszFileName)
{
if (m_pXy != NULL) {
m_pXy->Clear();
}
if (m_pXy == NULL)
m_pXy = new CXy;
if (m_pXy->ReadOtherWithExtension(lpszFileName))
{
return TRUE;
}
CFile file;
if (file.Open(lpszFileName, CFile::modeRead))
{
//m_FileName = lpszFileName;
CArchive ar(&file, CArchive::load);
Serialize(ar);
ar.Close();
}
file.Close();
return TRUE;
}
void CWinIDWDlg::Serialize(CArchive& ar)
{
if (ar.IsStoring()){ }
else
{
if (m_pXy == NULL) m_pXy = new CXy;
//BeginProgress(IDS_STRING_OpenFile);
CString name = ar.GetFile()->GetFileName();
name.MakeLower();
CSplitPath sp(name);
CString ext = sp.GetExtension();
//ar.m_pDocument = this; // set back-pointer in archive
if (ext == _T(".dfb") ||
ext == _T(".dft"))
{
m_pXy->m_version = m_pXy->DFB_ReadVersion(ar);
m_pXy->DFB_ReadEncrypt(ar, m_pXy->m_version);
if (m_pXy->IsEncrypted()){
}
m_pXy->DFB_Serialize(ar, m_pXy->m_version);
}
else if (ext == ".dml" || ext == ".xml")
m_pXy->DML_Read2(*(ar.GetFile()));
else if (ext == ".pcg")
m_pXy->PCG_Read2(*(ar.GetFile()));
else
m_pXy->DFD_Read2(*(ar.GetFile()));
}
}