明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2495|回复: 5

多文档范例的问题

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

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

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

提示:


E:\hulei\test\exam11\exam11.cpp(326) : error C2664: '__thiscall MyAppDocGlobals::MyAppDocGlobals(const class MyAppDocGlobals &)' : cannot convert parameter 1 from 'class AcApDocument *' to 'const class MyAppDocGlobals &'
        Reason: cannot convert from 'class AcApDocument *' to 'const class MyAppDocGlobals'
        No constructor could take the source type, or constructor overload resolution was ambiguous

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

可能是

gpMyAppDocGlobals=new MyAppDocGlobals(curDoc());

参数类型不正确,不知道怎么该?
  
  

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

MyAppDocGlobals *gpMyAppDocGlobals;

这是一个全局变量。

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

MyAppDocGlobals是我定义的一个类,

curDoc()是一个函数,返回AcApDocument类型。

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

MyAppDocGlobals是我定义的一个类,

curDoc()是一个函数,返回AcApDocument * 类型。

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

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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