Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
21
Добавлен:
16.04.2013
Размер:
6.81 Кб
Скачать
// ChildView.cpp : implementation of the CChildView class
//

#include "stdafx.h"
#include "Spline_3d.h"
#include "ChildView.h"
#include <math.h>

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

/////////////////////////////////////////////////////////////////////////////
// CChildView

CChildView::CChildView()
{ FunNum = 0;
  Quality = 10;
  RButtonDown = 0;
  LButtonDown = 0;
  ShowCarcas = 1;
  ShowLine = 0;
  ShowSpline = 1;
  a = pi/4, b = pi/4, d = 100;
  Center = CPoint(350, 240);
  Spline = new CSpline(FunNum, Quality, Center);
}

CChildView::~CChildView()
{
	if(Spline) delete Spline;
}


BEGIN_MESSAGE_MAP(CChildView,CWnd )
	//{{AFX_MSG_MAP(CChildView)
	ON_WM_PAINT()
	ON_COMMAND(ID_EDIT_FUNCTION_1, OnEditFunction1)
	ON_COMMAND(ID_EDIT_FUNCTION_2, OnEditFunction2)
	ON_COMMAND(ID_EDIT_FUNCTION_3, OnEditFunction3)
	ON_COMMAND(ID_EDIT_FUNCTION_4, OnEditFunction4)
	ON_COMMAND(ID_EDIT_FUNCTION_5, OnEditFunction5)
	ON_COMMAND(ID_SHOW_CARCAS, OnShowCarcas)
	ON_UPDATE_COMMAND_UI(ID_SHOW_CARCAS, OnUpdateShowCarcas)
	ON_COMMAND(ID_SHOW_SPLINE, OnShowSpline)
	ON_UPDATE_COMMAND_UI(ID_SHOW_SPLINE, OnUpdateShowSpline)
	ON_WM_CHAR()
	ON_WM_MOUSEMOVE()
	ON_WM_MOUSEWHEEL()
	ON_WM_RBUTTONDOWN()
	ON_WM_RBUTTONUP()
	ON_COMMAND(ID_CHANGE_QUALITY, OnChangeQuality)
	ON_COMMAND(ID_SHOW_LINE, OnShowLine)
	ON_UPDATE_COMMAND_UI(ID_SHOW_LINE, OnUpdateShowLine)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers

BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
{
	if (!CWnd::PreCreateWindow(cs))
		return FALSE;

	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
		::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);

	return TRUE;
}

void CChildView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	Spline->DrawXYZ(dc, a, b, d, Center);
	if(FunNum){if(ShowCarcas)Spline->DrawSetka(dc, a, b, d);
	           if(ShowSpline)Spline->DrawSpline(dc, a, b, d);
			   if(ShowLine)Spline->DrawLine(dc, a, b, d);
	}
	// Do not call CWnd::OnPaint() for painting messages
}


void CChildView::OnEditFunction1() 
{
	// TODO: Add your command handler code here
	FunNum = 1;
	if(Spline) delete Spline;
	Spline = new CSpline(FunNum, Quality, Center);
	Invalidate();
}

void CChildView::OnEditFunction2() 
{
	// TODO: Add your command handler code here
	FunNum = 2;
	if(Spline) delete Spline;
	Spline = new CSpline(FunNum, Quality, Center);
	Invalidate();
}

void CChildView::OnEditFunction3() 
{
	// TODO: Add your command handler code here
	FunNum = 3;
	if(Spline) delete Spline;
	Spline = new CSpline(FunNum, Quality, Center);
	Invalidate();
}

void CChildView::OnEditFunction4() 
{
	// TODO: Add your command handler code here
	FunNum = 4;
	if(Spline) delete Spline;
	Spline = new CSpline(FunNum, Quality, Center);
	Invalidate();
}

void CChildView::OnEditFunction5() 
{
	// TODO: Add your command handler code here
	FunNum = 5;
	if(Spline) delete Spline;
	Spline = new CSpline(FunNum, Quality, Center);
	Invalidate();
}

void CChildView::OnShowCarcas() 
{
	// TODO: Add your command handler code here
	if(ShowCarcas)ShowCarcas = 0;else ShowCarcas = 1;
	Invalidate();
}

void CChildView::OnUpdateShowCarcas(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(true);
	if(ShowCarcas)pCmdUI->SetCheck(1);else pCmdUI->SetCheck(0);

}

void CChildView::OnShowSpline() 
{
	// TODO: Add your command handler code here
	if(ShowSpline)ShowSpline = 0;else ShowSpline = 1;
	Invalidate();
}

void CChildView::OnUpdateShowSpline(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(true);
	if(ShowSpline)pCmdUI->SetCheck(1);else pCmdUI->SetCheck(0);
}

void CChildView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	if(nChar==43){d+=100; Invalidate();}
    if(nChar==45){d-=100; Invalidate();}
	CWnd ::OnChar(nChar, nRepCnt, nFlags);
}

void CChildView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(LButtonDown){Center.x += point.x - OldMousePoint.x;
	                Center.y += point.y - OldMousePoint.y;
	                
					OldMousePoint = point;
	                Invalidate();
	} 	
	if(RButtonDown){ a += pi/180*(point.x - OldMousePoint.x)/2;
	                 if(fabs(a)>=2*pi) a = fmod(a, 2*pi);
	                 b += pi/180*(point.y - OldMousePoint.y)/2;
	                 if(fabs(b)>=2*pi) b = fmod(b, 2*pi);
	                
					 OldMousePoint = point;
					 Invalidate();	
	}
	CWnd ::OnMouseMove(nFlags, point);
}

BOOL CChildView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{
	// TODO: Add your message handler code here and/or call default
	d += zDelta/2;
	Invalidate();

	return CWnd ::OnMouseWheel(nFlags, zDelta, pt);
}

void CChildView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	RButtonDown = 1;
	OldMousePoint = point;
	CWnd ::OnRButtonDown(nFlags, point);
}

void CChildView::OnRButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	RButtonDown = 0;
	CWnd ::OnRButtonUp(nFlags, point);
}



void CChildView::OnChangeQuality() 
{
	// TODO: Add your command handler code here
	CQuality *ChQ = new CQuality(Quality);
	int Result = ChQ->DoModal();
    
	if(Result==IDOK){if(Spline) delete Spline;
					 Quality = ChQ->m_Quality;
	                 Spline = new CSpline(FunNum, Quality, Center);
					 Invalidate();
					}
	if(ChQ) delete ChQ;
}

void CChildView::OnShowLine() 
{
	// TODO: Add your command handler code here
	if(ShowLine)ShowLine = 0;else ShowLine = 1;
	Invalidate();
}

void CChildView::OnUpdateShowLine(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(true);
	if(ShowLine)pCmdUI->SetCheck(1);else pCmdUI->SetCheck(0);
}

void CChildView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	LButtonDown = 1;
	OldMousePoint = point;
	CWnd ::OnLButtonDown(nFlags, point);
}

void CChildView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	LButtonDown = 0;
	CWnd ::OnLButtonUp(nFlags, point);
}
Соседние файлы в папке Spline_3d