📄 wgl_32.cpp
字号:
// wgl_32.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "wgl_32.h"
#include "ZhxDoc1.h"
#include "ResultView.h"
#include "ShowWnd.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "RighView.h"
#include "TreeDisp.h"
#include "wgl_32View.h"
#include "StringView.h"
#include "fileManage.h"
#include "Convert.h"
#include "analysis.h"
#include "Recorder.h"
#include "PwInput.h"
#include "PwChange.h"
#include "Ana_32View.h"
#include "AnaFrame.h"
#include "Ana2_32View.h"
#include "tty.h"
#include "selectcom.h"
#include "spromeps.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BOOL ReadDog(void);
extern CTTY MyTTY;
/////////////////////////////////////////////////////////////////////////////
// CWgl_32App
BEGIN_MESSAGE_MAP(CWgl_32App, CWinApp)
//{{AFX_MSG_MAP(CWgl_32App)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_OPEN_COMMFILE, OnFileOpenCommfile)
ON_COMMAND(ID_CONFIG_RECORD, OnConfigRecord)
ON_COMMAND(ID_CONFIG_PASSWORD, OnConfigPassword)
ON_COMMAND(ID_CONFIG_COMM, OnConfigComm)
ON_COMMAND(ID_CONFIG_COM, OnConfigCom)
//}}AFX_MSG_MAP
// Standard file based document commands
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWgl_32App construction
CWgl_32App::CWgl_32App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
FFTPoints = 20;
AnaError = FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CWgl_32App object
CWgl_32App theApp;
/////////////////////////////////////////////////////////////////////////////
// CWgl_32App initialization
BOOL CWgl_32App::InitInstance()
{
AfxEnableControlContainer();
// 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
// Change the registry key under which our settings are stored.
// You should modify this string to be something appropriate
// such as the name of your company or organization.
CString strSection = "Main Directory";
CString strStringItem = "path";
SetRegistryKey(_T("WyyMicro Software"));
m_PathStr = GetProfileString(strSection, strStringItem);
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CMultiDocTemplate *pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_WGL_32TYPE,
RUNTIME_CLASS(CWgl_32Doc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CWgl_32View));
AddDocTemplate(pDocTemplate);
CMultiDocTemplate *pDocTemplate2;
pDocTemplate2 = new CMultiDocTemplate(
IDR_WAT_32TYPE,
RUNTIME_CLASS(CWgl_32Doc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CWgl_32View));
AddDocTemplate(pDocTemplate2);
m_pTemplateSearch = new CMultiDocTemplate(
IDR_WYYQ,
RUNTIME_CLASS(CZhxDoc1),
RUNTIME_CLASS(CAnaFrame), // custom MDI frame window
RUNTIME_CLASS(CResultView));
m_pTemplateWgl = new CMultiDocTemplate(
IDR_WGL_32TYPE,
RUNTIME_CLASS(CWgl_32Doc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CWgl_32View));
m_pTemplateAna = new CMultiDocTemplate(
IDR_WAT_32TYPE,
RUNTIME_CLASS(CWgl_32Doc),
RUNTIME_CLASS(CAnaFrame), // custom MDI child frame
RUNTIME_CLASS(CAna_32View));
m_pTemplateAna2 = new CMultiDocTemplate(
IDR_WAT_32TYPE,
RUNTIME_CLASS(CWgl_32Doc),
RUNTIME_CLASS(CAnaFrame), // custom MDI child frame
RUNTIME_CLASS(CAna2_32View));
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
// Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(TRUE);
// Parse command line for standard shell commands, DDE, file open
// CCommandLineInfo cmdInfo;
// ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
// if (!ProcessShellCommand(cmdInfo))
// return FALSE;
// The main window has been initialized, so show and update it.
//pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
pMainFrame->UpdateWindow();
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 CWgl_32App::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CWgl_32App commands
void CWgl_32App::OnFileOpen()
{
// TODO: Add your command handler code here
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
CString m_strOpenFileName;
CConvert MyConvert;
CAnalysis Analysis;
CFileManage FileManageDlg;
if(FileManageDlg.DoModal()==IDOK)
{
if(ReadDog() == FALSE)return;
m_strOpenFileName = FileManageDlg.NowDirectory;
MyConvert.m_ConfigFileName1 =
FileManageDlg.m_Directory + FileManageDlg.m_CityName + "\\" + FileManageDlg.m_StationName + "\\" + FileManageDlg.m_strRecordID + "\\sys1.dat";
MyConvert.m_ConfigFileName2 =
FileManageDlg.m_Directory + FileManageDlg.m_CityName + "\\" + FileManageDlg.m_StationName + "\\" + FileManageDlg.m_strRecordID + "\\sys2.dat";
MyConvert.m_ReadaFileName =
FileManageDlg.m_Directory + FileManageDlg.m_CityName + "\\" + FileManageDlg.m_StationName + "\\" + FileManageDlg.m_strRecordID + "\\reada.dat";
MyConvert.m_FaultFileName = FileManageDlg.NowDirectory;
m_strRecordID = FileManageDlg.m_strRecordID;
Analysis.m_ConfigFileName1 =
FileManageDlg.m_Directory + FileManageDlg.m_CityName + "\\" + FileManageDlg.m_StationName + "\\" + FileManageDlg.m_strRecordID + "\\sys1.dat";
Analysis.m_ConfigFileName2 =
FileManageDlg.m_Directory + FileManageDlg.m_CityName + "\\" + FileManageDlg.m_StationName + "\\" + FileManageDlg.m_strRecordID + "\\sys2.dat";
Analysis.m_StrglconfigFile =
FileManageDlg.m_Directory + FileManageDlg.m_CityName + "\\" + FileManageDlg.m_StationName + "\\" + FileManageDlg.m_strRecordID + "\\glconfig.dat";
_splitpath(FileManageDlg.NowDirectory, drive, dir, fname, ext);
strcpy(ext, "rpt");
_makepath(Analysis.m_strReportFile.GetBuffer(_MAX_DIR), drive, dir, fname, ext);
Analysis.m_strReportFile.ReleaseBuffer();
m_strReportFile = Analysis.m_strReportFile;
strcpy(ext, "wat");
_makepath(m_strFaultFile.GetBuffer(_MAX_DIR), drive, dir, fname, ext);
m_strFaultFile.ReleaseBuffer();
Analysis.m_FaultFileName = FileManageDlg.NowDirectory;
if(Analysis.InitSys() == -1)return;
if(Analysis.ReadFile() == -1)return;
if(Analysis.tab1(1) == -1)return;
fFaultJL = Analysis.fFaultJL;
MyConvert.m_StrStartDateTime = Analysis.m_StrStartDateTime;
if(MyConvert.InitSys() == -1) return;
if(MyConvert.ReadFile() == -1)return;
if(MyConvert.wash1()<0)
{ AfxMessageBox("转换出错!"); return; }
//fault line no and name
m_FaultLineNo = Analysis.m_FaultLineNo ;
m_strFaultPhase = Analysis.m_strFaultPhase;
if(m_FaultLineNo != -1)
{
AnaError = FALSE;
for(int j=0; j<8; j++)
{
FaultLine[j] = MyConvert.m_Line[m_FaultLineNo-1].No[j];
if(FaultLine[j] <0 || FaultLine[j] >= 48){AnaError = TRUE; break;}
m_strFaultLineName[j] = MyConvert.m_Line[m_FaultLineNo-1].Name[j];
for(UINT i=0; i<=FFTPoints; i++)
{
Value[j][i] = *(MyConvert.m_ChannelsData[FaultLine[j]].c + 10 + 50 + i);
}
}
}
if(FileManageDlg.m_wReturn == 2)
{
char Temp[_MAX_PATH];
char TempOld[_MAX_PATH];
lstrcpy(TempOld,m_strOpenFileName);
MyConvert.ConvertToIEEE(_T(".dat"));
_splitpath(m_strOpenFileName, drive, dir, fname, ext);
strcpy(ext, "dat");
_makepath(m_strOpenFileName.GetBuffer(_MAX_DIR), drive, dir, fname, ext);
m_strOpenFileName.ReleaseBuffer();
sprintf(Temp, "%s已转换成\n%s", TempOld, m_strOpenFileName);
AfxMessageBox(Temp, MB_OK);
return;
}
else if(FileManageDlg.m_wReturn == 1)
{
MyConvert.ConvertToIEEE(_T(".wat"));
_splitpath(m_strOpenFileName, drive, dir, fname, ext);
strcpy(ext, "wat");
_makepath(m_strOpenFileName.GetBuffer(_MAX_DIR), drive, dir, fname, ext);
m_strOpenFileName.ReleaseBuffer();
CWinApp::OpenDocumentFile(m_strOpenFileName);
}
else MyConvert.ConvertToIEEE(_T(".dat"));
}
}
void CWgl_32App::OnFileOpenCommfile()
{
CWinApp::OnFileOpen();
}
void CWgl_32App::OnConfigRecord()
{
CPwInput MyPwInput;
if(MyPwInput.DoModal() == IDOK)
{
CRecorder MyRecorder;
MyRecorder.DoModal();
}
}
void CWgl_32App::OnConfigPassword()
{
CPwInput MyPwInput;
if(MyPwInput.DoModal() == IDOK)
{
CPwChange MyPwChange;
MyPwChange.DoModal();
}
}
int CWgl_32App::ExitInstance()
{
delete m_pTemplateWgl;
delete m_pTemplateAna;
delete m_pTemplateAna2;
delete m_pTemplateSearch;
return CWinApp::ExitInstance();
}
CDocument* CWgl_32App::OpenDocumentFile(LPCTSTR lpszFileName)
{
if(strstr(lpszFileName, ".wat") != NULL)//return (NULL);
{
CString drive;
CString dir;
CString fname;
CString ext;
CString m_strOpenFileName = lpszFileName;
_splitpath(m_strOpenFileName, drive.GetBuffer(_MAX_DRIVE), dir.GetBuffer(_MAX_DIR),
fname.GetBuffer(_MAX_FNAME), ext.GetBuffer(_MAX_EXT));
drive.ReleaseBuffer();
dir.ReleaseBuffer();
fname.ReleaseBuffer();
ext.ReleaseBuffer();
CConvert MyConvert;
CAnalysis Analysis;
MyConvert.m_ConfigFileName1 = drive + dir + _T("sys1.dat");
MyConvert.m_ConfigFileName2 = drive + dir + _T("sys2.dat");
MyConvert.m_ReadaFileName = drive + dir + _T("reada.dat");
MyConvert.m_FaultFileName = drive + dir + fname + _T(".wgl");
Analysis.m_ConfigFileName1 = MyConvert.m_ConfigFileName1;
Analysis.m_ConfigFileName2 = MyConvert.m_ConfigFileName2;
Analysis.m_StrglconfigFile = drive + dir + _T("glconfig.dat");
Analysis.m_FaultFileName = MyConvert.m_FaultFileName;
Analysis.m_strReportFile = drive + dir + fname + _T(".rpt");
m_strReportFile = Analysis.m_strReportFile;
m_strFaultFile = lpszFileName;
if(Analysis.InitSys()==-1)return NULL;
if(Analysis.ReadFile()==-1)return NULL;
if(Analysis.tab1(1) ==-1)return NULL;
fFaultJL = Analysis.fFaultJL;
MyConvert.m_StrStartDateTime = Analysis.m_StrStartDateTime;
if(MyConvert.InitSys()==-1)return NULL;
if(MyConvert.ReadFile() == -1)return NULL;
if(MyConvert.wash1()<0)
{ AfxMessageBox("转换出错!"); return NULL; }
m_FaultLineNo = Analysis.m_FaultLineNo ;
m_strFaultPhase = Analysis.m_strFaultPhase;
if(m_FaultLineNo != -1)
{
AnaError = FALSE;
for(int j=0; j<8; j++)
{
FaultLine[j] = MyConvert.m_Line[m_FaultLineNo-1].No[j];
if(FaultLine[j] <0 || FaultLine[j] >= 48)
{ AnaError = TRUE; break; }
m_strFaultLineName[j] = MyConvert.m_Line[m_FaultLineNo-1].Name[j];
for(UINT i=0; i<= FFTPoints; i++)
{
Value[j][i] = *(MyConvert.m_ChannelsData[FaultLine[j]-1].c + 10 + 50 + i);
}
}
}
MyConvert.ConvertToIEEE(_T(".wat"));
return CWinApp::OpenDocumentFile(m_strOpenFileName);
}
else return CWinApp::OpenDocumentFile(lpszFileName);
}
void CWgl_32App::OnConfigComm()
{
// TODO: Add your command handler code here
CString m_strBaudRate = GetProfileString("Config","BaudRate", "19200");
CString m_strCom = GetProfileString("Config","ComPort", "COM2");
COMMCONFIG cc;
cc.dwSize = sizeof(COMMCONFIG);
cc.wVersion = 0x100;
cc.dcb.BaudRate = atol(m_strBaudRate);
if(!CommConfigDialog(m_strCom, NULL, &cc))
{
MyTTY.SelectedBaudRate = 19200;
return;
}
MyTTY.SelectedBaudRate = cc.dcb.BaudRate;
char temp[20];
wsprintf(temp, "%ld",MyTTY.SelectedBaudRate);
WriteProfileString("Config","BaudRate", temp);
}
//WORD DevID = 0x4257;
BOOL ReadDog(void)
{
return TRUE;
}
/* RB_SPRO_APIPACKET dog;
SP_STATUS spStatus;
spStatus = RNBOsproFormatPacket( dog, sizeof( dog ));
spStatus = RNBOsproInitialize(dog);
if(spStatus != SP_SUCCESS) return FALSE;
spStatus =RNBOsproFindFirstUnit(dog, DevID);
if(spStatus != SP_SUCCESS) return FALSE;
RB_WORD ad = 8;
char qstr[] = "1FBB8827";
char ostr[] = "09EF470C";
RBP_DWORD ttt = (unsigned long *)(ostr+4);
spStatus = RNBOsproQuery( dog, 8, qstr, ostr, ttt, 8);
unsigned short dd;
spStatus = RNBOsproRead( dog,0x28, &dd);
if(spStatus !=SP_SUCCESS || dd != 0x1001)
{
spStatus = RNBOsproRead( dog,0x29, &dd);
if(spStatus !=SP_SUCCESS || dd != 0x1002)
return FALSE;
else
return TRUE;
}
else return TRUE;
}
*/
void CWgl_32App::OnConfigCom()
{
CSelectCom MySelectCom;
MySelectCom.m_strCom = GetProfileString("Config","ComPort", "COM2");
if(MySelectCom.DoModal() == IDOK)
{
WriteProfileString("Config","ComPort", MySelectCom.m_strCom);
}
MyTTY.ComPort = MySelectCom.Com;
WriteProfileInt("Config","PortNum", MySelectCom.Com);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -