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.
292 lines
8.8 KiB
C++
292 lines
8.8 KiB
C++
#include "StdAfx.h"
|
|
#include "ProgramCutMgr.h"
|
|
#include "Layer.h"
|
|
#include "DxfReadMgr.h"
|
|
#include "GlobalFunction.h"
|
|
#include "ObjComponentMgr.h"
|
|
#include "ProductMgr.h"
|
|
#include "CommonFlowMgr.h"
|
|
#include "CameraHawkvis.h"
|
|
#include "MsgBox.h"
|
|
#include "PropertieMgr.h"
|
|
#include "WorkTime.h"
|
|
#include "WorkRecord.h"
|
|
#include "WorkFileMgr.h"
|
|
#include "CommandMgr.h"
|
|
#include "EasyOperationMgr.h"
|
|
#include "FileMgr.h"
|
|
#include "LaserDeviceMgr.h"
|
|
#include "MarkParMgr.h"
|
|
#include "CStringFuc.h"
|
|
#include "LogMgr.h"
|
|
#include "ProductMgr.h"
|
|
#include "ObjSortMgr.h"
|
|
|
|
|
|
#define PRODUCT_CNT 1 //工件的数量
|
|
|
|
CProgramCutMgr *gProgramCutMgr = new CProgramCutMgr;
|
|
CProgramCutMgr::CProgramCutMgr(void)
|
|
{
|
|
}
|
|
CProgramCutMgr::~CProgramCutMgr(void)
|
|
{
|
|
}
|
|
void CProgramCutMgr::Ini()
|
|
{
|
|
GetFrame()->m_DlgCutDeviceCtrl.SetPar();
|
|
}
|
|
#if 1
|
|
//打开加工文件(bOpenDxf 为false 的时候可以不重新打开dxf)
|
|
void CProgramCutMgr::OpenWorkFile(bool bDxf,bool bOpenDxf)
|
|
{
|
|
//重置定位
|
|
gProductMgr->ResetRealMarkPt();
|
|
//删除所有obj 元件
|
|
gObjComponentMgr->SetShapeLockState(false);//绑定的obj 解锁
|
|
gObjComponentMgr->DelAll();
|
|
//删除图形对象
|
|
CLayer &Layer = GetLayerInstance();
|
|
if(bOpenDxf)
|
|
{
|
|
Layer.DelAllObj();
|
|
}
|
|
CObjContainer &ObjContainer = Layer.GetObjContainer();
|
|
|
|
try
|
|
{
|
|
if (bDxf)
|
|
{
|
|
//读取dxf 文件,创建layer obj 对象
|
|
if (bOpenDxf)
|
|
{
|
|
gDxfReadMgr->OpenDxfFileDlg(0);
|
|
}
|
|
}
|
|
else//打开mak 文件
|
|
{
|
|
OpenMarkFile();
|
|
}
|
|
}
|
|
catch (CString) { return; };
|
|
|
|
Layer.NotSelAllObj();
|
|
gProductMgr->SetDefualtRect(ObjContainer.GetObjRect(false));
|
|
|
|
//对obj 进行排序
|
|
CObjSortMgr ObjSortMgr;
|
|
ObjSortMgr.SortObjByDir(_DIR_R);
|
|
|
|
//通过layer 对象创建obj 对象
|
|
gObjComponentMgr->CreatObjByLayerObj();
|
|
//从obj 中分析出两个定位mark 的位置
|
|
gObjComponentMgr->AnalyseMarkPt();
|
|
|
|
gCommandMgr.DelAllCmd();//删除所有指令
|
|
}
|
|
//移动加工数据
|
|
void CProgramCutMgr::MoveObjData(Dbxy BasePt)
|
|
{
|
|
gLogMgr->WriteDebugLog("CProgramCutMgr::MoveObjData");
|
|
//重置定位
|
|
gProductMgr->ResetRealMarkPt();
|
|
//先解除所有obj 的锁定状态
|
|
gObjComponentMgr->SetShapeLockState(false);
|
|
//将layer obj移动到当前product 的基准点上
|
|
gProductMgr->MoveObjToBasePt(BasePt);
|
|
CLayer &Layer = GetLayerInstance();
|
|
CObjContainer ObjContainer = Layer.GetObjContainer();
|
|
ObjContainer.NotSelAllObj();
|
|
gEasyOperationMgr->Refresh();
|
|
//删除所有指令
|
|
gCommandMgr.DelAllCmd();
|
|
//重新锁定
|
|
gObjComponentMgr->SetShapeLockState(true);
|
|
//GetCurViewPtr()->RefreshView();
|
|
}
|
|
void CProgramCutMgr::OpenMarkFile()
|
|
{
|
|
CWorkFileMgr WorkFileMgr;
|
|
WorkFileMgr.OnOpenFile();
|
|
gDrawPropertieMgr.SaveAllPropertie();
|
|
gDevicePropertieMgr.SaveAllPropertie();
|
|
}
|
|
void CProgramCutMgr::SaveMarkFile()
|
|
{
|
|
CWorkFileMgr WorkFileMgr;
|
|
WorkFileMgr.OnSaveFileAs();
|
|
}
|
|
//通过图形直接保存为mak (主要是为了在软件中直接调整dxf 文件)
|
|
void CProgramCutMgr::SaveMarkFile2()
|
|
{
|
|
OpenWorkFile(true,false);
|
|
CWorkFileMgr WorkFileMgr;
|
|
WorkFileMgr.OnSaveFileAs();
|
|
}
|
|
#endif
|
|
#if 1
|
|
//初始化设备
|
|
bool CProgramCutMgr::InitDevice()
|
|
{
|
|
if(gCommonFlowMgr->InitDevice())
|
|
{
|
|
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
//移动平台之前的操作(主要是要停掉占cpu 的工作)
|
|
void CProgramCutMgr::OnPlatformMoveStart()
|
|
{
|
|
}
|
|
void CProgramCutMgr::OnPlatformMoveEnd()
|
|
{
|
|
}
|
|
void CProgramCutMgr::CameraCatchTwoMark()
|
|
{
|
|
//先抓一帧,把CCD 停掉
|
|
//gCommonFlowMgr->CameraCatch();
|
|
gCommonFlowMgr->CameraCatchTwoMark();
|
|
}
|
|
//启动加工
|
|
bool CProgramCutMgr::StartWork(CProduct &Product,bool bSel)
|
|
{
|
|
/* CMsgBox MsgBox;
|
|
if(Product.IsMarkReady())
|
|
{*/
|
|
//gWorkRecordMgr->SetStartWorkTime(gWorkTime.GetCurTime(":"));
|
|
if(gCommonFlowMgr->MultipleAreaMark(Product,bSel))
|
|
{
|
|
//gWorkRecordMgr->SetEndWorkTime(gWorkTime.GetCurTime(":"));
|
|
//CString WorkTime = gWorkTime.GetTimeSpanStr();//加工时间
|
|
//gWorkRecordMgr->SetWorkTime(WorkTime);
|
|
//gWorkRecordMgr->WriteRecordToFile();//记录加工文件
|
|
//Product.ResetRealMarkPt();
|
|
//记录上次运行时间
|
|
//gWorkTime.SaveLastWorkTime();
|
|
return true;
|
|
}
|
|
/*}
|
|
else
|
|
{
|
|
MsgBox.Show("请先进行定位操作");
|
|
}*/
|
|
return false;
|
|
}
|
|
#endif
|
|
#if 1
|
|
//保存当前打开的dxf 文件对应的参数
|
|
void CProgramCutMgr::SaveWorkParFile()
|
|
{
|
|
CString OpenFileName = GetCurOpenFileName();
|
|
if(OpenFileName != "")
|
|
{
|
|
CString FileName = "\\WorkPar\\"+OpenFileName+".txt";
|
|
CFileMgr FileMgr;
|
|
char filepath[1024];
|
|
FileMgr.GetFullFilePath(filepath,FileName);
|
|
|
|
ofstream file;
|
|
file.open(filepath);
|
|
//工位的基准点
|
|
vector<CProduct> &ProductVec = gProductMgr->GetProductVec();
|
|
int ProductCnt = ProductVec.size();
|
|
file<<ProductCnt<<"\n";
|
|
for(int k=0;k<ProductCnt;k++)
|
|
{
|
|
Dbxy pt = ProductVec[k].GetProductBasePt();
|
|
file<<pt.x<<"\n";
|
|
file<<pt.y<<"\n";
|
|
}
|
|
//
|
|
file<<gCLaserDeviceMgr->GetPower()<<"\n";//激光电流
|
|
file<<gCLaserDeviceMgr->GetLaserFre()<<"\n";//激光频率
|
|
CMarkPar& MarkPar = gMarkParMgr->GetCurPen();
|
|
file<<MarkPar.ms<<"\n";//切割速度
|
|
file<<gCommonFlowMgr->GetOneObjMarkCnt()<<"\n";//切割次数
|
|
file<<gCommonFlowMgr->GetAreaCycleCnt()<<"\n";//循环次数
|
|
}
|
|
}
|
|
//读取当前打开的dxf 文件对应的参数
|
|
void CProgramCutMgr::ReadWorkParFile()
|
|
{
|
|
CString OpenFileName = GetCurOpenFileName();
|
|
if(OpenFileName != "")
|
|
{
|
|
CString FileName = "\\WorkPar\\"+OpenFileName+".txt";
|
|
CFileMgr FileMgr;
|
|
CString filepath;
|
|
FileMgr.GetFullFilePath(filepath,FileName);
|
|
|
|
if(FileMgr.IsFileExist(filepath))
|
|
{
|
|
vector<CString> vec;
|
|
FileMgr.ReadFileToStringVec(filepath,vec);
|
|
int size = vec.size();
|
|
int k = 0;
|
|
int ParIdx = 1;
|
|
while(k<size)
|
|
{
|
|
if(k==0)
|
|
{
|
|
int ProductCnt = CStringToInt(vec[k++]);
|
|
vector<CProduct> &ProductVec = gProductMgr->GetProductVec();
|
|
int ProductCnt2 = ProductVec.size();
|
|
if(ProductCnt != ProductCnt2)
|
|
{
|
|
gLogMgr->WriteDebugLog("ReadWorkParFile 参数product 数量不一致!");
|
|
return;
|
|
}
|
|
for(int i=0;i<ProductCnt;i++)
|
|
{
|
|
Dbxy pt;
|
|
pt.x = CStringToDouble(vec[k++]);
|
|
pt.y = CStringToDouble(vec[k++]);
|
|
ProductVec[i].SetBasePt(pt);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(ParIdx == 1)
|
|
gCLaserDeviceMgr->SetPower(CStringToDouble(vec[k++]));
|
|
else if(ParIdx == 2)
|
|
gCLaserDeviceMgr->SetFre(CStringToInt(vec[k++]));
|
|
else if(ParIdx == 3)
|
|
{
|
|
CMarkPar& MarkPar = gMarkParMgr->GetCurPen();
|
|
MarkPar.ms = CStringToDouble(vec[k++]);//切割速度
|
|
gMarkParMgr->SaveCurPen(MarkPar);
|
|
}
|
|
else if(ParIdx == 4)
|
|
gCommonFlowMgr->SetOneObjMarkCnt(CStringToInt(vec[k++]));
|
|
else if(ParIdx == 5)
|
|
gCommonFlowMgr->SetAreaCycleCnt(CStringToInt(vec[k++]));
|
|
|
|
|
|
ParIdx++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
#if 1
|
|
//搜集数据源
|
|
void CProgramCutMgr::CollectSrcWorkData()
|
|
{
|
|
//先清除之前的数据
|
|
gMarkAreaMgr->ClearSrcWorkData();
|
|
int ProductCnt = PRODUCT_CNT;
|
|
for(int k=ProductCnt-1;k>=0;k--)
|
|
{
|
|
//将数据对象移动到product k 的基准点上
|
|
CProduct &Product = gProductMgr->GetProduct(k);
|
|
MoveObjData(Product.GetProductBasePt());
|
|
//搜集数据源
|
|
//重置原件的搜集状态
|
|
gObjComponentMgr->ResetObjCollectState(false);
|
|
gMarkAreaMgr->CollectSrcWorkData();
|
|
}
|
|
}
|
|
#endif
|