您的位置:首页 > 其它

写AcEdJig类的一点心得

2010-07-19 16:21 253 查看
很不幸的,今天被老大训导了,但也因为学到不少东西:

AcGePoint3d (AcGePoint2d )转换 ads_point 用:asDblArray函数。

ads_point 转换AcGePoint2d 用asPnt2d(const double &pnt) 或aspnt3d

acdbUcs2Wcs(ptAds, asDblArray(m_ptStart) ,false), 是表示在CAD中的转换成常用坐标系WCS 进行转换

使用AcDbPolyline类时,必须用到的函数有:

m_pEntity->setNormal(AcGeVector3d::kZAxis);

m_pEntity->setElevation(0.0);

转换成实体所在平面的点:

先定义平面:AcGePlane plane(AcGePoint3d::kOrigin + m_pEntity->normal() * m_pEntity->elevation(), m_pEntity->normal());

AcGePoint2d pt1(m_ptStart.convert2d(plane)), pt2(m_ptEnd.convert2d(plane));

AcGeVector2d vt1(pt2 - pt1);

vt1.normalize();

AcGeVector2d vt2(vt1);

vt2.rotateBy(PI / 2.0);

向量vt1 与

向量vt2 互相垂直

用向量求点更简单(示例):

AcGePoint2d ptMid((pt1.x + pt2.x) / 2.0, (pt1.y + pt2.y) / 2.0);
AcGePoint2d p1(pt1 - vt1 * DbLen);
AcGePoint2d p2(ptMid - vt1 * FuHaoLen / 2);
AcGePoint2d p3(p2 + vt2 * FuHaoWid);
AcGePoint2d p5(ptMid + vt1 * FuHaoLen / 2);
AcGePoint2d p4(p5 - vt2 * FuHaoWid);
AcGePoint2d p6(pt2 + vt1 * DbLen);


还有一点是:变量第一个字母用小写,函数用大写

AcEdJIg的入门用法:

定义一个新类,从AcEdJig中继函

重载AcEdJig三个函数 (必须重载):

AcEdJig::sampler(), which
acquires a geometric value (an angle, a distance, or a point),得到一个角度,距离,或点

AcEdJig::update(), which analyzes
the geometric value and stores it or updates the entity,更新实体数据

AcEdJig::entity(), which
returns a pointer to the entity to be regenerated

sampler 函数示例:这里面尽量不要计算更新的数据

AcEdJig::DragStatus sampler () {
//- Setup the user input controls for each sample
setUserInputControls ((AcEdJig::UserInputControls)	(kNoZeroResponseAccepted| kNoNegativeResponseAccepted | kAccept3dCoordinates)) ;
//setSpecialCursorType (kCrosshair) ;
AcGePoint3d pt;
AcEdJig::DragStatus status = acquirePoint(pt);
if (AcEdJig::kNormal != status)
return status;
if (m_ptEnd.distanceTo(pt) < 0.000000001)
return AcEdJig::kNoChange;
m_ptEnd = pt;
return AcEdJig::kNormal;
}


update函数:计算更新的数据

entity ()返回最终的实体指针;

再定义一个实现函数 。

AcAxDocLock docLock(acdbHostApplicationServices()->workingDatabase()->blockTableId());

setDispPrompt(_T("/n请输入直线的终点:"));
AcEdJig::DragStatus statusDrag = drag();
if (AcEdJig::kNormal == statusDrag)
{
AcDbObjectId id = append();
m_pEntity->close();
}


其中drag 回调的是sampler (),update函数。

注意,应养成一个习惯,在做判断语句时,应该常量应前,变量在后,这样,不至于少使比较符而出错。

如: if (AcEdJig::kNormal == statusDrag)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: