实现夹点函数
AutoCAD 图元具有当用户选择带有指针设备的图元时显示的夹点。该函数返回已为实体定义的夹点。该函数执行由夹点编辑导致的实体修改。getGripPoints()moveGripPointsAt() 使用夹点编辑中的拉伸模式,您可以通过将选定的夹点移动到新位置来拉伸对象。AutoCAD 在用户处于拉伸模式时调用该函数。但是,对于某些实体,某些夹点会移动对象而不是拉伸对象。这些夹点包括对文本对象、块、线条中点、圆心、椭圆中心和点对象的夹点。在这些情况下,该函数调用 .moveGripPointsAt()moveGripPointsAt()transformBy() 注意:该函数的默认实现是调用该函数。AcDbEntity::moveGripPointsAt()transformBy()
当用户处于抓取、移动、旋转、缩放或镜像模式时,AutoCAD 将调用“图元”部分中所述的函数。transformBy() 如果希望用户能够使用夹点编辑实体,则需要重写 and 函数。该实体定义其夹持点以及如何解释用户提供的偏移量。subGetGripPoints()subMoveGripPointsAt() 下面的摘录演示自定义类如何实现这些函数。此类定义的对象在每个顶点处都有一个夹持点,在其中心有一个夹点。这些抓取点由函数返回。如果用户在夹持拉伸模式下选择夹持点,AutoCAD 将调用该函数。这将调用自定义实体的 ,传入所选抓取点的索引数组和一个 3D 矢量,指定用户移动指点设备的程度。如果用户选择了顶点夹点,则多边形将按指定的偏移量均匀拉伸。如果用户选取了中心夹点,则多边形将简单地平移等于偏移量。(此值将传递给函数,如下所示。AsdkPolysubGetGripPoints()moveGripPointsAt()subMoveGripPointsAt()transformBy() Acad::ErrorStatus
AsdkPoly::subGetGripPoints(
AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
Acad::ErrorStatus es;
if ((es = getVertices3d(gripPoints)) != Acad::eOk) {
return es;
}
// Remove the duplicate point at the start/end and add
// center as the last point.
//
gripPoints.removeAt(gripPoints.length() - 1);
AcGePoint3d center;
getCenter(center);
gripPoints.append(center);
return es;
}
Acad::ErrorStatus
AsdkPoly::subMoveGripPointsAt(
const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
if (indices.length()== 0 || offset.isZeroLength())
return Acad::eOk; //that's easy :-)
if (mDragDataFlags & kCloneMeForDraggingCalled) {
mDragDataFlags |= kUseDragCache;
} else
// Only if we're not dragging do we want to make an undo
// recording and check if the object's open for write.
//
assertWriteEnabled();
//if there more than one hot vertex or there's one and it
// is the center then simply transform
if (indices.length()>1 || indices[0] == mNumSides)
return transformBy(AcGeMatrix3d::translation(offset));
AcGeVector3d off(offset);
//calculate the offset vector of the startpoint
//from the offset vector on a vertex
double rotateBy = 2.0 * 3.14159265358979323846 /
nNumSides * indices[0];
AcGePoint3d cent;
getCenter(cent);
off.transformBy(AcGeMatrix3d::rotation(-rotateBy,
normal(),cent));
acdbWcs2Ecs(asDblArray(off),asDblArray(off),asDblArray(normal()),
Adesk::kTrue);
if (mDragDataFlags & kUseDragCache){
mDragCenter = mCenter;
mDragPlaneNormal = mPlaneNormal;
mDragStartPoint = mStartPoint + AcGeVector2d(off.x,off.y);
mDragElevation = mElevation + off.z;
}else{
mStartPoint = mStartPoint + AcGeVector2d(off.x,off.y);
mElevation = mElevation + off.z;
}
return Acad::eOk;
}
父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-11-3 17:43
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.