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.

487 lines
13 KiB
C++

#include "StdAfx.h"
#include "SequentialPoint.h"
#include "GlobalFunction.h"
#include "GlobalDrawMgr.h"
#include "DrawSimpleShape.h"
#include "WorkFileLable.h"
#include "WorkFileMgr.h"
#include "LogMgr.h"
CSequentialPoint::CSequentialPoint(void)
{
}
CSequentialPoint::~CSequentialPoint(void)
{
}
#if 1
void CSequentialPoint::WriteWorkFile(vector<CLab> &LabVec)
{
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
for(;iter!=iter_end;iter++)
{
LabVec.push_back(CLab(LAB_POINT_START));//<2F><><EFBFBD>ݵ㿪ʼ
Dbxy pt = (*iter).GetPt();
LabVec.push_back(CLab(LAB_POINT_X,pt.x));
LabVec.push_back(CLab(LAB_POINT_Y,pt.y));
LabVec.push_back(CLab(LAB_POINT_IS_NODE,(*iter).IsNode()));//<2F>Ƿ<EFBFBD>Ϊ<EFBFBD>ڵ<EFBFBD>
LabVec.push_back(CLab(LAB_POINT_END));//<2F><><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD>
}
}
void CSequentialPoint::ReadWorkFile(CLabVecRang &LabVecRang)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>---------------------------------------------------
vector<CLabVecRang> LabVecRangVec;
CWorkFileMgr WorkFileMgr;
WorkFileMgr.SeparateStrVec(LabVecRang,LabVecRangVec,LAB_POINT_START,LAB_POINT_END);
//<2F><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD>
if(!LabVecRangVec.empty())
{
vector<CLabVecRang>::iterator iter = LabVecRangVec.begin();
vector<CLabVecRang>::iterator iter_end = LabVecRangVec.end();
for(;iter!=iter_end;iter++)
{
Dbxy pt;
bool bIsNode;
{//X<><58><EFBFBD><EFBFBD>
CLab Lab = WorkFileMgr.FindLab((*iter),LAB_POINT_X);
if(Lab.m_ValType != _TYPE_NULL)
{
pt.x = Lab.m_Double;
}
}
{//Y<><59><EFBFBD><EFBFBD>
CLab Lab = WorkFileMgr.FindLab((*iter),LAB_POINT_Y);
if(Lab.m_ValType != _TYPE_NULL)
{
pt.y = Lab.m_Double;
}
}
{//<2F>Ƿ<EFBFBD>ΪNODE <20><>
CLab Lab = WorkFileMgr.FindLab((*iter),LAB_POINT_IS_NODE);
if(Lab.m_ValType != _TYPE_NULL)
{
bIsNode = Lab.m_Bool;
}
}
CDataPoint DataPoint(pt);
DataPoint.SetIsNode(bIsNode);
AddDataPoint(DataPoint);
}
}
}
#endif
#if 1
void CSequentialPoint::AddDataPoint(CDataPoint DataPt)
{
m_PtContainer.push_back(DataPt);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CSequentialPoint::Load(CSequentialPoint &rhs)
{
vector<CDataPoint>::iterator iter = rhs.m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = rhs.m_PtContainer.end();
for(;iter!=iter_end;iter++)
{
m_PtContainer.push_back(*iter);
}
}
bool CSequentialPoint::Empty()//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>
{
return m_PtContainer.empty();
};
void CSequentialPoint::DelAllPt()//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>
{
m_PtContainer.clear();
};
void CSequentialPoint::DelLastDataPoint()//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڵ<EFBFBD>
{
if(!Empty())
{
m_PtContainer.pop_back();
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڵ<EFBFBD>
void CSequentialPoint::SetLastPoint(CDataPoint &pt)
{
if(!Empty())
{
CDataPoint &LastPt = m_PtContainer[m_PtContainer.size()-1];
LastPt = pt;
}
}
//ʹ<><CAB9>ʱ<EFBFBD><CAB1>Ҫ<EFBFBD><D2AA>֤m_Container <20>ǿ<EFBFBD>
Dbxy CSequentialPoint::GetFirstPt()
{
return m_PtContainer[0].GetPt();
}
//ʹ<><CAB9>ʱ<EFBFBD><CAB1>Ҫ<EFBFBD><D2AA>֤m_Container <20>ǿ<EFBFBD>
Dbxy CSequentialPoint::GetLastPt()
{
return m_PtContainer[m_PtContainer.size()-1].GetPt();
}
//<2F><>ȡnode <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int CSequentialPoint::GetNodePtIdx(Dbxy pt)
{
int idx = -1;
int size = m_PtContainer.size();
for(int i=0;i<size;i++)
{
if(pt==m_PtContainer[i].GetPt())
{
idx = i;
break;
}
}
return idx;
}
//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵɾ<D6B5><C9BE>node <20><>
void CSequentialPoint::DelNodePtByIdx(int idx)
{
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
int i=0;
for(;iter!=iter_end;iter++)
{
if(i==idx && (*iter).IsNode())
{
m_PtContainer.erase(iter);
break;
}
i++;
}
}
//<2F><><EFBFBD><EFBFBD>idx <20><>Ӧ<EFBFBD><D3A6>node <20><><EFBFBD><EFBFBD>ֵΪpt
void CSequentialPoint::SetNodePtByIdx(int idx,Dbxy pt)
{
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
int i=0;
for(;iter!=iter_end;iter++)
{
if(i==idx && (*iter).IsNode())
{
(*iter).SetPt(pt);
break;
}
i++;
}
}
void CSequentialPoint::InsertNode(int idx,Dbxy pt)
{
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
int i=0;
for(;iter!=iter_end;iter++)
{
if(i==idx)
{
CDataPoint DataPoint(pt);
DataPoint.SetIsNode(true);
m_PtContainer.insert(iter,DataPoint);
break;
}
i++;
}
}
#endif
#if 1
//<2F>Ƿ<EFBFBD><C7B7>ھ<EFBFBD><DABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool CSequentialPoint::IsInRect(DbRect rect,bool bNeedAllIn)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>
{
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
for(;iter!=iter_end;iter++)
{
if(iter != m_PtContainer.begin())
{
Dbxy pt1 = (*(iter-1)).GetPt();
Dbxy pt2 = (*iter).GetPt();
if(bNeedAllIn)//<2F><>Ҫȫ<D2AA><C8AB><EFBFBD>ھ<EFBFBD><DABE>η<EFBFBD>Χ<EFBFBD><CEA7>
{
if(!IsPointInRect(pt1,rect)||!IsPointInRect(pt2,rect))
{
return false;
}
}
else //(<28>ҵ<EFBFBD><D2B5><EFBFBD>Ҳ<EFBFBD><D2B2>)
{
if(IsLineInRect(pt1,pt2,rect))
return true;
}
}
}
}
if(bNeedAllIn)
return true;
else
return false;
}
//<2F><>ȡ<EFBFBD>߽<EFBFBD><DFBD><EFBFBD><EFBFBD><EFBFBD>
DbRect CSequentialPoint::GetRect()
{
DbRect rect;
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
for(;iter!=iter_end;iter++)
{
AdjustRectByPoint(rect,(*iter).GetPt());
}
return rect;
}
//<2F>Ƿ<EFBFBD><C7B7>нڵ<D0BD><DAB5><EFBFBD>rect <20><>
bool CSequentialPoint::HasNodeInRect(DbRect rect)
{
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
for(;iter!=iter_end;iter++)
{
if((*iter).IsNode()&&IsPointInRect((*iter).GetPt(),rect))
{
return true;
}
}
return false;
}
#endif
#if 1
void CSequentialPoint::Operate(SObjOperatePar par)
{
if(par.OpType == _OP_REVERSE)
{
//<2F><>ת<EFBFBD>ڵ<EFBFBD>
Reverse();
}
else
{
OperateExt(par);
}
}
void CSequentialPoint::OperateExt(SObjOperatePar par)
{
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
for(;iter!=iter_end;iter++)
{
(*iter).Operate(par);
}
}
//<2F><>ת<EFBFBD>ڵ<EFBFBD>
void CSequentialPoint::Reverse()
{
//<2F>ȱ<EFBFBD><C8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
vector<CDataPoint> vec;
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
for(;iter!=iter_end;iter++)
{
vec.push_back((*iter));
}
//<2F><><EFBFBD><EFBFBD>
m_PtContainer.clear();
//<2F><><EFBFBD>򵹻<EFBFBD>
int size = vec.size();
for(int i=size-1;i>=0;i--)
{
m_PtContainer.push_back(vec[i]);
}
}
#endif
#if 1//<2F><><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>
void CSequentialPoint::DrawDataPointVec(CDC* pDC,vector<CDataPoint> &vec)
{
if(vec.size()>1)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
//<2F><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>߶<EFBFBD>
vector<CDataPoint>::iterator iter = vec.begin();
vector<CDataPoint>::iterator iter_end = vec.end();
for(;iter!=iter_end;iter++)
{
CDataPoint &DataPt = (*iter);
CPoint pt = DataPt.GetDevicePt();
if(iter == vec.begin())
{
pDC->MoveTo(pt.x,pt.y);
}
else
{
pDC->LineTo(pt.x,pt.y);
}
}
}
}
void CSequentialPoint::Draw(CDC* pDC,CPen&Pen)
{
CPen *pOldPen;
pOldPen = pDC->SelectObject(&Pen);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>
DrawDataPointVec(pDC,m_PtContainer);
pDC->SelectObject(pOldPen);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>߶<EFBFBD>
void CSequentialPoint::DrawLastLine(CDC* pDC,CPen &Pen)
{
CPen *pOldPen;
pOldPen = pDC->SelectObject(&Pen);
if(!Empty())
{
vector<CDataPoint> &vec = m_PtContainer;
int size = vec.size();
if(size>=2)
{
CPoint pt1 = vec[size-2].GetDevicePt();
pDC->MoveTo(pt1.x,pt1.y);
CPoint pt2 = vec[size-1].GetDevicePt();
pDC->LineTo(pt2.x,pt2.y);
}
}
pDC->SelectObject(pOldPen);
}
//<2F><><EFBFBD>ƽڵ<C6BD>
void CSequentialPoint::DrawNode(CDC* pDC)
{
int size = m_PtContainer.size();
for(int i=0;i<size;i++)
{
//<2F><><EFBFBD><EFBFBD>obj <20>պ<EFBFBD><D5BA><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ڵ<EFBFBD>
if(i==size-1 && m_PtContainer[i].GetPt() == m_PtContainer[0].GetPt())
{
break;
}
if(m_PtContainer[i].IsNode())
{
if(i==0)//<2F>׽ڵ<D7BD>
{
DrawSolidRect(pDC,gDraw->GetObjFirstNodeColor(),gDraw->GetCurPointRect(m_PtContainer[i].GetPt()));
}
else
{
DrawSolidRect(pDC,gDraw->GetObjNodeColor(),gDraw->GetCurPointRect(m_PtContainer[i].GetPt()));
}
}
}
}
#endif
#if 1
void CSequentialPoint::GetLineInRect(DbRect &rect,vector<DbLine> &DataPtLineVec)
{
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
for(;iter!=iter_end;iter++)
{
if(iter != m_PtContainer.begin())
{
Dbxy pt1 = (*(iter-1)).GetPt();
Dbxy pt2 = (*iter).GetPt();
if(IsLineInRect(pt1,pt2,rect))
{
DataPtLineVec.push_back(DbLine((*(iter-1)),(*iter)));
}
}
}
}
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>
void CSequentialPoint::GetNodePtLineInRect(DbRect &rect,vector<DbLine> &DataPtLineVec)
{
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
for(;iter!=iter_end;iter++)
{
Dbxy pt1 = (*iter).GetPt();
Dbxy pt2 = (*iter).GetPt();
if(IsLineInRect(pt1,pt2,rect))
{
DataPtLineVec.push_back(DbLine((*iter),(*iter)));
}
}
}
#endif
//<2F>Ѽ<EFBFBD><D1BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>vec (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) (PenNumΪ<6D>ʺ<EFBFBD>)
void CSequentialPoint::GetPtData(vector<vector<Dbxy>> &vec,int PenNum)
{
bool bhasLastPt = false;//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
Dbxy LastPt;
//<2F><>ȡ֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
int size = vec.size();
if(size>0)
{
if(vec[size-1].empty()==false)
{
int size1 = vec[size-1].size();
LastPt = vec[size-1][size1-1];
bhasLastPt = true;
}
}
vector<Dbxy> VecTmp;
bool bNeedConnect = false;//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
for(;iter!=iter_end;iter++)
{
if(iter == m_PtContainer.begin() && bhasLastPt)//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
{
if((*iter).GetPt() == LastPt)
{
bNeedConnect = true;
}
}
Dbxy pt = (*iter).GetPt();
pt.PenNum = PenNum;//<2F><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ڵıʺ<C4B1>
VecTmp.push_back(pt);
}
if(!VecTmp.empty())
{
#if 0//<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(bNeedConnect)
{
vector<Dbxy>::iterator iter = VecTmp.begin();
vector<Dbxy>::iterator iter_end = VecTmp.end();
for(;iter!=iter_end;iter++)
{
vec[size-1].push_back(*iter);
}
}
else
#endif
{
vec.push_back(VecTmp);
}
}
}
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>line <20>
bool CSequentialPoint::IntersectWithLine(DbLine &line)
{
Dbxy pt1 = line.GetPt1();
Dbxy pt2 = line.GetPt2();
vector<CDataPoint>::iterator iter = m_PtContainer.begin();
vector<CDataPoint>::iterator iter_end = m_PtContainer.end();
for(;iter!=iter_end;iter++)
{
if(iter != m_PtContainer.begin())
{
if(IsTwoLineIntersect(pt1,pt2,(*(iter-1)).GetPt(),(*iter).GetPt()))
{
return true;
}
}
}
return false;
}