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.

80 lines
2.4 KiB
C++

#include "StdAfx.h"
#include "MouseToolBreakNode.h"
#include "GlobalDrawMgr.h"
#include "Layer.h"
#include "GlobalFunction.h"
#include "CommandDelNode.h"
#include "CommandBreakNode.h"
#include "ObjPline.h"
#include "CommandMgr.h"
CMouseToolBreakNode::CMouseToolBreakNode(void)
{
}
CMouseToolBreakNode::~CMouseToolBreakNode(void)
{
}
void CMouseToolBreakNode::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 中的第一个node 点-----------------------------------------------
vector<DbLine> LineVec;
pObj->GetLineInRect(rect,LineVec,false);
Dbxy NodePt = LineVec[0].m_pt1.GetPt();
if(!IsPointInRect(NodePt,rect))
{
NodePt = LineVec[0].m_pt2.GetPt();
}
if(!IsPointInRect(NodePt,rect))
return;
//获得NodePt 在obj 的序号
int idx = pObj->GetNodePtIdx(NodePt);
if(idx!=-1 && idx!=0)
{
//前一部分
CObjPline *pPline1 = new CObjPline;
pPline1->CopyPt(*(pObj.GetPtr()));
pPline1->SetSelected(true);
int ptCnt = pPline1->GetPtCnt();
for(int i=0;i<(ptCnt-(idx+1));i++)
{
pPline1->DelLastDataPoint();
}
//后一部分
CObjPline *pPline2 = new CObjPline;
pPline2->CopyPt(*(pObj.GetPtr()));
pPline2->SetSelected(true);
for(int i=0;i<idx;i++)
{
pPline2->DelNodePtByIdx(0);
}
//创建撤销指令-----------------------------------
Sptr<CObjBase> pObj1(pPline1);
Sptr<CObjBase> pObj2(pPline2);
m_TmpObjContainer.AddObject(pObj1);
m_TmpObjContainer.AddObject(pObj2);
m_TmpObjContainer.AllObjAddToLayer();
m_TmpObjContainer.Clear();//清空容器
gLayer.DelObj(pObj);
//创建撤销指令
CCommandBreakNode *pCmd = new CCommandBreakNode;
pCmd->AddOpObj(pObj);
pCmd->AddOpObj(pObj1);
pCmd->AddOpObj(pObj2);
gCommandMgr.AddUndoCommand(pCmd);
//刷新
GetCurViewPtr()->RefreshView();
}
}