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.

191 lines
5.2 KiB
C++

#include "StdAfx.h"
#include "ObjComponent.h"
#include "DrawSimpleShape.h"
#include "GlobalFunction.h"
#include "TemplateMgr.h"
#include "ObjComponentMgr.h"
#include "CommonFlowMgr.h"
CObjComponent::CObjComponent()
{
m_Size.w = 5;
m_Size.h = 4.2;
Reset();
}
CObjComponent::CObjComponent(Dbxy pt,DbSize size)
{
m_BasePt = pt;//Ԫ<><D4AA><EFBFBD>Ļ<EFBFBD>׼<EFBFBD><D7BC>
m_Size = size;//Ԫ<><D4AA><EFBFBD>ijߴ<C4B3>
Reset();
}
void CObjComponent::Reset()
{
m_bBase = false;//<2F>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA>׼Ԫ<D7BC><D4AA>
m_bSel = false;//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>ѡ<EFBFBD><D1A1>
m_TempIdx = 0;//ʹ<>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_bMarked = false;//<2F>Ƿ񱻼ӹ<F1B1BBBC><D3B9><EFBFBD><EFBFBD><EFBFBD>
m_bCollected = false;
m_bCircle = false;//<2F>Ƿ<EFBFBD>ΪԲ<CEAA><D4B2>
m_bMarkObj = false;//<2F>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ǵ<EFBFBD>obj
m_bMarkSidewardObj = false;//<2F>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>obj <20>Աߵ<D4B1>obj
m_ColorIdx = -1;//<2F><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>ֵ
m_ObjMarkIdx = -1;//obj <20><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ񿪿<C7B7>
m_bAutoCreatObj = false;//<2F>Ƿ<EFBFBD>Ϊ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>obj
m_ObjLineIdx = 0;//obj <20><>line <20>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>ֵ,<2C><><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>line <20><>obj <20>Ĺ<EFBFBD>ϵ
m_bView = false;//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڹ۲<DAB9>
m_bViewed = false;//<2F>Ƿ񱻹۲<F1B1BBB9><DBB2><EFBFBD><EFBFBD><EFBFBD>
m_bCollecteData = true;//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD>ռ<EFBFBD><D5BC>ӹ<EFBFBD><D3B9><EFBFBD><EFBFBD><EFBFBD>(false <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
m_Val1 = 0;//<2F><>¼ֵ1(<28><><EFBFBD><EFBFBD>w)
m_Val2 = 0;//<2F><>¼ֵ2(<28><EFBFBD>)
}
CObjComponent::~CObjComponent(void)
{
}
DbRect CObjComponent::GetRect()
{
DbRect rect(m_BasePt,m_Size);
return rect;
}
void CObjComponent::Draw(CDC* pDC)
{
//<2F><>ɫ-----------------------------------------------
COLORREF c;
c = m_Color;
//<2F><><EFBFBD><EFBFBD>-------------------------------------------------
Dbxy pt = m_BasePt;
DbSize size = m_Size;
DbRect rect = GetRect();
DrawSolidRect(pDC,c,rect);
}
COLORREF CObjComponent::GetObjColorByIdx(int Idx)
{
COLORREF c = RGB_GREEN;
//<2F><><EFBFBD><EFBFBD>ɫ
int r = GetRValue(c)+30*Idx;
int g = GetGValue(c)+30*Idx;
int b = GetBValue(c)+30*Idx;
COLORREF Color = RGB(r,g,b);
return Color;
}
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>Χ(bCenterIn <20><>ʾ<EFBFBD><CABE><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>rect <20><>Χ<EFBFBD><CEA7>)
bool CObjComponent::IsInRect(DbRect rect,bool bCenterIn)
{
if(bCenterIn && !m_bCollecteData)//<2F>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD>ݵ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Ҫ
return false;
DbRect ObjRect = GetRect();
bool ret;
if(bCenterIn)
ret = IsPointInRect(ObjRect.GetCenterPt(),rect);//obj <20><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>rect <20><>
else
ret = IsTwoRectIntersect(ObjRect,rect)||IsTwoRectIntersect(rect,ObjRect);//<2F>ҵ<EFBFBD>obj <20>ı߾<C4B1><DFBE><EFBFBD>
return ret;
}
//<2F><><EFBFBD><EFBFBD>mark <20><><EFBFBD><EFBFBD>
void CObjComponent::SetObjMarkIdx(bool b)
{
m_ObjMarkIdx = b?1:2;
}
//<2F><><EFBFBD>Ӱ󶨵<D3B0>layer obj
void CObjComponent::AddObjShape(Sptr<CObjBase> p)
{
m_ObjShapeVec.push_back(p);
}
//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>״̬
void CObjComponent::SetSelected(bool b)
{
m_bSel = b;
#if 0
//ͬʱ<CDAC><CAB1><EFBFBD>ð<EFBFBD><C3B0><EFBFBD>layer obj <20><>ѡ<EFBFBD><D1A1>״̬
vector<Sptr<CObjBase>>::iterator iter = m_ObjShapeVec.begin();
vector<Sptr<CObjBase>>::iterator iter_end = m_ObjShapeVec.end();
{
(*iter)->SetSelected(b);
}
#endif
}
//<2F><><EFBFBD>ð<EFBFBD><C3B0><EFBFBD>layer obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
void CObjComponent::SetShapeLockState(bool b)
{
vector<Sptr<CObjBase>>::iterator iter = m_ObjShapeVec.begin();
vector<Sptr<CObjBase>>::iterator iter_end = m_ObjShapeVec.end();
{
(*iter)->SetLock(b);
}
}
//<2F>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(Ŀǰ<C4BF><C7B0><EFBFBD><EFBFBD><E3B7A8><EFBFBD>Ƚ<EFBFBD><C8BD><EFBFBD>)
void CObjComponent::CollectWorkData(DbRect &rect,vector<vector<Dbxy>> &vec)
{
if(!m_bCollecteData)
return;
if(m_bCollected)//<2F><>Ҫ<EFBFBD>ظ<EFBFBD><D8B8>ռ<EFBFBD>
return;
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD>Χ
if(!IsInRect(rect,true))//<2F>Ѽ<EFBFBD><D1BC><EFBFBD><EFBFBD>ݵ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>ж<EFBFBD>
return;
//<2F><><EFBFBD>ռ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
vector<vector<Dbxy>> VecTmp;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool bUseTemplateData = m_ObjShapeVec.empty();//<2F>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0,0 <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>)
if(bUseTemplateData)
{
gTemplateMgr->CollectWorkData(m_TempIdx,VecTmp);//ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
else//<2F><><EFBFBD><EFBFBD>layer obj <20><><EFBFBD><EFBFBD>ʱ
{
vector<Sptr<CObjBase>>::iterator iter = m_ObjShapeVec.begin();
vector<Sptr<CObjBase>>::iterator iter_end = m_ObjShapeVec.end();
{
(*iter)->GetPtData(VecTmp);
}
}
int cnt = 1;//<2F><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD><EFBFBD><EFBFBD>
vector<Dbxy> PointVec;
bool bConnectObj = gCommonFlowMgr->IsbConnectObj();//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD>obj <20><><EFBFBD><EFBFBD>
for(int i=0;i<cnt;i++)
{
vector<vector<Dbxy>>::iterator iter = VecTmp.begin();
vector<vector<Dbxy>>::iterator iter_end = VecTmp.end();
for(;iter!=iter_end;iter++)
{
if(!bConnectObj)
{
PointVec.clear();
}
vector<Dbxy>::iterator iter1 = (*iter).begin();
vector<Dbxy>::iterator iter1_end = (*iter).end();
for(;iter1!=iter1_end;iter1++)
{
Dbxy pt = (*iter1);
//ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫת<D2AA><D7AA>ΪԪ<CEAA><D4AA><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>(<28>󶨵<EFBFBD>layer obj <20><><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD>Ҫת<D2AA><D7AA>)
if(bUseTemplateData)
{
pt.x += m_BasePt.x;
pt.y += m_BasePt.y;
}
PointVec.push_back(pt);
}
if(!bConnectObj)
{
vec.push_back(PointVec);
}
}
}
if(bConnectObj)
{
vec.push_back(PointVec);
}
m_bCollected = true;
}