要实现捡选只要把实体集中的实体选择到捡选集中即可
鼠标经过实体集中是一种艳色,鼠标选中实体后又是一种
艳色,把实体从实体中选择出来,然后再放入选择集中
因此开发一个对实体庥和选择集进行操作的类
typedef struct //与实体指针相关的索引
{
CSolid *m_pickSolid;
int index;//与指针相关联的索引
} PINDEX;
typedef CTypedPtrArray<CObArray, CSolid *> tagCArray;
//本类对实体集和选择集进行操作,包括
class CHandleCG//操作数据集,可以从一个集合里面取出特定元素放入另一个集合
{
public:
CHandleCG(){};
CHandleCG(tagCArray *solid, tagCArray *select);
virtual ~CHandleCG(){};
public:
BOOL IsSelect(CSolid *solid);
void DrawSelect(CDC *pDC, CPosition pos, float dis, int DNormal, int DSelect);//移动出画出图形
void AddSelect();//选择的实体放放选择集中
void DeleteSolid(CDC *pDC);//删除选择的实体
void DeleteAll(CDC *pDC);//把所有的资料全删掉
void Mirror(CPosition &first, CPosition &second, int mode);//镜像,最后一个变量说明是否删除原来的实体
void AddMirror(CPosition &first, CPosition &second, int mode);
private:
tagCArray *m_solid;
tagCArray *m_select;
PINDEX m_pIndex;
tagCArray me;
tagCArray m_select_mirror;
};
CHandleCG::CHandleCG(tagCArray *solid, tagCArray *select)//
{
m_solid = solid;
m_select = select;
m_pIndex.m_pickSolid = NULL;
m_pIndex.index = -1;
}
BOOL CHandleCG::IsSelect(CSolid *solid)//检测是否在元素是否在数据集中
{
if (solid)
{
for (int i = 0; i < m_select->GetSize(); i++)
{
if (solid == (*m_select)[i])
{
return TRUE;
}
}
}
return FALSE;
}
void CHandleCG::DrawSelect(CDC *pDC, CPosition pos, float dis, int DNormal, int DSelect)
{
if (m_pIndex.m_pickSolid && !IsSelect(m_pIndex.m_pickSolid))//IsSelect避免最后一个捡选的图形闪烁
{
m_pIndex.m_pickSolid->DrawSolid(pDC, DNormal);
}
for (int i = 0; i < m_solid->GetSize(); i++)
{
if ( (*m_solid)[i]->PickSolid(pos, dis) )//IsSelect()避免已经捡选的图形闪烁
{
(*m_solid)[i]->DrawSolid(pDC, DSelect);
m_pIndex.m_pickSolid = (*m_solid)[i];
m_pIndex.index = i;
break;
}
}
}
void CHandleCG::AddSelect()
{
if (m_pIndex.m_pickSolid)
{
if (m_solid->GetSize())
{
m_select->Add(m_pIndex.m_pickSolid);//挑选到选择集中
m_solid->RemoveAt(m_pIndex.index);
m_pIndex.m_pickSolid = NULL;
}
}
}
void CHandleCG::DeleteSolid(CDC *pDC)//把选到的元素删掉,m_solid指向选择集的指针
{
if (m_pIndex.m_pickSolid)
{
m_pIndex.m_pickSolid->DrawSolid(pDC, Back);//消除屏幕上的实体
delete m_pIndex.m_pickSolid;
m_solid->RemoveAt(m_pIndex.index);
m_pIndex.m_pickSolid = NULL;
}
}
void CHandleCG::DeleteAll(CDC *pDC)//全删掉
{
for (int i = 0; i < m_select->GetSize(); i++)
{
(*m_select)[i]->DrawSolid(pDC, Back);
delete (*m_select)[i];
}
m_select->RemoveAll();
}
void CHandleCG::Mirror(CPosition &first, CPosition &second, int mode)//指针传递
{
//
CDC * pDC = g_pView->GetDC();
int m = m_select->GetSize();
for (int j = 0; j < m; j++)
{
(*m_select)[j]->Mirror(first, second)->DrawSolid(pDC, mode);
}
g_pView->ReleaseDC(pDC);
}
void CHandleCG::AddMirror(CPosition &first, CPosition &second, int mode)
{
int m = m_select->GetSize();
for (int j = 0; j < m; j++)
{
m_select_mirror.Add( (*m_select)[j]->Mirror(first, second) );
}
Mirror(first, second, mode);
m_select_mirror.RemoveAll();
}