📄 mainfrm.cpp
字号:
return (float)sqrt(this->m_fCurLAxis*this->m_fCurLAxis-this->m_fCurSAxis*this->m_fCurSAxis);
}
bool CMainFrame::IsEven(Point p1, Point p2)
{
if(p1.x==p2.x&&p1.y==p2.y&&p1.z==p2.z)
return true;
else
return false;
}
//对于当前的长半轴和短半轴随机生成已经给出的光子数并模拟
/*DWORD WINAPI CMainFrame::SimulateProc()
{
Point pCutPoint; //交点
Point pTempPoint; //临时交点
Line pReflectLine; //反射直线
int nReflectCount; //已反射次数
bool IsDie=false; //光子是否消灭
bool IsSorb=false; //光子是否被吸收
m_CriticalSection.Lock();
//清除最大记录
m_MaxRecord.fGoodRate=0;
m_Rand.SetTimerSeed();
m_nGoodPhotonCount=0;
m_nBadPhotonCount=0;
m_nDeadPhotonCount=0;
m_fFocus=this->GetFocus(this->m_fCurLAxis);
for(int i=1;i<=this->m_nAllPhoton;i++)
{
IsDie=false;
if(m_nObjSort==0)//球面
{
//-----------产生随机光子并发射之--------------
pReflectLine.dPointDirct.dx=(float)m_Rand.DrawRandomNumber();
pReflectLine.dPointDirct.dy=(float)m_Rand.DrawRandomNumber();
pReflectLine.dPointDirct.dz=(float)m_Rand.DrawRandomNumber();
pReflectLine.pPassPoint.x=this->GetSAxis(this->m_fCurLAxis);
pReflectLine.pPassPoint.y=(float)m_Rand.DrawRandomNumber()/100*2*m_fCurSAxis*m_fCurSAxis/m_fCurLAxis-m_fCurSAxis*m_fCurSAxis/m_fCurLAxis;
pReflectLine.pPassPoint.z=(float)m_Rand.DrawRandomNumber()/100*2*m_fCurSAxis*m_fCurSAxis/m_fCurLAxis-m_fCurSAxis*m_fCurSAxis/m_fCurLAxis;
//---------------------------------------------
}
else
{
//-----------产生随机光子并发射之--------------
pReflectLine.dPointDirct.dx=(float)m_Rand.DrawRandomNumber();
pReflectLine.dPointDirct.dy=(float)m_Rand.DrawRandomNumber();
pReflectLine.dPointDirct.dz=(float)m_Rand.DrawRandomNumber();
pReflectLine.pPassPoint.x=(float)m_Rand.DrawRandomNumber()/100*2*this->m_fObjRadius+this->m_fFocus-this->m_fObjRadius;
pReflectLine.pPassPoint.y=(float)m_Rand.DrawRandomNumber()/100*2*this->m_fObjRadius-this->m_fObjRadius;
pReflectLine.pPassPoint.z=(float)m_Rand.DrawRandomNumber()/100*2*this->m_fObjRadius-this->m_fObjRadius;
//---------------------------------------------
}
//-----------------求出交点--------------------
pCutPoint=this->GetCutPoint(pReflectLine,-1);
//---------------------------------------------
pReflectLine.pPassPoint.x=pCutPoint.x;
pReflectLine.pPassPoint.y=pCutPoint.y;
pReflectLine.pPassPoint.z=pCutPoint.z;
//光子在没有被光电管接收或被物体消灭之前不停的在椭球内反射
for(nReflectCount=0;nReflectCount<=this->m_nReflectCount;nReflectCount++)
{
//得出反射直线,反射直线的方程:(x-x1)/x2=(y-y1)/y2=(z-z1)/z2
pReflectLine=this->GetReflectLine(pReflectLine);
pTempPoint=pCutPoint;
//求出反射直线与椭球的交点
pCutPoint=this->GetCutPoint(pReflectLine,1);
if(this->IsEven(pCutPoint,pTempPoint))
pCutPoint=this->GetCutPoint(pReflectLine,-1);
switch(this->IsCutWithPipe(pReflectLine))
{
case -1://不与光电管相交
break;
case 0://光子消灭
IsDie=true;
break;
case 1://光子被光电管接收
IsSorb=true;
m_nGoodPhotonCount+=1;
break;
default:
break;
}
//是否与物体相交
if(this->IsCutWithObj(pReflectLine,m_nObjSort))
IsDie=true;
if(IsDie)
m_nBadPhotonCount+=1;
if(IsDie || IsSorb)
break;
}
}
//--------------------------插入记录-----------------------------------
m_nDeadPhotonCount=m_nAllPhoton-m_nGoodPhotonCount-m_nBadPhotonCount;
m_fGoodRate=(float)this->m_nGoodPhotonCount/this->m_nAllPhoton;
m_fBadRate=(float)this->m_nBadPhotonCount/this->m_nAllPhoton;
m_fDeadRate=(float)this->m_nDeadPhotonCount/this->m_nAllPhoton;
m_Record.fLAxis=this->m_fCurLAxis;
m_Record.fSAxis=this->m_fCurSAxis;
m_Record.nBadPhotonCount=this->m_nBadPhotonCount;
m_Record.nGoodPhotonCount=this->m_nGoodPhotonCount;
m_Record.nDeadPhotonCount=this->m_nDeadPhotonCount;
m_Record.fGoodRate=this->m_fGoodRate;
m_Record.fBadRate=this->m_fBadRate;
m_Record.fDeadRate=this->m_fDeadRate;
InsertRecord(m_Record);
//---------------------------------------------------------------------
//--------------------------记录最佳效果-------------------------------
if(m_fGoodRate>m_MaxRecord.fGoodRate)
{
m_MaxRecord.fLAxis=this->m_fCurLAxis;
m_MaxRecord.fSAxis=this->m_fCurSAxis;
m_MaxRecord.nIndex=this->m_pList->GetItemCount();
m_MaxRecord.nGoodPhotonCount=this->m_nGoodPhotonCount;
m_MaxRecord.fGoodRate=this->m_fGoodRate;
m_MaxRecord.fBadRate=this->m_fBadRate;
m_MaxRecord.fDeadRate=this->m_fDeadRate;
m_MaxRecord.nBadPhotonCount=this->m_nBadPhotonCount;
m_MaxRecord.nDeadPhotonCount=this->m_nDeadPhotonCount;
m_MaxRecord.nGoodPhotonCount=this->m_nGoodPhotonCount;
}
//--------------------------------------------------------------------
m_CriticalSection.Unlock();
//线程计数器减一
m_CriticalSection.Lock();
m_nCurThreadNum--;
m_CriticalSection.Unlock();
return 0;
}*/
bool CMainFrame::IsCutWithObj(Line l0,int nObjSort)
{
float cx0=0,cy0=0,cz0=0,dx0=0,dy0=0,dz0=0; //已知直线:(x-cx0)/dx0=(y-cy0)/dy0=(z-cz0)/dz0=k
float r,c;//物体:(x-c)^2+y^2+z^2=r^2;
float m,n,p;
r=this->m_fObjRadius;
c=this->m_fFocus;
if(nObjSort==0)//球面
{
m=dy0*dy0+dz0*dz0;
n=dy0*cy0+dz0*cz0;
p=cy0*cy0+cz0*cz0-r*r;
if(m*n-p*p<0)
return false;
else
return true;
}
cx0=l0.pPassPoint.x;
cy0=l0.pPassPoint.y;
cz0=l0.pPassPoint.z;
dx0=l0.dPointDirct.dx;
dy0=l0.dPointDirct.dy;
dz0=l0.dPointDirct.dz;
m=dx0*dx0+dy0*dy0+dz0*dz0;
n=(cx0-c)*dx0+cy0*dy0+cz0*dz0;
p=(cx0-c)*(cx0-c)+cy0*cy0+cz0*cz0-r*r;
if(n*n-m*p<0)
return false;
else
return true;
}
//返回-1表示不与光电管相交,返回0表示光子消灭,返回1表示光子被光电管接收
int CMainFrame::IsCutWithPipe(Line l0)
{
float cx0,cy0,cz0,dx0,dy0,dz0; //已知直线:(x-cx0)/dx0=(y-cy0)/dy0=(z-cz0)/dz0=k
float a,c;//光电倍增管方程:y*y+z*z=1.41*1.41 -a<=x<=-c
float cx1,cx2;
a=this->m_fCurLAxis;
c=this->m_fFocus;
cx0=l0.pPassPoint.x;
cy0=l0.pPassPoint.y;
cz0=l0.pPassPoint.z;
dx0=l0.dPointDirct.dx;
dy0=l0.dPointDirct.dy;
dz0=l0.dPointDirct.dz;
float m,n,p,k1,k2;
m=dy0*dy0+dz0*dz0;
n=dy0*cy0+dz0*cz0;
p=(float)(cy0*cy0+cz0*cz0-1.41*1.41);
if(n*n-m*p<0)
return -1;
//-------------与形式管有交点----------------
//形式管是光电管的延伸
k1=(float)(-n+sqrt(n*n-m*p))/m;
k2=(float)(-n-sqrt(n*n-m*p))/m;
cx1=dx0*k1+cx0;
cx2=dx0*k2+cx0;
if(cx0<-c)//此时光子不可能被光电管接收
{
if(cx1>-c && cx2>-c)
return -1;
else
return 0;
}
else
{
if(cx1>-c && cx2>-c)
return -1;
else
{
/// if(cx1<-c && cx2<-c)
// return 0;
// else
// return 1;
if((cx1+c)*(cx2+c)<=0)
return 1;
else
return 0;
}
}
//-----------------------------------------
}
CSimulateView* CMainFrame::SearchViewByIndex(int nIndex,bool bIsSimulate)
{
//正在模拟
if(bIsSimulate)
return m_pSimulateViewListHead->pTail->pSimulateView;
SimulateViewList* p;
p=this->m_pSimulateViewListHead;
while(p)
{
if(nIndex==p->nIndex)
return p->pSimulateView;
else
p=p->pNext;
}
return NULL;
}
void CMainFrame::AnalyseData()
{
SimulateViewList* p;
CSimulateView* q;
p=this->m_pSimulateViewListHead->pNext;
while(p)
{
q=p->pSimulateView;
q->m_rMaxRecord=p->rMaxRecord;
q->AnalyseData(m_fError,m_pAnalyseView);
p=p->pNext;
}
}
void CMainFrame::OnHideoutbar()
{
// TODO: Add your command handler code here
m_wndOutputBar.ShowWindow(false);
RecalcLayout();
}
void CMainFrame::OnClearedit()
{
// TODO: Add your command handler code here
m_wndOutputBar.SetEditText(m_wndOutputBar.m_FlatTabCtrl.GetCurSel(),"");
}
void CMainFrame::OnOutputbar()
{
// TODO: Add your command handler code here
CCmdUI* pCmdUI;
m_wndOutputBar.ShowWindow(!m_wndOutputBar.IsWindowVisible());
// pCmdUI->SetCheck(!m_wndOutputBar.IsWindowVisible());
RecalcLayout();
}
void CMainFrame::OnWorkspacebar()
{
// TODO: Add your command handler code here
CCmdUI* pCmdUI;
m_wndWorkSpaceBar.ShowWindow(!m_wndWorkSpaceBar.IsWindowVisible());
// pCmdUI->SetCheck(!m_wndOutputBar.IsWindowVisible());
RecalcLayout();
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
int ans=MessageBox("你真的要退出吗?","退出系统",MB_ICONQUESTION | MB_YESNO);
if(ans==IDYES)
{
//注销热键
UnregisterHotKey(m_hWnd,0XB4EE);
//动画消失
// AnimateWindow(GetSafeHwnd(),2000,AW_CENTER|AW_HIDE);
//保存可变栏状态
m_wndStatusBar.StopRun();
this->OnStop();
CFrameWnd::OnClose();
}
else
return;
}
LRESULT CMainFrame::OnTrayNotification(WPARAM wParam, LPARAM lParam)
{
UINT uMouseMsg;//鼠标动作
uMouseMsg=(UINT) lParam;
if(uMouseMsg==WM_LBUTTONDOWN)//如果是单击左键
{
if(m_bShow)
{
PostMessage(WM_SYSCOMMAND,SC_MINIMIZE,NULL);
}
else
{
PostMessage(WM_SYSCOMMAND,SC_RESTORE,NULL);
}
}
if(uMouseMsg==WM_RBUTTONDOWN)//如果是单击右键
{
AfxGetMainWnd()->SetForegroundWindow(); //弹出Popup菜单
CMenu menu;
menu.LoadMenu(IDR_MENU_TRAY);
CMenu* pPopup=menu.GetSubMenu(0);
CPoint Point;
GetCursorPos(&Point);
pPopup->TrackPopupMenu(TPM_LEFTALIGN,
Point.x,Point.y,AfxGetMainWnd(),NULL );
AfxGetMainWnd()->PostMessage(WM_NULL, 0, 0);
}
return 1;
}
void CMainFrame::OnMain()
{
// TODO: Add your command handler code here
ShowWindow(SW_RESTORE);
}
void CMainFrame::OnHide()
{
// TODO: Add your command handler code here
ShowWindow(false);
}
void CMainFrame::OnAppExit()
{
// TODO: Add your command handler code here
OnClose();
}
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if(nID==SC_MINIMIZE)
{
CFrameWnd::OnSysCommand(nID, lParam);
m_bShow=false;
AfxGetMainWnd()->ShowWindow(SW_HIDE);//隐藏窗口
}
else
if(nID==SC_CLOSE)
{
PostMessage(WM_SYSCOMMAND,SC_MINIMIZE,NULL);
}
else
if(nID==SC_RESTORE)
{
AfxGetMainWnd()->ShowWindow(SW_SHOW);//显示窗口
CFrameWnd::OnSysCommand(nID, lParam);
m_bShow=true;
}
else
if(nID==SC_MAXIMIZE){;}
else
{
CFrameWnd::OnSysCommand(nID, lParam);
}
}
LRESULT CMainFrame::OnHotKey(WPARAM wParam,LPARAM lParam)
{
if(wParam==0XB4EE)
{
this->ShowWindow(SW_SHOW);
this->SetForegroundWindow();
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -