ObjectArxC++鼠标悬停公里标高亮

鼠标悬停在平面图设备上时,相应的公里标会高亮显示。鼠标悬停在设备上时候,会先激活AcDbEntity:highlight(),这是一个虚函数。在C++中虚函数没有函数体,因此调用上一层AcDbEntity::subHighlight(),这也是一个虚函数。因此虚函数是不能执行的,所以继续调用上一层的CthEntity::subHighlight()函数,这个函数是自定义的。该自定义函数继续调用高亮C++中的CthEntityHighlight::subHighlight(),此函数将实体相应的公里标高亮。

主要思路是:

  1. 鼠标悬停在平台图设备上,触发该设备的AcDbEntity:highlight()。
  2. 经过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("CthName"))
					es = pdd->highlight();
				es = pdd->close();
			}
		}
		return Acad::eOk;
	}
	catch (...) {
		CString strMsg;
		//acutPrintf(_T("请检查配置文件%s是否存在 \n"),strFileName);
		strMsg.Format(_T("\n UnKnown Exception in FileName: %s\t,Function=%s\t,Line=%d"), __FILE__,__FUNCTION__,__LINE__);
		AfxMessageBox(strMsg);
	}
}
  • 2.在定义实体CthEntity文件中,实现调用
// 实体亮显声明
virtual Acad::ErrorStatus subHighlight  (const AcDbFullSubentPath& = kNullSubent, const Adesk::Boolean highlightAll = Adesk::kFalse) const;
// 实体亮显
Acad::ErrorStatus CthEntity::subHighlight (const AcDbFullSubentPath& path , const Adesk::Boolean highlightAll) const
{
    AcDbObjectId oi = objectId();
    acdbQueueForRegen(&oi, 1);
    mIsHighlight = true;
	Acad::ErrorStatus es = AcDbEntity::subHighlight(path, highlightAll);
    return Acad::eOk;
}
  • 参考文献:

1.赵安安:ObjectArxC++公里标与坡度曲线配置初始化

2.赵安安:CPP实际经验总结1-20

3.赵安安:CPP实际经验总结21-40

posted @   unicornsir  阅读(17)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示