📄 femmviewlua.cpp
字号:
}
}
}
}
}
else{
pDoc->contour.Add(z);
theView->DrawUserContour(FALSE);
return 0;
}
if((lineno<0) && (arcno<0)){
pDoc->contour.Add(z);
theView->DrawUserContour(FALSE);
}
if(lineno>=0){
j=pDoc->contour.GetSize();
if(j>1){
if(abs(pDoc->contour[j-2]-z)<1.e-08){
//CView::OnLButtonDown(nFlags, point);
return 0;
}
}
pDoc->contour.Add(z);
theView->DrawUserContour(FALSE);
}
if(arcno>=0){
k=arcno;
pDoc->GetCircle(pDoc->arclist[k],x,R);
j=(int) ceil(pDoc->arclist[k].ArcLength/pDoc->arclist[k].MaxSideLength);
if(flag==TRUE)
z=exp(I*pDoc->arclist[k].ArcLength*PI/(180.*((double) j)) );
else
z=exp(-I*pDoc->arclist[k].ArcLength*PI/(180.*((double) j)) );
for(i=0;i<j;i++){
y=(y-x)*z+x;
m=pDoc->contour.GetSize();
if(m>1){
if(abs(pDoc->contour[m-2]-y)<1.e-08){
//CView::OnLButtonDown(nFlags, point);
return 0;
}
}
pDoc->contour.Add(y);
theView->DrawUserContour(FALSE);
}
}
}
}
//*************
return 0;
}
int CFemmviewDoc::lua_seteditmode(lua_State *L)
{
CString EditAction;
EditAction.Format("%s",lua_tostring(L,1));
EditAction.MakeLower();
CFemmviewDoc * thisDoc;
CFemmviewView * theView;
thisDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=thisDoc->GetFirstViewPosition();
theView=(CFemmviewView *)thisDoc->GetNextView(pos);
if (EditAction=="point")
{
if (theView->EditAction==1){
theView->EraseUserContour(TRUE);
thisDoc->contour.RemoveAll();
}
if (theView->EditAction==2){
int i;
BOOL flg=FALSE;
thisDoc->bHasMask=FALSE;
for(i=0;i<thisDoc->blocklist.GetSize();i++)
{
if (thisDoc->blocklist[i].IsSelected==TRUE)
{
thisDoc->blocklist[i].IsSelected=FALSE;
flg=TRUE;
}
}
if(flg==TRUE) theView->RedrawView();
}
theView->EditAction=0;
}
if (EditAction=="contour")
{
if(theView->EditAction==2){
int i;
BOOL flg=FALSE;
thisDoc->bHasMask=FALSE;
for(i=0;i<thisDoc->blocklist.GetSize();i++){
if (thisDoc->blocklist[i].IsSelected==TRUE)
{
thisDoc->blocklist[i].IsSelected=FALSE;
flg=TRUE;
}
}
if(flg==TRUE) theView->RedrawView();
}
theView->EditAction=1;
}
if (EditAction=="area")
{
if(theView->EditAction==1){
theView->EraseUserContour(TRUE);
thisDoc->contour.RemoveAll();
}
theView->EditAction=2;
}
return 0;
}
int CFemmviewDoc::lua_bendcontour(lua_State *L)
{
CFemmviewDoc * thisDoc;
CFemmviewView * theView;
thisDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=thisDoc->GetFirstViewPosition();
theView=(CFemmviewView *)thisDoc->GetNextView(pos);
thisDoc->BendContour(lua_tonumber(L,1),lua_tonumber(L,2));
theView->InvalidateRect(NULL);
return 0;
}
int CFemmviewDoc::lua_makeplot(lua_State *L)
{
CFemmviewDoc *pDoc;
CFemmviewView *pView;
pDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=pDoc->GetFirstViewPosition();
pView=(CFemmviewView *)pDoc->GetNextView(pos);
int PlotType,npoints,FileFormat,n;
CString ToFile;
// if ((pView->EditAction!=1) || (pDoc->contour.GetSize()==0)){
if (pDoc->contour.GetSize()==0){
CString outmsg;
outmsg.Format("*** Cannot create a plot;\r\n*** No contour has been defined\r\n");
pDoc->LuaConsole.ToOutput(outmsg);
return FALSE;
}
n=lua_gettop(L);
if(n>0) PlotType=(int) lua_tonumber(L,1);
else return FALSE;
if(n>1) npoints=(int) lua_tonumber(L,2);
else npoints=pView->d_PlotPoints;
CXYPlot xyplot;
pDoc->GetLineValues(xyplot,PlotType,npoints);
if(n<3)
{
CMetaFileDC Meta;
Meta.CreateEnhanced(NULL,NULL,NULL,NULL);
HGLOBAL BoundingBox=GlobalAlloc(0,256);
xyplot.MakePlot(&Meta,(char *) BoundingBox);
HENHMETAFILE hMeta=Meta.CloseEnhanced();
if (hMeta==NULL) AfxMessageBox("No Handle...");
if (pView->OpenClipboard()==FALSE)
AfxMessageBox("Cannot access the Clipboard");
else{
EmptyClipboard();
if(SetClipboardData(CF_ENHMETAFILE,hMeta)==NULL)
AfxMessageBox("Couldn't SetClipboardData");
if(SetClipboardData(CF_TEXT,BoundingBox)==NULL)
AfxMessageBox("Couldn't SetClipboardData");
CloseClipboard();
char CommandLine[512];
sprintf(CommandLine,"\"%sfemmplot.exe\"",pView->BinDir);
STARTUPINFO StartupInfo2 = {0};
PROCESS_INFORMATION ProcessInfo2;
StartupInfo2.cb = sizeof(STARTUPINFO);
if (CreateProcess(NULL,CommandLine, NULL, NULL, FALSE,
0, NULL, NULL, &StartupInfo2, &ProcessInfo2)){
}
else
{
pDoc->LuaConsole.ToOutput("*** Problem executing femmplot\r\n");
return FALSE;
}
}
}
else{
ToFile.Format("%s",lua_tostring(L,3));
if(n>3){
FileFormat=(int) lua_tonumber(L,4);
if (xyplot.ToDisk(FileFormat,ToFile)==FALSE)
pDoc->LuaConsole.ToOutput("*** Couldn't write data to disk\r\n");
}
else{
CMetaFileDC Meta;
Meta.CreateEnhanced(NULL,NULL,NULL,NULL);
HGLOBAL BoundingBox=GlobalAlloc(0,256);
xyplot.MakePlot(&Meta,(char *) BoundingBox);
HENHMETAFILE hMeta=Meta.CloseEnhanced();
if (hMeta==NULL) AfxMessageBox("No Handle...");
CopyEnhMetaFile(hMeta,ToFile);
}
}
return TRUE;
}
int CFemmviewDoc::lua_shownames(lua_State * L)
{
CFemmviewDoc * thisDoc;
CFemmviewView * theView;
thisDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=thisDoc->GetFirstViewPosition();
theView=(CFemmviewView *)thisDoc->GetNextView(pos);
int flg=(int)lua_tonumber(L,1);
if (flg!=0) flg=1;
theView->ShowNames=flg;
theView->InvalidateRect(NULL);
return 0;
}
int CFemmviewDoc::lua_vectorplot(lua_State * L)
{
CFemmviewDoc * thisDoc;
CFemmviewView * theView;
thisDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=thisDoc->GetFirstViewPosition();
theView=(CFemmviewView *)thisDoc->GetNextView(pos);
int n=lua_gettop(L);
if (n>0) theView->VectorPlot=(int)lua_tonumber(L,1);
if (n>1) theView->VectorScaleFactor=lua_tonumber(L,2);
theView->InvalidateRect(NULL);
return 0;
}
/*
int CFemmviewDoc::lua_gradient(lua_State *L)
{
// computes the gradients of the B field by differentiating
// the shape functions that are used to represent the smoothed
// B in an element.
CFemmviewDoc * thisDoc;
CFemmviewView * theView;
thisDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=thisDoc->GetFirstViewPosition();
theView=(CFemmviewView *)thisDoc->GetNextView(pos);
double x,y;
int i,n[3];
double b[3],c[3],da;
CComplex dbxdx,dbxdy,dbydx,dbydy;
CElement elm;
x=lua_tonumber(L,1);
y=lua_tonumber(L,2);
i=thisDoc->InTriangle(x,y);
if(i<0){
for(i=0;i<8;i++) lua_pushnumber(L,0);
return 8;
}
elm=thisDoc->meshelem[i];
for(i=0;i<3;i++) n[i]=elm.p[i];
b[0]=thisDoc->meshnode[n[1]].y - thisDoc->meshnode[n[2]].y;
b[1]=thisDoc->meshnode[n[2]].y - thisDoc->meshnode[n[0]].y;
b[2]=thisDoc->meshnode[n[0]].y - thisDoc->meshnode[n[1]].y;
c[0]=thisDoc->meshnode[n[2]].x - thisDoc->meshnode[n[1]].x;
c[1]=thisDoc->meshnode[n[0]].x - thisDoc->meshnode[n[2]].x;
c[2]=thisDoc->meshnode[n[1]].x - thisDoc->meshnode[n[0]].x;
da=(b[0]*c[1]-b[1]*c[0])*thisDoc->LengthConv[thisDoc->LengthUnits];
dbxdx=0; dbxdy=0; dbydx=0; dbydy=0;
for(i=0;i<3;i++)
{
dbxdx+=elm.b1[i]*b[i]/da;
dbxdy+=elm.b1[i]*c[i]/da;
dbydx+=elm.b2[i]*b[i]/da;
dbydy+=elm.b2[i]*c[i]/da;
}
if (thisDoc->ProblemType==PLANAR)
{
// in a source-free region, we can get a little bit
// of smoothing by enforcing the dependencies that
// are implied by the differential equation.
dbxdx=(dbxdx-dbydy)/2.;
dbydy=-dbxdx;
dbydx=(dbydx+dbxdy)/2;
dbxdy=dbydx;
}
lua_pushnumber(L,Re(dbxdx));
lua_pushnumber(L,Im(dbxdx));
lua_pushnumber(L,Re(dbxdy));
lua_pushnumber(L,Im(dbxdy));
lua_pushnumber(L,Re(dbydx));
lua_pushnumber(L,Im(dbydx));
lua_pushnumber(L,Re(dbydy));
lua_pushnumber(L,Im(dbydy));
return 8;
}
*/
int CFemmviewDoc::lua_gradient(lua_State *L)
{
// computes the gradients of the B field by differentiating
// the shape functions that are used to represent the smoothed
// B in an element.
CFemmviewDoc * thisDoc;
CFemmviewView * theView;
thisDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=thisDoc->GetFirstViewPosition();
theView=(CFemmviewView *)thisDoc->GetNextView(pos);
int i;
double xo,yo,x,y,da,p0,p1,p2;
CComplex dbxdx,dbxdy,dbydx,dbydy,Mx,My;
xo=lua_tonumber(L,1);
yo=lua_tonumber(L,2);
dbxdx=0;
dbxdy=0;
dbydx=0;
dbydy=0;
for(i=0;i<thisDoc->meshelem.GetSize();i++)
{
thisDoc->GetMagnetization(i,Mx,My);
da=muo*thisDoc->ElmArea(i)/thisDoc->LengthConv[thisDoc->LengthUnits];
x=Re(thisDoc->meshelem[i].ctr);
y=Im(thisDoc->meshelem[i].ctr);
p0=PI*pow(pow(x - xo,2.) + pow(y - yo,2.),3.);
p1=(-3.*pow(x - xo,2.) + pow(y - yo,2.))*(y - yo);
p2=(x - xo)*(pow(x - xo,2.) - 3.*pow(y - yo,2.));
dbxdx+=(da*(-(My*p1) + Mx*p2))/p0;
dbydx+=(da*(-(Mx*p1) - My*p2))/p0;
dbxdy+=(da*(-(Mx*p1) - My*p2))/p0;
dbydy+=-(da*(-(My*p1) + Mx*p2))/p0;
}
lua_pushnumber(L,Re(dbxdx));
lua_pushnumber(L,Im(dbxdx));
lua_pushnumber(L,Re(dbxdy));
lua_pushnumber(L,Im(dbxdy));
lua_pushnumber(L,Re(dbydx));
lua_pushnumber(L,Im(dbydx));
lua_pushnumber(L,Re(dbydy));
lua_pushnumber(L,Im(dbydy));
return 8;
}
int CFemmviewDoc::luaMinimize(lua_State *L)
{
CFemmviewDoc * thisDoc;
CFemmviewView * theView;
thisDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=thisDoc->GetFirstViewPosition();
theView=(CFemmviewView *)thisDoc->GetNextView(pos);
CMainFrame *pMainFrm = (CMainFrame *)theView->GetParentFrame();
pMainFrm->ShowWindow(SW_MINIMIZE);
return 0;
}
int CFemmviewDoc::luaMaximize(lua_State *L)
{
CFemmviewDoc * thisDoc;
CFemmviewView * theView;
thisDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=thisDoc->GetFirstViewPosition();
theView=(CFemmviewView *)thisDoc->GetNextView(pos);
CMainFrame *pMainFrm = (CMainFrame *)theView->GetParentFrame();
pMainFrm->ShowWindow(SW_MAXIMIZE);
return 0;
}
int CFemmviewDoc::luaRestore(lua_State *L)
{
CFemmviewDoc * thisDoc;
CFemmviewView * theView;
thisDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=thisDoc->GetFirstViewPosition();
theView=(CFemmviewView *)thisDoc->GetNextView(pos);
CMainFrame *pMainFrm = (CMainFrame *)theView->GetParentFrame();
pMainFrm->ShowWindow(SW_RESTORE);
return 0;
}
int CFemmviewDoc::lua_messagebox(lua_State *L)
{
CString errmsg;
errmsg.Format("%s",lua_tostring(L,1));
CFemmviewDoc * thisDoc;
CFemmviewView * theView;
thisDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=thisDoc->GetFirstViewPosition();
theView=(CFemmviewView *)thisDoc->GetNextView(pos);
AfxMessageBox(errmsg,MB_ICONINFORMATION);
return 0;
}
int CFemmviewDoc::lua_afxpause(lua_State * L)
{
AfxMessageBox("LUA pause");
return 0;
}
int CFemmviewDoc::lua_promptbox(lua_State *L)
{
CPromptBox dlg;
int n=lua_gettop(L);
if(n>0) dlg.mytitle = lua_tostring(L,1);
dlg.DoModal();
lua_pushstring(L,dlg.instring);
return TRUE;
}
int CFemmviewDoc::lua_showpointprops(lua_State *L)
{
CFemmviewDoc * thisDoc;
CFemmviewView * theView;
thisDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=thisDoc->GetFirstViewPosition();
theView=(CFemmviewView *)thisDoc->GetNextView(pos);
CMainFrame * pfrm;
pfrm=(CMainFrame *)AfxGetApp()->GetMainWnd();
pfrm->ShowControlBar(&pfrm->m_dlgBar,TRUE,FALSE);
return 0;
}
int CFemmviewDoc::lua_hidepointprops(lua_State *L)
{
CFemmviewDoc * thisDoc;
CFemmviewView * theView;
thisDoc=(CFemmviewDoc *)pFemmviewdoc;
POSITION pos;
pos=thisDoc->GetFirstViewPosition();
theView=(CFemmviewView *)thisDoc->GetNextView(pos);
CMainFrame * pfrm;
pfrm=(CMainFrame *)AfxGetApp()->GetMainWnd();
pfrm->ShowControlBar(&pfrm->m_dlgBar,FALSE,FALSE);
theView->Invalidate(true);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -