feat: add FailureReason to FaceInferResult for specific error messages

- FaceInferToolPlugin now returns specific reasons: '未命中模型' or '表面过窄'
- ViewModel handlers show FailureReason instead of generic '未命中有效表面'
- Catch exceptions still pass through BuildFromFaceNormal error messages
This commit is contained in:
tian 2026-06-09 02:53:41 +08:00
parent cd05553dd9
commit d3b2906169
3 changed files with 21 additions and 26 deletions

View File

@ -3,22 +3,15 @@ using Autodesk.Navisworks.Api;
namespace NavisworksTransport
{
/// <summary>
/// 快速取面结果。
/// 所有坐标为宿主坐标系。
/// 快速取面结果。所有坐标为宿主坐标系。
/// </summary>
public class FaceInferResult
{
/// <summary>点击命中点(宿主坐标系)</summary>
public Point3D HitPoint { get; }
/// <summary>面法向量(已归一化,朝向相机)</summary>
public Vector3D Normal { get; }
/// <summary>命中的 ModelItem</summary>
public ModelItem ModelItem { get; }
/// <summary>推断是否成功</summary>
public bool IsValid { get; }
public string FailureReason { get; }
public FaceInferResult(Point3D hitPoint, Vector3D normal, ModelItem modelItem)
{
@ -26,10 +19,20 @@ namespace NavisworksTransport
Normal = normal;
ModelItem = modelItem;
IsValid = modelItem != null;
FailureReason = null;
}
/// <summary>创建失败结果</summary>
public static FaceInferResult Invalid { get; } = new FaceInferResult(
new Point3D(), new Vector3D(), null);
private FaceInferResult(string failureReason)
{
HitPoint = new Point3D();
Normal = new Vector3D();
ModelItem = null;
IsValid = false;
FailureReason = failureReason;
}
public static FaceInferResult Invalid { get; } = new FaceInferResult(new Point3D(), new Vector3D(), null);
public static FaceInferResult Failure(string reason) => new FaceInferResult(reason);
}
}

View File

@ -99,7 +99,7 @@ namespace NavisworksTransport
// 拾取中心点
var centerPick = view.PickItemFromPoint(x, y);
if (centerPick == null)
return FaceInferResult.Invalid;
return FaceInferResult.Failure("未命中任何模型,请点击模型表面。");
var p0 = centerPick.Point;
@ -145,7 +145,7 @@ namespace NavisworksTransport
}
LogManager.Debug("[FaceInferTool] 所有偏移量均无法推断平面");
return FaceInferResult.Invalid;
return FaceInferResult.Failure("点击位置表面过窄或不平整,无法推断平面。\n请点击较大的平整表面。");
}
// ---- Vector3D 辅助方法(避免依赖 Navisworks Vector3D 静态方法在不同版本的可用性差异)----

View File

@ -2434,12 +2434,8 @@ namespace NavisworksTransport.UI.WPF.ViewModels
if (!result.IsValid)
{
CleanupAssemblyEndFaceSelection(clearVisuals: false);
DialogHelper.ShowStatusAndDialog(
"未命中有效表面。",
"取端面失败",
"未命中有效表面。\n请在终点箱体端面上点击。",
UpdateMainStatus,
System.Windows.MessageBoxImage.Warning);
var reason = result.FailureReason ?? "未命中有效表面。";
DialogHelper.ShowStatusAndDialog(reason, "取端面失败", reason, UpdateMainStatus, System.Windows.MessageBoxImage.Warning);
return;
}
@ -2567,12 +2563,8 @@ namespace NavisworksTransport.UI.WPF.ViewModels
if (!result.IsValid)
{
CleanupAssemblyInstallationSelection();
DialogHelper.ShowStatusAndDialog(
"未命中有效表面。",
"选安装面失败",
"未命中有效表面。",
UpdateMainStatus,
System.Windows.MessageBoxImage.Warning);
var reason = result.FailureReason ?? "未命中有效表面。";
DialogHelper.ShowStatusAndDialog(reason, "选安装面失败", reason, UpdateMainStatus, System.Windows.MessageBoxImage.Warning);
return;
}