@@ -12,16 +12,17 @@ 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 , 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' ;
16
16
import { VolsegGlobalState } from './global-state' ;
17
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 { Source , actionShowSegments , findNodesByRef } from '../../common' ;
21
+ import { actionShowSegments } from '../../common' ;
22
+ import { findNodesByRef , Source } from '../../common' ;
22
23
23
24
// 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 ;
25
26
26
27
export const VolsegVolumeServerConfig = {
27
28
// DefaultServer: new PluginConfigItem('volseg-volume-server', DEFAULT_VOLUME_SERVER_V2),
@@ -69,41 +70,6 @@ export const Volseg = PluginBehavior.create<{ autoAttach: boolean, showTooltip:
69
70
} ) ;
70
71
71
72
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
-
107
73
export const LoadVolseg = StateAction . build ( {
108
74
display : { name : 'Load Volume & Segmentation' } ,
109
75
from : SO . Root ,
@@ -221,4 +187,39 @@ export const LoadVolseg = StateAction.build({
221
187
await actionShowSegments ( allSegmentKeysForTimeframe , entryData ) ;
222
188
}
223
189
} ) . 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
+ }
0 commit comments