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

📄 motorctrlview.cpp

📁 电机加速曲线生成器VC源程序,为从事或学习VC的朋友提供方便,同时该电机加速曲线生成器也是从事电机控制的朋友不可或缺的开发利器.
💻 CPP
字号:
// MotorCtrlView.cpp : implementation of the CMotorCtrlView class
//

#include "stdafx.h"
#include "MotorCtrl.h"

#include "MotorCtrlDoc.h"
#include "MotorCtrlView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMotorCtrlView

IMPLEMENT_DYNCREATE(CMotorCtrlView, CView)

BEGIN_MESSAGE_MAP(CMotorCtrlView, CView)
	//{{AFX_MSG_MAP(CMotorCtrlView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMotorCtrlView construction/destruction

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

}

CMotorCtrlView::~CMotorCtrlView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMotorCtrlView drawing

void CMotorCtrlView::OnDraw(CDC* pDC)
{
   
	int i;

	CMotorCtrlDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);  
    
    int   nSteps     = pDoc->m_nSteps;
	int   nHalfSteps = nSteps/2; 
	float A          = pDoc->m_A;
    float BeginF     = pDoc->m_BeginF;
    int   nFq,MaxFq;
	
	CArray <int,int> FqArray;

	CPoint point;
    
	if ( nSteps <= 0 || nSteps > 2000) { 
		return;
	}	
	
	for( i=0; i<nHalfSteps; i++ ){
 		 nFq =(int) A*( i*i );
         FqArray.Add( nFq );
	}
     
  
    MaxFq = (int) FqArray[nHalfSteps-1];
	for( i=1; i<nHalfSteps  ; i++ ){
		nFq =  (MaxFq - FqArray[nHalfSteps-1-i]) + MaxFq;
		FqArray.Add( nFq );
	}
	for( i=0;i< FqArray.GetSize();i++ ){
		FqArray[i] += (int)BeginF;
	}
    
  

    pDoc->m_FqArray.Copy(FqArray);
	DrawAxes(pDC,8,10);
	DrawLine(pDC,FqArray.GetData(),FqArray.GetSize());
	

	// TODO: add draw code for native data here
}

VOID   CMotorCtrlView::DrawAxes( CDC *pDC,int nHPart,int nWPart)
{	
	CPen pen,*pOldPen;	
	int i,nDot;	    
    CRect rect;
	GetClientRect(&rect);
	AxesRect.top    = rect.top +20;
	AxesRect.bottom = rect.bottom-20;
	AxesRect.left   = rect.left+20;
	AxesRect.right  = rect.right - 20;
  
	
    pen.CreatePen(PS_SOLID,1,RGB(0,0,255));
    pOldPen = pDC->SelectObject(&pen);
	pDC->Rectangle( AxesRect );
    pDC->SelectObject(pOldPen);
	pen.DeleteObject();	
	pen.CreatePen(PS_DOT,1,RGB(0,0,255));
	pOldPen = pDC->SelectObject(&pen);
    
	nDot = AxesRect.Height()/nHPart;
	for(i=1;i<nHPart;i++){	
		pDC->MoveTo(AxesRect.left,AxesRect.top+nDot*i);
		pDC->LineTo(AxesRect.right,AxesRect.top+nDot*i);
	}
	nDot = AxesRect.Width()/nWPart;
	for(i=1;i<nWPart;i++){	
		pDC->MoveTo(AxesRect.left+i*nDot,AxesRect.top);
		pDC->LineTo(AxesRect.left+i*nDot,AxesRect.bottom);
	}
    pDC->SelectObject(pOldPen);
    pen.DeleteObject();
	pDC->TextOut(AxesRect.left+(AxesRect.Width()-150)/2,AxesRect.top-20,"加速曲线(步-频关系)");  
}


VOID   CMotorCtrlView::DrawLine( CDC *pDC,int *pDataArray,int nCount)
{
int i;
CPoint point;    
CPen pen,*pOldPen;
int Max = *(pDataArray + nCount -1); 
   pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
   pOldPen = pDC->SelectObject(&pen);

     pDC->MoveTo(AxesRect.left,AxesRect.bottom);
	for( i=0; i<nCount; i++ ){	
		point.x = AxesRect.left   + (i*AxesRect.Width())/nCount;
		point.y = AxesRect.bottom - *( pDataArray + i )*AxesRect.Height()/Max;
		pDC->LineTo(point);
	}
	pDC->SelectObject(pOldPen);
	pen.DeleteObject();
	CString csLebel;
	csLebel.Format("%dHZ",Max);
	pDC->TextOut(AxesRect.left,AxesRect.top-20,csLebel);
	csLebel.Format("步数:%d",nCount);
	pDC->TextOut(AxesRect.right-50,AxesRect.bottom,csLebel);    
}
/////////////////////////////////////////////////////////////////////////////
// CMotorCtrlView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMotorCtrlView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMotorCtrlView message handlers

⌨️ 快捷键说明

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