exam11.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" #include "acdocman.h"
/* void assocLines(); void addToModelSpace(AcDbObjectId&,AcDbEntity *); void initApp(void); void unloadApp(void);
void printDbEvent(const AcDbObject *pObj, const char *pEvent); extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode,void *); */
long gEntAcc=0; 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;
class MyDocReactor:public AcApDocManagerReactor { public: virtual void documentToBeActivated(AcApDocument * pDoc); virtual void documentCreated(AcApDocument * pDoc); virtual void documentToBeDestroyed(AcApDocument * pDoc); };
class MyPerDocData { friend class MyAppDocGlobals; public: MyPerDocData(AcApDocument * pDoc); private: AcApDocument * m_pDoc; MyPerDocData * m_pNext; long m_EntAcc; MyDbReactor * m_pDbr; };
class MyAppDocGlobals { public: MyAppdocGlobals(AcApDocument *pDoc); void setGlobals(AcApDocument *pDoc); void removeDocGlobals(AcApDocument * pDoc); void removeAllDocGlobals(MyPerDocData * pTarget); void unload(); long &entityCount(); void incrementEntityCount(); void decrementEntityCount(); MyDbReactor * gpReactor(); void setDbReactor(MyDbReactor *pDb); private: MyPerDocData *m_pHead; MyPerDocData *m_pData; MyDocReactor *m_pDocReactor; };
MyAppDocGlobals *gpMyAppDocGlobals;
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==%ls\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 MyDocReactor::documentToBeActivated(AcApDocument *pDoc) { gpMyAppDocGlobals->setGlobals(pDoc); }
void MyDocReactor::documentToBeDestroyed(AcApDocument *pDoc) { gpMyAppDocGlobals->removeDocGlobals(pDoc); }
void MyDocReactor::documentCreated(AcApDocument *pDoc) { gpMyAppDocGlobals->setGlobals(pDoc); }
MyPerDocData::MyPerDocData(AcApDocument *pDoc) { m_pDoc=pDoc; m_pNext=NULL; m_EntAcc=0; m_pDbr=NULL; }
MyAppDocGlobals::MyAppdocGlobals(AcApDocument *pDoc) { m_pData=m_pHead=NULL; m_pDocReactor=new MyDocReactor(); acDocManager->addReactor(m_pDocReactor); }
void MyAppDocGlobals::setGlobals(AcApDocument *pDoc) { MyPerDocData *p_data=m_pHead,*prev_data=m_pHead; while(p_data!=NULL) { if(p_data->m_pDoc==pDoc) { m_pData=p_data; break; } prev_data=p_data; p_data=p_data->m_pNext ;
} if(p_data==NULL) { if(m_pHead==NULL) { m_pHead=m_pData=new MyPerDocData(pDoc); } else { prev_data->m_pNext=m_pData=new MyPerDocData(pDoc); } } }
void MyAppDocGlobals::removeDocGlobals(AcApDocument * pDoc) { MyPerDocData *p_data=m_pHead,*prev_data=m_pHead; while(p_data!=NULL) { if(p_data->m_pDoc=pDoc) { if(p_data==m_pHead) { m_pHead=p_data->m_pNext; } else { prev_data->m_pNext=p_data->m_pNext; } if(m_pData==p_data) { m_pData=m_pHead; } delete p_data; break; } prev_data=p_data; p_data=p_data->m_pNext; } }
void MyAppDocGlobals::removeAllDocGlobals (MyPerDocData * p_target) { if(p_target==NULL) { return; } if(p_target->m_pNext!=NULL) { removeAllDocGlobals(p_target->m_pNext ); } if(p_target->m_pDbr!=NULL) { acdbHostApplicationServices()->workingDatabase() ->removeReactor(p_target->m_pDbr ); delete p_target->m_pDbr; p_target->m_pDbr=NULL; } delete p_target; }
void MyAppDocGlobals::unload() { acDocManager->removeReactor(m_pDocReactor); delete m_pDocReactor; removeAllDocGlobals(m_pHead); m_pHead=m_pData=NULL; }
long & MyAppDocGlobals::entityCount() { return m_pData->m_EntAcc; }
void MyAppDocGlobals::incrementEntityCount() { m_pData->m_EntAcc++; }
void MyAppDocGlobals::decrementEntityCount() { m_pData->m_EntAcc--; }
MyDbReactor * MyAppDocGlobals::gpReactor() { return m_pData->m_pDbr; }
void MyAppDocGlobals::setDbReactor(MyDbReactor *pDb) { m_pData->m_pDbr=pDb; }
void watchDb() { MyDbReactor *pDbr; if(gpMyAppDocGlobals->gpReactor()==NULL) { pDbr=new MyDbReactor(); gpMyAppDocGlobals->setDbReactor(pDbr); acdbHostApplicationServices()->workingDatabase() ->addReactor(pDbr); acutPrintf("Added Database Reactor to " "acdbHostApplicationServices()->workingDatabase()\n"); } }
void clearReactors() { MyDbReactor *pDbr; if((pDbr=gpMyAppDocGlobals->gpReactor())!=NULL) { acdbHostApplicationServices()->workingDatabase() ->removeReactor(pDbr); delete pDbr; gpMyAppDocGlobals->setDbReactor(NULL); } }
AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg,void *appId) { switch(msg) { case AcRx::kInitAppMsg: acrxUnlockApplication(appId); acrxRegisterAppMDIAware(appId); gpMyAppDocGlobals=new MyAppDocGlobals(curDoc()); gpMyAppDocGlobals->setGlobals(curDoc()); acedRegCmds->addCommand("EXAM11", "WATCH", "WATCH", ACRX_CMD_MODAL, watchDb); acedRegCmds->addCommand("EXAM11", "CLEAR", "CLEAR", ACRX_CMD_MODAL, clearReactors); break; case AcRx::kUnloadAppMsg: if(gpMyAppDocGlobals!=NULL) { gpMyAppDocGlobals->unload(); delete gpMyAppDocGlobals; gpMyAppDocGlobals=NULL; } acedRegCmds->removeGroup("EXAM11"); break; } return AcRx::kRetOK; }
|