ObjectArxC++鼠标悬停公里标高亮
鼠标悬停在平面图设备上时,相应的公里标会高亮显示。鼠标悬停在设备上时候,会先激活AcDbEntity:highlight(),这是一个虚函数。在C++中虚函数没有函数体,因此调用上一层AcDbEntity::subHighlight(),这也是一个虚函数。因此虚函数是不能执行的,所以继续调用上一层的CthEntity::subHighlight()函数,这个函数是自定义的。该自定义函数继续调用高亮C++中的CthEntityHighlight::subHighlight(),此函数将实体相应的公里标高亮。
主要思路是:
- 鼠标悬停在平台图设备上,触发该设备的AcDbEntity:highlight()。
- 经过AcDbEntity:highlight()的一系列虚函数调用,最终调用CthEntityHighlight::subHighlight()。
时序图如下:

代码示例如下:
- 1.在高亮CthEntityHighlight文件中的subHighlight()函数,实现了高亮的功能。
// 实体亮显声明
virtual Acad::ErrorStatus subHighlight (const AcDbFullSubentPath& = kNullSubent, const Adesk::Boolean highlightAll = Adesk::kFalse) const;
// 实体亮显
Acad::ErrorStatus CthEntityHighlight::subHighlight (const AcDbFullSubentPath& path , const Adesk::Boolean highlightAll) const
{
try
{
AcDbObjectId oi = objectId();
acdbQueueForRegen(&oi, 1);
mIsHighlight = true;
Acad::ErrorStatus es = AcDbEntity::subHighlight(path, highlightAll);
const AcDbVoidPtrArray* rs = reactors();
if (rs != NULL) {
for (int i = 0; i < rs->length(); i++)
{
void* pSomething = rs->at(i);
AcDbObjectId did = acdbPersistentReactorObjectId(pSomething);
//获取实体的反应器-公里标图元
CthDependency* pd;
es = acdbOpenObject(pd, did, AcDb::kForRead, Adesk::kTrue);
if (es != Acad::eOk)
continue;
CthPoint* pdd;
//获取反应器的所属对象-公里标
es = acdbOpenObject(pdd, pd->dependencyId(), AcDb::kForRead, Adesk::kTrue);
pd->close();
if (es != Acad::eOk)
continue;
AcString name = pdd->isA()->name();
if (name == _T("CthDimension"))
es = pdd->highlight();
else if (name == _T("CthRailTerminal"))
es = pdd->highlight();
else if (name == _T(