exam10a.cpp代码:
#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 objectModifier(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::objectModifier(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; }
|