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

📄 wshmview.cpp

📁 提供交互的方式选取合适的震相
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		if( NULL != pSelSac ) {
			pSelSac->Show( false );
			list< CFileDataHolder * >::iterator iter = 
				find( m_lsShow.begin(), m_lsShow.end(), pSelSac );
			if( iter != m_lsShow.end() )
				m_lsShow.erase(iter);
		}
		Invalidate();
	}
	else if( ID_MENU_DATAFILE_ALIGNTOTHIS == LOWORD(wParam) ) {
		// 将时间轴对齐到选中的图形
		CSacFile * pSelSac = GetSelSacFile();
		if( NULL != pSelSac ) {
			CTime tm;
			double delta;

			pSelSac->GetTime(tm, delta);
			
			// align other datafile's showing time to selected datafile
			long iIndex = 0;
			list<CFileDataHolder *>::const_iterator iter = m_lsShow.begin();
			while( iter != m_lsShow.end() ) {
				if( iIndex++ != m_selFileIndex ) {
					((CSacFile*)*iter)->Align2Time(tm, delta);
				}

				++iter;
			}

			Invalidate();
		}

	}
	else if( LOWORD(wParam) >= ID_MENU_DATAFILE_EVENT &&
		LOWORD(wParam) < ID_MENU_DATAFILE_EVENT + 1000 ) {
	
		strcpy( m_strCurEvt , (pDoc->m_vecEventNm.begin() + LOWORD(wParam) - ID_MENU_DATAFILE_EVENT)->c_str() );
		SetDataShowByOption();
		Invalidate();
	}
	else if( LOWORD(wParam) >= ID_MENU_DATAFILE_PHASE &&
		LOWORD(wParam) < ID_MENU_DATAFILE_PHASE+30 ) {
		CSacFile * pSelSac = GetSelSacFile();
		
		if( NULL != pSelSac ) {
			GotoPhase( LOWORD(wParam) - ID_MENU_DATAFILE_PHASE);

			CRect drawRc;

			GetDrawRect(drawRc);
			drawRc.top = m_iDrawMoveVPos-floor(CFileDataHolder::m_singleProfileHeight/2);
			drawRc.bottom = drawRc.top + 2*CFileDataHolder::m_singleProfileHeight;

			InvalidateRect(drawRc);
		}

	}
	
	return CView::OnCommand(wParam, lParam);
}

void CWshmView::CalcMouseAtFileIndex(CPoint point)
{
	// 设置mouse所在位置的文件时间轴纵坐标,
	m_iDrawMoveVPos = long( floor(point.y/CFileDataHolder::m_singleProfileHeight) * CFileDataHolder::m_singleProfileHeight ) + 
						long(CFileDataHolder::m_singleProfileHeight/2);

	// 设置mouse所在位置的文件索引值
	// 客户区mouse所在位置对应的屏幕索引
	int nSelScrnIndex = ( m_iDrawMoveVPos - floor(CFileDataHolder::m_singleProfileHeight/2) )/CFileDataHolder::m_singleProfileHeight; 

	m_selFileIndex = m_bDrawFileIndex + nSelScrnIndex;

}

void CWshmView::GotoPhase(int nPhaseIndex)
{
	CSacFile *pSelSac = GetSelSacFile();
	long nDrawPos = pSelSac->GetPhaseDrawPos( nPhaseIndex );

	ASSERT( -1 != nDrawPos );

	CRect drawRc;
	GetDrawRect(drawRc);
	pSelSac->SetbDrawIndex4GoPos( nDrawPos, drawRc.Width() );
}

void CWshmView::OnToolMagnify() 
{
	if( ID_TOOLS_MAGNIFY != m_curTool ) {
		m_curTool = ID_TOOLS_MAGNIFY;
	}
	else
		m_curTool = ID_TOOLS_NULL;
}

void CWshmView::OnUpdateToolMagnify(CCmdUI* pCmdUI) 
{
	if( ID_TOOLS_MAGNIFY == m_curTool ) {
		pCmdUI->SetRadio();
	}
	else
		pCmdUI->SetRadio(false);
	
}
void CWshmView::OnToolSelectSks() 
{
	if( NULL == m_pDlgSKSinfo ) {
		m_pDlgSKSinfo = new CDlgSKSinfo;
		m_pDlgSKSinfo->Create( CDlgSKSinfo::IDD, this );
		m_pDlgSKSinfo->ShowWindow(SW_SHOW); 
	}
	else
		m_pDlgSKSinfo->ShowWindow(SW_SHOW); 
		
	if( ID_TOOLS_MARK_SKS != m_curTool ) {
		m_curTool = ID_TOOLS_MARK_SKS;
	}
	else
		m_curTool = ID_TOOLS_NULL;
	
}

void CWshmView::OnUpdateToolSelectSks(CCmdUI* pCmdUI) 
{
	if( ID_TOOLS_MARK_SKS == m_curTool ) {
		pCmdUI->SetRadio();
	}
	else
		pCmdUI->SetRadio(false);
	
}

void CWshmView::OnToolShowE() 
{
	if( ShowE() ) {
		ShowE(false);
		SetDataShowByOption();
	}
	else {
		ShowE(true);
		SetDataShowByOption();
	}
	Invalidate();
	
}

void CWshmView::OnUpdateToolShowE(CCmdUI* pCmdUI) 
{
	if( ShowE() )
		pCmdUI->SetCheck();
	else
		pCmdUI->SetCheck(false);
	
}

void CWshmView::OnToolShowN() 
{
	if( ShowN() ) {
		ShowN(false);
		SetDataShowByOption();
	}
	else {
		ShowN(true);
		SetDataShowByOption();
	}
	Invalidate();
	
}

void CWshmView::OnUpdateToolShowN(CCmdUI* pCmdUI) 
{
	if( ShowN() )
		pCmdUI->SetCheck();
	else
		pCmdUI->SetCheck(false);	
}

void CWshmView::OnToolShowZ() 
{
	if( ShowZ() ) {
		ShowZ(false);
		SetDataShowByOption();
	}
	else {
		ShowZ(true);
		SetDataShowByOption();
	}
	Invalidate();
}

void CWshmView::OnUpdateToolShowZ(CCmdUI* pCmdUI) 
{
	if( ShowZ() )
		pCmdUI->SetCheck();
	else
		pCmdUI->SetCheck(false);
	
}

void CWshmView::OnToolModeEvent() 
{
	if( !ShowEvent() ) {
		ShowEvent(true);
		if( 0 == strlen(m_strCurEvt) ) {
			CWshmDoc* pDoc = GetDocument();
			ASSERT_VALID(pDoc);

			if( pDoc->m_vecEventNm.size() )
				strcpy( m_strCurEvt , pDoc->m_vecEventNm.begin()->c_str() );
		}

		SetDataShowByOption();
		Invalidate();
	}
}

void CWshmView::OnUpdateToolModeEvent(CCmdUI* pCmdUI) 
{
	if( ShowEvent() )
		pCmdUI->SetRadio();
	else
		pCmdUI->SetRadio(false);	
}

void CWshmView::OnToolModeFile() 
{
	if( !ShowFile() ) {
		ShowFile(true);
		SetDataShowByOption();
		Invalidate();
	}
}

void CWshmView::OnUpdateToolModeFile(CCmdUI* pCmdUI) 
{
	if( ShowFile() )
		pCmdUI->SetRadio();
	else
		pCmdUI->SetRadio(false);		
}
// Note: Tony.Huang
// all the algorithm's implementation were written
// by William Menke, 1998
void CWshmView::CalcCurSKSparam(const CPoint &point)
{
	CSacFile* pSac = GetSelSacFile();
	if( NULL == pSac )
		return;

	string staName = pSac->GetStaNm();
	string evtName = pSac->GetEvtNm();
	CTime selTimeBegin;
	double tmdelta;
	pSac->GetTime(selTimeBegin, tmdelta, m_ptMouseDown.x);
	float *pSKSe, *pSKSn;

	fprintf( skslog, "%s\n",staName.c_str() );
	fprintf( skslog, "%s\n",evtName.c_str() );
	fprintf( skslog, "data start time: %d/%d/%d %d:%d:%6.3f\n", selTimeBegin.GetYear(), 
		selTimeBegin.GetMonth(), 
		selTimeBegin.GetDay(), 
		selTimeBegin.GetHour(), 
		selTimeBegin.GetMinute(),
		selTimeBegin.GetSecond() + tmdelta );

	std::list<CFileDataHolder *>::const_iterator iter = m_lsShow.begin();
	while( iter != m_lsShow.end() ) {
		if( ! stricmp(((CSacFile*)*iter)->GetStaNm(), staName.c_str()) &&
			! stricmp(((CSacFile*)*iter)->GetEvtNm(), evtName.c_str()) ) {
			if( 'e' == ((CSacFile*)*iter)->GetCmpNm() ) {
				// adjust to selection
				pSKSe = ((CSacFile*)*iter)->GetDataPtrByTime(selTimeBegin);
			}
			else if( 'n' == ((CSacFile*)*iter)->GetCmpNm() ) {
				// adjust to selection
				pSKSn = ((CSacFile*)*iter)->GetDataPtrByTime(selTimeBegin);
			}
		}
		++iter;
	}
	ASSERT( NULL != pSKSe && NULL != pSKSn );
	if( NULL == pSKSe && NULL == pSKSn )
		return;

	int i, ndata = pSac->GetNptsByWidth( abs(point.x - m_ptMouseDown.x) );
	fprintf( skslog, "Number of points: %d\ne\tn\n", ndata );

	// demean
	//计算北、东水平分量振幅的平均值。
	double em=0.0, nm=0.0;
	for( i=0; i<ndata; i++ ) {
		em += (double)pSKSe[i];
		nm += (double)pSKSn[i];

		fprintf( skslog, "%f\t%f\n", pSKSe[i], pSKSn[i] );

		}
	em /= (double)ndata;
	nm /= (double)ndata;
	//调整分量的零值到均值
	for( i=0; i<ndata; i++ ) {
		pSKSe[i] -= (float)em;
		pSKSn[i] -= (float)nm;
	}
	double * dedata = new double[ndata];
	double * dndata = new double[ndata];
	double delta = pSac->GetDelta();
	double direction;
	double delay;
	double dir_curv, delay_curv, cross_curv, C;
	//转换数据为double类型并存储到dedata, dndata
	for( i=0; i<ndata; i++ ) 
	{
		dedata[i] = (double)pSKSe[i];
		dndata[i] = (double)pSKSn[i];
	}
	//估算S波分裂的方向和延时,
	splitest(dedata, dndata,	//input, east and north component
		delta,		//input, the sampling interval of the east and north component seismgrams
		ndata,		//input, the number of samples
		direction,				//output, the direction of fast wave
		delay,					//output, 
		dir_curv, delay_curv, cross_curv, C); //output, the error estimate
		

	fprintf( skslog, "fast direction: %f\n", direction );
	fprintf( skslog, "delay: %f\n", delay );
	/* evaluate */
	//将均值调整到零的数据再次复制到dedata, dndata中准备下一步处理
	for( i=0; i<ndata; i++ ) {
		dedata[i] = (double)pSKSe[i];
		dndata[i] = (double)pSKSn[i];
		}

	double snratio, snratio2;
	double dir_err, delay_err, det;
	double oversamp, *mean = NULL, *residual = NULL, *tauto = NULL;
	float *fmean = NULL, *fresidual = NULL, *ftauto = NULL;

	mean = new double[ndata];
	residual = new double[ndata];
	tauto = new double[ndata];

	fmean = new float[ndata];
	fresidual = new float[ndata];
	ftauto = new float[ndata];

	//?获取评估splitest()得到的s波分裂参数数据
	split_rotate( dedata, dndata, ndata, delta,
		direction, delay, 
		snratio2,	//output, 
		oversamp,
		mean, residual, tauto );
	
	for( i=0; i<ndata; i++ ) {
		fmean[i] = (float)mean[i];
		fresidual[i] = (float)residual[i];
		ftauto[i] = (float)tauto[i];
		}

	// error calculation
	if( C<=1.0 ) {
		snratio = 1.0/sqrt((1.0/fabs(C))-1.0);
		}
	else {
		snratio=1000.0;
		}
	det = dir_curv*delay_curv - cross_curv*cross_curv;
	dir_err = sqrt(fabs(2.0*delay_curv/det));
	delay_err = sqrt(fabs(2.0*dir_curv/det));
	dir_err *= sqrt(oversamp) / 
	(snratio2*sqrt((double)ndata));
	delay_err *= sqrt(oversamp) /
	(snratio2*sqrt((double)ndata));
	C=fabs(C);

	fprintf( skslog,"direction error: %f\n", dir_err );
	fprintf( skslog,"delay error: %f\n", delay_err );
	fprintf( skslog,"crosscorrelation value: %f\n", C );

	delete []mean;
	delete []residual;
	delete []tauto;

	delete []fmean;
	delete []fresidual;
	delete []ftauto;

	delete []dedata;
	delete []dndata;

	float dist,azi,bazi;
	float evtLat, evtLon, stationLat, stationLon;
	pSac->GetStationLoc( stationLat, stationLon );
	pSac->GetEventLoc( evtLat, evtLon );

	//计算距离、方位角、反方位角,单位:度
	distaz(evtLat,
		evtLon, 
		stationLat,
		stationLon,
		dist,
		azi,
		bazi);

	fprintf( skslog, "station location(lat,lon): %f,%f\n", stationLat, stationLon );
	fprintf( skslog, "event location(lat,lon):%f,%f\n", evtLat, evtLon );
	fprintf( skslog, "azimuth: %f\n", azi );

	m_pDlgSKSinfo->SetDelay( delay );
	m_pDlgSKSinfo->SetDelay_err( delay_err );
	m_pDlgSKSinfo->SetDirection( direction );
	m_pDlgSKSinfo->SetDir_err( dir_err );
	m_pDlgSKSinfo->SetCorrelation( C );
	m_pDlgSKSinfo->SetAzimuth(azi);
	m_pDlgSKSinfo->SetStationLoc( stationLat, stationLon );
	m_pDlgSKSinfo->SetEventLoc( evtLat, evtLon );
	m_pDlgSKSinfo->ShowWindow(SW_SHOW); 
}

void CWshmView::OnFileOpen() 
{
	CFileDialog dlg(true, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_FILEMUSTEXIST, 
		"文件名列表文件(*.nam)|*.nam||");

	if( dlg.DoModal() == IDOK ) {
		CWshmDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);

		pDoc->OpenListFile( LPCTSTR(dlg.GetPathName()) );
		m_bDrawFileIndex = 0;
		m_lsShow = pDoc->m_lsDataHolder;
		
		SetDataShowByOption();
	}	
}

void CWshmView::SetDataShowByOption( BOOL bOn ){
	// first of all, clear the show container.
	m_bDrawFileIndex = 0;
	m_lsShow.clear();

	const int & option = m_ShowOption;
	CWshmDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	list<CFileDataHolder *> &lsDataHolder = pDoc->m_lsDataHolder;
	list<CFileDataHolder *>::const_iterator iter = lsDataHolder.begin();
	// set the E component
	if( eShowFile & option ) {
		while( iter != lsDataHolder.end() ) {
			if( ( 'e' == ((CSacFile*)*iter)->GetCmpNm() ) && ( eShowE & option ) ||
				( 'n' == ((CSacFile*)*iter)->GetCmpNm() ) && ( eShowN & option ) ||
				( 'z' == ((CSacFile*)*iter)->GetCmpNm() ) && ( eShowZ & option ) )  {

				((CSacFile*)*iter)->Show( bOn );
				m_lsShow.push_back(*iter);
			}
			else
				((CSacFile*)*iter)->Show( !bOn );

			++iter;
		}
	}
	else if( eShowEvent & option ) {
		while( iter != lsDataHolder.end() ) {
			if( !stricmp( m_strCurEvt, ((CSacFile*)*iter)->GetEvtNm() ) ) {
				if( ( 'e' == ((CSacFile*)*iter)->GetCmpNm() ) && ( eShowE & option ) ||
					( 'n' == ((CSacFile*)*iter)->GetCmpNm() ) && ( eShowN & option ) ||
					( 'z' == ((CSacFile*)*iter)->GetCmpNm() ) && ( eShowZ & option ) ) {
					((CSacFile*)*iter)->Show( bOn );
					m_lsShow.push_back(*iter);
				}
				else
					((CSacFile*)*iter)->Show( !bOn );
			}
			else
				((CSacFile*)*iter)->Show( !bOn );

			++iter;
		}

	}

	list<CFileDataHolder *>::size_type size = m_lsShow.size();
	CRect viewRc;

	GetDrawRect(viewRc);

	SetScrollRange( SB_VERT, 0, size - viewRc.Height()/CFileDataHolder::m_singleProfileHeight, false );
	SetScrollPos( SB_VERT, 0 );
}

CSacFile *CWshmView::GetSelSacFile(void){

	long iIndex = m_selFileIndex;
	VERIFY( iIndex >= 0 );

	std::list<CFileDataHolder *>::const_iterator iter = m_lsShow.begin();
	while( iter != m_lsShow.end() ) {
		if( 0 == iIndex-- ) {
			break;
		}
		++iter;
	}
	if( iter != m_lsShow.end() )
		return (CSacFile*)*iter;
	else 
		return NULL;
}

void CWshmView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	if( nSBCode == SB_LINEUP ) {// 向上滚动一行
		if( m_bDrawFileIndex ) {
			--m_bDrawFileIndex;
			int pos = GetScrollPos(SB_VERT);
			SetScrollPos(SB_VERT, --pos);

			Invalidate();
		}
	}
	else if( nSBCode == SB_LINEDOWN ) { //向下滚动一行
		if( m_bDrawFileIndex < m_lsShow.size() ) {
			++m_bDrawFileIndex;
			int pos = GetScrollPos(SB_VERT);
			SetScrollPos(SB_VERT, ++pos);
			Invalidate();
		}
	}
	
	CView::OnVScroll(nSBCode, nPos, pScrollBar);
}

⌨️ 快捷键说明

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