如果希望自定义实体支持对象对齐模式,则需要覆盖函数。AutoCAD 调用以获取当前模式的相关捕捉点,而当前模式又调用以访问自定义图元的捕捉模式。如果不希望实体支持特定模式的对齐点,则可以筛选出支持的对齐模式并返回其他模式;系统会提示用户再次选择。如果多个对象捕捉模式处于活动状态,则为每个对象捕捉模式调用一次此函数。subGetOsnapPoints()getOsnapPoints()subGetOsnapPoints()eOk 注意:相交对象捕捉模式的处理方式与 不同。它使用,不使用。getOsnapPoints()AcDbEntity::intersectWith()getOsnapPoints()
下面显示了该类如何实现该函数:AsdkPolysubGetOsnapPoints() Acad::ErrorStatus AsdkPoly::subGetOsnapPoints( AcDb::OsnapMode osnapMode, Adesk::GsMarker gsSelectionMark, const AcGePoint3d& pickPoint, const AcGePoint3d& lastPoint, const AcGeMatrix3d& viewXform, AcGePoint3dArray& snapPoints, AcDbIntArray& /*geomIds*/) const { assertReadEnabled(); Acad::ErrorStatus es = Acad::eOk; if (gsSelectionMark == 0) return Acad::eOk; if ( osnapMode != AcDb::kOsModeEnd && osnapMode != AcDb::kOsModeMid && osnapMode != AcDb::kOsModeNear && osnapMode != AcDb::kOsModePerp && osnapMode != AcDb::kOsModeCen && osnapMode != AcDb::kOsModeIns) { return Acad::eOk; } // First, check to see if the gsSelection marker is the // text geometry. If so, handle center and insertion // modes, then return. No need to go into perp, mid, etc. // AcGePoint3d center; getCenter(center); if (gsSelectionMark == (mNumSides + 1)) { if (osnapMode == AcDb::kOsModeIns) snapPoints.append(center); else if (osnapMode == AcDb::kOsModeCen) snapPoints.append(center); return es; } int startIndex = (int)(gsSelectionMark - 1); AcGePoint3dArray vertexArray; if ((es = getVertices3d(vertexArray)) != Acad::eOk) { return es; } AcGeLineSeg3d lnsg(vertexArray[startIndex], vertexArray[startIndex + 1]); AcGePoint3d pt; AcGeLine3d line, perpLine; AcGeVector3d vec; AcGeVector3d viewDir(viewXform(Z, 0), viewXform(Z, 1), viewXform(Z, 2)); switch (osnapMode) { case AcDb::kOsModeEnd: snapPoints.append(vertexArray[startIndex]); snapPoints.append(vertexArray[startIndex + 1]); break; case AcDb::kOsModeMid: pt.set( ((vertexArray[startIndex])[X] + (vertexArray[startIndex + 1])[X]) * 0.5, ((vertexArray[startIndex])[Y] + (vertexArray[startIndex + 1])[Y]) * 0.5, ((vertexArray[startIndex])[Z] + (vertexArray[startIndex + 1])[Z]) * 0.5); snapPoints.append(pt); break; case AcDb::kOsModeNear: pt = lnsg.projClosestPointTo(pickPoint, viewDir); snapPoints.append(pt); break; case AcDb::kOsModePerp: // Create a semi-infinite line and find a point on it. // vec = vertexArray[startIndex + 1] - vertexArray[startIndex]; vec.normalize(); line.set(vertexArray[startIndex], vec); pt = line.closestPointTo(lastPoint); snapPoints.append(pt); break; case AcDb::kOsModeCen: snapPoints.append(center); break; default: return Acad::eOk; } return es; } |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:32
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.