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

📄 femmeview.cpp

📁 一个2D电磁场FEM计算的VC++源程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		if(j>=0) pDoc->linelist[j].ToggleSelect();
		DrawPSLG(); 
	} 

	//toggle select of nearest arc segment
	if(EditAction==3){
		j=pDoc->ClosestArcSegment(mx,my);
		if(j>=0) pDoc->arclist[j].ToggleSelect();
		DrawPSLG(); 
	} 
	//toggle select of nearest blocklabel
	if(EditAction==2){
		j=pDoc->ClosestBlockLabel(mx,my);
		if(j>=0) pDoc->blocklist[j].ToggleSelect();
		DrawPSLG();
	}

	if(EditAction==4){
		int clnode,clseg,claseg,cllbl;
		double dnode,dseg,daseg,dlbl,d;

		// find distance to closest node;
		clnode=pDoc->ClosestNode(mx,my);
		if(clnode>=0) dnode=pDoc->nodelist[clnode].GetDistance(mx,my);
		else dnode=-1.;

		// find distance to closest segment;
		clseg=pDoc->ClosestSegment(mx,my);
		if (clseg>=0) dseg=pDoc->ShortestDistance(mx,my,clseg);
		else dseg=-1.;

		// find distance to closest arc segment;
		claseg=pDoc->ClosestArcSegment(mx,my);
		if (claseg>=0) 
			daseg=pDoc->ShortestDistanceFromArc(CComplex(mx,my),pDoc->arclist[claseg]);
		else daseg=-1.;

		// find distance to closest block label;
		cllbl=pDoc->ClosestBlockLabel(mx,my);
		if(cllbl>=0) dlbl=pDoc->blocklist[cllbl].GetDistance(mx,my);
		else dlbl=-1.;

		// now, compare to find the closest entity;
		j=-1;
		if (clnode>=0){
			d=dnode;
			j=pDoc->nodelist[clnode].InGroup;
		}
		if ((dseg<d) && (clseg>=0)){
			d=dseg;
			j=pDoc->linelist[clseg].InGroup;
		}
		if ((daseg<d) && (claseg>=0)){
			d=daseg;
			j=pDoc->arclist[claseg].InGroup;
		}
		if ((dlbl<d) && (cllbl>=0)){
			d=dlbl;
			j=pDoc->blocklist[cllbl].InGroup;
		}

		if (j<1) return; // return if the closest object is associated with
		                 // the default group, or if there are no objects.
		
		
		// now, the group associated with the nearest entity is in j;
		// toggle the select of all objects in this group;
		for(i=0;i<pDoc->nodelist.GetSize();i++)
			if (pDoc->nodelist[i].InGroup==j) pDoc->nodelist[i].ToggleSelect();
		for(i=0;i<pDoc->linelist.GetSize();i++)
			if (pDoc->linelist[i].InGroup==j) pDoc->linelist[i].ToggleSelect();
		for(i=0;i<pDoc->arclist.GetSize();i++)
			if (pDoc->arclist[i].InGroup==j) pDoc->arclist[i].ToggleSelect();
		for(i=0;i<pDoc->blocklist.GetSize();i++)
			if (pDoc->blocklist[i].InGroup==j) pDoc->blocklist[i].ToggleSelect();
		DrawPSLG();
	}

	CView::OnRButtonDown(nFlags, point);
}

void CFemmeView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
		
	CView::OnLButtonDblClk(nFlags, point);
}

void CFemmeView::OnRButtonDblClk(UINT nFlags, CPoint point) 
{
	CFemmeDoc *pDoc=GetDocument();
	if (EditAction==0)
	{
		int i=pDoc->ClosestNode(mx,my);
		if(i>=0){
			char s[256];
			int j;
			CString ss;
			
			sprintf(s,"Closest node:  (%g,%g)\n",pDoc->nodelist[i].x,
				pDoc->nodelist[i].y);
			ss+=s;
			ss+="Nodal Property:  ";
			sprintf(s,"<None>\n");
			for(j=0;j<pDoc->nodeproplist.GetSize();j++)
			{
				if(pDoc->nodeproplist[j].PointName==
				   pDoc->nodelist[i].BoundaryMarker)
				{
					sprintf(s,"%s\n",pDoc->nodelist[i].BoundaryMarker);
				}
			}
			ss+=s;
			sprintf(s,"In Group:  %i",pDoc->nodelist[i].InGroup);
			ss+=s;
			
			AfxMessageBox(ss,MB_ICONINFORMATION);
			pDoc->nodelist[i].ToggleSelect();
			DrawPSLG();
		}
	}

	if (EditAction==1)
	{
		int i=pDoc->ClosestSegment(mx,my);
		int j;
		CString ss;

		if(i>=0){
			char s[256];
			sprintf(s,"Length of closest segment: %g\n",
				pDoc->LineLength(i));
			
			ss+=s;
			ss+="Boundary Property:  ";
			
			sprintf(s,"<None>\n");
			for(j=0;j<pDoc->lineproplist.GetSize();j++)
			{
				if(pDoc->lineproplist[j].BdryName==
				   pDoc->linelist[i].BoundaryMarker)
				{
					sprintf(s,"%s\n",pDoc->linelist[i].BoundaryMarker);
				}
			}
			ss+=s;

			ss+="Grid spacing:  ";
			if (pDoc->linelist[i].MaxSideLength<=0)
				sprintf(s,"<Auto>\n");
			else sprintf(s,"%g\n",pDoc->linelist[i].MaxSideLength);
			ss+=s;
			sprintf(s,"In Group:  %i",pDoc->linelist[i].InGroup);
			ss+=s;
			
			if(pDoc->linelist[i].Hidden==TRUE)
				ss+="\nHidden in postprocessor";

			AfxMessageBox(ss,MB_ICONINFORMATION);
			pDoc->linelist[i].ToggleSelect();
			DrawPSLG();
		}
	}

	if (EditAction==2)
	{
		int i=pDoc->ClosestBlockLabel(mx,my);
		int j,k;
		if(i>=0){
			char s[256];
			sprintf(s,"Closest block label:  (%g,%g)\n",pDoc->blocklist[i].x,
				pDoc->blocklist[i].y);
			CString ss=s;
			ss+="Block Material:  ";
			k=-1;
			sprintf(s,"<None>\n");
			if (pDoc->blocklist[i].BlockType=="<No Mesh>")
			{
				sprintf(s,"<No Mesh>\n");
			}
			else for(j=0;j<pDoc->blockproplist.GetSize();j++)
			{
				if(pDoc->blockproplist[j].BlockName==
				   pDoc->blocklist[i].BlockType)
				{
					sprintf(s,"%s\n",pDoc->blocklist[i].BlockType);
					k=j;
				}
			}
			ss+=s;
			
			ss+="In Circuit:  ";
			sprintf(s,"<None>\n");
			for(j=0;j<pDoc->circproplist.GetSize();j++)
			{
				if(pDoc->circproplist[j].CircName==
				   pDoc->blocklist[i].InCircuit)
				{
					sprintf(s,"%s\n",pDoc->blocklist[i].InCircuit);
				}
			}
			ss+=s;

			ss+="Mesh size:  ";
			if (pDoc->blocklist[i].MaxArea==0)
				sprintf(s,"<Auto>\n");
			else sprintf(s,"%g\n",
				floor(2.e07*sqrt(pDoc->blocklist[i].MaxArea/PI)
				      +0.5)/1.e07 );
			ss+=s;

			sprintf(s,"In Group:  %i",pDoc->blocklist[i].InGroup);
			ss+=s;

			// if it has magnetized material....
			if(k>=0)
			{
				if(pDoc->blockproplist[k].H_c>0)
				{
					sprintf(s,"\nMag Direction:  %g deg",
						pDoc->blocklist[i].MagDir);
					ss+=s;
				}
			}
			AfxMessageBox(ss,MB_ICONINFORMATION);
			pDoc->blocklist[i].ToggleSelect();
			DrawPSLG();
		}
	}

	if (EditAction==3)
	{
		int i=pDoc->ClosestArcSegment(mx,my);
		if(i>=0){
			char s[256];
			CString ss;
			int j;
			double R;
			CComplex c;

			sprintf(s,"Angle spanned by closest arc: %g deg\n",
				pDoc->arclist[i].ArcLength); ss+=s;
			pDoc->GetCircle(pDoc->arclist[i],c,R);
			c=Chop(c);
			sprintf(s,"Radius of associated circle: %g\n",R); ss+=s;
			sprintf(s,"Center of associated circle: (%g,%g)\n",Re(c),Im(c)); ss+=s;
			ss+="Boundary Property:  ";
			
			sprintf(s,"<None>\n");
			for(j=0;j<pDoc->lineproplist.GetSize();j++)
			{
				if(pDoc->lineproplist[j].BdryName==
				   pDoc->arclist[i].BoundaryMarker)
				{
					sprintf(s,"%s\n",pDoc->arclist[i].BoundaryMarker);
				}
			}
			ss+=s;
			sprintf(s,"Grid spacing:  %g deg\n",pDoc->arclist[i].MaxSideLength); ss+=s;
			sprintf(s,"In Group:  %i",pDoc->arclist[i].InGroup); ss+=s;
			if(pDoc->arclist[i].Hidden==TRUE) ss+="\nHidden in postprocessor";
				
			AfxMessageBox(ss,MB_ICONINFORMATION);
			pDoc->arclist[i].ToggleSelect();
			DrawPSLG();
		}
	}
	CView::OnRButtonDblClk(nFlags, point);
}

void CFemmeView::OnMakeMesh() 
{
	CFemmeDoc *TheDoc = GetDocument();

	ASSERT_VALID(TheDoc);
	CString pn = TheDoc->GetPathName();
	if (pn.GetLength()==0){
		AfxMessageBox("A data file must be loaded,\nor the current data must saved.",MB_OK | MB_ICONEXCLAMATION,0);
		return;
	}

	if (TheDoc->OnSaveDocument(pn)==FALSE) return;

	BeginWaitCursor();
	if (TheDoc->HasPeriodicBC()==TRUE){
		if (TheDoc->FunnyOnWritePoly()==FALSE){
			EndWaitCursor();
			TheDoc->UnselectAll();
			return;
		}
	}
	else{
		if (TheDoc->OnWritePoly()==FALSE){
			EndWaitCursor();
			return;
		}
	}
	BOOL LoadMesh=TheDoc->LoadMesh();
	EndWaitCursor();

	if(LoadMesh==TRUE){
		MeshUpToDate=TRUE;
		if(MeshFlag==FALSE) OnShowMesh();
		else InvalidateRect(NULL);
		CString s;
		s.Format("Created mesh with %i nodes",TheDoc->meshnode.GetSize());
		if (TheDoc->greymeshline.GetSize()!=0)
			s+="\nGrey mesh lines denote regions\nthat have no block label.";
		if(bLinehook==FALSE) AfxMessageBox(s,MB_ICONINFORMATION);
		else lua_pushnumber(lua,TheDoc->meshnode.GetSize());
	}
	
}

void CFemmeView::OnMenuAnalyze() 
{
	int i,j,k;
	CFemmeDoc *TheDoc = GetDocument();
	BOOL bFlag=FALSE;
	BOOL bExteriorDefined=TRUE;
	
	ASSERT_VALID(TheDoc);

	// check to see if all blocklabels are kosher...
	if (TheDoc->blocklist.GetSize()==0){
		AfxMessageBox("No block information has been defined\nCannot analyze the problem");
		return;
	}

	for(i=0,bFlag=FALSE;i<TheDoc->blocklist.GetSize();i++)
	{
		for(k=0,j=0;k<TheDoc->blockproplist.GetSize();k++)
			if (TheDoc->blocklist[i].BlockType!=TheDoc->blockproplist[k].BlockName) j++;
		if((j==TheDoc->blockproplist.GetSize()) && (TheDoc->blocklist[i].BlockType!="<No Mesh>"))
		{
			if(bFlag==FALSE) OnBlockOp();
			bFlag=TRUE;
			TheDoc->blocklist[i].IsSelected=TRUE;
		}
	}

	if(bFlag==TRUE){
			InvalidateRect(NULL);
			CString ermsg="Material properties have not\n";
			ermsg+=       "been defined for all block labels.\n";
			ermsg+=       "Cannot analyze the problem";
			AfxMessageBox(ermsg);
			return;
	}

	
	if(TheDoc->ProblemType==1)
	{
		// check to see if all of the input points are on r>=0 for axisymmetric problems.
		for(k=0;k<TheDoc->nodelist.GetSize();k++)
			if(TheDoc->nodelist[k].x<-(1.e-6))
			{
				InvalidateRect(NULL);
				CString ermsg="The problem domain must lie in\n";
				ermsg+=       "r>=0 for axisymmetric problems.\n";
				ermsg+=       "Cannot analyze the problem.";
				AfxMessageBox(ermsg);
				return;
			}

		// check to see if all block defined to be in an axisymmetric external region are linear.
		for(k=0;k<TheDoc->blocklist.GetSize();k++)
		{
			if(TheDoc->blocklist[k].IsExternal){

				if((TheDoc->extRo==0) || (TheDoc->extRi==0)) bExteriorDefined=FALSE;

				for(i=0;i<TheDoc->blockproplist.GetSize();i++)
					if(TheDoc->blocklist[k].BlockType==TheDoc->blockproplist[i].BlockName)
					{
						if(TheDoc->blockproplist[i].BHpoints!=0) bFlag=TRUE;
						else if(TheDoc->blockproplist[i].mu_x!=TheDoc->blockproplist[i].mu_y) bFlag=TRUE;
					}
			}
		}
		if(bFlag)
		{
			InvalidateRect(NULL);
			CString ermsg="Only linear istropic materials are\n";
			ermsg+=       "allowed in axisymmetric external regions.\n";
			ermsg+=       "Cannot analyze the problem";
			AfxMessageBox(ermsg);
			return;
		}

		if(!bExteriorDefined)
		{
			InvalidateRect(NULL);
			CString ermsg="Some block labels have been specific as placed in\n";
			ermsg+=       "an axisymmetric exterior region, but no properties\n";
			ermsg+=		  "have been adequately defined for the exterior region\n";
			ermsg+=       "Cannot analyze the problem";
			AfxMessageBox(ermsg);
			return;
		}
	}

	CString pn = TheDoc->GetPathName();
	if (pn.GetLength()==0){
		AfxMessageBox("A data file must be loaded,\nor the current data must saved.",MB_OK | MB_ICONEXCLAMATION,0);
		return;
	}
	if (TheDoc->OnSaveDocument(pn)==FALSE) return;
		
	BeginWaitCursor();
	if (TheDoc->HasPeriodicBC()==TRUE){
		if (TheDoc->FunnyOnWritePoly()==FALSE){
			EndWaitCursor();
			TheDoc->UnselectAll();
			return;
		}
	}
	else{
		if (TheDoc->OnWritePoly()==FALSE){
			EndWaitCursor();
			return;
		}
	}
	EndWaitCursor();

	char CommandLine[512];
	CString rootname="\"" + pn.Left(pn.ReverseFind('.')) + "\"";

	sprintf(CommandLine,"\"%sfkn.exe\" %s",BinDir,rootname);

	STARTUPINFO StartupInfo2 = {0};
	PROCESS_INFORMATION ProcessInfo2;
	StartupInfo2.cb = sizeof(STARTUPINFO);
	if(bLinehook==HiddenLua){
		StartupInfo2.dwFlags = STARTF_USESHOWWINDOW;
		//<DP> SHOWNOACTIVATE doesn't steal focus to others </DP>
		StartupInfo2.wShowWindow = SW_SHOWNOACTIVATE|SW_MINIMIZE;
	}
	if (CreateProcess(NULL,CommandLine, NULL, NULL, FALSE,
		0, NULL, NULL, &StartupInfo2, &ProcessInfo2))
	{		
		if(bLinehook!=FALSE)
		{
			DWORD ExitCode;
			TheDoc->hProc=ProcessInfo2.hProcess;
			do{
				GetExitCodeProcess(ProcessInfo2.hProcess,&ExitCode);
				TheDoc->line_hook(lua,NULL);	
			} while(ExitCode==STILL_ACTIVE);
			TheDoc->hProc=NULL;
		}
	}
	else
	{
		AfxMessageBox("Problem executing the solver");
		return;
	}
	
}

void CFemmeView::OnMenuViewres() 
{
    CFemmeDoc *TheDoc = GetDocument();

    ASSERT_VALID(TheDoc);
    CString pn = TheDoc->GetPathName();
    if (pn.GetLength()==0){
        AfxMessageBox("No results to display",MB_OK | MB_ICONEXCLAMATION,0);
        return;
    }

    CString rootname= "\"" + pn.Left(pn.ReverseFind('.'))+".ans\"";
    char CommandLine[512];

    sprintf(CommandLine,"\"%sfemmview.exe\" %s",BinDir,rootname);

    STARTUPINFO StartupInfo2 = {0};
    PROCESS_INFORMATION ProcessInfo2;
    StartupInfo2.cb = sizeof(STARTUPINFO);
    if (CreateProcess(NULL,CommandLine, NULL, NULL, FALSE,
        0, NULL, NULL, &StartupInfo2, &ProcessInfo2)){
    }
    else
    {
        AfxMessageBox("Problem executing the postprocessor");
        return;
    }
}

void CFemmeView::OnUndo() 
{
	CFemmeDoc *TheDoc = GetDocument();
	TheDoc->Undo();
	TheDoc->UnselectAll();
	InvalidateRect(NULL);
}

void CFemmeView::OnKbdZoom() 
{
	// TODO: Add your command handler code here
	CFemmeDoc *pDoc=GetDocument();
	CKbdZoom dlg;
	RECT r;
	double m[2],x[4],z;

	GetClientRect(&r);
	ScreenToDwg(r.right,r.top, &dlg.m_scr_right, &dlg.m_scr_top, &r);
	dlg.m_scr_top=floor(1000.*dlg.m_

⌨️ 快捷键说明

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