155 lines
3.2 KiB
C++
155 lines
3.2 KiB
C++
#include "stdafx.h"
|
|
#include "KTEntityDumb.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
ACRX_DXF_DEFINE_MEMBERS(CKTEntityDumb, AcDbEntity,
|
|
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
|
AcDbProxyEntity::kAllAllowedBits, KT_DUMBENTITY,
|
|
KTCadKernel.dll);
|
|
|
|
// 默认构造函数
|
|
CKTEntityDumb::CKTEntityDumb(BOOL bAutoRelease)
|
|
: CKTObjLifeMgr(FALSE)
|
|
{
|
|
m_bAutoRelease = bAutoRelease;
|
|
}
|
|
|
|
// 构造函数, 加入管理实体
|
|
CKTEntityDumb::CKTEntityDumb(AcDbEntity* pEnt, BOOL bAutoRelease)
|
|
: CKTObjLifeMgr(pEnt, FALSE)
|
|
{
|
|
m_bAutoRelease = bAutoRelease;
|
|
}
|
|
|
|
// 构造函数, 加入管理实体
|
|
CKTEntityDumb::CKTEntityDumb(const AcDbVoidPtrArray& arpEnts, BOOL bAutoRelease)
|
|
: CKTObjLifeMgr(arpEnts, FALSE)
|
|
{
|
|
m_bAutoRelease = bAutoRelease;
|
|
}
|
|
|
|
// 构造函数, 加入管理实体
|
|
CKTEntityDumb::CKTEntityDumb(const AcDbObjectId& idEnt, BOOL bAutoRelease)
|
|
: CKTObjLifeMgr(idEnt, FALSE)
|
|
{
|
|
m_bAutoRelease = bAutoRelease;
|
|
}
|
|
|
|
// 构造函数, 加入管理实体
|
|
CKTEntityDumb::CKTEntityDumb(const AcDbObjectIdArray& aridEnts, BOOL bAutoRelease)
|
|
: CKTObjLifeMgr(aridEnts, FALSE)
|
|
{
|
|
m_bAutoRelease = bAutoRelease;
|
|
}
|
|
|
|
// 析构函数
|
|
CKTEntityDumb::~CKTEntityDumb()
|
|
{
|
|
if (m_bAutoRelease)
|
|
CKTObjLifeMgr::Release(FALSE);
|
|
else
|
|
CKTObjLifeMgr::Remove();
|
|
}
|
|
|
|
// 判断是否自动close/delete管理的实体
|
|
BOOL CKTEntityDumb::IsAutoRelease()
|
|
{
|
|
return m_bAutoRelease;
|
|
}
|
|
|
|
// 设置自动close/delete标志
|
|
void CKTEntityDumb::EnableAutoRelease(BOOL bEnable)
|
|
{
|
|
m_bAutoRelease = bEnable;
|
|
}
|
|
|
|
// 实体被添加
|
|
void CKTEntityDumb::OnObjectAdded(AcDbObject* pObj)
|
|
{
|
|
AcDbEntity* pEnt = AcDbEntity::cast(pObj);
|
|
if (pEnt != NULL && pEnt->database() == NULL)
|
|
{
|
|
if (pEnt->isWriteEnabled())
|
|
pEnt->setDatabaseDefaults(acdbHostApplicationServices()->workingDatabase());
|
|
else if (pEnt->upgradeOpen() == Acad::eOk)
|
|
{
|
|
pEnt->setDatabaseDefaults(acdbHostApplicationServices()->workingDatabase());
|
|
pEnt->downgradeOpen();
|
|
}
|
|
}
|
|
}
|
|
|
|
Acad::ErrorStatus CKTEntityDumb::subTransformBy(const AcGeMatrix3d& xform)
|
|
{
|
|
assertWriteEnabled();
|
|
|
|
AcDbEntity* pEnt;
|
|
int iLen = CKTObjLifeMgr::GetCount();
|
|
for (int i = 0; i < iLen; i++)
|
|
{
|
|
pEnt = AcDbEntity::cast(CKTObjLifeMgr::Get(i));
|
|
if (pEnt == NULL)
|
|
continue;
|
|
|
|
if (pEnt->isWriteEnabled())
|
|
{
|
|
pEnt->transformBy(xform);
|
|
}
|
|
else
|
|
{
|
|
if (pEnt->upgradeOpen() == Acad::eOk)
|
|
{
|
|
pEnt->transformBy(xform);
|
|
pEnt->downgradeOpen();
|
|
}
|
|
}
|
|
}
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
void CKTEntityDumb::subViewportDraw(AcGiViewportDraw* mode)
|
|
{
|
|
assertReadEnabled();
|
|
|
|
AcDbEntity* pEnt;
|
|
int iLen = CKTObjLifeMgr::GetCount();
|
|
for (int i = 0; i < iLen; i++)
|
|
{
|
|
pEnt = AcDbEntity::cast(CKTObjLifeMgr::Get(i));
|
|
if (pEnt == NULL)
|
|
continue;
|
|
|
|
if (pEnt->objectId().isValid())
|
|
pEnt->draw();
|
|
else
|
|
mode->geometry().draw(pEnt->drawable());
|
|
}
|
|
}
|
|
|
|
Adesk::Boolean CKTEntityDumb::subWorldDraw(AcGiWorldDraw* mode)
|
|
{
|
|
assertReadEnabled();
|
|
|
|
AcDbEntity* pEnt;
|
|
int iLen = CKTObjLifeMgr::GetCount();
|
|
for (int i = 0; i < iLen; i++)
|
|
{
|
|
pEnt = AcDbEntity::cast(CKTObjLifeMgr::Get(i));
|
|
if (pEnt == NULL)
|
|
continue;
|
|
|
|
if (pEnt->objectId().isValid())
|
|
pEnt->draw();
|
|
else
|
|
mode->geometry().draw(pEnt->drawable());
|
|
}
|
|
|
|
return Adesk::kTrue;
|
|
}
|