ewaveDlg.cpp
资源名称:ewave.rar [点击查看]
上传用户:mayisishi
上传日期:2007-08-08
资源大小:80k
文件大小:13k
源码类别:
能源行业(电力石油煤炭)
开发平台:
Visual C++
- // ewaveDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ewave.h"
- #include "ewaveDlg.h"
- #include "math.h"
- #include "fstream.h"
- double adAg[2000],adt[2000],amax,tmax,dOpx=65,dOpy=220,adAgtemp[2000];
- #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()
- /////////////////////////////////////////////////////////////////////////////
- // CEwaveDlg dialog
- CEwaveDlg::CEwaveDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CEwaveDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CEwaveDlg)
- m_dAmax = 0.08;
- m_dTg = 0.65;
- m_pd = 35;
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CEwaveDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CEwaveDlg)
- DDX_Text(pDX, IDC_AMAX, m_dAmax);
- DDX_Text(pDX, IDC_TG, m_dTg);
- DDX_Text(pDX, IDC_PD, m_pd);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CEwaveDlg, CDialog)
- //{{AFX_MSG_MAP(CEwaveDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDOK, OnSTART)
- ON_BN_CLICKED(IDC_OUTPUT, OnOutput)
- ON_BN_CLICKED(IDC_INPUT, OnInput)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CEwaveDlg message handlers
- BOOL CEwaveDlg::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
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CEwaveDlg::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 CEwaveDlg::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(adt[0]==0)
- {
- CPaintDC dcb(this);
- CBrush br(RGB(0,0,0));
- CBrush * pOldBr;
- pOldBr=dcb.SelectObject(&br);
- dcb.Rectangle(dOpx-50,dOpy-70,dOpx+420,dOpy+70);
- dcb.SelectObject(pOldBr);
- CClientDC dc(this);
- CPen pen(PS_SOLID,1,RGB(0,255,0));
- CPen *pOldPen;
- pOldPen=dc.SelectObject(&pen);
- dc.MoveTo(dOpx,dOpy-40);
- dc.LineTo(dOpx,dOpy+40);
- dc.MoveTo(dOpx+100,dOpy-40);
- dc.LineTo(dOpx+100,dOpy+40);
- dc.MoveTo(dOpx+200,dOpy-40);
- dc.LineTo(dOpx+200,dOpy+40);
- dc.MoveTo(dOpx+300,dOpy-40);
- dc.LineTo(dOpx+300,dOpy+40);
- dc.MoveTo(dOpx+400,dOpy-40);
- dc.LineTo(dOpx+400,dOpy+40);
- dc.MoveTo(dOpx,dOpy-40);
- dc.LineTo(dOpx+400,dOpy-40);
- dc.MoveTo(dOpx,dOpy);
- dc.LineTo(dOpx+400,dOpy);
- dc.MoveTo(dOpx,dOpy+40);
- dc.LineTo(dOpx+400,dOpy+40);
- dc.SelectObject(pOldPen);
- CClientDC dcf(this);
- CFont font,font1;
- font.CreateFont(15,0,0,0,560,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
- OUT_DEFAULT_PRECIS,PROOF_QUALITY,FF_ROMAN,"a");
- font1.CreateFont(17,0,0,0,0,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
- OUT_DEFAULT_PRECIS,PROOF_QUALITY,FF_ROMAN,"a1");
- CFont * pOldFont;
- pOldFont=dcf.SelectObject(&font);
- dcf.SetBkMode(TRANSPARENT);
- dcf.SetTextColor(RGB(255,255,0));
- dcf.TextOut(dOpx+5,dOpy+40,"0");
- dcf.TextOut(dOpx+95,dOpy+40,"10");
- dcf.TextOut(dOpx+195,dOpy+40,"20");
- dcf.TextOut(dOpx+295,dOpy+40,"30");
- dcf.TextOut(dOpx+395,dOpy+40,"40");
- dcf.TextOut(dOpx-10,dOpy-6,"0");
- dcf.TextOut(dOpx+193,dOpy+53,"t(s)");
- dcf.TextOut(dOpx-45,dOpy-6,"a(gal)");
- pOldFont=dcf.SelectObject(&font1);
- dcf.SetBkMode(TRANSPARENT);
- dcf.SetTextColor(RGB(255,255,0));
- dcf.TextOut(dOpx+105,dOpy-63,"人工地震波加速度时程曲线");
- dcf.SelectObject(pOldFont);
- }
- else
- {
- Wavedrawing();
- }
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CEwaveDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CEwaveDlg::Wavegener()
- {
- UpdateData(true);
- double dAmax=m_dAmax*9.8;
- double adGpu[10000],adFpu[10000],ddOmiga=0.02,adOmiga[10000];
- double Omiga1=2*pi/(5*m_dTg),Omiga2=2*pi/m_dTg,Omiga3=20*pi;
- /////////////////////////////////////////////////////////////////////
- ///////得到反应谱
- for(int loop=0;loop<10000;loop++)
- {
- adOmiga[loop]=(loop+1-0.5)*ddOmiga;
- if(adOmiga[loop]<=Omiga1)
- adFpu[loop]=pow(0.2,0.9)*dAmax-0.02*dAmax*(2*pi/adOmiga[loop]-5*m_dTg);
- else
- if(adOmiga[loop]>=Omiga1 && adOmiga[loop]<Omiga2)
- adFpu[loop]=pow(m_dTg*adOmiga[loop]/(2*pi),0.9)*dAmax;
- else
- if(adOmiga[loop]>=Omiga2 && adOmiga[loop]<Omiga3)
- adFpu[loop]=dAmax;
- else
- adFpu[loop]=11*dAmax*pi/adOmiga[loop]+0.45*dAmax;
- }
- /////////////////////////////////////////////////////////////////////
- ///////得到功率谱
- for(loop=0;loop<10000;loop++)
- {
- if(adFpu[loop]<0)
- adFpu[loop]=0.0;
- adGpu[loop]=2*0.05*pow(adFpu[loop],2)/(-2*(pi*adOmiga[loop])*log(-pi*log(0.85)/(adOmiga[loop]*40)));
- }
- /////////////////////////////////////////////////////////////////////
- ///////生成地震波
- double adFi[10000];
- int i;
- srand((unsigned)time( NULL ));
- for(loop=0;loop<10000;loop++)
- {
- int temp=rand();
- temp=temp%6282+1;
- adFi[loop]=double(temp)/1000; //随机相位角
- }
- for(loop=0;loop<2000;loop++)
- adt[loop]=0.02*(loop+1);
- for(loop=0;loop<2000;loop++)
- {
- adAg[loop]=0;
- i=0;
- while(i<10000)
- {
- adAg[loop]+=pow(0.08*adGpu[i],0.5)*cos(adOmiga[i]*adt[loop]+adFi[i]); //人工波地面加速度
- i++;
- }
- }
- for(loop=0;loop<200;loop++)
- adAg[loop]*=pow(adt[loop]/4,2);
- for(loop=750;loop<2000;loop++)
- adAg[loop]*=pow(2.71828,-0.15*(adt[loop]-15)); //乘包络线
- for(loop=0;loop<2000;loop++)
- adAg[loop]*=100; //转换单位
- for(loop=0;loop<2000;loop++)
- {
- if(adAg[loop]<0)
- adAgtemp[loop]=-adAg[loop];
- else
- adAgtemp[loop]=adAg[loop];
- }
- amax=0;
- for(loop=0;loop<2000;loop++)
- {
- if(adAgtemp[loop]>amax)
- {amax=adAgtemp[loop];
- tmax=adt[loop];
- }
- } //求峰值
- for(loop=0;loop<2000;loop++)
- adAg[loop]*=m_pd/amax; //修正峰值
- amax=0;
- for(loop=0;loop<2000;loop++)
- {
- if(adAg[loop]<0)
- adAgtemp[loop]=-adAg[loop];
- else
- adAgtemp[loop]=adAg[loop];
- }
- for(loop=0;loop<2000;loop++)
- {
- if(adAgtemp[loop]>amax)
- {amax=adAgtemp[loop];
- tmax=adt[loop];
- }
- }
- UpdateData(false);
- }
- /////////////////////////////////////////////////////////////////////
- ///////绘制地震波加速度时程曲线
- void CEwaveDlg::Wavedrawing()
- {
- Invalidate();
- CPaintDC dcb(this);
- CBrush br(RGB(0,0,0));
- CBrush * pOldBr;
- pOldBr=dcb.SelectObject(&br);
- dcb.Rectangle(dOpx-50,dOpy-70,dOpx+420,dOpy+70);
- dcb.SelectObject(pOldBr);
- CClientDC dc(this);
- CPen pen(PS_SOLID,1,RGB(255,0,0));
- CPen *pOldPen;
- CPen pen1(PS_SOLID,1,RGB(0,255,0));
- pOldPen=dc.SelectObject(&pen);
- dc.MoveTo(dOpx,dOpy);
- for(int loop=0;loop<2000;loop++)
- dc.LineTo(dOpx+adt[loop]*10,dOpy-adAg[loop]*40/amax);
- pOldPen=dc.SelectObject(&pen1);
- dc.MoveTo(dOpx,dOpy-40);
- dc.LineTo(dOpx,dOpy+40);
- dc.MoveTo(dOpx+100,dOpy-40);
- dc.LineTo(dOpx+100,dOpy+40);
- dc.MoveTo(dOpx+200,dOpy-40);
- dc.LineTo(dOpx+200,dOpy+40);
- dc.MoveTo(dOpx+300,dOpy-40);
- dc.LineTo(dOpx+300,dOpy+40);
- dc.MoveTo(dOpx+400,dOpy-40);
- dc.LineTo(dOpx+400,dOpy+40);
- dc.MoveTo(dOpx,dOpy-40);
- dc.LineTo(dOpx+400,dOpy-40);
- dc.MoveTo(dOpx,dOpy);
- dc.LineTo(dOpx+400,dOpy);
- dc.MoveTo(dOpx,dOpy+40);
- dc.LineTo(dOpx+400,dOpy+40);
- dc.SelectObject(pOldPen);
- CString str,str1;
- str.Format("%3.0f",amax);
- str1.Format("%3.0f",-amax);
- CClientDC dcf(this);
- CFont font,font1;
- font.CreateFont(15,0,0,0,560,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
- OUT_DEFAULT_PRECIS,PROOF_QUALITY,FF_ROMAN,"a");
- font1.CreateFont(17,0,0,0,0,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
- OUT_DEFAULT_PRECIS,PROOF_QUALITY,FF_ROMAN,"a1");
- CFont * pOldFont;
- pOldFont=dcf.SelectObject(&font);
- dcf.SetBkMode(TRANSPARENT);
- dcf.SetTextColor(RGB(255,255,0));
- dcf.TextOut(dOpx+5,dOpy+40,"0");
- dcf.TextOut(dOpx+95,dOpy+40,"10");
- dcf.TextOut(dOpx+195,dOpy+40,"20");
- dcf.TextOut(dOpx+295,dOpy+40,"30");
- dcf.TextOut(dOpx+395,dOpy+40,"40");
- dcf.TextOut(dOpx-10,dOpy-6,"0");
- dcf.TextOut(dOpx+193,dOpy+53,"t(s)");
- dcf.TextOut(dOpx-45,dOpy-6,"a(gal)");
- dcf.TextOut(dOpx-25,dOpy-45,str);
- dcf.TextOut(dOpx-25,dOpy+35,str1);
- pOldFont=dcf.SelectObject(&font1);
- dcf.SetBkMode(TRANSPARENT);
- dcf.SetTextColor(RGB(255,255,0));
- dcf.TextOut(dOpx+105,dOpy-63,"人工地震波加速度时程曲线");
- dcf.SelectObject(pOldFont);
- UpdateWindow();
- }
- void CEwaveDlg::OnSTART()
- {
- // TODO: Add your control notification handler code here
- Wavegener();
- Wavedrawing();
- }
- /////////////////////////////////////////////////////////////////////
- ///////数据输出
- void CEwaveDlg::OnOutput()
- {
- // TODO: Add your control notification handler code here
- CString sFileName;
- ofstream fout;
- CFileDialog dlg(false);
- char sFilter[]="All file(*.*) *.* ";
- dlg.m_ofn.lpstrFilter=sFilter;
- if(dlg.DoModal()==IDOK)
- {
- sFileName=dlg.GetPathName();
- if(sFileName.GetLength()==0)return;
- fout.open(sFileName);
- }
- fout<<"t"<<" "<<tmax<<" "<<"a"<<" "<<amax<<endl;
- for(int loop=0;loop<2000;loop++)
- fout<<adt[loop]<<" "<<adAg[loop]<<endl;
- fout.close();
- }
- /////////////////////////////////////////////////////////////////////
- ///////数据输入
- void CEwaveDlg::OnInput()
- {
- // TODO: Add your control notification handler code here
- CString sFileName;
- ifstream fin;
- char tempt,tempa;
- double temptmax,tempamax;
- CFileDialog dlg(true);
- char sFilter[]="All file(*.*) *.* ";
- dlg.m_ofn.lpstrFilter=sFilter;
- if(dlg.DoModal()==IDOK)
- {
- sFileName=dlg.GetPathName();
- if(sFileName.GetLength()==0)return;
- fin.open(sFileName);
- }
- fin>>tempt>>temptmax>>tempa>>tempamax;
- for(int loop=0;loop<2000;loop++)
- fin>>adt[loop]>>adAg[loop];
- fin.close();
- for(loop=0;loop<2000;loop++)
- {
- if(adAg[loop]<0)
- adAgtemp[loop]=-adAg[loop];
- else
- adAgtemp[loop]=adAg[loop];
- }
- amax=0;
- for(loop=0;loop<2000;loop++)
- {
- if(adAgtemp[loop]>amax)
- {amax=adAgtemp[loop];
- tmax=adt[loop];
- }
- }
- Wavedrawing();
- UpdateData(false);
- }