using Autodesk.Navisworks.Api; using Microsoft.VisualStudio.TestTools.UnitTesting; using NavisworksTransport.Core.Animation; using NavisworksTransport.Utils.CoordinateSystem; namespace NavisworksTransport.UnitTests.CoordinateSystem { [TestClass] public class RailPreservedPoseTests { [TestMethod] public void ResolvePreservedPoseRotation_ShouldPreferActualGeometryRotationForRealObjects() { Rotation3D fallbackRotation = new Rotation3D(0.0, 0.0, 0.0, 1.0); Rotation3D actualGeometryRotation = new Rotation3D(0.0, 0.70710678, 0.0, 0.70710678); Rotation3D resolved = PathAnimationManager.ResolvePreservedPoseRotation( preferActualGeometryRotation: true, hasActualGeometryRotation: true, actualGeometryRotation: actualGeometryRotation, fallbackRotation: fallbackRotation); Assert.AreEqual(actualGeometryRotation.A, resolved.A, 1e-9); Assert.AreEqual(actualGeometryRotation.B, resolved.B, 1e-9); Assert.AreEqual(actualGeometryRotation.C, resolved.C, 1e-9); Assert.AreEqual(actualGeometryRotation.D, resolved.D, 1e-9); } [TestMethod] public void ResolvePreservedPoseRotation_ShouldFallbackWhenActualGeometryRotationUnavailable() { Rotation3D fallbackRotation = new Rotation3D(0.0, 0.0, 0.38268343, 0.92387953); Rotation3D actualGeometryRotation = new Rotation3D(0.0, 0.70710678, 0.0, 0.70710678); Rotation3D resolved = PathAnimationManager.ResolvePreservedPoseRotation( preferActualGeometryRotation: true, hasActualGeometryRotation: false, actualGeometryRotation: actualGeometryRotation, fallbackRotation: fallbackRotation); Assert.AreEqual(fallbackRotation.A, resolved.A, 1e-9); Assert.AreEqual(fallbackRotation.B, resolved.B, 1e-9); Assert.AreEqual(fallbackRotation.C, resolved.C, 1e-9); Assert.AreEqual(fallbackRotation.D, resolved.D, 1e-9); } [TestMethod] public void ShouldPreservePathRotationForFrames_ShouldEnableHoistingWhenTranslationModeHasLockedRotation() { bool shouldPreserve = PathAnimationManager.ShouldPreservePathRotationForFrames( PathType.Hoisting, ObjectStartPlacementMode.PreserveInitialPose, hasPreservedRotation: true); Assert.IsTrue(shouldPreserve); } [TestMethod] public void ShouldPreservePathRotationForFrames_ShouldEnableRailWhenTranslationModeHasLockedRotation() { bool shouldPreserve = PathAnimationManager.ShouldPreservePathRotationForFrames( PathType.Rail, ObjectStartPlacementMode.PreserveInitialPose, hasPreservedRotation: true); Assert.IsTrue(shouldPreserve); } [TestMethod] public void ShouldPreservePathRotationForFrames_ShouldDisableGroundEvenInTranslationMode() { bool shouldPreserve = PathAnimationManager.ShouldPreservePathRotationForFrames( PathType.Ground, ObjectStartPlacementMode.PreserveInitialPose, hasPreservedRotation: true); Assert.IsFalse(shouldPreserve); } [TestMethod] public void ShouldPreservePathRotationForFrames_ShouldDisableWhenLockedRotationMissing() { bool shouldPreserve = PathAnimationManager.ShouldPreservePathRotationForFrames( PathType.Hoisting, ObjectStartPlacementMode.PreserveInitialPose, hasPreservedRotation: false); Assert.IsFalse(shouldPreserve); } [TestMethod] public void ShouldAllowFragmentPlanarFallback_ShouldDisableHoisting() { Assert.IsFalse(PathAnimationManager.ShouldAllowFragmentPlanarFallback(PathType.Hoisting)); Assert.IsTrue(PathAnimationManager.ShouldAllowFragmentPlanarFallback(PathType.Ground)); Assert.IsTrue(PathAnimationManager.ShouldAllowFragmentPlanarFallback(PathType.Rail)); } [TestMethod] public void ResolveCurrentRotationBaseline_ShouldPreferActualGeometryForHoisting() { Rotation3D trackedRotation = new Rotation3D(0.0, 0.0, 0.0, 1.0); Rotation3D actualGeometryRotation = new Rotation3D(0.0, 0.70710678, 0.0, 0.70710678); Rotation3D resolved = PathAnimationManager.ResolveCurrentRotationBaseline( PathType.Hoisting, isRealObjectMode: true, hasTrackedRotation: true, trackedRotation: trackedRotation, hasReferenceRotation: false, referenceRotation: Rotation3D.Identity, transformRotation: Rotation3D.Identity, hasActualGeometryRotation: true, actualGeometryRotation: actualGeometryRotation); Assert.AreEqual(actualGeometryRotation.A, resolved.A, 1e-9); Assert.AreEqual(actualGeometryRotation.B, resolved.B, 1e-9); Assert.AreEqual(actualGeometryRotation.C, resolved.C, 1e-9); Assert.AreEqual(actualGeometryRotation.D, resolved.D, 1e-9); } [TestMethod] public void ResolveCurrentRotationBaseline_ShouldKeepTrackedRotationForGround() { Rotation3D trackedRotation = new Rotation3D(0.0, 0.0, 0.38268343, 0.92387953); Rotation3D actualGeometryRotation = new Rotation3D(0.0, 0.70710678, 0.0, 0.70710678); Rotation3D resolved = PathAnimationManager.ResolveCurrentRotationBaseline( PathType.Ground, isRealObjectMode: true, hasTrackedRotation: true, trackedRotation: trackedRotation, hasReferenceRotation: false, referenceRotation: Rotation3D.Identity, transformRotation: Rotation3D.Identity, hasActualGeometryRotation: true, actualGeometryRotation: actualGeometryRotation); Assert.AreEqual(trackedRotation.A, resolved.A, 1e-9); Assert.AreEqual(trackedRotation.B, resolved.B, 1e-9); Assert.AreEqual(trackedRotation.C, resolved.C, 1e-9); Assert.AreEqual(trackedRotation.D, resolved.D, 1e-9); } [TestMethod] public void ShouldUseRealObjectOverrideRotation_ShouldEnableForRealObjects() { Assert.IsTrue(PathAnimationManager.ShouldUseRealObjectOverrideRotation(true)); Assert.IsFalse(PathAnimationManager.ShouldUseRealObjectOverrideRotation(false)); } [TestMethod] public void ShouldUseOriginalBoundingBoxCenterForBusinessTrackedPosition_ShouldEnableOnlyForGroundRealObjects() { Assert.IsTrue(PathAnimationManager.ShouldUseOriginalBoundingBoxCenterForBusinessTrackedPosition( PathType.Ground, isRealObjectMode: true)); Assert.IsFalse(PathAnimationManager.ShouldUseOriginalBoundingBoxCenterForBusinessTrackedPosition( PathType.Ground, isRealObjectMode: false)); Assert.IsFalse(PathAnimationManager.ShouldUseOriginalBoundingBoxCenterForBusinessTrackedPosition( PathType.Hoisting, isRealObjectMode: true)); Assert.IsFalse(PathAnimationManager.ShouldUseOriginalBoundingBoxCenterForBusinessTrackedPosition( PathType.Rail, isRealObjectMode: true)); } [TestMethod] public void ResolveHoistingPoseSourceLabel_ShouldDescribeCachedBasePose() { Assert.AreEqual("缓存基姿态", PathAnimationManager.ResolveHoistingPoseSourceLabel(true)); Assert.AreEqual("实际几何姿态基线", PathAnimationManager.ResolveHoistingPoseSourceLabel(false)); } } }