📄 processdoc.cpp
字号:
// ProcessDoc.cpp : implementation of the CProcessDoc class
//
#include "stdafx.h"
#include "Process.h"
#include "ProcessDoc.h"
#include "MainFrm.h"
#include "ProcessView.h"
#include "DlgIntensity.h"
#include <iostream.h>
#include <fstream.h>
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CProcessDoc
IMPLEMENT_DYNCREATE(CProcessDoc, CDocument)
BEGIN_MESSAGE_MAP(CProcessDoc, CDocument)
//{{AFX_MSG_MAP(CProcessDoc)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_VIEW_INTENSITY, OnViewIntensity)
ON_COMMAND(ID_OPENTEXT, OnOpentext)
ON_COMMAND(ID_QUDIAODOUHAO, OnQudiaodouhao)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProcessDoc construction/destruction
CProcessDoc::CProcessDoc()
{
DataNum=0;
m_bOpenFile=FALSE;
m_SHOWDATAVIEW=FALSE;
DRAWDATABPNN=FALSE;
}
CProcessDoc::~CProcessDoc()
{
}
BOOL CProcessDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CProcessDoc serialization
void CProcessDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CProcessDoc diagnostics
#ifdef _DEBUG
void CProcessDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CProcessDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CProcessDoc commands
void CProcessDoc::OnFileOpen()
{
OnNewDocument();
DataNum=0;
//获得的主框架的句柄
CMainFrame *pFrm=(CMainFrame*)AfxGetMainWnd();
//获得活动视图的句柄
CProcessView *pView=(CProcessView* )pFrm->GetActiveView();
static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
static char BASED_CODE lpszDefExt[] = TEXT("txt");
//Create the dialog to select the demo data file to load the data
CFileDialog dlg(TRUE,
lpszDefExt,
NULL,
OFN_READONLY |
OFN_FILEMUSTEXIST |
OFN_PATHMUSTEXIST,
szFilter,
NULL);//不能为this指针,因为this 是指父窗口,而这里的this是CProcessDoc,不对
//父窗口应是CWnd
if(dlg.DoModal () == IDOK)
{
lpszinputdatafile = dlg.GetPathName ();
FileName=dlg.GetFileName();
// FileExt=dlg.GetFolderPath();
}
else
{
return;
}
CStdioFile m_File;
CFileException e;
if(!m_File.Open(lpszinputdatafile,CFile::modeRead, &e))
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
}
double XX,YY ;
CString m_strLine;
CString m_str;
char m_char;
BOOL m_bEnd=TRUE;
int TempDepth,TempData,dot,kk;
int temp;
memset(DataDepth,0.0,sizeof(double)*shuzu);
memset(DataData,0.0,sizeof(double)*shuzu);
XX=0.0;
YY=0.0;
TempDepth=0;
TempData=0;
while(m_bEnd)
{
m_bEnd=m_File.ReadString(m_strLine);
if(m_bEnd)//如果读出一行
{
DataNum++;
dot=0;
kk=0;
int num=m_strLine.GetLength();
for(int i=0;i<num;i++)
{
m_char=m_strLine.GetAt(i);
if(m_char!=',')//当两组数据间用空格分开时为' '
{ //当两组数据间用逗号分开时为','
m_str+=m_char;
}
else
{
dot++;
switch(dot)
{
case 1:
YY=atof(m_str);
DataDepth[TempDepth]=(double)YY;
TempDepth++;
m_str="";
for(kk=i+1;kk<num;kk++)
{ //注意:如果让kk<num-1的话,读出的DataData[]有可能不对!!!
m_char=m_strLine.GetAt(kk);
m_str+=m_char;
}
XX=atof(m_str);
DataData[TempData]=(double)XX;
TempData++;
m_str="";
i=num;
break;
default:
break;
}
}
}
}
}
temp=2*DataNum;
memset(DataWaveletLow,0.0,sizeof(double)*shuzu);
memset(DataWaveletHigh,0.0,sizeof(double)*shuzu);
m_File.Close();
UpdateAllViews(NULL, HINT_UPDATE_WINDOW, NULL);
// UpdateAllViews(NULL);
m_bOpenFile=TRUE ;
pView->Invalidate();
pView->AFTERKALMAN=false;
pView->AFTERDWT=false;
m_SHOWDATAVIEW=TRUE;
}
void CProcessDoc::OnViewIntensity()
{ //显示直方图
int i;
int j;
int m_lCount[1000];
int temp;
int MaxData;
MaxData=0;
//测井曲线的最大值
for (i = 0; i < DataNum; i ++)
{
(int)temp=DataData[i];
if(temp>MaxData) MaxData=temp;
if(temp<0)
{
AfxMessageBox("有负数,暂不能显示!",MB_OK|MB_ICONINFORMATION);
return;
}
}
for (i = 0; i < MaxData; i ++)
{
// 清零
m_lCount[i] = 0;
}
// 计算各个灰度值的计数
for (j = 0; j <DataNum; j ++)
{
// 计数加1
m_lCount[(int)DataData[j]]++;
}
CDlgIntensity dlgPara;//
dlgPara.MaxData=MaxData;
dlgPara.nDataFrom=DataDepth[0];
dlgPara.nDataTo=DataDepth[DataNum-1];
dlgPara.DataNum=DataNum;
memcpy(dlgPara.DataData,DataData,sizeof(double)*shuzu);
memcpy(dlgPara.DataDepth,DataDepth,sizeof(double)*shuzu);
for (i = 0; i < MaxData; i ++)
{
dlgPara.m_lCount[i]=m_lCount[i];
}
// 显示对话框
if (dlgPara.DoModal() != IDOK)
{
// 返回
return;
}
}
void CProcessDoc::OnOpentext()
{ //打开对应的文本文件,FileName是要打开的文件,_T(NULL)是要打开的文件的路径
::ShellExecute(NULL,NULL,_T(FileName),NULL,_T(NULL),SW_SHOW);
}
void CProcessDoc::OnQudiaodouhao()
{
int i,j;
ofstream ostrm;
ostrm.open( lpszinputdatafile);
for(j=0;j<DataNum;j++)
{
ostrm<<DataDepth[j]<<" ";
ostrm<<DataData[j]<<endl;
}
ostrm.close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -