hulei_accp 发表于 2005-9-9 17:49:00

多文档范例的问题

<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&amp;,AcDbEntity *);<BR>void initApp(void);<BR>void unloadApp(void);</P>
<P>void printDbEvent(const AcDbObject *pObj,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>&nbsp;virtual void documentToBeActivated(AcApDocument * pDoc);<BR>&nbsp;virtual void documentCreated(AcApDocument * pDoc);<BR>&nbsp;virtual void documentToBeDestroyed(AcApDocument * pDoc);<BR>};</P>
<P>class MyPerDocData<BR>{<BR>&nbsp;friend class MyAppDocGlobals;<BR>public:<BR>&nbsp;MyPerDocData(AcApDocument * pDoc);<BR>private:<BR>&nbsp;AcApDocument * m_pDoc;<BR>&nbsp;MyPerDocData * m_pNext;<BR>&nbsp;long m_EntAcc;<BR>&nbsp;MyDbReactor * m_pDbr;<BR>};</P>
<P>class MyAppDocGlobals<BR>{<BR>public:<BR>&nbsp;<BR>&nbsp;MyAppdocGlobals(AcApDocument *pDoc);<BR>&nbsp;void setGlobals(AcApDocument *pDoc);<BR>&nbsp;void removeDocGlobals(AcApDocument * pDoc);<BR>&nbsp;void removeAllDocGlobals(MyPerDocData * pTarget);<BR>&nbsp;void unload();<BR>&nbsp;long &amp;entityCount();<BR>&nbsp;void incrementEntityCount();<BR>&nbsp;void decrementEntityCount();<BR>&nbsp;MyDbReactor * gpReactor();<BR>&nbsp;void setDbReactor(MyDbReactor *pDb);<BR>private:<BR>&nbsp;MyPerDocData *m_pHead;<BR>&nbsp;MyPerDocData *m_pData;<BR>&nbsp;MyDocReactor *m_pDocReactor;<BR>};</P>
<P>MyAppDocGlobals *gpMyAppDocGlobals;</P>
<P><BR>class MyDbReactor:public AcDbDatabaseReactor<BR>{<BR>public:<BR>&nbsp;virtual void objectAppended(const AcDbDatabase * dwg,<BR>&nbsp;&nbsp;const AcDbObject *dbObj);<BR>&nbsp;virtual void objectModified(const AcDbDatabase * dwg,<BR>&nbsp;&nbsp;const AcDbObject * dbObj);<BR>&nbsp;virtual void objectErased(const AcDbDatabase *dwg,<BR>&nbsp;&nbsp;const AcDbObject *dbObj,<BR>&nbsp;&nbsp;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;&nbsp;<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><BR>void MyDbReactor::objectModified(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==%ls\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;}<BR>&nbsp;AcDbHandle objHand;<BR>&nbsp;char handbuf;<BR>&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 MyDocReactor::documentToBeActivated(AcApDocument *pDoc)<BR>{<BR>&nbsp;gpMyAppDocGlobals-&gt;setGlobals(pDoc);<BR>}</P>
<P>void MyDocReactor::documentToBeDestroyed(AcApDocument *pDoc)<BR>{<BR>&nbsp;gpMyAppDocGlobals-&gt;removeDocGlobals(pDoc);<BR>}</P>
<P>void MyDocReactor::documentCreated(AcApDocument *pDoc)<BR>{<BR>&nbsp;gpMyAppDocGlobals-&gt;setGlobals(pDoc);<BR>}</P>
<P>MyPerDocData::MyPerDocData(AcApDocument *pDoc)<BR>{<BR>&nbsp;m_pDoc=pDoc;<BR>&nbsp;m_pNext=NULL;<BR>&nbsp;m_EntAcc=0;<BR>&nbsp;m_pDbr=NULL;<BR>}</P>
<P>MyAppDocGlobals::MyAppdocGlobals(AcApDocument *pDoc)<BR>{<BR>&nbsp;m_pData=m_pHead=NULL;<BR>&nbsp;m_pDocReactor=new MyDocReactor();<BR>&nbsp;acDocManager-&gt;addReactor(m_pDocReactor);<BR>}</P>
<P>void MyAppDocGlobals::setGlobals(AcApDocument *pDoc)<BR>{<BR>&nbsp;MyPerDocData *p_data=m_pHead,*prev_data=m_pHead;<BR>&nbsp;while(p_data!=NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;if(p_data-&gt;m_pDoc==pDoc)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;m_pData=p_data;<BR>&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;prev_data=p_data;<BR>&nbsp;&nbsp;p_data=p_data-&gt;m_pNext ;</P>
<P>&nbsp;}<BR>&nbsp;if(p_data==NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;if(m_pHead==NULL)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;m_pHead=m_pData=new MyPerDocData(pDoc);<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;else<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;prev_data-&gt;m_pNext=m_pData=new MyPerDocData(pDoc);<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}</P>
<P><BR>void MyAppDocGlobals::removeDocGlobals(AcApDocument * pDoc)<BR>{<BR>&nbsp;MyPerDocData *p_data=m_pHead,*prev_data=m_pHead;<BR>&nbsp;while(p_data!=NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;if(p_data-&gt;m_pDoc=pDoc)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if(p_data==m_pHead)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_pHead=p_data-&gt;m_pNext;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;prev_data-&gt;m_pNext=p_data-&gt;m_pNext;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;if(m_pData==p_data)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_pData=m_pHead;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;delete p_data;<BR>&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;prev_data=p_data;<BR>&nbsp;&nbsp;p_data=p_data-&gt;m_pNext;<BR>&nbsp;}<BR>}</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>void MyAppDocGlobals::removeAllDocGlobals (MyPerDocData * p_target)<BR>{<BR>&nbsp;if(p_target==NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;return;<BR>&nbsp;}<BR>&nbsp;if(p_target-&gt;m_pNext!=NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;removeAllDocGlobals(p_target-&gt;m_pNext );<BR>&nbsp;}<BR>&nbsp;if(p_target-&gt;m_pDbr!=NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp;-&gt;removeReactor(p_target-&gt;m_pDbr );<BR>&nbsp;&nbsp;delete p_target-&gt;m_pDbr;<BR>&nbsp;&nbsp;p_target-&gt;m_pDbr=NULL;<BR>&nbsp;}<BR>&nbsp;delete p_target;<BR>}</P>
<P><BR>void MyAppDocGlobals::unload()<BR>{<BR>&nbsp;acDocManager-&gt;removeReactor(m_pDocReactor);<BR>&nbsp;delete m_pDocReactor;<BR>&nbsp;removeAllDocGlobals(m_pHead);<BR>&nbsp;m_pHead=m_pData=NULL;<BR>}</P>
<P>long &amp; MyAppDocGlobals::entityCount()<BR>{<BR>&nbsp;return m_pData-&gt;m_EntAcc;<BR>}</P>
<P>void MyAppDocGlobals::incrementEntityCount()<BR>{<BR>&nbsp;m_pData-&gt;m_EntAcc++;<BR>}</P>
<P>void MyAppDocGlobals::decrementEntityCount()<BR>{<BR>&nbsp;m_pData-&gt;m_EntAcc--;<BR>}</P>
<P>MyDbReactor * MyAppDocGlobals::gpReactor()<BR>{<BR>&nbsp;return m_pData-&gt;m_pDbr;<BR>}</P>
<P>void MyAppDocGlobals::setDbReactor(MyDbReactor *pDb)<BR>{<BR>&nbsp;m_pData-&gt;m_pDbr=pDb;<BR>}</P>
<P>void watchDb()<BR>{<BR>&nbsp;MyDbReactor *pDbr;<BR>&nbsp;if(gpMyAppDocGlobals-&gt;gpReactor()==NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;pDbr=new MyDbReactor();<BR>&nbsp;&nbsp;gpMyAppDocGlobals-&gt;setDbReactor(pDbr);<BR>&nbsp;&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp;-&gt;addReactor(pDbr);<BR>&nbsp;&nbsp;acutPrintf("Added Database Reactor to "<BR>&nbsp;&nbsp;&nbsp;"acdbHostApplicationServices()-&gt;workingDatabase()\n");<BR>&nbsp;}<BR>}</P>
<P>void clearReactors()<BR>{<BR>&nbsp;MyDbReactor *pDbr;<BR>&nbsp;if((pDbr=gpMyAppDocGlobals-&gt;gpReactor())!=NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp;-&gt;removeReactor(pDbr);<BR>&nbsp;&nbsp;delete pDbr;<BR>&nbsp;&nbsp;gpMyAppDocGlobals-&gt;setDbReactor(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;acrxUnlockApplication(appId);<BR>&nbsp;&nbsp;acrxRegisterAppMDIAware(appId);<BR>&nbsp;&nbsp;gpMyAppDocGlobals=new MyAppDocGlobals(curDoc());<BR>&nbsp;&nbsp;gpMyAppDocGlobals-&gt;setGlobals(curDoc());<BR>&nbsp;&nbsp;acedRegCmds-&gt;addCommand("EXAM11",<BR>&nbsp;&nbsp;&nbsp;"WATCH",<BR>&nbsp;&nbsp;&nbsp;"WATCH",<BR>&nbsp;&nbsp;&nbsp;ACRX_CMD_MODAL,<BR>&nbsp;&nbsp;&nbsp;watchDb);<BR>&nbsp;&nbsp;acedRegCmds-&gt;addCommand("EXAM11",<BR>&nbsp;&nbsp;&nbsp;"CLEAR",<BR>&nbsp;&nbsp;&nbsp;"CLEAR",<BR>&nbsp;&nbsp;&nbsp;ACRX_CMD_MODAL,<BR>&nbsp;&nbsp;&nbsp;clearReactors);<BR>&nbsp;&nbsp;break;<BR>&nbsp;case&nbsp; AcRx::kUnloadAppMsg:<BR>&nbsp;&nbsp;if(gpMyAppDocGlobals!=NULL)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;gpMyAppDocGlobals-&gt;unload();<BR>&nbsp;&nbsp;&nbsp;delete gpMyAppDocGlobals;<BR>&nbsp;&nbsp;&nbsp;gpMyAppDocGlobals=NULL;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;acedRegCmds-&gt;removeGroup("EXAM11");<BR>&nbsp;&nbsp;break;<BR>&nbsp;}<BR>&nbsp;return AcRx::kRetOK;<BR>}</P>

hulei_accp 发表于 2005-9-9 17:50:00

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

hulei_accp 发表于 2005-9-9 17:52:00

<P>可能是</P>
<P>gpMyAppDocGlobals=new MyAppDocGlobals(curDoc());</P>
<P>参数类型不正确,不知道怎么该?<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;</P>

hulei_accp 发表于 2005-9-9 17:52:00

<P>MyAppDocGlobals *gpMyAppDocGlobals;</P>
<P>这是一个全局变量。</P>

hulei_accp 发表于 2005-9-9 17:54:00

<P>MyAppDocGlobals是我定义的一个类,</P>
<P>curDoc()是一个函数,返回AcApDocument类型。</P>

hulei_accp 发表于 2005-9-9 18:01:00

<P>MyAppDocGlobals是我定义的一个类,</P>
<P>curDoc()是一个函数,返回AcApDocument * 类型。</P>
页: [1]
查看完整版本: 多文档范例的问题