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;//元件的基准点
m_Size = size;//元件的尺寸
Reset();
}
void CObjComponent::Reset()
{
m_bBase = false;//是否为基准元件
m_bSel = false;//是否被选中
m_TempIdx = 0;//使用的数据模板编号
m_bMarked = false;//是否被加工过了
m_bCollected = false;
m_bCircle = false;//是否为圆形
m_bMarkObj = false;//是否为标记的obj
m_bMarkSidewardObj = false;//是否为标记obj 旁边的obj
m_ColorIdx = -1;//颜色索引值
m_ObjMarkIdx = -1;//obj 标记,用来区别是否开孔
m_bAutoCreatObj = false;//是否为自动创建的obj
m_ObjLineIdx = 0;//obj 在line 上的索引值,用来确定相邻line 中obj 的关系
m_bView = false;//是否正在观察
m_bViewed = false;//是否被观察过了
m_bCollecteData = true;//是否需要收集加工数据(false 的时候不收集obj 的数据)
m_Val1 = 0;//记录值1(功率w)
m_Val2 = 0;//记录值2(温度)
}
CObjComponent::~CObjComponent(void)
{
}
DbRect CObjComponent::GetRect()
{
DbRect rect(m_BasePt,m_Size);
return rect;
}
void CObjComponent::Draw(CDC* pDC)
{
//颜色-----------------------------------------------
COLORREF c;
c = m_Color;
//绘制-------------------------------------------------
Dbxy pt = m_BasePt;
DbSize size = m_Size;
DbRect rect = GetRect();
DrawSolidRect(pDC,c,rect);
}
COLORREF CObjComponent::GetObjColorByIdx(int Idx)
{
COLORREF c = RGB_GREEN;
//渐变色
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;
}
//是否在鼠标选择范围(bCenterIn 表示中心点在rect 范围内)
bool CObjComponent::IsInRect(DbRect rect,bool bCenterIn)
{
if(bCenterIn && !m_bCollecteData)//收集数据的时候不要
return false;
DbRect ObjRect = GetRect();
bool ret;
if(bCenterIn)
ret = IsPointInRect(ObjRect.GetCenterPt(),rect);//obj 的中心点必须在rect 内
else
ret = IsTwoRectIntersect(ObjRect,rect)||IsTwoRectIntersect(rect,ObjRect);//挂到obj 的边就算
return ret;
}
//设置mark 标记
void CObjComponent::SetObjMarkIdx(bool b)
{
m_ObjMarkIdx = b?1:2;
}
//添加绑定的layer obj
void CObjComponent::AddObjShape(Sptr<CObjBase> p)
{
m_ObjShapeVec.push_back(p);
}
//设置选中状态
void CObjComponent::SetSelected(bool b)
{
m_bSel = b;
#if 0
//同时设置绑定layer obj 的选择状态
vector<Sptr<CObjBase>>::iterator iter = m_ObjShapeVec.begin();
vector<Sptr<CObjBase>>::iterator iter_end = m_ObjShapeVec.end();
{
(*iter)->SetSelected(b);
}
#endif
}
//设置绑定layer obj 的锁定状态
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);
}
}
//收集工作数据(目前的算法会比较慢)
void CObjComponent::CollectWorkData(DbRect &rect,vector<vector<Dbxy>> &vec)
{
if(!m_bCollecteData)
return;
if(m_bCollected)//不要重复收集
return;
//是否在数据收集范围
if(!IsInRect(rect,true))//搜集数据的时候按中心点来判断
return;
//先收集模板的数据
vector<vector<Dbxy>> VecTmp;//数据容器
bool bUseTemplateData = m_ObjShapeVec.empty();//是否使用模板数据(相对于0,0 点的模板)
if(bUseTemplateData)
{
gTemplateMgr->CollectWorkData(m_TempIdx,VecTmp);//模板数据
}
else//绑定layer obj 对象时
{
vector<Sptr<CObjBase>>::iterator iter = m_ObjShapeVec.begin();
vector<Sptr<CObjBase>>::iterator iter_end = m_ObjShapeVec.end();
{
(*iter)->GetPtData(VecTmp);
}
}
int cnt = 1;//单个元件加工次数
vector<Dbxy> PointVec;
bool bConnectObj = gCommonFlowMgr->IsbConnectObj();//是否连接多个obj 数据
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);
//模板数据需要转换为元件中心的数据(绑定的layer obj 数据不需要转换)
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;
}