- UID
- 319
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-11
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- #include "rxobject.h"
- #include "rxregsvc.h"
- #include "rxdlinkr.h"
- #include "rxditer.h"
- #include "aced.h"
- #include "dbmain.h"
- #include "dbdict.h"
- #include "dbidmap.h"
- #include "dbapserv.h"
- #include "adslib.h"
- void printDbEvent(const AcDbObject*, const char* eventStr);
- void printObj(const AcDbObject* pObj);
- void watchDb();
- void clearReactors();
- extern "C"
- AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*);
- class MyDbReactor;
- long gEntAcc = 0;
- MyDbReactor *gpDbr = NULL;
- class MyDbReactor : public AcDbDatabaseReactor
- {
- public:
- virtual void objectAppended(const AcDbDatabase* dwg,
- const AcDbObject* dbObj);
- virtual void objectModified(const AcDbDatabase* dwg,
- const AcDbObject* dbObj);
- virtual void objectErased(const AcDbDatabase* dwg,
- const AcDbObject* dbObj, Adesk::Boolean pErased);
- };
- void
- MyDbReactor::objectAppended(const AcDbDatabase* db,
- const AcDbObject* pObj)
- {
- printDbEvent(pObj, "objectAppended");
- acutPrintf(" Db==%lx\n", (long) db);
- gEntAcc++;
- acutPrintf("Entity Count = %d\n", gEntAcc);
- }
- void
- MyDbReactor::objectModified(const AcDbDatabase* db,
- const AcDbObject* pObj)
- {
- printDbEvent(pObj, "objectModified");
- acutPrintf(" Db==%lx\n", (long) db);
- }
- void
- MyDbReactor::objectErased(const AcDbDatabase* db,
- const AcDbObject* pObj, Adesk::Boolean pErased)
- {
- if (pErased) {
- printDbEvent(pObj, "objectErased");
- gEntAcc--;
- } else {
- printDbEvent(pObj, "object(Un)erased");
- gEntAcc++;
- }
- acutPrintf(" Db==%lx\n", (long) db);
- acutPrintf("Entity Count = %d\n", gEntAcc);
- }
- void
- printDbEvent(const AcDbObject* pObj, const char* pEvent)
- {
- acutPrintf(" Event: AcDbDatabaseReactor::%s ", pEvent);
- printObj(pObj);
- }
- void
- printObj(const AcDbObject* pObj)
- {
- if (pObj == NULL) {
- acutPrintf("(NULL)");
- return;
- }
- AcDbHandle objHand;
- char handbuf[17];
- pObj->getAcDbHandle(objHand);
- objHand.getIntoAsciiBuffer(handbuf);
- acutPrintf(
- "\n (class==%s, handle==%s, id==%lx, db==%lx)",
- pObj->isA()->name(), handbuf,
- pObj->objectId().asOldId(), pObj->database());
- }
- void
- watchDb()
- {
- if (gpDbr == NULL) {
- gpDbr = new MyDbReactor();
- }
- acdbHostApplicationServices()->workingDatabase()->addReactor(gpDbr);
- acutPrintf(
- " Added Database Reactor to "
- "acdbHostApplicationServices()->workingDatabase().\n");
- }
- void
- clearReactors()
- {
- if (acdbHostApplicationServices()->workingDatabase() != NULL) {
- acdbHostApplicationServices()->workingDatabase()->removeReactor(gpDbr);
- delete gpDbr;
- gpDbr = NULL;
- }
- }
- AcRx::AppRetCode
- acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
- {
- switch (msg) {
- case AcRx::kInitAppMsg:
- acrxDynamicLinker->unlockApplication(appId);
- acrxDynamicLinker->registerAppNotMDIAware(appId);
- acedRegCmds->addCommand("EXAM10A",
- "WATCH",
- "WATCH",
- ACRX_CMD_TRANSPARENT,
- watchDb);
- acedRegCmds->addCommand("EXAM10A",
- "CLEAR",
- "CLEAR",
- ACRX_CMD_TRANSPARENT,
- clearReactors);
- break;
- case AcRx::kUnloadAppMsg:
- clearReactors();
- acedRegCmds->removeGroup("EXAM10A");
- break;
- }
- return AcRx::kRetOK;
- }
复制代码 |
|