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

📄 p_rview.cpp

📁 此为地球物理中的
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// P_RView.cpp : implementation of the CP_RView class
//

#include "stdafx.h"


#include "P_R.h"
#include "P_RDoc.h"
#include "P_RView.h"
#include"MainFrm.h"

#include"math.h"

#include"globalExt.h"

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

/////////////////////////////////////////////////////////////////////////////
// CP_RView

IMPLEMENT_DYNCREATE(CP_RView, CView)

BEGIN_MESSAGE_MAP(CP_RView, CView)
	//{{AFX_MSG_MAP(CP_RView)
	ON_COMMAND(ID_BUTTON_DRAWPOINT, OnButtonDrawpoint)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_COMMAND(ID_BUTTON_ERASE, OnButtonErase)
	ON_WM_SETCURSOR()
	ON_WM_CONTEXTMENU()
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_FILE_SAVE, OnFileSave)
	ON_WM_SIZE()
	ON_WM_LBUTTONDBLCLK()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CP_RView construction/destruction

CP_RView::CP_RView()
{
    NOWACTION=NULLACTION;//初始动作为无动作

   	m_hMouseCursor=LoadCursor(NULL,IDC_ARROW);//初始化系统鼠标指针

    ::SetCursor(m_hMouseCursor);


	OnPoint=false;//鼠标移动爆炸点为假

	m_TotleObj=0;//界面个数初始化0

	m_RgnPoint=NULL;//坐标数组初始化为NULL
    
	g_HaveTerrain=false;
}

CP_RView::~CP_RView()
{
  if(m_RgnPoint)
	  delete []m_RgnPoint;
}

BOOL CP_RView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CP_RView drawing

void CP_RView::OnDraw(CDC* pDC)
{
	CP_RDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	//CPen pen(2,1,RGB(255,0,0)); //创建画笔
	//CPen* pOldPen=pDC->SelectObject(&pen);//选入画笔
    CRect rc;
    GetClientRect(&rc);
	if(g_HaveTerrain)
	{
           // m_Rgn.CreatePolygonRgn(m_RgnPoint,m_TotleObj+3,WINDING);

			CBrush pointKnob(::GetSysColor(COLOR_3DSHADOW));
	//	
	        pDC->FillRgn(&m_Rgn, &pointKnob);

	        pointKnob.DeleteObject();
            
			int xp,yp;
            CString str;
            
			m_RgnPoint[m_TotleObj+1]=CPoint(rc.right-10,rc.bottom-10);
			m_RgnPoint[m_TotleObj+2]=CPoint(rc.left+10,rc.bottom-10);
            Center(m_RgnPoint,m_TotleObj+3,&xp,&yp);
      		
            str.Format("下层速度%.1f m/s",g_fVDown);
            pDC->TextOut(xp,yp,str);
            
            m_RgnPoint[m_TotleObj+1]=CPoint(rc.right-10,rc.top+10);
			m_RgnPoint[m_TotleObj+2]=CPoint(rc.left +10,rc.top+10);
		    Center(m_RgnPoint,m_TotleObj+3,&xp,&yp);

            str.Format("上层速度%.1f m/s",g_fVUp);
            pDC->TextOut(xp,yp,str);
             
	}
    int flag=g_SumTer;
	if(flag)
	{
	    while(flag--)
		g_Terrain[flag].Draw(pDC);//给地形类赋值
		//g_Terrain[0].Draw(pDC);//给地形类赋值
	}
	 DrawAxis(pDC);

	DrawBall((int)g_fEXAxis,(int)g_fEYAxis,pDC);
   // pDC->SelectObject(pOldPen);    //恢复画笔
}
void CP_RView::DrawBall(int x,int y,CDC* pDC)
{
   
		   CBrush b;
		   b.CreateSolidBrush(RGB(255,0,0)); // 创建填充色画刷 

		   CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&b);//选择对象进DC
       
		   pDC->Ellipse(x-5,y-5,x+5,y+5);//画点(以圆代替点)
           
		   pDC->MoveTo(x+6,y);
           pDC->LineTo(x+12,y-6);//画出X轴
           
		   pDC->MoveTo(x+6,y);
           pDC->LineTo(x+12,y+6);//画出X轴

		   pDC->MoveTo(x+6,y);
           pDC->LineTo(x+26,y);//画出X轴
           
		   pDC->TextOut(x+26,y,"放炮点");

           pDC->SelectObject(pOldBrush);//恢复原始画刷
   
		   b.DeleteObject();
}
void CP_RView::DrawAxis(CDC* pDC)
{    //画坐标线的函数
        

 //确定图象显示大小
	   CRect rc;
       GetClientRect(&rc);

//确定X,Y轴每单位显示宽度
	   pDC->TextOut(0,0,"(0,0)");

	   CPen pen(0,2,RGB(0,0,0)); //创建画笔
	   CPen* pOldPen=pDC->SelectObject(&pen);//选入画笔

   	   pDC->MoveTo(rc.left+10,rc.top+10);
       pDC->LineTo(rc.right-10,rc.top+10);//画出X轴
        
	   pDC->MoveTo(rc.left+10,rc.top+10);
       pDC->LineTo(rc.left+10,rc.bottom-10);//画出Y轴
    
	   pDC->SelectObject(pOldPen);    //恢复画笔
//////////////////////////////////////////////////////
	   CPen pen2(0,1,RGB(0,0,0)); //创建画笔
	   CPen* pOldPen2=pDC->SelectObject(&pen2);//选入画笔
 
   	  
       for(double ii=rc.left+10+37.8/2;ii<rc.right-10;ii+=37.8)
	   {
		   pDC->MoveTo(int(ii),rc.top+10);
           pDC->LineTo(int(ii),rc.top+15);//X轴每5毫米一个间隔
	   }
	   for(ii=rc.top+10+37.8/2;ii<rc.bottom-10;ii+=37.8)
	   {
		   pDC->MoveTo(rc.left+10,int(ii));//Y轴每5毫米一个间隔
           pDC->LineTo(rc.left+15,int(ii));
	   }
	    CString strAxis;
       
       int k=0;
       for(ii=rc.left+10;ii<rc.right-10;ii+=37.8)
	   {
		   pDC->MoveTo(int(ii),rc.top+10);
           pDC->LineTo(int(ii),rc.top+20);////X轴每10毫米一个间隔
           /*
		   k++;
		   if(k>1)
		   {
		       strAxis.Format("%.0f",double(k-1)*(g_fXDis/500.0/13.0)*g_fXDis);
		       pDC->TextOut(int(ii)-5,rc.top+20,strAxis);
		   }
           */
	   }
	    strAxis.Format("%.0f 米",g_fXDis);
        int L=strAxis.GetLength();

		pDC->TextOut(rc.right-L*7,rc.top+20,strAxis);
	   // k=0;
	    for(ii=rc.top+10;ii<rc.bottom-10;ii+=37.8)
	   {
		   pDC->MoveTo(rc.left+10,int(ii));
           pDC->LineTo(rc.left+20,int(ii));////Y轴每10毫米一个间隔
           /*
		   k++;
		   if(k>1)
		   {
		       strAxis.Format("%.0f",double(k-1)*(g_fYDis/600.0/16.0)*g_fYDis);
		       pDC->TextOut(rc.left+20,int(ii)-7,strAxis);
		   }
          */
	   }
	   
      CFont vFont;//第三个参数是字体的旋转角度,为了竖排输出文字
	  vFont.CreateFont(13,0,-900,
		0,0,
		FALSE,
		FALSE,
		FALSE,
		ANSI_CHARSET,
		OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS,
		PROOF_QUALITY,
		DEFAULT_PITCH+FF_ROMAN,
		"Times New Roman"
		);
       CFont* pOldFont=pDC->SelectObject(&vFont);//选入画笔

       strAxis.Format("%.0f 千米",g_fYDis);

       L=strAxis.GetLength();

	   pDC->TextOut(rc.left+30,rc.bottom-6*L,strAxis);

	   pDC->SelectObject(pOldFont);

	   pDC->SelectObject(pOldPen2);    //恢复画笔
}
/////////////////////////////////////////////////////////////////////////////
// CP_RView printing

BOOL CP_RView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CP_RView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CP_RView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CP_RView diagnostics

#ifdef _DEBUG
void CP_RView::AssertValid() const
{
	CView::AssertValid();
}

void CP_RView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CP_RDoc* CP_RView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CP_RDoc)));
	return (CP_RDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CP_RView message handlers

void CP_RView::OnButtonDrawpoint() 
{
	NOWACTION = DRAWTERRAIN;//当前动作为画点

    m_OldPoint=CPoint(10,10);
	if(NOWACTION==DRAWTERRAIN)//改变鼠标样式以示当前动作
	{  
	   m_hMouseCursor=AfxGetApp()->LoadCursor(IDC_CURSOR_UP);
	   ::SetCursor(m_hMouseCursor); 
	}
}

void CP_RView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	m_bLdown=true;  //鼠标按下为真

    CRect rc;
    GetClientRect(&rc);//得到视图区大小
	
	CClientDC dc(this);//设备初始化
    
	if((point.x>g_fEXAxis-5 && point.x<g_fEXAxis+5) &&
		(point.y>g_fEYAxis-5 && point.y<g_fEYAxis+5))
	{
		OnPoint=true;//鼠标在放炮点上为真
    }
	else
       OnPoint=false;//鼠标在放炮点上为假
    
	   CPen pen(0,3,RGB(4,36,255)); //创建画笔
	   CPen* pOldPen=dc.SelectObject(&pen);//选入画笔

	switch (NOWACTION)
	{
	 case DRAWTERRAIN:
		 {   

⌨️ 快捷键说明

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