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

📄 simulateview.cpp

📁 运用扫描法求设计一个最佳比例的聚光腔
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SimulateView.cpp : implementation of the CSimulateView class
//

#include "stdafx.h"
#include "Simulate.h"

#include "SimulateDoc.h"
#include "SimulateView.h"
#include "math.h"
#include "MainFrm.h"
#include "PropertyDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSimulateView
int CALLBACK ListCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);

IMPLEMENT_DYNCREATE(CSimulateView, CListView)

BEGIN_MESSAGE_MAP(CSimulateView, CListView)
	//{{AFX_MSG_MAP(CSimulateView)
	ON_COMMAND(IDM_CLEAR, OnClear)
	ON_COMMAND(IDM_DELETE, OnDelete)
	ON_COMMAND(IDM_ANALYSE, OnAnalyse)
	ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
	ON_COMMAND(IDM_HELP, OnHelp)
	ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
	ON_NOTIFY_REFLECT(LVN_KEYDOWN, OnKeydown)
	ON_WM_CREATE()
	ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
	ON_COMMAND(IDM_PROPERTY, OnProperty)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSimulateView construction/destruction
SetParam strAllData[65535];

CSimulateView::CSimulateView()
{
	// TODO: add construction code here
	m_pList=(CSortListCtrl*)&this->GetListCtrl();

	//传递指针给视图链表
//	this->SetDefaultViewPointer();
}

CSimulateView::~CSimulateView()
{
}

BOOL CSimulateView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CListView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSimulateView drawing

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


/////////////////////////////////////////////////////////////////////////////
// CSimulateView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CSimulateView diagnostics

#ifdef _DEBUG
void CSimulateView::AssertValid() const
{
	CListView::AssertValid();
}

void CSimulateView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}


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

/////////////////////////////////////////////////////////////////////////////
// CSimulateView message handlers

void CSimulateView::OnClear() 
{
	// TODO: Add your command handler code here
	this->m_pList->DeleteAllItems();
}

void CSimulateView::OnDelete() 
{
	// TODO: Add your command handler code here
	if (m_nCurSel != NULL)
	{
		int nIndex = (int)m_nCurSel - 1;
		m_pList->SetItemData(nIndex, (DWORD)0);
		m_pList->DeleteItem(nIndex);
		m_nCurSel--;
		if (0 == m_pList->GetItemCount())
		{
			return;
		}
		if ((int)m_nCurSel <= 0)
			m_nCurSel = (POSITION)1;
	}
}

void CSimulateView::InsertRecord(Record m_Record)
{
	this->m_strLAxis.Format("%f",m_Record.fLAxis);
	this->m_strSAxis.Format("%f",m_Record.fSAxis);
	this->m_strGoodPhotonCount.Format("%d",m_Record.nGoodPhotonCount);
	this->m_strBadPhotonCount.Format("%d",m_Record.nBadPhotonCount);
	this->m_strDeadPhotonCount.Format("%d",m_Record.nDeadPhotonCount);

 	this->m_strGoodRate.Format("%f",m_Record.fGoodRate*100);
	this->m_strGoodRate=this->m_strGoodRate+"%";

	this->m_strBadRate.Format("%f",m_Record.fBadRate*100);
	this->m_strBadRate=this->m_strBadRate+"%";

	this->m_strDeadRate.Format("%f",m_Record.fDeadRate*100);
	this->m_strDeadRate=this->m_strDeadRate+"%";


	m_nIndex=this->m_pList->GetItemCount();
	
	m_strIndex.Format("%d",m_nIndex+1);

	this->m_pList->InsertItem(m_nIndex,m_strIndex);
	this->m_pList->SetItemText(m_nIndex,1,m_strLAxis);
	this->m_pList->SetItemText(m_nIndex,2,m_strSAxis);
	this->m_pList->SetItemText(m_nIndex,3,m_strGoodPhotonCount);
	this->m_pList->SetItemText(m_nIndex,4,m_strGoodRate);

	this->m_pList->SetItemText(m_nIndex,5,m_strBadPhotonCount);
	this->m_pList->SetItemText(m_nIndex,6,m_strBadRate);

	this->m_pList->SetItemText(m_nIndex,7,m_strDeadPhotonCount);
	this->m_pList->SetItemText(m_nIndex,8,m_strDeadRate);

	//列表条目下移
	m_pList->PostMessage(WM_VSCROLL, SB_BOTTOM, 0);
}

void CSimulateView::OnAnalyse() 
{
	// TODO: Add your command handler code here
	CAnalyseDlg dlg;
//	dlg.Display(this->m_rMaxRecord,this->m_SetParam);
	dlg.DoModal();
}



void CSimulateView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	POINT point;
	GetCursorPos(&point);
	CMenu menu;

	VERIFY(menu.LoadMenu(IDR_POPUPMENU));

	CMenu* pPopup = menu.GetSubMenu(0);
	ASSERT(pPopup != NULL);
	CWnd* pWndPopupOwner = this;

	while (pWndPopupOwner->GetStyle() & WS_CHILD)
		pWndPopupOwner = pWndPopupOwner->GetParent();

	pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,pWndPopupOwner);

	*pResult = 0;
}


void CSimulateView::OnHelp() 
{
	// TODO: Add your command handler code here
	CHelpDlg dlg;
	dlg.DoModal();
}

void CSimulateView::OnClick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	POSITION pos = m_pList->GetFirstSelectedItemPosition();
	do
	{
		if (NULL == pos)
			break;
		if (m_nCurSel == pos)
			break;
		m_nCurSel = pos;
		OnSelectionChanged();		
	}
	while (FALSE);	

	*pResult = 0;
}

void CSimulateView::OnKeydown(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here
	switch(pLVKeyDow->wVKey)
	{
	case VK_UP:
		if ((int)m_nCurSel == 0)
			return;
		m_nCurSel--;
		break;
	case VK_DOWN:
		m_nCurSel++;
		break;
	case VK_PRIOR:
		m_nCurSel -= m_pList->GetCountPerPage();
		break;
	case VK_NEXT:
		m_nCurSel += m_pList->GetCountPerPage();
		break;
	case VK_DELETE:
		OnDelete();
	default:
		return;
	}

	if ((int)m_nCurSel <= 0)
		m_nCurSel = (POSITION)1;

	if ((int)m_nCurSel > m_pList->GetItemCount())
		m_nCurSel = (POSITION)m_pList->GetItemCount();

	*pResult = 0;
}


int CSimulateView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CListView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	m_pList->ModifyStyle(NULL, LVS_REPORT);

	m_pList->InsertColumn(0,"序号",LVCFMT_LEFT,85,-1);
	m_pList->InsertColumn(1,"长半轴",LVCFMT_LEFT,85,-1);
	m_pList->InsertColumn(2,"短半轴",LVCFMT_LEFT,85,-1);

	m_pList->InsertColumn(3,"好光子数",LVCFMT_LEFT,85,-1);
	m_pList->InsertColumn(4,"好光子率",LVCFMT_LEFT,85,-1);

	m_pList->InsertColumn(5,"坏光子数",LVCFMT_LEFT,85,-1);
	m_pList->InsertColumn(6,"坏光子率",LVCFMT_LEFT,85,-1);

	m_pList->InsertColumn(7,"死光子数",LVCFMT_LEFT,85,-1);
	m_pList->InsertColumn(8,"死光子率",LVCFMT_LEFT,85,-1);

	m_pList->SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);

	return 0;
}

int CALLBACK ListCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	CSortListCtrl* pV=(CSortListCtrl*)lParamSort;
	SetParam* pInfo1=strAllData+lParam1;
	SetParam* pInfo2=strAllData+lParam2;
	CString szComp1,szComp2;
	int iCompRes;
	switch(pV->m_nSortedCol)
	{
	case(0):
		szComp1=pInfo1->fLAxisAdd;
		szComp2=pInfo2->fLAxisAdd;
		iCompRes=szComp1.Compare(szComp2);
		break;
	case(1):
		if(pInfo1->fLAxisFrom== pInfo2->fLAxisFrom)
			iCompRes = 0;
		else
			iCompRes=(pInfo1->fLAxisFrom < pInfo2->fLAxisFrom)?-1:1;
		break;
	default:
		ASSERT(0);
		break;
	}
	//根据当前的排序方式进行调整
	if(pV->m_fAsc)
		return iCompRes;
	else
		return iCompRes*-1;
}

BOOL CSimulateView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CListView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}


void CSimulateView::OnSelectionChanged()
{
	CString str;

	CString strIndex;           //序号
	CString strLAxis;           //长半轴
	CString strSAxis;           //短半轴
	CString strGoodPhotonCount; //好光子数
	CString strBadPhotonCount;  //坏光子数
	CString strDeadPhotonCount; //死光子数
	CString strGoodRate;        //光子吸收率
	CString strBadRate;         //坏光子率
	CString strDeadRate;        //死光子率

	strIndex=m_pList->GetItemText((int)m_nCurSel - 1,0);
	strLAxis=m_pList->GetItemText((int)m_nCurSel - 1,1);
	strSAxis=m_pList->GetItemText((int)m_nCurSel - 1,2);

	strGoodPhotonCount=m_pList->GetItemText((int)m_nCurSel - 1,3);
	strBadPhotonCount=m_pList->GetItemText((int)m_nCurSel - 1,4);
	strDeadPhotonCount=m_pList->GetItemText((int)m_nCurSel - 1,5);

	strGoodRate=m_pList->GetItemText((int)m_nCurSel - 1,6);
	strBadRate=m_pList->GetItemText((int)m_nCurSel - 1,7);
	strDeadRate=m_pList->GetItemText((int)m_nCurSel - 1,8);

/*	str="序号: "+strNum+"\r\n"
		"时间: "+time+"\r\n"
		"长度: "+len+"\r\n"
		"协议: "+proto+"\r\n"
		"源地址: "+srcip+"\r\n"
		"目的地址: "+dstip+"\r\n"
		"源端口: "+srcport+"\r\n"
		"目的端口: "+dstport+"\r\n"
		"是否合法: "+legal+"\r\n"
		"数据: "+data;*/
	str="                                        -------------------------------该记录属性-------------------------------\r\n"
		"                                                               序号:       "+strIndex+"\r\n"
		"                                                               长半轴:     "+strLAxis+"\r\n"
		"                                                               短半轴:     "+strSAxis+"\r\n"
		"                                                               好光子数    "+strGoodPhotonCount+"\r\n"
		"                                                               坏光子数:   "+strBadPhotonCount+"\r\n"
		"                                                               死光子数:   "+strDeadPhotonCount+"\r\n"
		"                                                               好光子率:   "+strGoodRate+"\r\n"
		"                                                               坏光子率:   "+strBadRate+"\r\n"
		"                                                               死光子率:   "+strDeadRate;

	m_pMainFrame=(CMainFrame*)::AfxGetApp()->m_pMainWnd;

	m_pMainFrame->m_wndOutputBar.SetEditText(0,str);
}

void CSimulateView::SetDefaultViewPointer()
{
//	m_pMainFrame=(CMainFrame*)::AfxGetApp()->m_pMainWnd;
	m_pMainFrame=(CMainFrame*)::AfxGetMainWnd();

	if(!m_pMainFrame->m_pSimulateViewList->pSimulateView)
	{
		this->m_pMainFrame->m_pSimulateViewList->pSimulateView=this;
		this->m_pMainFrame->m_pSimulateViewListHead->pSimulateView=this;
		this->m_pMainFrame->m_pSimulateViewList->nIndex=0;
	}
}

void CSimulateView::OnInitialUpdate() 
{
	CListView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	//设置列表控件的风格
	m_pList->SetExtendedStyle(LVS_EX_FLATSB | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES //| LVS_EX_TRACKSELECT
							 | LVS_EX_HEADERDRAGDROP | LVS_EX_INFOTIP
							 | LVS_EX_UNDERLINEHOT | LVS_EX_MULTIWORKAREAS);
}


void CSimulateView::SingleSimulate(SetParam sp)
{
	//-------------传递参数--------------------
	m_SetParam=sp;

	m_fLAxisAdd=m_SetParam.fLAxisAdd;
	m_fLAxisFrom=m_SetParam.fLAxisFrom;
	m_fObjRadius=m_SetParam.fObjRadius;
	m_fSAxisAdd=m_SetParam.fSAxisAdd;
	m_fSAxisFrom=m_SetParam.fSAxisFrom;
	m_fShineIntensity=m_SetParam.fShineIntensity;
	m_nAllPhoton=m_SetParam.nAllPhoton;
	m_nReflectCount=m_SetParam.nReflectCount;
	m_nObjSort=m_SetParam.nObjSort;
	//-----------------------------------------

	this->SingleSimulateProc();
//	m_bStop =false;
/*	DWORD dwThreadID;
	DWORD (WINAPI CSimulateView:: *p1)() =SingleSimulateProc;
	DWORD (WINAPI *p2)(LPVOID) = NULL;		
	memcpy(&p2, &p1, sizeof(p1));
	// Be sure to pass "this" parameter to the thread procedure.
	m_hThread = ::CreateThread(NULL, 0, p2, this, 0, &dwThreadID);
	if(m_hThread == NULL)
	{
		MessageBox("创建线程时出现错误!","嗅探",MB_ICONINFORMATION);
		return;	
	}*/

	//依次模拟长短半轴
/*	for(m_fCurLAxis=m_fLAxisFrom;m_fCurLAxis<=80;m_fCurLAxis+=m_fLAxisAdd)
		for(m_fCurSAxis=Max(m_fSAxisFrom,(float)sqrt(2*m_fCurLAxis*m_fObjRadius-m_fObjRadius*m_fObjRadius));m_fCurSAxis<m_fCurLAxis;m_fCurSAxis+=m_fSAxisAdd)
		{					
			//判断当前线程数是否超过最大线程数,是则空循环
			while(m_nCurThreadNum >= m_nMaxThreadNum)
			{};
			
			//线程计数加一
			m_CriticalSection.Lock();
			m_nCurThreadNum++;
			m_CriticalSection.Unlock();
			
			//开始线程

⌨️ 快捷键说明

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