#include "stdafx.h" #include "LaiPuLaser.h" #include "DlgCutDeviceCtrl.h" #include "afxdialogex.h" #include "MsgBox.h" #include "AuthorityMgr.h" #include "DlgAuthorityMgr.h" #include "ProgramCutMgr.h" #include "CommonFlowMgr.h" #include "ProgramCutMgr.h" #include "PlatformXY.h" #include "ProductMgr.h" #include "LaserDeviceMgr.h" #include "MarkParMgr.h" #include "PropertieMgr.h" #include "Propertie.h" #include "WorkTime.h" #include "MsgBox.h" #include "EncryptionMgr.h" #include "PciCh365Mgr.h" #include "CStringFuc.h" #include "WorkCmdContainer.h" #include "MarkAreaMgr.h" //#include "SuperDogMgr.h" #include "ObjComponentMgr.h" IMPLEMENT_DYNAMIC(DlgCutDeviceCtrl, CDialogEx) BEGIN_MESSAGE_MAP(DlgCutDeviceCtrl, CDialogEx) ON_WM_TIMER() ON_BN_CLICKED(IDC_INI_DEVICE_BTN, &DlgCutDeviceCtrl::OnBnClickedIniDeviceBtn) ON_BN_CLICKED(IDC_OPEN_DXF, &DlgCutDeviceCtrl::OnBnClickedOpenDxfWorkFile) ON_BN_CLICKED(IDC_START_WORK, &DlgCutDeviceCtrl::OnBnClickedStartWork) ON_BN_CLICKED(IDC_BOOL_SEL_MARK, &DlgCutDeviceCtrl::OnBnClickedSelectedMark) ON_BN_CLICKED(IDC_SAVE_PAR, &DlgCutDeviceCtrl::OnBnClickedSavePar) ON_BN_CLICKED(IDC_OPEN_MAK, &DlgCutDeviceCtrl::OnBnClickedOpenMarkFile) ON_BN_CLICKED(IDC_PRODUCT_1, &DlgCutDeviceCtrl::OnBnClickedProduct1) ON_BN_CLICKED(IDC_PRODUCT_2, &DlgCutDeviceCtrl::OnBnClickedProduct2) ON_BN_CLICKED(IDC_PRODUCT_3, &DlgCutDeviceCtrl::OnBnClickedProduct3) ON_BN_CLICKED(IDC_PRODUCT_4, &DlgCutDeviceCtrl::OnBnClickedProduct4) ON_BN_CLICKED(IDC_ADJUST_PRODUCT_POS, &DlgCutDeviceCtrl::OnBnClickedAdjustProductPos) END_MESSAGE_MAP() #define WORK_TIMER1 1 #define WORK_TIME_DELAY1 200 #define WORK_TIMER2 2 #define WORK_TIME_DELAY2 200 #define WORK_TIMER3 3 #define WORK_TIME_DELAY3 200 #define WORK_TIMER5 5 #define WORK_TIME_DELAY5 200 #define LASER_INFO_TIMER 6 #define LASER_INFO_TIMER_DELAY5 500 bool gbSelMark = false; DlgCutDeviceCtrl::DlgCutDeviceCtrl(CWnd* pParent /*=NULL*/) { m_LaserPower = 7.5;//电流值 m_LaserFre = 50000; m_LaserSpeed =300; m_CutCount = 1;//切割次数 m_MarkAreaCutCount = 1; m_RotatoAdjust = 0;//旋转调整mm m_CurWorkStep = 0; m_CurProductIdx = -1;//当前操作的 } DlgCutDeviceCtrl::~DlgCutDeviceCtrl() { m_CurWorkStep = 0; } void DlgCutDeviceCtrl::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_OPEN_DXF, m_ReadDxfBtn); DDX_Control(pDX, IDC_INI_DEVICE_BTN, m_IniDeviceBtn); DDX_Control(pDX, IDC_START_WORK, m_StartWorkBtn); DDX_Control(pDX, IDC_BOOL_SEL_MARK, m_SelMarkBtn); DDX_Control(pDX, IDC_SAVE_PAR, m_SaveParBtn); DDX_Control(pDX, IDC_OPEN_MAK, m_ReadMarkBtn); DDX_Control(pDX, IDC_SAVE_MAK, m_SaveMarkBtn); DDX_Control(pDX, IDC_PRODUCT_1, m_ProductBtn1); DDX_Control(pDX, IDC_PRODUCT_2, m_ProductBtn2); DDX_Control(pDX, IDC_PRODUCT_3, m_ProductBtn3); DDX_Control(pDX, IDC_PRODUCT_4, m_ProductBtn4); DDX_Control(pDX, IDC_ADJUST_PRODUCT_POS, m_AdjustProductPosBtn); DDX_Text(pDX, IDC_LAESR_DIODE, m_LaserPower); DDX_Text(pDX, IDC_LASER_FRE, m_LaserFre); DDX_Text(pDX, IDC_CUT_SPEED, m_LaserSpeed); DDX_Text(pDX, IDC_CUT_CNT, m_CutCount); DDX_Text(pDX, IDC_SIZE_ADJUST, m_SizeAdjust.x); DDX_Text(pDX, IDC_SIZE_ADJUSTY, m_SizeAdjust.y); DDX_Text(pDX, IDC_CUR_WORK_TIME, m_CurWorkTimes); DDX_Text(pDX, IDC_TOTAL_WORK_TIME, m_TotalWorkTimes); DDX_Text(pDX, IDC_WORK_TIME, m_WorkTime); DDX_Text(pDX, IDC_POS_ADJUSTX, m_OffsetAdjust.x); DDX_Text(pDX, IDC_POS_ADJUSTY, m_OffsetAdjust.y); DDX_Text(pDX, IDC_AREA_CUT_CNT, m_MarkAreaCutCount); DDX_Text(pDX, IDC_ROTATO_ADJUST, m_RotatoAdjust); } BOOL DlgCutDeviceCtrl::OnInitDialog() { CDialogEx::OnInitDialog(); m_IniDeviceBtn.SetUpColor(RGB_RED); m_EndInspectionBtn.SetUpColor(RGB_BLUE1); m_SelMarkBtn.SetUpColor(RGB_GRAY1); m_StartWorkBtn.SetUpColor(RGB_GREEN); m_AdjustProductPosBtn.SetUpColor(RGB_PINK); UpdateInfo(); //SetTimer(WORK_TIMER3,WORK_TIME_DELAY3,NULL); //SetTimer(LASER_INFO_TIMER,LASER_INFO_TIMER_DELAY5,NULL); UpdateData(FALSE); return TRUE; } #if 1 //观察平台坐标的变化 void DlgCutDeviceCtrl::UpdateInfo() { m_CurWorkTimes = gProductMgr->GetCurWorkTimes(); m_TotalWorkTimes = gProductMgr->GetTotalWorkTimes(); m_WorkTime = gWorkTime.GetTimeSpanStr(); m_OffsetAdjust = gCommonFlowMgr->GetAdjustOffset(); m_SizeAdjust = gCommonFlowMgr->GetAdjustSize(); m_RotatoAdjust = gCommonFlowMgr->GetRotatoAdjust();//旋转调整 m_MarkAreaCutCount = gCommonFlowMgr->GetAreaCycleCnt(); UpdateData(FALSE); } void DlgCutDeviceCtrl::Update() { SetTimer(WORK_TIMER1,WORK_TIME_DELAY1,NULL);//用timer来更新,否则会报错 } void DlgCutDeviceCtrl::OnTimer(UINT nIDEvent) { if(nIDEvent == WORK_TIMER1) { UpdateInfo(); KillTimer(WORK_TIMER1); } if(nIDEvent == WORK_TIMER2)//启动加工 { KillTimer(WORK_TIMER2); AutoWork(); } if(nIDEvent == WORK_TIMER3)//检查是否需要加工 { SetProductBtnState(); CheckStartState(); } if(nIDEvent == WORK_TIMER5)//重复启动加工 { KillTimer(WORK_TIMER5); OnBnClickedStartWork(); } if(nIDEvent == LASER_INFO_TIMER)//检测激光参数 { #ifdef __READ_LASER_DEVICE_INFO__ //更新激光参数 UpdateLaserParInfo(); #endif } CDialog::OnTimer(nIDEvent); } #endif #if 1 void DlgCutDeviceCtrl::OnBnClickedIniDeviceBtn() { if(gAuthorityMgr->CheckAuthority(_USER,true)==false) return; if(gProgramCutMgr->InitDevice()) { m_IniDeviceBtn.SetUpColor(RGB_GREEN); } else { m_IniDeviceBtn.SetUpColor(RGB_RED); } m_IniDeviceBtn.Refreash(); } #endif #if 1 //打开dxf 文件--并创建加工原件 void DlgCutDeviceCtrl::OnBnClickedOpenDxfWorkFile() { if(gAuthorityMgr->CheckAuthority(_USER,true)==false) return; OpenWorkFile(true); } void DlgCutDeviceCtrl::OnBnClickedOpenMarkFile() { if(gAuthorityMgr->CheckAuthority(_USER,true)==false) return; OpenWorkFile(false); } void DlgCutDeviceCtrl::OpenWorkFile(bool bDxf) { if(gAuthorityMgr->CheckAuthority(_USER,true)==false) return; //打开 gProgramCutMgr->OpenWorkFile(bDxf); //读取文件名对应的加工参数文件 gProgramCutMgr->ReadWorkParFile(); gDevicePropertieMgr.SaveAllPropertie(); //设置参数,更新显示 SetPar(); //重新搜集数据源 //gProgramCutMgr->CollectSrcWorkData(); UpdateInfo(); } #endif #if 1 void DlgCutDeviceCtrl::SetProductBtnState() { vector &ProductVec = gProductMgr->GetProductVec(); int size = ProductVec.size(); for(int k=0;k &ProductVec = gProductMgr->GetProductVec(); int size = ProductVec.size(); if(size>idx) { bool b = ProductVec[idx].IsUsed(); ProductVec[idx].SetUsed(!b); SetProductBtnState(); gDevicePropertieMgr.SaveAllPropertie(); int ProductCnt = gProductMgr->GetUsedProductCnt(); if(ProductCnt == 1) { int size = ProductVec.size(); for(int i=0;iMoveObjData(CurBasePt); break; } } } GetCurViewPtr()->RefreshView(); } } //调整产品的抓取偏移位置 void DlgCutDeviceCtrl::OnBnClickedAdjustProductPos() { CMsgBox MsgBox; if(MsgBox.ConfirmOkCancel("调整抓取偏移位置?")==false) return; gProductMgr->SetProductCenterPt(); //保存加工参数 gProgramCutMgr->SaveWorkParFile(); } #endif #if 1 //选择加工 void DlgCutDeviceCtrl::OnBnClickedSelectedMark() { if(gAuthorityMgr->CheckAuthority(_USER,true)==false) return; gbSelMark = !gbSelMark; if(gbSelMark) m_SelMarkBtn.SetUpColor(RGB_YELLOW); else m_SelMarkBtn.SetUpColor(RGB_GRAY1); } //开始工作 void DlgCutDeviceCtrl::OnBnClickedStartWork() { if(gEncryptionMgr->CheckLockState()==false) { CMsgBox MsgBox; MsgBox.Show("设备使用授权有问题 ,请联系供应商!"); return; } if(gAuthorityMgr->CheckAuthority(_USER,true)==false) return; //避免重复启动 if(m_CurWorkStep != 0) return; //加工前提示 if(gCommonFlowMgr->StartWorkConfirm(gbSelMark)==false) return; m_CurProductIdx = -1; //更新product 的状态(标记最后一个product) gProductMgr->UpdateProductState(); //取消停止状态 gCommonFlowMgr->SetbWorkStop(false); //设置第一个加工的product 编号 gProductMgr->SetCurProductIdx(0); } //自动加工(每次加工一个product ) void DlgCutDeviceCtrl::AutoWork() { if(gCommonFlowMgr->IsbWorkStop()) { m_CurWorkStep = 0; } int Idx = gProductMgr->GetCurProductIdx(); if(Idx<0) { return; } CProduct &Product = gProductMgr->GetProduct(Idx); if(Product.IsUsed()==false)//过滤掉不使用的product { m_CurWorkStep = 0; } if(m_CurWorkStep == 1)//抓取定位1 { //先抓一帧,把CCD 停掉 if(Idx ==0)//第一个product { gWorkTime.StartRecordTime();//计时开始 } //将数据移动到当前product 的基准点上 gProgramCutMgr->MoveObjData(Product.GetProductBasePt()); gCommonFlowMgr->CameraCatchTwoMark(Product);//只抓取一个点 if(Product.IsSetRealMarkPt1()) { m_CurWorkStep = 2; } else { m_CurWorkStep = 0; } } else if(m_CurWorkStep == 2)//抓取定位2 { gCommonFlowMgr->CameraCatchTwoMark(Product); if(Product.IsMarkReady()) { m_CurWorkStep = 3; } else { m_CurWorkStep = 0; } } else if(m_CurWorkStep == 3)//开始切割 { if(Product.IsMarkReady()) { if(!gbSelMark)//全打的时候直接全部选择2018-04-20 { gObjComponentMgr->SelAllObj(); } gProgramCutMgr->StartWork(Product,true); CLayer &layer = GetLayerInstance(); CObjContainer ObjContainer = layer.GetObjContainer(); ObjContainer.NotSelAllObj(); } m_CurWorkStep = 0;//结束 } if(m_CurWorkStep == 0)//结束 { gProductMgr->CurProductIdxInc();//product 的索引值++ if(gProductMgr->GetCurProductIdx()<0)//所有product 加工完成 { //移动回默认的位置 gProgramCutMgr->MoveObjData(Dbxy(0,0)); gCommonFlowMgr->SetLightStateCmd(false); gWorkTime.StopRecordTime();//停止计时 //将数据移动到product 0 的基准点上 CProduct &Product0 = gProductMgr->GetProduct(0); gProgramCutMgr->MoveObjData(Product0.GetProductBasePt()); if(gCommonFlowMgr->IsNeedExecAgain())//拷机再次启动 { SetTimer(WORK_TIMER5,WORK_TIME_DELAY5,NULL); } //清空指令集 CWorkCmdContainer &CmdContainer = CWorkCmdContainer::GetInstance();//指令集 CmdContainer.Clear(); gLogMgr->WriteDebugLog("All Work End"); } } //没结束,继续启动AutoWork() if(m_CurWorkStep>=1 && m_CurWorkStep<=3) { SetTimer(WORK_TIMER2,WORK_TIME_DELAY2,NULL); } } //检查启动状态(这里负责切割product 进行加工) void DlgCutDeviceCtrl::CheckStartState() { int Idx = gProductMgr->GetCurProductIdx(); if(Idx>=0 && Idx != m_CurProductIdx)//不要重复启动 { m_CurProductIdx = Idx;//当前加工的product m_CurWorkStep = 1;//控制加工当前product的步骤 if(Idx == 0) { gCommonFlowMgr->SetLightStateCmd(true); } AutoWork(); } } //通过按钮启动加工 void DlgCutDeviceCtrl::StartWrokByBottom() { } #endif #if 1 void DlgCutDeviceCtrl::SetPar() { m_LaserPower = gCLaserDeviceMgr->GetPower(); m_LaserFre = gCLaserDeviceMgr->GetLaserFre(); CMarkPar& MarkPar = gMarkParMgr->GetCurPen(); m_LaserSpeed = MarkPar.ms;//切割速度 m_CutCount = gCommonFlowMgr->m_OneObjMarkCnt;//切割次数 m_OffsetAdjust = gCommonFlowMgr->GetAdjustOffset(); m_RotatoAdjust = gCommonFlowMgr->GetRotatoAdjust();//旋转调整 m_SizeAdjust = gCommonFlowMgr->GetAdjustSize(); m_MarkAreaCutCount = gCommonFlowMgr->GetAreaCycleCnt();//循环次数 //UpdateData(FALSE); } //应用参数 void DlgCutDeviceCtrl::OnBnClickedSavePar() { if(gAuthorityMgr->CheckAuthority(_USER,true)==false) return; UpdateData(TRUE); gCLaserDeviceMgr->SetPower(m_LaserPower); gCLaserDeviceMgr->SetFre(m_LaserFre); CMarkPar& MarkPar = gMarkParMgr->GetCurPen(); MarkPar.ms = m_LaserSpeed;//切割速度 gMarkParMgr->SaveCurPen(MarkPar); gCommonFlowMgr->m_OneObjMarkCnt = m_CutCount;//切割次数 gCommonFlowMgr->SetAdjustOffset(m_OffsetAdjust); gCommonFlowMgr->SetRotatoAdjust(m_RotatoAdjust); gCommonFlowMgr->SetAdjustSize(m_SizeAdjust); gCommonFlowMgr->SetAreaCycleCnt(m_MarkAreaCutCount); gDevicePropertieMgr.SaveAllPropertie(); //设置激光的参数 gCLaserDeviceMgr->SetParToLaserDevice(false); //重新搜集数据源 gProgramCutMgr->CollectSrcWorkData(); CMsgBox MsgBox; MsgBox.Show("参数应用成功"); //保存加工参数 gProgramCutMgr->SaveWorkParFile(); } #endif //更新激光参数 void DlgCutDeviceCtrl::UpdateLaserParInfo() { double LaserCurr = gCLaserDeviceMgr->GetCurLaserCurr(); double LaserFre = gCLaserDeviceMgr->GetCurLaserFre(); if(LaserCurr<0 ||LaserCurr>100) LaserCurr = 0; if(LaserFre<0 ||LaserFre>100) LaserFre = 0; GetDlgItem(IDC_SLEEP_TIME)->SetWindowText(gCLaserDeviceMgr->GetCurLeftTimes()); GetDlgItem(IDC_CUR_LASER_CURR)->SetWindowText(Db2CString(LaserCurr)); GetDlgItem(IDC_CUR_LASER_FRE)->SetWindowText(Db2CString(LaserFre)); }