|
ARX自定义实体常用虚函数
i. 统一说明- sub/非sub
sub开头函数用于vc90以及上版本继承函数,对应的不带sub开头的为vc80及以下版本继承函数。
原因是对于vc90以上版本AcGiDrawable/AcDbEntity类:
Sub开头函数为protect纯虚函数;
对应不带sub开头函数为public实现函数—定义为了非可重载函数。
另外注意: vc90及以上版本部分参数也发生了变化,例如 subGetOsnapPoints的参数2由int改为Adesk::GsMarker
ii. 分解实体-subExplode/explode:
explode用于vc80和以下版本继承函数
subExplode用于vc90及以上版本继承函数
分解的过程是删除本身实体,创建分解实体的过程:
在传入参数中AcDbVoidPtrArray&entitySet,传入clone实体指针,就可以在实体分解的本身清除动作时,创建entitySet中的实体。
iii. 绘制实体-subWorldDraw&subViewPortDraw:
subWorldDraw/worldDraw (AcGiWorldDraw*mode)
subViewPortDraw/viewPortDraw subViewportDraw(AcGiViewportDraw*pVd)
subSetAttribute/setAttribute(AcGiDrawableTraits *traits)
worldDraw绘制实体的公共几何部分,类似于构建一个空间图形;
viewPortDraw绘制指定几何面的图形,类似于把一个空间图形投影到面上来。
setAttributes:指定绘图的一些基本属性,例如线型,颜色等
在AcGiDrawable中定义: (geometry: 几何学)
worldDraw: For geometry shared between multiple viewports
viewPortDraw: For viewport-specific geometry
setAttributes: For default attributes.
在AcDbEntity中定义:
worldDraw: Whenever a regeneration of the entity's graphics is required, AutoCAD calls this function to generate the graphics primitives that will represent this entity on screen. This function will then provide a generic set of 3D graphics primitives that AutoCAD will adjust for each viewport's parameters as they are displayed.
viewPortDraw:Whenever a regeneration of the entity's graphics is required, AutoCAD calls the entity's worldDraw() method. If worldDraw() returns Adesk::kFalse, then AutoCAD calls this function once for each viewport that is currently active in the AutoCAD editor. This function then generates 3D graphic primitives independently for each viewport.
setAttributes: This function provides a way for a custom entity to override the graphical attribute settings (such as color and lineweight) specified in the given AcGiDrawableTraits object. For example, to override the color, use the AcGiDrawableTraits object's setColor() function.
iv. dwg读写实体: dwgInFields/ dwgOutFields
在这个里面把实体中的内容保存在dwg图纸,下次打开dwg图纸时,从图纸时实例化实体,加载实体的内容。有点类似于MFC的Serialization持久化的机制。
v. 获取实体的四至范围-subGetGeomExtents
subGetGeomExtents/GetGeomExtents(AcDbExtents& extents)
获取实体的四至范围,四至范围可能会影晌到实体的刷新。----关于这点尚不太清楚。
对于旋转后实体的四至范围,仍是x/y小点与x/y最大点,对于长方形,旋转后,四至范围的面积变大。
一般情况,简单起见: 可以直接使用包装的内部实体的四至范围,
如m_polyline.GetGeomExtents(extents);作为返回值
vi. 实体变换-subTransformBy
subTransformBy/transformBy(constAcGeMatrix3d&xform)
使用变换矩阵进行三维变换。
Matrix中可能有的变换:
移动,旋转,放大 或者 三种情况N种(多种)操作组合
通常情况下,把这个变换矩阵传递到内部实体中,完成变换
如: m_polyline.transformBy(xform)
vii. 获取捕捉点- subGetOsnapPoints / getOsnapPoints
// 实体捕捉点协议AcDbOsnapOverrule
subGetOsnapPoints/getOsnapPoints(AcDb::OsnapModeosnapMode,Adesk::GsMarkergsSelectionMark,constAcGePoint3d&pickPoint,constAcGePoint3d&lastPoint,constAcGeMatrix3d&viewXform,AcGePoint3dArray&snapPoints,AcDbIntArray&geomIds, < ,constAcGeMatrix3d&insertionMat>)
(注意,参数2在vc90以及上版本为Adesk::GsMarke类型;在vc80及以下版本为int类型;填写错的话会导致捕捉点无效)
subGetOsnapPoints/getOsnapPoints捕捉点提供的话,就可以在开启捕捉的情况下,看到这些返回的特征点,这些捕捉点可以用于其他实体定义时的参考点。例如定义直线上的点时,通过捕捉点,可以选中点作为起点。
如果在其中调用AcDbEntity::subGetOsnapPoints作为处理的的话,相当于没有捕捉点。
viii. 获取夹点subGetGripPoints& subMoveGripPointsAt
// 实体夹点协议 AcDbGripOverrule //夹点编辑协议
subGetGripPoints/getGripPoints(AcGePoint3dArray&gripPoints,AcDbIntArray&osnapModes,AcDbIntArray&geomIds)
subGetGripPoints/getGripPoints(AcDbGripDataPtrArray &grips,constdoublecurViewUnitSize,constintgripSize,constAcGeVector3d&curViewDir,constint bitflags)
subMoveGripPointsAt/moveGripPointsAt (constAcDbIntArray&indices,constAcGeVector3d&offset)
subMoveGripPointsAt/moveGripPointsAt(constAcDbVoidPtrArray&gripAppData,constAcGeVector3d&offset,constintbitflags)
subGetGripPoints/getGripPoints/subMoveGripPointsAt/moveGripPointsAt:这一套函数主要提供夹点编辑操作,当点击之后,提供夹点出来,以供操作,操作之后,根据夹点拖动的情况,进行移动处理。
subGetGripPoints/getGripPoints:如果提供夹点移动操作的话,这个函数必须要继承,因为它缺省处理是无夹点。Default implementation: Immediately returns Adesk::eNotImplemented.
subMoveGripPointsAt/moveGripPointsAt:可以使用其缺省处理,缺省情况下调用transformby移动动像。
Default implementation: Calls the entity'sAcDbEntity::transformBy() method with a transformation matrix that translates the entire entity by offset. It then returns whatever status the transformBy() method returns.
ix. 获取拉伸点- subGetStretchPoints
subGetStretchPoints/getStretchPoints(AcGePoint3dArray& stretchPoints)
subMoveStretchPointsAt/moveStretchPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset);
晌应stretch命令,缺省情况下,相当于位移操作。
GetStretchPoints缺省调用GetGripPoints作为返回结果。在拉伸的过程中moveStretchPoints缺省调用transformBy来实现变形拉伸效果。
getStretchPoints:This function is not intended to be called by ObjectARX applications. However, it is possible to do so (for example, as a pass-through from the getGripPoints() method). Default implementation:Calls theAcDbEntity::getGripPoints() method. So, unless the entity needs to have stretch points that are different from the grip points, there is no need to override this method.
moveStretchPoints:This function is intended to be called by AutoCAD during execution of a stretch command in which the entity has been selected. However, it is certainly possible for ObjectARX applications to call this function.Default implementation:Calls the entity'sAcDbEntity::transformBy() method with a transformation matrix that translates the entire entity by offset. It then returns whatever status the transformBy() method returns.
x. 支持OPM属性subGetClassID/getClassID
subGetClassID/getClassID(CLSID*pClsid): 获取实体的guid,在这个函数中,基于版本号,配置不同的guid。
这个主要是是适配支持OPM属性添加的类,OPM属性机制上大概是基于guid来查找实体的对应显示及支持的操作等。
一般写成形如如下的样子:
static CLSID id;
#if _MSC_VER >= 1600
CLSIDFromString(L"{11111111-11111-1111-1111-111111111111}", &id);
#elif _MSC_VER >= 1500
…
#endif
*pClsid = id; |
|