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.

56 lines
1.7 KiB
C++

#include "StdAfx.h"
#include "MouseToolAddNode.h"
#include "GlobalDrawMgr.h"
#include "Layer.h"
#include "GlobalFunction.h"
#include "CommandAddNode.h"
#include "CommandMgr.h"
CMouseToolAddNode::CMouseToolAddNode(void)
{
}
CMouseToolAddNode::~CMouseToolAddNode(void)
{
}
void CMouseToolAddNode::OnLButtonDown(UINT nFlags, CPoint point,CClientDC &dc)
{
Dbxy pt = gDraw->CPoint2Dbxy(point);
DbRect rect = gDraw->GetCurPointRect(pt);
CLayer &layer = gLayer;
if(!layer.HasObjectInRect(rect))
return;
//先找到第一个在rect 的obj -----------------------------------------------
Sptr<CObjBase> pObj = layer.GetFirstObjInRect(rect);
//获得obj 在rect 中的第一条线段-----------------------------------------------
vector<DbLine> LineVec;
pObj->GetLineInRect(rect,LineVec,false);
Dbxy LinePt1 = LineVec[0].m_pt1.GetPt();
Dbxy LinePt2 = LineVec[0].m_pt2.GetPt();
if(IsPointInRect(LinePt1,rect)||IsPointInRect(LinePt2,rect))//不要在端点附近添加
{
return;
}
//得到鼠标rect 线段的交点--------------------------------------------------
Dbxy MousePt = IntersectionOfRectAndLine(LinePt1,LinePt2,rect);
//获得LinePt1 在obj 的序号
int idx = pObj->GetNodePtIdx(LinePt1);
if(idx!=-1)
{
//插入到LinePt1 点的后面-------------------------
pObj->InsertNode(idx+1,MousePt);
pObj->SetSelected(true);
//创建撤销指令-----------------------------------
CCommandAddNode *p = new CCommandAddNode;
p->SetPar(idx+1,MousePt);
p->AddOpObj(pObj);
gCommandMgr.AddUndoCommand(p);
//刷新
GetCurViewPtr()->RefreshView();
}
}