Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using UI.States;

namespace UI.AutomationStack
{
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using UI.States;

namespace UI.AutomationStack
{
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Pinpoint.Probes;
using UI.States;
using UnityEngine;
using UnityEngine.UIElements;

Expand Down Expand Up @@ -62,7 +63,7 @@ private partial void OnTargetInsertionSelectionChanged(ChangeEvent<int> 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 "
Expand Down Expand Up @@ -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."
);
Expand Down
23 changes: 20 additions & 3 deletions Assets/Scripts/UI/States/AutomationStackState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,33 @@ public class AutomationStackState : ResettingScriptableObject

#region Panel

/// <summary>
/// Is the current probe's pitch valid for automation.
/// </summary>
/// <returns>True if the probe's pitch is above 30°, false otherwise (or when there is no active probe).</returns>
private static bool IsPitchValid =>
ProbeManager.ActiveProbeManager
&& ProbeManager.ActiveProbeManager.ProbeController.Insertion.Pitch > 30;

/// <summary>
/// Visibility of the pitch warning.
/// </summary>
/// <returns>Flex when the pitch is invalid, none otherwise.</returns>
/// <see cref="IsPitchValid"/>
[CreateProperty]
public DisplayStyle PitchWarningDisplayStyle =>
!IsPitchValid ? DisplayStyle.Flex : DisplayStyle.None;

/// <summary>
/// Is the entire Automation stack enabled.
/// </summary>
/// <returns>True when the active probe manager is Ephys Link controlled.</returns>
[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

Expand Down
5 changes: 5 additions & 0 deletions Assets/UI/Components/AutomationStack.uxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<engine:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:engine="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<Style src="project://database/Assets/UI/Styles/InspectorStyle.uss?fileID=7433441132597879392&amp;guid=a2355dc3cb713b34c80b9934307f1c56&amp;type=3#InspectorStyle" />
<engine:Label text="Unsupported probe angle.&#10;Ensure pitch is &gt; 30°." style="color: rgb(179, 57, 57); -unity-font-style: bold; white-space: normal;">
<Bindings>
<engine:DataBinding property="style.display" data-source-path="PitchWarningDisplayStyle" binding-mode="ToTarget" data-source="project://database/Assets/Scripts/UI/States/AutomationStackState.asset?fileID=11400000&amp;guid=1f3a268d723c7fe4f90bd218f72aa27d&amp;type=2#AutomationStackState" />
</Bindings>
</engine:Label>
<engine:VisualElement data-source="project://database/Assets/Scripts/UI/States/AutomationStackState.asset?fileID=11400000&amp;guid=1f3a268d723c7fe4f90bd218f72aa27d&amp;type=2#AutomationStackState">
<engine:VisualElement enabled="true" class="inspectorBox">
<engine:Label tabindex="-1" text="Bregma Calibration" parse-escape-sequences="true" display-tooltip-when-elided="true" />
Expand Down