Skip to content

Commit

Permalink
Catch snap abandoned exception. (#3634)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbastings authored May 17, 2022
1 parent 51e7d53 commit 18fc6f5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-frontend",
"comment": "Catch snap abandoned exception.",
"type": "none"
}
],
"packageName": "@itwin/core-frontend"
}
101 changes: 53 additions & 48 deletions core/frontend/src/AccuSnap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,64 +705,69 @@ export class AccuSnap implements Decorator {
}
}

const result = await thisHit.iModel.requestSnap(requestProps);
try {
const result = await thisHit.iModel.requestSnap(requestProps);

if (out) out.snapStatus = result.status;
if (result.status !== SnapStatus.Success)
return undefined;
if (out) out.snapStatus = result.status;
if (result.status !== SnapStatus.Success)
return undefined;

const parseCurve = (json: any): CurvePrimitive | undefined => {
const parsed = undefined !== json ? GeomJson.Reader.parse(json) : undefined;
return parsed instanceof GeometryQuery && "curvePrimitive" === parsed.geometryCategory ? parsed : undefined;
};
const parseCurve = (json: any): CurvePrimitive | undefined => {
const parsed = undefined !== json ? GeomJson.Reader.parse(json) : undefined;
return parsed instanceof GeometryQuery && "curvePrimitive" === parsed.geometryCategory ? parsed : undefined;
};

// If this hit is from a plan projection model, apply the model's elevation to the snap point for display.
// Likewise, if it is a hit on a model with a display transform, apply the model's transform to the snap point.
let snapPoint = result.snapPoint!;
const elevation = undefined !== thisHit.modelId ? thisHit.viewport.view.getModelElevation(thisHit.modelId) : 0;
if (0 !== elevation || undefined !== thisHit.viewport.view.modelDisplayTransformProvider) {
const adjustedSnapPoint = Point3d.fromJSON(snapPoint);
thisHit.viewport.view.transformPointByModelDisplayTransform(thisHit.modelId, adjustedSnapPoint, false);
adjustedSnapPoint.z += elevation;
snapPoint = adjustedSnapPoint;
}

// If this hit is from a plan projection model, apply the model's elevation to the snap point for display.
// Likewise, if it is a hit on a model with a display transform, apply the model's transform to the snap point.
let snapPoint = result.snapPoint!;
const elevation = undefined !== thisHit.modelId ? thisHit.viewport.view.getModelElevation(thisHit.modelId) : 0;
if (0 !== elevation || undefined !== thisHit.viewport.view.modelDisplayTransformProvider) {
const adjustedSnapPoint = Point3d.fromJSON(snapPoint);
thisHit.viewport.view.transformPointByModelDisplayTransform(thisHit.modelId, adjustedSnapPoint, false);
adjustedSnapPoint.z += elevation;
snapPoint = adjustedSnapPoint;
}
const snap = new SnapDetail(thisHit, result.snapMode, result.heat, snapPoint);

const snap = new SnapDetail(thisHit, result.snapMode, result.heat, snapPoint);
// Apply model's elevation and display transform to curve for display.
let transform;
if (undefined !== thisHit.modelId && undefined !== thisHit.viewport.view.modelDisplayTransformProvider) {
transform = thisHit.viewport.view.getModelDisplayTransform(thisHit.modelId, Transform.createIdentity());
if (0 !== elevation)
transform.origin.set(0, 0, elevation);
} else if (0 !== elevation) {
transform = Transform.createTranslationXYZ(0, 0, elevation);
}

// Apply model's elevation and display transform to curve for display.
let transform;
if (undefined !== thisHit.modelId && undefined !== thisHit.viewport.view.modelDisplayTransformProvider) {
transform = thisHit.viewport.view.getModelDisplayTransform(thisHit.modelId, Transform.createIdentity());
if (0 !== elevation)
transform.origin.set(0, 0, elevation);
} else if (0 !== elevation) {
transform = Transform.createTranslationXYZ(0, 0, elevation);
}
snap.setCurvePrimitive(parseCurve(result.curve), transform, result.geomType);
if (undefined !== result.parentGeomType)
snap.parentGeomType = result.parentGeomType;
if (undefined !== result.hitPoint) {
snap.hitPoint.setFromJSON(result.hitPoint); // Update hitPoint from readPixels with exact point location corrected to surface/edge geometry...
thisHit.viewport.view.transformPointByModelDisplayTransform(thisHit.modelId, snap.hitPoint, false);
}
if (undefined !== result.normal) {
snap.normal = Vector3d.fromJSON(result.normal);
thisHit.viewport.view.transformNormalByModelDisplayTransform(thisHit.modelId, snap.normal);
}

snap.setCurvePrimitive(parseCurve(result.curve), transform, result.geomType);
if (undefined !== result.parentGeomType)
snap.parentGeomType = result.parentGeomType;
if (undefined !== result.hitPoint) {
snap.hitPoint.setFromJSON(result.hitPoint); // Update hitPoint from readPixels with exact point location corrected to surface/edge geometry...
thisHit.viewport.view.transformPointByModelDisplayTransform(thisHit.modelId, snap.hitPoint, false);
}
if (undefined !== result.normal) {
snap.normal = Vector3d.fromJSON(result.normal);
thisHit.viewport.view.transformNormalByModelDisplayTransform(thisHit.modelId, snap.normal);
}
if (SnapMode.Intersection !== snap.snapMode)
return snap;

if (SnapMode.Intersection !== snap.snapMode)
return snap;
if (undefined === result.intersectId)
return undefined;

if (undefined === result.intersectId)
return undefined;
const otherPrimitive = parseCurve(result.intersectCurve);
if (undefined === otherPrimitive)
return undefined;

const otherPrimitive = parseCurve(result.intersectCurve);
if (undefined === otherPrimitive)
const intersect = new IntersectDetail(snap, snap.heat, snap.snapPoint, otherPrimitive, result.intersectId);
return intersect;
} catch (_err) {
if (out) out.snapStatus = SnapStatus.Aborted;
return undefined;

const intersect = new IntersectDetail(snap, snap.heat, snap.snapPoint, otherPrimitive, result.intersectId);
return intersect;
}
}

private async getAccuSnapDetail(hitList: HitList<HitDetail>, out: LocateResponse): Promise<SnapDetail | undefined> {
Expand Down

0 comments on commit 18fc6f5

Please sign in to comment.