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

📄 myview.cpp

📁 是有关石油物理测井曲线的分层方法
💻 CPP
字号:
// MyView.cpp : implementation file
//

#include "stdafx.h"
#include "MyView.h"
#include "SmoothDoc.h"
#include "LogCurve.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyView

extern CWellHead wh;
extern int nCurId;
extern BOOL flag;
extern int Lmin,Rmax;

IMPLEMENT_DYNCREATE(CMyView, CScrollView)

CMyView::CMyView()
{
	tmpPt=tmpPt1=NULL;
}

CMyView::~CMyView()
{
}


BEGIN_MESSAGE_MAP(CMyView, CScrollView)
	//{{AFX_MSG_MAP(CMyView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyView drawing

void CMyView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx  = 400;
	sizeTotal.cy = 400;
	SetScrollSizes(MM_TEXT, sizeTotal);
}
void CMyView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	CSize sizeTotal;
	if(wh.bWell)
		sizeTotal.cx = wh.myDao[wh.nNumDao].rcHead.right+wh.page.right;
	else	
		sizeTotal.cx =500;
	if(wh.bWell)
		sizeTotal.cy = wh.myDao[0].rcBody.bottom +5;		
	else
		sizeTotal.cy = 1000;

	CSize sizePage(sizeTotal.cx,sizeTotal.cy/10);
	CSize sizeLine(sizeTotal.cx/10,sizeTotal.cy/500);
	SetScrollSizes(MM_TEXT, sizeTotal,sizePage,sizeLine);

//对需要绘图显示的井段参数进行设置
	if(wh.bWell)
	{
		wh.nStPoint=int((wh.dispSTDEP-wh.STDEP)/wh.RLEV+0.1);
		wh.nEndPoint=int((wh.dispENDDEP-wh.STDEP)/wh.RLEV+0.1);
		wh.tnTotalNumPoint=wh.nEndPoint-wh.nStPoint+1;
		if(flag)
		{
			if(tmpPt!=NULL)
			{
				delete []tmpPt;
				tmpPt=NULL;
			}
			if(tmpPt1!=NULL)
			{
				delete []tmpPt1;
				tmpPt1=NULL;
			}
			tmpPt=new CPoint[wh.nTotalNumPoint+10];
			tmpPt1=new CPoint[wh.nTotalNumPoint+10];
			//纵坐标
			int i,k=0;
			float tmpVScal=(float)wh.nScal/wh.nVBili;
			float L,R;
			L=R=wh.pLogData[0][nCurId];
			for(i=wh.nStPoint;i<=wh.nEndPoint;i++)		
			{
				tmpPt[k].y=tmpPt1[k].y=tmpVScal*(wh.pLogData[i][0]-wh.dispSTDEP)+wh.page.top+wh.page.nHightHead;
				k++;
			}
			//横坐标	
			MyPrepare(0,nCurId,tmpPt);
			MyPrepare(2,nCurId,tmpPt1);
/*	//输出验证
	CFile f("f:\\out1.dat", CFile::modeCreate | CFile::modeWrite );
	CString str;
	for(i=0;i<wh.nTotalNumPoint;i++)
	{
		str.Format("%4d ",i);
		f.Write(str,4);
		str.Format("%10d %10d %10d\n",tmpPt[i].x,tmpPt1[i].x,tmpPt[i].x-tmpPt1[i].x );
		f.Write(str,str.GetLength());
	}
	f.Close();
*/
		}
	}
}

void CMyView::OnDraw(CDC* pDC)
{
	CSmoothDoc* pDoc = (CSmoothDoc*)GetDocument();
	// TODO: add draw code here
	CString str;
	int i,j,k;

	CPen NewPen1,NewPen2,NewPen3,NewPen4;
	NewPen1.CreatePen(PS_SOLID,1,RGB(0,128,0));
	NewPen2.CreatePen(PS_SOLID,2,RGB(0,128,0));
	NewPen3.CreatePen(PS_SOLID,1,RGB(255,0,0));
	NewPen4.CreatePen(PS_SOLID,1,RGB(0,0,255));
	CPen* oldPen=pDC->SelectObject(&NewPen2);

	CFont fontName,fontDanwei,fontDep,*oldFont,fontKedu;
	fontName.CreateFont(12,8,0,0,500,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,0,1,FIXED_PITCH,"Arial");
	fontDanwei.CreateFont(50,25,0,0,100,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,0,1,FIXED_PITCH,"Arial");
	fontKedu.CreateFont(10,5,0,0,100,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,0,1,FIXED_PITCH,"Arial"); 
	fontDep.CreateFont( 16,8,2700,2700,100,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,0,1,FIXED_PITCH,"Arial");	
	CRect rcClient;
	GetClientRect(&rcClient);
	int tw=25;
	VLine[0]=wh.page.left;
	VLine[1]=(rcClient.right/2-tw);
	VLine[2]=(rcClient.right/2+tw);
	VLine[3]=rcClient.right-wh.page.right;
	if (!wh.bWell)
	{
		//绘制大框	
		CRect rcHeadBox(wh.page.left,
						rcClient.top+wh.page.top,
						rcClient.right-wh.page.right,
						wh.page.nHightHead/2);
		CRect rcBodyBox(rcHeadBox.left,
						rcHeadBox.bottom,
						rcHeadBox.right,
						rcClient.bottom- 5 );
		pDC->Rectangle(rcHeadBox);
		pDC->Rectangle(rcBodyBox);
		pDC->MoveTo(rcClient.right /2-tw,rcClient.top+wh.page.top) ;
		pDC->LineTo(rcClient.right /2-tw,rcClient.bottom- 5) ;
		pDC->MoveTo(rcClient.right /2+tw,rcClient.top+wh.page.top) ;
		pDC->LineTo(rcClient.right /2+tw,rcClient.bottom- 5) ;
		return	;
	}
	//绘制各个道
	for(i=0;i<=wh.nNumDao;i++)
	{
		pDC->Rectangle(wh.myDao[i].rcHead);
		pDC->Rectangle(wh.myDao[i].rcBody);
	}

	if(wh.bWell)
	{
		//绘制网格线
		DrawGrid(pDC);
	}
	pDC->SetTextColor(RGB(0,255,0));
	pDC->SelectObject(&fontDanwei); 
	pDC->TextOut((VLine[0]+VLine[1])/2,wh.page.nHightHead+wh.page.top-70,"处理前") ;
	pDC->TextOut((VLine[2]+VLine[3])/2,wh.page.nHightHead+wh.page.top-70,"处理后");

	if(flag)
	{
	//校正前
		//绘制曲线
		pDC->SelectObject(&NewPen3);
		pDC->MoveTo(tmpPt[0].x,tmpPt[0].y);
		for(int i=wh.nStPoint;i<=wh.nEndPoint;i++)
			pDC->LineTo(tmpPt[i].x,tmpPt[i].y);
		//曲线名
		pDC->SetTextColor(RGB(255,0,0));
		pDC->SetTextAlign(TA_CENTER | TA_TOP);
		pDC->SelectObject(&fontName); 
		str.Format("%s",wh.Curve[nCurId].strCurName );
		pDC->TextOut((VLine[0]+VLine[1])/2,wh.page.nHightHead+wh.page.top-20,str);
		//左右刻度
		pDC->SelectObject(&fontKedu); 
		pDC->SetTextAlign(TA_LEFT | TA_TOP);
		str.Format("%.2f",Lmin*1.0);
		pDC->TextOut(VLine[0]+5,wh.page.nHightHead+wh.page.top-20,str);
		pDC->SetTextAlign(TA_RIGHT | TA_TOP);
		str.Format("%.2f",Rmax*1.0 );
		pDC->TextOut(VLine[1]-5,wh.page.nHightHead+wh.page.top-20,str);
	//校正后
		//绘制曲线
		pDC->SelectObject(&NewPen4);
		pDC->MoveTo(tmpPt1[0].x,tmpPt1[0].y);
		for(i=wh.nStPoint;i<=wh.nEndPoint;i++ )
			pDC->LineTo(tmpPt1[i].x,tmpPt1[i].y);
		//曲线名
		pDC->SetTextColor(RGB(0,0,255));
		pDC->SetTextAlign(TA_CENTER | TA_TOP);
		pDC->SelectObject(&fontName); 
		str.Format("%s",wh.Curve[nCurId].strCurName );
		pDC->TextOut((VLine[2]+VLine[3])/2,wh.page.nHightHead+wh.page.top-20,str);
		//左右刻度
		pDC->SelectObject(&fontKedu); 
		pDC->SetTextAlign(TA_LEFT | TA_TOP);
		str.Format("%.2f",Lmin*1.0);
		pDC->TextOut(VLine[2]+5,wh.page.nHightHead+wh.page.top-20,str);
		pDC->SetTextAlign(TA_RIGHT | TA_TOP);
		str.Format("%.2f",Rmax*1.0 );
		pDC->TextOut(VLine[3]-10,wh.page.nHightHead+wh.page.top-20,str); 

	
 
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics

#ifdef _DEBUG
void CMyView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CMyView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers

//绘制网格线
void CMyView::DrawGrid(CDC *pDC)
{
	int i,j,k;	
	CString str;
	CPen NewPen1,NewPen2,NewPen3,NewPen4;
	CFont fontName,fontDanwei,fontDep,*oldFont;
	NewPen1.CreatePen(PS_SOLID,1,RGB(0,128,0));
	NewPen2.CreatePen(PS_SOLID,2,RGB(0,128,0));
	NewPen3.CreatePen(PS_SOLID,1,RGB(255,0,0));
	NewPen4.CreatePen(PS_SOLID,1,RGB(0,0,255));
	fontName.CreateFont(12,8,0,0,500,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,0,1,FIXED_PITCH,"Arial");
	fontDanwei.CreateFont(10,5,0,0,100,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,0,1,FIXED_PITCH,"Arial");
	fontDep.CreateFont( 16,8,2700,2700,100,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,0,1,FIXED_PITCH,"Arial");	
	CPen* oldPen=pDC->SelectObject(&NewPen2);
	float tt=wh.nScal /wh.nVBili;
	for(j=(int)wh.dispSTDEP;j<=wh.dispENDDEP;j++)
	{
		if(j%10 ==0 )
		{
			k=j;
			j=wh.dispENDDEP;
		}
	}
	for(j=k;j<=wh.dispENDDEP;j+=10)//粗横格线
	{
		pDC->MoveTo(wh.myDao[0].rcBody.left, 
					wh.myDao[0].rcBody.top+(j-wh.dispSTDEP )*tt );
		pDC->LineTo(wh.myDao[wh.nNumDao].rcBody.right, 
					wh.myDao[wh.nNumDao].rcBody.top+(j-wh.dispSTDEP )*tt );
	}

	pDC->SelectObject(&NewPen1);//细横格线
	for(j=0;j<(wh.dispENDDEP-wh.dispSTDEP )/1 ;j++)
	{
		pDC->MoveTo(wh.myDao[0].rcBody.left, 
					wh.myDao[0].rcBody.top+j*tt );
		pDC->LineTo(wh.myDao[wh.nNumDao].rcBody.right, 
					wh.myDao[wh.nNumDao].rcBody.top+j*tt);
	}
	
	pDC->SelectObject(&NewPen1);//竖刻度线
	for(i=0;i<=wh.nNumDao;i++)//
	{
		for(j=0;j<5;j++)
		{
			int xx=(wh.myDao[i].rcBody.right -wh.myDao[i].rcBody.left )/5;
			pDC->MoveTo(wh.myDao[i].rcBody.left+j*xx, wh.myDao[i].rcBody.top);
			pDC->LineTo(wh.myDao[i].rcBody.left+j*xx, wh.myDao[i].rcBody.bottom );
		}
	}

	//书写深度刻度
	i=1;
	oldFont=(CFont*)pDC->SelectObject(&fontDep);
	pDC->SetTextColor(RGB(0,128,0)); 
	pDC->SetTextAlign(TA_CENTER | TA_BASELINE); 
	pDC->SelectObject(&NewPen2);
	pDC->Rectangle(wh.myDao[i].rcBody);
	for(j=wh.dispSTDEP+1;j<wh.dispENDDEP;j++)
		if(j%10 ==0 )
		{
			k=j;
			j=wh.dispENDDEP ;
		}
	for(j=k;j<wh.dispENDDEP;j+=10)
	{
		str.Format("%d",j);
		pDC->TextOut(wh.myDao[i].rcBody.left+20 ,
					wh.myDao[0].rcBody.top+(j-wh.dispSTDEP)*wh.nScal /wh.nVBili,
					str);
	}
	str.Format("%s%d","DEPTH  1:",wh.nVBili) ;
	pDC->TextOut(wh.myDao[1].rcHead.left +20,(wh.myDao[1].rcHead.top +wh.myDao[1].rcHead.bottom )/2,str);
	pDC->SelectObject(oldFont);

}

int CMyView::XianZhiXa(float &ll, float &lr, float &x, float &hScall)
{
	if(x<ll)
		return 0;
	if(x>lr)
		return 198;
	else
		return (int)((x-ll)*hScall+0.1);
}

void CMyView::MyPrepare(int d, int c, CPoint *tmpPt)
{	
	int j,k;
	j=c;
	float LL=Lmin,LR=Rmax;
	CRect rcClient;
	GetClientRect(&rcClient);
	int tw=25;
	float tmpHScal;
	int tmpLeft;
	int nID;
	if (d==0)
	{
		nID=nCurId;//wh.Curve[c].GetnID();   
		tmpLeft=wh.page.left;  
		tmpHScal=((float)(rcClient.right /2-tw-tmpLeft)/(LR -LL));
	}
	else
	{
		nID=wh.Curve[c].tmpnID;  
		tmpLeft=rcClient.right /2+tw;
		tmpLeft=wh.page.left;  
		tmpHScal=((float)(rcClient.right-wh.page.right -tmpLeft)/(LR -LL));
		tmpHScal=((float)(rcClient.right /2-tw-tmpLeft)/(LR -LL));
	}
//	int a[2000];
	for(k=wh.nStPoint;k<=wh.nEndPoint;k++)
	{
		tmpPt[k-wh.nStPoint].x=tmpLeft + XianZhiXa(LL,LR,wh.pLogData[k][nID],tmpHScal) ;
	}
}

⌨️ 快捷键说明

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