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.

528 lines
16 KiB
C++

#include "StdAfx.h"
#include "WaferRecipeDataMgr.h"
#include "GlobalFunction.h"
#include "LogMgr.h"
#include "WorkTime.h"
#include "FileMgr.h"
#include "WorkFileMgr.h"
#include "Layer.h"
#include "ObjFillMgr.h"
#include "Laser.h"
#include "Propertie.h"
#include "PropertieMgr.h"
#include "AuthorityMgr.h"
#include "MsgBox.h"
#include "CStringFuc.h"
#include "Layer.h"
#include "PenParMgr.h"
#include "ObjBase.h"
#include "ObjContainer.h"
#include "ExceptionMsg.h"
#include "WorkRecord.h"
#include "WorkCmdInvoker.h"
#include "WorkCmdContainer.h"
#include "WorkAreaMgr.h"
#include "PenParMgr.h"
#include "CommonFlowMgr.h"
#include "LaserPowCheckMgr.h"
#include "EncryptionMgr.h"
#include "ObjPline.h"
#include "CommomText.h"
#include "ProgramLaserTuiHuo.h"
#include "WorkAreaMgr.h"
#define WORK_AREA_PATH _T("\\WorkMode")
#define SCAN_AREA_FILE_PATH _T("\\ScanArea") //加工区域的路径
#define RECIPE_FILE_PATH _T("\\RecipeFile")
CSlotRecipeDataMgr *gWaferRecipeDataMgr = new CSlotRecipeDataMgr;
CSlotRecipeDataMgr::CSlotRecipeDataMgr(void)
{
m_bScanEnd = true;//扫描结束状态,用来确定扫描线的颜色
m_EndScanLineIdx = -1;//结束扫描时扫描线的索引值(用来恢复中断的情况)
m_TotalScanLineCnt = 0;//扫描线的总数
}
CSlotRecipeDataMgr::~CSlotRecipeDataMgr(void)
{
}
void CSlotRecipeDataMgr::OnAppInitialize()
{
//默认显示选择对象的idx
gLayer.SetbShowObjIdx(true);
//创建recipe 文件路径
CString RecordPath;
CFileMgr FileMgr;
FileMgr.GetFullFilePath(RecordPath,RECIPE_FILE_PATH);
if(!FileMgr.IsFileExist(RecordPath))//不存在,创建目录
{
FileMgr.CreatDir(RecordPath);
}
CString OffsetTabPath = gProgramLaserTuiHuo->GetLaipuLaserDataDir(OFFSET_TAB_FILE_PATH);
if(!FileMgr.IsFileExist(OffsetTabPath))//不存在,创建目录
{
FileMgr.CreatDir(OffsetTabPath);
}
}
//检查扫描数据的安全性
bool CSlotRecipeDataMgr::CheckScanPathSecurity()
{
gLogMgr->WriteDebugLog("Func---->CheckScanPathSecurity");
CObjContainer &ObjContainer = gLayer.GetObjContainer();
bool Ret = true;
vector<Sptr<CObjBase>> &m_ObjVec = ObjContainer.GetObjVec();
int size = m_ObjVec.size();
for(int k=0;k<size;k++)
{
vector<CDataPoint>&PtContainer = m_ObjVec[k]->GetPtContainer();
int size1 = PtContainer.size();
for(int i=0;i<size1;i++)
{
if(!gWorkAreaMgr->IsPtInWorkArea(PtContainer[i].GetPt()))
{
Ret = false;
break;
}
}
}
if(!Ret)
{
CMsgBox MsgBox;
MsgBox.Show("扫描数据不在安全的范围内!");
}
return Ret;
}
#if 1
//创建扫描路径,SelObjVec 是选择的obj 索引
void CSlotRecipeDataMgr::CreatScanPath(vector<bool> SelObjVec)
{
CObjContainer &ObjContainer = gLayer.GetObjContainer();
ObjContainer.DelAllFillObj();//先删除填充的obj
ObjContainer.SelObjByIdxVec(SelObjVec);//设置obj 的选择状态
gPenParMgr->SetParSelectState(SelObjVec);//设置对应笔号的选择状态
m_CurSelStateVec = SelObjVec;//记录当前选择状态
//填充所有选择的obj
gObjFillMgr.FillAllSelObj();
//创建完成后取消选择状态
//ObjContainer.NotSelAllObj();
//设置第一个选择的笔作为工作笔
gPenParMgr->SetFirstSelPenAsWorkPen();
//记录当前扫描线的数量
CScanState &ScanState = gWorkRecordMgr->GetCurScanState();
ScanState.m_TotalScanLineCnt = ObjContainer.GetScanLineCnt();
}
//通过制定area 的编号来创建扫描路径
void CSlotRecipeDataMgr::CreatScanPath(int AreaIdx)
{
vector<bool> SelObjVec;
CObjContainer &ObjContainer = gLayer.GetObjContainer();
int AreaCnt = ObjContainer.GetScanAreaCnt();
for(int k=0;k<AreaCnt;k++)
{
if(AreaIdx==k)
SelObjVec.push_back(true);
else
SelObjVec.push_back(false);
}
CreatScanPath(SelObjVec);
}
//获取选中recipe 的文件路径
CString CSlotRecipeDataMgr::GetSelRecipePath(int idx)
{
CString path;
int size = m_RecipeFilePathVec.size();
if(idx>=0 && idx<size)
{
path = m_RecipeFilePathVec[idx];
}
return path;
}
//重叠率/频率/光斑尺寸---->扫描速度
double CSlotRecipeDataMgr::CalScanSpeedByOverlapRatio(double OverlapRatio,double Fre)
{
if(Fre<=0 || (OverlapRatio<=0 || OverlapRatio>99.9))
{
return -1;
}
//当前光斑的尺寸
DbSize MainSpotSize = gLaser->GetSpotSize(_LaserDeviceType_MainLaser1);
double SpotSize;
if(gLaser->IsbScanByDirX())
SpotSize = MainSpotSize.w;
else
SpotSize = MainSpotSize.h;
double SpotGap = SpotSize*(OverlapRatio/100);
double ScanSpeed = (SpotSize - SpotGap)*Fre;
//频率Fre = 500
//光斑X方向宽度SpotSize = 0.686
//重叠率 OverlapRatio = 10%
//则计算出来的X 轴扫描速度ScanSpeed = 308.7
//ScanSpeed = (664.9 - (664.9-623.79))*500; = 311.895
return ScanSpeed;
}
//[功率密度/频率/光斑尺寸]--->[衰减器的旋转角度]
/*用于验算角度对应的Edi
double TestAng = Edi;
double TestEdi = cos(_360ToAngle(2*(TestAng)));
TestEdi *= TestEdi;
TestEdi *= Pow;//pow
TestEdi /= (Fre*LaserSpotX*LaserSpotY);
CString log;
log.Format("Test Edi = %lf",TestEdi);
gLogMgr->WriteDebugLog(log);
*/
//计算公式: Edi = (P(cos2θ)^2)/(F*H*L)
double CSlotRecipeDataMgr::CalRotatoDimmerAng(double LaserSpotX,double LaserSpotY,double Edi,double Fre,double Pow)
{
double Ang = 0;
LaserSpotX *= 0.1;//mm-->cm
LaserSpotY *= 0.1;
double Ret = (LaserSpotX*LaserSpotY);
Ret *= (Edi*Fre);
Ret /= Pow;
Ret = sqrt(Ret);//根号
Ret = acos(Ret);//cos的反三角函数(结果是反正切角)
Ret /=2;
Ang = Ret/2;
Ang = AngleTo360(Ret);//反正切角转换为360 角
Ang *= -1;
return Ang;
}
//通过速度和频率计算重叠率
double CSlotRecipeDataMgr::CalOverlapRatioByScanSpeed(double ScanSpeed,double Fre)
{
if(Fre<=0 || ScanSpeed<=0)
{
return -1;
}
//当前光斑的尺寸
DbSize MainSpotSize = gLaser->GetSpotSize(_LaserDeviceType_MainLaser1);
double SpotSize;
if(gLaser->IsbScanByDirX())
SpotSize = MainSpotSize.w;
else
SpotSize = MainSpotSize.h;
double SpotGap = SpotSize - ScanSpeed/Fre;
double OverlapRatio = (SpotGap/SpotSize)*100;
if(OverlapRatio<0 || OverlapRatio>99)
return -1;
return OverlapRatio;
}
#endif
#if 1
//初始化可以选择的扫描区域
void CSlotRecipeDataMgr::InitScanAreaComb(CComboBox &ComboBox)
{
ComboBox.ResetContent();//清空
//获取加工文件的名字
vector<CString> Vec;
GetScanAreaName(Vec);
int size = Vec.size();
for(int i=0;i<size;i++)
{
ComboBox.InsertString(i,Vec[i]);
}
}
//通过名字来选择区域文件
bool CSlotRecipeDataMgr::SelScanAreaByName(CString SelScanAreaName)
{
//获取加工文件的名字
vector<CString> Vec;
GetScanAreaName(Vec);
int size = Vec.size();
for(int i=0;i<size;i++)
{
if(Vec[i] == SelScanAreaName)
{
SelScanArea(i);
return true;
}
}
return false;
}
//获取加工文件的名字
void CSlotRecipeDataMgr::GetScanAreaName(vector<CString> &Vec)
{
Vec.clear();
CFileMgr FileMgr;
CString filepath;
//FileMgr.GetFullFilePath(filepath,SCAN_AREA_FILE_PATH);//获取完整路径
filepath = gProgramLaserTuiHuo->GetScanAreaFilePath();
FileMgr.GetChildFileOrDirName(false,filepath,Vec,".obj");
m_ScanAreaPathVec = Vec;//记录 文件的完整路径
int size = Vec.size();
for(int i=0;i<size;i++)
{
Vec[i] = FileMgr.GetFileNameFromPath(Vec[i],true);
}
}
//选择加工区域(并创建扫描路径,返回Area 名称)
CString CSlotRecipeDataMgr::SelScanArea(int idx)
{
CString AreaName;
gLayer.DelAllObj();
vector<CString> &ScanAreaPathVec = m_ScanAreaPathVec;
int size = ScanAreaPathVec.size();
for(int i=0;i<size;i++)
{
if(idx == i)
{
CString Path = ScanAreaPathVec[i];
//打开扫描区域文件
gWorkFileMgr->ReadObjTemplateFile(Path);
//记录当前使用的扫描区域
CFileMgr FileMgr;
FileMgr.GetFileNameFromPath(Path,true);
AreaName = FileMgr.GetFileNameFromPath(Path,true);
break;
}
}
return AreaName;
}
#endif
#if 1
void CSlotRecipeDataMgr::IniRecipeParList(CListCtrl &list)
{
//设置风格
list.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
//设置列
int idx = 0;
list.InsertColumn(idx,"Idx",LVCFMT_LEFT,50,-1);
idx++;
list.InsertColumn(idx,"参数名",LVCFMT_LEFT,155,-1);
idx++;
list.InsertColumn(idx,"",LVCFMT_LEFT,130,-1);
idx++;
vector<CRecipePar> &RecipeParVec = gPenParMgr->GetRecipeParVec();
int size = RecipeParVec.size();
for(int k=0;k<size;k++)
{
int idx = 0;
list.InsertItem(k," ");//插入一行
list.SetItemText(k,idx++,Int2CString(k+1));//序号
list.SetItemText(k,idx++,RecipeParVec[k].m_RecipeParName);//参数名
list.SetItemText(k,idx++,"");//参数值
}
}
//获取第一个选择obj 对象的索引值
int CSlotRecipeDataMgr::GetFristSelOutLineObjIdx()
{
vector<CPenPar> &ParVec = gPenParMgr->GetParVec();
int PenParCnt = ParVec.size();
CObjContainer &ObjContainer = gLayer.GetObjContainer();
int ObjCnt = ObjContainer.GetScanAreaCnt();
for(int k=0;(k<ObjCnt)||(k>=PenParCnt);k++)
{
CPenPar &PenPar =ParVec[k];
if(PenPar.m_bSelected)
return k;
}
return -1;
}
#endif
#if 1
void CSlotRecipeDataMgr::InitOffsetTableList(CListCtrl &List)
{
//设置风格
List.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
//设置列
int idx = 0;
List.InsertColumn(idx,"Idx",LVCFMT_CENTER,35,-1);
idx++;
List.InsertColumn(idx,"ParName",LVCFMT_LEFT,140,-1);
idx++;
List.InsertColumn(idx,"Unit",LVCFMT_CENTER,80,-1);
idx++;
List.InsertColumn(idx,"Value",LVCFMT_LEFT,100,-1);
idx++;
}
void CSlotRecipeDataMgr::UpdateOffsetTableList(CListCtrl &List,CString FilePath)
{
//从文件中读取OffsetTable
m_CurEditOffsetTable.ReadOffsetTableFile(FilePath);
//显示到列表
vector<COffsetTablePar> &OffsetTableParVec = m_CurEditOffsetTable.m_OffsetTableParVec;
{
List.DeleteAllItems();
int size = OffsetTableParVec.size();
for(int k=0;k<size;k++)
{
int idx = 0;
COffsetTablePar &TablePar = OffsetTableParVec[k];
List.InsertItem(k," ");//插入一行
List.SetItemText(k,idx++,Int2CString(k+1));//序号
List.SetItemText(k,idx++,TablePar.m_ParShowName);//参数名
List.SetItemText(k,idx++,TablePar.m_ParUnit);//参数单位
List.SetItemText(k,idx++,Db2CString(TablePar.m_ParVal));//参数值
}
}
}
void CSlotRecipeDataMgr::SaveRcpOffsetTable(CListCtrl &List,CString FilePath)
{
CMsgBox MsgBox;
CFileMgr FileMgr;
vector<COffsetTablePar> &OffsetTableParVec = m_CurEditOffsetTable.m_OffsetTableParVec;
int size = OffsetTableParVec.size();
for(int k=0;k<size;k++)
{
int idx = 0;
COffsetTablePar &TablePar = OffsetTableParVec[k];
CString ParValStr = List.GetItemText(k,OffsetTab_List_Val_Col);
double Val = CStringToDouble(ParValStr);
TablePar.m_ParVal = Val;
gLogMgr->WriteDebugLog(ParValStr);
}
m_CurEditOffsetTable.SaveOffsetTableFile(FilePath);
//保存操作记录
CString Name = FileMgr.GetFileNameFromPath(FilePath,true);
SaveOffsetTableHistory(OffsetTableParVec,"Change",Name);
CString s = FilePath;
s += "\nSave Succes";
MsgBox.Show(s);
}
//创建一个新的OffsetTable
void CSlotRecipeDataMgr::CreateNewOffsetTable(CString Name)
{
CMsgBox MsgBox;
CString s;
CString Path = gProgramLaserTuiHuo->GetLaipuLaserDataDir(OFFSET_TAB_FILE_PATH);
Path += Name;
Path += ".";
Path += OFFSET_TAB_FILE_SUFFIX;
CFileMgr FileMgr;
if(FileMgr.IsFileExist(Path))
{
s = Name + "已存在";
MsgBox.Show(s);
return;
}
COffsetTable OffsetTable;
//写入文件
OffsetTable.SaveOffsetTableFile(Path);
//保存操作记录
SaveOffsetTableHistory(OffsetTable.m_OffsetTableParVec,"Create",Name);
}
//删除OffsetTable
void CSlotRecipeDataMgr::DelOffsetTable(CString FilePath)
{
CMsgBox MsgBox;
CString s;
CFileMgr FileMgr;
if(!FileMgr.IsFileExist(FilePath))
{
s = FilePath + "\nNot Exist";
MsgBox.Show(s);
return;
}
s = "Delete: \n" + FilePath;
if(MsgBox.ConfirmOkCancel(s))
{
//保存操作记录
CString Name = FileMgr.GetFileNameFromPath(FilePath,true);
SaveOffsetTableHistory(m_CurEditOffsetTable.m_OffsetTableParVec,"Delete",Name);
CFileMgr FileMgr;
FileMgr.DeleteFolder(FilePath);
}
}
//保存操作记录
void CSlotRecipeDataMgr::SaveOffsetTableHistory(vector<COffsetTablePar>&OffsetTableParVec,CString OperateType,CString TableName)
{
CWorkTime WorkTime;
CCsvData CsvData;
CsvData.AddData("User Name",false);
CsvData.AddData(gAuthorityMgr->GetCurUserName(),true);
CsvData.AddData("Operate Time",false);
CsvData.AddData(WorkTime.GetDateTime("/",":"),true);
CsvData.AddData("OperateType",false);
CsvData.AddData(OperateType,true);
CsvData.AddData("Offset Table Name",false);
CsvData.AddData(TableName,true);
int size = OffsetTableParVec.size();
for(int k=0;k<size;k++)
{
COffsetTablePar &TablePar = OffsetTableParVec[k];
CsvData.AddData(TablePar.m_ParShowName,false);
CsvData.AddData(Db2CString(TablePar.m_ParVal),true);
}
CString FileName = WorkTime.GetCurTime("_");
FileName += "_";
FileName += TableName;
CString DataPath = CreatDataTimePath(gProgramLaserTuiHuo->GetLaipuLaserDataDir(OFFSET_TAB_HISTORY_PATH));
CFileMgr FileMgr;
FileMgr.WriteDataToExcel(DataPath,FileName,CsvData,false);
}
//初始化可以选择的Offset Table
void CSlotRecipeDataMgr::InitOffsetTableComb(CComboBox &ComboBox)
{
ComboBox.ResetContent();//清空
//获取加工文件的名字
vector<CString> Vec;
GetOffsetTableName(Vec);
ComboBox.InsertString(0,RECIPE_OFFSET_TBL_NULL);//第一行为空,表示不选择OffsetTable
int size = Vec.size();
for(int i=0;i<size;i++)
{
ComboBox.InsertString(i+1,Vec[i]);
}
}
//获取加工文件的名字
void CSlotRecipeDataMgr::GetOffsetTableName(vector<CString> &Vec)
{
Vec.clear();
CFileMgr FileMgr;
CString filepath;
filepath = gProgramLaserTuiHuo->GetLaipuLaserDataDir(OFFSET_TAB_FILE_PATH);
FileMgr.GetChildFileOrDirName(false,filepath,Vec,".tbl");
m_OffsetTablePathVec = Vec;//记录 文件的完整路径
int size = Vec.size();
for(int i=0;i<size;i++)
{
Vec[i] = FileMgr.GetFileNameFromPath(Vec[i],true);
}
}
//选择OffsetTable
CString CSlotRecipeDataMgr::SelOffsetTable(int idx)
{
idx--;//去掉
CString Name = RECIPE_OFFSET_TBL_NULL;
vector<CString> &OffsetTablePathVec = m_OffsetTablePathVec;
int size = OffsetTablePathVec.size();
for(int i=0;i<size;i++)
{
if(idx == i)
{
CString Path = OffsetTablePathVec[i];
CFileMgr FileMgr;
FileMgr.GetFileNameFromPath(Path,true);
Name = FileMgr.GetFileNameFromPath(Path,true);
break;
}
}
return Name;
}
#endif