明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1947|回复: 3

反应器实例

[复制链接]
发表于 2005-9-9 09:00:00 | 显示全部楼层 |阅读模式

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;
}

 楼主| 发表于 2005-9-9 09:02:00 | 显示全部楼层

exam10a.def代码:

LIBRARY   exam10a
DESCRIPTION  "exam10a application"
EXPORTS
acrxEntryPoint  RIVATE
acrxGetApiVersion RIVATE

 

 楼主| 发表于 2005-9-9 09:03:00 | 显示全部楼层

开发环境:vc++6.0

使用环境:autocad2002

调试和使用通过。与大家共免。

 楼主| 发表于 2005-9-9 09:04:00 | 显示全部楼层

vc++ 中的环境要设置一下。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 04:40 , Processed in 0.160728 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表