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.
TwoLaserHead-PushJig/LaiPuLaser/ProductMgr.cpp

859 lines
32 KiB
C++

#include "StdAfx.h"
#include "ProductMgr.h"
#include "Propertie.h"
#include "PropertieMgr.h"
#include "AuthorityMgr.h"
#include "GlobalFunction.h"
#include "CStringFuc.h"
#include "LogMgr.h"
#include "GlobalDrawMgr.h"
#include "DrawSimpleShape.h"
#include "ObjComponentMgr.h"
#include "PlatformXY.h"
#include "WorkFileMgr.h"
#include "ObjComponentMgr.h"
#include "Motor.h"
#include "Layer.h"
#include "CommandMgr.h"
#include "CameraHawkvis.h"
#include "MsgBox.h"
#include "ProgramCutMgr.h"
#define PRODUCT_STR _T("工件")
CProductMgr *gProductMgr = new CProductMgr;
CProductMgr::CProductMgr(void)
{
m_UseProductCnt = 1;//使用工件的数量
m_CurProductIdx = -1;//当前操作的工件索引值
m_CurWorkTimes = 0;//加工次数
m_TotalWorkTimes = 0;//总加工次数
m_FocalAdjustCnt = 0;//变焦次数
m_FocalAdjustDis = 0;//变焦距离mm
m_BaseFocAdjustDis = 0;//基准焦距距离mm
m_AngleAdjust = 0;//角度微调值
m_BasePtDir = _DIR_M;//产品基准点的方向
m_MaxMarkDisDiff = 0.3;//两个mark 点之间的实际距离和理论距离之间的最大差(用来避免识别误判)
}
CProductMgr::~CProductMgr(void)
{
}
#if 1//复写module 的函数
void CProductMgr::Ini()
{
ResetProductVec(m_UseProductCnt);
// GetFrame()->m_DlgCutDeviceCtrl.Update();
}
void CProductMgr::ResetProductVec(int cnt)
{
m_ProductVec.clear();
for(int i=0;i<cnt;i++)
{
CProduct Product;
m_ProductVec.push_back(Product);
}
}
CMFCPropertyGridProperty *CProductMgr::CreatGridProperty()
{
CPropertieMgr &PropertieMgr = gDevicePropertieMgr;
CString PropertyName;//属性名称
CString Description;//描述
CString Path = _T("Product");//存储路径
CString Name;
//-------------------------------------------------------------------------------//
PropertyName = _T("工件管理");
CMFCPropertyGridProperty* pGroup = new CMFCPropertyGridProperty(PropertyName);
//-------------------------------------------------------------------------------//
if(gAuthorityMgr->CheckAuthority(_FACTORY))
{
{
//添加属性变量映射
Name = _T("m_UseProductCnt");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_UseProductCnt);
pPropertie->SetType(_PROP_TYPE_INT);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("工件数量");
Description = _T("当前夹具支持工件的数量,修改后重启软件生效");
CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_UseProductCnt, Description);
//p->AllowEdit(FALSE);//不可修改
pGroup->AddSubItem(p);
PropertieMgr.Insert(p, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_ProductSize_w");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_ProductSize.w);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("工件宽度");
Description = _T("当前夹具工件的尺寸宽度mm");
CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_ProductSize.w, Description);
//p->AllowEdit(FALSE);//不可修改
pGroup->AddSubItem(p);
PropertieMgr.Insert(p, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_ProductSize_h");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_ProductSize.h);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("工件高度");
Description = _T("当前夹具工件的尺寸高度mm");
CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_ProductSize.h, Description);
//p->AllowEdit(FALSE);//不可修改
pGroup->AddSubItem(p);
PropertieMgr.Insert(p, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_TotalWorkTimes");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_TotalWorkTimes);
pPropertie->SetType(_PROP_TYPE_INT);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("总加工次数");
Description = _T("当前总共的加工次数");
CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_TotalWorkTimes, Description);
//p->AllowEdit(FALSE);//不可修改
pGroup->AddSubItem(p);
PropertieMgr.Insert(p, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_AngleAdjust");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_AngleAdjust);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("角度微调");
Description = _T("产品偏移角度的微调值(弧度值)");
CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_AngleAdjust, Description);
//p->AllowEdit(FALSE);//不可修改
pGroup->AddSubItem(p);
PropertieMgr.Insert(p, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_MaxMarkDisDiff");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_MaxMarkDisDiff);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("mark间距最大误差");
Description = _T("两个mark 点之间的实际距离和理论距离之间的最大差(单位:mm)");
CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_MaxMarkDisDiff, Description);
//p->AllowEdit(FALSE);//不可修改
pGroup->AddSubItem(p);
PropertieMgr.Insert(p, pPropertie);
}
{
PropertyName = _T("焦距管理");
CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(PropertyName);
{
//添加属性变量映射
Name = _T("m_BaseFocAdjustDis");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_BaseFocAdjustDis);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("基准焦距");
Description = _T("设备初始化后焦点的调整距离(单位:mm)");
CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_BaseFocAdjustDis, Description);
pGroup1->AddSubItem(p);
PropertieMgr.Insert(p, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_FocalAdjustCnt");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_FocalAdjustCnt);
pPropertie->SetType(_PROP_TYPE_INT);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("变焦次数");
Description = _T("用于比较厚的产品,加工一次调整焦距,再次加工");
CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_FocalAdjustCnt, Description);
p->AllowEdit(FALSE);//不可修改
pGroup1->AddSubItem(p);
PropertieMgr.Insert(p, pPropertie);
}
{
//添加属性变量映射
Name = _T("m_FocalAdjustDis");//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&m_FocalAdjustDis);
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("变焦距离");
Description = _T("对应变焦次数每次焦距调整的距离,向上为正,向下为负(单位:mm)");
CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_FocalAdjustDis, Description);
pGroup1->AddSubItem(p);
PropertieMgr.Insert(p, pPropertie);
}
pGroup->AddSubItem(pGroup1);
}
{
PropertyName = _T("理论定位点");
CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(PropertyName);
{
//添加属性变量映射
Name = "m_TheoryMarkPt1_x";//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&(m_TheoryMarkPt1.x));
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
//添加属性显示
PropertyName = _T("mark1坐标X");
Description = _T("理论mark 点1坐标X(自动)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_TheoryMarkPt1.x, Description);
p1->AllowEdit(FALSE);//不可修改
pGroup1->AddSubItem(p1);
PropertieMgr.Insert(p1, pPropertie);
}
{
//添加属性变量映射
Name = "m_TheoryMarkPt1_y";//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&(m_TheoryMarkPt1.y));
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
//添加属性显示
PropertyName = _T("mark1坐标Y");
Description = _T("理论mark 点1坐标Y(自动)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_TheoryMarkPt1.y, Description);
p1->AllowEdit(FALSE);//不可修改
pGroup1->AddSubItem(p1);
PropertieMgr.Insert(p1, pPropertie);
}
{
//添加属性变量映射
Name = "m_TheoryMarkPt2_x";//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&(m_TheoryMarkPt2.x));
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
//添加属性显示
PropertyName = _T("mark2坐标X");
Description = _T("理论mark 点2坐标X(自动)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_TheoryMarkPt2.x, Description);
p1->AllowEdit(FALSE);//不可修改
pGroup1->AddSubItem(p1);
PropertieMgr.Insert(p1, pPropertie);
}
{
//添加属性变量映射
Name = "m_TheoryMarkPt2_y";//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&(m_TheoryMarkPt2.y));
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
//添加属性显示
PropertyName = _T("mark2坐标Y");
Description = _T("理论mark 点2坐标Y(自动)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_TheoryMarkPt2.y, Description);
p1->AllowEdit(FALSE);//不可修改
pGroup1->AddSubItem(p1);
PropertieMgr.Insert(p1, pPropertie);
}
pGroup->AddSubItem(pGroup1);
}
int size = m_ProductVec.size();
for(int i=0;i<size;i++)
{
CString Idx;
Idx.Format("%ld",i+1);
PropertyName = "工件" + Idx;
CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(PropertyName);
{
//添加属性变量映射
Name = "m_ProductVec_bUsed" + Idx;//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&(m_ProductVec[i].m_bUsed));
pPropertie->SetType(_PROP_TYPE_BOOL);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("基准坐标X");
Description = _T("工件中心相对于平台原点的坐标X (mm)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)m_ProductVec[i].m_bUsed, Description);
pGroup1->AddSubItem(p1);
PropertieMgr.Insert(p1, pPropertie);
}
Dbxy &BasePt = m_ProductVec[i].GetProductBasePt();
{
//添加属性变量映射
Name = "m_ProductVec_X" + Idx;//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&(BasePt.x));
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("基准坐标X");
Description = _T("工件中心相对于平台原点的坐标X (mm)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)BasePt.x, Description);
pGroup1->AddSubItem(p1);
PropertieMgr.Insert(p1, pPropertie);
}
{
//添加属性变量映射
Name = "m_ProductVec_Y" + Idx;//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&(BasePt.y));
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
pPropertie->SetPath(Path);
pPropertie->SetName(Name);
pPropertie->WriteRead(true);//读取保存的属性
//添加属性显示
PropertyName = _T("基准坐标Y");
Description = _T("工件中心相对于平台原点的坐标Y (mm)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)BasePt.y, Description);
pGroup1->AddSubItem(p1);
PropertieMgr.Insert(p1, pPropertie);
}
Dbxy &Offset = m_ProductVec[i].GetOffset();
{
//添加属性变量映射
Name = "m_Offset_X" + Idx;//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&(Offset.x));
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
//添加属性显示
PropertyName = _T("偏移X");
Description = _T("工件实际的偏移位置X (mm)(自动)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)Offset.x, Description);
p1->AllowEdit(FALSE);//不可修改
pGroup1->AddSubItem(p1);
PropertieMgr.Insert(p1, pPropertie);
}
{
//添加属性变量映射
Name = "m_Offset_Y" + Idx;//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&(Offset.y));
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
//添加属性显示
PropertyName = _T("偏移Y");
Description = _T("工件实际的偏移位置Y (mm)(自动)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)Offset.y, Description);
p1->AllowEdit(FALSE);//不可修改
pGroup1->AddSubItem(p1);
PropertieMgr.Insert(p1, pPropertie);
}
double Angle = m_ProductVec[i].GetRotateAng();
{
//添加属性变量映射
Name = "m_Angle_Y" + Idx;//变量名字
CPropertie *pPropertie = new CPropertie;
pPropertie->SetpVal((void*)&(Angle));
pPropertie->SetType(_PROP_TYPE_DOUBLE);
pPropertie->SetpModule(this);
//添加属性显示
PropertyName = _T("旋转角度");
Description = _T("工件实际的旋转角度(自动)");
CMFCPropertyGridProperty* p1 = new CMFCPropertyGridProperty(PropertyName,(_variant_t)Angle, Description);
p1->AllowEdit(FALSE);//不可修改
pGroup1->AddSubItem(p1);
PropertieMgr.Insert(p1, pPropertie);
}
pGroup->AddSubItem(pGroup1);
}
}
return pGroup;
}
void CProductMgr::InsertProduct(CMFCPropertyGridProperty* p)
{
for(int i=0;i<m_UseProductCnt;i++)
{
CString Idx;
Idx.Format("%ld",i+1);
CString str = "工件" + Idx;
p->AddOption(str);
}
}
void CProductMgr::ExportPar(ofstream *pFile)
{
(*pFile)<<"[模块] [CProductMgr]------------------------------------------------"<<endl;
}
#endif
#if 1
void CProductMgr::WriteWorkFileExt(vector<CLab> &LabVec)
{
//读取也要按照这个顺序
LabVec.push_back(CLab(LAB_NULL,m_TheoryMarkPt1.x));
LabVec.push_back(CLab(LAB_NULL,m_TheoryMarkPt1.y));
LabVec.push_back(CLab(LAB_NULL,m_TheoryMarkPt2.x));
LabVec.push_back(CLab(LAB_NULL,m_TheoryMarkPt2.y));
LabVec.push_back(CLab(LAB_NULL,m_BaseFocAdjustDis));
LabVec.push_back(CLab(LAB_NULL,m_FocalAdjustCnt));
LabVec.push_back(CLab(LAB_NULL,m_FocalAdjustDis));
LabVec.push_back(CLab(LAB_NULL,m_UseProductCnt));
for(int i=0;i<m_UseProductCnt;i++)
{
LabVec.push_back(CLab(LAB_PRODUCT_START));
m_ProductVec[i].WriteWorkFile(LabVec);
LabVec.push_back(CLab(LAB_PRODUCT_END));
}
}
void CProductMgr::ReadWorkFile(CLabVecRang &LabVecRang)
{
int idx = LabVecRang.GetStart()+1;
m_TheoryMarkPt1.x = LabVecRang.GetDouble(idx++);
m_TheoryMarkPt1.y = LabVecRang.GetDouble(idx++);
m_TheoryMarkPt2.x = LabVecRang.GetDouble(idx++);
m_TheoryMarkPt2.y = LabVecRang.GetDouble(idx++);
SetTheoryMarkPt(m_TheoryMarkPt1,m_TheoryMarkPt2);
m_BaseFocAdjustDis = LabVecRang.GetDouble(idx++);
m_FocalAdjustCnt = LabVecRang.GetInt(idx++);
m_FocalAdjustDis = LabVecRang.GetDouble(idx++);
m_UseProductCnt = LabVecRang.GetInt(idx++);
ResetProductVec(m_UseProductCnt);
vector<CLabVecRang> LabVecRangVec;
CWorkFileMgr WorkFileMgr;
WorkFileMgr.SeparateStrVec(LabVecRang,LabVecRangVec,LAB_PRODUCT_START,LAB_PRODUCT_END);
//处理每个模板
if(!LabVecRangVec.empty())
{
size_t size = LabVecRangVec.size();
for(size_t i=0;i<size;i++)
{
m_ProductVec[i].ReadWorkFile(LabVecRangVec[i]);
}
}
}
#endif
#if 1
//绘制定位点
void CProductMgr::DrawMarkPoint(CDC* pDC,Dbxy pt,CString str)
{
if(!IsDbxyZero(pt))
{
DbRect Rect(pt,gDraw->GetCatchNodeSize());
DrawCrossX(pDC,gDraw->GetMarkPointPen(),Rect);
gDraw->DrawTxt(pDC,str,pt);
}
}
void CProductMgr::Draw(CDC* pDC)
{
}
DbRect CProductMgr::GetRect(Dbxy pt)
{
DbRect rect;
switch(m_BasePtDir)
{
case _DIR_M:
rect.L = pt.x - m_ProductSize.w/2;
rect.T = pt.y + m_ProductSize.h/2;
rect.R = pt.x + m_ProductSize.w/2;
rect.B = pt.y - m_ProductSize.h/2;
break;
case _DIR_LT:
rect.L = pt.x;
rect.T = pt.y;
rect.R = pt.x + m_ProductSize.w;
rect.B = pt.y - m_ProductSize.h;
break;
case _DIR_LB:
rect.L = pt.x;
rect.B = pt.y;
rect.R = pt.x + m_ProductSize.w;
rect.T = pt.y + m_ProductSize.h;
break;
case _DIR_RT:
rect.R = pt.x;
rect.T = pt.y;
rect.L = pt.x - m_ProductSize.w;
rect.B = pt.y - m_ProductSize.h;
break;
case _DIR_RB:
rect.R = pt.x;
rect.B = pt.y;
rect.L = pt.x - m_ProductSize.w;
rect.T = pt.y + m_ProductSize.h;
break;
default:
break;
}
return rect;
}
#endif
#if 1
//重置理论定位点坐标
void CProductMgr::ReSetTheoryMarkPt()
{
m_TheoryMarkPt1.x = 0;
m_TheoryMarkPt1.y = 0;
m_TheoryMarkPt2.x = 0;
m_TheoryMarkPt2.y = 0;
for(int i=0;i<m_UseProductCnt;i++)
{
m_ProductVec[i].SetTheoryMarkPt(m_TheoryMarkPt1,m_TheoryMarkPt2);
}
}
//设置定位点理论坐标
void CProductMgr::SetTheoryMarkPt(Dbxy pt1,Dbxy pt2)
{
if(pt1.x>pt2.x)//保证定位点1 在左边
{
SwapTwoPt(pt1,pt2);
}
m_TheoryMarkPt1 = pt1;
m_TheoryMarkPt2 = pt2;
for(int i=0;i<m_UseProductCnt;i++)
{
m_ProductVec[i].SetTheoryMarkPt(pt1,pt2);
}
}
Dbxy CProductMgr::TheoryPtToRealPt(Dbxy TheoryMarkPt)
{
return m_ProductVec[m_CurProductIdx].TheoryPtToRealPt(TheoryMarkPt);
}
//理论数据转换为实际数据
void CProductMgr::TheoryDataToRealData(vector<vector<Dbxy>> &vec,Dbxy &Offset)
{
vector<vector<Dbxy>>::iterator iter = vec.begin();
vector<vector<Dbxy>>::iterator iter_end = vec.end();
for(;iter!=iter_end;iter++)
{
TheoryDataToRealData(*iter,Offset);
}
}
//理论数据转换为实际数据
void CProductMgr::TheoryDataToRealData(vector<Dbxy> &vec,Dbxy &Offset)
{
vector<Dbxy>::iterator iter = vec.begin();
vector<Dbxy>::iterator iter_end = vec.end();
for(;iter!=iter_end;iter++)
{
(*iter) = TheoryPtToRealPt((*iter));
(*iter).x += Offset.x;
(*iter).y += Offset.y;
}
}
#endif
//获取当前使用的product 的数量
int CProductMgr::GetUsedProductCnt()
{
int cnt = 0;
for(int i=0;i<m_UseProductCnt;i++)
{
if(m_ProductVec[i].IsUsed())
cnt++;
}
return cnt;
}
void CProductMgr::ResetRealMarkPt()
{
vector<CProduct>::iterator iter = m_ProductVec.begin();
vector<CProduct>::iterator iter_end = m_ProductVec.end();
for(;iter!=iter_end;iter++)
{
(*iter).ResetRealMarkPt();
}
}
//加工次数增加
void CProductMgr::WorkTimesInc()
{
m_CurWorkTimes++;//加工次数
m_TotalWorkTimes++;//总加工次数
}
//移动obj 到夹具的基准点
void CProductMgr::MoveObjToBasePt(Dbxy BasePt)
{
int size = m_ProductVec.size();
if(size<=0)
return;
//获取所有obj 的rect
CLayer &layer = GetLayerInstance();
CObjContainer &ObjContainer = layer.GetObjContainer();
ObjContainer.SelAllObj();
DbRect rect = ObjContainer.GetSelObjRect();
//移动要区分方向
Dbxy MovePt;
switch(m_BasePtDir)
{
case _DIR_M:
MovePt.x = (rect.R+rect.L)/2;
MovePt.y = (rect.T+rect.B)/2;
break;
case _DIR_LT:
MovePt.x = rect.L;
MovePt.y = rect.T;
break;
case _DIR_LB:
MovePt.x = rect.L;
MovePt.y = rect.B;
break;
case _DIR_RT:
MovePt.x = rect.R;
MovePt.y = rect.T;
break;
case _DIR_RB:
MovePt.x = rect.R;
MovePt.y = rect.B;
break;
default:
break;
}
Dbxy Offset;
Offset.x = BasePt.x - MovePt.x;
Offset.y = BasePt.y - MovePt.y;
//移动
layer.OnMove(Offset.x,Offset.y,true);
gObjComponentMgr->OnMove(Offset);
CString s;
s.Format(_T("Move Obj [Offset_x]= %f,[Offset_y]= %f"),Offset.x,Offset.y);
gLogMgr->WriteDebugLog(s);
gCommandMgr.DelAllCmd();//删除所有指令
}
//当前操作的product 索引值
int CProductMgr::GetCurProductIdx()
{
int size = m_ProductVec.size();
if(m_CurProductIdx>=0 && m_CurProductIdx<size)
return m_CurProductIdx;
return -1;
}
//更新product 的状态(标记最后一个product)
void CProductMgr::UpdateProductState()
{
gLogMgr->WriteDebugLog("CProductMgr::UpdateProductState");
int size = m_ProductVec.size();
int LastIdx = -1;
for(int k=0;k<size;k++)
{
m_ProductVec[k].SetbLastOne(false);
if(m_ProductVec[k].IsUsed())//使用的product 才标记
LastIdx = k;
}
if(LastIdx>=0)
m_ProductVec[LastIdx].SetbLastOne(true);
}
//获取默认的基础位置
Dbxy CProductMgr::GetDefualtBasePt()
{
Dbxy pt;
switch(m_BasePtDir)
{
case _DIR_M:
pt.x = (m_DefualtRect.R+m_DefualtRect.L)/2;
pt.y = (m_DefualtRect.T+m_DefualtRect.B)/2;
break;
case _DIR_LT:
pt.x = m_DefualtRect.L;
pt.y = m_DefualtRect.T;
break;
case _DIR_LB:
pt.x = m_DefualtRect.L;
pt.y = m_DefualtRect.B;
break;
case _DIR_RT:
pt.x = m_DefualtRect.R;
pt.y = m_DefualtRect.T;
break;
case _DIR_RB:
pt.x = m_DefualtRect.R;
pt.y = m_DefualtRect.B;
break;
default:
break;
}
return pt;
}
#if 1
//通过设置product的中心点来控制默认抓取偏移
//mark 1移动到CCD 中心,然后点调整
void CProductMgr::SetProductCenterPt()
{
//当前实际的坐标值
Dbxy CurPlatCoord = gPlatformXY->GetCoord();
CProduct &Product = m_ProductVec[0];
bool bETrackType_Track_2 = (CurPlatCoord.y>200);//在X2 轴上调整
//将数据移动到当前product 的基准点上
Dbxy CurBasePt = Product.GetProductBasePt();
if(bETrackType_Track_2)
{
Dbxy Track2Offset = gProgram_SZ_XL->GetTrack2Offset();
CurBasePt.x += Track2Offset.x;
CurBasePt.y += Track2Offset.y;
}
gProgramCutMgr->MoveObjData(CurBasePt);
Dbxy MarkPt1;
Dbxy MarkPt2;
if(gObjComponentMgr->GetTwoMarkPt(MarkPt1,MarkPt2)==false)
{
CMsgBox MsgBox;
MsgBox.Show("没有指定定位点!");
return;
}
CCamera &Camera = *gCameraHawkvis;
Dbxy CameraPt = Camera.GetCenterPt();
Dbxy PlatCoord;//MarkPt1 移到Camera 的理论坐标值
PlatCoord.x = CameraPt.x - MarkPt1.x;
PlatCoord.y = MarkPt1.y - CameraPt.y;
Dbxy Offset;//移动偏移量
Offset.x = PlatCoord.x - CurPlatCoord.x;
Offset.y = CurPlatCoord.y - PlatCoord.y;
CurBasePt.x += Offset.x;
CurBasePt.y += Offset.y;
if(bETrackType_Track_2)//按轨道1 来设置
{
Dbxy Track2Offset = gProgram_SZ_XL->GetTrack2Offset();
CurBasePt.x -= Track2Offset.x;
CurBasePt.y -= Track2Offset.y;
}
Product.SetBasePt(CurBasePt);
gDevicePropertieMgr.SaveAllPropertie();
CMsgBox MsgBox;
MsgBox.Show("位置调整完成!");
}
//通过设置product的中心点来控制默认抓取偏移
//mark 1移动到CCD 中心,然后点调整
void CProductMgr::SetCamCoord()
{
Dbxy MarkPt1;
Dbxy MarkPt2;
if (gObjComponentMgr->GetTwoMarkPt(MarkPt1, MarkPt2) == false)
{
CMsgBox MsgBox;
MsgBox.Show("没有定位点1!");
return;
}
//当前实际的坐标值
Dbxy CurPlatCoord = gPlatformXY->GetCoord();
CProduct &Product = m_ProductVec[0];
bool bETrackType_Track_2 = (CurPlatCoord.y > 200);//在X2 轴上调整
//将数据移动到当前product 的基准点上
//Dbxy CurBasePt = Product.GetProductBasePt();
if (bETrackType_Track_2)
{
Dbxy Track2Offset = gProgram_SZ_XL->GetTrack2Offset();
CurPlatCoord.x -= Track2Offset.x;
CurPlatCoord.y -= Track2Offset.y;
}
//gProgramCutMgr->MoveObjData(CurBasePt);
CCamera &Camera = *gCameraHawkvis;
Dbxy CameraPt;// = Camera.GetCoord();
CameraPt.x = CurPlatCoord.x + MarkPt1.x;
CameraPt.y =MarkPt1.y- CurPlatCoord.y;
Camera.SetCoord(CameraPt);
/*Dbxy PlatCoord;//MarkPt1 移到Camera 的理论坐标值
PlatCoord.x = CameraPt.x - MarkPt1.x;
PlatCoord.y = MarkPt1.y - CameraPt.y;
Dbxy Offset;//移动偏移量
Offset.x = PlatCoord.x - CurPlatCoord.x;
Offset.y = CurPlatCoord.y - PlatCoord.y;
CurBasePt.x += Offset.x;
CurBasePt.y += Offset.y;
if (bETrackType_Track_2)//按轨道1 来设置
{
Dbxy Track2Offset = gProgram_SZ_XL->GetTrack2Offset();
CurBasePt.x -= Track2Offset.x;
CurBasePt.y -= Track2Offset.y;
}
Product.SetBasePt(CurBasePt);*/
gDevicePropertieMgr.SaveAllPropertie();
CMsgBox MsgBox;
MsgBox.Show("位置调整完成!");
}
#endif