From adfd4cd039dcd020d1ee8d1aaaf97be490954aa1 Mon Sep 17 00:00:00 2001 From: Kenneth Yang Date: Sun, 22 Sep 2024 14:05:29 -0700 Subject: [PATCH] Add warning if pitch is less than 30 --- .../AutomationStack/AutomationStackHandler.cs | 2 +- ...utomationStackHandler_BregmaCalibration.cs | 3 ++- .../AutomationStackHandler_DuraCalibration.cs | 3 ++- .../AutomationStackHandler_TargetInsertion.cs | 5 ++-- .../Scripts/UI/States/AutomationStackState.cs | 23 ++++++++++++++++--- Assets/UI/Components/AutomationStack.uxml | 5 ++++ 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/UI/AutomationStack/AutomationStackHandler.cs b/Assets/Scripts/UI/AutomationStack/AutomationStackHandler.cs index c91c9ca7..7f208f69 100644 --- a/Assets/Scripts/UI/AutomationStack/AutomationStackHandler.cs +++ b/Assets/Scripts/UI/AutomationStack/AutomationStackHandler.cs @@ -130,7 +130,7 @@ private void OnDisable() private void FixedUpdate() { // Shortcut exit if not enabled and cleanup. - if (!_state.IsEnabled) + if (!AutomationStackState.IsEnabled) { FlushTargetInsertionOptionsCache(); return; diff --git a/Assets/Scripts/UI/AutomationStack/AutomationStackHandler_BregmaCalibration.cs b/Assets/Scripts/UI/AutomationStack/AutomationStackHandler_BregmaCalibration.cs index e4306981..008ed20a 100644 --- a/Assets/Scripts/UI/AutomationStack/AutomationStackHandler_BregmaCalibration.cs +++ b/Assets/Scripts/UI/AutomationStack/AutomationStackHandler_BregmaCalibration.cs @@ -1,4 +1,5 @@ using System; +using UI.States; namespace UI.AutomationStack { @@ -10,7 +11,7 @@ public partial class AutomationStackHandler private async partial void ResetBregmaCalibration() { // Throw exception if invariant is violated. - if (!_state.IsEnabled) + if (!AutomationStackState.IsEnabled) throw new InvalidOperationException( "Cannot reset Bregma calibration if automation is not enabled on probe " + ProbeManager.ActiveProbeManager.name diff --git a/Assets/Scripts/UI/AutomationStack/AutomationStackHandler_DuraCalibration.cs b/Assets/Scripts/UI/AutomationStack/AutomationStackHandler_DuraCalibration.cs index fa8ef9b8..ff90c394 100644 --- a/Assets/Scripts/UI/AutomationStack/AutomationStackHandler_DuraCalibration.cs +++ b/Assets/Scripts/UI/AutomationStack/AutomationStackHandler_DuraCalibration.cs @@ -1,4 +1,5 @@ using System; +using UI.States; namespace UI.AutomationStack { @@ -9,7 +10,7 @@ public partial class AutomationStackHandler { private async partial void OnResetDuraCalibrationPressed() { - if (!_state.IsEnabled) + if (!AutomationStackState.IsEnabled) throw new InvalidOperationException( "Cannot reset Dura calibration if automation is not enabled on probe " + ProbeManager.ActiveProbeManager.name diff --git a/Assets/Scripts/UI/AutomationStack/AutomationStackHandler_TargetInsertion.cs b/Assets/Scripts/UI/AutomationStack/AutomationStackHandler_TargetInsertion.cs index d2d0523f..caec55c6 100644 --- a/Assets/Scripts/UI/AutomationStack/AutomationStackHandler_TargetInsertion.cs +++ b/Assets/Scripts/UI/AutomationStack/AutomationStackHandler_TargetInsertion.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Pinpoint.Probes; +using UI.States; using UnityEngine; using UnityEngine.UIElements; @@ -62,7 +63,7 @@ private partial void OnTargetInsertionSelectionChanged(ChangeEvent changeEv { // TODO: Change to throw exception if invariant is violated once update issue is resolved. // Shortcut exit if invariant is violated. - if (!_state.IsEnabled) + if (!AutomationStackState.IsEnabled) return; // throw new InvalidOperationException( // "Cannot select target insertion if automation is not enabled on probe " @@ -175,7 +176,7 @@ void CheckFinalInsertionIsOutOfBounds() private async partial void OnDriveToTargetEntryCoordinatePressed() { // Throw exception if invariant is violated. - if (!_state.IsEnabled || !ActiveProbeStateManager.IsCalibrated()) + if (!AutomationStackState.IsEnabled || !ActiveProbeStateManager.IsCalibrated()) throw new InvalidOperationException( $"Cannot drive {ProbeManager.ActiveProbeManager.name} to target insertion if not enabled and not calibrated to Bregma." ); diff --git a/Assets/Scripts/UI/States/AutomationStackState.cs b/Assets/Scripts/UI/States/AutomationStackState.cs index 5df9212b..3710b97f 100644 --- a/Assets/Scripts/UI/States/AutomationStackState.cs +++ b/Assets/Scripts/UI/States/AutomationStackState.cs @@ -32,16 +32,33 @@ public class AutomationStackState : ResettingScriptableObject #region Panel + /// + /// Is the current probe's pitch valid for automation. + /// + /// True if the probe's pitch is above 30°, false otherwise (or when there is no active probe). + private static bool IsPitchValid => + ProbeManager.ActiveProbeManager + && ProbeManager.ActiveProbeManager.ProbeController.Insertion.Pitch > 30; + + /// + /// Visibility of the pitch warning. + /// + /// Flex when the pitch is invalid, none otherwise. + /// + [CreateProperty] + public DisplayStyle PitchWarningDisplayStyle => + !IsPitchValid ? DisplayStyle.Flex : DisplayStyle.None; + /// /// Is the entire Automation stack enabled. /// /// True when the active probe manager is Ephys Link controlled. [CreateProperty] // ReSharper disable once MemberCanBePrivate.Global - // ReSharper disable once MemberCanBeMadeStatic.Global - public bool IsEnabled => + public static bool IsEnabled => ProbeManager.ActiveProbeManager - && ProbeManager.ActiveProbeManager.IsEphysLinkControlled; + && ProbeManager.ActiveProbeManager.IsEphysLinkControlled + && IsPitchValid; #endregion diff --git a/Assets/UI/Components/AutomationStack.uxml b/Assets/UI/Components/AutomationStack.uxml index 6bd9838a..b83a2ae2 100644 --- a/Assets/UI/Components/AutomationStack.uxml +++ b/Assets/UI/Components/AutomationStack.uxml @@ -1,5 +1,10 @@