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

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

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

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

CChildView::CChildView()
{	
	LButtonDown = 0;
    RButtonDown = 0;
	ShowCarcas = 1;
	Center = CPoint(350,230);
	a = pi/2; b = 0;
	d = 100; r =50;
	Spline = new CSpline(8, Center);

}

CChildView::~CChildView()
{
}


BEGIN_MESSAGE_MAP(CChildView,CWnd )
	//{{AFX_MSG_MAP(CChildView)
	ON_WM_PAINT()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_RBUTTONDOWN()
	ON_WM_RBUTTONUP()
	ON_COMMAND(ID_SHOW_CARCAS, OnShowCarcas)
	ON_UPDATE_COMMAND_UI(ID_SHOW_CARCAS, OnUpdateShowCarcas)
	ON_COMMAND(ID_NEW_SPLINE, OnNewSpline)
	ON_WM_MOUSEWHEEL()
	//}}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);
	Spline->DrawSpline(dc, ShowCarcas, a, b ,d);
	// Do not call CWnd::OnPaint() for painting messages
}


void CChildView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
   int flag = -1;
   
   for(int i=0; i<Spline->PointNum; i++)
   { CPoint P = Spline->Transform3Dto2D(Spline->Point[i]);
	 CRect Rect(P.x - Spline->PointRad, P.y - Spline->PointRad,
                P.x + Spline->PointRad, P.y + Spline->PointRad);
     if(Rect.PtInRect(point)) flag = i;
   } 
   
	LButtonDown = 1; OldMousePoint = point;	PointDown = flag;
	 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);
}

void CChildView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(LButtonDown){if(PointDown==-1){Center.x += point.x - OldMousePoint.x;
									  Center.y += point.y - OldMousePoint.y;
									}
	                 else {Spline->Point[PointDown].x += OldMousePoint.x - point.x;
	                       Spline->Point[PointDown].z += OldMousePoint.y - point.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);
}

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::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::OnNewSpline() 
{
	// TODO: Add your command handler code here
   	CNewSpline *NewSpline = new CNewSpline();
	int Result = NewSpline->DoModal();
    
	if(Result==IDOK){if(Spline) delete Spline;
						Spline = new CSpline(NewSpline->m_PointNum, Center);
						Invalidate();
					}
	if(NewSpline) delete NewSpline;	
}

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

    d += zDelta/10;           
    Invalidate();	

	return CWnd ::OnMouseWheel(nFlags, zDelta, pt);
}
Соседние файлы в папке Spline_3d_line