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.

222 lines
5.9 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "StdAfx.h"
#include "MarkArea.h"
#include "DrawSimpleShape.h"
#include "Layer.h"
#include "TemplateMgr.h"
#include "ObjComponentMgr.h"
#include "GlobalFunction.h"
#include "LogMgr.h"
#include "CommonFlowMgr.h"
#include "GlobalDrawMgr.h"
#define MIN_OBJ_CNT 5 //最少obj 数量
CMarkArea::CMarkArea()
{
UpdateSize();
m_bSel = false;//选择状态
Init();
}
CMarkArea::CMarkArea(Dbxy pt,DbSize size)
{
m_RealBasePt = m_BasePt = pt;//基准点
m_Size = size;//尺寸
Init();
}
void CMarkArea::Init()
{
m_AreaIdx = 0;//区域的编号
m_AreaPenNum = 0;//第一个区域内obj 的笔号
}
CMarkArea::~CMarkArea(void)
{
}
#if 1
void CMarkArea::Serialize(CArchive& ar)
{
if(ar.IsStoring())
{
ar<<m_BasePt.x;
ar<<m_BasePt.y;
ar<<m_Size.w;
ar<<m_Size.h;
ar<<m_Offset.x;
ar<<m_Offset.y;
}
else
{
ar>>m_BasePt.x;
ar>>m_BasePt.y;
ar>>m_Size.w;
ar>>m_Size.h;
ar>>m_Offset.x;
ar>>m_Offset.y;
}
}
void CMarkArea::WriteWorkFile(vector<CLab> &LabVec)
{
LabVec.push_back(CLab(LAB_NULL,m_BasePt.x));
LabVec.push_back(CLab(LAB_NULL,m_BasePt.y));
LabVec.push_back(CLab(LAB_NULL,m_Size.w));
LabVec.push_back(CLab(LAB_NULL,m_Size.h));
LabVec.push_back(CLab(LAB_NULL,m_Offset.x));
LabVec.push_back(CLab(LAB_NULL,m_Offset.y));
}
void CMarkArea::ReadWorkFile(CLabVecRang &LabVecRang)
{
int idx = LabVecRang.GetStart();
m_BasePt.x = LabVecRang.GetDouble(idx++);
m_BasePt.y = LabVecRang.GetDouble(idx++);
m_Size.w = LabVecRang.GetDouble(idx++);
m_Size.h = LabVecRang.GetDouble(idx++);
m_Offset.x = LabVecRang.GetDouble(idx++);
m_Offset.y = LabVecRang.GetDouble(idx++);
}
//更新尺寸为振镜范围
void CMarkArea::UpdateSize()
{
}
//获取area 的理论范围
DbRect CMarkArea::GetRect()
{
DbRect rect(m_BasePt,m_Size);
return rect;
}
void CMarkArea::Draw(CDC* pDC,bool bSel)
{
CPen pen;
if(bSel || m_bSel)
{
pen.CreatePen(PS_DOT,1,RGB_RED);
}
else
{
pen.CreatePen(PS_DOT,1,RGB_PINK);
}
double Gap = 0;//显示扩大一点
DbSize size = GetSize();
size.w += Gap;
size.h += Gap;
DbRect rect;
rect.Creat(m_BasePt,size);
//绘制外框
DrawRect(pDC,pen,rect,false);
//选择状态时在中间区域绘制网格线
if(m_bSel)
{
double GridGap = gDraw->GetAreaGridGap();//网格间隔mm
Drawgridding(pDC,pen,rect,GridGap);
}
}
bool CMarkArea::DrawObjComponentVec(vector<Sptr<CObjComponent>> &vec,CDC* pDC,bool bSel)
{
vector<Sptr<CObjComponent>>::iterator iter = vec.begin();
vector<Sptr<CObjComponent>>::iterator iter_end = vec.end();
for(;iter!=iter_end;iter++)
{
(*iter)->Draw(pDC);
}
return true;
}
//是否有工作数据
bool CMarkArea::HasWorkData()
{
if(m_WorkData.Empty())
return false;
return true;
}
bool CMarkArea::IsPtInArea(Dbxy pt)
{
return IsPointInRect(pt,DbRect(m_BasePt,m_Size));
}
void CMarkArea::SetBasePt(Dbxy pt)
{
m_BasePt = pt;
SetRealBasePt(pt);
}
#endif
#if 1
//获取实际中心位置
Dbxy CMarkArea::GetRealBasePt()
{
if(m_RealBasePt.Equal(Dbxy(0,0)))
m_RealBasePt = m_BasePt;
return m_RealBasePt;
}
//搜集在area 范围内的obj 数据(Product 是当前要加工的工件,主要用来偏移旋转数据)
void CMarkArea::CollectWorkData(bool bNeedSel)
{
//清空数据容器
m_WorkData.Clear();
vector<vector<Dbxy>> &WorkDataVec = m_WorkData.GetDataVec();
//先搜集元件对象数据-----------------------------------
//CollectComponentObj(WorkDataVec,bNeedSel);
//如果没有收集到原件的数据才搜集layer 中obj 的数据
if(WorkDataVec.empty())
{
//先找到在area 内的obj
CObjContainer ObjContainer;
CollectLayerObjExt(ObjContainer,bNeedSel);
int AreaCycleCnt = 1;
for(int k=0;k<AreaCycleCnt;k++)
{
//提取obj 的数据点(理论值) 这些数据是相对于layer 中心的坐标
ObjContainer.GetObjPtData(WorkDataVec,bNeedSel);
}
}
if(WorkDataVec.empty())
return;
}
//搜集layer 的obj 在area 范围内的obj 加入到容器ObjContainer
void CMarkArea::CollectLayerObjExt(CObjContainer &ObjContainer,bool bNeedSel)
{
//获得layer 的obj 容器直接操作
CObjContainer &LayerObjContainer = gLayer.GetObjContainer();
vector<Sptr<CObjBase>> &ObjVec = LayerObjContainer.GetObjVec();
//依次判断每个obj 需要加入哪个markarea
DbRect Rect = GetRect();
vector<Sptr<CObjBase>>::iterator iter = ObjVec.begin();
vector<Sptr<CObjBase>>::iterator iter_end = ObjVec.end();
for(;iter!=iter_end;iter++)
{
if(!bNeedSel || (bNeedSel && (*iter)->IsSelected()))
{
if((*iter)->IsbMarkPt())//不要收集mark 点
continue;
if(!(*iter)->IsbFillObj())//退火设备只收集填充对象
continue;
if(!(*iter)->IsbCollected() && (*iter)->IsInRect(Rect,false))//只要一个数据点在rect 内都算
{
(*iter)->SetbCollected(true);//设置为已收集
ObjContainer.AddObject((*iter));
m_AreaPenNum = (*iter)->GetPenNum();//区域内obj 的笔号
}
}
}
}
//搜集元件对象(被收集的obj 会被标记,防止被其他的area 重复收集)
void CMarkArea::CollectComponentObj(vector<vector<Dbxy>> &vec,bool bNeedSel)
{
//收集area 内的数据
gObjComponentMgr->CollectWorkData(GetRect(),vec,bNeedSel);
}
//通过数据范围来调整area 的中心和尺寸
void CMarkArea::AdjustByObj()
{
//获得area 内的数据范围
DbRect DataRect = gObjComponentMgr->SetMarkedStateRect(GetRect(),false);
DbSize size = DataRect.GetSize();
if(size.w>0 && size.h>0)
{
m_BasePt = DataRect.GetCenterPt();
m_Size = size;
}
}
#endif