hbird 发表于 2007-11-5 01:22:00

如何监控删除实体的操作?

本帖最后由 作者 于 2007-11-6 11:47:55 编辑 <br /><br /> 想法是:<br/>       监视每一个删除操作,通过被删除的objectId获取被删实体的属性,再根据属性判断是否有不应被删除的实体在内,执行其它操作<br/><br/>

hdr_37210427 发表于 2007-11-6 17:47:00

<p>派生一个类</p><p>// DbReactor.cpp: implementation of the CDbReactor class.<br/>//<br/>//////////////////////////////////////////////////////////////////////</p><p>#include "stdafx.h"<br/>#include "resource.h"<br/>#include "DbReactor.h"</p><p>#ifdef _DEBUG<br/>#undef THIS_FILE<br/>static char THIS_FILE[]=__FILE__;<br/>#define new DEBUG_NEW<br/>#endif</p><p>//////////////////////////////////////////////////////////////////////<br/>// Construction/Destruction<br/>//////////////////////////////////////////////////////////////////////</p><p>CDbReactor::CDbReactor()<br/>{</p><p>}</p><p>CDbReactor::~CDbReactor()<br/>{</p><p>}</p><p>void CDbReactor::objectAppended(const AcDbDatabase *db,const AcDbObject *pObj)<br/>{<br/>&nbsp; ads_alert("APPEND");<br/>}</p><p>void CDbReactor::objectModified(const AcDbDatabase *db,const AcDbObject *pObj)<br/>{<br/>&nbsp; ads_alert("MODIFY");<br/>}</p><p>void CDbReactor::objectErased(const AcDbDatabase *db,const AcDbObject *pObj,Adesk::Boolean pErased)<br/>{<br/>&nbsp; if(pErased) ads_alert("DELETE");<br/>}</p><p></p><p>// DbReactor.h: interface for the CDbReactor class.<br/>//<br/>//////////////////////////////////////////////////////////////////////</p><p>#if !defined(AFX_DBREACTOR_H__ED11D52E_E8ED_43A0_90CE_8BB65D78A51A__INCLUDED_)<br/>#define AFX_DBREACTOR_H__ED11D52E_E8ED_43A0_90CE_8BB65D78A51A__INCLUDED_</p><p>#if _MSC_VER &gt; 1000<br/>#pragma once<br/>#endif // _MSC_VER &gt; 1000</p><p>class CDbReactor : public AcDbDatabaseReactor&nbsp; <br/>{<br/>public:<br/>&nbsp;CDbReactor();<br/>&nbsp;virtual ~CDbReactor();</p><p>&nbsp; void objectAppended(const AcDbDatabase *db,const AcDbObject *pObj);<br/>&nbsp; void objectModified(const AcDbDatabase *db,const AcDbObject *pObj);<br/>&nbsp; void objectErased(const AcDbDatabase *db,const AcDbObject *pObj,Adesk::Boolean pErased);</p><p>};</p><p>#endif // !defined(AFX_DBREACTOR_H__ED11D52E_E8ED_43A0_90CE_8BB65D78A51A__INCLUDED_)</p><p><br/>增加监控函数</p><p>void WatchDb()<br/>{<br/>&nbsp; if(gpDbr==NULL) gpDbr = new CDbReactor();</p><p>&nbsp; AcDbDatabase *pCur=acdbHostApplicationServices()-&gt;workingDatabase();<br/>&nbsp; pCur-&gt;addReactor(gpDbr);<br/>}</p><p>//清除监控函数</p><p>void ClearReactors()<br/>{<br/>&nbsp; AcDbDatabase *pCur=acdbHostApplicationServices()-&gt;workingDatabase();</p><p>&nbsp; if(pCur!=NULL) pCur-&gt;removeReactor(gpDbr);<br/>&nbsp; delete gpDbr;<br/>&nbsp; gpDbr=NULL;<br/>}</p><p>在初始化时增加监控</p><p>void InitApplication()<br/>{<br/>&nbsp;&nbsp;// TODO: add your initialization functions</p><p>&nbsp; WatchDb();</p><p>}</p><p>// Unload this application. Unregister all objects<br/>// registered in InitApplication.</p><p>//在退出时清除监控<br/>void UnloadApplication()<br/>{<br/>&nbsp;// NOTE: DO NOT edit the following lines.<br/>&nbsp;//{{AFX_ARX_EXIT<br/>&nbsp;//}}AFX_ARX_EXIT<br/></p><p>&nbsp; ClearReactors();</p><p><br/>&nbsp; //deleteAcRxClass(CPersistentReactor::desc());<br/>&nbsp;// TODO: clean up your application<br/>}</p>
页: [1]
查看完整版本: 如何监控删除实体的操作?