- UID
- 281509
- 积分
- 1054
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-6-21
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
我在ARX(非DBX)中定义了一个无基类的公共辅助类
其中有三个成员函数:
BOOL CGenericFun::GetXYpoint(AcGePoint3d mLasPt,AcGePoint3d& retPoint,int mBasStyle)
BOOL CGenericFun::GetNearEntity(AcGePoint3d mousePt, AcDbEntity* pEnt, int entStyle)
这个函数的目的给定一点,将它转化为屏幕坐标,然后求出矩形框的屏幕坐标点,最后再将屏幕坐标点转化为CAD的坐标pt1,pt2,进行求选择集,但就是无法得到选择集。可是这个类的其他两个函数均是能运用的。我是在AcEdJig的派生类中的sample函数中调用的。我的目的是在光标移动的时候,不断去建立选择集,以此来分析当前光标是否非常接近某一个实体,如果是,我试图想对该实体进行高亮度显示等一些操作。
void CGenericFun::AddToModeSpace(AcDbEntity *pObj, AcDbObjectId nID)
类定义:
#if !defined(AFX_GENERICFUN_H__8D1C3803_D20E_4CE4_AB8D_18E29DE51EDC__INCLUDED_)
#define AFX_GENERICFUN_H__8D1C3803_D20E_4CE4_AB8D_18E29DE51EDC__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif
#include "dbents.h"
#include "geassign.h"
class CGenericFun
{
public:
void AddToModeSpace(AcDbEntity* pObj,AcDbObjectId nID);
BOOL GetNearEntity(AcGePoint3d mousePt,AcDbEntity* pEnt,int entStyle=0);
BOOL GetXYpoint(AcGePoint3d mLasPt,AcGePoint3d& retPoint,int mBasStyle=0);
CGenericFun();
virtual ~CGenericFun();
};
#endif
类实现:
#include "stdafx.h"
#include "stdarx.h"
#include "resource.h"
#include "GenericFun.h"
#include <string.h>
#include "acedads.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CGenericFun::CGenericFun()
{
}
CGenericFun::~CGenericFun()
{
}
BOOL CGenericFun::GetXYpoint(AcGePoint3d mLasPt,AcGePoint3d& retPoint,int mBasStyle)
{
AcGePoint3d pt0,pt1,pt2;
AcDbPoint* mPt;
if(mBasStyle==0)
{
if(acedGetPoint(asDblArray(mLasPt),"\n输入参考原点:",asDblArray(pt0))!=RTNORM)return false;
if(acedGetPoint(asDblArray(mLasPt),"\n输入第一定位点:",asDblArray(pt1))!=RTNORM)return false;
}
else
{
if(acedGetPoint(NULL,"\n输入参考原点:",asDblArray(pt0))!=RTNORM)return false;
if(acedGetPoint(asDblArray(pt0),"\n输入第一定位点:",asDblArray(pt1))!=RTNORM)return false;
}
mPt=new AcDbPoint;
mPt->setPosition(pt1);
AcDbObjectId mId;
AddToModeSpace(mPt,mId);
if(mBasStyle==0)
{
if(acedGetPoint(asDblArray(mLasPt),"\n输入第二定位点:",asDblArray(pt2))!=RTNORM)return false;
}
else
{
if(acedGetPoint(asDblArray(pt0),"\n输入第二定位点:",asDblArray(pt2))!=RTNORM)return false;
}
retPoint=pt2;
return true;
}
BOOL CGenericFun::GetNearEntity(AcGePoint3d mousePt, AcDbEntity* pEnt, int entStyle)
{
CPoint pt;
HWND mHnd;
CMDIFrameWnd *pFrm;
pFrm=acedGetAcadFrame();
pt.x=mousePt.x;
pt.y=mousePt.y;
mHnd=pFrm->GetActiveFrame()->m_hWnd;
ClientToScreen(mHnd,&pt);
struct resbuf rb;
acedGetVar("cursorsize",&rb);
rb.restype=RTSHORT;
int mLen=rb.resval.rint;
acedGetVar("screensize",&rb);
rb.restype=RTPOINT;
mLen=(int)(rb.resval.rpoint[0]*mLen/200);
ads_point pt1,pt2;
ads_name ssname;
ads_name LineName;
char sbuf[10];
rb.restype=0;
strcpy(sbuf,"LINE");
rb.resval.rstring=sbuf;
rb.rbnext=NULL;
CPoint pt0;
pt0.x=pt.x-mLen;
pt0.y=pt.y-mLen;
ScreenToClient(mHnd,&pt0);
pt1[X]=pt0.x;
pt1[Y]=pt0.y;
pt0.x=pt.x+mLen;
pt0.y=pt.y+mLen;
ScreenToClient(mHnd,&pt0);
pt2[X]=pt0.x;
pt2[Y]=pt0.y;
pt1[Z]=pt2[Z]=0.0;
//以下函数调用就是不行,但编译完全没问题
int ret=acedSSGet("C",pt1,pt2,NULL,ssname);//奇怪啊
long i=0;
acedSSLength(ssname,&i);
acedSSName(ssname,0L,LineName);
AcDbObjectId eId;
acdbGetObjectId(eId,LineName);
AcDbEntity* pLine;
acdbOpenObject(pLine,eId,AcDb::kForWrite);
pLine->setColorIndex(3);
acedSSFree(ssname);
return true;
}
void CGenericFun::AddToModeSpace(AcDbEntity *pObj, AcDbObjectId nID)
{
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlkTbl, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite);
pBlkTbl->close();
pBlkTblRcd->appendAcDbEntity(nID,pObj);
pBlkTblRcd->close();
pObj->close();
}
//一下是在AcEdJig的派生类中调用以上定义类中的成员函数
类定义:
#if !defined(AFX_DRAWANGLINE_H__150A114F_C470_4B24_97F8_451B4CF1B143__INCLUDED_)
#define AFX_DRAWANGLINE_H__150A114F_C470_4B24_97F8_451B4CF1B143__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "GenericFun.h"
class CDrawAngLine : public AcEdJig
{
public:
CDrawAngLine();
virtual ~CDrawAngLine();
public:
void doIt();
virtual AcEdJig::DragStatus sampler();
virtual Adesk::Boolean update();
virtual AcDbEntity* entity()const;
public:
AcDbLine* pLine;
int mBasLine;
AcGePoint3d mStrPt;
AcGePoint3d mSecPt;
AcGePoint3d mCurPt;
CGenericFun* geFun;
};
#endif
类实现
CDrawAngLine::CDrawAngLine()
{
}
CDrawAngLine::~CDrawAngLine()
{
}
void CDrawAngLine::doIt()
{
AcGePoint3d pt0(0,0,0);
int ret;
geFun=new CGenericFun;
acedInitGet(RSG_NOZERO,"A");
ret=acedGetPoint(NULL,"\n输入直线的起点 <输入A空格:相对点>",asDblArray(mStrPt));
if(ret!=RTNORM)
{
if(ret==-5005)
{
geFun->GetXYpoint(pt0,mStrPt,1);
}
else
{
return;
}
}
mBasLine=0;
pLine=new AcDbLine;
setDispPrompt("\n请确定基准线:");
AcEdJig::DragStatus stat=this->drag();
mBasLine=1;
setDispPrompt("\n请输入角度值:");
stat=this->drag();
}
AcEdJig::DragStatus CDrawAngLine::sampler()
{
AcEdJig::DragStatus stat;
static AcGePoint3d temPoint;
if(mBasLine==0)
{
//寻找基准线
setUserInputControls((UserInputControls)(AcEdJig::kAccept3dCoordinates|
AcEdJig::kNullResponseAccepted|
AcEdJig::kNoZeroResponseAccepted));
stat=acquirePoint(mCurPt,mStrPt);
if(temPoint!=mCurPt)
{
temPoint=mCurPt;
//开始寻找
geFun->GetNearEntity(mCurPt,pLine);
}
return AcEdJig::kNoChange;
}
else
{
//让用户输入角度
}
return AcEdJig::kNoChange;
}
Adesk::Boolean CDrawAngLine::update()
{
return Adesk::kTrue;
}
AcDbEntity* CDrawAngLine::entity() const
{
return pLine;
}
最后是定义一个全局的画角度线的命令
// This is command 'DRAWANGLINE'
void wjredcaddrawangline()
{
// TODO: Implement the command
CDrawAngLine* pDrawAngLn=new CDrawAngLine;
pDrawAngLn->doIt();
delete pDrawAngLn;
}
//命令注册的初始化代码中的一段
void InitApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_INIT
AddCommand("WJREDCAD", "AUTOCADINIT", "ACI", ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET, wjredcadautocadinit);
AddCommand("WJREDCAD", "CREATNEWFILE", "CNF", ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET, wjredcadcreatnewfile);
AddCommand("WJREDCAD", "OPENEXISTFILE", "OEF", ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET, wjredcadopenexistfile);
AddCommand("WJREDCAD", "SAVEASFILE", "SAF", ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET, wjredcadsaveasfile);
AddCommand("WJREDCAD", "PAILIAOSYSTEM", "PLX", ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET, wjredcadpailiaosystem);
AddCommand("WJREDCAD", "DRAWSPLINE", "DSP", ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET, wjredcaddrawspline);
AddCommand("WJREDCAD", "DRAWLINE", "DL", ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET, wjredcaddrawline);
AddCommand("WJREDCAD", "DRAWANGLINE", "DAL",
//最后一个命令是画角度线的
ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, wjredcaddrawangline);
//}}AFX_ARX_INIT
// TODO: add your initialization functions
wjredcadautocadinit();
} |
|