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

📄 artview.cpp

📁 凸轮设计源代码!经典!
💻 CPP
字号:
// ArtView.cpp : implementation file
//

#include "stdafx.h"
#include "Cams.h"
#include "ArtView.h"
#include "CamsDoc.h"
#include"Dlgjdcdj.h"
#include<math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CArtView

IMPLEMENT_DYNCREATE(CArtView, CScrollView)

CArtView::CArtView()
{
}

CArtView::~CArtView()
{
}


BEGIN_MESSAGE_MAP(CArtView, CScrollView)
	//{{AFX_MSG_MAP(CArtView)
	ON_COMMAND(ID_MENU_JDCDJ, OnMenuJdcdj)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CArtView drawing

void CArtView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();
    CCamsDoc *pDoc=GetDocument();
	h=pDoc->h;
	d=pDoc->d;
	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx =1000;
	sizeTotal.cy =7600;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

void CArtView::OnDraw(CDC* pDC)
{
	CCamsDoc* pDoc = GetDocument();
	// TODO: add draw code here
	CString str[363];
    double x[360],y[360];
	double a,b,c;
    double n;
	int d,r;
	a=pDoc->h;
	d=pDoc->d;
	r=d/2;
	b=a/120.0;
	c=b;
	n=3.1415926/180.0;
	for(int i=0;i<90;i++)
	{
		x[i]=200.0-(r+b)*sin(n);
		y[i]=250.0-(r+b)*cos(n);
		n+=(3.1415926/180.0);
		b+=c;
	}
	n=3.1415926/180.0;
	for( i=90;i<120;i++)
	{
		x[i]=200.0-(r+b)*cos(n);
		y[i]=250.0+(r+b)*sin(n);
		n+=(3.1415926/180.0);
		b+=c;
	}
    for( i=120;i<180;i++)
	{
		x[i]=200.0-(r+b)*cos(n);
		y[i]=250.0+(r+b)*sin(n);
		n+=(3.1415926/180.0);
	}
    n=3.1415926/180;
	for( i=180;i<270;i++)
	{
		x[i]=200.0+(r+b)*sin(n);
		y[i]=250.0+(r+b)*cos(n);
		n+=(3.1415926/180.0);
		b-=c;
	}
	n=3.1415926/180.0;
	for( i=270;i<300;i++)
	{
		x[i]=200.0+(r+b)*cos(n);
		y[i]=250.0-(r+b)*sin(n);
		n+=(3.1415926/180.0);
	    b-=c;
	}
   	for(i=300;i<360;i++)
	{
		x[i]=200.0+(r+b)*cos(n);
		y[i]=250.0-(r+b)*sin(n);
		n+=(3.1415926/180.0);
		}
	str[0].Format("G54 G17 G40 G49 G90;");
    str[1].Format("M03 S500 T0101");
	str[2].Format("G01 X%f   Y%f   F100;", x[0],y[0]);
	int m,p;
	m=1,p=20;
	for(int s=3;s<362;s++)
	{
		str[s].Format("X%f   Y%f ;" ,x[m],y[m]);
		m++;
	}
	str[362].Format("M30;");
	pDC->TextOut(10,0,"凸轮数控加工代码:");
	for(int t=0;t<363;t++)
	{
		pDC->TextOut(10,p,str[t]);
			p+=20;
	}
}

/////////////////////////////////////////////////////////////////////////////
// CArtView diagnostics

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

void CArtView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CCamsDoc* CArtView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCamsDoc)));
	return (CCamsDoc*)m_pDocument;
}


#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CArtView message handlers

void CArtView::OnMenuJdcdj() 
{
    CDlgjdcdj Dlgjdcdj;
    Dlgjdcdj.m_Edit1=100;
	Dlgjdcdj.m_Edit2=36.0;
	if(Dlgjdcdj.DoModal()==IDOK)
	{
	d=Dlgjdcdj.m_Edit1;
	h=Dlgjdcdj.m_Edit2;
	Invalidate();
	}
    CCamsDoc *pDoc=GetDocument();
	pDoc->h=h;
	pDoc->d=d;
	pDoc->SetModifiedFlag(TRUE);
	
}

⌨️ 快捷键说明

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