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

📄 femmviewview.cpp

📁 一个2D电磁场FEM计算的VC++源程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	else{
		GridFlag=TRUE;
		MMnu->CheckMenuItem(ID_SHOW_GRID, MF_CHECKED);
		tc->CheckButton(ID_SHOW_GRID,TRUE);
	}
	RedrawView();
}

void CFemmviewView::OnSetGrid() 
{
	CGridMod pDlg;
	CFemmviewDoc *pDoc=GetDocument();
	
	// Send present parameter values to the dialog
	// pDlg.m_rji=TheDoc->vi[0];
	pDlg.m_gridsize       = GridSize;
	pDlg.coords			  = pDoc->Coords;
	
	// Display dialog and collect data
	if(pDlg.DoModal()==IDOK)
	{
		GridSize=pDlg.m_gridsize;
		pDoc->Coords=pDlg.coords;
		RedrawView();
	}
}

void CFemmviewView::OnSnapGrid() 
{
	CMainFrame *MFrm;
	MFrm=(CMainFrame *)GetParentFrame();
	CMenu* MMnu=MFrm->GetMenu();
	CToolBar *pToolBar;
	pToolBar=&MFrm->m_toolBar;    
	CToolBarCtrl *tc=&pToolBar->GetToolBarCtrl();

	if(SnapFlag==TRUE){
		SnapFlag=FALSE;
		MMnu->CheckMenuItem(ID_SNAP_GRID, MF_UNCHECKED);
		tc->CheckButton(ID_SNAP_GRID,FALSE);
	}
	else{
		SnapFlag=TRUE;
		MMnu->CheckMenuItem(ID_SNAP_GRID, MF_CHECKED);
		tc->CheckButton(ID_SNAP_GRID,TRUE);
	}
}

void CFemmviewView::OnShowMesh() 
{
	CMainFrame *MFrm;
	MFrm=(CMainFrame *)GetParentFrame();
	CMenu* MMnu=MFrm->GetMenu();
	CToolBar *pToolBar;
	pToolBar=&MFrm->m_toolBar;    
	CToolBarCtrl *tc=&pToolBar->GetToolBarCtrl();
	
	if(MeshFlag==TRUE){
		MeshFlag=FALSE;
		MMnu->CheckMenuItem(ID_SHOW_MESH, MF_UNCHECKED);
		tc->CheckButton(ID_SHOW_MESH,FALSE);
	}
	else{
		MeshFlag=TRUE;
		MMnu->CheckMenuItem(ID_SHOW_MESH, MF_CHECKED);
		tc->CheckButton(ID_SHOW_MESH,TRUE);
	}

	RedrawView();
}


void CFemmviewView::OnCplot() 
{
	CFemmviewDoc *pDoc=GetDocument();

	if(pDoc->Frequency>0){
		CCPlotDlg dlg;
		dlg.m_showar=ShowAr;
		dlg.m_showai=ShowAi;
		dlg.m_showmask=ShowMask;
		dlg.m_numcontours=NumContours;
		dlg.m_alow=pDoc->A_Low;
		dlg.m_ahigh=pDoc->A_High;
		dlg.Alb=pDoc->A_lb;
		dlg.Aub=pDoc->A_ub;
		if(dlg.DoModal()==IDOK){
			ShowAr=dlg.m_showar;
			ShowAi=dlg.m_showai;
			ShowMask=dlg.m_showmask;
			pDoc->A_Low=dlg.m_alow;
			pDoc->A_High=dlg.m_ahigh;
			NumContours=dlg.m_numcontours;
			RedrawView();
		}
	}
	else{
		CCplotDlg2 dlg;
		dlg.m_showa=ShowAr;
		dlg.m_showmask=ShowMask;
		dlg.m_numcontours=NumContours;
		dlg.m_alow=pDoc->A_Low;
		dlg.m_ahigh=pDoc->A_High;
		dlg.Alb=pDoc->A_lb;
		dlg.Aub=pDoc->A_ub;
		if(dlg.DoModal()==IDOK){
			ShowAr=dlg.m_showa;
			ShowMask=dlg.m_showmask;
			ShowAi=FALSE;
			pDoc->A_Low=dlg.m_alow;
			pDoc->A_High=dlg.m_ahigh;
			NumContours=dlg.m_numcontours;
			RedrawView();
		}
	}
}

void CFemmviewView::OnDplot() 
{
	CFemmviewDoc *pDoc=GetDocument();

	if (pDoc->Frequency>0){
		CDPlotDlg1 dlg;
		dlg.btnState=DensityPlot;
		dlg.m_showlegend=LegendFlag;
		dlg.m_gscale=GreyContours;

		dlg.Bm_l=pDoc->B_Low;
		dlg.Bm_h=pDoc->B_High;
		
		dlg.Br_l=pDoc->Br_Low;
		dlg.Br_h=pDoc->Br_High;
		
		dlg.Bi_l=pDoc->Bi_Low;
		dlg.Bi_h=pDoc->Bi_High;

		dlg.m_lb1=pDoc->B_lb;
		dlg.m_ub1=pDoc->B_ub;
		if (DensityPlot>3){
			dlg.m_lb1*=1.e-6;
			dlg.m_ub1*=1.e-6;
		}

		dlg.Jm_l=pDoc->J_Low*1.e-6;
		dlg.Jm_h=pDoc->J_High*1.e-6;
		
		dlg.Jr_l=pDoc->Jr_Low*1.e-6;
		dlg.Jr_h=pDoc->Jr_High*1.e-6;
		
		dlg.Ji_l=pDoc->Ji_Low*1.e-6;
		dlg.Ji_h=pDoc->Ji_High*1.e-6;		

		if(dlg.DoModal()==IDOK){
			DensityPlot=dlg.btnState;
			LegendFlag=dlg.m_showlegend;
			GreyContours=dlg.m_gscale;
			RedrawView();
			if(DensityPlot>3){ // fix bound for J plot case;
				dlg.m_ub1*=1.e6;
				dlg.m_lb1*=1.e6;
			}
			pDoc->B_ub=dlg.m_ub1;
			pDoc->B_lb=dlg.m_lb1;
			

		}
	}
	else{
		CDPlotDlg2 dlg;
		if(DensityPlot>0) DensityPlot=1;
		dlg.m_showit=DensityPlot;
		dlg.m_showlegend=LegendFlag;
		dlg.m_gscale=GreyContours;
		dlg.Bm_h=pDoc->B_High;
		dlg.Bm_l=pDoc->B_Low;
		dlg.m_ub2=pDoc->B_ub;
		dlg.m_lb2=pDoc->B_lb;

		if(dlg.DoModal()==IDOK){
			DensityPlot=dlg.m_showit;
			LegendFlag=dlg.m_showlegend;
			GreyContours=dlg.m_gscale;
			pDoc->B_ub=dlg.m_ub2;
			pDoc->B_lb=dlg.m_lb2;
			RedrawView();
		}
	}
}

void CFemmviewView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	CMainFrame *MFrm;
	MFrm=(CMainFrame *)GetParentFrame();
	if (MFrm==NULL) AfxMessageBox("Null GetParentFrame");
	else{
		StatBar=(CStatusBar *)MFrm->GetMessageBar();
		Dspl=&MFrm->m_dlgBar;
	}

	CToolBar *pToolBar;
	pToolBar=&MFrm->m_toolBar;    
	CToolBarCtrl *tc=&pToolBar->GetToolBarCtrl();
}

void CFemmviewView::DisplayPointProperties(double px, double py)
{
	CFemmviewDoc* pDoc = GetDocument();
	CPointVals u;
	CComplex Jtot;
	if (pDoc->nodelist.GetSize()==0) return;
	if(pDoc->GetPointValues(px, py, u)==TRUE)
	{
		char s[80],c[80];
		if (pDoc->ProblemType>=0)
		{
			if(pDoc->Frequency==0)
			{
				if (pDoc->ProblemType==0)
				{
					CString msg;
					sprintf(s,"Point: x=%g, y=%g\r\n",px,py); msg=msg+s;
					sprintf(s,"A   = %g Weber\r\n",u.A.re); msg=msg+s;
					sprintf(s,"|B| = %g Tesla\r\n",sqrt(u.B1.re*u.B1.re + u.B2.re*u.B2.re)); msg=msg+s;
					sprintf(s,"Bx  = %g Tesla\r\n",u.B1.re); msg=msg+s;
					sprintf(s,"By  = %g Tesla\r\n",u.B2.re); msg=msg+s;
					sprintf(s,"|H| = %g Amp/m\r\n",sqrt(u.H1.re*u.H1.re + u.H2.re*u.H2.re)); msg=msg+s;
					sprintf(s,"Hx  = %g Amp/m\r\n",u.H1.re); msg=msg+s;
					sprintf(s,"Hy  = %g Amp/m\r\n",u.H2.re); msg=msg+s;
					sprintf(s,"mu_x= %g (relative)\r\n",u.mu1.re); msg=msg+s;
					sprintf(s,"mu_y= %g (relative)\r\n",u.mu2.re); msg=msg+s;
					sprintf(s,"E   = %g Joules/m^3\r\n",u.E); msg=msg+s;
					sprintf(s,"J   = %g MA/m^2\r\n",u.Js.re); msg=msg+s; 
					if (u.ff>0){sprintf(s,"Winding Fill = %.2f%%",u.ff*100.); msg=msg+s;}

					Dspl->SetDlgItemText(IDC_OUT,msg);
				}
				else{
					CString msg;
					sprintf(s,"Point: r=%g, z=%g\r\n",px,py); msg=msg+s;
					sprintf(s,"Flux= %g Webers\r\n",u.A.re); msg=msg+s;
					sprintf(s,"|B| = %g Tesla\r\n",sqrt(u.B1.re*u.B1.re + u.B2.re*u.B2.re)); msg=msg+s;
					sprintf(s,"Br  = %g Tesla\r\n",u.B1.re); msg=msg+s;
					sprintf(s,"Bz  = %g Tesla\r\n",u.B2.re); msg=msg+s;
					sprintf(s,"|H| = %g Amp/m\r\n",sqrt(u.H1.re*u.H1.re + u.H2.re*u.H2.re)); msg=msg+s;
					sprintf(s,"Hr  = %g Amp/m\r\n",u.H1.re); msg=msg+s;
					sprintf(s,"Hz  = %g Amp/m\r\n",u.H2.re); msg=msg+s;
					sprintf(s,"mu_r= %g (relative)\r\n",u.mu1.re); msg=msg+s;
					sprintf(s,"mu_z= %g (relative)\r\n",u.mu2.re); msg=msg+s;
					sprintf(s,"P   = %g Joules/m^3\r\n",u.E); msg=msg+s; 
					sprintf(s,"J   = %g MA/m^2\r\n",u.Js.re); msg=msg+s;
					if (u.ff>0){sprintf(s,"Winding Fill = %.2f%%",u.ff*100.); msg=msg+s;}
					Dspl->SetDlgItemText(IDC_OUT,msg); 
				}
			}
			// Harmonic problems...
			else{
				if(pDoc->ProblemType==0){
					CString msg;
					sprintf(s,"Point: x=%g, y=%g\r\n",px,py); msg=msg+s;
					sprintf(s,"A   = %s Weber/m\r\n",u.A.ToString(c)); msg=msg+s;
					sprintf(s,"|B| = %g Tesla\r\n",sqrt(u.B1.re*u.B1.re + u.B2.re*u.B2.re
						+u.B1.im*u.B1.im + u.B2.im*u.B2.im)); msg=msg+s;
					sprintf(s,"Bx  = %s Tesla\r\n",u.B1.ToString(c)); msg=msg+s;
					sprintf(s,"By  = %s Tesla\r\n",u.B2.ToString(c)); msg=msg+s;
					sprintf(s,"|H| = %g Amp/m\r\n",sqrt(u.H1.re*u.H1.re + u.H2.re*u.H2.re
						+u.H1.im*u.H1.im + u.B2.im*u.H2.im)); msg=msg+s;
					sprintf(s,"Hx  = %s Amp/m\r\n",u.H1.ToString(c)); msg=msg+s;
					sprintf(s,"Hy  = %s Amp/m\r\n",u.H2.ToString(c)); msg=msg+s;
					sprintf(s,"mu_x= %s (relative)\r\n",u.mu1.ToString(c)); msg=msg+s;
					sprintf(s,"mu_y= %s (relative)\r\n",u.mu2.ToString(c)); msg=msg+s;
					Jtot=u.Je + u.Js;
					sprintf(s,"J= %s MA/m^2\r\n",Jtot.ToString(c)); msg=msg+s;
					if (u.ff>0){sprintf(s,"Winding Fill = %.2f%%",u.ff*100.); msg=msg+s;}
					Dspl->SetDlgItemText(IDC_OUT,msg);
				}
				if(pDoc->ProblemType==1){
					CString msg;
					sprintf(s,"Point: r=%g, z=%g\r\n",px,py); msg=msg+s;
					sprintf(s,"Flux= %s Wb\r\n",u.A.ToString(c)); msg=msg+s; 
					sprintf(s,"|B| = %g Tesla\r\n",sqrt(u.B1.re*u.B1.re + u.B2.re*u.B2.re
						+u.B1.im*u.B1.im + u.B2.im*u.B2.im)); msg=msg+s;
					sprintf(s,"Br  = %s Tesla\r\n",u.B1.ToString(c)); msg=msg+s;
					sprintf(s,"Bz  = %s Tesla\r\n",u.B2.ToString(c)); msg=msg+s;
					sprintf(s,"|H| = %g Amp/m\r\n",sqrt(u.H1.re*u.H1.re + u.H2.re*u.H2.re
						+u.H1.im*u.H1.im + u.B2.im*u.H2.im)); msg=msg+s;
					sprintf(s,"Hr  = %s Amp/m\r\n",u.H1.ToString(c)); msg=msg+s;
					sprintf(s,"Hz  = %s Amp/m\r\n",u.H2.ToString(c)); msg=msg+s;
					sprintf(s,"mu_r= %s (relative)\r\n",u.mu1.ToString(c)); msg=msg+s;
					sprintf(s,"mu_z= %s (relative)\r\n",u.mu2.ToString(c)); msg=msg+s;
					Jtot=u.Je + u.Js;
					sprintf(s,"J= %s MA/m^2\r\n",Jtot.ToString(c)); msg=msg+s;
					if (u.ff>0){sprintf(s,"Winding Fill = %.2f%%",u.ff*100.); msg=msg+s;}
					Dspl->SetDlgItemText(IDC_OUT,msg);
				}
			}
		}
}
}

void CFemmviewView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	if (bLinehook!=FALSE)
	{
		CView::OnLButtonDown(nFlags, point);
		return;
	}

	int i,j,k,m;

	if (ZoomWndFlag==1)
	{
		ZoomWndFlag++;
		wzx=mx;wzy=my;
		return;
	}

	if (ZoomWndFlag==2) return;
		
	if (EditAction==0) DisplayPointProperties(mx,my);

	if (EditAction==1){
		CFemmviewDoc *pDoc=GetDocument();
		if (pDoc->nodelist.GetSize()>0){
			i=pDoc->ClosestNode(mx,my);
			CComplex x,y,z;
			double R,d1,d2;
			int lineno,arcno,flag=0;
			z.Set(pDoc->nodelist[i].x,pDoc->nodelist[i].y);

			if (pDoc->contour.GetSize()>0){
				
				//check to see if point is the same as last point in the contour;
				y=pDoc->contour[pDoc->contour.GetSize()-1];
				if ((y.re==z.re) && (y.im==z.im)) return;
				
				j=pDoc->ClosestNode(y.re,y.im);
				x.Set(pDoc->nodelist[j].x,pDoc->nodelist[j].y);

				//check to see if this point and the last point are ends of an
				//input segment;
				lineno=-1;
				d1=1.e08;
								
				if (abs(x-y)<1.e-08){
					for(k=0;k<pDoc->linelist.GetSize();k++){
						if((pDoc->linelist[k].n0==j) && (pDoc->linelist[k].n1==i))
						{
							d2=fabs(pDoc->ShortestDistanceFromSegment(mx,my,k));
							if(d2<d1){
								lineno=k;
								d1=d2;
							}
						}
						if((pDoc->linelist[k].n0==i) && (pDoc->linelist[k].n1==j))
						{
							d2=fabs(pDoc->ShortestDistanceFromSegment(mx,my,k));
							if(d2<d1){
								lineno=k;
								d1=d2;
							}
						}
					}
				}

				//check to see if this point and last point are ends of an
				// arc segment; if so, add entire arc to the contour;
				arcno=-1;
				if (abs(x-y)<1.e-08){
					for(k=0;k<pDoc->arclist.GetSize();k++){
						if((pDoc->arclist[k].n0==j) && (pDoc->arclist[k].n1==i))
						{
							d2=pDoc->ShortestDistanceFromArc(CComplex(mx,my),
							   pDoc->arclist[k]);
							if(d2<d1){
								arcno=k;
								lineno=-1;
								flag=TRUE;
								d1=d2;
							}
						}
						if((pDoc->arclist[k].n0==i) && (pDoc->arclist[k].n1==j))
						{
							d2=pDoc->ShortestDistanceFromArc(CComplex(mx,my),
							   pDoc->arclist[k]);
							if(d2<d1){
								arcno=k;
								lineno=-1;
								flag=FALSE;
								d1=d2;
							}
						}
					}
				}
				
			}
			else{
				pDoc->contour.Add(z);
				DrawUserContour(FALSE);
				return;
			}

			if((lineno<0) && (arcno<0)){
				pDoc->contour.Add(z);
				DrawUserContour(FALSE);
			}

			if(lineno>=0){
				j=pDoc->contour.GetSize();
				if(j>1){
					if(abs(pDoc->contour[j-2]-z)<1.e-08){
						CView::OnLButtonDown(nFlags, point);
						return;
					}
				}
				pDoc->contour.Add(z);
				DrawUserContour(FALSE);
			}
			if(arcno>=0){
				k=arcno;
				pDoc->GetCircle(pDoc->arclist[k],x,R);
				j=(int) ceil(pDoc->arclist[k].ArcLength/pDoc->arclist[k].MaxSideLength);
				if(flag==TRUE)
					z=exp(I*pDoc->arclist[k].ArcLength*PI/(180.*((double) j)) );
				else
					z=exp(-I*pDoc->arclist[k].ArcLength*PI/(180.*((double) j)) );
				for(i=0;i<j;i++){
					y=(y-x)*z+x;
					m=pDoc->contour.GetSize();
					if(m>1){
						if(abs(pDoc->contour[m-2]-y)<1.e-08){
							CView::OnLButtonDown(nFlags, point);
							return;
						}
					}
					pDoc->contour.Add(y);
					DrawUserContour(FALSE);
				}
			}
		}
	}

	if (EditAction==2){
		CFemmviewDoc *pDoc=GetDocument();

		if (pDoc->meshelem.GetSize()>0){
			k=pDoc->InTriangle(mx,my);
			if(k>=0){
				pDoc->bHasMask=FALSE;
				pDoc->blocklist[pDoc->meshelem[k].lbl].ToggleSelect();
				DrawSelected=pDoc->meshelem[k].lbl;
				CDC *pDC=GetDC();
				OnDraw(pDC);
				DrawSelected=-1;
				ReleaseDC(pDC);
			}
		}
			
	}
	
	CView::OnLButtonDown(nFlags, point);
}

void CFemmviewView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	if (bLinehook!=FALSE)
	{
		CView::OnLButtonUp(nFlags, point);
		return;
	}

	if (ZoomWndFlag>0){
		ZoomPix.RemoveAll();
		ZoomWndFlag=0;
		if((mx==wzx) && (my==wzy)){
			RedrawView();
			return;
		}
		RECT r;
		double z,cmag,m[2];
		if (mx<wzx){ z=wzx; wzx=mx; mx=z; }
		if (my<wzy){ z=wzy; wzy=my; my=z; }
		GetClientRect(&r);
		m[0]=((double) r.right)/(mx-wzx);
		m[1]=((double) r.bottom)/(my-wzy);


		if(m[0]<m[1]) cmag=m[0];
		else cmag=m[1];
		
		mag=cmag;
		ox=wzx; oy=wzy;
		
		RedrawView();
	}

	CView::OnLButtonUp(nFlags, point);
}

void CFemmviewView::OnRButtonDown(UINT nFlags, CPoint point) 
{	
	if (bLinehook!=FALSE)
	{
		CView::OnRButtonDown(nFlags, point);
		return;
	}

⌨️ 快捷键说明

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