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.
152 lines
4.6 KiB
C++
152 lines
4.6 KiB
C++
#include "StdAfx.h"
|
|
#include "MouseToolCircle.h"
|
|
#include "GlobalFunction.h"
|
|
#include "GlobalDrawMgr.h"
|
|
#include "ObjCircle.h"
|
|
#include "LogMgr.h"
|
|
#include "DrawSimpleShape.h"
|
|
#include "ObjArc.h"
|
|
|
|
|
|
#define DEFUALT_EDGE_CNT 100//圆的默认边数
|
|
CMouseToolCircle::CMouseToolCircle(void)
|
|
{
|
|
//标签栏-------------------------start
|
|
GetFrame()->ResetCaptionBar();
|
|
GetFrame()->SetCaptionCmdStr(CMD_TOOL_CIRCLE_CENTER);
|
|
GetFrame()->RefreashCaptionBar();
|
|
//标签栏-------------------------end
|
|
m_Radius = 0;
|
|
m_EdgeCnt = DEFUALT_EDGE_CNT;
|
|
}
|
|
CMouseToolCircle::~CMouseToolCircle(void)
|
|
{
|
|
}
|
|
void CMouseToolCircle::OperateOver()
|
|
{
|
|
//------------------------------------日志start
|
|
CString val1;
|
|
val1.Format("%lf",m_Radius*2);
|
|
CString val2;
|
|
val2.Format("%ld",m_EdgeCnt);
|
|
gLogMgr->WriteCmd(CMD_TOOL_CIRCLE_DIA_EDGE,val1,val2);
|
|
//------------------------------------日志end
|
|
//标签栏-------------------------start
|
|
GetFrame()->ResetCaptionBar();
|
|
//标签栏-------------------------end
|
|
AddCreatCommand();
|
|
//结束
|
|
m_Status = _STATUS_END;
|
|
|
|
CMouseTool::OperateOver();
|
|
}
|
|
void CMouseToolCircle::OnLButtonDown(UINT nFlags, CPoint point,CClientDC &dc)
|
|
{
|
|
Dbxy pt = gDraw->CPoint2Dbxy(point);
|
|
if(m_Status==_STATUS_1)
|
|
{
|
|
SaveDownPoint(point);
|
|
CObjCircle *pCircle = new CObjCircle;
|
|
CCirclePar ObjCirclePar;
|
|
ObjCirclePar.CenterPt = pt;
|
|
ObjCirclePar.Radius =m_Radius;
|
|
pCircle->Creat(ObjCirclePar);
|
|
AddObject(pCircle);
|
|
//------------------------------------日志start
|
|
CString val1;
|
|
val1.Format("%lf",pt.x);
|
|
CString val2;
|
|
val2.Format("%lf",pt.y);
|
|
gLogMgr->WriteCmd(CMD_TOOL_CIRCLE_CENTER,val1,val2);
|
|
//------------------------------------日志end
|
|
//标签栏-------------------------start
|
|
GetFrame()->ResetCaptionBar();
|
|
GetFrame()->SetCaptionCmdStr(CMD_TOOL_CIRCLE_DIA_EDGE);
|
|
GetFrame()->RefreashCaptionBar();
|
|
//标签栏-------------------------end
|
|
//变成下一个状态
|
|
ToNextStatus();
|
|
}
|
|
else
|
|
{
|
|
OperateOver();
|
|
}
|
|
}
|
|
void CMouseToolCircle::OnLButtonUp(UINT nFlags, CPoint point,CClientDC &dc)
|
|
{
|
|
}
|
|
void CMouseToolCircle::OnMouseMove(UINT nFlag, CPoint point,CClientDC &dc)
|
|
{
|
|
Dbxy OldPt = gDraw->CPoint2Dbxy(m_PreMovePt);
|
|
Dbxy pt = gDraw->CPoint2Dbxy(point);
|
|
if(m_Status!=_STATUS_1)
|
|
{
|
|
m_Radius = CalDistance(m_DownPoint,pt);
|
|
CObjBase *pCurOptObject = m_TmpObjContainer.GetCurOpObj();
|
|
if(pCurOptObject)
|
|
{
|
|
CObjCircle *p = dynamic_cast<CObjCircle*>(pCurOptObject);
|
|
m_TmpObjContainer.XorRedrawObj(&dc,false);
|
|
|
|
CCirclePar ObjCirclePar;
|
|
ObjCirclePar.CenterPt = m_DownPoint;
|
|
ObjCirclePar.Radius =m_Radius;
|
|
ObjCirclePar.DEdgeCnt = m_EdgeCnt;
|
|
|
|
p->Creat(ObjCirclePar);
|
|
m_TmpObjContainer.XorRedrawObj(&dc,false);
|
|
//状态栏-----------------------------start
|
|
CString str1 = "圆[直径] ";
|
|
CString str2;
|
|
str2.Format("%lf",m_Radius*2);
|
|
GetFrame()->ResetStatusBarExtStr();
|
|
GetFrame()->SetStatusBarExtStr(str1,str2,STR_NULL);
|
|
//状态栏-----------------------------end
|
|
}
|
|
SavePreMovePt(point);
|
|
}
|
|
}
|
|
bool CMouseToolCircle::OnSetCmd(CString str)
|
|
{
|
|
if(m_Status==_STATUS_2)//设置圆心
|
|
{
|
|
double Val1=0;//半径
|
|
double Val2=0;//边数
|
|
int result = GetTwoNum(str,Val1,Val2);
|
|
if(result>0)
|
|
{
|
|
if(result == 1)//只输入直径
|
|
{
|
|
Val2 = DEFUALT_EDGE_CNT;
|
|
}
|
|
if(Val1>0)//直径要大于0
|
|
{
|
|
m_Radius = Val1/2;
|
|
//EdgeCnt 要是4的倍数,最小为4
|
|
int min = 4;
|
|
m_EdgeCnt = (int)(Val2/min)*min;
|
|
if(m_EdgeCnt<min)
|
|
{
|
|
m_EdgeCnt = min;
|
|
}
|
|
|
|
CObjBase *pCurOptObject = m_TmpObjContainer.GetCurOpObj();
|
|
if(pCurOptObject)
|
|
{
|
|
CObjCircle *p = dynamic_cast<CObjCircle*>(pCurOptObject);
|
|
CCirclePar ObjCirclePar;
|
|
ObjCirclePar.CenterPt = m_DownPoint;
|
|
ObjCirclePar.Radius =m_Radius;
|
|
ObjCirclePar.DEdgeCnt = m_EdgeCnt;
|
|
|
|
p->Creat(ObjCirclePar);
|
|
}
|
|
OperateOver();
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|