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

📄 gearmeasurementview.cpp

📁 大齿轮渐开线齿形误差在位误差检测
💻 CPP
字号:
////////////////////////////////////////////////////////////////////////////////
// GearMeasurementView.cpp : implementation of the CGearMeasurementView class
// 右边视图成员函数的定义文件
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "GearMeasurement.h"

#include "GearMeasurementDoc.h"
#include "GearMeasurementView.h"

#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGearMeasurementView

IMPLEMENT_DYNCREATE(CGearMeasurementView, CView)

BEGIN_MESSAGE_MAP(CGearMeasurementView, CView)
	//{{AFX_MSG_MAP(CGearMeasurementView)
	ON_WM_MOUSEMOVE()
	ON_WM_ERASEBKGND()
	ON_WM_RBUTTONDOWN()
	ON_WM_LBUTTONDOWN()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CGearMeasurementView construction/destruction

CGearMeasurementView::CGearMeasurementView()
{
	// TODO: add construction code here

}

CGearMeasurementView::~CGearMeasurementView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CGearMeasurementView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CGearMeasurementView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CGearMeasurementView drawing
// 画图的入口
////////////////////////////////////////////////////////////////////////////

void CGearMeasurementView::OnDraw(CDC* pDC)
{
	// 获得指向Doc的指针
	CGearMeasurementDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	//获得当前的区域
	CRect rect;
	GetClientRect(&rect);
	//文字输出
	CString str("测控技术与仪器3班第一组专业课程设计:");
	pDC->TextOut(70,30,str);
	CString str0("       “大型齿轮齿形误差在位测量”");
	pDC->TextOut(150,60,str0);

	CString str1("(黑色)标准线");
	CPen myPen(PS_SOLID,2,RGB(0,0,0));// 设置画笔
    CPen* pOldPen=pDC->SelectObject(&myPen); //选择画笔,并保存旧画笔
	pDC->MoveTo(rect.Width()-300,rect.Height()-70);
	pDC->TextOut(rect.Width()-260,rect.Height()-78,str1);
    pDC->LineTo(rect.Width()-260,rect.Height()-70);
    pDC->SelectObject(pOldPen);					// 还原画笔

    CString str2("(绿色)实际测量线");
	CPen myPen1(PS_SOLID,2,RGB(0,255,0));		// 设置画笔
	CPen *pOldPen1=pDC->SelectObject(&myPen1);	// 选择画笔,并保存旧画笔	
	pDC->MoveTo(rect.Width()-300,rect.Height()-50);
    pDC->LineTo(rect.Width()-260,rect.Height()-50);
    pDC->TextOut(rect.Width()-260,rect.Height()-58,str2);
   	pDC->SelectObject(pOldPen1);					// 还原画笔

    CString str3("(红色)误差包络线");
    CPen myPen2(PS_SOLID,2,RGB(255,0,0));
    CPen *pOldPen2=pDC->SelectObject(&myPen2);
    pDC->MoveTo(rect.Width()-300,rect.Height()-30);
    pDC->LineTo(rect.Width()-260,rect.Height()-30);
    pDC->TextOut(rect.Width()-260,rect.Height()-38,str3);
    pDC->SelectObject(pOldPen2);			// 还原画笔


// 注意y的坐标与习惯相反,向下是正,为统一,记得在以后所有画图时,y前加一
	
	// 画视图的背景基准
	DrawBaseMark(pDC);

	// 画工件的轮廓
	DrawGearFigure(pDC);

	// 画测量的结果
	DrawMeasurementResult(pDC);
}

/////////////////////////////////////////////////////////////////////////////
// 具体画图实现部分
/////////////////////////////////////////////////////////////////////////////

// 画视图的背景基准
void CGearMeasurementView::DrawBaseMark(CDC *pDC)
{
	// 获得指向Doc的指针,为后面从Doc中取数准备
	CGearMeasurementDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// 获得当前的区域
	CRect rect;
	GetClientRect(rect);										

	// 设定画笔颜色、粗细
	CPen myPen1(PS_SOLID,2,RGB(0,0,0));						// 设置画笔
	CPen* pOldPen=pDC->SelectObject(&myPen1);				// 选择画笔,并保存旧画笔	
	
	// 画图主体部分
	pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2);		// 变换坐标原点到中心
	for(int i=0;i<(pDoc->m_n-1);i++)
	{
		pDC->MoveTo((int)((pDoc->m_X[i])*10+20),-(int)((pDoc->m_Y[i])*10+250));
	    pDC->LineTo((int)((pDoc->m_X[i+1])*10+20),-(int)((pDoc->m_Y[i+1])*10+250));
	}
   	pDC->SelectObject(pOldPen);	  // 还原画笔
}





// 画工件的轮廓
void CGearMeasurementView::DrawGearFigure(CDC *pDC)
{

// 获得指向Doc的指针,为后面从Doc中取数准备
	CGearMeasurementDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	 if(pDoc->m_flag==1)
	{
	
	// 获得当前的区域
	CRect rect;
	GetClientRect(rect);

	CPen myPen1(PS_SOLID,1,RGB(0,255,0));			// 设置画笔
	CPen* pOldPen1=pDC->SelectObject(&myPen1);		// 选择画笔保存旧画笔		
	// 画图主体部分
	pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2);// 变换坐标原点到中心
    for(int i=0;i<(pDoc->m_n-1);i++)
	{
		pDC->MoveTo((int)((pDoc->m_RandX[i])*10+20),-(int)((pDoc->m_Y[i])*10+250));
		pDC->LineTo((int)((pDoc->m_RandX[i+1])*10+20),-(int)((pDoc->m_Y[i+1])*10+250));	  
	}	 
	pDC->SelectObject(pOldPen1);	 	 
	}    

}


// 画测量的结果
void CGearMeasurementView::DrawMeasurementResult(CDC *pDC)
{
// 获得指向Doc的指针,为后面从Doc中取数准备
 	CGearMeasurementDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// 获得当前的区域
	if(pDoc->m_flag==1)
	{	
		CRect rect;
		GetClientRect(rect);											
		
		pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2);//变坐标原点到中心	
		CPen myPen2(PS_SOLID,2,RGB(255,0,0));	  
		CPen *pOldPen2=pDC->SelectObject(&myPen2);
		
//画图主体部分
		for(int i=0;i<(pDoc->m_n-1);i++)
	  	{
	     pDC->MoveTo((int)((pDoc->m_X[i]+pDoc->m_dfmin)*10+20),-(int)((pDoc->m_Y[i])*10+250));
		 pDC->LineTo((int)((pDoc->m_X[i+1]+pDoc->m_dfmin)*10+20),-(int)((pDoc->m_Y[i+1])*10+250));
		 pDC->MoveTo((int)((pDoc->m_X[i]+pDoc->m_dfmax)*10+20),-(int)((pDoc->m_Y[i])*10+250));
		 pDC->LineTo((int)((pDoc->m_X[i+1]+pDoc->m_dfmax)*10+20),-(int)((pDoc->m_Y[i+1])*10+250));
		}

// 恢复系统的初始设置
	   pDC->SelectObject(pOldPen2);		// 还原画笔
	 }


}

void CGearMeasurementView::OnMouseMove(UINT nFlags, CPoint point) 
{
	CString str;
	CMainFrame * pFrame=(CMainFrame *)AfxGetApp()->m_pMainWnd;  //获得指针
	CStatusBar * pStatus=&pFrame->m_wndStatusBar;
	BOOL m_bDisp=TRUE;
	if(!m_bDisp)
		pStatus->SetPaneStyle(1,SBPS_DISABLED);
	else
		pStatus->SetPaneStyle(1,SBPS_NORMAL);
	if(pStatus)
	{
		CRect rect;
		GetClientRect(rect);
		str.Format("X=%d,Y=%d",point.x-rect.Width()/2,-point.y+rect.Height()/2);
		pStatus->SetPaneText(1,str);
	}
	CView::OnMouseMove(nFlags, point);

}

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
BOOL CGearMeasurementView::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
    CBitmap bitmap;
	bitmap.LoadBitmap(IDB_chilun);
	BITMAP bmp;
	bitmap.GetBitmap(&bmp);
	CDC dcCompatible;
	dcCompatible.CreateCompatibleDC(pDC);
	dcCompatible.SelectObject(&bitmap);
	CRect rect;
	GetClientRect(&rect);
	pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
	
	return TRUE;
}
// return CView::OnEraseBkgnd(pDC);

void CGearMeasurementView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	CMenu menu;
	menu.LoadMenu(IDR_MAINFRAME);
	CMenu *pPopup=menu.GetSubMenu(3);
	ClientToScreen(&point);
	pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x,point.y,AfxGetMainWnd());
	
	CView::OnRButtonDown(nFlags, point);
}

⌨️ 快捷键说明

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