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

📄 studydlg.cpp

📁 信号消燥
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// studyDlg.cpp : implementation file
//

#include "StdAfx.h"
#include "study.h"
#include "studyDlg.h"
#include "wavelet.h"
#include "math.h"
#include <stdlib.h>


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CStudyDlg dialog

CStudyDlg::CStudyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CStudyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStudyDlg)
	m_mean = 0.0f;
	m_va = 0.2f;
	m_len = _T("");
	m_sign = _T("");
	m_numofdata = _T("");
	m_wavetype = _T("");
	m_numoflayer = -1;
	m_num = _T("");
	m_Coef = _T("");
	m_noLayer = _T("");
	IsCreat=FALSE;
	m_type = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	Cut_X_Y.x=0;
	Cut_X_Y.y=0;

}

void CStudyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStudyDlg)
	DDX_Control(pDX, IDC_COMBO1, m_signal);
	DDX_Text(pDX, IDC_Mean, m_mean);
	DDX_Text(pDX, IDC_Variance, m_va);
	DDX_CBString(pDX, IDC_COMBO2, m_len);
	DDX_CBString(pDX, IDC_COMBO1, m_sign);
	DDX_CBString(pDX, IDC_COMBO3, m_numofdata);
	DDX_CBString(pDX, IDC_COMBO5, m_wavetype);
	DDX_CBString(pDX, IDC_COMBO6, m_num);
	DDX_CBString(pDX, IDC_COMBO9, m_Coef);
	DDX_CBString(pDX, IDC_COMBO10, m_noLayer);
	DDX_Radio(pDX, IDC_RADIO1, m_type);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CStudyDlg, CDialog)
	//{{AFX_MSG_MAP(CStudyDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN1, OnDeltaposSpin1)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN2, OnDeltaposSpin2)
	ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_WM_LBUTTONDBLCLK()
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_Cut, OnCut)
	ON_CBN_EDITCHANGE(IDC_COMBO9, OnEditchangeCombo9)
	ON_BN_CLICKED(IDC_BUTTON6, OnDenoise)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStudyDlg message handlers

BOOL CStudyDlg::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

	((CComboBox *)GetDlgItem(IDC_COMBO2))->SetCurSel(3);
	m_signal.SetCurSel(1);
        ((CComboBox *)GetDlgItem(IDC_COMBO4))->SetCurSel(0);
		((CComboBox *)GetDlgItem(IDC_COMBO5))->SetCurSel(0);
		((CComboBox *)GetDlgItem(IDC_COMBO8))->SetCurSel(0);
        ((CComboBox *)GetDlgItem(IDC_COMBO6))->SetCurSel(4);
				((CComboBox *)GetDlgItem(IDC_COMBO10))->SetCurSel(2);
        //((CComboBox *)GetDlgItem(IDC_COMBO8))->SetCurSel(0);
		        ((CComboBox *)GetDlgItem(IDC_COMBO9))->SetCurSel(0);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CStudyDlg::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 CStudyDlg::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
	{
		if (IsCreat==TRUE)
		{ 
		  DataPaint();
		}

		CDialog::OnPaint();

	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CStudyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}




void CStudyDlg::OnDeltaposSpin1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here
	UpdateData();
    m_mean=m_mean-0.1   *   pNMUpDown->iDelta;
	if (m_mean<0.001 && m_mean>-0.001) {m_mean=0;}
    UpdateData(false);
	*pResult = 1;
}

void CStudyDlg::OnDeltaposSpin2(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here
    UpdateData();
    m_va=m_va-0.1   *   pNMUpDown->iDelta;
	if (m_va<0.001 && m_va>-0.001) {m_va=0;}
	if (m_va<0) 
	{
		AfxMessageBox("不能小于0!");
		m_va=0;
	}
    UpdateData(false);
	*pResult = 1;
}

void CStudyDlg::OnCheck1() 
{
	// TODO: Add your control notification handler code here
	CButton* pCheck=(CButton*)GetDlgItem(IDC_CHECK1);
	if (pCheck->GetCheck())
	{
       GetDlgItem(IDC_COMBO1)->EnableWindow(false);
	   GetDlgItem(IDC_COMBO2)->EnableWindow(false);
	   GetDlgItem(IDC_Mean)->EnableWindow(false);
	   GetDlgItem(IDC_Variance)->EnableWindow(false);
	   GetDlgItem(IDC_BUTTON2)->SetWindowText("加载");
	}
	else
	{
        GetDlgItem(IDC_COMBO1)->EnableWindow(true);
	    GetDlgItem(IDC_COMBO2)->EnableWindow(true);
		GetDlgItem(IDC_Mean)->EnableWindow(true);
		GetDlgItem(IDC_Variance)->EnableWindow(true);
		GetDlgItem(IDC_BUTTON2)->SetWindowText("确定");
	}
}

void CStudyDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	
	CButton* pCheck=(CButton*)GetDlgItem(IDC_CHECK1);
	if (pCheck->GetCheck())
	{
		CFileDialog FDlg(TRUE);
		FDlg.m_ofn.lpstrFilter=("text Files(*.txt)\0*.txt\0所有文件(*.*)\0*.*\0\0");
		
		if (IDOK==FDlg.DoModal())
		{
		Load(FDlg.GetFileName(),DataOriginal);
          IsCreat=TRUE;
		  DrawData=DataOriginal;
		OnPaint();
		
		//确定需要分解的数据的个数;
		int n=DataOriginal.ColumSize();

        ((CComboBox *)GetDlgItem(IDC_COMBO3))->ResetContent();//将所有数据从组合框中删除;

		CString ii;
		for ( int i=1;i<=n;i++)
		{
			ii.Format("%d",i);  //此函数将int转化成CString型;
           ((CComboBox *)GetDlgItem(IDC_COMBO3))->AddString(ii);
		}
        ((CComboBox *)GetDlgItem(IDC_COMBO3))->SetCurSel(0);
		
		}
		
	}
	else
	{
		int num;
		UpdateData();
		if (m_sign=="Blocks")
		{
              num=1;
		}
		else if (m_sign=="Heavysine")
		{
			num=2;
		}
		wavelet.wnoise(num,atoi(m_len),m_mean,m_va,DataOriginal);
		 IsCreat=TRUE;
		  DrawData=DataOriginal;
		OnPaint();

		((CComboBox *)GetDlgItem(IDC_COMBO3))->ResetContent();//将所有数据从组合框中删除;
        CString ii;
		ii.Format("%d",1); 
		((CComboBox *)GetDlgItem(IDC_COMBO3))->AddString(ii);
		((CComboBox *)GetDlgItem(IDC_COMBO3))->SetCurSel(0);
	}
	GetDlgItem(IDC_BUTTON3)->EnableWindow(true);//使清图按钮可用;
	GetDlgItem(IDC_BUTTON4)->EnableWindow(true);//使分解按钮可用;
	GetDlgItem(IDC_Cut)->EnableWindow(true);//使截图按钮可用
}

void CStudyDlg::Plot()
{
     double max_data=DataOriginal.Max();
	 double min_data=DataOriginal.Min();
	 int len=DataOriginal.LineSize();
	 CRect dr;
	 CWnd *pCwnd=GetDlgItem(IDC_Pic);
	 CDC *Ccdc=pCwnd->GetDC();
     ::GetClientRect(pCwnd->m_hWnd,dr);
		 
	 CRect drr(dr.left+dr.Width()/10,dr.top+dr.Height()/10,dr.right-dr.Width()/10,dr.bottom-dr.Height()/10);
	
	// float IntervalX=drr.Width()/len;
	  float IntervalX=drr.Width();
	 float IntervalY=drr.Height()/(max_data-min_data);
	 Ccdc->Rectangle(&drr);
	 Ccdc->MoveTo(drr.left,drr.top+drr.Height());
//	 for (int i=1;i<len;i++)
//	 {
//		 Ccdc->LineTo(drr.left+(i-1)*IntervalX,drr.bottom-(DataOriginal[i]-min_data)*IntervalY);
//	 }
	 pCwnd->ReleaseDC(Ccdc);
	// EndPaint(Ccdc);
//	 Ccdc.MoveTo(drr.left,drr.top+drr.Height());
//	 for ( i=1;i<len;i++)
//	 {
//		 Ccdc.LineTo(drr.left+(i-1)*IntervalX,drr.bottom-(DataOriginal[i]-min_data)*IntervalY-20);
//	 }
	 

}

void CStudyDlg::Load(CString path, matrix & data2)
{
    CStdioFile Fstd(path,CFile::modeRead);
	CString data1;
	matrix temp_matrix;
	vector temp_vector;
	int k;
	BOOL InitMatrix=FALSE;
	while (NULL!=Fstd.ReadString(data1))
	{
		data1.TrimLeft();
		data1.TrimRight();
		do 
		{
		  	k=data1.Find(" ");
		   if (k!=-1)
		   {
            temp_vector.Add(atof(data1.Left(k)));
			data1.Delete(0,k);
			data1.TrimLeft();
		   }
		   else
		   {

⌨️ 快捷键说明

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