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.

67 lines
1.8 KiB
C++

#include "StdAfx.h"
#include "MouseToolDelNode.h"
#include "GlobalDrawMgr.h"
#include "Layer.h"
#include "GlobalFunction.h"
#include "CommandDelNode.h"
#include "CommandMgr.h"
#include "LogMgr.h"
CMouseToolDelNode::CMouseToolDelNode(void)
{
}
CMouseToolDelNode::~CMouseToolDelNode(void)
{
}
void CMouseToolDelNode::OnLButtonDown(UINT nFlags, CPoint point,CClientDC &dc)
{
Dbxy pt = gDraw->CPoint2Dbxy(point);
DbRect rect = gDraw->GetCurPointRect(pt);
CLayer &layer = gLayer;
if(!layer.HasObjectInRect(rect))
{
gLogMgr->WriteDebugLog("对象不在范围之内",_LOG_ERROR);
return;
}
//先找到第一个在rect 的obj -----------------------------------------------
Sptr<CObjBase> pObj = layer.GetFirstObjInRect(rect);
if(pObj->GetPtCnt()<=2)//只删除3 个点以上的对象
{
gLogMgr->WriteDebugLog("只能删除3个点以上的对象",_LOG_ERROR);
return;
}
//获得obj 在rect 中的第一个node 点-----------------------------------------------
vector<DbLine> LineVec;
pObj->GetLineInRect(rect,LineVec,false);
if(LineVec.empty())
return;
Dbxy NodePt = LineVec[0].m_pt1.GetPt();
if(!IsPointInRect(NodePt,rect))
{
NodePt = LineVec[0].m_pt2.GetPt();
}
if(!IsPointInRect(NodePt,rect))
{
gLogMgr->WriteDebugLog("节点不在范围内",_LOG_ERROR);
return;
}
//获得NodePt 在obj 的序号
int idx = pObj->GetNodePtIdx(NodePt);
if(idx!=-1 && idx!=0)
{
pObj->DelNodePtByIdx(idx);
//创建撤销指令-----------------------------------
CCommandDelNode *p = new CCommandDelNode;
p->SetPar(idx,NodePt);
p->AddOpObj(pObj);
gCommandMgr.AddUndoCommand(p);
//刷新
GetCurViewPtr()->RefreshView();
}
}