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.

363 lines
11 KiB
C++

#include "StdAfx.h"
#include "ObjFillMgr.h"
#include "CommandArray.h"
#include "CommandMgr.h"
#include "Layer.h"
#include "MsgBox.h"
#include "ObjPline.h"
#include "FileMgr.h"
#include "PenParMgr.h"
#include "Laser.h"
#include "ProgramLaserTuiHuo.h"
#include "WaferRecipeDataMgr.h"
#include "RecipeMgr.h"
#include "WorkRecord.h"
#include "LogMgr.h"
#if 1
CObjFillMgr gObjFillMgr;
CObjFillMgr::CObjFillMgr(void)
{
m_FillOffset = 1;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mm
m_FillAngle = 90;//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>(360 <20><>)
m_bDelEdgeObj = false;//<2F>Ƿ<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>obj
m_bCreatConnectLine = true;//<2F>Ƿ񴴽<C7B7><F1B4B4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_CurScanType = _SCAN_TRACK_S_L_R;//<2F><>ǰ<EFBFBD><C7B0>ɨ<EFBFBD>ʽ
m_StartFillIdx = 0;//<2F>ӵڼ<D3B5><DABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߿<EFBFBD>ʼ
}
CObjFillMgr::~CObjFillMgr(void)
{
}
//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD>ʽ
void CObjFillMgr::UpdateCurScanType()
{
int WaferScanType = gProgramLaserTuiHuo->GetWaferScanType();
if(WaferScanType>=0&&WaferScanType<8)
{
m_CurScanType = (SCAN_TRACK_E)WaferScanType;
CString log;
log.Format("Func--->UpdateCurScanType = %ld",WaferScanType);
gLogMgr->WriteDebugLog(log);
}
}
//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CObjFillMgr::FillAllSelObj()
{
//<2F><><EFBFBD><EFBFBD>obj <20><><EFBFBD><EFBFBD>ת90 <20><><><CEAA><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD>)
if(gLaser->IsbScanByDirX())
gLayer.Rotato(90);
//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD>ʽ
UpdateCurScanType();
//<2F><>ʼ<EFBFBD><CABC>
m_ObjContainer.Clear();
m_ScanLineVec.clear();
//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>m_ScanLineVec)
if(!CreatScanLineByObjFill())
return;
//ͨ<><CDA8>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>obj
CreatObjByScanLine();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>layer
FillObjAddToLayer();
//<2F><><EFBFBD><EFBFBD>obj <20><><EFBFBD><EFBFBD>ת90<39><30>
if(gLaser->IsbScanByDirX())
gLayer.Rotato(-90);
}
void CObjFillMgr::FillObjAddToLayer()
{
CObjContainer &ObjContainer = gLayer.GetObjContainer();
m_ObjContainer.AllObjAddToContainer(ObjContainer,false);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊidx <20><>obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CObjFillMgr::FillAllSelObjByIdx(int idx)
{
CObjContainer &ObjContainer = gLayer.GetObjContainer();
ObjContainer.NotSelAllObj();
}
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
void CObjFillMgr::CreatCmd()
{
if(!m_ObjContainer.Empty())
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>-------start
CCommandArray *pCmd = new CCommandArray;
gCommandMgr.AddUndoCommand(pCmd,m_ObjContainer.GetObjVec());
//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>obj
if(m_bDelEdgeObj)
{
pCmd->SaveBaseObj(gLayer.GetObjContainer());
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>-------end
pCmd->Excute();
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CObjFillMgr::CreatObjFillData(CObjContainer &ObjContainer)
{
SFillPar FillPar;
FillPar.m_FillAngle = m_FillAngle;
FillPar.bFill = true;
FillPar.m_FillGap = m_FillOffset;
ObjContainer.FillObj(FillPar,false);
}
//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD>
bool CObjFillMgr::CreatScanLineByObjFill()
{
CObjContainer &ObjContainer = gLayer.GetObjContainer();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CreatObjFillData(ObjContainer);
//<2F><><EFBFBD><EFBFBD>obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B7A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-----------------------------
vector<Sptr<CObjBase>> &ObjVec = ObjContainer.GetObjVec();
vector<Sptr<CObjBase>>::iterator iter = ObjVec.begin();
vector<Sptr<CObjBase>>::iterator iter_end = ObjVec.end();
int idx = 0;
bool bNeedCloseLaser = true;//ɨ<>費ͬ<E8B2BB><CDAC><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD>رռ<D8B1><D5BC><EFBFBD>
vector<CScanLine> ScanLineVecTmp;
for(;iter!=iter_end;iter++,idx++)
{
ScanLineVecTmp.clear();
int CurPenNum = idx;//<2F>ʺ<EFBFBD><CABA><EFBFBD><EFBFBD><EFBFBD>Ϊobj <20><><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
if(!(*iter)->IsbFillObj() && (*iter)->IsSelected())//<2F><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD>obj
{
vector<vector<Dbxy>> FillDataVec;
(*iter)->GetFillData(FillDataVec);
bool DirFlg = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
vector<vector<Dbxy>>::iterator iter1 = FillDataVec.begin();
vector<vector<Dbxy>>::iterator iter1_end = FillDataVec.end();
for(;iter1!=iter1_end;iter1++)
{
int size = (*iter1).size();
int idx1 = (DirFlg)?1:0;
int idx2 = (DirFlg)?0:1;
DirFlg = !DirFlg;//<2F><><EFBFBD><EFBFBD>
Dbxy pt1 = (*iter1)[idx1];
Dbxy pt2 = (*iter1)[idx2];
if(size==2)
{
CScanLine ScanLine(pt1,pt2);//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
ScanLine.SetPenNum(CurPenNum);
ScanLineVecTmp.push_back(ScanLine);
}
}
//S <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD>µ<EFBFBD><C2B5>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
SCAN_TRACK_E ScanTrack = m_CurScanType;
if(ScanTrack == _SCAN_TRACK_S_D_U ||ScanTrack == _SCAN_TRACK_S_R_L)
{
reverse(ScanLineVecTmp.begin(),ScanLineVecTmp.end());
}
vector<CScanLine>::iterator iter2 = ScanLineVecTmp.begin();
vector<CScanLine>::iterator iter2_end = ScanLineVecTmp.end();
bool bFirst = true;//<2F><><EFBFBD>ǵ<EFBFBD>һ<EFBFBD><D2BB>line
for(;iter2!=iter2_end;iter2++)
{
if(bFirst && bNeedCloseLaser)
{
(*iter2).SetbFirstLine();
bFirst = false;
}
m_ScanLineVec.push_back(*iter2);
}
}
}
if(!m_ScanLineVec.empty())
{
m_ScanLineVec[0].SetbFirstLine();//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD>ߣ<EFBFBD>ʹɨ<CAB9><C9A8>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD><D4B8>ǵ<EFBFBD><C7B5><EFBFBD>Բ
AdjustScanLine1();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SFillPar FillPar;
FillPar.bFill = false;
ObjContainer.FillObj(FillPar,false);
return true;
}
//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD>ߣ<EFBFBD>ʹɨ<CAB9><C9A8>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD><D4B8>ǵ<EFBFBD><C7B5><EFBFBD>Բ
void CObjFillMgr::AdjustScanLine1()
{
vector<CScanLine>::iterator iter = m_ScanLineVec.begin();
vector<CScanLine>::iterator iter_end = m_ScanLineVec.end();
for(;iter!=iter_end;iter++)
{
Dbxy StartPt = (*iter).GetStartPt();
Dbxy EndPt = (*iter).GetEndPt();
Dbxy pt1 = StartPt;
Dbxy pt2 = StartPt;
Dbxy pt3 = EndPt;
Dbxy pt4 = EndPt;
int PenNum = (*iter).GetPenNum();
double FillAngle;
GetAngle(FillAngle,PenNum);
if(FillAngle>0)
{
if(pt1.y>pt3.y)
{
ScanLineCoverWafer(pt1,pt2,true,PenNum);
ScanLineCoverWafer(pt3,pt4,false,PenNum);
}
else
{
ScanLineCoverWafer(pt3,pt4,true,PenNum);
ScanLineCoverWafer(pt1,pt2,false,PenNum);
}
StartPt.y = pt1.y;
EndPt.y = pt3.y;
}
else
{
if(pt1.x>pt3.x)
{
ScanLineCoverWafer(pt1,pt2,true,PenNum);
ScanLineCoverWafer(pt3,pt4,false,PenNum);
}
else
{
ScanLineCoverWafer(pt3,pt4,true,PenNum);
ScanLineCoverWafer(pt1,pt2,false,PenNum);
}
StartPt.x = pt1.x;
EndPt.x = pt3.x;
}
(*iter).SetStartPt(StartPt);
(*iter).SetEndPt(EndPt);
}
}
//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD>߸<EFBFBD><DFB8><EFBFBD>ס<EFBFBD><D7A1>ԲbDir <20>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CObjFillMgr::ScanLineCoverWafer(Dbxy &pt1,Dbxy &pt2,bool bDir,int PenNum)
{
//<2F><>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double Offset = 0;
if(Offset<=0)//<2F><><EFBFBD><EFBFBD>0 <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
Offset = 0.05;
if(!bDir)
Offset*=-1;
double FillAngle;
GetAngle(FillAngle,PenNum);
while(gLayer.HasObjIntersectWithLine(DbLine(CDataPoint(pt1),CDataPoint(pt2))))
{
//ֻ<>Ծ<EFBFBD>Բ<EFBFBD><D4B2>Ե<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>
if(FillAngle>0)
{
pt1.y += Offset;
pt2.y += Offset;
}
else
{
pt1.x += Offset;
pt2.x += Offset;
}
}
}
//<2F><><EFBFBD><EFBFBD>ÿһ<C3BF>е<EFBFBD>end <20><>,<2C><><EFBFBD><EFBFBD>һ<EFBFBD>е<EFBFBD>start <20><><EFBFBD>Ƚ<EFBFBD>,ȡX Ϊ<>뾧Բ<EBBEA7><D4B2>Զ<EFBFBD>ĵ<EFBFBD>
void CObjFillMgr::AdjustScanLine2()
{
int size = m_ScanLineVec.size();
for(int i=0;i<size-1;i++)
{
Dbxy EndPt = m_ScanLineVec[i].GetEndPt();
Dbxy NextStartPt = m_ScanLineVec[i+1].GetStartPt();
double FillAngle;
GetAngle(FillAngle,m_ScanLineVec[i].GetPenNum());
double *pVal1 = (FillAngle>0)?(&(EndPt.y)):(&(EndPt.x));
double *pVal2 = (FillAngle>0)?(&(NextStartPt.y)):(&(NextStartPt.x));
if(abs(*pVal1)<abs(*pVal2))
{
*pVal1 = *pVal2;
m_ScanLineVec[i].SetEndPt(EndPt);
}
else
{
*pVal2 = *pVal1;
m_ScanLineVec[i+1].SetStartPt(NextStartPt);
}
}
}
//ͨ<><CDA8>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>obj
void CObjFillMgr::CreatObjByScanLine()
{
//CScanState &ScanState = gWorkRecordMgr->GetCurScanState();
//int EndScanLineIdx = ScanState.m_EndScanLineIdx;
int size = m_ScanLineVec.size();
Dbxy PerPt;
int ScanLineIdx = 0;
for(int i=0;i<size;i++)
{
Dbxy StartPt = m_ScanLineVec[i].GetStartPt();
Dbxy EndPt = m_ScanLineVec[i].GetEndPt();
SCAN_TRACK_E ScanTrack = m_CurScanType;
if(ScanTrack == _SCAN_TRACK_U_D)//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8>-<2D>ϵ<EFBFBD><CFB5><EFBFBD>
{
if(StartPt.y < EndPt.y)
swap(StartPt,EndPt);
}
if(ScanTrack == _SCAN_TRACK_D_U)//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8>-<2D>µ<EFBFBD><C2B5><EFBFBD>
{
if(StartPt.y > EndPt.y)
swap(StartPt,EndPt);
}
if(ScanTrack == _SCAN_TRACK_R_L)//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(StartPt.x < EndPt.x)
swap(StartPt,EndPt);
}
if(ScanTrack == _SCAN_TRACK_L_R)//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8>-<2D>ҵ<EFBFBD><D2B5><EFBFBD>
{
if(StartPt.x > EndPt.x)
swap(StartPt,EndPt);
}
//bool bScaned = (EndScanLineIdx>0 && ScanLineIdx<=EndScanLineIdx);
bool bScaned = false;
PerPt = EndPt;
CObjPline *pObjPline = new CObjPline;
pObjPline->SetbFillObj(true);//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pObjPline->SetPenNum(m_ScanLineVec[i].GetPenNum());
pObjPline->Creat(StartPt,EndPt);
//<2F><><EFBFBD>DZ<EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>
pObjPline->SetbScaned(bScaned);
if(ScanLineIdx>=m_StartFillIdx)
m_ObjContainer.AddObject(pObjPline);
//ɨ<><C9A8><EFBFBD>߶<EFBFBD>
ScanLineIdx++;
}
}
//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8>ģʽ<C4A3><CABD>ȡ<EFBFBD>Ƕȣ<C7B6><C8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8>
bool CObjFillMgr::GetAngle(double &Angle,int PenNum)
{
SCAN_TRACK_E ScanTrack = m_CurScanType;
bool bhorizontal = false;
if(ScanTrack == _SCAN_TRACK_S_U_D || ScanTrack == _SCAN_TRACK_S_D_U|| ScanTrack == _SCAN_TRACK_L_R|| ScanTrack == _SCAN_TRACK_R_L)
{
bhorizontal = true;
Angle = 0;
}
else if(ScanTrack == _SCAN_TRACK_S_L_R || ScanTrack == _SCAN_TRACK_S_R_L|| ScanTrack == _SCAN_TRACK_U_D|| ScanTrack == _SCAN_TRACK_D_U)
{
Angle = 90;
}
return bhorizontal;
}
#endif