📄 faultazmdlg.cpp
字号:
// FaultAzmDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FaultAzm.h"
#include "FaultAzmDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <math.h>
#define PI 3.1415926
/////////////////////////////////////////////////////////////////////////////
// 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)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CFaultAzmDlg dialog
CFaultAzmDlg::CFaultAzmDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFaultAzmDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFaultAzmDlg)
m_f = 0.0;
m_strAngle = _T("");
m_strR = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFaultAzmDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFaultAzmDlg)
DDX_Control(pDX, IDC_LIST2, m_listCtrlRlt);
DDX_Control(pDX, IDC_LIST1, m_listCtrl);
DDX_Text(pDX, IDC_EDIT_F, m_f);
DDX_Text(pDX, IDC_EDIT_ANGLE, m_strAngle);
DDX_Text(pDX, IDC_EDIT_R, m_strR);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFaultAzmDlg, CDialog)
//{{AFX_MSG_MAP(CFaultAzmDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
ON_BN_CLICKED(IDC_BUTTON_RESULT, OnButtonResult)
ON_BN_CLICKED(IDC_BUTTON_ZOOMIN, OnButtonZoomin)
ON_BN_CLICKED(IDC_BUTTON_ZOOMOUT, OnButtonZoomout)
ON_BN_CLICKED(IDC_BUTTON_ZOOMEQ1, OnButtonZoomeq1)
ON_WM_LBUTTONDBLCLK()
ON_WM_MOUSEMOVE()
ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFaultAzmDlg message handlers
BOOL CFaultAzmDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_listCtrl.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
m_listCtrl.InsertColumn (0, "id", LVCFMT_RIGHT, 30);
m_listCtrl.InsertColumn (1, "datOrg", LVCFMT_RIGHT,60);
m_listCtrl.InsertColumn (2, "datSort", LVCFMT_RIGHT,60);
m_listCtrl.InsertColumn (3, "S[i+1]-S[i]", LVCFMT_RIGHT,80);
m_listCtrl.InsertColumn (4, "", LVCFMT_LEFT,10);//多插入一列
m_listCtrlRlt.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
m_listCtrlRlt.InsertColumn (0, "组别", LVCFMT_RIGHT,40);
m_listCtrlRlt.InsertColumn (1, "数目", LVCFMT_RIGHT,40);
m_listCtrlRlt.InsertColumn (2, "百分比", LVCFMT_RIGHT,60);
m_listCtrlRlt.InsertColumn (3, "最小值", LVCFMT_RIGHT, 60);
m_listCtrlRlt.InsertColumn (4, "最大值", LVCFMT_RIGHT,60);
m_listCtrlRlt.InsertColumn (5, "平均值", LVCFMT_RIGHT,60);
m_listCtrlRlt.InsertColumn (6, "标准差", LVCFMT_RIGHT,60);
m_listCtrlRlt.InsertColumn (7, "", LVCFMT_LEFT,10);//多插入一列
m_canDrawLine=false;
m_Zoom = 1.0;
f_PreDraw();
InvalidateRect(m_Rect);//Invalidate();
return TRUE; // return TRUE unless you set the focus to a control
}
void CFaultAzmDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFaultAzmDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
f_DrawCircle();
if( m_canDrawLine )
f_DrawLine();
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFaultAzmDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFaultAzmDlg::OnButtonOpen()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[]="裂隙倾向数据(*.txt)|*.txt||";
LPCTSTR lpstrDefExt="txt";
LPCTSTR lpszFileName ="*.txt";
CFileDialog dlg(true,lpstrDefExt,lpszFileName,
OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|
OFN_OVERWRITEPROMPT |
OFN_EXPLORER ,
szFilter,NULL);
//文件对话框的窗口标题
dlg.m_ofn.lpstrTitle="打开裂隙倾向数据文件";
if(dlg.DoModal()!=IDOK)
return;
//读文件
FILE *fp;
int i;
if((fp=fopen(dlg.GetPathName(),"r"))==NULL)
return;
fscanf(fp,"%d\n",&m_N);
if( m_N<=0 )
return;
m_pdatOrg = new double[m_N];
m_pidSort = new int[m_N]; m_pdatSort = new double[m_N];
m_pdatdAB = new double[m_N];
for( i=0; i<m_N; i++)
{
fscanf(fp,"%lf\n",&m_pdatOrg[i]);
m_pidSort[i]=i;
m_pdatSort[i] = m_pdatOrg[i];
}
fclose(fp);
//排序
SortData(m_pdatSort,m_N,m_pidSort);
//排序数据后者的减去前者
m_pdatdAB[0]=-1;//不用
for( i=1; i<m_N; i++ )
{
m_pdatdAB[i] = m_pdatSort[i]-m_pdatSort[i-1];
}
//显示结果到List
if( m_listCtrl.GetItemCount() > 0 )
m_listCtrl.DeleteAllItems();
CString str;
const int nColumns = 4;
int iColumn;
int iItem;
int count=m_N;
for ( i=0; i<count; i++)
{
str.Format("%d",i+1);
iItem = m_listCtrl.InsertItem(i,str,0);
for (iColumn = 1; iColumn < nColumns; iColumn++)
{
if( iColumn == 1 ) str.Format("%.3lf",m_pdatOrg[i]);
else if( iColumn == 2 ) str.Format("%.3lf",m_pdatSort[i]);
else if( iColumn == 3 ) str.Format("%.3lf",m_pdatdAB[i]);
if( iColumn == 3 && i==0 ) str="";
m_listCtrl.SetItemText(iItem,iColumn,str);
}
}
}
void CFaultAzmDlg::OnButtonResult()
{
// TODO: Add your control notification handler code here
UpdateData(true);
FindClsPos(m_pdatdAB,m_N,m_f,m_uiaClsPos);
//
int nCls = m_uiaClsPos.GetSize()+1;//分组数多1
if( nCls <=1 )
{
AfxMessageBox("分组阀值太大!");
return;
}
m_pAmzStatCell = new CELL[nCls];
int t1,t2;
for( int i=0; i<nCls; i++ )
{
if( i==0 ) t1=0;
else t1=m_uiaClsPos[i-1];
if( i==nCls-1 ) t2=m_N-1;
else t2=m_uiaClsPos[i]-1;
BasStatVar(&m_pdatSort[t1],t2-t1+1,m_pAmzStatCell[i]);
}
//输出结果
if( m_listCtrlRlt.GetItemCount() > 0 )
m_listCtrlRlt.DeleteAllItems();
CString str;
const int nColumns = 7;//--5
int iColumn;
int iItem;
for ( i=0; i<nCls; i++)
{
str.Format("第%d组",i+1);
iItem = m_listCtrlRlt.InsertItem(i,str,0);
for (iColumn = 1; iColumn < nColumns; iColumn++)
{
if( iColumn == 1 ) str.Format("%d",m_pAmzStatCell[i].n);
else if( iColumn == 2 ) str.Format("%.3lf",m_pAmzStatCell[i].per);
else if( iColumn == 3 ) str.Format("%.3lf",m_pAmzStatCell[i].min);
else if( iColumn == 4 ) str.Format("%.3lf",m_pAmzStatCell[i].max);
else if( iColumn == 5 ) str.Format("%.3lf",m_pAmzStatCell[i].mean);
else if( iColumn == 6 ) str.Format("%.3lf",m_pAmzStatCell[i].stdvar);
else { }
m_listCtrlRlt.SetItemText(iItem,iColumn,str);
}
}
//绘图
m_canDrawLine=TRUE;
InvalidateRect(m_Rect);
//f_DrawLine();
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -