找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1227|回复: 0

[公告] [ARX 程序]:数据库反应器(database reactor)

[复制链接]
发表于 2002-1-27 22:34:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

  1. #include "rxobject.h"
  2. #include "rxregsvc.h"
  3. #include "rxdlinkr.h"
  4. #include "rxditer.h"
  5. #include "aced.h"
  6. #include "dbmain.h"
  7. #include "dbdict.h"
  8. #include "dbidmap.h"
  9. #include "dbapserv.h"
  10. #include "adslib.h"

  11. void printDbEvent(const AcDbObject*, const char* eventStr);
  12. void printObj(const AcDbObject* pObj);
  13. void watchDb();
  14. void clearReactors();
  15. extern "C"
  16. AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*);

  17. class MyDbReactor;

  18. long gEntAcc = 0;
  19. MyDbReactor *gpDbr = NULL;

  20. class MyDbReactor : public AcDbDatabaseReactor
  21. {
  22. public:

  23.     virtual void objectAppended(const AcDbDatabase* dwg,
  24.         const AcDbObject* dbObj);

  25.     virtual void objectModified(const AcDbDatabase* dwg,
  26.         const AcDbObject* dbObj);

  27.     virtual void objectErased(const AcDbDatabase* dwg,
  28.         const AcDbObject* dbObj, Adesk::Boolean pErased);
  29. };


  30. void
  31. MyDbReactor::objectAppended(const AcDbDatabase* db,
  32.     const AcDbObject* pObj)
  33. {
  34.     printDbEvent(pObj, "objectAppended");
  35.     acutPrintf(" Db==%lx\n", (long) db);
  36.     gEntAcc++;
  37.     acutPrintf("Entity Count = %d\n", gEntAcc);
  38. }


  39. void
  40. MyDbReactor::objectModified(const AcDbDatabase* db,
  41.     const AcDbObject* pObj)
  42. {
  43.     printDbEvent(pObj, "objectModified");
  44.     acutPrintf(" Db==%lx\n", (long) db);
  45. }

  46. void
  47. MyDbReactor::objectErased(const AcDbDatabase* db,
  48.     const AcDbObject* pObj, Adesk::Boolean pErased)
  49. {
  50.     if (pErased) {
  51.         printDbEvent(pObj, "objectErased");
  52.         gEntAcc--;
  53.     } else {
  54.         printDbEvent(pObj, "object(Un)erased");
  55.         gEntAcc++;
  56.     }
  57.     acutPrintf(" Db==%lx\n", (long) db);
  58.     acutPrintf("Entity Count = %d\n", gEntAcc);
  59. }


  60. void
  61. printDbEvent(const AcDbObject* pObj, const char* pEvent)
  62. {
  63.     acutPrintf("  Event: AcDbDatabaseReactor::%s ", pEvent);
  64.     printObj(pObj);
  65. }


  66. void
  67. printObj(const AcDbObject* pObj)
  68. {
  69.     if (pObj == NULL) {
  70.         acutPrintf("(NULL)");
  71.         return;
  72.     }

  73.     AcDbHandle objHand;
  74.     char  handbuf[17];

  75.     pObj->getAcDbHandle(objHand);
  76.     objHand.getIntoAsciiBuffer(handbuf);

  77.     acutPrintf(
  78.         "\n   (class==%s, handle==%s, id==%lx, db==%lx)",
  79.         pObj->isA()->name(), handbuf,
  80.         pObj->objectId().asOldId(), pObj->database());
  81. }


  82. void
  83. watchDb()
  84. {
  85.     if (gpDbr == NULL) {
  86.         gpDbr = new MyDbReactor();
  87.     }
  88.     acdbHostApplicationServices()->workingDatabase()->addReactor(gpDbr);
  89.     acutPrintf(
  90.         "  Added Database Reactor to "
  91.         "acdbHostApplicationServices()->workingDatabase().\n");
  92. }


  93. void
  94. clearReactors()
  95. {
  96.     if (acdbHostApplicationServices()->workingDatabase() != NULL) {
  97.         acdbHostApplicationServices()->workingDatabase()->removeReactor(gpDbr);
  98.         delete gpDbr;
  99.         gpDbr = NULL;
  100.     }
  101. }

  102. AcRx::AppRetCode
  103. acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
  104. {
  105.     switch (msg) {
  106.     case AcRx::kInitAppMsg:
  107.         acrxDynamicLinker->unlockApplication(appId);
  108.                 acrxDynamicLinker->registerAppNotMDIAware(appId);
  109.         acedRegCmds->addCommand("EXAM10A",
  110.             "WATCH",
  111.             "WATCH",
  112.             ACRX_CMD_TRANSPARENT,
  113.             watchDb);

  114.         acedRegCmds->addCommand("EXAM10A",
  115.             "CLEAR",
  116.             "CLEAR",
  117.             ACRX_CMD_TRANSPARENT,
  118.             clearReactors);
  119.         break;
  120.     case AcRx::kUnloadAppMsg:
  121.         clearReactors();
  122.         acedRegCmds->removeGroup("EXAM10A");
  123.         break;
  124.     }
  125.     return AcRx::kRetOK;
  126. }
复制代码
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-22 00:54 , Processed in 0.167986 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表