diff --git a/molstar-extension/src/extensions/volumes-and-segmentations/entry-root.ts b/molstar-extension/src/extensions/volumes-and-segmentations/entry-root.ts index 3b1f8f56..314dd67e 100644 --- a/molstar-extension/src/extensions/volumes-and-segmentations/entry-root.ts +++ b/molstar-extension/src/extensions/volumes-and-segmentations/entry-root.ts @@ -71,7 +71,7 @@ function entryParam(entries: string[] = []) { customEntryId: ParamDefinition.Text('', { hideIf: p => p.entryId !== '__custom__', description: 'Entry identifier, including the source prefix, e.g. "emd-1832"' }), }, { isFlat: true }); } -type LoadVolsegParamValues = ParamDefinition.Values>; +export type LoadVolsegParamValues = ParamDefinition.Values>; type RawDataKind = 'volume' | 'segmentation' | 'mesh' | 'primitive'; export function createVolsegEntryParams(plugin?: PluginContext) { diff --git a/molstar-extension/src/extensions/volumes-and-segmentations/index.ts b/molstar-extension/src/extensions/volumes-and-segmentations/index.ts index 82f1b13e..36ed0ea5 100644 --- a/molstar-extension/src/extensions/volumes-and-segmentations/index.ts +++ b/molstar-extension/src/extensions/volumes-and-segmentations/index.ts @@ -12,13 +12,13 @@ import { PluginContext } from 'molstar/lib/mol-plugin/context'; import { StateAction } from 'molstar/lib/mol-state'; import { Task } from 'molstar/lib/mol-task'; import { DEFAULT_VOLSEG_SERVER, VolumeApiV2 } from './volseg-api/api'; -import { GEOMETRIC_SEGMENTATION_NODE_TAG, MESH_SEGMENTATION_NODE_TAG, LATTICE_SEGMENTATION_NODE_TAG, VOLUME_NODE_TAG, VolsegEntryData, VolsegEntryParamValues, createLoadVolsegParams } from './entry-root'; +import { GEOMETRIC_SEGMENTATION_NODE_TAG, MESH_SEGMENTATION_NODE_TAG, LATTICE_SEGMENTATION_NODE_TAG, VOLUME_NODE_TAG, VolsegEntryData, VolsegEntryParamValues, createLoadVolsegParams, VolsegEntry, LoadVolsegParamValues } from './entry-root'; import { VolsegGlobalState } from './global-state'; -import { createEntryId } from './helpers'; +import { createEntryId, isDefined } from './helpers'; import { ProjectGeometricSegmentationData, ProjectGeometricSegmentationDataParamsValues, ProjectMeshData, ProjectMeshSegmentationDataParamsValues, ProjectSegmentationData, ProjectLatticeSegmentationDataParamsValues, ProjectVolumeData, VolsegEntryFromRoot, VolsegGlobalStateFromRoot, VolsegStateFromEntry } from './transformers'; import { VolsegUI } from './ui'; import { createSegmentKey, getSegmentLabelsFromDescriptions } from './volseg-api/utils'; -import { actionShowSegments } from '../../common'; +import { Source, actionShowSegments, findNodesByRef } from '../../common'; // const DEBUGGING = typeof window !== 'undefined' ? window?.location?.hostname === 'localhost' || '127.0.0.1' : false; const DEBUGGING = typeof window !== 'undefined' ? window?.location?.hostname === 'localhost' : false; @@ -69,6 +69,36 @@ export const Volseg = PluginBehavior.create<{ autoAttach: boolean, showTooltip: }); +export async function findOrCreateVolsegEntry(entryId: string, source: string, plugin: PluginContext) { + const nodes = plugin.state.data.selectQ(q => q.ofType(VolsegEntry)).map(cell => cell?.obj).filter(isDefined); + const targetNode = nodes.find(n => n.data.entryId === entryId && n.data.source === source); + debugger; + if (targetNode) { + // TODO: return selector? + // return targetNode; + const n = findNodesByRef(plugin, targetNode.data.ref); + const nn = findNodesByRef(plugin, n.transform.ref); + console.log(nn); + debugger; + return nn; + } + else { + const entryParams = { + serverUrl: plugin?.config.get(VolsegVolumeServerConfig.DefaultServer) ?? DEFAULT_VOLSEG_SERVER, + source: source as Source, + entryId: entryId + }; + // const entryParams: LoadVolsegParamValues = { + // serverUrl: defaultVolumeServer, + // source: SourceChoice.PDSelect(), + // entryId: ParamDefinition.Text('emd-1832', { description: 'Entry identifier, including the source prefix, e.g. "emd-1832"' }), + // }; + debugger; + const entryNode = await plugin.state.data.build().toRoot().apply(VolsegEntryFromRoot, entryParams).commit(); + return entryNode; + } +} + export const LoadVolseg = StateAction.build({ display: { name: 'Load Volume & Segmentation' }, from: SO.Root, @@ -93,7 +123,6 @@ export const LoadVolseg = StateAction.build({ if (!globalStateNode) { await state.build().toRoot().apply(VolsegGlobalStateFromRoot, {}, { state: { isGhost: !DEBUGGING } }).commit(); } - const entryNode = await state.build().toRoot().apply(VolsegEntryFromRoot, entryParams).commit(); await state.build().to(entryNode).apply(VolsegStateFromEntry, {}, { state: { isGhost: !DEBUGGING } }).commit(); if (entryNode.data) { @@ -114,7 +143,8 @@ export const LoadVolseg = StateAction.build({ if (result) { const isovalue = result.isovalue.kind === 'relative' ? result.isovalue.relativeValue : result.isovalue.absoluteValue; updatedChannelsData.push( - { channelId: result.channelId, volumeIsovalueKind: result.isovalue.kind, volumeIsovalueValue: isovalue, volumeType: result.volumeType, volumeOpacity: result.opacity, + { + channelId: result.channelId, volumeIsovalueKind: result.isovalue.kind, volumeIsovalueValue: isovalue, volumeType: result.volumeType, volumeOpacity: result.opacity, label: result.label, color: result.color }