diff --git a/src/neuroglancer/segmentation_user_layer_with_graph.ts b/src/neuroglancer/segmentation_user_layer_with_graph.ts index cd8bd4504..6053f6f06 100644 --- a/src/neuroglancer/segmentation_user_layer_with_graph.ts +++ b/src/neuroglancer/segmentation_user_layer_with_graph.ts @@ -31,7 +31,7 @@ import {StatusMessage} from 'neuroglancer/status'; import {trackableAlphaValue} from 'neuroglancer/trackable_alpha'; import {TrackableBoolean} from 'neuroglancer/trackable_boolean'; import {TrackableValue, WatchableRefCounted, WatchableValue} from 'neuroglancer/trackable_value'; -import {GraphOperationTab, SelectedGraphOperationState} from 'neuroglancer/ui/graph_multicut'; +import {enableSplitPointTool, GraphOperationTab, PlaceGraphOperationMarkerTool, SelectedGraphOperationState} from 'neuroglancer/ui/graph_multicut'; import {Uint64Set} from 'neuroglancer/uint64_set'; import {TrackableRGB} from 'neuroglancer/util/color'; import {Borrowed, RefCounted} from 'neuroglancer/util/disposable'; @@ -322,7 +322,12 @@ function helper(Base: TBase) { break; } case 'switch-multicut-group': { - this.graphOperationLayerState.value!.toggleSource(); + if (this.tool.value === undefined || + (!(this.tool.value instanceof PlaceGraphOperationMarkerTool))) { + enableSplitPointTool(this, this.graphOperationLayerState.value!); + } else { + this.graphOperationLayerState.value!.toggleSource(); + } break; } default: diff --git a/src/neuroglancer/ui/graph_multicut.ts b/src/neuroglancer/ui/graph_multicut.ts index 07ba77ac0..d9e6e4965 100644 --- a/src/neuroglancer/ui/graph_multicut.ts +++ b/src/neuroglancer/ui/graph_multicut.ts @@ -278,6 +278,26 @@ function getCenterPosition(annotation: Annotation, transform: mat4) { return vec3.transformMat4(center, center, transform); } +export function enableSplitPointTool( + layer: SegmentationUserLayerWithGraph, graphOperationLayerState: GraphOperationLayerState) { + layer.tool.value = new PlaceGraphOperationMarkerTool( + layer, {}, + () => { + if (graphOperationLayerState.activeSource === graphOperationLayerState.sourceA) { + return 'set graph red split point'; + } else { + return 'set graph blue split point'; + } + }, + () => { + if (graphOperationLayerState.activeSource === graphOperationLayerState.sourceA) { + return 'rgb(255,0,0)'; + } else { + return 'rgb(120,120,255)'; + } + }); +} + export class GraphOperationLayerView extends Tab { private annotationListContainer = document.createElement('ul'); private annotationListElements = new Map(); @@ -319,24 +339,7 @@ export class GraphOperationLayerView extends Tab { const pointButton = document.createElement('button'); pointButton.textContent = getAnnotationTypeHandler(AnnotationType.POINT).icon; pointButton.title = 'Set split point'; - pointButton.addEventListener('click', () => { - this.wrapper.tool.value = new PlaceGraphOperationMarkerTool( - this.wrapper, {}, - () => { - if (this.annotationLayer.activeSource === sourceA) { - return 'set graph red split point'; - } else { - return 'set graph blue split point'; - } - }, - () => { - if (this.annotationLayer.activeSource === sourceA) { - return 'rgb(255,0,0)'; - } else { - return 'rgb(120,120,255)'; - } - }); - }); + pointButton.addEventListener('click', enableSplitPointTool.bind(undefined, this.wrapper, this.annotationLayer)); toolbox.appendChild(pointButton); }