diff --git a/src/mol-plugin/state/transforms/representation.ts b/src/mol-plugin/state/transforms/representation.ts index 08b0c3275ad5fa487fdd5e818217edd6b3f99d47..6b8d31f51c850c5d7ead6ee5cdabfbf2b523c699 100644 --- a/src/mol-plugin/state/transforms/representation.ts +++ b/src/mol-plugin/state/transforms/representation.ts @@ -194,7 +194,12 @@ const StructureLabels3D = PluginStateTransform.BuiltIn({ to: SO.Molecule.Representation3D, params: { // TODO: other targets - target: PD.Select<'elements' | 'residues'>('residues', [['residues', 'Residues'], ['elements', 'Elements']]), + target: PD.MappedStatic('residues', { + 'elements': PD.Group({ }), + 'residues': PD.Group({ }), + 'static-text': PD.Group({ value: PD.Text('') }, { isFlat: true }) + }), + // PD.Select<'elements' | 'residues'>('residues', [['residues', 'Residues'], ['elements', 'Elements']]), options: PD.Group({ ...Text.Params, @@ -212,7 +217,7 @@ const StructureLabels3D = PluginStateTransform.BuiltIn({ apply({ a, params }) { return Task.create('Structure Labels', async ctx => { const repr = await getLabelRepresentation(ctx, a.data, params); - return new SO.Molecule.Representation3D(repr, { label: `Labels`, description: params.target }); + return new SO.Molecule.Representation3D(repr, { label: `Labels`, description: params.target.name }); }); }, update({ a, b, newParams }) { diff --git a/src/mol-plugin/util/structure-labels.ts b/src/mol-plugin/util/structure-labels.ts index 7bdb7bce0af682291d332c55f15378cfc9e5e282..e2057a51e522d6a499f96492357f962847ac4bd2 100644 --- a/src/mol-plugin/util/structure-labels.ts +++ b/src/mol-plugin/util/structure-labels.ts @@ -36,7 +36,7 @@ function getLabelsText(data: LabelsData, props: PD.Values<Text.Params>, text?: T export async function getLabelRepresentation(ctx: RuntimeContext, structure: Structure, params: StateTransformer.Params<StructureLabels3D>, prev?: ShapeRepresentation<LabelsData, Text, Text.Params>) { const repr = prev || ShapeRepresentation(getLabelsShape, Text.Utils); - const data = getLabelData(structure, params.target); + const data = getLabelData(structure, params); await repr.createOrUpdate(params.options, data).runInContext(ctx); return repr; } @@ -47,7 +47,26 @@ function getLabelsShape(ctx: RuntimeContext, data: LabelsData, props: PD.Values< } const boundaryHelper = new BoundaryHelper(); -function getLabelData(structure: Structure, level: 'elements' | 'residues'): LabelsData { +function getLabelData(structure: Structure, params: StateTransformer.Params<StructureLabels3D>): LabelsData { + if (params.target.name === 'static-text') { + return getLabelDataStatic(structure, params.target.params.value); + } else { + return getLabelDataComputed(structure, params.target.name); + } + +} + +function getLabelDataStatic(structure: Structure, text: string): LabelsData { + const boundary = structure.boundary.sphere; + return { + texts: [text], + positions: [boundary.center], + sizes: [1], + depths: [boundary.radius] + }; +} + +function getLabelDataComputed(structure: Structure, level: 'elements' | 'residues'): LabelsData { const data: LabelsData = { texts: [], positions: [], sizes: [], depths: [] }; const l = StructureElement.create();