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

📄 femmviewlua.cpp

📁 一个2D电磁场FEM计算的VC++源程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	lua_pushnumber(L,z.im);

	return 2;
}

int CFemmviewDoc::lua_zoomin(lua_State * L)
{
	
	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);
	
	RECT r;
	double x,y;

	theView->GetClientRect(&r);
	x=r.right; y=r.bottom;

	theView->ox=theView->ox+0.25*x/theView->mag;
	theView->oy=theView->oy+0.25*y/theView->mag;
	theView->mag*=2.;

	theView->RedrawView();

	
	
	
	return 0;
}

int CFemmviewDoc::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);

	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);

	CRect r;

	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];

	return 0;
}


int CFemmviewDoc::lua_zoomnatural(lua_State * L)
{
	
	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);


	CFemmviewDoc *pDoc=theView->GetDocument();
	double x[2],y[2],m[2],w;
	RECT r;
	int i;

	if (pDoc->meshnode.GetSize()<2) return 0;
	x[0]=pDoc->meshnode[0].x;	x[1]=pDoc->meshnode[0].x;
	y[0]=pDoc->meshnode[0].y;	y[1]=pDoc->meshnode[0].y;
	for(i=1;i<pDoc->meshnode.GetSize();i++)
	{
		if(pDoc->meshnode[i].x<x[0]) x[0]=pDoc->meshnode[i].x;
		if(pDoc->meshnode[i].x>x[1]) x[1]=pDoc->meshnode[i].x;
		if(pDoc->meshnode[i].y<y[0]) y[0]=pDoc->meshnode[i].y;
		if(pDoc->meshnode[i].y>y[1]) y[1]=pDoc->meshnode[i].y;
	}

	if(pDoc->FirstDraw==TRUE){
		if((x[1]-x[0])>(y[1]-y[0])) w=x[1]-x[0];
		else w=y[1]-y[0];
		if(w!=0)
			theView->GridSize=pow(10.,floor(log(w)/log(10.)-1.));
	}

	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];
	
	if(pDoc->FirstDraw==TRUE) pDoc->FirstDraw=FALSE;
	else theView->RedrawView();	



	return 0;
}

int CFemmviewDoc::lua_zoomout(lua_State * L)
{
	
	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);
	RECT r;
	double x,y;

	theView->GetClientRect(&r);
	x=r.right; y=r.bottom;
	theView->ox=theView->ox-0.5*x/theView->mag;
	theView->oy=theView->oy-0.5*y/theView->mag;
	theView->mag/=2.;

	theView->RedrawView();

	return 0;
}

int CFemmviewDoc::lua_showmesh(lua_State * L)
{
	
	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);

	CMainFrame *MFrm;
	MFrm=(CMainFrame *)theView->GetTopLevelFrame();
	CMenu* MMnu=MFrm->GetMenu();
	CToolBar *pToolBar;
	pToolBar=&MFrm->m_toolBar;    
	CToolBarCtrl *tc=&pToolBar->GetToolBarCtrl();
	
	theView->MeshFlag=TRUE;
	MMnu->CheckMenuItem(ID_SHOW_MESH, MF_CHECKED);
	tc->PressButton(ID_SHOW_MESH,TRUE);

	theView->RedrawView();

	return 0;
}

int CFemmviewDoc::lua_hidemesh(lua_State * L)
{
	
	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);

	CMainFrame *MFrm;
	MFrm=(CMainFrame *)theView->GetTopLevelFrame();
	CMenu* MMnu=MFrm->GetMenu();
	CToolBar *pToolBar;
	pToolBar=&MFrm->m_toolBar;    
	CToolBarCtrl *tc=&pToolBar->GetToolBarCtrl();
	
	theView->MeshFlag=FALSE;
	MMnu->CheckMenuItem(ID_SHOW_MESH, MF_UNCHECKED);
	tc->PressButton(ID_SHOW_MESH,FALSE);

	theView->RedrawView();

	return 0;
}

int CFemmviewDoc::lua_hidegrid(lua_State * L)
{
	
	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);

	CMainFrame *MFrm;
	MFrm=(CMainFrame *)theView->GetTopLevelFrame();
	CMenu* MMnu=MFrm->GetMenu();
	CToolBar *pToolBar;
	pToolBar=&MFrm->m_toolBar;    
	CToolBarCtrl *tc=&pToolBar->GetToolBarCtrl();

	theView->GridFlag=FALSE;
	MMnu->CheckMenuItem(ID_SHOW_GRID, MF_UNCHECKED);
	tc->PressButton(ID_SHOW_GRID,FALSE);
	theView->RedrawView();

	return 0;
}


int CFemmviewDoc::lua_showgrid(lua_State * L)
{
	
	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);

	CMainFrame *MFrm;
	MFrm=(CMainFrame *)theView->GetTopLevelFrame();
	CMenu* MMnu=MFrm->GetMenu();
	CToolBar *pToolBar;
	pToolBar=&MFrm->m_toolBar;    
	CToolBarCtrl *tc=&pToolBar->GetToolBarCtrl();

	theView->GridFlag=TRUE;
	MMnu->CheckMenuItem(ID_SHOW_GRID, MF_CHECKED);
	tc->PressButton(ID_SHOW_GRID,TRUE);
	theView->RedrawView();

	return 0;
}


int CFemmviewDoc::lua_showdensity(lua_State * L)
{
	
    BOOL showlegend;
    BOOL gscale;
    double m_ub1,m_lb1;
    CString type;
    int btnState;
    //type real,imag,mag;


    CFemmviewDoc * thisDoc;
    CFemmviewView * theView;
    thisDoc=(CFemmviewDoc *)pFemmviewdoc;
    POSITION pos;
    pos=thisDoc->GetFirstViewPosition();
    theView=(CFemmviewView *)thisDoc->GetNextView(pos);


    // we shouldn't need to check for num of params as
    // the problem is either static or harmonic ! lua dosn't care
    // abount unused parameters

    showlegend=(int) lua_tonumber(L,1);
    gscale=(int) lua_tonumber(L,2);
    m_ub1=lua_tonumber(L,3);
    m_lb1=lua_tonumber(L,4);

    if(m_lb1>m_ub1)
    {
        double temp=m_lb1;
        m_lb1=m_ub1;
        m_ub1=temp;
    }

    type.Format("%s",lua_tostring(L,5));

    btnState=0;

    if(type=="real")
        btnState=2;
    if(type=="imag")
        btnState=3;
    if(type=="mag")
        btnState=1;
    if(type=="jreal")
        btnState=5;
    if(type=="jimag")
        btnState=6;
    if(type=="jmag")
        btnState=4;

	// for zero frequency, only a subset of plots are legal
	if (thisDoc->Frequency==0)
	{
		if ((btnState==2) || (btnState==3)) btnState=1;
		if ((btnState==5) || (btnState==6)) btnState=4;
	}

    if (showlegend==-1)
    {
        if (btnState==0){ m_lb1=thisDoc->B_Low;  m_ub1=thisDoc->B_High;}
        if (btnState==1){ m_lb1=thisDoc->B_Low;  m_ub1=thisDoc->B_High;}
        if (btnState==2){ m_lb1=thisDoc->Br_Low; m_ub1=thisDoc->Br_High;}
        if (btnState==3){ m_lb1=thisDoc->Bi_Low; m_ub1=thisDoc->Bi_High;}
        if (btnState==4){ m_lb1=thisDoc->J_Low;  m_ub1=thisDoc->J_High;}
        if (btnState==5){ m_lb1=thisDoc->Jr_Low; m_ub1=thisDoc->Jr_High;}
        if (btnState==6){ m_lb1=thisDoc->Ji_Low; m_ub1=thisDoc->Ji_High;}
        if (btnState>3){m_lb1*=1.e-6; m_ub1*=1.e-6;}
        showlegend=1;
        gscale=0;
    }

    theView->DensityPlot=btnState;
    theView->LegendFlag=showlegend;
    theView->GreyContours=gscale;
    if (btnState>3){m_lb1*=1.e6; m_ub1*=1.e6;}
    thisDoc->B_ub=m_ub1;
    thisDoc->B_lb=m_lb1;
    theView->RedrawView();
       
    return 0;
}

int CFemmviewDoc::lua_hidedensity(lua_State * L)
{
	
	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);

	theView->DensityPlot=0;

	theView->RedrawView();

	return 0;
}


int CFemmviewDoc::lua_showcountour(lua_State * L)
{
	
	int m_numcontours;
	double m_alow,m_ahigh;
	CString type;
	m_numcontours=(int) lua_tonumber(L,1);
	m_alow=lua_tonumber(L,2);
	m_ahigh=lua_tonumber(L,3);
	type=lua_tostring(L,4);	
	type.MakeLower();

	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);

	if(thisDoc->Frequency!=0)
	{
		if(type=="real")
		{
			theView->ShowAr=true;
			theView->ShowAi=false;
		}
		if(type=="imag")
		{
			theView->ShowAi=true;
			theView->ShowAr=false;
		}
		if(type=="both")
		{
			theView->ShowAi=theView->ShowAr=true;
		}	
				
		thisDoc->A_Low=m_alow;
		thisDoc->A_High=m_ahigh;
		theView->NumContours=m_numcontours;
		theView->RedrawView();
	}
	else{
		theView->ShowAr=true;
		theView->ShowAi=FALSE;
		thisDoc->A_Low=m_alow;
		thisDoc->A_High=m_ahigh;
		theView->NumContours=m_numcontours;
		theView->RedrawView();
	}

	if(m_numcontours==-1)
	{
		thisDoc->A_Low=thisDoc->A_lb;
		thisDoc->A_High=thisDoc->A_ub;
		theView->NumContours=19;
	}

	theView->RedrawView();
	
	return 0;
}

int CFemmviewDoc::lua_hidecountour(lua_State * L)
{
	
	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);

	theView->ShowAr=FALSE;
	theView->ShowAi=FALSE;
	
	theView->RedrawView();
	return 0;
}

int CFemmviewDoc::lua_smoothing(lua_State * L)
{
	
	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);

	CString temp;
	temp.Format("%s",lua_tostring(L,1));
	temp.MakeLower();

	CMainFrame *MFrm;
	MFrm=(CMainFrame *)theView->GetTopLevelFrame();
	CMenu* MMnu=MFrm->GetMenu();


	if (temp=="off")
	{
		thisDoc->Smooth=FALSE;
		MMnu->CheckMenuItem(ID_SMOOTH, MF_UNCHECKED);

	}
	if (temp=="on")
	{
			thisDoc->Smooth=TRUE;
			MMnu->CheckMenuItem(ID_SMOOTH, MF_CHECKED);
	}


		if (temp !="on" && temp !="off")
	{
		CString msg="Unknown option for smoothing";
		lua_error(L,msg.GetBuffer(1));
		return 0;

	}



	theView->RedrawView();

	return 0;
}


int CFemmviewDoc::lua_showpoints(lua_State * L)
{
	
	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);

	CFrameWnd *MFrm;
	MFrm=theView->GetTopLevelFrame();
	CMenu* MMnu=MFrm->GetMenu();

	theView->PtsFlag=TRUE;
	MMnu->CheckMenuItem(ID_MENUSHOWPTS, MF_CHECKED);

	theView->RedrawView();

	return 0;
}

int CFemmviewDoc::lua_hidepoints(lua_State * L)
{
	
	CFemmviewDoc * thisDoc;
	CFemmviewView * theView;
	thisDoc=(CFemmviewDoc *)pFemmviewdoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmviewView *)thisDoc->GetNextView(pos);

	CFrameWnd *MFrm;
	MFrm=theView->GetTopLevelFrame();
	CMenu* MMnu=MFrm->GetMenu();

	theView->PtsFlag=FALSE;

⌨️ 快捷键说明

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