#include "stdafx.h" #include "KTAdsEntity.h" #include "KTAdsPickSet.h" #include "KTCadDebug.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif // 默认构造函数 CKTAdsEntity::CKTAdsEntity() : m_bHighlight(FALSE), m_bGriplight(FALSE) { ZeroMemory(m_adsName, sizeof(ads_name)); } // 构造函数,拷贝构造 CKTAdsEntity::CKTAdsEntity(const CKTAdsEntity& cEnt) : m_bHighlight(FALSE), m_bGriplight(FALSE) { CopyMemory(m_adsName, cEnt.m_adsName, sizeof(ads_name)); } // 构造函数,传入ID CKTAdsEntity::CKTAdsEntity(const AcDbObjectId& idEnt) : m_bHighlight(FALSE), m_bGriplight(FALSE) { acdbGetAdsName(m_adsName, idEnt); } // 构造函数,传入handle CKTAdsEntity::CKTAdsEntity(const AcDbHandle& handle) : m_bHighlight(FALSE), m_bGriplight(FALSE) { TCHAR szHandle[10]; handle.getIntoAsciiBuffer(szHandle); acdbHandEnt(szHandle, m_adsName); } // 构造函数,传入ads_name CKTAdsEntity::CKTAdsEntity(const ads_name adsName) : m_bHighlight(FALSE), m_bGriplight(FALSE) { CopyMemory(m_adsName, adsName, sizeof(ads_name)); } // 析构函数 CKTAdsEntity::~CKTAdsEntity() { if (m_bHighlight) Highlight(FALSE); if (m_bGriplight) Griplight(FALSE); } // 从旧的ID方式获得ads_name #ifdef _WIN64 CKTAdsEntity& CKTAdsEntity::SetFromOldId(__int64 lOldId) { AcDbObjectId id; id.setFromOldId(lOldId); acdbGetAdsName(m_adsName, id); return (*this); } #else CKTAdsEntity& CKTAdsEntity::SetFromOldId(long lOldId) { AcDbObjectId id; id.setFromOldId(lOldId); acdbGetAdsName(m_adsName, id); return (*this); } #endif // 从Handle字符串方式获得ads_name CKTAdsEntity& CKTAdsEntity::SetFromHandle(LPCTSTR pszHandle) { acdbHandEnt(pszHandle, m_adsName); return (*this); } // 获取旧的ID值 Adesk::IntDbId CKTAdsEntity::AsOldId() const { AcDbObjectId id; acdbGetObjectId(id, m_adsName); return id.asOldId(); } // 取得ads_name void CKTAdsEntity::GetAdsName(ads_name adsName) const { CopyMemory(adsName, m_adsName, sizeof(ads_name)); } // 取得AcDbObjectId void CKTAdsEntity::GetObjectId(AcDbObjectId& idEnt) const { acdbGetObjectId(idEnt, m_adsName); } // 获得与之关联的Handle AcDbHandle CKTAdsEntity::Handle() const { AcDbObjectId id; acdbGetObjectId(id, m_adsName); return id.handle(); } // 判断是否有效 bool CKTAdsEntity::IsValid() const { AcDbObjectId id; acdbGetObjectId(id, m_adsName); return id.isValid(); } // 判断是否被删除 bool CKTAdsEntity::IsErased() const { AcDbObjectId id; acdbGetObjectId(id, m_adsName); return id.isErased(); } // 设置高亮显示 void CKTAdsEntity::Highlight(BOOL bHighlight, BOOL bUpdate) { m_bHighlight = (bHighlight && bUpdate); if (bUpdate) { acedRedraw(m_adsName, (bHighlight ? 3 : 4)); } } // 设置夹点显示 void CKTAdsEntity::Griplight(BOOL bGriplight, BOOL bUpdate) { BOOL bNoCmd = (curDoc() != NULL && curDoc()->isQuiescent()); m_bGriplight = (bGriplight && bUpdate && bNoCmd); if (bUpdate && bNoCmd) { struct resbuf* pRbGrip = NULL; struct resbuf* pRbPick = NULL; acedSSGetFirst(&pRbGrip, &pRbPick); CKTAdsPickSet ssGrip, ssPick; struct resbuf* pRb; for (pRb = pRbGrip; pRb != NULL; pRb = pRb->rbnext) { if (pRb->restype == RTPICKS) { ssGrip += pRb->resval.rlname; acedSSFree(pRb->resval.rlname); } } acutRelRb(pRbGrip); // for (pRb = pRbPick; pRb != NULL; pRb = pRb->rbnext) { if (pRb->restype == RTPICKS) { ssPick += pRb->resval.rlname; acedSSFree(pRb->resval.rlname); } } acutRelRb(pRbPick); CKTAdsEntity adsEnt(m_adsName); if (bGriplight) { ssGrip += adsEnt; ssPick += adsEnt; } else { ssGrip -= adsEnt; ssPick -= adsEnt; } acedSSSetFirst((ssGrip.IsEmpty() ? NULL : ssGrip), (ssPick.IsEmpty() ? NULL : ssPick)); } } // 重载运算符号= CKTAdsEntity& CKTAdsEntity::operator=(const CKTAdsEntity& adsEnt) { CopyMemory(m_adsName, adsEnt.m_adsName, sizeof(ads_name)); return (*this); } CKTAdsEntity& CKTAdsEntity::operator=(const AcDbObjectId& idEnt) { acdbGetAdsName(m_adsName, idEnt); return (*this); } CKTAdsEntity& CKTAdsEntity::operator=(const AcDbHandle& handle) { TCHAR szHandle[10]; handle.getIntoAsciiBuffer(szHandle); acdbHandEnt(szHandle, m_adsName); return (*this); } CKTAdsEntity& CKTAdsEntity::operator=(const ads_name adsName) { CopyMemory(m_adsName, adsName, sizeof(ads_name)); return (*this); } CKTAdsEntity& CKTAdsEntity::operator=(int iNull) { KTASSERT(iNull == NULL); ZeroMemory(m_adsName, sizeof(ads_name)); return (*this); } // 重载运算符号 CKTAdsEntity::operator AcDbObjectId() { AcDbObjectId id; acdbGetObjectId(id, m_adsName); return id; } CKTAdsEntity::operator AcDbHandle() { AcDbObjectId id; acdbGetObjectId(id, m_adsName); return id.handle(); } // 重载运算符号== bool CKTAdsEntity::operator==(const CKTAdsEntity& adsEnt) const { AcDbObjectId id1, id2; acdbGetObjectId(id1, m_adsName); acdbGetObjectId(id2, adsEnt.m_adsName); return (id1 == id2); } bool CKTAdsEntity::operator==(const AcDbObjectId& idEnt) const { AcDbObjectId id; acdbGetObjectId(id, m_adsName); return (id == idEnt); } bool CKTAdsEntity::operator==(const AcDbHandle& handle) const { AcDbObjectId id; acdbGetObjectId(id, m_adsName); return (id.handle() == handle); } bool CKTAdsEntity::operator==(const ads_name adsName) const { AcDbObjectId id1, id2; acdbGetObjectId(id1, m_adsName); acdbGetObjectId(id2, adsName); return (id1 == id2); } bool CKTAdsEntity::operator==(int iNull) const { KTASSERT(iNull == NULL); AcDbObjectId id; acdbGetObjectId(id, m_adsName); return id.isNull(); }