|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
#include "CatchMgr.h"
|
|
|
|
|
#include "GlobalDrawMgr.h"
|
|
|
|
|
#include "GlobalFunction.h"
|
|
|
|
|
#include "LogMgr.h"
|
|
|
|
|
#include "DrawSimpleShape.h"
|
|
|
|
|
#include "ObjComponentMgr.h"
|
|
|
|
|
#include "MouseToolmgr.h"
|
|
|
|
|
|
|
|
|
|
CCatchMgr gCatchMgr;//<2F><><EFBFBD><D7BD><EFBFBD><EFBFBD>
|
|
|
|
|
CCatchMgr::CCatchMgr()
|
|
|
|
|
{
|
|
|
|
|
ResetCatchNode();
|
|
|
|
|
}
|
|
|
|
|
CCatchMgr::~CCatchMgr(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
#if 1//<2F><><EFBFBD><D7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void CCatchMgr::DrawCatchPoint(CCatchPoint CatchPt,CDC* pDC)
|
|
|
|
|
{
|
|
|
|
|
if(m_CatchPointVec.empty())
|
|
|
|
|
{
|
|
|
|
|
ResetCatchPoint(pDC);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>֮ǰ<D6AE><C7B0>
|
|
|
|
|
if(!CatchPt.Equal(m_CatchNode))
|
|
|
|
|
{
|
|
|
|
|
ResetCatchPoint(pDC);
|
|
|
|
|
}
|
|
|
|
|
if(!CatchPt.Equal(m_CatchNode))
|
|
|
|
|
{
|
|
|
|
|
DrawCatchPointExt(CatchPt,pDC);
|
|
|
|
|
//<2F><><EFBFBD>浱ǰ<E6B5B1>IJ<EFBFBD><C4B2><EFBFBD>
|
|
|
|
|
m_CatchNode = CatchPt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void CCatchMgr::DrawCatchPointExt(CCatchPoint pt,CDC* pDC)
|
|
|
|
|
{
|
|
|
|
|
DbRect NodeRect(pt,gDraw->GetCatchNodeSize());
|
|
|
|
|
switch(pt.GetType())
|
|
|
|
|
{
|
|
|
|
|
case _CATCH_NODE:
|
|
|
|
|
DrawRect(pDC,gDraw->GetCatchNodePen(),NodeRect);
|
|
|
|
|
break;
|
|
|
|
|
case _CATCH_INTERSECT:
|
|
|
|
|
case _CATCH_ORTHO:
|
|
|
|
|
case _CATCH_CUT_TRACK:
|
|
|
|
|
XorDrawCrossX(pDC,gDraw->GetCatchNodePen(),NodeRect);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void CCatchMgr::ResetCatchNode()
|
|
|
|
|
{
|
|
|
|
|
m_CatchNode.x = -10000.123456;
|
|
|
|
|
m_CatchNode.y = -10000.123456;
|
|
|
|
|
}
|
|
|
|
|
void CCatchMgr::ResetCatchPoint(CDC* pDC)
|
|
|
|
|
{
|
|
|
|
|
if(HasCatchPoint())
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>֮ǰ<D6AE><C7B0>
|
|
|
|
|
DrawCatchPointExt(m_CatchNode,pDC);
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
ResetCatchNode();
|
|
|
|
|
}
|
|
|
|
|
bool CCatchMgr::HasCatchPoint()
|
|
|
|
|
{
|
|
|
|
|
if(m_CatchNode.x == -10000.123456)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
bool CCatchMgr::GetCatchPoint(CPoint &pt)
|
|
|
|
|
{
|
|
|
|
|
if(HasCatchPoint())
|
|
|
|
|
{
|
|
|
|
|
pt = gDraw->Dbxy2CPoint(m_CatchNode);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CCatchPoint CCatchMgr::GetNearestCatchPt(Dbxy pt)
|
|
|
|
|
{
|
|
|
|
|
CCatchPoint CatchPt;
|
|
|
|
|
double MinDis;
|
|
|
|
|
vector<CCatchPoint>::iterator iter = m_CatchPointVec.begin();
|
|
|
|
|
vector<CCatchPoint>::iterator iter_end = m_CatchPointVec.end();
|
|
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
|
|
{
|
|
|
|
|
double dis = CalDistance(pt,(*iter));
|
|
|
|
|
if(iter == m_CatchPointVec.begin())
|
|
|
|
|
{
|
|
|
|
|
MinDis = dis;
|
|
|
|
|
CatchPt = (*iter);
|
|
|
|
|
}
|
|
|
|
|
else if(dis<MinDis)
|
|
|
|
|
{
|
|
|
|
|
MinDis = dis;
|
|
|
|
|
CatchPt = (*iter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return CatchPt;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#if 1//ÿ<>ֲ<EFBFBD><EFBFBD><D7BD>Ӧ<EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>pt <20><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>
|
|
|
|
|
void CCatchMgr::Catch(Dbxy DownPt,Dbxy pt,CDC* pDC,bool bCatchTemp)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ղ<EFBFBD><D5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
m_CatchPointVec.clear();
|
|
|
|
|
m_DataPtLineVec.clear();
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ĵIJ<C4B5><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>rect
|
|
|
|
|
DbRect rect = gDraw->GetCurCatchRect(pt);
|
|
|
|
|
|
|
|
|
|
//<2F>ռ<EFBFBD>rect <20><>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5>߶<EFBFBD>
|
|
|
|
|
GetLineInRect(rect,bCatchTemp);
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>rect <20><>Χ<EFBFBD>ڵ<EFBFBD>node <20>ڵ<EFBFBD>
|
|
|
|
|
CatchNode(rect);
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>rect <20><>Χ<EFBFBD><CEA7><EFBFBD>߶εĽ<CEB5><C4BD><EFBFBD>
|
|
|
|
|
CatchIntersectPointOfLines(rect);
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>rect <20><><EFBFBD>߶εĽ<CEB5><C4BD><EFBFBD>
|
|
|
|
|
CatchIntersectPointWithMouse(rect);
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CatchOrthoPoint(DownPt,pt,rect);
|
|
|
|
|
//<2F><>Ԫ<D7BD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><D0B8><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD>㣬<EFBFBD><E3A3AC><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>mark <20><>
|
|
|
|
|
CatchCutTrack(rect);
|
|
|
|
|
//ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CCatchPoint CatchPt;
|
|
|
|
|
if(!m_CatchPointVec.empty())
|
|
|
|
|
{
|
|
|
|
|
CatchPt = GetNearestCatchPt(pt);
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
DrawCatchPoint(CatchPt,pDC);
|
|
|
|
|
}
|
|
|
|
|
//<2F>ռ<EFBFBD>rect <20><>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5>߶<EFBFBD>
|
|
|
|
|
void CCatchMgr::GetLineInRect(DbRect &rect,bool bCatchTemp)
|
|
|
|
|
{
|
|
|
|
|
gLayer.GetLineInRect(rect,m_DataPtLineVec,bCatchTemp);
|
|
|
|
|
}
|
|
|
|
|
//<2F>ռ<EFBFBD>rect <20><>Χ<EFBFBD>ڵĽڵ<C4BD>
|
|
|
|
|
void CCatchMgr::CatchNode(DbRect rect)
|
|
|
|
|
{
|
|
|
|
|
if(gDraw->IsCatchObjNode()== false)
|
|
|
|
|
return;
|
|
|
|
|
//<2F><><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(!m_CatchPointVec.empty())
|
|
|
|
|
return;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>߶εĶ˵<C4B6><CBB5>Ƿ<EFBFBD><C7B7>ھ<EFBFBD><DABE><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>
|
|
|
|
|
vector<DbLine>::iterator iter = m_DataPtLineVec.begin();
|
|
|
|
|
vector<DbLine>::iterator iter_end = m_DataPtLineVec.end();
|
|
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
|
|
{
|
|
|
|
|
if((*iter).m_pt1.IsNode())
|
|
|
|
|
{
|
|
|
|
|
Dbxy pt = (*iter).m_pt1.GetPt();
|
|
|
|
|
if(IsPointInRect(pt,rect))
|
|
|
|
|
{
|
|
|
|
|
CCatchPoint CatchPoint(pt.x,pt.y,_CATCH_NODE);
|
|
|
|
|
m_CatchPointVec.push_back(CatchPoint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if((*iter).m_pt2.IsNode())
|
|
|
|
|
{
|
|
|
|
|
Dbxy pt = (*iter).m_pt2.GetPt();
|
|
|
|
|
if(IsPointInRect(pt,rect))
|
|
|
|
|
{
|
|
|
|
|
CCatchPoint CatchPoint(pt.x,pt.y,_CATCH_NODE);
|
|
|
|
|
m_CatchPointVec.push_back(CatchPoint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F>ռ<EFBFBD>rect <20><>Χ<EFBFBD>ڵ<EFBFBD><DAB5>߶ν<DFB6><CEBD><EFBFBD>
|
|
|
|
|
void CCatchMgr::CatchIntersectPointOfLines(DbRect rect)
|
|
|
|
|
{
|
|
|
|
|
if(gDraw->IsCatchCrossPoint()== false)
|
|
|
|
|
return;
|
|
|
|
|
//<2F><><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(!m_CatchPointVec.empty())
|
|
|
|
|
return;
|
|
|
|
|
int size = m_DataPtLineVec.size();
|
|
|
|
|
for(int i=0;i<size;i++)
|
|
|
|
|
{
|
|
|
|
|
DbLine &line1 = m_DataPtLineVec[i];
|
|
|
|
|
for(int j=i+1;j<size;j++)
|
|
|
|
|
{
|
|
|
|
|
DbLine &line2 = m_DataPtLineVec[j];
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>߶εĽ<CEB5><C4BD>㲻<EFBFBD><E3B2BB>
|
|
|
|
|
if(line1.IsSerialLine(line2))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ཻ
|
|
|
|
|
if(IsTwoLineIntersect(line1.m_pt1.GetPt(),line1.m_pt2.GetPt(),line2.m_pt1.GetPt(),line2.m_pt2.GetPt()))
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ཻ<EFBFBD><E0BDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Dbxy pt = CalIntersection(line1.m_pt1.GetPt(),line1.m_pt2.GetPt(),line2.m_pt1.GetPt(),line2.m_pt2.GetPt());
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>rect <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>벶<EBB2B6><D7BD>
|
|
|
|
|
if(IsPointInRect(pt,rect))
|
|
|
|
|
{
|
|
|
|
|
CCatchPoint CatchPoint(pt.x,pt.y,_CATCH_INTERSECT);
|
|
|
|
|
m_CatchPointVec.push_back(CatchPoint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>߶κ<DFB6><CEBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD>
|
|
|
|
|
void CCatchMgr::CatchIntersectPointWithMouse(DbRect rect)
|
|
|
|
|
{
|
|
|
|
|
if(gDraw->IsCatchObjLine()== false)
|
|
|
|
|
return;
|
|
|
|
|
//<2F><><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(!m_CatchPointVec.empty())
|
|
|
|
|
return;
|
|
|
|
|
vector<DbLine>::iterator iter = m_DataPtLineVec.begin();
|
|
|
|
|
vector<DbLine>::iterator iter_end = m_DataPtLineVec.end();
|
|
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
|
|
{
|
|
|
|
|
Dbxy LinePt1 = (*iter).m_pt1.GetPt();
|
|
|
|
|
Dbxy LinePt2 = (*iter).m_pt2.GetPt();
|
|
|
|
|
if(IsPointInRect(LinePt1,rect)||IsPointInRect(LinePt2,rect))//<2F><>Ҫ<EFBFBD><D2AA><EFBFBD>˵<EFBFBD><CBB5>IJ<EFBFBD><C4B2><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Dbxy pt = IntersectionOfRectAndLine(LinePt1,LinePt2,rect);
|
|
|
|
|
CCatchPoint CatchPoint(pt.x,pt.y,_CATCH_INTERSECT);
|
|
|
|
|
m_CatchPointVec.push_back(CatchPoint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void CCatchMgr::CatchOrthoPoint(Dbxy DownPt,Dbxy MousePt,DbRect rect)
|
|
|
|
|
{
|
|
|
|
|
if(gDraw->IsCatchOrthoPoint()== false)
|
|
|
|
|
return;
|
|
|
|
|
//<2F><><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(!m_CatchPointVec.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
DbSize size = rect.GetSize();
|
|
|
|
|
if(abs(MousePt.x-DownPt.x)<=size.w/2)
|
|
|
|
|
{
|
|
|
|
|
CCatchPoint CatchPoint(DownPt.x,MousePt.y,_CATCH_ORTHO);
|
|
|
|
|
m_CatchPointVec.push_back(CatchPoint);
|
|
|
|
|
}
|
|
|
|
|
else if(abs(MousePt.y-DownPt.y)<=size.h/2)
|
|
|
|
|
{
|
|
|
|
|
CCatchPoint CatchPoint(MousePt.x,DownPt.y,_CATCH_ORTHO);
|
|
|
|
|
m_CatchPointVec.push_back(CatchPoint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><>Ԫ<D7BD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><D0B8><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD>㣬<EFBFBD><E3A3AC><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>mark <20><>
|
|
|
|
|
void CCatchMgr::CatchCutTrack(DbRect rect)
|
|
|
|
|
{
|
|
|
|
|
if(gDraw->IsCatchCutTrack()== false)
|
|
|
|
|
return;
|
|
|
|
|
//<2F><><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(!m_CatchPointVec.empty())
|
|
|
|
|
return;
|
|
|
|
|
//ֻ<><D6BB><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>Ų<EFBFBD>
|
|
|
|
|
MOUSE_TOOL tool = gMouseToolMgr.GetToolType();
|
|
|
|
|
if(tool == _TOOL_MEASURE)
|
|
|
|
|
{
|
|
|
|
|
vector<CObjComponent>&vec = gObjComponentMgr->GetComponentVec();
|
|
|
|
|
|
|
|
|
|
Dbxy pt = rect.GetCenterPt();
|
|
|
|
|
|
|
|
|
|
double MinDis = 0;//<2F><><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>
|
|
|
|
|
|
|
|
|
|
int MinIdx = -1;
|
|
|
|
|
int size = vec.size();
|
|
|
|
|
for(int i=0;i<size;i++)
|
|
|
|
|
{
|
|
|
|
|
double CurDis = CalDistance(pt,vec[i].GetBasePt());
|
|
|
|
|
if(CurDis <= vec[i].GetSize().w)
|
|
|
|
|
{
|
|
|
|
|
if(MinDis == 0 || CurDis<MinDis)
|
|
|
|
|
{
|
|
|
|
|
MinIdx = i;
|
|
|
|
|
MinDis = CurDis;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(MinIdx != -1)
|
|
|
|
|
{
|
|
|
|
|
Dbxy pt = vec[MinIdx].GetBasePt();
|
|
|
|
|
CCatchPoint CatchPoint(pt.x,pt.y,_CATCH_CUT_TRACK);
|
|
|
|
|
m_CatchPointVec.push_back(CatchPoint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|