📄 femmview.cpp
字号:
// femmview.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "femmview.h"
#include "MainFrm.h"
#include <afx.h>
#include <afxtempl.h>
#include "problem.h"
#include "XYPlot.h"
#include "ptloc.h"
#include "femmviewDoc.h"
#include "femmviewView.h"
#include "mycommandlineinfo.h"
#include "lua.h"
#include <afxctl.h>
extern CFemmviewDoc * pFemmviewdoc;
extern int m_luaWindowStatus;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFemmviewApp
BEGIN_MESSAGE_MAP(CFemmviewApp, CWinApp)
//{{AFX_MSG_MAP(CFemmviewApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFemmviewApp construction
CFemmviewApp::CFemmviewApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
bActiveX=FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CFemmviewApp object
CFemmviewApp theApp;
// lua globals
lua_State * lua; // the main lua object
BOOL bLinehook=NULL;
BOOL lua_byebye=FALSE;
int m_luaWindowStatus=SW_SHOW;
CString luafiles[20];
int luafilepointer;
CString luascriptname;
/////////////////////////////////////////////////////////////////////////////
// CFemmviewApp initialization
BOOL CFemmviewApp::InitInstance()
{
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox("OLE initialization failed. Make sure that the OLE libraries are the correct version.");
return FALSE;
}
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
// Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
SetRegistryKey("Gedanken Magnetics\\FEMM\\3");
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// SetDialogBkColor();
// Parse the command line to see if launched as OLE server
if (RunEmbedded() || RunAutomated())
{
// Register all OLE server (factories) as running. This enables the
// OLE libraries to create objects from other applications.
COleTemplateServer::RegisterAll();
}
else
{
// When a server application is launched stand-alone, it is a good idea
// to update the system registry in case it has been damaged.
COleObjectFactory::UpdateRegistryAll();
}
// {EE5BB3DE-259D-400C-81D3-C31492BAC758}
const IID LIBID_ActiveFEMM = { 0xEE5BB3DE, 0x259D, 0x400C, { 0x81, 0xD3, 0xC3, 0x14, 0x92, 0xBA, 0xC7, 0x58 } };
if(AfxOleRegisterTypeLib(AfxGetInstanceHandle(), LIBID_ActiveFEMM, _T("femmview.TLB"))==FALSE)
AfxMessageBox("TypeLib not registered!");
// Initialize Lua
bLinehook=FALSE;
lua=lua_open(4096);
lua_baselibopen(lua);
lua_strlibopen(lua);
lua_mathlibopen(lua);
lua_iolibopen(lua);
lua_register(lua,"_ALERT",lua_ERROR);
// define some initial Lua variables
lua_dostring(lua,"uo=PI*4.e-7");
lua_dostring(lua,"eo=8.85418781762e-12");
lua_dostring(lua,"function AWG(awg) return 8.252919195992115*exp(-0.11593801908089453*awg) end");
lua_dostring(lua,"function IEC(iec) return 7.959159641581004*exp(-0.11519673572274754*iec) end");
lua_dostring(lua,"Pi=PI; pi=PI");
lua_dostring(lua,"meter=1");
lua_dostring(lua,"meters=meter; Meter=meter; Meters=meter");
lua_dostring(lua,"inch=0.0254");
lua_dostring(lua,"inches=inch; Inch=inch; Inches=inch; in=inch;");
lua_dostring(lua,"cm=0.01");
lua_dostring(lua,"centimeter=cm; centimeters=cm; Centimeters=cm; Centimeter=cm");
lua_dostring(lua,"mm=0.001");
lua_dostring(lua,"millimeters=mm; millimeter=mm; Millimeter=mm; Millimeters=mm; milimeter=mm; milimeters=mm");
lua_dostring(lua,"um=0.000001");
lua_dostring(lua,"micrometer=um; Micrometer=um; micrometers=um; Micrometers=um");
lua_dostring(lua,"micron=um; Micron=um; microns=um; Microns=um");
lua_dostring(lua,"mil=0.001*inch");
lua_dostring(lua,"mils=mil; Mils=mil; Mil=mil");
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CFemmviewDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CFemmviewView));
AddDocTemplate(pDocTemplate);
// Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(TRUE);
// Parse command line for standard shell commands, DDE, file open
CMyCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// lua extension
// if we are running in quite mode hide window
this->m_nCmdShow=m_luaWindowStatus;
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
// All Docs Views etc are ok at this point
// so now is a nice time to fire lua
//(using the doc pointer (global))
// this pointer could be obtained via
// the getactiveview and working back to the doc
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CFemmviewApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CFemmviewApp commands
BOOL CFemmviewApp::OnIdle(LONG lCount)
{
// if a lua script was specified on the command line, run it.
// Invoking the lua script here, rather than in InitInstance,
// makes sure that everything is initialized correctly before
// the lua script starts to run.
if (luascriptname.GetLength()!=0){
if(m_luaWindowStatus==SW_SHOW) bLinehook=NormalLua;
else bLinehook=HiddenLua;
CString doscript=luascriptname;
luascriptname.Empty();
int lua_error_code;
lua_byebye=FALSE;
CStatusBar *StatBar=(CStatusBar *)((CMainFrame *)m_pMainWnd)->GetMessageBar();
StatBar->SetPaneText(0,"EXECUTING LUASCRIPT -- HIT <BREAK> TO ABORT",TRUE);
if (lua_error_code=lua_dofile(lua,doscript)!=0)
{
if (lua_error_code==LUA_ERRRUN)
AfxMessageBox("Run Error");
if (lua_error_code==LUA_ERRMEM)
AfxMessageBox("Lua memory Error");
if (lua_error_code==LUA_ERRERR)
AfxMessageBox("User error error");
if (lua_error_code==LUA_ERRFILE)
AfxMessageBox("File Error");
}
StatBar->SetPaneText(0,"Ready",TRUE);
if(lua_byebye==TRUE){
ASSERT(AfxGetMainWnd() != NULL);
AfxGetMainWnd()->PostMessage(WM_CLOSE);
}
bLinehook=FALSE;
}
return CWinApp::OnIdle(lCount);
}
CString CFemmviewApp::GetExecutablePath()
{
char szPath[MAX_PATH];
char szDrive[64];
char szDir[MAX_PATH];
GetModuleFileName(NULL, szPath, MAX_PATH);
_splitpath(szPath, szDrive, szDir, NULL, NULL);
return ((CString) szDrive) + szDir;
}
int CFemmviewApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
lua_close(lua);
return CWinApp::ExitInstance();
}
int CFemmviewApp::lua_ERROR(lua_State *L)
{
CString errmsg;
errmsg.Format("%s",lua_tostring(L,1));
theApp.LuaErrmsg=errmsg;
// Somthing went wrong in lua execution
// Windows dosn't have stdout so lets afxmessagebox it
/*
if(theApp.bFileLink)
{
FILE* fp;
fp=fopen(theApp.OFile,"wt");
if(fp!=NULL){
errmsg.Replace("error:","");
errmsg.Replace("\"","\\\"");
errmsg.Replace("\n","\\n");
fprintf(fp,"error(\"FEMM returns:\\n%s\\n\")",errmsg);
fclose(fp);
}
}
else */
if (!theApp.bActiveX) AfxMessageBox(errmsg);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -