hulei_accp 发表于 2005-9-9 09:00:00

反应器实例

<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>&nbsp;virtual void objectAppended(const AcDbDatabase * dwg,<BR>&nbsp;&nbsp;&nbsp;&nbsp;const AcDbObject *dbObj);<BR>&nbsp;virtual void objectModifier(const AcDbDatabase * dwg,<BR>&nbsp;&nbsp;&nbsp;&nbsp;const AcDbObject *dbObj);<BR>&nbsp;virtual void objectErased(const AcDbDatabase * dwg,<BR>&nbsp;&nbsp;const AcDbObject * dbObj,Adesk::Boolean pErased);<BR>};</P>
<P>void MyDbReactor::objectAppended(const AcDbDatabase * db,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const AcDbObject *pObj)<BR>{<BR>&nbsp;printDbEvent(pObj,"objectAppended");<BR>&nbsp;acutPrintf("db==%lx\n",(long)db);<BR>&nbsp;gEntAcc++;<BR>&nbsp;acutPrintf("Entity Count=%d\n",gEntAcc);<BR>}</P>
<P>void MyDbReactor::objectModifier(const AcDbDatabase *db,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const AcDbObject *pObj)<BR>{<BR>&nbsp;printDbEvent(pObj,"objectModified");<BR>&nbsp;acutPrintf("db==%=%lx\n",(long)db);<BR>}</P>
<P>void MyDbReactor::objectErased(const AcDbDatabase * db,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const AcDbObject *pObj,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Adesk::Boolean pErased)<BR>{<BR>&nbsp;if(pErased)<BR>&nbsp;{<BR>&nbsp;&nbsp;printDbEvent(pObj,"objectErased");<BR>&nbsp;&nbsp;gEntAcc--;<BR>&nbsp;}<BR>&nbsp;else<BR>&nbsp;{<BR>&nbsp;&nbsp;printDbEvent(pObj,"object (un)erased");<BR>&nbsp;&nbsp;gEntAcc++;<BR>&nbsp;}<BR>&nbsp;acutPrintf("Db=%lx\n",(long)db);<BR>&nbsp;acutPrintf("Entity Count=%d\n",gEntAcc);<BR>}</P>
<P>void printDbEvent(const AcDbObject * pObj,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char * pEvent)<BR>{<BR>&nbsp;acutPrintf("Event::AcDbDatabaseReactor::%s",pEvent);<BR>&nbsp;printObj(pObj);<BR>}</P>
<P>void printObj(const AcDbObject *pObj)<BR>{<BR>&nbsp;if(pObj==NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;acutPrintf("(NULL)");<BR>&nbsp;&nbsp;return;<BR>&nbsp;}</P>
<P>&nbsp;AcDbHandle objHand;<BR>&nbsp;char handbuf;</P>
<P>&nbsp;pObj-&gt;getAcDbHandle(objHand);<BR>&nbsp;objHand.getIntoAsciiBuffer(handbuf);<BR>&nbsp;acutPrintf("\n (class==%s,handle==%s,id==%lx,db==%lx)",<BR>&nbsp;&nbsp;pObj-&gt;isA()-&gt;name(),handbuf,<BR>&nbsp;&nbsp;pObj-&gt;objectId().asOldId(),pObj-&gt;database());<BR>}</P>
<P>void watchDb()<BR>{<BR>&nbsp;if(gpDbr==NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;gpDbr=new MyDbReactor();<BR>&nbsp;}<BR>&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;-&gt;addReactor(gpDbr);<BR>&nbsp;acutPrintf("Added Database Reactor to"<BR>&nbsp;&nbsp;"acdbHostApplicationServices()-&gt;workingDatabase().\n");<BR>}</P>
<P>void clearReactors()<BR>{<BR>&nbsp;if(acdbHostApplicationServices()-&gt;workingDatabase()!=NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp;-&gt;removeReactor(gpDbr);<BR>&nbsp;&nbsp;delete gpDbr;<BR>&nbsp;&nbsp;gpDbr=NULL;<BR>&nbsp;}<BR>}</P>
<P><BR>AcRx::AppRetCode<BR>acrxEntryPoint(AcRx::AppMsgCode msg,void * appId)<BR>{<BR>&nbsp;switch(msg)<BR>&nbsp;{<BR>&nbsp;case AcRx::kInitAppMsg:<BR>&nbsp;&nbsp;acrxDynamicLinker-&gt;unlockApplication(appId);<BR>&nbsp;&nbsp;acrxDynamicLinker-&gt;registerAppNotMDIAware(appId);<BR>&nbsp;&nbsp;acedRegCmds-&gt;addCommand("EXAM10A",<BR>&nbsp;&nbsp;&nbsp;"WATCH",<BR>&nbsp;&nbsp;&nbsp;"WATCH",<BR>&nbsp;&nbsp;&nbsp;ACRX_CMD_TRANSPARENT,<BR>&nbsp;&nbsp;&nbsp;watchDb);<BR>&nbsp;&nbsp;acedRegCmds-&gt;addCommand("EXAM10A",<BR>&nbsp;&nbsp;&nbsp;"CLEAR",<BR>&nbsp;&nbsp;&nbsp;"CLEAR",<BR>&nbsp;&nbsp;&nbsp;ACRX_CMD_TRANSPARENT,<BR>&nbsp;&nbsp;&nbsp;clearReactors);<BR>&nbsp;&nbsp;break;<BR>&nbsp;case AcRx::kUnloadAppMsg:<BR>&nbsp;&nbsp;clearReactors();<BR>&nbsp;&nbsp;acedRegCmds-&gt;removeGroup("EXAM10A");<BR>&nbsp;&nbsp;break;<BR>&nbsp;}<BR>&nbsp;return AcRx::kRetOK;<BR>}</P>

hulei_accp 发表于 2005-9-9 09:02:00

<P>exam10a.def代码:</P>
<P>LIBRARY&nbsp;&nbsp;&nbsp;exam10a<BR>DESCRIPTION&nbsp;&nbsp;"exam10a application"<BR>EXPORTS<BR>acrxEntryPoint&nbsp;&nbsp;PRIVATE<BR>acrxGetApiVersion&nbsp;PRIVATE</P>
<P>&nbsp;</P>

hulei_accp 发表于 2005-9-9 09:03:00

<P>开发环境:vc++6.0</P>
<P>使用环境:autocad2002</P>
<P>调试和使用通过。与大家共免。</P>

hulei_accp 发表于 2005-9-9 09:04:00

<P>vc++ 中的环境要设置一下。</P>
页: [1]
查看完整版本: 反应器实例