- UID
- 675574
- 积分
- 450
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2013-5-4
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2013-6-2 16:12:05
|
显示全部楼层
反应器我是用工具条添加的,MySelectFilter是这个反应器的文档级变量。
这是h文件
- //-----------------------------------------------------------------------------
- //----- SelectFilter.h : Declaration of the SelectFilter
- //-----------------------------------------------------------------------------
- #pragma once
- #ifdef MY_MODULE
- #define DLLIMPEXP __declspec(dllexport)
- #else
- //----- Note: we don't use __declspec(dllimport) here, because of the
- //----- "local vtable" problem with msvc. If you use __declspec(dllimport),
- //----- then, when a client dll does a new on the class, the object's
- //----- vtable pointer points to a vtable allocated in that client
- //----- dll. If the client dll then passes the object to another dll,
- //----- and the client dll is then unloaded, the vtable becomes invalid
- //----- and any virtual calls on the object will access invalid memory.
- //-----
- //----- By not using __declspec(dllimport), we guarantee that the
- //----- vtable is allocated in the server dll during the ctor and the
- //----- client dll does not overwrite the vtable pointer after calling
- //----- the ctor. And, since we expect the server dll to remain in
- //----- memory indefinitely, there is no problem with vtables unexpectedly
- //----- going away.
- #define DLLIMPEXP
- #endif
- //-----------------------------------------------------------------------------
- #include "acssgetfilter.h"
- #include "afx.h"
- //-----------------------------------------------------------------------------
- //----- Note: Uncomment the DLLIMPEXP symbol below if you wish exporting
- //----- your class to other ARX/DBX modules
- class /*DLLIMPEXP*/ SelectFilter : public AcEdSSGetFilter {
- protected:
- AcApDocument *mpDoc ;
- public:
- //CString addFilterpname;
-
- SelectFilter (AcApDocument *pDoc =acDocManager->curDocument (),const ACHAR *addFilterpname = NULL) ;
- SelectFilter (AcApDocument *pDoc =acDocManager->curDocument (),const struct resbuf *Rb = NULL) ;
- virtual ~SelectFilter () ;
- virtual void Attach () ;
- virtual void Detach () ;
- virtual AcApDocument *Subject () const { return (mpDoc) ; }
- virtual bool IsAttached () const { return (mpDoc != NULL) ; }
- virtual void ssgetAddFilter (
- int ssgetFlags,
- AcEdSelectionSetService &service,
- const AcDbObjectIdArray &selectionSet,
- const AcDbObjectIdArray &subSelectionSet
- ) ;
- static int addSetectFilter(struct resbuf *rb);
- static int removeSetectFilter(struct resbuf *rb);
- static int addFilter(struct resbuf *rb);
- int SetPFuncName(ACHAR * pName)//设置回调函数方法
- {
- if (pName == NULL)
- {
- delete addFilterpname;
- addFilterpname = NULL;
- return RTNORM;
- }
- if (addFilterpname != NULL)
- {
- delete[] addFilterpname;
- addFilterpname = NULL;
- //addFilterpname =(ACHAR*) realloc(addFilterpname , wcslen(pName) + 1);
- }
- addFilterpname = new ACHAR[wcslen(pName)+ 1];
- wcscpy(addFilterpname,pName);
- return RTNORM;
- }
- int SetFilter(struct resbuf *rb)//设置过虑链表,我把方法直接写这里不知对不对。
- {
- if (rb == NULL)
- {
- if (FilterRb != NULL)
- {
- acutRelRb(FilterRb);
- FilterRb = NULL;
- }
- return RTNORM;
- }
- if (FilterRb != NULL)
- {
- if (RTNORM != acutRelRb(FilterRb))
- {
- return ERROR;
- }
- FilterRb = NULL;
- }
-
- if (rb->restype != RTLB)
- {
- return ERROR;
- }
- struct resbuf *tmrb = NULL;
- while ( (rb = rb->rbnext) != NULL && rb->restype != RTLE)
- {
- struct resbuf *newrb;
- /*int rbtype;*/
- if ((rb->restype >= 0 && rb->restype <= 9)||(rb->restype >= 999 && rb->restype <= 1005) || rb->restype == -4 )
- {
- newrb = acutNewRb(rb->restype);
- newrb->resval.rstring = (ACHAR *)malloc(wcslen(rb->resval.rstring)+ 1);
- wcscpy(newrb->resval.rstring,rb->resval.rstring);
- }
- else if ((rb->restype >= 10 && rb->restype <= 19)||(rb->restype >= 210 && rb->restype <= 239))
- {
- ads_point pt;
- ads_point_set(rb->resval.rpoint,pt);
- newrb = acutNewRb(rb->restype);
- newrb->resval.rpoint[X] = pt[X];
- newrb->resval.rpoint[Y] = pt[Y];
- newrb->resval.rpoint[Z] = pt[Z];
- }
- else if (rb->restype >= 38 && rb->restype <= 59)
- {
- newrb = acutNewRb(rb->restype);
- newrb->resval.rreal = rb->resval.rreal;
- }
- else if (rb->restype >= 60 && rb->restype <= 79)
- {
- newrb = acutNewRb(rb->restype);
- newrb->resval.rint = rb->resval.rint;
- }
- else if(rb->restype == -3)
- {
- newrb = acutNewRb(rb->restype);
- }
- else
- {
- if (FilterRb != NULL)
- {
- acutRelRb(FilterRb);
- FilterRb = NULL;
- }
- return RTERROR;
- }
- if (FilterRb == NULL)
- {
- FilterRb = tmrb = newrb;
- }
- else
- {
- tmrb->rbnext = newrb;
- tmrb = tmrb->rbnext;
- }
- }
- return RTNORM;
- }
- private:
- ACHAR *addFilterpname;//成员变量回调函数名称字符串
- struct resbuf *FilterRb;//成员变量过虑链表
- } ;
这是CPP文件
- //-----------------------------------------------------------------------------
- //----- SelectFilter.cpp : Implementation of SelectFilter
- //-----------------------------------------------------------------------------
- #include "StdAfx.h"
- #include "SelectFilter.h"
- #include "DocData.h"
- //-----------------------------------------------------------------------------
- SelectFilter::SelectFilter (AcApDocument *pDoc,ACHAR *pname,resbuf *rb) : AcEdSSGetFilter ()
- {
- addFilterpname = NULL;
- if (pname != NULL)
- {
- addFilterpname = new ACHAR(wcslen(pname));
- wcscpy(addFilterpname,pname);
- }
- FilterRb = NULL;
- if (rb != NULL)
- {
- }
- mpDoc =NULL ;
- if ( pDoc != NULL ) {
- mpDoc =pDoc ;
- addSSgetFilterInputContextReactor (mpDoc, this) ;
- }
- }
- //-----------------------------------------------------------------------------
- SelectFilter::~SelectFilter ()
- {
- Detach () ;
- if (addFilterpname != NULL)
- {
- delete[] addFilterpname;
- addFilterpname = NULL;
- }
- if (FilterRb != NULL)
- {
- acutRelRb(FilterRb);//到这里总是出错。
- FilterRb = NULL;
- }
- }
- //-----------------------------------------------------------------------------
- void SelectFilter::Attach ()
- {
- Detach () ;
- mpDoc =acDocManager->curDocument () ;
- if ( mpDoc )
- addSSgetFilterInputContextReactor (mpDoc, this) ;
- }
- void SelectFilter::Detach ()
- {
- if ( mpDoc ) {
- removeSSgetFilterInputContextReactor (mpDoc, this) ;
- mpDoc =NULL ;
- }
- }
- //-----------------------------------------------------------------------------
- void SelectFilter::ssgetAddFilter (int ssgetFlags,AcEdSelectionSetService &service,const AcDbObjectIdArray &selectionSet,const AcDbObjectIdArray &subSelectionSet)
- {
- if (addFilterpname == NULL && FilterRb == NULL)
- {
- return;
- }
- ads_name eName;
- bool bol;
- for (int i = 0;i< subSelectionSet.length();i++)
- {
- bol = false;
- struct resbuf *rb = NULL;
- service.ssNameX(true,i,rb);
- if (rb != NULL)
- {
- struct resbuf *temrb=rb;
- while(temrb != NULL)
- {
- if(temrb->restype == RTENAME)
- {
- eName[0]=temrb->resval.rlname[0];
- eName[1]=temrb->resval.rlname[1];
- if (addFilterpname != NULL)
- {
- struct resbuf *in_rb = acutBuildList(RTSTR,addFilterpname,RTENAME,eName,RTNONE);
- if(in_rb == NULL)
- {
- acutPrintf(_T("\n程序出错."));
- return;
- }
- struct resbuf *out_rb = NULL;
- int ret = acedInvoke(in_rb,&out_rb);
- if (ret != RTNORM || out_rb == NULL)
- {
- acutPrintf(_T("\n回调函数错误."));
- return;
- }
- if (out_rb->restype == RTNIL)
- {
- bol = true;
- }
- }
- if (!bol && FilterRb != NULL)
- {
- struct resbuf *endata;
- endata = acdbEntGet(eName);
- }
- }
- temrb = temrb->rbnext;
- }
- }
- if (bol)
- {
- service.remove(i);
- }
- }
- }
- int SelectFilter::addSetectFilter(struct resbuf *rb)//这个方法添加回调函数返回真假来过虑对象
- {
- if(rb == NULL || rb->restype != RTSTR)
- {
- return RTERROR;
- }
- if (DocVars.docData().MySelectFilter != NULL)
- {
- DocVars.docData().MySelectFilter->SetPFuncName(rb->resval.rstring);
- acedRetStr(rb->resval.rstring);
- return RTNORM;
- //delete DocVars.docData().MySelectFilter;
- //DocVars.docData().MySelectFilter = NULL;
- }
- DocVars.docData().MySelectFilter = new SelectFilter();
- DocVars.docData().MySelectFilter->SetPFuncName(rb->resval.rstring);
- acedRetStr(rb->resval.rstring);
- return RTNORM;
- }
- int SelectFilter::removeSetectFilter(struct resbuf *rb)//移除反应器
- {
- if (DocVars.docData().MySelectFilter != NULL)
- {
- delete DocVars.docData().MySelectFilter;
- DocVars.docData().MySelectFilter = NULL;
- }
- return RTNORM;
- }
- int SelectFilter::addFilter(struct resbuf *rb)//这个方法想添加一个和SSGET过虑链表一样的过虑器
- {
- if (NULL != DocVars.docData().MySelectFilter)
- {
- delete DocVars.docData().MySelectFilter;
- }
- DocVars.docData().MySelectFilter = new SelectFilter();
- if (RTNORM != DocVars.docData().MySelectFilter->SetFilter(rb))
- {
- delete DocVars.docData().MySelectFilter;
- acutPrintf(_T("\n过虑列表错误。"));
- acedRetNil();
- return ERROR;
- }
- acedRetT();
- return RTNORM;
- }
|
|