www.pudn.com > OpenGL实现三维绘图.rar > ControlWnd.cpp
// ControlWnd.cpp : implementation file
//
#include "stdafx.h"
#include "Test1.h"
#include "ControlWnd.h"
#include "ProjectView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CControlWnd
IMPLEMENT_DYNCREATE(CControlWnd, CFormView)
extern GLfloat xrof,yrof,zrof;
extern bool gbDataIsEmpty;
CControlWnd::CControlWnd()
: CFormView(CControlWnd::IDD)
{
//{{AFX_DATA_INIT(CControlWnd)
m_nxZoom = 60;
m_nyZoom = 5;
m_nzZoom = 10;
m_nMaxrange = 0.0f;
m_nMinrange = 0.0f;
//}}AFX_DATA_INIT
m_bShowCoordinate = true;
this->m_bShowConsult = true;
m_bXpWnd = false;
pWnd = NULL;
}
CControlWnd::~CControlWnd()
{
if (pWnd)
{
delete pWnd;
pWnd = NULL;
}
}
void CControlWnd::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CControlWnd)
DDX_Control(pDX, IDC_ZOOMBACK, m_ZoomBack);
DDX_Control(pDX, IDC_ZOOMDEL, m_ZoomDel);
DDX_Control(pDX, IDC_ZOOMADD, m_ZoomAdd);
DDX_Control(pDX, IDC_SHOWTPWND, m_ShowXpWnd);
DDX_Control(pDX, IDC_SHOWDATAWND, m_ShowDataWnd);
DDX_Control(pDX, IDC_MINRANGE, m_Minrange);
DDX_Control(pDX, IDC_MAXRANGE, m_Maxrange);
DDX_Control(pDX, IDC_CLEAR_DATA, m_Clearbtn);
DDX_Control(pDX, IDC_VIEWPIC, m_Viewpicbtn);
DDX_Control(pDX, IDC_SETDEFAULT, m_SetDefaultbtn);
DDX_Control(pDX, IDC_GETDATA, m_GetDatabtn);
DDX_Control(pDX, IDC_PICVALUE, m_PicValue);
DDX_Control(pDX, IDC_ALLVALUE, m_AllValue);
DDX_Control(pDX, IDC_ZZOOM, m_zZoom);
DDX_Control(pDX, IDC_YZOOM, m_yZoom);
DDX_Control(pDX, IDC_XZOOM, m_xZoom);
DDX_Text(pDX, IDC_XZOOM, m_nxZoom);
DDX_Text(pDX, IDC_YZOOM, m_nyZoom);
DDX_Text(pDX, IDC_ZZOOM, m_nzZoom);
DDX_Text(pDX, IDC_MAXRANGE, m_nMaxrange);
DDX_Text(pDX, IDC_MINRANGE, m_nMinrange);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CControlWnd, CFormView)
//{{AFX_MSG_MAP(CControlWnd)
ON_BN_CLICKED(IDC_VIEWPIC, OnViewpic)
ON_LBN_DBLCLK(IDC_ALLVALUE, OnDblclkAllvalue)
ON_LBN_DBLCLK(IDC_PICVALUE, OnDblclkPicvalue)
ON_BN_CLICKED(IDC_SETDEFAULT, OnSetdefault)
ON_BN_CLICKED(IDC_RADIOTURN, OnRadioturn)
ON_BN_CLICKED(IDC_RADIOSELECT, OnRadioselect)
ON_BN_CLICKED(IDC_GETDATA, OnGetdata)
ON_BN_CLICKED(IDC_CLEAR_DATA, OnClearData)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_SHOWDATAWND, OnShowdatawnd)
ON_BN_CLICKED(IDC_CHECKCONSULT, OnCheckconsult)
ON_BN_CLICKED(IDC_CHECKCOOLDINATE, OnCheckcooldinate)
ON_BN_CLICKED(IDC_RADIOTURNX, OnRadioturnx)
ON_BN_CLICKED(IDC_RADIOTURNY, OnRadioturny)
ON_BN_CLICKED(IDC_RADIOTURNZ, OnRadioturnz)
ON_BN_CLICKED(IDC_SHOWTPWND, OnShowTpWnd)
ON_BN_CLICKED(IDC_ZOOMADD, OnZoomAdd)
ON_BN_CLICKED(IDC_ZOOMDEL, OnZoomdel)
ON_BN_CLICKED(IDC_ZOOMBACK, OnZoomback)
ON_BN_CLICKED(IDC_CHECKLIGHTING, OnChecklighting)
//}}AFX_MSG_MAP
ON_MESSAGE(MESSAGE_ENABLEBTN,EnableButton)
ON_MESSAGE(MESSAGE_DISABLEBTN, DisableButton)
ON_MESSAGE(MESSAGE_GETDATAFINISHED,GetData)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CControlWnd diagnostics
#ifdef _DEBUG
void CControlWnd::AssertValid() const
{
CFormView::AssertValid();
}
void CControlWnd::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CControlWnd message handlers
void CControlWnd::OnViewpic()
{
if(::gbDataIsEmpty)
{
MessageBox("当前没有任何数据,请重新加载数据!","提示信息",MB_ICONINFORMATION);
return;
}
int nCount = this->m_PicValue.GetCount();
if (nCount<3)
{
MessageBox("请选中三个数据进行交会成像","提示信息",MB_ICONINFORMATION);
return;
}
CString Name = "";
this->m_PicValue.GetText(0,Name);
m_pFr->m_pView->m_First = GetPicData(Name);
this->m_PicValue.GetText(1,Name);
m_pFr->m_pView->m_Second = GetPicData(Name);
this->m_PicValue.GetText(2,Name);
m_pFr->m_pView->m_Third = GetPicData(Name);
CString Angle;
this->m_xZoom.GetWindowText(Angle);
m_pFr->m_pView->m_Prox = atoi(Angle);
this->m_yZoom.GetWindowText(Angle);
m_pFr->m_pView->m_Proy = atoi(Angle);
this->m_zZoom.GetWindowText(Angle);
m_pFr->m_pView->m_Proz = atoi(Angle);
this->m_Minrange.GetWindowText(Angle);
m_pFr->m_pView->m_nMinDepth = atof(Angle);
this->m_Maxrange.GetWindowText(Angle);
m_pFr->m_pView->m_nMaxDepth = atof(Angle);
m_pFr->InvalidateAllWnd();
}
void CControlWnd::FillListBox()
{
int nCount = m_AllValue.GetCount();
for (int n=0; nm_AllValue.InsertString(0,"ild");
this->m_AllValue.InsertString(1,"ilm");
this->m_AllValue.InsertString(2,"ll8");
this->m_AllValue.InsertString(3,"lld");
this->m_AllValue.InsertString(4,"lls");
this->m_AllValue.InsertString(5,"rmll");
this->m_AllValue.InsertString(6,"ml1");
this->m_AllValue.InsertString(7,"ml2");
this->m_AllValue.InsertString(8,"r04");
this->m_AllValue.InsertString(9,"r4");
this->m_AllValue.InsertString(10,"r25");
this->m_AllValue.InsertString(11,"gr");
nCount = this->m_PicValue.GetCount();
for (n=0; nm_PicValue.InsertString(0,"声波");
this->m_PicValue.InsertString(1,"中子");
this->m_PicValue.InsertString(2,"密度");
}
void CControlWnd::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
this->m_pFr = (CMainFrame*)AfxGetApp()->m_pMainWnd;
/* m_pDataWnd = new CPicDataWnd;
m_pDataWnd->Create(IDD_PICDATADLG,this);
m_pDataWnd->ShowWindow(SW_HIDE);*/
this->FillListBox();
CButton* btn = (CButton*)GetDlgItem(IDC_RADIOTURN);
btn->SetCheck(1);
btn = (CButton*)GetDlgItem(IDC_CHECKCONSULT);
btn->SetCheck(1);
btn = (CButton*)GetDlgItem(IDC_CHECKCOOLDINATE);
btn->SetCheck(1);
btn = (CButton*)GetDlgItem(IDC_RADIOTURNX);
btn->SetCheck(1);
this->m_SetDefaultbtn.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
this->m_GetDatabtn.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
this->m_Viewpicbtn.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
this->m_Clearbtn.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
this->m_ShowDataWnd.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
m_ShowXpWnd.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
m_ZoomAdd.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
m_ZoomDel.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
m_ZoomBack.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
GLfloat MaxDepth = m_pFr->m_pView->GetMaxDepth();
}
void CControlWnd::OnDblclkAllvalue()
{
int index = this->m_AllValue.GetCurSel();
int nCount = this->m_PicValue.GetCount();
if (nCount>=3)
return;
CString name;
this->m_AllValue.GetText(index,name);
this->m_PicValue.InsertString(0,name);
this->m_AllValue.DeleteString(index);
}
void CControlWnd::OnDblclkPicvalue()
{
int index = this->m_PicValue.GetCurSel();
CString name;
this->m_PicValue.GetText(index,name);
this->m_AllValue.InsertString(0,name);
this->m_PicValue.DeleteString(index);
}
int CControlWnd::GetPicData(CString Name)
{
int nArrayValue = 0;
if (Name == "声波")
nArrayValue = 1;
else if (Name == "中子")
nArrayValue = 2;
else if (Name == "密度")
nArrayValue = 3;
else if (Name == "ild")
nArrayValue = 4;
else if (Name == "ilm")
nArrayValue = 5;
else if (Name == "ll8")
nArrayValue = 6;
else if (Name == "lld")
nArrayValue = 7;
else if (Name == "lls")
nArrayValue = 8;
else if (Name == "rmll")
nArrayValue = 9;
else if (Name == "ml1")
nArrayValue = 10;
else if (Name == "ml2")
nArrayValue = 11;
else if (Name == "r04")
nArrayValue = 12;
else if (Name == "r4")
nArrayValue = 13;
else if (Name == "r25")
nArrayValue = 14;
else if (Name == "gr")
nArrayValue = 15;
return nArrayValue;
}
void CControlWnd::OnSetdefault()
{
if(::gbDataIsEmpty)
{
MessageBox("当前没有任何数据,请重新加载数据!","提示信息",MB_ICONINFORMATION);
return;
}
xrof = 0;
yrof = 0;
zrof = 0;
m_pFr->m_pView->m_Prox = 60;
m_pFr->m_pView->m_Proy = 5;
m_pFr->m_pView->m_Proz = 10;
m_pFr->m_pView->m_First = 1;
m_pFr->m_pView->m_Second = 2;
m_pFr->m_pView->m_Third = 3;
m_pFr->m_pView->m_Zoom = 0;
this->m_xZoom.SetWindowText("60");
this->m_yZoom.SetWindowText("5");
this->m_zZoom.SetWindowText("10");
this->GetData(0,0);
this->FillListBox();
this->m_pFr->InvalidateAllWnd();
}
void CControlWnd::OnRadioturn()
{
this->m_pFr->m_pView->m_bIsMove = true;
this->m_pFr->m_pView->Invalidate();
}
void CControlWnd::OnRadioselect()
{
this->m_pFr->m_pView->m_bIsMove = false;
this->m_pFr->m_pView->Invalidate();
}
void CControlWnd::OnGetdata()
{
CFileDialog dlg(TRUE,_T("3DSF"),_T("*.3DSF"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,_T("三维交会图数据(*.3DSF)|*.3DSF|"));
if (IDCANCEL == dlg.DoModal())
return;
CString FilePath = dlg.GetPathName();
m_pFr->m_pView->m_FileName = FilePath;
AfxBeginThread(CTest1View::ReadFile,m_pFr->m_pView);
CString Wtext = "三维交会图演示系统,当前加载文件->";
Wtext += FilePath;
AfxGetMainWnd()->SetWindowText(Wtext);
}
void CControlWnd::OnClearData()
{
if(::gbDataIsEmpty)
{
MessageBox("当前没有任何数据,请重新加载数据!","提示信息",MB_ICONINFORMATION);
return;
}
this->m_pFr->m_pView->ZeroArray();
::gbDataIsEmpty = true;
this->m_pFr->InvalidateAllWnd();//Invalidate();
AfxGetMainWnd()->SetWindowText("三维交会图演示系统->没有任何数据");
}
void CControlWnd::EnableButton(LPARAM lp,WPARAM wp)
{
this->m_Clearbtn.EnableWindow(TRUE);
this->m_GetDatabtn.EnableWindow();
this->m_SetDefaultbtn.EnableWindow();
this->m_Viewpicbtn.EnableWindow();
}
void CControlWnd::DisableButton(LPARAM lp, WPARAM wp)
{
this->m_Clearbtn.EnableWindow(FALSE);
this->m_GetDatabtn.EnableWindow(FALSE);
this->m_SetDefaultbtn.EnableWindow(FALSE);
this->m_Viewpicbtn.EnableWindow(FALSE);
}
HBRUSH CControlWnd::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
/* if ( nCtlColor == CTLCOLOR_EDIT
||nCtlColor == CTLCOLOR_LISTBOX
|| nCtlColor == CTLCOLOR_STATIC )
{
pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkMode(1);
}*/
return hbr;
}
void CControlWnd::OnShowdatawnd()
{
this->m_pFr->SendMessage(WM_CLOSE);
}
void CControlWnd::GetData(LPARAM lp, WPARAM wp)
{
GLfloat Max = this->m_pFr->m_pView->m_nMaxDepth = this->m_pFr->m_pView->GetMaxDepth();
GLfloat Min = this->m_pFr->m_pView->m_nMinDepth = this->m_pFr->m_pView->GetMinDepth();
CString str;
str.Format("%f",Max);
this->m_Maxrange.SetWindowText(str);
str.Format("%f",Min);
this->m_Minrange.SetWindowText(str);
this->m_pFr->InvalidateAllWnd();
}
void CControlWnd::OnCheckconsult()
{
this->m_bShowConsult = !m_bShowConsult;
this->m_pFr->m_pView->Invalidate();
}
void CControlWnd::OnCheckcooldinate()
{
this->m_bShowCoordinate = !m_bShowCoordinate;
this->m_pFr->m_pView->Invalidate();
}
void CControlWnd::OnRadioturnx()
{
this->m_pFr->m_pView->nWithy = 0;
}
void CControlWnd::OnRadioturny()
{
this->m_pFr->m_pView->nWithy = 1;
}
void CControlWnd::OnRadioturnz()
{
this->m_pFr->m_pView->nWithy = 2;
}
void CControlWnd::OnShowTpWnd()
{
if(!m_bXpWnd)
{
if (pWnd)
{
delete pWnd;
pWnd = NULL;
}
GetDlgItem(IDC_SHOWTPWND)->SetWindowText("取消");
m_bXpWnd = true;
pWnd = new CXTPWnd;
pWnd->XCreate("交会图外挂放大镜");
}
else
{
GetDlgItem(IDC_SHOWTPWND)->SetWindowText("放大镜");
m_bXpWnd = false;
pWnd->DestroyWindow();
}
}
void CControlWnd::OnZoomAdd()
{
if (this->m_pFr->m_pView->m_Zoom <3)
{
this->m_pFr->m_pView->m_Zoom ++;
this->m_pFr->m_pView->Invalidate();
}
}
void CControlWnd::OnZoomdel()
{
if (this->m_pFr->m_pView->m_Zoom > 0)
{
this->m_pFr->m_pView->m_Zoom--;
this->m_pFr->m_pView->Invalidate();
}
}
void CControlWnd::OnZoomback()
{
this->m_pFr->m_pView->m_Zoom = 0;
this->m_pFr->m_pView->Invalidate();
}
void CControlWnd::OnChecklighting()
{
this->m_pFr->m_pView->m_bLighting = !this->m_pFr->m_pView->m_bLighting;
this->m_pFr->m_pView->Invalidate();
}