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

📄 movecopy.cpp

📁 一个2D电磁场FEM计算的VC++源程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	}

	if(EditAction==1)
	{
		for(i=0;i<linelist.GetSize();i++)
		{
			if(linelist[i].IsSelected==TRUE){
				nodelist[linelist[i].n0].IsSelected=TRUE;
				nodelist[linelist[i].n1].IsSelected=TRUE;
			}
		}
		ScaleMove(bx,by,sf,0);
		return;
	}

	if(EditAction==2)
	{
		for(i=0;i<blocklist.GetSize();i++)
		{
			if(blocklist[i].IsSelected==TRUE){
				blocklist[i].x=bx+sf*(blocklist[i].x-bx);
				blocklist[i].y=by+sf*(blocklist[i].y-by);
				blocklist[i].MaxArea*=(sf*sf);
			}
		}
		EnforcePSLG();
		return;
	}

	if(EditAction==3)
	{
		for(i=0;i<arclist.GetSize();i++)
		{
			if(arclist[i].IsSelected==TRUE){
				nodelist[arclist[i].n0].IsSelected=TRUE;
				nodelist[arclist[i].n1].IsSelected=TRUE;
			}
		}
		ScaleMove(bx,by,sf,0);
		return;
	}

	if(EditAction==4)
	{
		for(i=0;i<linelist.GetSize();i++)
		{
			if(linelist[i].IsSelected==TRUE){
				nodelist[linelist[i].n0].IsSelected=TRUE;
				nodelist[linelist[i].n1].IsSelected=TRUE;
			}
		}
		
		for(i=0;i<arclist.GetSize();i++)
		{
			if(arclist[i].IsSelected==TRUE){
				nodelist[arclist[i].n0].IsSelected=TRUE;
				nodelist[arclist[i].n1].IsSelected=TRUE;
			}
		}
		
		for(i=0;i<nodelist.GetSize();i++)
		{
			if(nodelist[i].IsSelected==TRUE){
				nodelist[i].x=bx+sf*(nodelist[i].x-bx);
				nodelist[i].y=by+sf*(nodelist[i].y-by);
			}
		}

		for(i=0;i<blocklist.GetSize();i++)
		{
			if(blocklist[i].IsSelected==TRUE){
				blocklist[i].x=bx+sf*(blocklist[i].x-bx);
				blocklist[i].y=by+sf*(blocklist[i].y-by);
				blocklist[i].MaxArea*=(sf*sf);
			}
		}
		
		EnforcePSLG();
		return;
		
	}


}


void CFemmeDoc::MirrorSelected(double x0, double y0, double x1, double y1, int EditAction)
{
	int i,j,k;
	CComplex x,p,y;
  
	x=x0 + I*y0;
	p=(x1-x0) + I*(y1-y0);
	if(abs(p)==0) return;
	p/=abs(p);  

    if(EditAction==0)
    {
		CNode node;
		k=nodelist.GetSize();
		for(i=0;i<k;i++)
		{
			if(nodelist[i].IsSelected==TRUE){
				node=nodelist[i];
				y=((node.x + I*node.y) - x)/p;
				y=p*y.Conj()+x;
				node.x=y.re;
				node.y=y.im;
				node.IsSelected=FALSE;
				nodelist.Add(node);
			}
		}
	}

	if(EditAction==1)
	{
		CSegment segm;
		CNode n0,n1;
		k=linelist.GetSize();
		for(i=0;i<k;i++)
		{
			if(linelist[i].IsSelected==TRUE){
				n0=nodelist[linelist[i].n0];
				n1=nodelist[linelist[i].n1];
				
				y=((n0.x + I*n0.y) - x)/p;
				y=p*y.Conj()+x;
				n0.x=y.re;
				n0.y=y.im;

				y=((n1.x + I*n1.y) - x)/p;
				y=p*y.Conj()+x;
				n1.x=y.re;
				n1.y=y.im;

				j=nodelist.GetSize();
				segm=linelist[i];
				segm.n0=j; segm.n1=j+1;
				segm.IsSelected=FALSE;
				nodelist.Add(n0);
				nodelist.Add(n1);
				linelist.Add(segm);
			}
		}
	}

	if(EditAction==2)
	{
		CBlockLabel lbl;
		k=blocklist.GetSize();
		for(i=0;i<k;i++)
		{
			if(blocklist[i].IsSelected==TRUE){
				lbl=blocklist[i];
				y=((lbl.x + I*lbl.y)-x)/p;
				y=p*y.Conj()+x;
				lbl.x=y.re;
				lbl.y=y.im;
				lbl.MagDir=(180./PI)*arg(p*conj(exp(I*lbl.MagDir*PI/180.)/p));
				lbl.IsSelected=FALSE;
				blocklist.Add(lbl);
			}
		}
	}

	if(EditAction==3)
	{
		CArcSegment asegm;
		CNode n0,n1;
		k=arclist.GetSize();
		for(i=0;i<k;i++)
		{
			if(arclist[i].IsSelected==TRUE){
				n0=nodelist[arclist[i].n1];
				n1=nodelist[arclist[i].n0];
							
				y=((n0.x + I*n0.y) - x)/p;
				y=p*y.Conj()+x;
				n0.x=y.re;
				n0.y=y.im;
				n0.IsSelected=FALSE;

				y=((n1.x + I*n1.y) - x)/p;
				y=p*y.Conj()+x;
				n1.x=y.re;
				n1.y=y.im;
				n1.IsSelected=FALSE;

				j=nodelist.GetSize();
				asegm=arclist[i];
				asegm.n0=j; asegm.n1=j+1;
				asegm.IsSelected=FALSE;
				nodelist.Add(n0);
				nodelist.Add(n1);
				arclist.Add(asegm);
			}
		}
		
	}

    if(EditAction==4)
	{
		CNode node;
		k=nodelist.GetSize();
		for(i=0;i<k;i++)
		{
			if(nodelist[i].IsSelected==TRUE){
				node=nodelist[i];
				y=((node.x + I*node.y) - x)/p;
				y=p*y.Conj()+x;
				node.x=y.re;
				node.y=y.im;
				node.IsSelected=FALSE;
				nodelist.Add(node);
			}
		}
	
		CSegment segm;
		CNode n0,n1;
		k=linelist.GetSize();
		for(i=0;i<k;i++)
		{
			if(linelist[i].IsSelected==TRUE){
				n0=nodelist[linelist[i].n0];
				n1=nodelist[linelist[i].n1];
				
				y=((n0.x + I*n0.y) - x)/p;
				y=p*y.Conj()+x;
				n0.x=y.re;
				n0.y=y.im;

				y=((n1.x + I*n1.y) - x)/p;
				y=p*y.Conj()+x;
				n1.x=y.re;
				n1.y=y.im;

				j=nodelist.GetSize();
				segm=linelist[i];
				segm.n0=j; segm.n1=j+1;
				segm.IsSelected=FALSE;
				nodelist.Add(n0);
				nodelist.Add(n1);
				linelist.Add(segm);
			}
		}
	
		CBlockLabel lbl;
		k=blocklist.GetSize();
		for(i=0;i<k;i++)
		{
			if(blocklist[i].IsSelected==TRUE){
				lbl=blocklist[i];
				y=((lbl.x + I*lbl.y)-x)/p;
				y=p*y.Conj()+x;
				lbl.x=y.re;
				lbl.y=y.im;
				lbl.MagDir=(180./PI)*arg(p*conj(exp(I*lbl.MagDir*PI/180.)/p));
				lbl.IsSelected=FALSE;
				blocklist.Add(lbl);
			}
		}
	
		CArcSegment asegm;
		k=arclist.GetSize();
		for(i=0;i<k;i++)
		{
			if(arclist[i].IsSelected==TRUE){
				n0=nodelist[arclist[i].n1];
				n1=nodelist[arclist[i].n0];
							
				y=((n0.x + I*n0.y) - x)/p;
				y=p*y.Conj()+x;
				n0.x=y.re;
				n0.y=y.im;
				n0.IsSelected=FALSE;

				y=((n1.x + I*n1.y) - x)/p;
				y=p*y.Conj()+x;
				n1.x=y.re;
				n1.y=y.im;
				n1.IsSelected=FALSE;

				j=nodelist.GetSize();
				asegm=arclist[i];
				asegm.n0=j; asegm.n1=j+1;
				asegm.IsSelected=FALSE;
				nodelist.Add(n0);
				nodelist.Add(n1);
				arclist.Add(asegm);
			}
		}
		
	}

  EnforcePSLG();
  return;
}

BOOL CFemmeDoc::dxf_line_hook()
{
    MSG msg;

	while ( ::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
	{ 
		if ((msg.message == WM_KEYDOWN) && (msg.wParam == VK_PAUSE))
		{
			MessageBeep(MB_ICONEXCLAMATION);
			return TRUE;
		}
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return FALSE;
}
  
void CFemmeDoc::FancyEnforcePSLG(double tol)
{
	/*  
		need to enforce:
		1) no duplicate point;
		2) no intersections between line segments, lines and arcs, or arcs;
		3) no duplicate block labels;
		4) no overlapping lines or arcs.

		can do this by cleaning out the various lists, and rebuilding them
		using the ``add'' functions that ensure that things come out right.
	*/

	CArray< CNode, CNode&>             newnodelist;
	CArray< CSegment, CSegment&>       newlinelist;
	CArray< CArcSegment, CArcSegment&> newarclist;
	CArray< CBlockLabel, CBlockLabel&> newblocklist;
	int i,k;
	CComplex p0,p1;
	double d;

	bNoClose=TRUE;  // kludge to stop the program from giving a crash if
					// the user tries to exit during a dxf import.

	CFemmeView *pView;
	POSITION pos;
	pos=GetFirstViewPosition();
	pView=(CFemmeView *)GetNextView(pos);

	FirstDraw=TRUE;
//	pView->lua_zoomnatural();
	dxf_line_hook();
	pView->EditAction=4;

	newnodelist.RemoveAll();
	newlinelist.RemoveAll();
	newarclist.RemoveAll();
	newblocklist.RemoveAll();

	for(i=0;i<nodelist.GetSize();i++) newnodelist.Add(nodelist[i]);
	for(i=0;i<linelist.GetSize();i++) newlinelist.Add(linelist[i]);
	for(i=0;i<arclist.GetSize();i++) newarclist.Add(arclist[i]);
	for(i=0;i<blocklist.GetSize();i++) newblocklist.Add(blocklist[i]);

	nodelist.RemoveAll();
	linelist.RemoveAll();
	arclist.RemoveAll();
	blocklist.RemoveAll();
	
	pView->InvalidateRect(NULL);
	dxf_line_hook();

	// find out what tolerance is so that there are not nodes right on
	// top of each other;
	if(tol==0){
		if (newnodelist.GetSize()<2) d=1.e-08;
		else{
			p0=newnodelist[0].CC();
			p1=p0;
			for(i=1;i<newnodelist.GetSize();i++)
			{
				if(newnodelist[i].x<p0.re) p0.re=newnodelist[i].x;
				if(newnodelist[i].x>p1.re) p1.re=newnodelist[i].x;
				if(newnodelist[i].y<p0.im) p0.im=newnodelist[i].y;
				if(newnodelist[i].y>p1.im) p1.im=newnodelist[i].y;
			}
			d=abs(p1-p0)*1.e-06;
		}
	}
	else d=tol;

	// put in all of the lines;
	for(i=0;i<newlinelist.GetSize();i++)
	{
		// Add in endpoints of the proposed line;
		AddNode(newnodelist[newlinelist[i].n0],d);
		AddNode(newnodelist[newlinelist[i].n1],d);

		// Add in the proposed line itself;
		p0=newnodelist[newlinelist[i].n0].CC();
		p1=newnodelist[newlinelist[i].n1].CC();
		if(AddSegment(p0,p1,newlinelist[i],d)==TRUE)
		{
			pView->DrawPSLG();	
			if(dxf_line_hook()){
				bNoClose=FALSE;
				return;
			}
		}
	}

	// put in all of the arcs;
	for(i=0;i<newarclist.GetSize();i++)
	{

		// Add in endpoints of the proposed line;
		AddNode(newnodelist[newarclist[i].n0],d);
		AddNode(newnodelist[newarclist[i].n1],d);

		// Add in the proposed arc inself;
		p0=newnodelist[newarclist[i].n0].CC();
		p1=newnodelist[newarclist[i].n1].CC();
		if(AddArcSegment(p0,p1,newarclist[i],d)==TRUE)
		{
			pView->DrawPSLG();	
			if(dxf_line_hook()){
				bNoClose=FALSE;
				return;
			}
		}
	}

	UnselectAll();

	// do one last check to eliminate shallow arcs that
	// link up the same two points as a line segment;
	for(i=0;i<arclist.GetSize();i++)
	{
		if (arclist[i].ArcLength<=22.5)
		{
			for(k=0;k<linelist.GetSize();k++)
			{
				if ((arclist[i].n0==linelist[k].n0) &&
					(arclist[i].n1==linelist[k].n1)) 
					arclist[i].IsSelected=TRUE;
				if ((arclist[i].n1==linelist[k].n0) &&
					(arclist[i].n0==linelist[k].n1)) 
					arclist[i].IsSelected=TRUE;
				if (arclist[i].IsSelected) k=linelist.GetSize();
			}
		}
	}
	DeleteSelectedArcSegments();

	// put in all of the block labels;
	for(i=0;i<newblocklist.GetSize();i++) AddBlockLabel(newblocklist[i],d);

	if(SelectOrphans())
	{
		CString msg;
		msg ="There are lines or arcs with \"Orphaned\" end points.\n";
		msg+="The lines or arcs could be glitches in the DXF import\n";
		msg+="import, so they should be examined manually.\n";
		msg+="These points and lines will be shown as selected.\n";
		msg+="To redisplay the orphaned points and lines, select\n";
		msg+="View|Show Orphans off of the main menu.";
		AfxMessageBox(msg);
	}

	bNoClose=FALSE;

	return;
}


BOOL CFemmeDoc::SelectOrphans()
{
	int i;
	BOOL bHasOrphans;

	UnselectAll();

	// figure out if there are any orphan segments or arcs
	// and select them so that the will be visible to the user
	// We will first figure out which nodes are elements of only
	// one line or arc.  Then, we will select the lines and arcs
	// that are associated with these orphaned nodes
	for(i=0;i<linelist.GetSize();i++)
	{
		nodelist[linelist[i].n0].IsSelected++;
		nodelist[linelist[i].n1].IsSelected++;
	}
	for(i=0;i<arclist.GetSize();i++)
	{
		nodelist[arclist[i].n0].IsSelected++;
		nodelist[arclist[i].n1].IsSelected++;
	}
	for(i=0,bHasOrphans=FALSE;i<nodelist.GetSize();i++)
	{
		if (nodelist[i].IsSelected!=1) nodelist[i].IsSelected=FALSE;
		else bHasOrphans=TRUE;
	}
	if(bHasOrphans)
	{
		// We _have_ orphaned nodes.  Select their associated
		// lines and/or arcs, and give the user a message about it.
		for(i=0;i<linelist.GetSize();i++)
		{
			if(nodelist[linelist[i].n0].IsSelected)
				linelist[i].IsSelected=TRUE;
			if(nodelist[linelist[i].n1].IsSelected)
				linelist[i].IsSelected=TRUE;
		}
		for(i=0;i<arclist.GetSize();i++)
		{
			if(nodelist[arclist[i].n0].IsSelected)
				arclist[i].IsSelected=TRUE;
			if(nodelist[arclist[i].n1].IsSelected)
				arclist[i].IsSelected=TRUE;
		}	
	}

	return bHasOrphans;
}

⌨️ 快捷键说明

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