@@ -12,13 +12,13 @@ import { PluginContext } from 'molstar/lib/mol-plugin/context';
12
12
import { StateAction } from 'molstar/lib/mol-state' ;
13
13
import { Task } from 'molstar/lib/mol-task' ;
14
14
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 } from './entry-root' ;
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' ;
16
16
import { VolsegGlobalState } from './global-state' ;
17
- import { createEntryId } from './helpers' ;
17
+ import { createEntryId , isDefined } from './helpers' ;
18
18
import { ProjectGeometricSegmentationData , ProjectGeometricSegmentationDataParamsValues , ProjectMeshData , ProjectMeshSegmentationDataParamsValues , ProjectSegmentationData , ProjectLatticeSegmentationDataParamsValues , ProjectVolumeData , VolsegEntryFromRoot , VolsegGlobalStateFromRoot , VolsegStateFromEntry } from './transformers' ;
19
19
import { VolsegUI } from './ui' ;
20
20
import { createSegmentKey , getSegmentLabelsFromDescriptions } from './volseg-api/utils' ;
21
- import { actionShowSegments } from '../../common' ;
21
+ import { Source , actionShowSegments , findNodesByRef } from '../../common' ;
22
22
23
23
// const DEBUGGING = typeof window !== 'undefined' ? window?.location?.hostname === 'localhost' || '127.0.0.1' : false;
24
24
const DEBUGGING = typeof window !== 'undefined' ? window ?. location ?. hostname === 'localhost' : false ;
@@ -69,6 +69,36 @@ export const Volseg = PluginBehavior.create<{ autoAttach: boolean, showTooltip:
69
69
} ) ;
70
70
71
71
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
+ if ( targetNode ) {
77
+ // TODO: return selector?
78
+ // return targetNode;
79
+ const n = findNodesByRef ( plugin , targetNode . data . ref ) ;
80
+ const nn = findNodesByRef ( plugin , n . transform . ref ) ;
81
+ console . log ( nn ) ;
82
+ debugger ;
83
+ return nn ;
84
+ }
85
+ else {
86
+ const entryParams = {
87
+ serverUrl : plugin ?. config . get ( VolsegVolumeServerConfig . DefaultServer ) ?? DEFAULT_VOLSEG_SERVER ,
88
+ source : source as Source ,
89
+ entryId : entryId
90
+ } ;
91
+ // const entryParams: LoadVolsegParamValues = {
92
+ // serverUrl: defaultVolumeServer,
93
+ // source: SourceChoice.PDSelect(),
94
+ // entryId: ParamDefinition.Text('emd-1832', { description: 'Entry identifier, including the source prefix, e.g. "emd-1832"' }),
95
+ // };
96
+ debugger ;
97
+ const entryNode = await plugin . state . data . build ( ) . toRoot ( ) . apply ( VolsegEntryFromRoot , entryParams ) . commit ( ) ;
98
+ return entryNode ;
99
+ }
100
+ }
101
+
72
102
export const LoadVolseg = StateAction . build ( {
73
103
display : { name : 'Load Volume & Segmentation' } ,
74
104
from : SO . Root ,
@@ -93,7 +123,6 @@ export const LoadVolseg = StateAction.build({
93
123
if ( ! globalStateNode ) {
94
124
await state . build ( ) . toRoot ( ) . apply ( VolsegGlobalStateFromRoot , { } , { state : { isGhost : ! DEBUGGING } } ) . commit ( ) ;
95
125
}
96
-
97
126
const entryNode = await state . build ( ) . toRoot ( ) . apply ( VolsegEntryFromRoot , entryParams ) . commit ( ) ;
98
127
await state . build ( ) . to ( entryNode ) . apply ( VolsegStateFromEntry , { } , { state : { isGhost : ! DEBUGGING } } ) . commit ( ) ;
99
128
if ( entryNode . data ) {
@@ -114,7 +143,8 @@ export const LoadVolseg = StateAction.build({
114
143
if ( result ) {
115
144
const isovalue = result . isovalue . kind === 'relative' ? result . isovalue . relativeValue : result . isovalue . absoluteValue ;
116
145
updatedChannelsData . push (
117
- { channelId : result . channelId , volumeIsovalueKind : result . isovalue . kind , volumeIsovalueValue : isovalue , volumeType : result . volumeType , volumeOpacity : result . opacity ,
146
+ {
147
+ channelId : result . channelId , volumeIsovalueKind : result . isovalue . kind , volumeIsovalueValue : isovalue , volumeType : result . volumeType , volumeOpacity : result . opacity ,
118
148
label : result . label ,
119
149
color : result . color
120
150
}
0 commit comments