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

📄 femmelua.cpp

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

	x=lua_tonumber(L,1);
	y=lua_tonumber(L,2);

	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmeView *)thisDoc->GetNextView(pos);

//	if(thisDoc->Coords)
//	{
//		double r,t;
//		r=mx;
//		t=my*PI/180;
//		x=mx*cos(t);
//		y=mx*sin(t);
//	}

	if (thisDoc->nodelist.GetSize()<2) d=1.e-08;
	else{
		CComplex p0,p1,p2;
		p0=thisDoc->nodelist[0].CC();
		p1=p0;
		for(int i=1;i<thisDoc->nodelist.GetSize();i++)
		{
			p2=thisDoc->nodelist[i].CC();
			if(p2.re<p0.re) p0.re=p2.re;
			if(p2.re>p1.re) p1.re=p2.re;
			if(p2.im<p0.im) p0.im=p2.im;
			if(p2.im>p1.im) p1.im=p2.im;
		}
		d=abs(p1-p0)*1.e-06;
	}
	BOOL flag;
	flag=thisDoc->AddBlockLabel(x,y,d);
	
	if(flag==TRUE){
		theView->MeshUpToDate=FALSE;
		if(theView->MeshFlag==TRUE) theView->lnu_show_mesh();
		else theView->DrawPSLG();
	}

	return 0;
}


int CFemmeDoc::lua_addline(lua_State *L)
{
	
	CFemmeDoc * thisDoc;
	CFemmeView * theView;

	double sx,sy,ex,ey;

	sx=lua_tonumber(L,1);
	sy=lua_tonumber(L,2);

	ex=lua_tonumber(L,3);
	ey=lua_tonumber(L,4);

	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();

	theView=(CFemmeView *)thisDoc->GetNextView(pos);
	BOOL flag;

	flag=thisDoc->AddSegment(thisDoc->ClosestNode(sx,sy),thisDoc->ClosestNode(ex,ey));

	if(flag==TRUE)
	{
		theView->MeshUpToDate=FALSE;
		if(theView->MeshFlag==TRUE) theView->lnu_show_mesh();
		else theView->DrawPSLG(); 
	}
	else theView->DrawPSLG();
	
	return 0;
}

int CFemmeDoc::lua_addarc(lua_State *L)
{
	
	CFemmeDoc *thisDoc;
	CFemmeView *theView;
	
	double sx,sy,ex,ey;
	double angle,maxseg;

	sx=lua_tonumber(L,1);
	sy=lua_tonumber(L,2);
	ex=lua_tonumber(L,3);
	ey=lua_tonumber(L,4);

	angle=lua_tonumber(L,5);
	maxseg=lua_tonumber(L,6);

	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();

	theView=(CFemmeView *)thisDoc->GetNextView(pos);
	BOOL flag;

	CArcSegment asegm;
	asegm.n0=thisDoc->ClosestNode(sx,sy);
	asegm.n1=thisDoc->ClosestNode(ex,ey);
	thisDoc->nodelist[asegm.n1].ToggleSelect();
	theView->DrawPSLG();

	asegm.MaxSideLength=maxseg;
	asegm.ArcLength=angle;
	asegm.BoundaryMarker="<None>";

	flag=thisDoc->AddArcSegment(asegm);
	flag=FALSE;
	thisDoc->UnselectAll();
	if(flag==TRUE){
		theView->MeshUpToDate=FALSE;
		if(theView->MeshFlag==TRUE) theView->lnu_show_mesh();
		else theView->DrawPSLG(); 
	}
	else theView->DrawPSLG();
		
	return 0;
}

int CFemmeDoc::lua_selectnode(lua_State *L)
{
	
	CFemmeDoc *thisDoc;
	CFemmeView *theView;
	
	double mx,my;
	mx=lua_tonumber(L,1);
	my=lua_tonumber(L,2);
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmeView *)thisDoc->GetNextView(pos);

	int node;
	node=thisDoc->ClosestNode(mx,my);
	thisDoc->nodelist[node].ToggleSelect();

	lua_pushnumber(L,thisDoc->nodelist[node].x);
	lua_pushnumber(L,thisDoc->nodelist[node].y);

	return 2;
}

int CFemmeDoc::lua_selectlabel(lua_State *L)
{
	
	CFemmeDoc *thisDoc;
	CFemmeView *theView;

	double mx,my;
	mx=lua_tonumber(L,1);
	my=lua_tonumber(L,2);
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmeView *)thisDoc->GetNextView(pos);

	int node;
	node=thisDoc->ClosestBlockLabel(mx,my);
	thisDoc->blocklist[node].ToggleSelect();

	lua_pushnumber(L,thisDoc->blocklist[node].x);
	lua_pushnumber(L,thisDoc->blocklist[node].y);

	return 2;
}


int CFemmeDoc::lua_selectsegment(lua_State *L)
{	
	
	CFemmeDoc *thisDoc;
	CFemmeView *theView;

	double mx,my;
	mx=lua_tonumber(L,1);
	my=lua_tonumber(L,2);
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmeView *)thisDoc->GetNextView(pos);

	int node;
	node=thisDoc->ClosestSegment(mx,my);
	thisDoc->linelist[node].ToggleSelect();

	lua_pushnumber(L,thisDoc->nodelist[thisDoc->linelist[node].n0].x);  
	lua_pushnumber(L,thisDoc->nodelist[thisDoc->linelist[node].n0].y);  
	lua_pushnumber(L,thisDoc->nodelist[thisDoc->linelist[node].n1].x);  
	lua_pushnumber(L,thisDoc->nodelist[thisDoc->linelist[node].n1].y);  

	return 4;
}


int CFemmeDoc::lua_selectarcsegment(lua_State *L)
{
	
	CFemmeDoc *thisDoc;
	CFemmeView *theView;

	double mx,my;
	mx=lua_tonumber(L,1);
	my=lua_tonumber(L,2);
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmeView *)thisDoc->GetNextView(pos);

	int node;
	node=thisDoc->ClosestArcSegment(mx,my);
	thisDoc->arclist[node].ToggleSelect();

	lua_pushnumber(L,thisDoc->nodelist[thisDoc->arclist[node].n0].x);  
	lua_pushnumber(L,thisDoc->nodelist[thisDoc->arclist[node].n0].y);  
	lua_pushnumber(L,thisDoc->nodelist[thisDoc->arclist[node].n1].x);  
	lua_pushnumber(L,thisDoc->nodelist[thisDoc->arclist[node].n1].y);  

	return 4;
}

int CFemmeDoc::lua_clearselected(lua_State *L)
{
	
	CFemmeDoc *thisDoc;
	CFemmeView *theView;
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmeView *)thisDoc->GetNextView(pos);

	thisDoc->UnselectAll();
	return 0;
}

int CFemmeDoc::lua_setnodeprop(lua_State *L)
{
	
	CString nodeprop;
	int groupno;

	nodeprop.Format("%s",lua_tostring(L,1));
	groupno=(int) lua_tonumber(L,2);

	if (groupno<0)
	{
	CString msg;
	msg.Format("Invalid group no %d",groupno);
	lua_error(L,msg.GetBuffer(1));
	return 0;
	}

	CFemmeDoc *thisDoc=(CFemmeDoc *)pFemmeDoc;
	int i;

	// check to see how many (if any) nodes are selected.
	for(i=0;i<thisDoc->nodelist.GetSize();i++)
	{
		if(thisDoc->nodelist[i].IsSelected==TRUE)
		{
			thisDoc->nodelist[i].InGroup=groupno;
			thisDoc->nodelist[i].BoundaryMarker=nodeprop;
		}			
	}

	return 0;
}

int CFemmeDoc::lua_setblockprop(lua_State *L)
{
	
	CString blocktype,incircuit;
	BOOL automesh;
	double meshsize,magdirection;
	int group,turns;

	int n=lua_gettop(L);

	blocktype.Format("%s",lua_tostring(L,1));
	automesh=(int) lua_tonumber(L,2);
	meshsize=lua_tonumber(L,3);
	incircuit.Format("%s",lua_tostring(L,4));
	magdirection=lua_tonumber(L,5);
	group=(int) lua_tonumber(L,6);
	// catch optional last term for backward-compat.
	if(n>6){
		turns=(int) lua_tonumber(L,7);
		if (turns<1) turns=1;
	}
	else turns=1;

	

	CFemmeDoc *thisDoc=(CFemmeDoc *)pFemmeDoc;
	int i;	

	for(i=0;i<thisDoc->blocklist.GetSize();i++)
	{
		if(thisDoc->blocklist[i].IsSelected==TRUE)
		{
			thisDoc->blocklist[i].MaxArea=PI*meshsize*meshsize/4.;
			thisDoc->blocklist[i].MagDir=magdirection;
			thisDoc->blocklist[i].BlockType=blocktype;
			thisDoc->blocklist[i].InCircuit=incircuit;
			thisDoc->blocklist[i].InGroup=group;
			thisDoc->blocklist[i].Turns=turns;
			if(automesh==1) thisDoc->blocklist[i].MaxArea=0;
		}
	}
	
	return 0;
}

int CFemmeDoc::lua_setsegmentprop(lua_State *L)
{
	
	CString prop;
	double elesize;
	int automesh,hide,group;

	prop.Format("%s",lua_tostring(L,1));
	elesize=lua_tonumber(L,2);
	automesh=(int) lua_tonumber(L,3);
	hide=(int) lua_tonumber(L,4);
	group=(int) lua_tonumber(L,5);

	CFemmeDoc *thisDoc=(CFemmeDoc *)pFemmeDoc;

	for(int i=0;i<thisDoc->linelist.GetSize();i++)
	{
		if(thisDoc->linelist[i].IsSelected==TRUE){
			if (automesh==1) thisDoc->linelist[i].MaxSideLength=-1;
			else{
				if (elesize>0) 
					thisDoc->linelist[i].MaxSideLength=elesize;
				else elesize=-1;
			}
			thisDoc->linelist[i].BoundaryMarker=prop;
			thisDoc->linelist[i].Hidden=hide;
			thisDoc->linelist[i].InGroup=group;
		}
	}

	return 0;
}

int CFemmeDoc::lua_setarcsegmentprop(lua_State *L)
{
	
	CString boundprop;
	double maxsegdeg;
	int hide,group;

	maxsegdeg=lua_tonumber(L,1);
	boundprop.Format("%s",lua_tostring(L,2));
	hide=(int) lua_tonumber(L,3);
	group=(int) lua_tonumber(L,4);
	
	CFemmeDoc *thisDoc=(CFemmeDoc *)pFemmeDoc;
	int i;

	for(i=0;i<thisDoc->arclist.GetSize();i++)
	{
		if(thisDoc->arclist[i].IsSelected==TRUE){
			thisDoc->arclist[i].BoundaryMarker=boundprop;
			thisDoc->arclist[i].MaxSideLength=maxsegdeg;
			thisDoc->arclist[i].Hidden=hide;
			thisDoc->arclist[i].InGroup=group;
		}
	}

	return 0;
}

int CFemmeDoc::lua_deleteselectednodes(lua_State *L)
{
	
	CFemmeDoc * thisDoc;
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	thisDoc->DeleteSelectedNodes();
	return 0;
}

int CFemmeDoc::lua_deleteselectedlabels(lua_State *L)
{
	
	CFemmeDoc * thisDoc;
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	thisDoc->DeleteSelectedBlockLabels();
	return 0;
}

int CFemmeDoc::lua_deleteselectedsegments(lua_State *L)
{
	
	CFemmeDoc * thisDoc;
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	thisDoc->DeleteSelectedSegments();
	return 0;
}

int CFemmeDoc::lua_deleteselectedarcsegments(lua_State *L)
{
	
	CFemmeDoc *thisDoc;
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	thisDoc->DeleteSelectedArcSegments();
	return 0;
}

int CFemmeDoc::lua_deleteselected(lua_State *L)
{
	
	CFemmeDoc *thisDoc;
	thisDoc=(CFemmeDoc *)pFemmeDoc;

	thisDoc->DeleteSelectedSegments();
	thisDoc->DeleteSelectedArcSegments();
	thisDoc->DeleteSelectedNodes();
	thisDoc->DeleteSelectedBlockLabels();	
	
	return 0;
}

int CFemmeDoc::lua_newdocument(lua_State *L)
{
	
	CFemmeDoc * thisDoc;
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	thisDoc->OnNewDocument();
	thisDoc->SetPathName("Untitled",FALSE);
	thisDoc->SetTitle("Untitled");
	return 0;
}


int CFemmeDoc::lua_zoomnatural(lua_State *L)
{
	
	CFemmeDoc * thisDoc;
	CFemmeView * theView;
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmeView *)thisDoc->GetNextView(pos);
	theView->lua_zoomnatural();

	return 0;
}


int CFemmeDoc::lua_zoomout(lua_State *L)
{
	
	CFemmeDoc *thisDoc;
	CFemmeView *theView;
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmeView *)thisDoc->GetNextView(pos);

	theView->lua_zoomout();
	
	return 0;
}

int CFemmeDoc::lua_zoomin(lua_State *L)
{
	
	CFemmeDoc *thisDoc;
	CFemmeView *theView;
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmeView *)thisDoc->GetNextView(pos);
	theView->lua_zoomin();

//	PostMessage(theView->m_hWnd,WM_COMMAND,0,ID_ZOOM_IN);
// it would be nice to use messages but I need to check the format first
// this would cut down on code used twice and some unnecessary code !

	
	return 0;
}

int CFemmeDoc::lua_zoom(lua_State *L)
{
	
	
	double x[2],y[2],m[2];

	x[0]=lua_tonumber(L,1);
	y[0]=lua_tonumber(L,2);
	x[1]=lua_tonumber(L,3);
	y[1]=lua_tonumber(L,4);
	
	CFemmeDoc * thisDoc;CFemmeView * theView;
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmeView *)thisDoc->GetNextView(pos);

	CRect r;

⌨️ 快捷键说明

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