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

📄 hoopsmfcview.cpp

📁 hoops的代码
💻 CPP
字号:
// HoopsMfcView.cpp : implementation of the CHoopsMfcView class
//

#include "stdafx.h"
#include "HoopsMfc.h"

#include "HoopsMfcDoc.h"
#include "HoopsMfcView.h"
#include "HBaseView.h"
#include "HBaseOperator.h"
#include "HOpCameraOrbit.h"

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

/////////////////////////////////////////////////////////////////////////////
// CHoopsMfcView

IMPLEMENT_DYNCREATE(CHoopsMfcView, CView)

BEGIN_MESSAGE_MAP(CHoopsMfcView, CView)
	//{{AFX_MSG_MAP(CHoopsMfcView)
	ON_WM_PAINT()
	ON_COMMAND(ID_TEST_ORBIT, OnTestOrbit)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_CANCELMODE()
	ON_WM_MOUSEMOVE()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CHoopsMfcView construction/destruction

CHoopsMfcView::CHoopsMfcView()
{
	// TODO: add construction code here
	m_pHBaseView=NULL;
	m_bFirstUpdate=TRUE;
}

CHoopsMfcView::~CHoopsMfcView()
{
	if(m_pHBaseView)
		delete m_pHBaseView;
}

BOOL CHoopsMfcView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	cs.lpszClass=AfxRegisterWndClass(CS_OWNDC|CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW);

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CHoopsMfcView drawing

void CHoopsMfcView::OnDraw(CDC* pDC)
{
	CHoopsMfcDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CHoopsMfcView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CHoopsMfcView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CHoopsMfcView message handlers

void CHoopsMfcView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	m_pHBaseView = new HBaseView(GetDocument()->m_pHBaseModel, NULL, "opengl", NULL, m_hWnd, NULL);
	
	// initialize view(s)
	m_pHBaseView->Init();
	m_pHBaseView->SetAxisMode(AxisOn);
	
}

void CHoopsMfcView::AdjustAxisWindow()
{
	if(m_pHBaseView)
	{
		RECT rect;
		GetClientRect(&rect);
		int h_size=125;
		int v_size=125;
		if(m_pHBaseView->GetAxisMode()!=AxisOff)
		{
			HC_Open_Segment_By_Key(m_pHBaseView->GetAxisTriadKey());
			HC_Set_Window(-1.0,-1.0+h_size/(float)rect.right*2.0,1.0,-1.0+v_size/(float)rect.bottom*2.0);
			HC_Set_Window_Pattern("clear");
			HC_Close_Segment();
		}
	}

}

void CHoopsMfcView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	if(m_bFirstUpdate)
	{
		AdjustAxisWindow();
		m_bFirstUpdate=FALSE;
	}
	if(m_pHBaseView)
	{
		HC_Control_Update_By_Key(m_pHBaseView->GetViewKey(),"redraw everything");
		HC_Update_Display();
	}
}

void CHoopsMfcView::OnTestOrbit() 
{
	HOpCameraOrbit * pOperator = new HOpCameraOrbit(m_pHBaseView);

	m_pHBaseView->SetOperator(pOperator);
}

unsigned long CHoopsMfcView::MapFlags(unsigned long state)
{
	unsigned long flags=0;
	if(state&MK_LBUTTON)flags=MVO_LBUTTON;
	if(state&MK_RBUTTON)flags=MVO_RBUTTON;
	if(state&MK_MBUTTON)flags=MVO_MBUTTON;
	if(state&MK_SHIFT)flags=MVO_SHIFT;
	if(state&MK_CONTROL)flags=MVO_CONTROL;
	return flags;
}

void CHoopsMfcView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	HEventInfo event(m_pHBaseView);
	HBaseOperator *op=m_pHBaseView->GetCurrentOperator();
	if(op)
	{
		event.SetPoint(HE_LButtonDown,point.x,point.y,MapFlags(nFlags));
		op->OnLButtonDown(event);
	}
	
	CView::OnLButtonDown(nFlags, point);
}


void CHoopsMfcView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	HEventInfo event(m_pHBaseView);
	HBaseOperator *op=m_pHBaseView->GetCurrentOperator();
	if(op)
	{
		event.SetPoint(HE_LButtonUp,point.x,point.y,MapFlags(nFlags));
		op->OnLButtonUp(event);
	}
	CView::OnLButtonUp(nFlags, point);
}

void CHoopsMfcView::OnMouseMove(UINT nFlags, CPoint point) 
{
	HEventInfo event(m_pHBaseView);
	HBaseOperator *op=m_pHBaseView->GetCurrentOperator();
	if(op)
	{
		event.SetPoint(HE_MouseMove,point.x,point.y,MapFlags(nFlags));
		op->OnMouseMove(event);
	}
	
	CView::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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