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.

222 lines
5.9 KiB
C++

#include "StdAfx.h"
#include "MarkArea.h"
#include "DrawSimpleShape.h"
#include "Layer.h"
#include "TemplateMgr.h"
#include "ObjComponentMgr.h"
#include "GlobalFunction.h"
#include "LogMgr.h"
#include "CommonFlowMgr.h"
#include "GlobalDrawMgr.h"
#define MIN_OBJ_CNT 5 //<2F><><EFBFBD><EFBFBD>obj <20><><EFBFBD><EFBFBD>
CMarkArea::CMarkArea()
{
UpdateSize();
m_bSel = false;//ѡ<><D1A1>״̬
Init();
}
CMarkArea::CMarkArea(Dbxy pt,DbSize size)
{
m_RealBasePt = m_BasePt = pt;//<2F><>׼<EFBFBD><D7BC>
m_Size = size;//<2F>ߴ<EFBFBD>
Init();
}
void CMarkArea::Init()
{
m_AreaIdx = 0;//<2F><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
m_AreaPenNum = 0;//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>obj <20>ıʺ<C4B1>
}
CMarkArea::~CMarkArea(void)
{
}
#if 1
void CMarkArea::Serialize(CArchive& ar)
{
if(ar.IsStoring())
{
ar<<m_BasePt.x;
ar<<m_BasePt.y;
ar<<m_Size.w;
ar<<m_Size.h;
ar<<m_Offset.x;
ar<<m_Offset.y;
}
else
{
ar>>m_BasePt.x;
ar>>m_BasePt.y;
ar>>m_Size.w;
ar>>m_Size.h;
ar>>m_Offset.x;
ar>>m_Offset.y;
}
}
void CMarkArea::WriteWorkFile(vector<CLab> &LabVec)
{
LabVec.push_back(CLab(LAB_NULL,m_BasePt.x));
LabVec.push_back(CLab(LAB_NULL,m_BasePt.y));
LabVec.push_back(CLab(LAB_NULL,m_Size.w));
LabVec.push_back(CLab(LAB_NULL,m_Size.h));
LabVec.push_back(CLab(LAB_NULL,m_Offset.x));
LabVec.push_back(CLab(LAB_NULL,m_Offset.y));
}
void CMarkArea::ReadWorkFile(CLabVecRang &LabVecRang)
{
int idx = LabVecRang.GetStart();
m_BasePt.x = LabVecRang.GetDouble(idx++);
m_BasePt.y = LabVecRang.GetDouble(idx++);
m_Size.w = LabVecRang.GetDouble(idx++);
m_Size.h = LabVecRang.GetDouble(idx++);
m_Offset.x = LabVecRang.GetDouble(idx++);
m_Offset.y = LabVecRang.GetDouble(idx++);
}
//<2F><><EFBFBD>³ߴ<C2B3>Ϊ<EFBFBD>񾵷<EFBFBD>Χ
void CMarkArea::UpdateSize()
{
}
//<2F><>ȡarea <20><><EFBFBD><EFBFBD><EFBFBD>۷<EFBFBD>Χ
DbRect CMarkArea::GetRect()
{
DbRect rect(m_BasePt,m_Size);
return rect;
}
void CMarkArea::Draw(CDC* pDC,bool bSel)
{
CPen pen;
if(bSel || m_bSel)
{
pen.CreatePen(PS_DOT,1,RGB_RED);
}
else
{
pen.CreatePen(PS_DOT,1,RGB_PINK);
}
double Gap = 0;//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
DbSize size = GetSize();
size.w += Gap;
size.h += Gap;
DbRect rect;
rect.Creat(m_BasePt,size);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DrawRect(pDC,pen,rect,false);
//ѡ<><D1A1>״̬ʱ<CCAC><CAB1><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(m_bSel)
{
double GridGap = gDraw->GetAreaGridGap();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mm
Drawgridding(pDC,pen,rect,GridGap);
}
}
bool CMarkArea::DrawObjComponentVec(vector<Sptr<CObjComponent>> &vec,CDC* pDC,bool bSel)
{
vector<Sptr<CObjComponent>>::iterator iter = vec.begin();
vector<Sptr<CObjComponent>>::iterator iter_end = vec.end();
for(;iter!=iter_end;iter++)
{
(*iter)->Draw(pDC);
}
return true;
}
//<2F>Ƿ<EFBFBD><C7B7>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool CMarkArea::HasWorkData()
{
if(m_WorkData.Empty())
return false;
return true;
}
bool CMarkArea::IsPtInArea(Dbxy pt)
{
return IsPointInRect(pt,DbRect(m_BasePt,m_Size));
}
void CMarkArea::SetBasePt(Dbxy pt)
{
m_BasePt = pt;
SetRealBasePt(pt);
}
#endif
#if 1
//<2F><>ȡʵ<C8A1><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
Dbxy CMarkArea::GetRealBasePt()
{
if(m_RealBasePt.Equal(Dbxy(0,0)))
m_RealBasePt = m_BasePt;
return m_RealBasePt;
}
//<2F>Ѽ<EFBFBD><D1BC><EFBFBD>area <20><>Χ<EFBFBD>ڵ<EFBFBD>obj <20><><EFBFBD><EFBFBD>(Product <20>ǵ<EFBFBD>ǰҪ<C7B0>ӹ<EFBFBD><D3B9>Ĺ<EFBFBD><C4B9><EFBFBD>,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>)
void CMarkArea::CollectWorkData(bool bNeedSel)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_WorkData.Clear();
vector<vector<Dbxy>> &WorkDataVec = m_WorkData.GetDataVec();
//<2F><><EFBFBD>Ѽ<EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-----------------------------------
//CollectComponentObj(WorkDataVec,bNeedSel);
//<2F><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2>Ѽ<EFBFBD>layer <20><>obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(WorkDataVec.empty())
{
//<2F><><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>area <20>ڵ<EFBFBD>obj
CObjContainer ObjContainer;
CollectLayerObjExt(ObjContainer,bNeedSel);
int AreaCycleCnt = 1;
for(int k=0;k<AreaCycleCnt;k++)
{
//<2F><>ȡobj <20><><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>(<28><><EFBFBD><EFBFBD>ֵ) <20><>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>layer <20><><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>
ObjContainer.GetObjPtData(WorkDataVec,bNeedSel);
}
}
if(WorkDataVec.empty())
return;
}
//<2F>Ѽ<EFBFBD>layer <20><>obj <20><><EFBFBD><EFBFBD>area <20><>Χ<EFBFBD>ڵ<EFBFBD>obj <20><><EFBFBD><EFBFBD><EBB5BD><EFBFBD><EFBFBD>ObjContainer
void CMarkArea::CollectLayerObjExt(CObjContainer &ObjContainer,bool bNeedSel)
{
//<2F><><EFBFBD><EFBFBD>layer <20><>obj <20><><EFBFBD><EFBFBD>ֱ<EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD>
CObjContainer &LayerObjContainer = gLayer.GetObjContainer();
vector<Sptr<CObjBase>> &ObjVec = LayerObjContainer.GetObjVec();
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ÿ<EFBFBD><C3BF>obj <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>markarea
DbRect Rect = GetRect();
vector<Sptr<CObjBase>>::iterator iter = ObjVec.begin();
vector<Sptr<CObjBase>>::iterator iter_end = ObjVec.end();
for(;iter!=iter_end;iter++)
{
if(!bNeedSel || (bNeedSel && (*iter)->IsSelected()))
{
if((*iter)->IsbMarkPt())//<2F><>Ҫ<EFBFBD>ռ<EFBFBD>mark <20><>
continue;
if(!(*iter)->IsbFillObj())//<2F>˻<EFBFBD><CBBB>豸ֻ<E8B1B8>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
continue;
if(!(*iter)->IsbCollected() && (*iter)->IsInRect(Rect,false))//ֻҪһ<D2AA><D2BB><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>rect <20>ڶ<EFBFBD><DAB6><EFBFBD>
{
(*iter)->SetbCollected(true);//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ռ<EFBFBD>
ObjContainer.AddObject((*iter));
m_AreaPenNum = (*iter)->GetPenNum();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>obj <20>ıʺ<C4B1>
}
}
}
}
//<2F>Ѽ<EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD>obj <20><EFBFBD><E1B1BB><EFBFBD><EFBFBD>,<2C><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>area <20>ظ<EFBFBD><D8B8>ռ<EFBFBD>)
void CMarkArea::CollectComponentObj(vector<vector<Dbxy>> &vec,bool bNeedSel)
{
//<2F>ռ<EFBFBD>area <20>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
gObjComponentMgr->CollectWorkData(GetRect(),vec,bNeedSel);
}
//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>area <20><><EFBFBD><EFBFBD><EFBFBD>ĺͳߴ<CDB3>
void CMarkArea::AdjustByObj()
{
//<2F><><EFBFBD><EFBFBD>area <20>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD>ݷ<EFBFBD>Χ
DbRect DataRect = gObjComponentMgr->SetMarkedStateRect(GetRect(),false);
DbSize size = DataRect.GetSize();
if(size.w>0 && size.h>0)
{
m_BasePt = DataRect.GetCenterPt();
m_Size = size;
}
}
#endif