Acad::ErrorStatus
AsdkBody::subGetOsnapPoints(
AcDb::OsnapMode osnapMode,
Adesk::GsMarker gsSelectionMark,
const AcGePoint3d& pickPoint,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray & geomIds) const
{
AcGeVector3d viewDir(viewXform(Z, 0), viewXform(Z, 1), viewXform(Z, 2));
if (osnapMode == AcDb::OsnapMode::kOsModeNear) {
AcGePoint3d pNearest(1e+160,1e+160,1e+160);
double distPrj = 1e+160;
Face *face = m_3dGeom.faceList();
for (Face *faceCur = face; faceCur != NULL; faceCur = faceCur->next()) {
for (int iEdge = 0; iEdge < faceCur->edgeCount(); iEdge++) {
Edge *edge = faceCur->edge(iEdge);
Vertex *vertex1 = edge->vertex();
Edge *edgeNext = edge->next();
Vertex *vertex2 = face->edge(0)->vertex();
if (edgeNext != NULL) {
vertex2 = edgeNext->vertex();
}
AcGeLineSeg3d lSeg3d(vertex1->point(), vertex2->point());
AcGePlane viewPlan(vertex1->point(), viewDir);
AcGePoint3d pEndPrj = AcGePoint3d(vertex2->point()).project(viewPlan, viewDir);
AcGeLineSeg3d lsegprj(vertex1->point(), pEndPrj);
AcGePoint3d pickprj = pickPoint.orthoProject(viewPlan);
AcGePointOnCurve3d pOn1;
lsegprj.getClosestPointTo(pickprj, pOn1);
double distPrjCur = pOn1.point().distanceTo(pickprj);
if (distPrjCur < distPrj) {
distPrj = distPrjCur;
lSeg3d.getProjClosestPointTo(pickPoint, viewDir, pOn1);
pNearest = pOn1.point();
}
}
}
snapPoints.append(pNearest);
} else if (osnapMode == AcDb::OsnapMode::kOsModeEnd) {
AcGePoint3d pNearest(1e+160,1e+160,1e+160);
double distPrj = 1e+160;
Face *face = m_3dGeom.faceList();
Face *faceCur = face;
for (Face *faceCur = face; faceCur->next() != NULL; faceCur = faceCur->next()) {
for (int iEdge = 0; iEdge < faceCur->edgeCount(); iEdge++) {
Edge *edge = faceCur->edge(iEdge);
Vertex *vertex1 = edge->vertex();
Edge *edgeNext = edge->next();
Vertex *vertex2 = face->edge(0)->vertex();
if (edgeNext != NULL) {
vertex2 = edgeNext->vertex();
}
AcGePoint3d pStart = vertex1->point();
AcGePoint3d pEnd = vertex2->point();
AcGeLineSeg3d lSeg3d(pStart, pEnd);
AcGePlane viewPlan(pStart, viewDir);
AcGePoint3d pEndPrj = AcGePoint3d(vertex2->point()).project(viewPlan, viewDir);
AcGeLineSeg3d lsegprj(pStart, pEndPrj);
AcGePoint3d pickprj = pickPoint.orthoProject(viewPlan);
AcGePointOnCurve3d pOn1;
lsegprj.getClosestPointTo(pickprj, pOn1);
double distPrjCur = pOn1.point().distanceTo(pickprj);
if (distPrjCur < distPrj) {
distPrj = distPrjCur;
lSeg3d.getProjClosestPointTo(pickPoint, viewDir, pOn1);
if (pStart.distanceTo(pOn1.point()) < pEnd.distanceTo(pOn1.point())) {
pNearest = pStart;
} else {
pNearest = pEnd;
}
}
}
}
snapPoints.append(pNearest);
}
return Acad::eOk;
}