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.

376 lines
9.0 KiB
C++

#include "StdAfx.h"
#include "ObjBase.h"
#include "LogMgr.h"
#include "GlobalFunction.h"
#include "GlobalDrawMgr.h"
#include "PenParMgr.h"
#include "WorkFileLable.h"
#include "WorkFileMgr.h"
#include "CommonFlowMgr.h"
#include "DrawSimpleShape.h"
#include "ProgramLaserTuiHuo.h"
#include "WaferRecipeDataMgr.h"
#include "CStringFuc.h"
CObjBase::CObjBase(void)
{
SetSelected(false);//是否被选中
SetLock(false);//是否锁定
m_bDraw = true;//是否绘制
m_bMarkPt = false;//是否用来作为mark 定位点
m_bCollected = false;//是否被收集
m_bFillObj = false;//是否为填充obj
m_bScaned = false;//是否被扫描过
OnCreat();
}
CObjBase::~CObjBase(void)
{
}
//创建的时候
void CObjBase::OnCreat()
{
SetPenNum(gPenParMgr->GetCurPenNum());
}
void CObjBase::SetPenNum(int n)
{
m_PenNum = n;
}
#if 1
//拷贝构造函数
CObjBase::CObjBase(CObjBase &rhs)
{
m_bSelected = rhs.m_bSelected;//是否被选中
m_PtContainer.Load(rhs.m_PtContainer);//坐标数据的容器
m_NodePtContainer.Load(rhs.m_NodePtContainer);
m_PenNum = rhs.m_PenNum;
m_bLocked = rhs.m_bLocked;
m_bDraw = rhs.m_bDraw;//是否绘制
m_bMarkPt = false;//是否用来作为mark 定位点
m_bFillObj = rhs.m_bFillObj;//是否为填充obj
m_bScaned = rhs.m_bScaned;//是否被扫描过
}
//复制rhs 的数据点
void CObjBase::CopyPt(CObjBase &rhs)
{
m_PtContainer.Load(rhs.m_PtContainer);
}
#endif
#if 1
void CObjBase::WriteWorkFileBase(vector<CLab> &LabVec)
{
LabVec.push_back(CLab(LAB_OBJ_TYPE,(int)GetType()));//obj 的类型
LabVec.push_back(CLab(LAB_PEN_NUM,m_PenNum));//obj 轮廓的笔号
LabVec.push_back(CLab(LAB_OBJ_IS_MARK,m_bMarkPt));//是否为mark 点
}
void CObjBase::ReadWorkFileBase(CLabVecRang &LabVecRang)
{
CWorkFileMgr WorkFileMgr;
//读取笔号------------------------------------------------
{
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_PEN_NUM);
if(Lab.m_ValType != _TYPE_NULL)
{
m_PenNum = Lab.m_Int;
}
}
{
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_OBJ_IS_MARK);
if(Lab.m_ValType != _TYPE_NULL)
{
m_bMarkPt = Lab.m_Bool;
}
}
}
void CObjBase::WriteWorkFile(vector<CLab> &LabVec)
{
//写入公共信息
WriteWorkFileBase(LabVec);
WriteWorkFileExt(LabVec);
}
void CObjBase::ReadWorkFile(CLabVecRang &LabVecRang)
{
//读取公共信息
ReadWorkFileBase(LabVecRang);
ReadWorkFileExt(LabVecRang);
}
void CObjBase::WriteWorkFileExt(vector<CLab> &LabVec)
{
m_PtContainer.WriteWorkFile(LabVec);
}
void CObjBase::ReadWorkFileExt(CLabVecRang &LabVecRang)
{
//读取数据点--------------------------------------------
m_PtContainer.ReadWorkFile(LabVecRang);
}
#endif
#if 1
void CObjBase::Draw(CDC* pDC,CPen &Pen)
{
if(!m_bDraw)
return;
//图形数据
m_PtContainer.Draw(pDC,Pen);
//节点
if(gDraw->IsbShowObjNode() && IsSelected())
{
m_PtContainer.DrawNode(pDC);
}
//填充线
DrawFill(pDC,Pen);
}
void CObjBase::Draw(CDC* pDC)
{
if(!m_bDraw)
return;
CPen Pen;
COLORREF color = gPenParMgr->GetPenColor(m_PenNum);
if(IsbFillObj())//扫描线的颜色
{
if(gWaferRecipeDataMgr->IsbScanEnd())
color = RGB_RED;
else
color = RGB_BLUE1;
if(gPenParMgr->IsSpecialPen(m_PenNum))
return;
}
Pen.CreatePen(PS_INSIDEFRAME,0.5,color);
Draw(pDC,Pen);
}
//绘制最后一个线段
void CObjBase::DrawLastLine(CDC* pDC,CPen &Pen)
{
if(!m_bDraw)
return;
m_PtContainer.DrawLastLine(pDC,Pen);
}
#endif
//添加一个数据点
void CObjBase::AddDataPoint(CDataPoint pt)
{
m_PtContainer.AddDataPoint(pt);
}
//添加额外用于捕获的点
void CObjBase::AddNodePt(CDataPoint pt)
{
m_NodePtContainer.AddDataPoint(pt);
}
bool CObjBase::Empty()
{
return (m_PtContainer.GetPtCnt()<2) ;
}
void CObjBase::DelAllPt()//删除所有数据点
{
m_PtContainer.DelAllPt();
m_NodePtContainer.DelAllPt();
}
//获取点的个数
int CObjBase::GetPtCnt()
{
return m_PtContainer.GetPtCnt();
}
void CObjBase::DelLastDataPoint()//删除最后一个节点
{
m_PtContainer.DelLastDataPoint();
}
int CObjBase::GetNodePtIdx(Dbxy pt)
{
return m_PtContainer.GetNodePtIdx(pt);
}
void CObjBase::DelNodePtByIdx(int idx)
{
m_PtContainer.DelNodePtByIdx(idx);
}
void CObjBase::SetNodePtByIdx(int idx,Dbxy pt)
{
m_PtContainer.SetNodePtByIdx(idx,pt);
}
void CObjBase::InsertNode(int idx,Dbxy pt)
{
m_PtContainer.InsertNode(idx,pt);
}
void CObjBase::SetLastPoint(CDataPoint &pt)
{
m_PtContainer.SetLastPoint(pt);
}
bool CObjBase::IsSelected()
{
return m_bSelected;
}
void CObjBase::SetSelected(bool bSelected)
{
if(m_bLocked)//锁定状态不能被选中
return;
m_bSelected = bSelected;
}
DbRect CObjBase::GetRect()
{
return m_PtContainer.GetRect();
}
Dbxy CObjBase::GetFirstPt()
{
return m_PtContainer.GetFirstPt();
}
Dbxy CObjBase::GetLastPt()
{
return m_PtContainer.GetLastPt();
}
//是否有节点在rect 内
bool CObjBase::HasNodeInRect(DbRect rect)
{
return m_PtContainer.HasNodeInRect(rect);
}
//是否和line 相交
bool CObjBase::IntersectWithLine(DbLine &line)
{
return m_PtContainer.IntersectWithLine(line);
}
#if 1
void CObjBase::Operate(SObjOperatePar &par)
{
m_GeometryPorp.Operate(par);//记录几何属性
m_PtContainer.Operate(par);//数据点
m_NodePtContainer.Operate(par);//节点
OperateFill(par);//填充
}
#endif
#if 1//捕获相关函数
//获取obj 和rect 相交的线段(bGetCatchNode 表示是否获得额外的捕捉点)
void CObjBase::GetLineInRect(DbRect &rect,vector<DbLine> &DataPtLineVec,bool bGetCatchNode)
{
m_PtContainer.GetLineInRect(rect,DataPtLineVec);
if(bGetCatchNode)
{
m_NodePtContainer.GetNodePtLineInRect(rect,DataPtLineVec);
}
}
#endif
#if 1
//搜集obj 点的数据到vec 中
void CObjBase::GetPtData(vector<vector<Dbxy>> &vec)
{
if(m_bMarkPt)//不要收集mark 的数据
return;
m_PtContainer.GetPtData(vec,m_PenNum);
//填充数据--------------------------------------------------
vector<CSequentialPoint>::iterator iter = m_FillDataVec.begin();
vector<CSequentialPoint>::iterator iter_end = m_FillDataVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).GetPtData(vec,m_PenNum);
}
}
#endif
#if 1//填充相关函数
//创建填充数据
void CObjBase::CreatFillData(SFillPar FillPar)
{
m_FillDataVec.clear();
if(!FillPar.bFill)
return;
//搜集obj 点的数据到vec 中
vector<vector<Dbxy>> vec;
GetPtData(vec);
//创建填充
CObjFill Fill(m_FillDataVec);
Fill.SetPar(FillPar);
Fill.CreatFill(vec,GetRect());
}
void CObjBase::DrawFill(CDC* pDC,CPen &Pen)
{
vector<CSequentialPoint>::iterator iter = m_FillDataVec.begin();
vector<CSequentialPoint>::iterator iter_end = m_FillDataVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).Draw(pDC,Pen);
}
}
//操作填充
void CObjBase::OperateFill(SObjOperatePar &par)
{
vector<CSequentialPoint>::iterator iter = m_FillDataVec.begin();
vector<CSequentialPoint>::iterator iter_end = m_FillDataVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).Operate(par);
}
}
//获取填充数据
void CObjBase::GetFillData(vector<vector<Dbxy>> &vec)
{
//填充数据
vector<CSequentialPoint>::iterator iter = m_FillDataVec.begin();
vector<CSequentialPoint>::iterator iter_end = m_FillDataVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).GetPtData(vec);
}
}
#endif
#if 1
void CObjBase::AddDataPointVec(vector<CDataPoint> &Vec)
{
vector<CDataPoint> &DataPointVec = GetPtContainer();
vector<CDataPoint>::iterator iter = Vec.begin();
vector<CDataPoint>::iterator iter_end = Vec.end();
for(;iter!=iter_end;iter++)
{
DataPointVec.push_back(*iter);
}
}
//显示点的坐标txt
void CObjBase::DrawPtCoord(CDC* pDC)
{
if(m_bFillObj)//填充对象不显示
return;
vector<CDataPoint> &DataPointVec = GetPtContainer();
bool bShowPerPt = false;//前一个点是否显示
int size = DataPointVec.size();
for(int k=0;k<size;k++)
{
Dbxy pt = DataPointVec[k].GetPt();
bool bShow = false;
if(k==0||k==size-1)//端点
{
bShow = true;
}
if(k>0)
{
Dbxy PerPt = DataPointVec[k-1].GetPt();//前一个点
//和前一个点距离大于指定值时显示
if(CalDistance(PerPt,pt)>30)
{
bShow = true;
if(!bShowPerPt)//前一个点没有显示的时,补上
{
DrawPtCoordExt(pDC,PerPt);
}
}
}
if(bShow)
{
DrawPtCoordExt(pDC,pt);
}
//记录当前点是否显示
bShowPerPt = bShow;
}
}
void CObjBase::DrawPtCoordExt(CDC* pDC,Dbxy &pt)
{
CString str= "X"+Db2CString(pt.x,3)+"Y"+Db2CString(pt.y,3);
gDraw->DrawTxt(pDC,str,pt);
}
#endif