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;
//<2F><><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>rect <20><>obj -----------------------------------------------
Sptr<CObjBase> pObj = layer.GetFirstObjInRect(rect);
//<2F><><EFBFBD><EFBFBD>obj <20><>rect <20>еĵ<D0B5>һ<EFBFBD><D2BB>node <20><>-----------------------------------------------
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;
//<2F><><EFBFBD><EFBFBD>NodePt <20><>obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int idx = pObj->GetNodePtIdx(NodePt);
if(idx!=-1 && idx!=0)
{
//ǰһ<C7B0><D2BB><EFBFBD><EFBFBD>
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();
}
//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
CObjPline *pPline2 = new CObjPline;
pPline2->CopyPt(*(pObj.GetPtr()));
pPline2->SetSelected(true);
for(int i=0;i<idx;i++)
{
pPline2->DelNodePtByIdx(0);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>-----------------------------------
Sptr<CObjBase> pObj1(pPline1);
Sptr<CObjBase> pObj2(pPline2);
m_TmpObjContainer.AddObject(pObj1);
m_TmpObjContainer.AddObject(pObj2);
m_TmpObjContainer.AllObjAddToLayer();
m_TmpObjContainer.Clear();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
gLayer.DelObj(pObj);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
CCommandBreakNode *pCmd = new CCommandBreakNode;
pCmd->AddOpObj(pObj);
pCmd->AddOpObj(pObj1);
pCmd->AddOpObj(pObj2);
gCommandMgr.AddUndoCommand(pCmd);
//ˢ<><CBA2>
GetCurViewPtr()->RefreshView();
}
}