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

📄 formcommandview.cpp

📁 RBF平台
💻 CPP
字号:
// FormCommandView.cpp : implementation file
//

#include "stdafx.h"
#include "RBFmodelor.h"
#include "FormCommandView.h"
#include "RBFmodelorDoc.h"
#include "RBFmodelorView.h"
#include "MainFrm.h"
#include "glut.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFormCommandView

IMPLEMENT_DYNCREATE(CFormCommandView, CFormView)

CFormCommandView::CFormCommandView()
	: CFormView(CFormCommandView::IDD)
{
	//{{AFX_DATA_INIT(CFormCommandView)
		// NOTE: the ClassWizard will add member initialization here
		BackColor = RGB(0,0,0);
		AmbientColor = RGB(256,0,0);
		DiffuseColor = RGB(0,256,0);
		SpecularColor = RGB(0,0,256);
	//}}AFX_DATA_INIT

}

CFormCommandView::~CFormCommandView()
{

}

void CFormCommandView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFormCommandView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	DDX_Control(pDX, IDC_FRAME_COLOR_BACK, m_ControlBackColor);
	DDX_Control(pDX, IDC_FRAME_COLOR_LIGHT_AMBIENT3, m_ControlColorLightSpecular);
	DDX_Control(pDX, IDC_FRAME_COLOR_LIGHT_AMBIENT2, m_ControlColorLightDiffuse);
	DDX_Control(pDX, IDC_FRAME_COLOR_LIGHT_AMBIENT, m_ControlColorLightAmbient);
    DDX_Control(pDX, IDC_RADIO_ROTATION, m_fvrot);
	DDX_Control(pDX, IDC_RADIO_PAN, m_fvpan);
	DDX_Control(pDX, IDC_RADIO_ZOOM, m_fvzoom);
	DDX_Control(pDX, IDC_RADIO_SURF, m_fvsurf);
	DDX_Control(pDX, IDC_RADIO_POINT, m_fvvertex);
	DDX_Control(pDX, IDC_RADIO_LINE,  m_fvline);
	DDX_Control(pDX, IDC_CHECK_SHOWMODE, m_fvshowmode);
	DDX_Control(pDX, IDC_CENBOX, m_fvbox);
	DDX_Control(pDX, IDC_SLIDER_POINTSIZE, m_fvptsizeslder);
	DDX_Control(pDX, IDC_CHECK_AXES, m_fvaxis);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFormCommandView, CFormView)
	//{{AFX_MSG_MAP(CFormCommandView)
	ON_WM_LBUTTONUP()
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_RADIO_ROTATION, OnRadioRotation)
	ON_BN_CLICKED(IDC_RADIO_PAN, OnRadioPan)
	ON_BN_CLICKED(IDC_RADIO_ZOOM, OnRadioZoom)
	ON_BN_CLICKED(IDC_RADIO_SURF, OnRadioSurf)
	ON_BN_CLICKED(IDC_RADIO_LINE, OnRadioLine)
	ON_BN_CLICKED(IDC_RADIO_POINT, OnRadioPoint)
	ON_BN_CLICKED(IDC_CHECK_SHOWMODE, OnCheckShowmode)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER_POINTSIZE, OnCustomdrawSliderPointsize)
	ON_BN_CLICKED(IDC_CENBOX, OnCenbox)
	ON_BN_CLICKED(IDC_CHECK_AXES, OnCheckAxes)
	//}}AFX_MSG_MAP
	ON_REGISTERED_MESSAGE(WM_MY_MESSAGEONMESH, OnMyMessageMesh)

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFormCommandView diagnostics

#ifdef _DEBUG
void CFormCommandView::AssertValid() const
{
	CFormView::AssertValid();
}

void CFormCommandView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFormCommandView message handlers
CView *CFormCommandView::GetRBFModelorView() 
{
	CRBFmodelorApp *pApp = (CRBFmodelorApp *)AfxGetApp();
	CMainFrame *pFrame = (CMainFrame *)pApp->m_pMainWnd;
	CView *pView = (CView *)pFrame->m_wndSplitter.GetPane(0,1);
	return pView;
}



void CFormCommandView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CRect rect;
	//CToolApp *pApp = (CToolApp *)AfxGetApp();
	float r,g,b;
	CRBFmodelorView *pView = (CRBFmodelorView *)GetRBFModelorView();
	// back color
	m_ControlBackColor.GetWindowRect(&rect);	
	ScreenToClient(&rect);
	if(rect.PtInRect(point))
	{
		CColorDialog dlg(BackColor);
		if(dlg.DoModal()==IDOK)
		{
			BackColor = dlg.GetColor();	
			r = (float)GetRValue(BackColor) / 255.0f;
			g = (float)GetGValue(BackColor) / 255.0f;
			b = (float)GetBValue(BackColor) / 255.0f;
			pView->m_ClearColorRed   = r;
			pView->m_ClearColorGreen = g;
			pView->m_ClearColorBlue  = b;
			glClearColor(r,g,b,1.0f);
			this->InvalidateRect(&rect,FALSE);
			pView->InvalidateRect(NULL,FALSE);
		}
	}

	// ambient light color
	m_ControlColorLightAmbient.GetWindowRect(&rect);	
	ScreenToClient(&rect);
	if(rect.PtInRect(point))
	{
		CColorDialog dlg(AmbientColor);
		if(dlg.DoModal()==IDOK)
		{
			AmbientColor = dlg.GetColor();	
			// Refresh Light0
			r = (float)GetRValue(AmbientColor) / 255.0f;
			g = (float)GetGValue(AmbientColor) / 255.0f;
			b = (float)GetBValue(AmbientColor) / 255.0f;
			float	ambientProperties[] = {r,g,b,1.0f};
			glLightfv( GL_LIGHT0, GL_AMBIENT, ambientProperties);
			// Refresh views
			this->InvalidateRect(&rect,FALSE);
			pView->InvalidateRect(NULL,FALSE); 
		}
	}		
	
	// specular light color
	m_ControlColorLightSpecular.GetWindowRect(&rect);	
	ScreenToClient(&rect);
	if(rect.PtInRect(point))
	{
		CColorDialog dlg(SpecularColor);
		if(dlg.DoModal()==IDOK)
		{
			SpecularColor = dlg.GetColor();	
			// Refresh Light0
			float r = (float)GetRValue(SpecularColor) / 255.0f;
			float g = (float)GetGValue(SpecularColor) / 255.0f;
			float b = (float)GetBValue(SpecularColor) / 255.0f;
			float	specularProperties[]  = {r,g,b,1.0f};
			glLightfv( GL_LIGHT0, GL_DIFFUSE, specularProperties);
			// Refresh views
			this->InvalidateRect(&rect,FALSE);
			pView->InvalidateRect(NULL,FALSE); 
		}
	}		

	// diffuse light color
	m_ControlColorLightDiffuse.GetWindowRect(&rect);	
	ScreenToClient(&rect);
	if(rect.PtInRect(point))
	{
		CColorDialog dlg(DiffuseColor);
		if(dlg.DoModal()==IDOK)
		{
			DiffuseColor = dlg.GetColor();	
			// Refresh Light0
			float r = (float)GetRValue(DiffuseColor) / 255.0f;
			float g = (float)GetGValue(DiffuseColor) / 255.0f;
			float b = (float)GetBValue(DiffuseColor) / 255.0f;
			float	diffuseProperties[]  = {r,g,b,1.0f};
			glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseProperties);
			// Refresh views
			this->InvalidateRect(&rect,FALSE);
			pView->InvalidateRect(NULL,FALSE); 
		}
	}		
	CFormView::OnLButtonUp(nFlags, point);	
}

void CFormCommandView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	// Options are stored in Application
	// TODO: Add your message handler code here
	CRect rect;
	
	// Color back
	m_ControlBackColor.GetWindowRect(&rect);
	ScreenToClient(&rect);
	CBrush BrushBack(BackColor);
	dc.FillRect(&rect,&BrushBack);
	
	// Color light ambient
	m_ControlColorLightAmbient.GetWindowRect(&rect);	
	ScreenToClient(&rect);
	CBrush BrushLightAmbient(AmbientColor);
	dc.FillRect(&rect,&BrushLightAmbient);

	// Color light diffuse
	m_ControlColorLightDiffuse.GetWindowRect(&rect);	
	ScreenToClient(&rect);
	CBrush BrushLightDiffuse(DiffuseColor);
	dc.FillRect(&rect,&BrushLightDiffuse);

	// Color light specular
	m_ControlColorLightSpecular.GetWindowRect(&rect);	
	ScreenToClient(&rect);
	CBrush BrushLightSpecular(SpecularColor);
	dc.FillRect(&rect,&BrushLightSpecular);
	// Do not call CFormView::OnPaint() for painting messages
}

void CFormCommandView::OnRadioRotation() 
{
	// TODO: Add your control notification handler code here
	CRBFmodelorView * pview = (CRBFmodelorView *) GetRBFModelorView();
	
	pview->m_rotate = m_fvrot.GetCheck();
	pview->m_pan = false;
	pview->m_zoom = false;

}

void CFormCommandView::OnRadioPan() 
{
	// TODO: Add your control notification handler code here
	CRBFmodelorView * pview = (CRBFmodelorView *) GetRBFModelorView();

	pview->m_pan = m_fvpan.GetCheck();
	pview->m_rotate = false;
	pview->m_zoom = false;
}

void CFormCommandView::OnRadioZoom() 
{
	// TODO: Add your control notification handler code here
	CRBFmodelorView * pview = (CRBFmodelorView *) GetRBFModelorView();
	
	pview->m_zoom = m_fvzoom.GetCheck();
	pview->m_rotate = false;
	pview->m_pan = false;
}

void CFormCommandView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	CRBFmodelorView * pview = (CRBFmodelorView *) GetRBFModelorView();

	m_fvrot.SetCheck(pview->m_rotate);
	m_fvsurf.SetCheck(pview->m_surf);

	m_fvptsizeslder.SetRange(1,8,TRUE);
	m_fvptsizeslder.SetPageSize(1);
	m_fvptsizeslder.SetPos(1);

	//Three light icon
	RECT r1 = {23,180,58,200};
	m_fvlit_r.Create("",WS_VISIBLE|WS_TABSTOP,r1,this,0);
	m_fvlit_r.SetButtonStyle(BS_PUSHLIKE|BS_FLAT|BS_AUTOCHECKBOX,0);
	m_fvlit_r.SetWindowText("R");
	m_fvlit_r.EnableTarget(0);
	m_fvlit_r.SetIcon(IDI_ICON_RED,BS_LEFT);
	m_fvlit_r.SetCheck(0);
	m_fvlit_r.EnableWindow(1);

	RECT r2 = {70,180,110,200};
	m_fvlit_g.Create("",WS_VISIBLE|WS_TABSTOP,r2,this,0);
	m_fvlit_g.SetButtonStyle(BS_PUSHLIKE|BS_FLAT|BS_AUTOCHECKBOX,0);
	m_fvlit_g.SetWindowText("G");
	m_fvlit_g.EnableTarget(0);
	m_fvlit_g.SetIcon(IDI_ICON_GREEN,BS_LEFT);
	m_fvlit_g.SetCheck(0);
	m_fvlit_g.EnableWindow(1);

	RECT r3 = {114,180,150,200};
	m_fvlit_b.Create("",WS_VISIBLE|WS_TABSTOP,r3,this,0);
	m_fvlit_b.SetButtonStyle(BS_PUSHLIKE|BS_FLAT|BS_AUTOCHECKBOX,0);
	m_fvlit_b.SetWindowText("B");
	m_fvlit_b.EnableTarget(0);
	m_fvlit_b.SetIcon(IDI_ICON_BLUE,BS_LEFT);
	m_fvlit_b.SetCheck(0);
	m_fvlit_b.EnableWindow(1);

}

void CFormCommandView::OnRadioSurf() 
{
	// TODO: Add your control notification handler code here
	CRBFmodelorView * pview = (CRBFmodelorView *) GetRBFModelorView();
	pview->m_surf = m_fvsurf.GetCheck();

	pview->m_vertex = false;
	pview->m_line = false;

	pview->InvalidateRect(NULL,FALSE);

}
void CFormCommandView::OnRadioLine() 
{
	// TODO: Add your control notification handler code here
	CRBFmodelorView * pview = (CRBFmodelorView *) GetRBFModelorView();
	pview->m_line = m_fvline.GetCheck();

	pview->m_surf = false;
	pview->m_vertex = false;
	
	pview->InvalidateRect(NULL,FALSE);
}

void CFormCommandView::OnRadioPoint() 
{
	// TODO: Add your control notification handler code here
	CRBFmodelorView * pview = (CRBFmodelorView *) GetRBFModelorView();
	pview->m_vertex = m_fvvertex.GetCheck();

	pview->m_line = false;
	pview->m_surf = false;

	pview->InvalidateRect(NULL,FALSE);
}

void CFormCommandView::OnCheckShowmode() 
{
	// TODO: Add your control notification handler code here
	CRBFmodelorView * pview = (CRBFmodelorView *) GetRBFModelorView();
	
	if( !m_fvshowmode.GetCheck() )
		pview->shademode = GL_FLAT;
	else
		pview->shademode = GL_SMOOTH;

	pview->InvalidateRect(NULL,FALSE);
	
}

void CFormCommandView::OnCustomdrawSliderPointsize(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CRBFmodelorView * pview = (CRBFmodelorView *) GetRBFModelorView();
	int sldpos = m_fvptsizeslder.GetPos();
	
	pview->m_pointsize = (float)sldpos;
	pview->InvalidateRect(NULL,FALSE);

	*pResult = 0;
}

BOOL CFormCommandView::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	CRBFmodelorView * pview = (CRBFmodelorView *) GetRBFModelorView();
	
	if(m_fvlit_r.GetCheck()){
		pview->m_colortype[0] = 0;
		pview->m_colortype[1] = 5;
		pview->m_colortype[2] = 5;

		m_fvlit_g.SetCheck(0);
		m_fvlit_b.SetCheck(0);
	}
	else if(m_fvlit_g.GetCheck()){
		pview->m_colortype[1] = 1;
		pview->m_colortype[0] = 5;
		pview->m_colortype[2] = 5;

		m_fvlit_r.SetCheck(0);
		m_fvlit_b.SetCheck(0);
	}
	else if(m_fvlit_b.GetCheck()){
		pview->m_colortype[2] = 2;
		pview->m_colortype[0] = 5;
		pview->m_colortype[1] = 5;

		m_fvlit_r.SetCheck(0);
		m_fvlit_g.SetCheck(0);
	}
	else
	{
		pview->m_colortype[2] = 5;
		pview->m_colortype[0] = 5;
		pview->m_colortype[1] = 5;
	}
	pview->InvalidateRect(NULL,FALSE);
	
	return CFormView::OnCommand(wParam, lParam);
}

void CFormCommandView::OnCenbox() 
{
	// TODO: Add your control notification handler code here
	CRBFmodelorView * pview = (CRBFmodelorView *) GetRBFModelorView();
	pview->m_isbox = m_fvbox.GetCheck();
	pview->InvalidateRect(NULL,FALSE);
}

void CFormCommandView::OnCheckAxes() 
{
	// TODO: Add your control notification handler code here
	CRBFmodelorView * pview = (CRBFmodelorView *) GetRBFModelorView();
	pview->m_isaxis = m_fvaxis.GetCheck();
	pview->InvalidateRect(NULL,FALSE);

}

LRESULT CFormCommandView::OnMyMessageMesh(WPARAM wParam, LPARAM lParam)
{
	CRect rect;
	CRBFmodelorDoc *pdoc=(CRBFmodelorDoc*) GetDocument();
	//AfxMessageBox("1",MB_OK,-1);


	return 0;
	
}

⌨️ 快捷键说明

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