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

📄 stmpatheventhandle.cpp

📁 电子交通地图
💻 CPP
字号:
// STMPathEventHandle.cpp: implementation of the CSTMPathEventHandle class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "stmeditor.h"
#include "STMPathEventHandle.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSTMPathEventHandle::CSTMPathEventHandle()
{
	m_pDoc=NULL;
	m_pMapView=NULL;
}

CSTMPathEventHandle::~CSTMPathEventHandle()
{
}

void CSTMPathEventHandle::OnLButtonUp(UINT nFlags, CPoint point)
{
	if(m_pDoc->m_focusEI.eleType==ET_CROSS)
	{
		if(m_pDoc->m_activeType==ACT_PATH_PICK_BEGIN)
		{
			if(m_pDoc->m_focusEI.index==-1) return;
			m_pDoc->m_activeType=ACT_PATH_PICK_END;
			m_traceLineBegin=m_pDoc->m_arrCross.GetAt(m_pDoc->m_focusEI.index).pos ;
			m_hotPath.begin_id=m_pDoc->m_focusEI.index;
			m_traceLineEnd=m_traceLineBegin;
		}else if(m_pDoc->m_activeType==ACT_PATH_PICK_END)
		{
			if(m_pDoc->m_focusEI.index==-1) return;
			XORtraceLine();
			m_hotPath.end_id=m_pDoc->m_focusEI.index;
			if(m_hotPath.end_id==m_hotPath.begin_id)
			{
				m_pMapView->MessageBox("the path's two points can not be the same!","input error");
			}else
			{
				int index=m_pDoc->AddPath(m_hotPath);
				if(index!=-1)
				{
					DrawPath(index);
					m_traceLineBegin=m_pDoc->m_arrCross.GetAt(m_pDoc->m_focusEI.index).pos ;
					m_hotPath.begin_id=m_pDoc->m_focusEI.index;
					m_traceLineEnd=m_traceLineBegin;
				}else
				{
					m_pMapView->MessageBox("the path has existed!","error");
				}
			}
		}
	}else if(m_pDoc->m_focusEI.eleType==ET_PATH&&
		m_pDoc->m_focusEI.index!=-1)
	{
		if(m_pDoc->m_activeType==ACT_BROWSE)//select the path
		{
//			m_pMapView->MessageBox("you have click a path");
		}
	}
}

void CSTMPathEventHandle::OnRButtonUp(UINT nFlags, CPoint point)
{
	if(m_pDoc->m_focusEI.eleType==ET_PATH && 
		m_pDoc->m_focusEI.index !=-1)
	{
		if(m_pDoc->m_focusEI.eleType==ET_PATH &&
			m_pDoc->m_focusEI.index!=-1 &&
			m_pDoc->m_activeType!=ACT_PATH_PICK_END)//delete path
		{
			CRgn effectrgn;
			m_pDoc->RemovePath(effectrgn,m_pDoc->m_focusEI.index);
			m_pDoc->m_focusEI.index=-1;
			m_pDoc->m_preFocusEI.index=-1;
			m_pMapView->InvalidateRgn(&effectrgn,FALSE);
		}
	}
	if(m_pDoc->m_activeType==ACT_PATH_PICK_END) //cancel the pick active
	{
		m_pDoc->m_activeType=ACT_PATH_PICK_BEGIN;
		XORtraceLine();
	}
}

void CSTMPathEventHandle::OnMouseMove(UINT nFlags, CPoint point)
{
	POINT	originpoint;
	originpoint=m_pMapView->GetScrollPosition();
	point.Offset(originpoint);

	if(m_pDoc->m_activeType==ACT_PATH_PICK_END)
	{
		XORtraceLine();
		m_traceLineEnd=point;
		XORtraceLine();
	}else if(m_pDoc->m_activeType==ACT_CROSS_MOVE)//move attached path
	{

	}else //if(m_pDoc->m_activeType==ACT_BROWSE)
	{
		if(m_pDoc->m_bFocusChanged)
		{
			if(m_pDoc->m_preFocusEI.eleType==ET_PATH &&
				m_pDoc->m_preFocusEI.index!=-1) //restore old focus 
			{
				DrawPath(m_pDoc->m_preFocusEI.index);
			}
			if(m_pDoc->m_focusEI.eleType==ET_PATH &&
				m_pDoc->m_focusEI.index!=-1)
			{
				DrawPath(m_pDoc->m_focusEI.index);
			}
		}
	}
}

POINT CSTMPathEventHandle::CalcHitPoint(int begin, int end)
{
	POINT hitpt;
	POINT beginpt,endpt;
	beginpt=m_pDoc->m_arrCross.GetAt(begin).pos ;
	endpt=m_pDoc->m_arrCross.GetAt(end).pos ;
	hitpt.x=(beginpt.x+endpt.x)/2;
	hitpt.y=(beginpt.y+endpt.y)/2;
	return hitpt;
}

void CSTMPathEventHandle::DrawPath(int index)
{
	PATHINFO pi=m_pDoc->m_arrPath.GetAt(index);
	ELEINFO	ei;
	ei.eleType=ET_PATH;
	ei.index=index;
	ELESTATE state=m_pDoc->GetElementState(ei);//get element state
	COLORREF color;
	switch(state)
	{
	case ES_NORMAL:color=RGB(0,0,255);break;
	case ES_FOCUS:color=RGB(255,255,0);break;
	case ES_SELECTED:color=RGB(255,0,0);break;
	}

	POINT	originpoint;
	originpoint=m_pMapView->GetScrollPosition();


	CDC *pDC=m_pMapView->GetDC();
	POINT	lineBegin,lineEnd;
	lineBegin=m_pDoc->m_arrCross.GetAt(pi.begin_id).pos ;
	lineEnd=m_pDoc->m_arrCross.GetAt(pi.end_id).pos ;
	if(lineBegin.x==-1 ||lineEnd.x==-1) return;

	lineBegin.x-=originpoint.x;
	lineBegin.y-=originpoint.y;
	lineEnd.x-=originpoint.x;
	lineEnd.y-=originpoint.y;

	CPen	linePen,*oldpen;
	linePen.CreatePen(PS_SOLID,3,color);
	oldpen=pDC->SelectObject(&linePen);
	pDC->MoveTo(lineBegin);
	pDC->LineTo(lineEnd);
	pDC->SelectObject(oldpen);
	m_pMapView->ReleaseDC(pDC);
}

void CSTMPathEventHandle::DrawAllPathes()
{
	for(int i=0;i<m_pDoc->m_arrPath.GetSize();i++)
	{
		DrawPath(i);
	}
}

void CSTMPathEventHandle::XORtraceLine()
{
	if(m_traceLineBegin.x==m_traceLineEnd.x&&
		m_traceLineBegin.y==m_traceLineEnd.y)
		return;

	POINT	originpoint;
	originpoint=m_pMapView->GetScrollPosition();

	CDC *pDC=m_pMapView->GetDC();
	CPen pen,*oldpen;
	pen.CreatePen(PS_SOLID,3,RGB(0,0,125));
	oldpen=pDC->SelectObject(&pen);
	int	preDrawMode=pDC->SetROP2(R2_NOTXORPEN);
	POINT begin,end;
	begin=m_traceLineBegin,end=m_traceLineEnd;
	begin.x-=originpoint.x;
	begin.y-=originpoint.y;
	end.x-=originpoint.x;
	end.y-=originpoint.y;

	pDC->MoveTo(begin);
	pDC->LineTo(end);
	pDC->SetROP2(preDrawMode);
	pDC->SelectObject(oldpen);
	m_pMapView->ReleaseDC(pDC);
}

void CSTMPathEventHandle::OnLButtonDown(UINT nFlags, CPoint point)
{
	//draw new selected path
	if(m_pDoc->m_focusEI.eleType==ET_PATH &&
		m_pDoc->m_focusEI.index!=-1)
	{
		ELEINFO selEI=m_pDoc->m_focusEI;
		m_pDoc->SelectElements(&selEI,1);
		DrawPath(selEI.index);
	}
}

void CSTMPathEventHandle::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{

}

⌨️ 快捷键说明

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