反应器实例
<P>exam10a.cpp代码:</P><P>#include "rxobject.h"<BR>#include "rxregsvc.h"<BR>#include "rxdlinkr.h"<BR>#include "rxditer.h"<BR>#include "aced.h"<BR>#include "dbmain.h"<BR>#include "dbdict.h"<BR>#include "dbidmap.h"<BR>#include "dbapserv.h"<BR>#include "adslib.h"</P>
<P>void printDbEvent(const AcDbObject *,const char * eventStr);<BR>void printObj(const AcDbObject * pObj);<BR>void watchDb();<BR>void clearReactors();<BR>extern "C" <BR>AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode ,void *);</P>
<P>class MyDbReactor;<BR>long gEntAcc =0;<BR>MyDbReactor *gpDbr=NULL;</P>
<P>class MyDbReactor :public AcDbDatabaseReactor<BR>{<BR>public:<BR> virtual void objectAppended(const AcDbDatabase * dwg,<BR> const AcDbObject *dbObj);<BR> virtual void objectModifier(const AcDbDatabase * dwg,<BR> const AcDbObject *dbObj);<BR> virtual void objectErased(const AcDbDatabase * dwg,<BR> const AcDbObject * dbObj,Adesk::Boolean pErased);<BR>};</P>
<P>void MyDbReactor::objectAppended(const AcDbDatabase * db,<BR> const AcDbObject *pObj)<BR>{<BR> printDbEvent(pObj,"objectAppended");<BR> acutPrintf("db==%lx\n",(long)db);<BR> gEntAcc++;<BR> acutPrintf("Entity Count=%d\n",gEntAcc);<BR>}</P>
<P>void MyDbReactor::objectModifier(const AcDbDatabase *db,<BR> const AcDbObject *pObj)<BR>{<BR> printDbEvent(pObj,"objectModified");<BR> acutPrintf("db==%=%lx\n",(long)db);<BR>}</P>
<P>void MyDbReactor::objectErased(const AcDbDatabase * db,<BR> const AcDbObject *pObj,<BR> Adesk::Boolean pErased)<BR>{<BR> if(pErased)<BR> {<BR> printDbEvent(pObj,"objectErased");<BR> gEntAcc--;<BR> }<BR> else<BR> {<BR> printDbEvent(pObj,"object (un)erased");<BR> gEntAcc++;<BR> }<BR> acutPrintf("Db=%lx\n",(long)db);<BR> acutPrintf("Entity Count=%d\n",gEntAcc);<BR>}</P>
<P>void printDbEvent(const AcDbObject * pObj,<BR> const char * pEvent)<BR>{<BR> acutPrintf("Event::AcDbDatabaseReactor::%s",pEvent);<BR> printObj(pObj);<BR>}</P>
<P>void printObj(const AcDbObject *pObj)<BR>{<BR> if(pObj==NULL)<BR> {<BR> acutPrintf("(NULL)");<BR> return;<BR> }</P>
<P> AcDbHandle objHand;<BR> char handbuf;</P>
<P> pObj->getAcDbHandle(objHand);<BR> objHand.getIntoAsciiBuffer(handbuf);<BR> acutPrintf("\n (class==%s,handle==%s,id==%lx,db==%lx)",<BR> pObj->isA()->name(),handbuf,<BR> pObj->objectId().asOldId(),pObj->database());<BR>}</P>
<P>void watchDb()<BR>{<BR> if(gpDbr==NULL)<BR> {<BR> gpDbr=new MyDbReactor();<BR> }<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->addReactor(gpDbr);<BR> acutPrintf("Added Database Reactor to"<BR> "acdbHostApplicationServices()->workingDatabase().\n");<BR>}</P>
<P>void clearReactors()<BR>{<BR> if(acdbHostApplicationServices()->workingDatabase()!=NULL)<BR> {<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->removeReactor(gpDbr);<BR> delete gpDbr;<BR> gpDbr=NULL;<BR> }<BR>}</P>
<P><BR>AcRx::AppRetCode<BR>acrxEntryPoint(AcRx::AppMsgCode msg,void * appId)<BR>{<BR> switch(msg)<BR> {<BR> case AcRx::kInitAppMsg:<BR> acrxDynamicLinker->unlockApplication(appId);<BR> acrxDynamicLinker->registerAppNotMDIAware(appId);<BR> acedRegCmds->addCommand("EXAM10A",<BR> "WATCH",<BR> "WATCH",<BR> ACRX_CMD_TRANSPARENT,<BR> watchDb);<BR> acedRegCmds->addCommand("EXAM10A",<BR> "CLEAR",<BR> "CLEAR",<BR> ACRX_CMD_TRANSPARENT,<BR> clearReactors);<BR> break;<BR> case AcRx::kUnloadAppMsg:<BR> clearReactors();<BR> acedRegCmds->removeGroup("EXAM10A");<BR> break;<BR> }<BR> return AcRx::kRetOK;<BR>}</P> <P>exam10a.def代码:</P>
<P>LIBRARY exam10a<BR>DESCRIPTION "exam10a application"<BR>EXPORTS<BR>acrxEntryPoint PRIVATE<BR>acrxGetApiVersion PRIVATE</P>
<P> </P> <P>开发环境:vc++6.0</P>
<P>使用环境:autocad2002</P>
<P>调试和使用通过。与大家共免。</P> <P>vc++ 中的环境要设置一下。</P>
页:
[1]