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

📄 fileterview.cpp

📁 这个我写的一个计算LC滤波器的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		dc.SetROP2(PreR2);
		m_OldPos=point;
	}
	CScrollView::OnMouseMove(nFlags, point);
}

void CFileterView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_Moving)
	{
		CClientDC dc(this);
		int PreR2=dc.SetROP2(R2_NOT);
		//del
		dc.MoveTo(m_OrgPos);
		dc.LineTo(m_OrgPos.x,m_OldPos.y);
		dc.LineTo(m_OldPos);
		dc.LineTo(m_OldPos.x,m_OrgPos.y);
		dc.LineTo(m_OrgPos);
		//get pre
		dc.SetROP2(PreR2);

		PutBlock(m_OldPos.x,m_OldPos.y);

		//judge
		if(labs(point.x-m_OrgPos.x)>80 && labs(point.y-m_OrgPos.y)>50)
		{
			//draw rectange
			CRect MagRect;
			MagRect.left  = point.x<m_OrgPos.x ? point.x : m_OrgPos.x;
			MagRect.right = point.x>m_OrgPos.x ? point.x : m_OrgPos.x;
			MagRect.top   = point.y<m_OrgPos.y ? point.y : m_OrgPos.y;
			MagRect.bottom= point.y>m_OrgPos.y ? point.y : m_OrgPos.y;

			double beginF,endF,begindB,enddB;
			beginF= GetF(MagRect.left);
			endF=  GetF(MagRect.right);

			if(!m_Invert)
			{
				begindB=GetdB(MagRect.bottom);
				enddB = GetdB(MagRect.top);
			}
			else
			{
				begindB=GetdB(MagRect.top);
				enddB = GetdB(MagRect.bottom);
			}
			
			if (beginF<MinF)  BeginF=MinF;
			            else  BeginF=beginF;
			if (endF>MaxF)    EndF=MaxF;
			            else  EndF=endF;
			if (begindB<MindB)BegindB=MindB;
			            else  BegindB=begindB;
			if (enddB>MaxdB)  EnddB=MaxdB;
			            else  EnddB=enddB;
			OnDraw(&dc);
			//write block
		}
		m_Moving=0;
		ReleaseCapture();
		ClipCursor(NULL);
		SetCursor(PreCursor);
	}
	CScrollView::OnLButtonUp(nFlags, point);
}

void CFileterView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{

	if(m_DrawRect.PtInRect(point))
	{
		CClientDC dc(this);
		//ffff magnify 
		double f,db,beginF,endF,begindB,enddB;
		f = GetF(point.x);
		beginF= f- (EndF-BeginF)/4;  // twice
		endF= f+(EndF-BeginF)/4;
		///db magnify
		db = GetdB(point.y);
		begindB=db - (EnddB-BegindB)/4;
		enddB=db + (EnddB-BegindB)/4;
		//range
		if (beginF<MinF)  BeginF=MinF;
		            else  BeginF=beginF;
		if (endF>MaxF)    EndF=MaxF;
		            else  EndF=endF;
		if (begindB<MindB)BegindB=MindB;
		            else  BegindB=begindB;
		if (enddB>MaxdB)  EnddB=MaxdB;
			        else  EnddB=enddB;

		//redraw
		OnDraw(&dc);
	}	
	CScrollView::OnLButtonDblClk(nFlags, point);
}

void CFileterView::OnRButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
		if(m_DrawRect.PtInRect(point))
	{
		CClientDC dc(this);
		//ffff magnify 
		double f,db,beginF,endF,begindB,enddB;
		f = GetF(point.x);
		beginF= f- (EndF-BeginF);  // twice
		endF= f+(EndF-BeginF);
		///db magnify
		db = GetdB(point.y);
		begindB=db - (EnddB-BegindB);
		enddB=db + (EnddB-BegindB);
		//range
		if (beginF<MinF)  BeginF=MinF;
		            else  BeginF=beginF;
		if (endF>MaxF)    EndF=MaxF;
		            else  EndF=endF;
		if (begindB<MindB)BegindB=MindB;
		            else  BegindB=begindB;
		if (enddB>MaxdB)  EnddB=MaxdB;
			        else  EnddB=enddB;

		//redraw
		OnDraw(&dc);
	}

	CScrollView::OnRButtonUp(nFlags, point);
}

void CFileterView::OnRButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_DrawRect.PtInRect(point))
	{
		CClientDC dc(this);
		//ffff magnify 
		double f,db,beginF,endF,begindB,enddB;
		f = GetF(point.x);
		beginF= f- (EndF-BeginF)*2;  // four
		endF= f+(EndF-BeginF)*2;
		///db magnify
		db = GetdB(point.y);
		begindB=db - (EnddB-BegindB)*2;
		enddB=db + (EnddB-BegindB)*2;
		//range
		if (beginF<MinF)  BeginF=MinF;
		            else  BeginF=beginF;
		if (endF>MaxF)    EndF=MaxF;
		            else  EndF=endF;
		if (begindB<MindB)BegindB=MindB;
		            else  BegindB=begindB;
		if (enddB>MaxdB)  EnddB=MaxdB;
			        else  EnddB=enddB;

		//redraw
		OnDraw(&dc);
	}
	
	CScrollView::OnRButtonDblClk(nFlags, point);
}

double CFileterView::GetF(int x)
{	
	double F= BeginF + (EndF-BeginF)*(x-m_DrawRect.left)/m_DrawRect.Width();
	return (F);
}

double CFileterView:: GetdB(int y)
{
	double dB;
	if(!m_Invert)
		dB= EnddB - (EnddB-BegindB)*y/m_DrawRect.Height();
	else
		dB= BegindB + (EnddB-BegindB)*y/m_DrawRect.Height();
	return (dB);
}
int CFileterView:: GetX(double f)
{
	int x=(int)(m_DrawRect.left+(m_DrawRect.right-m_DrawRect.left)/(EndF-BeginF)*(f-BeginF));

	return (x);
}
int CFileterView:: GetY(double db)
{
	int y;
	if(!m_Invert) //no invert
		y=int(m_DrawRect.bottom - (db-BegindB) / (EnddB-BegindB) * m_DrawRect.Height());
	else
		y=int(m_DrawRect.top + (db-BegindB) / (EnddB-BegindB) * m_DrawRect.Height());
	return (y);
	
}

void CFileterView::GetBlock(int x,int y)
{
	int beginX,beginY;
	CClientDC dc(this);
	CString str;
	str.Format("%6.2fM, %4.1f dB",GetF(x)/(1e6),-GetdB(y));
	CSize ExtentSize=dc.GetTextExtent(str);

	m_MovPtSize=ExtentSize;
	beginX=x-m_MovPtSize.cx-m_Distance;
	beginY=y-m_MovPtSize.cy-m_Distance;
	//out X left
	if(beginX<m_ClientRect.left)  
		beginX=x+m_Distance;
	//out of Y top
	if(beginY<m_ClientRect.top)  
		beginY=y+m_Distance;

	memDC.BitBlt(0,0,m_MovPtSize.cx,m_MovPtSize.cy,
			     &dc,beginX,beginY,SRCCOPY);
	//text out
	dc.TextOut(beginX,beginY,str);

}
void CFileterView::PutBlock(int x,int y)
{
	CClientDC dc(this);
	int beginX,beginY;
	beginX=x-m_MovPtSize.cx-m_Distance;
	beginY=y-m_MovPtSize.cy-m_Distance;
	//out X left
	if(beginX<m_ClientRect.left)  
		beginX=x+m_Distance;
	//out of Y top
	if(beginY<m_ClientRect.top)  
		beginY=y+m_Distance;

	dc.BitBlt(beginX,beginY,m_MovPtSize.cx,m_MovPtSize.cy,
			     &memDC,0,0,SRCCOPY);

}
void CFileterView::WriteWord(int x,int y)
{
//write  f db
/*	CClientDC dc(this);
	int beginX,beginY;
	CString str;
	str.Format("%6.2fM, %4.1f dB",GetF(x)/(1e6),-GetdB(y));
	CSize ExtentSize=dc.GetTextExtent(str);	
	
	m_MovPtSize=ExtentSize;
	beginX=x-m_MovPtSize.cx-m_Distance;
	beginY=y-m_MovPtSize.cy-m_Distance;
	dc.TextOut(beginX,beginY,str);
*/	
}

void CFileterView::OnSetDbtype() 
{
	// TODO: Add your command handler code here

	if(m_Invert)
		m_Invert=FALSE;
	else m_Invert=TRUE;
	CClientDC dc(this);
	OnDraw(&dc);
}

void CFileterView::OnUpdateSetDbtype(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Invert);
	
}

enum {NO,IsC1,IsC2,IsC3,IsC4,IsC5,IsL2,IsR2,IsL4,IsR4,IsRL};

void CFileterView::OnSelectC1() 
{
	// TODO: Add your command handler code here
	m_Who=IsC1;
}

void CFileterView::OnUpdateSelectC1(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Who==IsC1);
}

void CFileterView::OnSelectC2() 
{
	// TODO: Add your command handler code here
	m_Who=IsC2;
}

void CFileterView::OnUpdateSelectC2(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Who==IsC2);
}

void CFileterView::OnSelectC3() 
{
	// TODO: Add your command handler code here
	m_Who=IsC3;
}

void CFileterView::OnUpdateSelectC3(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Who==IsC3);
}

void CFileterView::OnSelectC4() 
{
	// TODO: Add your command handler code here
	m_Who=IsC4;
}

void CFileterView::OnUpdateSelectC4(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Who==IsC4);
}

void CFileterView::OnSelectC5() 
{
	// TODO: Add your command handler code here
	m_Who=IsC5;
}

void CFileterView::OnUpdateSelectC5(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Who==IsC5);
}

void CFileterView::OnSelectL2() 
{
	// TODO: Add your command handler code here
	m_Who=IsL2;
}

void CFileterView::OnUpdateSelectL2(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Who==IsL2);
}

void CFileterView::OnSelectR2() 
{
	// TODO: Add your command handler code here
	m_Who=IsR2;
}

void CFileterView::OnUpdateSelectR2(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Who==IsR2);
}

void CFileterView::OnSelectL4() 
{
	// TODO: Add your command handler code here
	m_Who=IsL4;
}

void CFileterView::OnUpdateSelectL4(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Who==IsL4);
}

void CFileterView::OnSelectR4() 
{
	// TODO: Add your command handler code here
	m_Who=IsR4;
	
}

void CFileterView::OnUpdateSelectR4(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Who==IsR4);
	
}
void CFileterView::OnSelectRl() 
{
	// TODO: Add your command handler code here
	m_Who=IsRL;
}

void CFileterView::OnUpdateSelectRl(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Who==IsRL);
}


void CFileterView::OnSetAdd() 
{
	// TODO: Add your command handler code here
	double times=1.05;
	double rl=pViewFilter->GetRL();
	pViewFilter->GetVal(pCC,pLC);

	CCompnent *pC;
	switch(m_Who){
	case IsC1: pC=&pCC[0];break;
	case IsC2: pC=&pCC[1];break;
	case IsC3: pC=&pCC[2];break;
	case IsC4: pC=&pCC[3];break;
	case IsC5: pC=&pCC[4];break;
	case IsL2: pC=&pLC[0];break;
	case IsR2: pC=&pLC[0];break;
	case IsL4: pC=&pLC[1];break;
	case IsR4: pC=&pLC[1];break;
	case IsRL: rl*=times;break;
//	case default:
	}
	switch(m_Who) {
	case IsC1:
	case IsC2:
	case IsC3:
	case IsC4:
	case IsC5:
	case IsL2:
	case IsL4: pC->SetVal(pC->GetVal()*times);break;
	case IsR2:
	case IsR4: pC->SetValR(pC->GetValR()*times);break;
	}
	pViewFilter->SetVal(pCC,pLC);
	pViewFilter->SetRL(rl);
	CClientDC dc(this);
	OnDraw(&dc);
}

void CFileterView::OnUpdateSetAdd(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
}

void CFileterView::OnSetSub() 
{
	double times=1.05;
	double rl=pViewFilter->GetRL();
	pViewFilter->GetVal(pCC,pLC);

	CCompnent *pC;
	switch(m_Who){
	case IsC1: pC=&pCC[0];break;
	case IsC2: pC=&pCC[1];break;
	case IsC3: pC=&pCC[2];break;
	case IsC4: pC=&pCC[3];break;
	case IsC5: pC=&pCC[4];break;
	case IsL2: pC=&pLC[0];break;
	case IsR2: pC=&pLC[0];break;
	case IsL4: pC=&pLC[1];break;
	case IsR4: pC=&pLC[1];break;
	case IsRL: rl/=times;break;
//	case default:
	}
	switch(m_Who) {
	case IsC1:
	case IsC2:
	case IsC3:
	case IsC4:
	case IsC5:
	case IsL2:
	case IsL4: pC->SetVal(pC->GetVal()/times);break;
	case IsR2:
	case IsR4: pC->SetValR(pC->GetValR()/times);break;
	}
	pViewFilter->SetVal(pCC,pLC);
	pViewFilter->SetRL(rl);
	CClientDC dc(this);
	OnDraw(&dc);
}

void CFileterView::OnUpdateSetSub(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
//	pCmdUI->SetCheck(1);
}

void CFileterView::OnSetReturn() 
{
	// TODO: Add your command handler code here
	pViewFilter->CountValue();
	CClientDC dc(this);
	OnDraw(&dc);
}

void CFileterView::OnSetClass() 
{
	// TODO: Add your command handler code here
	double f1,f2,rl;
	CClientDC dc(this);
	CNewDlg0 newdlg0;
	CNewDlg1 newdlg1;
	int result0,result1;
	pViewFilter->GetFrequence(f1,f2);
	rl=pViewFilter->GetRL();
	newdlg0.SetValToDlg(FilterClass,FilterType,f1,f2,rl);
	result0=newdlg0.DoModal();
//	if(result0==IDCANCEL) 
	if(result0==IDOK)
	{
	newdlg0.GetValFromDlg(FilterClass,FilterType,f1,f2,rl);
	UpdateViewFilter(FilterClass,FilterType,f1,f2,rl);
	OnDraw(&dc);
	}
	if(result0==ID_NEXT)
	{
		result1=newdlg1.DoModal();
	}
}

void CFileterView::UpdateViewFilter(int fClass,int fType,double f1,double f2,double rl)
{
    delete pViewFilter;
	switch(fClass) {
	case BUTTER:
		 pViewFilter=new CButterLPF; 
		 break;
	case CHEBY:
	     pViewFilter=new CChebyLPF;
		 break; 
	case CAUER:
	     pViewFilter=new CCauerLPF;
	     pViewFilter->SetReflex(20);
    	 break; 
	default: break;
	}
	pViewFilter->SetFrequence(f1,f2);
	pViewFilter->SetRL(rl);
	pViewFilter->SetSectionNum(5);
	pViewFilter->CountValue();
}

⌨️ 快捷键说明

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