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

📄 femmelua.cpp

📁 一个2D电磁场FEM计算的VC++源程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		case 3:
			thisDoc->blockproplist[k].H_c=lua_tonumber(L,3);
			break;
		case 4:
			thisDoc->blockproplist[k].Jr=lua_tonumber(L,3);
			break;
		case 5:
			thisDoc->blockproplist[k].Ji=lua_tonumber(L,3);
			break;
		case 6:
			thisDoc->blockproplist[k].Cduct=lua_tonumber(L,3);
			break;
		case 7:
			thisDoc->blockproplist[k].Lam_d=lua_tonumber(L,3);
			break;
		case 8:
			thisDoc->blockproplist[k].Theta_hn=lua_tonumber(L,3);
			break;
		case 9:
			thisDoc->blockproplist[k].LamFill=lua_tonumber(L,3);
			break;
		case 10:
			thisDoc->blockproplist[k].LamType=(int) lua_tonumber(L,3);
			break;
		case 11:
			thisDoc->blockproplist[k].Theta_hx=lua_tonumber(L,3);
			break;
		case 12:
			thisDoc->blockproplist[k].Theta_hy=lua_tonumber(L,3);
			break;
		case 13:
			thisDoc->blockproplist[k].NStrands=(int) lua_tonumber(L,3);
			break;
		case 14:
			thisDoc->blockproplist[k].WireD=lua_tonumber(L,4);
		default:
			break;
	}
	
	return 0;
}

int CFemmeDoc::lua_addboundprop(lua_State *L)
{
	
	
	CBoundaryProp m;
	int n=lua_gettop(L);

	if (n>0) m.BdryName.Format("%s",lua_tostring(L,1));
	if (n>1) m.A0=lua_tonumber(L,2);
	if (n>2) m.A1=lua_tonumber(L,3);
	if (n>3) m.A2=lua_tonumber(L,4);
	if (n>4) m.phi=lua_tonumber(L,5);
	if (n>5) m.Mu=lua_tonumber(L,6);
	if (n>6) m.Sig=lua_tonumber(L,7);
	if (n>7) m.c0=lua_tonumber(L,8);
	if (n>8) m.c1=lua_tonumber(L,9);
	if (n>9) m.BdryFormat=(int) lua_tonumber(L,10);

	((CFemmeDoc *)pFemmeDoc)->lineproplist.Add(m);

	return 0;
}

int CFemmeDoc::lua_modboundprop(lua_State *L)
{
	
	CString BdryName;
	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 boundary property to modify;
	if (thisDoc->lineproplist.GetSize()==0) return TRUE;
	BdryName.Format("%s",lua_tostring(L,1));
	for(k=0;k<thisDoc->lineproplist.GetSize();k++)
		if(BdryName==thisDoc->lineproplist[k].BdryName) break;
	
	// get out of here if there's no matching material
	if(k==thisDoc->lineproplist.GetSize()) return TRUE;

	modprop=(int) lua_tonumber(L,2);
	
	// now, modify the specified attribute...
	switch(modprop)
	{
		case 0:
			thisDoc->lineproplist[k].BdryName.Format("%s",lua_tostring(L,3));
			break;
		case 1:
			thisDoc->lineproplist[k].A0	=lua_tonumber(L,3);
			break;
		case 2:
			thisDoc->lineproplist[k].A1	=lua_tonumber(L,3);
			break;
		case 3:
			thisDoc->lineproplist[k].A2	=lua_tonumber(L,3);
			break;
		case 4:
			thisDoc->lineproplist[k].phi=lua_tonumber(L,3);
			break;
		case 5:
			thisDoc->lineproplist[k].Mu	=lua_tonumber(L,3);
			break;
		case 6:
			thisDoc->lineproplist[k].Sig=lua_tonumber(L,3);
			break;
		case 7:
			thisDoc->lineproplist[k].c0	=lua_tonumber(L,3);
			break;
		case 8:
			thisDoc->lineproplist[k].c1	=lua_tonumber(L,3);
			break;
		case 9:
			thisDoc->lineproplist[k].BdryFormat=(int)lua_tonumber(L,3);
			break;
		default:
			break;
	}
	
	return 0;
}

int CFemmeDoc::lua_addpointprop(lua_State *L)
{
	
	
	CPointProp m;
	int n=lua_gettop(L);

	if (n>0) m.PointName.Format("%s",lua_tostring(L,1));
	if (n>1) m.Ar=lua_tonumber(L,2);
	if (n>2) m.Ai=lua_tonumber(L,3);
	if (n>3) m.Jr=lua_tonumber(L,4);
	if (n>4) m.Ji=lua_tonumber(L,5);
	
	((CFemmeDoc *)pFemmeDoc)->nodeproplist.Add(m);
		
	return 0;
}

int CFemmeDoc::lua_modpointprop(lua_State *L)
{
	
	CString PointName;
	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->nodeproplist.GetSize()==0) return TRUE;
	PointName.Format("%s",lua_tostring(L,1));
	for(k=0;k<thisDoc->nodeproplist.GetSize();k++)
		if(PointName==thisDoc->nodeproplist[k].PointName) break;
	
	// get out of here if there's no matching material
	if(k==thisDoc->nodeproplist.GetSize()) return TRUE;

	modprop=(int) lua_tonumber(L,2);
	
	// now, modify the specified attribute...
	switch(modprop)
	{
		case 0:
			thisDoc->nodeproplist[k].PointName.Format("%s",lua_tostring(L,3));
			break;
		case 1:
			thisDoc->nodeproplist[k].Ar=lua_tonumber(L,3);
			break;
		case 2:
			thisDoc->nodeproplist[k].Ai=lua_tonumber(L,3);
			break;
		case 3:
			thisDoc->nodeproplist[k].Jr=lua_tonumber(L,3);
			break;
		case 4:
			thisDoc->nodeproplist[k].Ji=lua_tonumber(L,3);
			break;
		default:
			break;
	}
	
	return 0;
}

int CFemmeDoc::lua_addcircuitprop(lua_State *L)
{
	
	
	CCircuit m;
	int n=lua_gettop(L);

	if (n>0) m.CircName=lua_tostring(L,1);
	if (n>1) m.Amps+=lua_tonumber(L,2);
	if (n>2) m.Amps+=I*lua_tonumber(L,3);
	if (n>3) m.CircType=(int) lua_tonumber(L,4);

	((CFemmeDoc *)pFemmeDoc)->circproplist.Add(m);

	return 0;
}

int CFemmeDoc::lua_modcircprop(lua_State *L)
{
	
	CString CircName;
	int k,modprop;

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

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

	modprop=(int) lua_tonumber(L,2);
	
	// now, modify the specified attribute...
	switch(modprop)
	{
		case 0:
			thisDoc->circproplist[k].CircName.Format("%s",lua_tostring(L,3));
			break;
		case 3:
			thisDoc->circproplist[k].CircType=(int) lua_tonumber(L,3);
			break;
		case 1:
			thisDoc->circproplist[k].Amps=lua_tonumber(L,3)+
				I*Im(thisDoc->circproplist[k].Amps);
			break;
		case 2:
			thisDoc->circproplist[k].Amps=I*lua_tonumber(L,3)+
				Re(thisDoc->circproplist[k].Amps);
			break;
	
		default:
			break;
	}
	
	return 0;
}

int CFemmeDoc::lua_delcircuitprop(lua_State *L)
{
	
	CString name;
	name.Format("%s",lua_tostring(L,1));

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

	for(int i=0;i<thisDoc->circproplist.GetSize();i++)
	{
		if (thisDoc->circproplist[i].CircName==name)
			thisDoc->circproplist.RemoveAt(i);

	}

	return 0;
}

int CFemmeDoc::lua_delmatprop(lua_State *L)
{
	
	CString name;
	name.Format("%s",lua_tostring(L,1));

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

	for(int i=0;i<thisDoc->blockproplist.GetSize();i++)
	{
		if (thisDoc->blockproplist[i].BlockName==name)
			thisDoc->blockproplist.RemoveAt(i);

	}

	return 0;
}


int CFemmeDoc::lua_delboundprop(lua_State *L)
{
	
	CString name;
	name.Format("%s",lua_tostring(L,1));

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

	for(int i=0;i<thisDoc->lineproplist.GetSize();i++)
	{
		if (thisDoc->lineproplist[i].BdryName==name)
		thisDoc->lineproplist.RemoveAt(i);
	}

	
	return 0;
}

int CFemmeDoc::lua_delpointprop(lua_State *L)
{
	
	CString name;
	name.Format("%s",lua_tostring(L,1));
	CFemmeDoc * thisDoc;CFemmeView * theView;
	
	thisDoc=(CFemmeDoc *)pFemmeDoc;
	POSITION pos;
	pos=thisDoc->GetFirstViewPosition();
	theView=(CFemmeView *)thisDoc->GetNextView(pos);

	for(int i=0;i<thisDoc->nodeproplist.GetSize();i++)
	{
		if (thisDoc->nodeproplist[i].PointName==name)
		thisDoc->nodeproplist.RemoveAt(i);
	}

	return 0;
}

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

        CDC tempDC;
        CDC *pDC=theView->GetDC();

        // erase background
        CBrush backBrush(theView->BackColor);
        CBrush* pOldBrush = pDC->SelectObject(&backBrush);
        CRect rect;
        pDC->GetClipBox(&rect);
        pDC->PatBlt(rect.left, rect.top, rect.Width(),
           rect.Height(), PATCOPY);
        pDC->SelectObject(pOldBrush);

        // force redraw
        theView->OnDraw(pDC);

        return 0;
}


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

    filename.Format("%s",lua_tostring(L,1));

    RECT r;
    CDC tempDC;
    CBitmap bitmap;
    CDC *pDC=theView->GetDC();

    theView->GetClientRect(&r);
    tempDC.CreateCompatibleDC(pDC);
    bitmap.CreateCompatibleBitmap(pDC, r.right, r.bottom);
    tempDC.SelectObject(&bitmap);

        tempDC.Rectangle(0,0,r.right,r.bottom);

        theView->OnDraw(&tempDC);

        PBITMAPINFO pbmi;

        pbmi=thisDoc->CreateBitmapInfoStruct(theView->m_hWnd,HBITMAP(bitmap));
        thisDoc->CreateBMPFile(theView->m_hWnd,filename.GetBuffer(1),pbmi,HBITMAP(bitmap),tempDC.m_hDC);

        return 0;
}


PBITMAPINFO CFemmeDoc::CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp)
{
    BITMAP bmp;
    PBITMAPINFO pbmi;
    WORD    cClrBits;

    // Retrieve the bitmap's color format, width, and height.
    if (!GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp))
        {//errhandler("GetObject", hwnd);
        AfxMessageBox("Critical error on getting bmp info, possible page fault ahoy17");
        }
    // Convert the color format to a count of bits.
    cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
    if (cClrBits == 1)
        cClrBits = 1;
    else if (cClrBits <= 4)
        cClrBits = 4;
    else if (cClrBits <= 8)
        cClrBits = 8;
    else if (cClrBits <= 16)
        cClrBits = 16;
    else if (cClrBits <= 24)
        cClrBits = 24;
    else cClrBits = 32;

    // Allocate memory for the BITMAPINFO structure. (This structure
    // contains a BITMAPINFOHEADER structure and an array of RGBQUAD
    // data structures.)

     if (cClrBits != 24)
         pbmi = (PBITMAPINFO) LocalAlloc(LPTR,
                    sizeof(BITMAPINFOHEADER) +
                    sizeof(RGBQUAD) * (1<< cClrBits));

     // There is no RGBQUAD array for the 24-bit-per-pixel format.

     else
         pbmi = (PBITMAPINFO) LocalAlloc(LPTR,
                    sizeof(BITMAPINFOHEADER));

    // Initialize the fields in the BITMAPINFO structure.

    pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    pbmi->bmiHeader.biWidth = bmp.bmWidth;
    pbmi->bmiHeader.biHeight = bmp.bmHeight;
    pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
    pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
    if (cClrBits < 24)
        pbmi->bmiHeader.biClrUsed = (1<<cClrBits);

    // If the bitmap is not compressed, set the BI_RGB flag.
    pbmi->bmiHeader.biCompression = BI_RGB;

    // Compute the number of bytes in the array of color
    // indices and store the result in biSizeImage.
    // For Windows NT/2000, the width must be DWORD aligned unless
    // the bitmap is RLE compressed. This example shows this.
    // For Windows 95/98, the width must be WORD aligned unless the
    // bitmap is RLE compressed.
    pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits +31) & ~31) /8
                                  * pbmi->bmiHeader.biHeight;
    // Set biClrImportant to 0, indicating that all of the
    // device colors are important.
     pbmi->bmiHeader.biClrImportant = 0;
     return pbmi;
 }


void CFemmeDoc::CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi,
                  HBITMAP hBMP, HDC hDC)
 {
     HANDLE hf;                 // file handle
    BITMAPFILEHEADER hdr;       // bitmap file-header
    PBITMAPINFOHEADER pbih;     // bitmap info-header
    LPBYTE lpBits;              // memory pointer
    DWORD dwTotal;              // total count of bytes
    DWORD cb;                   // incremental count of bytes
    BYTE *hp;                   // byte pointer
    DWORD dwTmp;

    pbih = (PBITMAPINFOHEADER) pbi;
    lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

    if (!lpBits)
        AfxMessageBox("Critical error on getting bmp info, possible page fault ahoy18");
//              errhandler("GlobalAlloc", hwnd);

    // Retrieve the color table (RGBQUAD array) and the bits
    // (array of palette indices) from the DIB.
    if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi,
        DIB_RGB_COLORS))
    {
    //    errhandler("GetDIBits", hwnd);
        AfxMessageBox("Critical error on getting bmp info, possible page fault ahoy19");

        }

⌨️ 快捷键说明

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