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.

1151 lines
34 KiB
C++

#include "StdAfx.h"
#include "ObjComponentMgr.h"
#include "CStringFuc.h"
#include "GlobalDrawMgr.h"
#include "GlobalFunction.h"
#include "DrawSimpleShape.h"
#include "ObjCircle.h"
#include "WorkFileMgr.h"
#include "ProductMgr.h"
#include "Propertie.h"
#include "PropertieMgr.h"
#include "AuthorityMgr.h"
#include "MotionCtrl.h"
#include "MsgBox.h"
#include "WorkCmdMoveAsixXY.h"
#include "WorkCmdInvoker.h"
#include "LogMgr.h"
#include "Layer.h"
#include "ObjContainer.h"
#include "CommonFlowMgr.h"
#define GENG_3 (1.7320508075689)//根号3
CObjComponentMgr *gObjComponentMgr = new CObjComponentMgr;
CObjComponentMgr::CObjComponentMgr(void)
{
m_CurSelIdx = -1;//当前选择的 索引值
m_bDrawBase = false;//是否只绘制基准元件
m_ArrayXcntZ = 35;//X 正方向阵列数量
m_ArrayXcntF = 0;//X 负方向阵列数量
m_ArrayYcntZ = 3;//Y 正方向阵列数量
m_ArrayYcntF = 0;//Y 负方向阵列数量
m_OffsetX = 5;//X 方向间隔
m_OffsetY = 4.2;//Y 方向间隔
m_RealOffsetX = m_OffsetX;//实际的X 方向间隔mm
m_RealOffsetY = m_OffsetY;//实际的Y 方向间隔mm
//限定元件的范围
m_bUseArea = false;//是否使用限定范围
m_bRectArea = false;//true 为矩形范围,false 为圆形范围
m_AreaSize.w = 50;//矩形范围的尺寸
m_AreaSize.h = 50;//矩形范围的尺寸
m_AreaRadius = 150;//圆形范围的直径
m_bDrawAllObj = true;//是否绘制所有的原件对象
m_bDrawFillColor = false;//是否绘制填充
m_NoSelColor = RGB_GREEN;
m_SelColor = RGB_RED;
m_ViewObjColor = RGB_YELLOW;
m_ViewedObjColor = RGB_GREEN;//观察过的obj 颜色
m_bNeedAllIn = true;//元件是否需要全部在范围内
m_bAutoArray = false;//是否自动排列
m_AutoArrayGap = 0.5;//自动排布间隔
m_DefaultAng = 0;//默认角度
m_CurSelObjIdx.x = 1;
m_CurSelObjIdx.y = 1;
m_bMoveTrackSDir = true;//S形轨迹移动的方向标志
m_bShowRealObj = false;//显示obj 的实际位置
m_bObjToCcdMode = false;//true 的时候选择obj 会移动到CCD 观察
m_bDrawBindingObj = true;//是否绘制绑定的layer obj
}
CObjComponentMgr::~CObjComponentMgr(void)
{
}
#if 1
void CObjComponentMgr::WriteWorkFileExt(vector<CLab> &LabVec)
{
//读取也要按照这个顺序
LabVec.push_back(CLab(LAB_NULL,m_ArrayXcntZ));
LabVec.push_back(CLab(LAB_NULL,m_ArrayXcntF));
LabVec.push_back(CLab(LAB_NULL,m_ArrayYcntZ));
LabVec.push_back(CLab(LAB_NULL,m_ArrayYcntF));
LabVec.push_back(CLab(LAB_NULL,m_OffsetX));
LabVec.push_back(CLab(LAB_NULL,m_OffsetY));
LabVec.push_back(CLab(LAB_NULL,m_bUseArea));
LabVec.push_back(CLab(LAB_NULL,m_bRectArea));
LabVec.push_back(CLab(LAB_NULL,m_AreaBasePt.x));
LabVec.push_back(CLab(LAB_NULL,m_AreaBasePt.y));
LabVec.push_back(CLab(LAB_NULL,m_AreaSize.w));
LabVec.push_back(CLab(LAB_NULL,m_AreaSize.h));
LabVec.push_back(CLab(LAB_NULL,m_AreaRadius));
LabVec.push_back(CLab(LAB_NULL,m_bAutoArray));
LabVec.push_back(CLab(LAB_NULL,m_AutoArrayGap));
LabVec.push_back(CLab(LAB_NULL,m_DefaultAng));
//存储基准对象--------------------------------------------------------
SaveBaseObj(LabVec);
}
void CObjComponentMgr::ReadWorkFile(CLabVecRang &LabVecRang)
{
//删除所有
DelAll();
//读取顺序和类型要和写入相同
int idx = LabVecRang.GetStart()+1;
m_ArrayXcntZ = LabVecRang.GetInt(idx++);
m_ArrayXcntF = LabVecRang.GetInt(idx++);
m_ArrayYcntZ = LabVecRang.GetInt(idx++);
m_ArrayYcntF = LabVecRang.GetInt(idx++);
m_OffsetX = LabVecRang.GetDouble(idx++);
m_OffsetY = LabVecRang.GetDouble(idx++);
m_bUseArea = LabVecRang.GetBool(idx++);
m_bRectArea = LabVecRang.GetBool(idx++);
m_AreaBasePt.x = LabVecRang.GetDouble(idx++);
m_AreaBasePt.y = LabVecRang.GetDouble(idx++);
m_AreaSize.w = LabVecRang.GetDouble(idx++);
m_AreaSize.h = LabVecRang.GetDouble(idx++);
m_AreaRadius = LabVecRang.GetDouble(idx++);
m_bAutoArray = LabVecRang.GetBool(idx++);
m_AutoArrayGap = LabVecRang.GetDouble(idx++);
m_DefaultAng = LabVecRang.GetDouble(idx++);
//读取基准对象
ReadBaseObj(LabVecRang);
//重新阵列
Array();
}
//保存基准对象
void CObjComponentMgr::SaveBaseObj(vector<CLab> &LabVec)
{
vector<CObjComponent>::iterator iter = m_BaseComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_BaseComponentVec.end();
for(;iter!=iter_end;iter++)
{
LabVec.push_back(CLab(LAB_OBJ_START));//数据点开始
Dbxy BasePt = (*iter).GetBasePt();
DbSize size = (*iter).GetSize();
LabVec.push_back(CLab(LAB_POINT_X,BasePt.x));
LabVec.push_back(CLab(LAB_POINT_Y,BasePt.y));
LabVec.push_back(CLab(LAB_SIZE_W,size.w));
LabVec.push_back(CLab(LAB_SIZE_H,size.h));
LabVec.push_back(CLab(LAB_OBJ_IS_CIRCLE,(*iter).IsCircle()));
LabVec.push_back(CLab(LAB_OBJ_END));//数据点结束
}
}
void CObjComponentMgr::ReadBaseObj(CLabVecRang &LabVecRang)
{
//分离obj 对象---------------------------------------------------
vector<CLabVecRang> LabVecRangVec;
CWorkFileMgr WorkFileMgr;
WorkFileMgr.SeparateStrVec(LabVecRang,LabVecRangVec,LAB_OBJ_START,LAB_OBJ_END);
//处理每个obj ---------------------------------------------------
if(!LabVecRangVec.empty())
{
vector<CLabVecRang>::iterator iter = LabVecRangVec.begin();
vector<CLabVecRang>::iterator iter_end = LabVecRangVec.end();
for(;iter!=iter_end;iter++)
{
Dbxy BasePt;
DbSize size;
{//BasePt X 坐标
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_POINT_X);
if(Lab.m_ValType != _TYPE_NULL)
{
BasePt.x = Lab.m_Double;
}
}
{//BasePt Y 坐标
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_POINT_Y);
if(Lab.m_ValType != _TYPE_NULL)
{
BasePt.y = Lab.m_Double;
}
}
{//size w
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_SIZE_W);
if(Lab.m_ValType != _TYPE_NULL)
{
size.w = Lab.m_Double;
}
}
{//size h
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_SIZE_H);
if(Lab.m_ValType != _TYPE_NULL)
{
size.h = Lab.m_Double;
}
}
bool bIsCircle = true;
{//size h
CLab Lab = WorkFileMgr.FindLab(LabVecRang,LAB_OBJ_IS_CIRCLE);
if(Lab.m_ValType != _TYPE_NULL)
{
bIsCircle = Lab.m_Bool;
}
}
CObjComponent Obj(BasePt,size);
Obj.SetIsCircle(bIsCircle);
m_BaseComponentVec.push_back(Obj);
}
}
}
#endif
#if 1
void CObjComponentMgr::Draw(CDC* pDC)
{
if(!m_bDrawAllObj)
return;
{
//元件
int size = m_ComponentVec.size();
for(int i=0;i<size;i++)
{
m_ComponentVec[i].Draw(pDC);
}
Dbxy Offset;
DrawArea(pDC,Offset);//限定范围
}
if(m_bDrawBase)//基准元件
{
int size = m_BaseComponentVec.size();
for(int i=0;i<size;i++)
{
if(m_CurSelIdx==i)
{
m_BaseComponentVec[i].SetSelected(true);
m_BaseComponentVec[i].Draw(pDC);
}
else
{
m_BaseComponentVec[i].SetSelected(false);
m_BaseComponentVec[i].Draw(pDC);
}
}
}
#if 0
//在所有搜集的obj 中心绘制一个十字
DbRect Rect(m_AllObjCenterPt,2);
DrawCrossX(pDC,gDraw->GetMarkPointPen(),Rect);
#endif
}
//按偏移绘制限定范围
void CObjComponentMgr::DrawArea(CDC* pDC,Dbxy Offset)
{
if(m_bUseArea && !m_ComponentVec.empty())
{
Dbxy BasePt;
BasePt.x += Offset.x;
BasePt.y += Offset.y;
if(m_bRectArea)
{
DbRect rect(BasePt,m_AreaSize);
DrawRect(pDC,gDraw->GetObjComponentAreaPen(),rect,false);
}
else
{
CObjCircle Circle;
CCirclePar par;
par.CenterPt = m_AreaBasePt;
par.Radius = m_AreaRadius;
par.DEdgeCnt = 200;
Circle.Creat(par);
Circle.Draw(pDC,gDraw->GetObjComponentAreaPen());
}
}
}
//选择元件
bool CObjComponentMgr::SelObjectInRect(DbRect rect)
{
if(!m_bDrawAllObj)
return false;
bool flg = false;
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
if((*iter).IsInRect(rect))
{
//反转选择
bool b = !((*iter).IsSelected());
(*iter).SetSelected(b);
flg = true;
if(!gDraw->IsbMultipleSel())//不多选
{
Dbxy pt = (*iter).GetBasePt();
gLogMgr->WriteDebugLog("Sel Obj ViewCoord :","x","y",pt.x,pt.y);
//这里可以观察选择obj 的实际坐标值
Dbxy RealBasePt = (*iter).GetRealBasePt();
gLogMgr->WriteDebugLog("Sel Obj RealCoord :","x","y",RealBasePt.x,RealBasePt.y);
break;
}
}
}
//响应obj 选择状态的改变
OnObjSelStateChange();
return flg;
}
//全选
void CObjComponentMgr::SelAllObj()
{
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).SetSelected(true);
}
//相应obj 选择状态的改变
OnObjSelStateChange();
}
void CObjComponentMgr::NotSelAllObj()
{
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).SetSelected(false);
}
//相应obj 选择状态的改变
OnObjSelStateChange();
}
//反选
void CObjComponentMgr::RevSelAllObj()
{
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).SetSelected(!((*iter).IsSelected()));
}
//相应obj 选择状态的改变
OnObjSelStateChange();
}
//相应obj 选择状态的改变
void CObjComponentMgr::OnObjSelStateChange()
{
}
//获取所有选择obj 的索引值到vec
void CObjComponentMgr::GetSelObjIdx(vector<bool> &SelObjIdxVec)
{
SelObjIdxVec.clear();
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
int idx = 0;
for(;iter!=iter_end;iter++,idx++)
{
SelObjIdxVec.push_back((*iter).IsSelected());
}
}
//通过索引值来设置obj 的选择状态
void CObjComponentMgr::SetSelectedByIdx(int idx,bool b)
{
int size = m_ComponentVec.size();
if(idx<size)
{
m_ComponentVec[idx].SetSelected(b);
}
}
//计算所有obj 的中心点
void CObjComponentMgr::CalAllObjCenterPt()
{
DbRect Rect;
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
int idx = 0;
for(;iter!=iter_end;iter++,idx++)
{
if((*iter).IsbCollecteData())
{
AdjustRectByPoint(Rect,(*iter).GetBasePt());
}
}
m_AllObjCenterPt = Rect.GetCenterPt();
}
#endif
#if 1
//获取当前选择obj 的数量
int CObjComponentMgr::GetSelObjCnt()
{
int cnt = 0;
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
if((*iter).IsSelected())
cnt++;
}
return cnt;
}
//获取当前设定的mark 数量
int CObjComponentMgr::GetMarkObjCnt()
{
int cnt = 0;
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
if((*iter).IsMarkObj())
cnt++;
}
return cnt;
}
void CObjComponentMgr::ResetAllMarkObj()
{
int cnt = 0;
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).SetbMarkObj(false);
}
}
//设置当前选择的obj 为mark
void CObjComponentMgr::SetSelObjMark(int CurMarkCnt)
{
int idx = CurMarkCnt+1;
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
if((*iter).IsSelected())
{
(*iter).SetbMarkObj(true);
CString LogStr;
LogStr.Format(("Set Mark Pt [%d]"),idx++);
gLogMgr->WriteDebugLog(LogStr);
Dbxy pt = (*iter).GetBasePt();
LogStr.Format(("[pt.x] = [%f] ,[pt.y] = [%f]"),pt.x,pt.y);
gLogMgr->WriteDebugLog(LogStr);
}
}
}
//设置当前选择的obj 为mark obj
bool CObjComponentMgr::SetMarkObj()
{
int SelObjCnt = GetSelObjCnt();//选择的个数
if(SelObjCnt>2)
{
return false;
}
if(SelObjCnt==0)
{
return false;
}
int MarkObjCnt = GetMarkObjCnt();//现在mark obj 的个数
if(MarkObjCnt>=2)
{
ResetAllMarkObj();
MarkObjCnt = 0;
}
//设置当前选择的obj 为mark
SetSelObjMark(MarkObjCnt);
return true;
}
#endif
#if 1
//添加一个基准元件
void CObjComponentMgr::AddBaseComponent()
{
Dbxy pt;
DbSize size(2,2);
AddBaseComponent(pt,size);
}
void CObjComponentMgr::AddBaseComponent(Dbxy pt,DbSize size)
{
CObjComponent Component(pt,size);
Component.SetBase(true);
m_BaseComponentVec.push_back(Component);
}
//添加一个普通原件
void CObjComponentMgr::AddComponent(CObjComponent Component)
{
m_ComponentVec.push_back(Component);
}
void CObjComponentMgr::InsertList(CListCtrl &List)
{
int size = m_BaseComponentVec.size();
for(int i=0;i<size;i++)
{
int idx = 0;
List.InsertItem(i," ");//插入一行
List.SetItemText(i,idx++,Int2CString(i+1));//序号
Dbxy pt = m_BaseComponentVec[i].GetBasePt();//基准点
List.SetItemText(i,idx++,Db2CString(pt.x));
List.SetItemText(i,idx++,Db2CString(pt.y));
DbSize size = m_BaseComponentVec[i].GetSize();//尺寸
List.SetItemText(i,idx++,Db2CString(size.w));
List.SetItemText(i,idx++,Db2CString(size.h));
}
}
//检查idx 是否有效
bool CObjComponentMgr::IdxValid(int idx)
{
int size = m_BaseComponentVec.size();
if(idx<0 || idx>= size)
return false;
return true;
}
void CObjComponentMgr::DelSel(int &idx)
{
if(!IdxValid(idx))
return;
vector<CObjComponent>::iterator iter = m_BaseComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_BaseComponentVec.end();
int i=0;
for(;iter!=iter_end;iter++)
{
if(i==idx)
{
m_BaseComponentVec.erase(iter);
idx = -1;
break;
}
i++;
}
}
//删除所有
void CObjComponentMgr::DelAll()
{
m_BaseComponentVec.clear();
m_ComponentVec.clear();
m_CatchPtVec.clear();
}
//操作idx 索引
void CObjComponentMgr::OpArea(int idx,CObjComponent &Area,bool bRead)
{
int size = m_BaseComponentVec.size();
for(int i=0;i<size;i++)
{
if(idx == i)
{
if(bRead)
{
Area = m_BaseComponentVec[i];
}
else
{
m_BaseComponentVec[i] = Area;
}
}
}
}
#endif
#if 1
//是否在限定范围内(Size 用来去除挂到边的obj)
bool CObjComponentMgr::IsInArea(Dbxy pt,DbSize Size)
{
if(!m_bUseArea)
return true;
if(!m_bNeedAllIn)
Size.w = Size.h = 0;
if(m_bRectArea)//矩形范围
{
DbRect rect(m_AreaBasePt,DbSize(m_AreaSize.w-Size.w,m_AreaSize.h-Size.h));
return IsPointInRect(pt,rect);
}
else//圆形
{
return CalDistance(m_AreaBasePt,pt)<(m_AreaRadius-Size.w/2);
}
}
//阵列元件
void CObjComponentMgr::Array()
{
m_ComponentVec.clear();
m_CatchPtVec.clear();
if(m_bAutoArray)//自动排布
{
AutoArray();
}
else
{
ArrayExt();
}
}
//自动排布
void CObjComponentMgr::AutoArray()
{
if(m_BaseComponentVec.empty())
return;
if(!m_bUseArea)
return;
//自动排布只取第一个
Dbxy BasePt = m_BaseComponentVec[0].GetBasePt();
DbSize Size = m_BaseComponentVec[0].GetSize();
bool bIsCircle = m_BaseComponentVec[0].IsCircle();
double OffsetX = (Size.w + m_AutoArrayGap)/2;
double OffsetY = GENG_3*OffsetX;
Dbxy Pt = BasePt;
while(1)//正向
{
if(AutoArrayExt(Pt,Size,OffsetX,OffsetY,bIsCircle)==false)
break;
Pt.x += (Size.w + m_AutoArrayGap);
}
Pt = BasePt;
Pt.x -= (Size.w + m_AutoArrayGap);
while(1)//负向
{
if(AutoArrayExt(Pt,Size,OffsetX,OffsetY,bIsCircle)==false)
break;
Pt.x -= (Size.w + m_AutoArrayGap);
}
}
//自动阵列
bool CObjComponentMgr::AutoArrayExt(Dbxy BasePt,DbSize Size,double OffsetX,double OffsetY,bool bIsCircle)
{
bool ret = false;//是否有范围内的obj
Dbxy Pt = BasePt;
for(int i=0;i<m_ArrayYcntZ;i++)//正向
{
if(IsInArea(Pt,Size))
{
CObjComponent Obj(Pt,Size);
Obj.SetIsCircle(bIsCircle);
m_ComponentVec.push_back(Obj);
ret = true;
}
Pt.x += OffsetX;
Pt.y += OffsetY;
}
Pt = BasePt;
Pt.x -= OffsetX;
Pt.y -= OffsetY;
for(int i=0;i<m_ArrayYcntF;i++)//负向
{
if(IsInArea(Pt,Size))
{
CObjComponent Obj(Pt,Size);
Obj.SetIsCircle(bIsCircle);
m_ComponentVec.push_back(Obj);
ret = true;
}
Pt.x -= OffsetX;
Pt.y -= OffsetY;
}
return ret;
}
//XY方向矩阵阵列
void CObjComponentMgr::ArrayExt()
{
//从右上角开始
int startX = m_ArrayXcntZ;
int endX = m_ArrayXcntF*(-1);
int startY = m_ArrayYcntZ;
int endY = m_ArrayYcntF*(-1);
Dbxy Offset;//整体偏移
Offset.x = (endX*m_OffsetX-startX*m_OffsetX)/2;
Offset.y = (endY*m_OffsetY-startY*m_OffsetY)/2;
Dbxy RealOffset;//整体偏移
RealOffset.x = (endX*m_RealOffsetX-startX*m_RealOffsetX)/2;
RealOffset.y = (endY*m_RealOffsetY-startY*m_RealOffsetY)/2;
for(int i = startX;i>=endX;i--)
{
for(int j = startY;j>=endY;j--)
{
//设置obj 的索引值
IntXY idx;
idx.x = (i-startX-1)*(-1);
idx.y = (j-startY-1)*(-1);
Arrayij(i,j,idx,Offset,RealOffset);
}
}
}
//第i 列第j 行(Offset 显示整体偏移,RealOffset 实际整体偏移)
void CObjComponentMgr::Arrayij(int i,int j,IntXY idx,Dbxy Offset,Dbxy RealOffset)
{
int size = m_BaseComponentVec.size();
for(int k=0;k<size;k++)
{
Dbxy BasePt = m_BaseComponentVec[k].GetBasePt();
DbSize Size = m_BaseComponentVec[k].GetSize();
bool bIsCircle = m_BaseComponentVec[k].IsCircle();
Dbxy RealBasePt = BasePt;//实际坐标
BasePt.x += m_OffsetX*i + Offset.x;
BasePt.y += m_OffsetY*j + Offset.y;
RealBasePt.x += m_RealOffsetX*i + RealOffset.x;
RealBasePt.y += m_RealOffsetY*j + RealOffset.y;
//检查是否在限定范围内
if(!IsInArea(BasePt,Size))
continue;
//创建新的obj
CObjComponent Obj(BasePt,Size);
Obj.SetRealBasePt(RealBasePt);
Obj.SetIsCircle(bIsCircle);
if(i==0 && j==0)//标记基准元件
{
Obj.SetBase(true);
}
Obj.SetIndex(idx);
m_ComponentVec.push_back(Obj);
if(k==0)//计算抓取用的交点,只计算一次
{
Dbxy pt(BasePt.x-m_OffsetX/2,BasePt.y-m_OffsetY/2);
m_CatchPtVec.push_back(pt);
}
}
}
//设置基准obj 的偏移
void CObjComponentMgr::SetBaseObjOffset(Dbxy Offset)
{
vector<CObjComponent>::iterator iter = m_BaseComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_BaseComponentVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).SetBasePt(Offset);
}
}
//在交叉点中找到离pt 最近的点
Dbxy CObjComponentMgr::FindNearestPt(Dbxy pt)
{
Dbxy NearestPt = pt;
double MinDis = -1;
vector<Dbxy>::iterator iter = m_CatchPtVec.begin();
vector<Dbxy>::iterator iter_end = m_CatchPtVec.end();
for(;iter!=iter_end;iter++)
{
double dis = CalDistance(pt,(*iter));
if(MinDis == -1 || dis < MinDis)
{
MinDis = dis;
NearestPt = (*iter);
}
}
return NearestPt;
}
#endif
#if 1
//通过layer 中的图形对象来创建obj 对象
void CObjComponentMgr::CreatObjByLayerObj()
{
m_ComponentVec.clear();
CLayer &Layer = gLayer;
CObjContainer &ObjContainer = Layer.GetObjContainer();
vector<Sptr<CObjBase>> &ObjVec = ObjContainer.GetObjVec();
vector<Sptr<CObjBase>>::iterator iter = ObjVec.begin();
vector<Sptr<CObjBase>>::iterator iter_end = ObjVec.end();
for(;iter!=iter_end;iter++)
{
DbRect rect = (*iter)->GetRect();
if(!m_bDrawBindingObj)//是否绘制绑定obj
{
(*iter)->SetbDraw(false);
}
(*iter)->SetSelected(false);
Dbxy pt = rect.GetCenterPt();
DbSize size = rect.GetSize();
double MinSize = 2;
if(size.w<MinSize)
size.w=MinSize;
if(size.h<MinSize)
size.h=MinSize;
double gap = 0.1;//范围比数据大一点
size.w += gap;
size.h += gap;
CObjComponent Obj(pt,size);
Obj.SetIsCircle(false);//方形
Obj.AddObjShape(*iter);//绑定layer obj 的数据
m_ComponentVec.push_back(Obj);
}
//锁定绑定的layer obj (防止编辑)
SetShapeLockState(true);
}
//从obj 中分析出两个定位mark 的位置(两个同心圆)
//直径小于R 的obj 被认为可能的mark 对象
void CObjComponentMgr::AnalyseMarkPt(double R)
{
vector<CObjComponent*> MarkVec;
//先找出半径小于R 的对象
{
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
DbSize Size = (*iter).GetSize();
if(Size.w<R && Size.h<R)
{
(*iter).NotCollect();//不要收集加工数据
MarkVec.push_back(&(*iter));
}
}
}
//分析出两个同心mark
int MarkCnt = 0;//找到mark 的数量
{
int size = MarkVec.size();
for(int i=0;i<size-1;i++)
{
if(MarkVec[i]->IsCollected())//避免重复
continue;
Dbxy pt1 = MarkVec[i]->GetBasePt();
for(int k=i+1;k<size;k++)
{
if(MarkVec[k]->IsCollected())//避免重复
continue;
Dbxy pt2 = MarkVec[k]->GetBasePt();
double dis = CalDistance(pt1,pt2);
if(dis<0.5)//匹配
{
MarkVec[k]->SetbMarkObj(true);//标记为mark
MarkVec[k]->SetbCollected(true);
MarkCnt++;//记录找到mark 的数量
break;
}
}
MarkVec[i]->SetbCollected(true);//标记
}
}
CString LogStr;
LogStr.Format(_T("func: AnalyseMarkPt---->[MarkCnt] = [%d]"),MarkCnt);
}
//获得基准对象的
DbSize CObjComponentMgr::GetBaseSize(int idx)
{
DbSize BaseSize;
int size = m_BaseComponentVec.size();
if(idx>=0 && idx<size)
{
BaseSize = m_BaseComponentVec[idx].GetSize();
}
return BaseSize;
}
bool CObjComponentMgr::IsBaseCircle(int idx)
{
bool ret = false;
int size = m_BaseComponentVec.size();
if(idx>=0 && idx<size)
{
ret = m_BaseComponentVec[idx].IsCircle();
}
return ret;
}
//重置元件的收集状态NeedSel 为true 表示选择的才收集
void CObjComponentMgr::ResetObjCollectState(bool NeedSel)
{
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).SetbCollected(false);
if(NeedSel && (*iter).IsSelected()==false)
{
(*iter).SetbCollected(true);//未选择的不要收集
}
}
}
//收集rect 范围内元件的工作数据
void CObjComponentMgr::CollectWorkData(DbRect &rect,vector<vector<Dbxy>> &vec,bool bNeedSel)
{
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
if(!bNeedSel || (bNeedSel && (*iter).IsSelected()))
{
(*iter).CollectWorkData(rect,vec);
}
}
}
//返回第一个基准obj 是否是圆形
bool CObjComponentMgr::IsCircle()
{
if(m_BaseComponentVec.empty())
return true;
return m_BaseComponentVec[0].IsCircle();
}
//设置第一个基准obj 是否为圆形
void CObjComponentMgr::SetIsCircle(bool b)
{
if(!m_BaseComponentVec.empty())
{
m_BaseComponentVec[0].SetIsCircle(b);
}
}
//通过obj 对象创建markarea
void CObjComponentMgr::CreatAreaByObj(CMarkAreaMgr &AreaMgr)
{
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
CMarkArea Area((*iter).GetBasePt(),(*iter).GetSize());
AreaMgr.AddArea(Area);
}
}
#endif
#if 1
//获取第一个选择的obj 的索引值
IntXY CObjComponentMgr::GetFristSelectedObjIdx()
{
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
if((*iter).IsSelected())
{
return (*iter).GetIndex();
}
}
IntXY idx(-1,-1);
return idx;
}
//索引编号转换为vector 的索引值(没有匹配返回-1)
int CObjComponentMgr::ConvertIdx(IntXY Idx)
{
int size = m_ComponentVec.size();
for(int i=0;i<size;i++)
{
if(m_ComponentVec[i].GetIndex() == Idx)
return i;
}
return -1;
}
//移动第一个选择的obj 到目标点TargetPt
void CObjComponentMgr::MoveFristSelObjToPt(Dbxy TargetPt)
{
//获取第一个选择obj 的索引
IntXY IdxXY = GetFristSelectedObjIdx();
//按索引移动
MoveObjToPtByIdx(IdxXY,TargetPt);
}
//设置当前观察的obj
void CObjComponentMgr::SetCurViewObjIdx(IntXY Idx)
{
m_CurSelObjIdx = Idx;
int size = m_ComponentVec.size();
for(int i=0;i<size;i++)
{
if(m_ComponentVec[i].GetIndex() == Idx)
{
m_ComponentVec[i].SetbView(true);
}
else
{
m_ComponentVec[i].SetbView(false);
}
}
}
//设置当前选择的obj
void CObjComponentMgr::SetCurSelObjIdx(IntXY Idx)
{
m_CurSelObjIdx = Idx;
int size = m_ComponentVec.size();
for(int i=0;i<size;i++)
{
if(m_ComponentVec[i].GetIndex() == Idx)
{
m_ComponentVec[i].SetSelected(true);
}
else
{
m_ComponentVec[i].SetSelected(false);
}
}
}
//通过索引值来移动obj (最终都是用这个函数来移动观察obj )
bool CObjComponentMgr::MoveObjToPtByIdx(IntXY IdxXY,Dbxy TargetPt)
{
//转换为容器索引
int idx = ConvertIdx(IdxXY);
if(idx>=0)
{
CString LogStr;
LogStr.Format(_T("Fuc:MoveSelObjToPt : Idx[X] = [%d] ,Idx[Y] = [%d]"),IdxXY.x,IdxXY.y);
gLogMgr->WriteDebugLog(LogStr);
//记录当前观察obj 的索引值
SetCurViewObjIdx(IdxXY);
//设置为已观察
m_ComponentVec[idx].SetbViewed(true);
return true;
}
return false;
}
//通过方向来移动obj 到指定点
void CObjComponentMgr::MoveObjToCameraByDir(DIRECTION dir,Dbxy TargetPt)
{
IntXY IdxXY = GetCurViewObjIdx();
if(dir == _DIR_R)
IdxXY.x--;
else if(dir == _DIR_L)
IdxXY.x++;
else if(dir == _DIR_U)
IdxXY.y--;
else if(dir == _DIR_D)
IdxXY.y++;
else if(dir == _DIR_M)
{
IdxXY.x = 1;
IdxXY.y = 1;
}
MoveObjToPtByIdx(IdxXY,TargetPt);
}
//按S 形轨迹来移动obj (bDir 向左或向右移动)
void CObjComponentMgr::MoveTrackS(Dbxy TargetPt,IntXY Gap,bool bDir)
{
IntXY IdxXY = GetCurViewObjIdx();
IntXY NewIdxXY = IdxXY;
if(m_bMoveTrackSDir)//向下
NewIdxXY.y += Gap.y;
else//向上
NewIdxXY.y -= Gap.y;
if(MoveObjToPtByIdx(NewIdxXY,TargetPt)==false)//到头了,横向移动
{
NewIdxXY.y = IdxXY.y;
if(bDir)//向左
NewIdxXY.x += Gap.x;
else//向右
NewIdxXY.x -= Gap.x;
if(MoveObjToPtByIdx(NewIdxXY,TargetPt))//横向移动
{
m_bMoveTrackSDir = !m_bMoveTrackSDir;//横向移动后Y 方向变向
}
}
}
#endif
#if 1
//LPS ISP3000 通过两颗die 的距离来将一个obj 分成两个(bDivideX 是分离方向)
void CObjComponentMgr::DivideBySpacingDis(double dis,bool bDivideX)
{
if(dis<0.001)
return;
vector<CObjComponent> ComponentVecTmp;//临时容器
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
ComponentVecTmp.push_back(CopyObj((*iter),-1,dis,bDivideX));
ComponentVecTmp.push_back(CopyObj((*iter),1,dis,bDivideX));
}
m_ComponentVec = ComponentVecTmp;
}
CObjComponent CObjComponentMgr::CopyObj(CObjComponent &Obj,int sign,double dis,bool bDivideX)
{
Dbxy BasePt = Obj.GetBasePt();//显示点
Dbxy RealBasePt = Obj.GetRealBasePt();//实际点
DbSize size = Obj.GetSize();//显示尺寸
IntXY Idx = Obj.GetIndex();
CObjComponent NewObj = Obj;
BasePt.x += (size.w/4)*(sign);
NewObj.SetBasePt(BasePt);
RealBasePt.x += (dis/2)*(sign);
NewObj.SetRealBasePt(RealBasePt);
size.w /= 2;
NewObj.SetSize(size);
Idx.x *=2;
if(sign==1)
Idx.x -= 1;
NewObj.SetIndex(Idx);
return NewObj;
}
//当前观察过的obj 的数量
int CObjComponentMgr::GetCurViewedObj()
{
int cnt = 0;
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
if((*iter).IsbViewed())
cnt++;
}
return cnt;
}
#endif
#if 1
//切换是否移动到ccd 的模式
bool CObjComponentMgr::SwithObjToCcdMode()
{
m_bObjToCcdMode = !m_bObjToCcdMode;
return m_bObjToCcdMode;
}
//获取第一个选择的obj 的中心点
Dbxy CObjComponentMgr::GetFristSelObjCenter()
{
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
if((*iter).IsSelected())
return (*iter).GetRealBasePt();
}
Dbxy pt;
return pt;
}
#endif
#if 1
//设置rect 区域内obj 的mark 状态(bSel 表示是否需要选择时设置)
//返回obj 的数据范围(用来调整markarea)
DbRect CObjComponentMgr::SetMarkedStateRect(DbRect AreaRect,bool bSel)
{
DbRect DataRect;//数据范围
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
if(bSel && !(*iter).IsSelected())
continue;
if(!(*iter).IsbMarked() && (*iter).IsInRect(AreaRect,true))
{
(*iter).SetbMarked(true);
AdjustRectByRect(DataRect,(*iter).GetRect());
}
}
return DataRect;
}
//重置所有obj 的加工状态
void CObjComponentMgr::ResetAllMarkedState()
{
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).SetbMarked(false);
}
}
//设置原件绑定layer obj 的锁定状态(用来删除)
void CObjComponentMgr::SetShapeLockState(bool b)
{
vector<CObjComponent>::iterator iter = m_ComponentVec.begin();
vector<CObjComponent>::iterator iter_end = m_ComponentVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).SetShapeLockState(b);
}
}
#endif