Skip to content

Commit 2be4fee

Browse files
findOrCreateVolsegEntry
1 parent 966bda7 commit 2be4fee

File tree

2 files changed

+41
-40
lines changed
  • molstar-extension/src

2 files changed

+41
-40
lines changed

molstar-extension/src/extensions/volumes-and-segmentations/index.ts

+40-39
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ import { PluginContext } from 'molstar/lib/mol-plugin/context';
1212
import { StateAction } from 'molstar/lib/mol-state';
1313
import { Task } from 'molstar/lib/mol-task';
1414
import { DEFAULT_VOLSEG_SERVER, VolumeApiV2 } from './volseg-api/api';
15-
import { GEOMETRIC_SEGMENTATION_NODE_TAG, MESH_SEGMENTATION_NODE_TAG, LATTICE_SEGMENTATION_NODE_TAG, VOLUME_NODE_TAG, VolsegEntryData, VolsegEntryParamValues, createLoadVolsegParams, VolsegEntry, LoadVolsegParamValues } from './entry-root';
15+
import { GEOMETRIC_SEGMENTATION_NODE_TAG, MESH_SEGMENTATION_NODE_TAG, LATTICE_SEGMENTATION_NODE_TAG, VOLUME_NODE_TAG, VolsegEntryData, VolsegEntryParamValues, createLoadVolsegParams, LoadVolsegParamValues, VolsegEntry } from './entry-root';
1616
import { VolsegGlobalState } from './global-state';
1717
import { createEntryId, isDefined } from './helpers';
1818
import { ProjectGeometricSegmentationData, ProjectGeometricSegmentationDataParamsValues, ProjectMeshData, ProjectMeshSegmentationDataParamsValues, ProjectSegmentationData, ProjectLatticeSegmentationDataParamsValues, ProjectVolumeData, VolsegEntryFromRoot, VolsegGlobalStateFromRoot, VolsegStateFromEntry } from './transformers';
1919
import { VolsegUI } from './ui';
2020
import { createSegmentKey, getSegmentLabelsFromDescriptions } from './volseg-api/utils';
21-
import { Source, actionShowSegments, findNodesByRef } from '../../common';
21+
import { actionShowSegments } from '../../common';
22+
import { findNodesByRef, Source } from '../../common';
2223

2324
// const DEBUGGING = typeof window !== 'undefined' ? window?.location?.hostname === 'localhost' || '127.0.0.1' : false;
24-
const DEBUGGING = typeof window !== 'undefined' ? window?.location?.hostname === 'localhost' : false;
25+
export const DEBUGGING = typeof window !== 'undefined' ? window?.location?.hostname === 'localhost' : false;
2526

2627
export const VolsegVolumeServerConfig = {
2728
// DefaultServer: new PluginConfigItem('volseg-volume-server', DEFAULT_VOLUME_SERVER_V2),
@@ -69,41 +70,6 @@ export const Volseg = PluginBehavior.create<{ autoAttach: boolean, showTooltip:
6970
});
7071

7172

72-
export async function findOrCreateVolsegEntry(entryId: string, source: string, plugin: PluginContext) {
73-
const nodes = plugin.state.data.selectQ(q => q.ofType(VolsegEntry)).map(cell => cell?.obj).filter(isDefined);
74-
const targetNode = nodes.find(n => n.data.entryId === entryId && n.data.source === source);
75-
debugger;
76-
const globalStateNode = plugin.state.data.selectQ(q => q.ofType(VolsegGlobalState))[0];
77-
if (!globalStateNode) {
78-
await plugin.state.data.build().toRoot().apply(VolsegGlobalStateFromRoot, {}, { state: { isGhost: !DEBUGGING } }).commit();
79-
}
80-
if (targetNode) {
81-
// TODO: return selector?
82-
// return targetNode;
83-
const n = findNodesByRef(plugin, targetNode.data.ref);
84-
const nn = findNodesByRef(plugin, n.transform.ref);
85-
console.log(nn);
86-
debugger;
87-
return nn;
88-
}
89-
else {
90-
const entryParams = {
91-
serverUrl: plugin?.config.get(VolsegVolumeServerConfig.DefaultServer) ?? DEFAULT_VOLSEG_SERVER,
92-
source: source as Source,
93-
entryId: entryId
94-
};
95-
// const entryParams: LoadVolsegParamValues = {
96-
// serverUrl: defaultVolumeServer,
97-
// source: SourceChoice.PDSelect(),
98-
// entryId: ParamDefinition.Text('emd-1832', { description: 'Entry identifier, including the source prefix, e.g. "emd-1832"' }),
99-
// };
100-
const entryNode = await plugin.state.data.build().toRoot().apply(VolsegEntryFromRoot, entryParams).commit();
101-
await plugin.state.data.build().to(entryNode).apply(VolsegStateFromEntry, {}, { state: { isGhost: !DEBUGGING } }).commit();
102-
debugger;
103-
return entryNode;
104-
}
105-
}
106-
10773
export const LoadVolseg = StateAction.build({
10874
display: { name: 'Load Volume & Segmentation' },
10975
from: SO.Root,
@@ -221,4 +187,39 @@ export const LoadVolseg = StateAction.build({
221187
await actionShowSegments(allSegmentKeysForTimeframe, entryData);
222188
}
223189
}).runInContext(taskCtx);
224-
}));
190+
}));
191+
192+
export async function findOrCreateVolsegEntry(entryId: string, source: string, plugin: PluginContext) {
193+
const nodes = plugin.state.data.selectQ(q => q.ofType(VolsegEntry)).map(cell => cell?.obj).filter(isDefined);
194+
const targetNode = nodes.find(n => n.data.entryId === entryId && n.data.source === source);
195+
debugger;
196+
const globalStateNode = plugin.state.data.selectQ(q => q.ofType(VolsegGlobalState))[0];
197+
if (!globalStateNode) {
198+
await plugin.state.data.build().toRoot().apply(VolsegGlobalStateFromRoot, {}, { state: { isGhost: !DEBUGGING } }).commit();
199+
}
200+
if (targetNode) {
201+
// TODO: return selector?
202+
// return targetNode;
203+
const n = findNodesByRef(plugin, targetNode.data.ref);
204+
const nn = findNodesByRef(plugin, n.transform.ref);
205+
console.log(nn);
206+
debugger;
207+
return nn;
208+
}
209+
else {
210+
const entryParams = {
211+
serverUrl: plugin?.config.get(VolsegVolumeServerConfig.DefaultServer) ?? DEFAULT_VOLSEG_SERVER,
212+
source: source as Source,
213+
entryId: entryId
214+
};
215+
// const entryParams: LoadVolsegParamValues = {
216+
// serverUrl: defaultVolumeServer,
217+
// source: SourceChoice.PDSelect(),
218+
// entryId: ParamDefinition.Text('emd-1832', { description: 'Entry identifier, including the source prefix, e.g. "emd-1832"' }),
219+
// };
220+
const entryNode = await plugin.state.data.build().toRoot().apply(VolsegEntryFromRoot, entryParams).commit();
221+
await plugin.state.data.build().to(entryNode).apply(VolsegStateFromEntry, {}, { state: { isGhost: !DEBUGGING } }).commit();
222+
debugger;
223+
return entryNode;
224+
}
225+
}

molstar-extension/src/viewer/app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { StateObjectRef } from 'molstar/lib/mol-state';
3030
import { Color } from 'molstar/lib/mol-util/color';
3131
import 'molstar/lib/mol-util/polyfill';
3232
import { ObjectKeys } from 'molstar/lib/mol-util/type-helpers';
33-
import { Volseg, findOrCreateVolsegEntry } from '../extensions/volumes-and-segmentations';
33+
import { Volseg } from '../extensions/volumes-and-segmentations';
3434
import { CVSXSpec } from '../extensions/cvsx-extension/behaviour';
3535
import { loadCVSXFromAnything } from '../extensions/cvsx-extension';
3636

0 commit comments

Comments
 (0)