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.
183 lines
5.2 KiB
C++
183 lines
5.2 KiB
C++
#include "StdAfx.h"
|
|
#include "MouseToolPline.h"
|
|
#include "LogMgr.h"
|
|
#include "ObjPLine.h"
|
|
#include "GlobalFunction.h"
|
|
#include "GlobalDrawMgr.h"
|
|
CMouseToolPline::CMouseToolPline(void)
|
|
{
|
|
//标签栏-------------------------start
|
|
GetFrame()->ResetCaptionBar();
|
|
GetFrame()->SetCaptionCmdStr(CMD_LINE_FIRST_PT);
|
|
GetFrame()->RefreashCaptionBar();
|
|
//标签栏-------------------------end
|
|
m_Length = 0;//长度
|
|
m_Angle = 0;//360 角
|
|
}
|
|
CMouseToolPline::~CMouseToolPline(void)
|
|
{
|
|
}
|
|
void CMouseToolPline::CreatOneLine(Dbxy pt)
|
|
{
|
|
CObjPline *p = new CObjPline;
|
|
p->Creat(pt,pt);
|
|
AddObject(p);
|
|
//-------------------------------------------命令栏start
|
|
if(m_Status==_STATUS_1)
|
|
{
|
|
CString val1;
|
|
val1.Format("%lf",pt.x);
|
|
CString val2;
|
|
val2.Format("%lf",pt.y);
|
|
gLogMgr->WriteCmd(CMD_LINE_FIRST_PT,val1,val2);
|
|
ToNextStatus();
|
|
}
|
|
else
|
|
{
|
|
CString val1;
|
|
val1.Format("%lf",m_Length);
|
|
CString val2;
|
|
val2.Format("%lf",m_Angle);
|
|
gLogMgr->WriteCmd(CMD_LINE_NEXT_PT,val1,val2);
|
|
}
|
|
//-------------------------------------------命令栏end
|
|
//标签栏-------------------------start
|
|
GetFrame()->ResetCaptionBar();
|
|
GetFrame()->SetCaptionCmdStr(CMD_LINE_NEXT_PT);
|
|
GetFrame()->RefreashCaptionBar();
|
|
//标签栏-------------------------end
|
|
SaveDownPoint(pt);
|
|
}
|
|
void CMouseToolPline::OnLButtonDown(UINT nFlags, CPoint point,CClientDC &dc)
|
|
{
|
|
//每点一下创建一条直线
|
|
Dbxy pt = gDraw->CPoint2Dbxy(point);
|
|
CreatOneLine(pt);
|
|
}
|
|
void CMouseToolPline::OnLButtonUp(UINT nFlags, CPoint point,CClientDC &dc)
|
|
{
|
|
|
|
}
|
|
void CMouseToolPline::OnRButtonDown(UINT nFlags, CPoint point,CClientDC &dc)
|
|
{
|
|
//擦除
|
|
m_TmpObjContainer.XorDrawLastObj(&dc);
|
|
//删除最后一个obj
|
|
m_TmpObjContainer.DeleteLastObj();
|
|
//所有的line 组合成pline
|
|
AlllineCombToPline();
|
|
//添加指令
|
|
AddCreatCommand();
|
|
//标签栏-------------------------start
|
|
GetFrame()->ResetCaptionBar();
|
|
//标签栏-------------------------end
|
|
//结束
|
|
m_Status = _STATUS_END;
|
|
OperateOver();
|
|
}
|
|
void CMouseToolPline::OnMouseMove(UINT nFlag, CPoint point,CClientDC &dc)
|
|
{
|
|
Dbxy pt = gDraw->CPoint2Dbxy(point);
|
|
if(m_Status!=_STATUS_1)
|
|
{
|
|
CObjBase *pCurOptObject = m_TmpObjContainer.GetCurOpObj();
|
|
if(pCurOptObject)
|
|
{
|
|
CObjPline *p = dynamic_cast<CObjPline*>(pCurOptObject);
|
|
m_TmpObjContainer.XorDrawLastObj(&dc);
|
|
p->Creat(m_DownPoint,pt);
|
|
m_TmpObjContainer.XorDrawLastObj(&dc);
|
|
|
|
m_Length = CalDistance(m_DownPoint,pt);//长度
|
|
m_Angle = Cal360AngleByTwoPt(m_DownPoint,pt);//360 角
|
|
//状态栏-----------------------------start
|
|
CString str1 = "线段[长度] [角度]";
|
|
CString str2;
|
|
str2.Format("%lf",m_Length);
|
|
CString str3;
|
|
str3.Format("%lf",m_Angle);
|
|
GetFrame()->ResetStatusBarExtStr();
|
|
GetFrame()->SetStatusBarExtStr(str1,str2,str3);
|
|
//状态栏-----------------------------end
|
|
}
|
|
}
|
|
}
|
|
void CMouseToolPline::OnEscapeKey()
|
|
{
|
|
//删除最后一个obj
|
|
m_TmpObjContainer.DeleteLastObj();
|
|
|
|
//所有的line 组合成pline
|
|
AlllineCombToPline();
|
|
//添加指令
|
|
AddCreatCommand();
|
|
//标签栏-------------------------start
|
|
GetFrame()->ResetCaptionBar();
|
|
//标签栏-------------------------end
|
|
m_Status = _STATUS_END;
|
|
OperateOver();
|
|
}
|
|
bool CMouseToolPline::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 = m_Angle;
|
|
}
|
|
if(Val1>0)//长度要大于0
|
|
{
|
|
m_Length = Val1;
|
|
m_Angle = Val2;
|
|
//计算出指定点
|
|
Dbxy SetPoint = GetPoint2(m_DownPoint,Val1,_360ToAngle(Val2));
|
|
//先把当前的线段连接到这个点上
|
|
CObjBase *pCurOptObject = m_TmpObjContainer.GetCurOpObj();
|
|
if(pCurOptObject)
|
|
{
|
|
CObjPline *p = dynamic_cast<CObjPline*>(pCurOptObject);
|
|
p->Creat(m_DownPoint,SetPoint);
|
|
}
|
|
//再以这个点为起点创建新线段
|
|
CreatOneLine(SetPoint);
|
|
//强制刷新
|
|
GetCurViewPtr()->RefreshView();
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
//所有的line 组合成pline
|
|
void CMouseToolPline::AlllineCombToPline()
|
|
{
|
|
if(m_TmpObjContainer.Empty())
|
|
return;
|
|
CObjPline *p = NULL;
|
|
vector<Sptr<CObjBase>> &vec = m_TmpObjContainer.GetObjVec();
|
|
int size = vec.size();
|
|
for(int i=0;i<size;i++)
|
|
{
|
|
if(i==0)
|
|
{
|
|
p = new CObjPline;
|
|
p->Creat(vec[0]->GetFirstPt(),vec[0]->GetLastPt());
|
|
}
|
|
else
|
|
{
|
|
CDataPoint DataPoint(vec[i]->GetLastPt());
|
|
DataPoint.SetIsNode(true);
|
|
p->AddDataPoint(DataPoint);
|
|
}
|
|
}
|
|
//创建所有线段的中间点为捕捉点
|
|
p->CreatMidNode();
|
|
m_TmpObjContainer.Clear();
|
|
AddObject(p);
|
|
}
|