多文档范例的问题
<P>exam11.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"<BR>#include "acdocman.h"</P>
<P>/*<BR>void assocLines();<BR>void addToModelSpace(AcDbObjectId&,AcDbEntity *);<BR>void initApp(void);<BR>void unloadApp(void);</P>
<P>void printDbEvent(const AcDbObject *pObj,<BR> const char *pEvent);<BR>extern "C" <BR>AcRx::AppRetCode <BR>acrxEntryPoint(AcRx::AppMsgCode,void *);<BR>*/</P>
<P>long gEntAcc=0;<BR>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;</P>
<P><BR>class MyDocReactor:public AcApDocManagerReactor<BR>{<BR>public:<BR> virtual void documentToBeActivated(AcApDocument * pDoc);<BR> virtual void documentCreated(AcApDocument * pDoc);<BR> virtual void documentToBeDestroyed(AcApDocument * pDoc);<BR>};</P>
<P>class MyPerDocData<BR>{<BR> friend class MyAppDocGlobals;<BR>public:<BR> MyPerDocData(AcApDocument * pDoc);<BR>private:<BR> AcApDocument * m_pDoc;<BR> MyPerDocData * m_pNext;<BR> long m_EntAcc;<BR> MyDbReactor * m_pDbr;<BR>};</P>
<P>class MyAppDocGlobals<BR>{<BR>public:<BR> <BR> MyAppdocGlobals(AcApDocument *pDoc);<BR> void setGlobals(AcApDocument *pDoc);<BR> void removeDocGlobals(AcApDocument * pDoc);<BR> void removeAllDocGlobals(MyPerDocData * pTarget);<BR> void unload();<BR> long &entityCount();<BR> void incrementEntityCount();<BR> void decrementEntityCount();<BR> MyDbReactor * gpReactor();<BR> void setDbReactor(MyDbReactor *pDb);<BR>private:<BR> MyPerDocData *m_pHead;<BR> MyPerDocData *m_pData;<BR> MyDocReactor *m_pDocReactor;<BR>};</P>
<P>MyAppDocGlobals *gpMyAppDocGlobals;</P>
<P><BR>class MyDbReactor:public AcDbDatabaseReactor<BR>{<BR>public:<BR> virtual void objectAppended(const AcDbDatabase * dwg,<BR> const AcDbObject *dbObj);<BR> virtual void objectModified(const AcDbDatabase * dwg,<BR> const AcDbObject * dbObj);<BR> virtual void objectErased(const AcDbDatabase *dwg,<BR> const AcDbObject *dbObj,<BR> Adesk::Boolean pErased);<BR>};</P>
<P>void MyDbReactor::objectAppended(const AcDbDatabase * db,<BR> const AcDbObject *pObj)<BR>{<BR> <BR> printDbEvent(pObj,"objectAppended");<BR> acutPrintf("Db==%lx\n",(long)db);<BR> gEntAcc++;<BR> acutPrintf("Entity Count=%d\n",gEntAcc);<BR>}</P>
<P><BR>void MyDbReactor::objectModified(const AcDbDatabase * db,<BR> const AcDbObject *pObj)<BR>{<BR> printDbEvent(pObj,"objectModified");<BR> acutPrintf("Db==%ls\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> }<BR> AcDbHandle objHand;<BR> char handbuf;<BR> 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 MyDocReactor::documentToBeActivated(AcApDocument *pDoc)<BR>{<BR> gpMyAppDocGlobals->setGlobals(pDoc);<BR>}</P>
<P>void MyDocReactor::documentToBeDestroyed(AcApDocument *pDoc)<BR>{<BR> gpMyAppDocGlobals->removeDocGlobals(pDoc);<BR>}</P>
<P>void MyDocReactor::documentCreated(AcApDocument *pDoc)<BR>{<BR> gpMyAppDocGlobals->setGlobals(pDoc);<BR>}</P>
<P>MyPerDocData::MyPerDocData(AcApDocument *pDoc)<BR>{<BR> m_pDoc=pDoc;<BR> m_pNext=NULL;<BR> m_EntAcc=0;<BR> m_pDbr=NULL;<BR>}</P>
<P>MyAppDocGlobals::MyAppdocGlobals(AcApDocument *pDoc)<BR>{<BR> m_pData=m_pHead=NULL;<BR> m_pDocReactor=new MyDocReactor();<BR> acDocManager->addReactor(m_pDocReactor);<BR>}</P>
<P>void MyAppDocGlobals::setGlobals(AcApDocument *pDoc)<BR>{<BR> MyPerDocData *p_data=m_pHead,*prev_data=m_pHead;<BR> while(p_data!=NULL)<BR> {<BR> if(p_data->m_pDoc==pDoc)<BR> {<BR> m_pData=p_data;<BR> break;<BR> }<BR> prev_data=p_data;<BR> p_data=p_data->m_pNext ;</P>
<P> }<BR> if(p_data==NULL)<BR> {<BR> if(m_pHead==NULL)<BR> {<BR> m_pHead=m_pData=new MyPerDocData(pDoc);<BR> }<BR> else<BR> {<BR> prev_data->m_pNext=m_pData=new MyPerDocData(pDoc);<BR> }<BR> }<BR>}</P>
<P><BR>void MyAppDocGlobals::removeDocGlobals(AcApDocument * pDoc)<BR>{<BR> MyPerDocData *p_data=m_pHead,*prev_data=m_pHead;<BR> while(p_data!=NULL)<BR> {<BR> if(p_data->m_pDoc=pDoc)<BR> {<BR> if(p_data==m_pHead)<BR> {<BR> m_pHead=p_data->m_pNext;<BR> }<BR> else<BR> {<BR> prev_data->m_pNext=p_data->m_pNext;<BR> }<BR> if(m_pData==p_data)<BR> {<BR> m_pData=m_pHead;<BR> }<BR> delete p_data;<BR> break;<BR> }<BR> prev_data=p_data;<BR> p_data=p_data->m_pNext;<BR> }<BR>}</P>
<P> <BR>void MyAppDocGlobals::removeAllDocGlobals (MyPerDocData * p_target)<BR>{<BR> if(p_target==NULL)<BR> {<BR> return;<BR> }<BR> if(p_target->m_pNext!=NULL)<BR> {<BR> removeAllDocGlobals(p_target->m_pNext );<BR> }<BR> if(p_target->m_pDbr!=NULL)<BR> {<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->removeReactor(p_target->m_pDbr );<BR> delete p_target->m_pDbr;<BR> p_target->m_pDbr=NULL;<BR> }<BR> delete p_target;<BR>}</P>
<P><BR>void MyAppDocGlobals::unload()<BR>{<BR> acDocManager->removeReactor(m_pDocReactor);<BR> delete m_pDocReactor;<BR> removeAllDocGlobals(m_pHead);<BR> m_pHead=m_pData=NULL;<BR>}</P>
<P>long & MyAppDocGlobals::entityCount()<BR>{<BR> return m_pData->m_EntAcc;<BR>}</P>
<P>void MyAppDocGlobals::incrementEntityCount()<BR>{<BR> m_pData->m_EntAcc++;<BR>}</P>
<P>void MyAppDocGlobals::decrementEntityCount()<BR>{<BR> m_pData->m_EntAcc--;<BR>}</P>
<P>MyDbReactor * MyAppDocGlobals::gpReactor()<BR>{<BR> return m_pData->m_pDbr;<BR>}</P>
<P>void MyAppDocGlobals::setDbReactor(MyDbReactor *pDb)<BR>{<BR> m_pData->m_pDbr=pDb;<BR>}</P>
<P>void watchDb()<BR>{<BR> MyDbReactor *pDbr;<BR> if(gpMyAppDocGlobals->gpReactor()==NULL)<BR> {<BR> pDbr=new MyDbReactor();<BR> gpMyAppDocGlobals->setDbReactor(pDbr);<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->addReactor(pDbr);<BR> acutPrintf("Added Database Reactor to "<BR> "acdbHostApplicationServices()->workingDatabase()\n");<BR> }<BR>}</P>
<P>void clearReactors()<BR>{<BR> MyDbReactor *pDbr;<BR> if((pDbr=gpMyAppDocGlobals->gpReactor())!=NULL)<BR> {<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->removeReactor(pDbr);<BR> delete pDbr;<BR> gpMyAppDocGlobals->setDbReactor(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> acrxUnlockApplication(appId);<BR> acrxRegisterAppMDIAware(appId);<BR> gpMyAppDocGlobals=new MyAppDocGlobals(curDoc());<BR> gpMyAppDocGlobals->setGlobals(curDoc());<BR> acedRegCmds->addCommand("EXAM11",<BR> "WATCH",<BR> "WATCH",<BR> ACRX_CMD_MODAL,<BR> watchDb);<BR> acedRegCmds->addCommand("EXAM11",<BR> "CLEAR",<BR> "CLEAR",<BR> ACRX_CMD_MODAL,<BR> clearReactors);<BR> break;<BR> case AcRx::kUnloadAppMsg:<BR> if(gpMyAppDocGlobals!=NULL)<BR> {<BR> gpMyAppDocGlobals->unload();<BR> delete gpMyAppDocGlobals;<BR> gpMyAppDocGlobals=NULL;<BR> }<BR> acedRegCmds->removeGroup("EXAM11");<BR> break;<BR> }<BR> return AcRx::kRetOK;<BR>}</P> <P>提示:</P>
<P><BR>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 &'<BR> Reason: cannot convert from 'class AcApDocument *' to 'const class MyAppDocGlobals'<BR> No constructor could take the source type, or constructor overload resolution was ambiguous</P> <P>可能是</P>
<P>gpMyAppDocGlobals=new MyAppDocGlobals(curDoc());</P>
<P>参数类型不正确,不知道怎么该?<BR> <BR> </P> <P>MyAppDocGlobals *gpMyAppDocGlobals;</P>
<P>这是一个全局变量。</P> <P>MyAppDocGlobals是我定义的一个类,</P>
<P>curDoc()是一个函数,返回AcApDocument类型。</P> <P>MyAppDocGlobals是我定义的一个类,</P>
<P>curDoc()是一个函数,返回AcApDocument * 类型。</P>
页:
[1]