You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

274 lines
7.5 KiB
C++

#include "StdAfx.h"
#include "GlobalDrawMgr.h"
#include "GlobalFunction.h"
#include "MouseToolmgr.h"
#include "MouseToolPointer.h"
#include "MouseToolRect.h"
#include "MouseToolLine.h"
#include "MouseToolCircle.h"
#include "MouseToolMove.h"
#include "MouseToolRotate.h"
#include "MarkObjPropertieMgr.h"
#include "MouseToolMove2.h"
#include "MouseToolMeasure.h"
#include "MouseToolCopy.h"
#include "MouseToolCut.h"
#include "MouseToolPline.h"
#include "MouseToolDelNode.h"
#include "MouseToolAddNode.h"
#include "MouseToolBreakNode.h"
#include "MouseToolMoveNode.h"
#include "MouseToolOnePoint.h"
#include "CatchMgr.h"
#include "MouseToolStretch.h"
#include "EasyOperationMgr.h"
#include "MouseToolLaserCoord.h"
//全局指针工具管理对象
CMouseToolMgr gMouseToolMgr;
CMouseToolMgr::CMouseToolMgr(void)
{
m_MouseToolType = _TOOL_POINT;
}
CMouseToolMgr::~CMouseToolMgr(void)
{
ReleseTool();
}
void CMouseToolMgr::ReleseTool()
{
if(m_pMouseTool)
delete m_pMouseTool;
}
//设置鼠标工具
void CMouseToolMgr::SetMouseTool(MOUSE_TOOL MouseToolType)
{
GetCurViewPtr()->SetCursorStyle(MouseToolType);
//保存之前的工具
m_OldMouseToolType = m_MouseToolType;
m_MouseToolType = MouseToolType;
//先删除原来的工具
ReleseTool();
//设置新工具
m_pMouseTool = CreatMouseTool(MouseToolType);
//标题栏刷新
if(GetFrame())
{
//一些工具将鼠标限制在view 以内
if(m_MouseToolType != _TOOL_POINT)
{
GetCurViewPtr()->LimitCursor();
}
else
{
GetCurViewPtr()->ReleseLimitCursor();
}
}
}
CMouseTool * CMouseToolMgr::CreatMouseTool(MOUSE_TOOL MouseToolType)
{
CMouseTool *pMouseTool = NULL;
switch(MouseToolType)
{
case _TOOL_POINT:
pMouseTool = new CMouseToolPointer;
break;
case _TOOL_RECT:
pMouseTool = new CMouseToolRect;
break;
case _TOOL_CIRCLE:
pMouseTool = new CMouseToolCircle;
break;
case _TOOL_LINE:
pMouseTool = new CMouseToolLine;
break;
case _TOOL_PLINE:
pMouseTool = new CMouseToolPline;
break;
case _TOOL_MOVE:
pMouseTool = new CMouseToolMove;
break;
case _TOOL_MOVE2:
pMouseTool = new CMouseToolMove2;
break;
case _TOOL_ROTATO:
pMouseTool = new CMouseToolRotate;
break;
case _TOOL_MEASURE:
pMouseTool = new CMouseToolMeasure;
break;
case _TOOL_COPY:
pMouseTool = new CMouseToolCopy;
break;
case _TOOL_CUT:
pMouseTool = new CMouseToolCut;
break;
case _TOOL_DEL_NODE:
pMouseTool = new CMouseToolDelNode;
break;
case _TOOL_ADD_NODE:
pMouseTool = new CMouseToolAddNode;
break;
case _TOOL_BREAK_NODE:
pMouseTool = new CMouseToolBreakNode;
break;
case _TOOL_MOVE_NODE:
pMouseTool = new CMouseToolMoveNode;
break;
case _TOOL_ONE_POINT:
pMouseTool = new CMouseToolOnePoint;
break;
case _TOOL_STRETCH:
pMouseTool = new CMouseToolStretch;
break;
case _TOOL_LASER_COORD:
pMouseTool = new CMouseToolLaserCoord;
break;
default:
break;
}
return pMouseTool;
}
void CMouseToolMgr::OnLButtonDown(UINT nFlags, CPoint point,CClientDC &dc)
{
//如果有捕获点,使用捕获点
CPoint CatchPoint;
if(gCatchMgr.GetCatchPoint(CatchPoint))
{
point = CatchPoint;
}
m_pMouseTool->OnLButtonDown(nFlags,point,dc);
}
void CMouseToolMgr::OnLButtonUp(UINT nFlags, CPoint point,CClientDC &dc)
{
Dbxy pt = gDraw->CPoint2Dbxy(point);
m_pMouseTool->OnLButtonUp(nFlags,point,dc);
if(m_pMouseTool->NeedToPointTool())
{
GetCurViewPtr()->RefreshView();
if(m_pMouseTool->IsEndStatus())
{
SetMouseTool(_TOOL_POINT);
ResetCatchPoint(&dc);
}
}
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
}
void CMouseToolMgr::OnRButtonDown(UINT nFlags, CPoint point,CClientDC &dc)
{
m_pMouseTool->OnRButtonDown(nFlags,point,dc);
if(m_MouseToolType == _TOOL_LINE
||m_MouseToolType == _TOOL_PLINE)
{
SetMouseTool(_TOOL_POINT);
ResetCatchPoint(&dc);
}
}
void CMouseToolMgr::OnRButtonUp(UINT nFlags, CPoint point,CClientDC &dc)
{
m_pMouseTool->OnRButtonUp(nFlags,point,dc);
}
void CMouseToolMgr::OnMouseMove(UINT nFlags, CPoint point,CClientDC &dc)
{
//捕捉point 附近的点
CatchPoint(point,dc);
//如果有捕捉点则使用捕捉点
CPoint CatchPoint;
if(gCatchMgr.GetCatchPoint(CatchPoint))
{
point = CatchPoint;
}
//根据鼠标的位置改变工具的类型
ChangeMouseTool(nFlags,point);
m_pMouseTool->OnMouseMove(nFlags,point,dc);
}
void CMouseToolMgr::CatchPoint(CPoint point,CClientDC &dc)
{
Dbxy pt = gDraw->CPoint2Dbxy(point);
Dbxy DownPt = m_pMouseTool->GetDownPoint();
//一些工具捕获鼠标附近的点(捕获临时对象)
if(m_MouseToolType==_TOOL_LINE
||m_MouseToolType==_TOOL_PLINE)
{
gCatchMgr.Catch(DownPt,pt,&dc,true);
}
//不要捕获临时对象
else if(m_MouseToolType==_TOOL_RECT
||m_MouseToolType==_TOOL_CIRCLE
||m_MouseToolType==_TOOL_MEASURE
||m_MouseToolType==_TOOL_ADD_NODE
||m_MouseToolType==_TOOL_DEL_NODE
||m_MouseToolType==_TOOL_ONE_POINT
||m_MouseToolType==_TOOL_LASER_COORD
||m_MouseToolType==_TOOL_MOVE_NODE
||m_MouseToolType==_TOOL_PT_MOVE_TO_CCD
||m_MouseToolType==_TOOL_SET_MARK_PT
||m_MouseToolType==_TOOL_BREAK_NODE)
{
gCatchMgr.Catch(DownPt,pt,&dc,false);
}
else if(m_MouseToolType==_TOOL_MOVE2
||m_MouseToolType==_TOOL_COPY
||m_MouseToolType==_TOOL_ROTATO)
{
//有些工具只在初始状态捕捉临时对象
if(m_pMouseTool->GetStatus()==_STATUS_1)
{
gCatchMgr.Catch(DownPt,pt,&dc,true);
}
else
{
gCatchMgr.Catch(DownPt,pt,&dc,false);
}
}
}
void CMouseToolMgr::ResetCatchPoint(CDC* pDC)
{
gCatchMgr.ResetCatchPoint(pDC);
}
void CMouseToolMgr::OnEscapeKey(CDC* pDC)
{
ResetCatchPoint(pDC);
m_pMouseTool->OnEscapeKey();
}
//根据鼠标的位置改变工具的类型
void CMouseToolMgr::ChangeMouseTool(UINT nFlags, CPoint point)
{
if((m_MouseToolType==_TOOL_POINT && m_pMouseTool->IsStartStatus())
||(m_MouseToolType==_TOOL_MOVE||m_MouseToolType==_TOOL_STRETCH||m_MouseToolType==_TOOL_MOVE_NODE) && !(nFlags&MK_LBUTTON ))
{
//判断当前工具类型
MOUSE_TOOL type = gLayer.JudgeMouseToolType(gDraw->CPoint2Dbxy(point));
if(type == _TOOL_POINT)
{
type = gEasyOperationMgr->JudgeMouseToolType(gDraw->CPoint2Dbxy(point));
}
SetMouseTool(type);
}
}
bool CMouseToolMgr::OnSetCmd(CString str)
{
if(m_pMouseTool->OnSetCmd(str))
{
if(m_MouseToolType == _TOOL_CIRCLE
||m_MouseToolType == _TOOL_MOVE2
||m_MouseToolType == _TOOL_ROTATO
||m_MouseToolType == _TOOL_RECT)
{
if(m_pMouseTool->IsEndStatus())
{
SetMouseTool(_TOOL_POINT);
GetCurViewPtr()->RefreshView();
}
}
//更新图形属性
gMarkObjPropertieMgr->UpdateSelMarkObjPropertie();
return true;
}
else
{
return false;
}
}