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

📄 femmelua.cpp

📁 一个2D电磁场FEM计算的VC++源程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	theView->ox=x[0]; theView->oy=y[0];
	theView->GetClientRect(&r);
	m[0]=((double) (r.right-1))/(x[1]-x[0]);
	m[1]=((double) (r.bottom-1))/(y[1]-y[0]);

	if(m[0]<m[1]) theView->mag=m[0];
	else theView->mag=m[1];

	theView->Invalidate(TRUE);
	return 0;
}


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

	int n;
	n=lua_gettop(L);
	// IF N=5 WE Have an edit action, if n=4 we dont !

	int EditAction,copies;

	double x,y,angle;
	x=lua_tonumber(L,1);
	y=lua_tonumber(L,2);
	angle=lua_tonumber(L,3);
	copies=(int) lua_tonumber(L,4);

	if (n==5) EditAction=(int) lua_tonumber(L,5);
	if (n==4) EditAction=theView->EditAction;

	if(n!=4 && n!=5)
	{
		CString msg;
		msg.Format("Invalid number of parameters for copy rotate");
		lua_error(L,msg.GetBuffer(1));
		return 0;
	}
	
	thisDoc->RotateCopy(CComplex(x,y),angle,copies,EditAction);		
	thisDoc->meshnode.RemoveAll();
	thisDoc->meshline.RemoveAll();
	thisDoc->greymeshline.RemoveAll();
	theView->MeshFlag=FALSE;
	theView->MeshUpToDate=FALSE;
	theView->InvalidateRect(NULL);

	return 0;
}

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

	int n;
	n=lua_gettop(L);

	int EditAction, copies;
	double x,y;
	x=lua_tonumber(L,1);
	y=lua_tonumber(L,2);
	copies=(int) lua_tonumber(L,3);

	if (n==4) EditAction=(int) lua_tonumber(L,4);
	if (n==3) EditAction=theView->EditAction;

	if(n!=4 && n!=3)
	{
		CString msg;
		msg.Format("Invalid number of parameters for copy translate");
		lua_error(L,msg.GetBuffer(1));
		return 0;
	}


	thisDoc->UpdateUndo();
	thisDoc->TranslateCopy(x,y,copies,EditAction);
	thisDoc->meshnode.RemoveAll();
	thisDoc->meshline.RemoveAll();
	thisDoc->greymeshline.RemoveAll();
	theView->MeshFlag=FALSE;
	theView->MeshUpToDate=FALSE;
	theView->InvalidateRect(NULL);

	return 0;
}


int CFemmeDoc::lua_move_translate(lua_State *L)
{
	
	
	double x,y;
	int EditAction;

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

	int n;
	n=lua_gettop(L);

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

	if (n==3) EditAction=(int) lua_tonumber(L,3);
	if (n==2) EditAction=theView->EditAction;

		if(n!=3 && n!=2)
	{
		CString msg;
		msg.Format("Invalid number of parameters for move translate");
		lua_error(L,msg.GetBuffer(1));
		return 0;
	}


	{
			thisDoc->UpdateUndo();
			thisDoc->TranslateMove(x,y,EditAction);
			thisDoc->meshnode.RemoveAll();
			thisDoc->meshline.RemoveAll();
			thisDoc->greymeshline.RemoveAll();
			theView->MeshFlag=FALSE;
			theView->MeshUpToDate=FALSE;
			theView->InvalidateRect(NULL);
	}

	return 0;
}

int CFemmeDoc::lua_move_rotate(lua_State *L)
{
	
	
	double x,y,shiftangle;
	int EditAction;

	int n;
	n=lua_gettop(L);

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

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

	if (n==4) EditAction=(int) lua_tonumber(L,4);
	if (n==3) EditAction=theView->EditAction;

	if(n!=4 && n!=3)
	{
		CString msg;
		msg.Format("Invalid number of parameters for move rotate");
		lua_error(L,msg.GetBuffer(1));
		return 0;
	}


	{
		thisDoc->UpdateUndo();
		thisDoc->RotateMove(CComplex(x,y),shiftangle,EditAction);
		thisDoc->meshnode.RemoveAll();
		thisDoc->meshline.RemoveAll();
		thisDoc->greymeshline.RemoveAll();
		theView->MeshFlag=FALSE;
		theView->MeshUpToDate=FALSE;
		theView->InvalidateRect(NULL);
	}

	return 0;
}


int CFemmeDoc::lua_mirror(lua_State *L)
{
	
	double m_pax,m_pay,m_pbx,m_pby;
	int EditAction;

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

	int n;
	n=lua_gettop(L);

	m_pax=lua_tonumber(L,1);
	m_pay=lua_tonumber(L,2);
	m_pbx=lua_tonumber(L,3);
	m_pby=lua_tonumber(L,4);

	if (n==5) EditAction=(int) lua_tonumber(L,5);
	if (n==4) EditAction=theView->EditAction;

	if(n!=4 && n!=5)
	{
		CString msg;
		msg.Format("Invalid number of parameters for mirror");
		lua_error(L,msg.GetBuffer(1));
		return 0;
	}


	thisDoc->UpdateUndo();
	thisDoc->MirrorSelected(m_pax,m_pay,m_pbx,m_pby,EditAction);
	theView->InvalidateRect(NULL);

	return 0;
}

int CFemmeDoc::lua_scale(lua_State *L)
{
	
	int EditAction;
	double x,y,scalefactor;

	int n;
	n=lua_gettop(L);

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

	x=lua_tonumber(L,1);
	y=lua_tonumber(L,2);
	scalefactor=lua_tonumber(L,3);
	EditAction=(int) lua_tonumber(L,4);

	if (n==4) EditAction=(int) lua_tonumber(L,4);
	if (n==3) EditAction=theView->EditAction;

		if(n!=4 && n!=3)
	{
		CString msg;
		msg.Format("Invalid number of parameters for scale");
		lua_error(L,msg.GetBuffer(1));
		return 0;
	}


	thisDoc->UpdateUndo();
	thisDoc->ScaleMove(x,y,scalefactor,EditAction);
	theView->InvalidateRect(NULL);

	return 0;
}


int CFemmeDoc::lua_seteditmode(lua_State *L)
{
	
	CString EditAction;
	
	EditAction.Format("%s",lua_tostring(L,1));
	EditAction.MakeLower();

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

	int iEditAction;
	iEditAction=-1;

	if (EditAction=="nodes") iEditAction=0;
	if (EditAction=="segments") iEditAction=1;
	if (EditAction=="blocks") iEditAction=2;
	if (EditAction=="arcsegments") iEditAction=3;
	if (EditAction=="group") iEditAction=4;

	if(iEditAction==-1)
	{
		CString msg;
		msg.Format("Invalid Edit Action %s",EditAction);
		lua_error(L,msg.GetBuffer(1));
		return 0;
	}
	else
	{
		theView->EditAction=iEditAction;
	}


	return 0;
}

int CFemmeDoc::lua_selectgroup(lua_State *L)
{
	
	
	int group,i;
	group=(int) lua_tonumber(L,1);

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


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

//	thisDoc->UnselectAll();

	// select nodes
	for(i=0;i<thisDoc->nodelist.GetSize();i++)
	{
		if(thisDoc->nodelist[i].InGroup==group)
			thisDoc->nodelist[i].IsSelected=TRUE;
	}

	// select segments
	for(i=0;i<thisDoc->linelist.GetSize();i++)
	{
		if(thisDoc->linelist[i].InGroup==group)
			thisDoc->linelist[i].IsSelected=TRUE;
	}

	// select arc segments
	for(i=0;i<thisDoc->arclist.GetSize();i++)
	{
		if(thisDoc->arclist[i].InGroup==group)
			thisDoc->arclist[i].IsSelected=TRUE;
	}

	// select blocks
	for(i=0;i<thisDoc->blocklist.GetSize();i++)
	{
		if(thisDoc->blocklist[i].InGroup==group)
		thisDoc->blocklist[i].IsSelected=TRUE;
	}


	theView->EditAction=4; // set to group

	return 0;
}


int CFemmeDoc::lua_addmatprop(lua_State *L)
{
	

	CMaterialProp m;
	int n=lua_gettop(L);
	
	if (n>0)  m.BlockName.Format("%s",lua_tostring(L,1));
	if (n>1){
			m.mu_x=lua_tonumber(L,2);
			m.mu_y=m.mu_x;
	}
	if (n>2)  m.mu_y=lua_tonumber(L,3);
	if (n>3)  m.H_c=lua_tonumber(L,4);
	if (n>4)  m.Jr=lua_tonumber(L,5);
	if (n>5)  m.Ji=lua_tonumber(L,6);
	if (n>6)  m.Cduct=lua_tonumber(L,7);
	if (n>7)  m.Lam_d=lua_tonumber(L,8);
	if (n>8)  m.Theta_hn=lua_tonumber(L,9);
	if (n>9)  m.LamFill=lua_tonumber(L,10);
	if (n>10) m.LamType=(int) lua_tonumber(L,11);
	if(n>11)
	{
		m.Theta_hx=lua_tonumber(L,12);
		m.Theta_hy=lua_tonumber(L,13);
	}
	else{
		m.Theta_hx=m.Theta_hn;
		m.Theta_hy=m.Theta_hn;
	}
	if(n>13){
		m.NStrands=(int) lua_tonumber(L,14);
		m.WireD=lua_tonumber(L,15);
	}

	((CFemmeDoc *)pFemmeDoc)->blockproplist.Add(m);
	
	return 0;
}

int CFemmeDoc::lua_addbhpoint(lua_State *L)
{
	
	CString BlockName;
	int j,k,n;

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

	// find the index of the material to modify;
	if (thisDoc->blockproplist.GetSize()==0) return TRUE;
	BlockName.Format("%s",lua_tostring(L,1));
	for(k=0;k<thisDoc->blockproplist.GetSize();k++)
		if(BlockName==thisDoc->blockproplist[k].BlockName) break;
	
	// get out of here if there's no matching material
	if(k==thisDoc->blockproplist.GetSize()) return TRUE;
	
	// now, add the bhpoint for the specified material;
	n=thisDoc->blockproplist[k].BHpoints;
	CComplex *newBHdata=(CComplex *)calloc(n+1,sizeof(CComplex));
	for(j=0;j<n;j++) newBHdata[j]=thisDoc->blockproplist[k].BHdata[j];
	thisDoc->blockproplist[k].BHpoints=n+1;
	if (n!=0) free(thisDoc->blockproplist[k].BHdata);
	thisDoc->blockproplist[k].BHdata=newBHdata;
	newBHdata[n]=lua_tonumber(L,2)+I*lua_tonumber(L,3);

	return 0;
}

int CFemmeDoc::lua_clearbhpoints(lua_State *L)
{
	
	CString BlockName;
	int k;

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

	// find the index of the material to modify;
	if (thisDoc->blockproplist.GetSize()==0) return TRUE;
	BlockName.Format("%s",lua_tostring(L,1));
	for(k=0;k<thisDoc->blockproplist.GetSize();k++)
		if(BlockName==thisDoc->blockproplist[k].BlockName) break;
	
	// get out of here if there's no matching material
	if(k==thisDoc->blockproplist.GetSize()) return TRUE;
	
	// now, snuff the BH curve for the specified material
	if (thisDoc->blockproplist[k].BHpoints>0)
	{
		thisDoc->blockproplist[k].BHpoints=0;
		free(thisDoc->blockproplist[k].BHdata);
		thisDoc->blockproplist[k].BHdata=NULL;
	}
	
	return 0;
}

int CFemmeDoc::lua_modmatprop(lua_State *L)
{
	
	CString BlockName;
	int k,modprop;

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

	// find the index of the material to modify;
	if (thisDoc->blockproplist.GetSize()==0) return TRUE;
	BlockName.Format("%s",lua_tostring(L,1));
	for(k=0;k<thisDoc->blockproplist.GetSize();k++)
		if(BlockName==thisDoc->blockproplist[k].BlockName) break;
	
	// get out of here if there's no matching material
	if(k==thisDoc->blockproplist.GetSize()) return TRUE;

	modprop=(int) lua_tonumber(L,2);
	
	// now, modify the specified attribute...
	switch(modprop)
	{
		case 0:
			thisDoc->blockproplist[k].BlockName.Format("%s",lua_tostring(L,3));
			break;
		case 1:
			thisDoc->blockproplist[k].mu_x=lua_tonumber(L,3);
			break;
		case 2:
			thisDoc->blockproplist[k].mu_y=lua_tonumber(L,3);
			break;

⌨️ 快捷键说明

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