如何监控删除实体的操作?
本帖最后由 作者 于 2007-11-6 11:47:55 编辑 <br /><br /> 想法是:<br/> 监视每一个删除操作,通过被删除的objectId获取被删实体的属性,再根据属性判断是否有不应被删除的实体在内,执行其它操作<br/><br/> <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/> ads_alert("APPEND");<br/>}</p><p>void CDbReactor::objectModified(const AcDbDatabase *db,const AcDbObject *pObj)<br/>{<br/> ads_alert("MODIFY");<br/>}</p><p>void CDbReactor::objectErased(const AcDbDatabase *db,const AcDbObject *pObj,Adesk::Boolean pErased)<br/>{<br/> 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 > 1000<br/>#pragma once<br/>#endif // _MSC_VER > 1000</p><p>class CDbReactor : public AcDbDatabaseReactor <br/>{<br/>public:<br/> CDbReactor();<br/> virtual ~CDbReactor();</p><p> void objectAppended(const AcDbDatabase *db,const AcDbObject *pObj);<br/> void objectModified(const AcDbDatabase *db,const AcDbObject *pObj);<br/> 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/> if(gpDbr==NULL) gpDbr = new CDbReactor();</p><p> AcDbDatabase *pCur=acdbHostApplicationServices()->workingDatabase();<br/> pCur->addReactor(gpDbr);<br/>}</p><p>//清除监控函数</p><p>void ClearReactors()<br/>{<br/> AcDbDatabase *pCur=acdbHostApplicationServices()->workingDatabase();</p><p> if(pCur!=NULL) pCur->removeReactor(gpDbr);<br/> delete gpDbr;<br/> gpDbr=NULL;<br/>}</p><p>在初始化时增加监控</p><p>void InitApplication()<br/>{<br/> // TODO: add your initialization functions</p><p> WatchDb();</p><p>}</p><p>// Unload this application. Unregister all objects<br/>// registered in InitApplication.</p><p>//在退出时清除监控<br/>void UnloadApplication()<br/>{<br/> // NOTE: DO NOT edit the following lines.<br/> //{{AFX_ARX_EXIT<br/> //}}AFX_ARX_EXIT<br/></p><p> ClearReactors();</p><p><br/> //deleteAcRxClass(CPersistentReactor::desc());<br/> // TODO: clean up your application<br/>}</p>
页:
[1]