Browse Source

measurements & labels options

David Sehnal 4 years ago
parent
commit
405d9d524f

+ 17 - 7
src/mol-plugin-state/manager/structure/measurement.ts

@@ -13,7 +13,8 @@ import { arraySetAdd } from '../../../mol-util/array';
 import { PluginStateObject } from '../../objects';
 import { StatefulPluginComponent } from '../../component';
 import { ParamDefinition as PD } from '../../../mol-util/param-definition';
-import { MeasurementRepresentationCommonTextParams } from '../../../mol-repr/shape/loci/common';
+import { MeasurementRepresentationCommonTextParams, LociLabelTextParams } from '../../../mol-repr/shape/loci/common';
+import { LineParams } from '../../../mol-repr/structure/representation/line';
 
 export { StructureMeasurementManager };
 
@@ -40,7 +41,9 @@ export interface StructureMeasurementManagerState {
 type StructureMeasurementManagerAddOptions = {
     customText?: string,
     selectionTags?: string | string[],
-    reprTags?: string | string[]
+    reprTags?: string | string[],
+    lineParams?: Partial<PD.Values<LineParams>>,
+    labelParams?: Partial<PD.Values<LociLabelTextParams>>
 }
 
 class StructureMeasurementManager extends StatefulPluginComponent<StructureMeasurementManagerState>  {
@@ -108,7 +111,9 @@ class StructureMeasurementManager extends StatefulPluginComponent<StructureMeasu
             .apply(StateTransforms.Representation.StructureSelectionsDistance3D, {
                 customText: options?.customText || '',
                 unitLabel: this.state.options.distanceUnitLabel,
-                textColor: this.state.options.textColor
+                textColor: this.state.options.textColor,
+                ...options?.lineParams,
+                ...options?.labelParams
             }, { tags: options?.reprTags });
 
         const state = this.plugin.state.data;
@@ -139,7 +144,9 @@ class StructureMeasurementManager extends StatefulPluginComponent<StructureMeasu
             }, { dependsOn, tags: options?.selectionTags })
             .apply(StateTransforms.Representation.StructureSelectionsAngle3D, {
                 customText: options?.customText || '',
-                textColor: this.state.options.textColor
+                textColor: this.state.options.textColor,
+                ...options?.lineParams,
+                ...options?.labelParams
             }, { tags: options?.reprTags });
 
         const state = this.plugin.state.data;
@@ -173,14 +180,16 @@ class StructureMeasurementManager extends StatefulPluginComponent<StructureMeasu
             }, { dependsOn, tags: options?.selectionTags })
             .apply(StateTransforms.Representation.StructureSelectionsDihedral3D, {
                 customText: options?.customText || '',
-                textColor: this.state.options.textColor
+                textColor: this.state.options.textColor,
+                ...options?.lineParams,
+                ...options?.labelParams
             }, { tags: options?.reprTags });
 
         const state = this.plugin.state.data;
         await PluginCommands.State.Update(this.plugin, { state, tree: update, options: { doNotLogTiming: true } });
     }
 
-    async addLabel(a: StructureElement.Loci, options?: Omit<StructureMeasurementManagerAddOptions, 'customText'>) {
+    async addLabel(a: StructureElement.Loci, options?: Omit<StructureMeasurementManagerAddOptions, 'customText' | 'lineParams'>) {
         const cellA = this.plugin.helpers.substructureParent.get(a.structure);
 
         if (!cellA) return;
@@ -197,7 +206,8 @@ class StructureMeasurementManager extends StatefulPluginComponent<StructureMeasu
                 label: 'Label'
             }, { dependsOn, tags: options?.selectionTags })
             .apply(StateTransforms.Representation.StructureSelectionsLabel3D, {
-                textColor: this.state.options.textColor
+                textColor: this.state.options.textColor,
+                ...options?.labelParams
             }, { tags: options?.reprTags });
 
         const state = this.plugin.state.data;

+ 3 - 10
src/mol-repr/shape/loci/angle.ts

@@ -24,7 +24,7 @@ import { transformPrimitive } from '../../../mol-geo/primitive/primitive';
 import { MarkerActions, MarkerAction } from '../../../mol-util/marker-action';
 import { angleLabel } from '../../../mol-theme/label';
 import { Sphere3D } from '../../../mol-math/geometry';
-import { MeasurementRepresentationCommonTextParams } from './common';
+import { LociLabelTextParams } from './common';
 
 export interface AngleData {
     triples: Loci.Bundle<3>[]
@@ -61,25 +61,18 @@ const SectorParams = {
 };
 type SectorParams = typeof SectorParams
 
-const TextParams = {
-    ...Text.Params,
-    ...MeasurementRepresentationCommonTextParams,
-    borderWidth: PD.Numeric(0.2, { min: 0, max: 0.5, step: 0.01 })
-};
-type TextParams = typeof TextParams
-
 const AngleVisuals = {
     'vectors': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<AngleData, VectorsParams>) => ShapeRepresentation(getVectorsShape, Lines.Utils, { modifyState: s => ({ ...s, pickable: false }) }),
     'arc': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<AngleData, ArcParams>) => ShapeRepresentation(getArcShape, Lines.Utils, { modifyState: s => ({ ...s, pickable: false }) }),
     'sector': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<AngleData, SectorParams>) => ShapeRepresentation(getSectorShape, Mesh.Utils, { modifyProps: p => ({ ...p, alpha: p.sectorOpacity }), modifyState: s => ({ ...s, markerActions: MarkerActions.Highlighting }) }),
-    'text': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<AngleData, TextParams>) => ShapeRepresentation(getTextShape, Text.Utils, { modifyState: s => ({ ...s, markerActions: MarkerAction.None }) }),
+    'text': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<AngleData, LociLabelTextParams>) => ShapeRepresentation(getTextShape, Text.Utils, { modifyState: s => ({ ...s, markerActions: MarkerAction.None }) }),
 };
 
 export const AngleParams = {
     ...VectorsParams,
     ...ArcParams,
     ...SectorParams,
-    ...TextParams,
+    ...LociLabelTextParams,
     visuals: PD.MultiSelect(['vectors', 'sector', 'text'], PD.objectToOptions(AngleVisuals)),
 };
 export type AngleParams = typeof AngleParams

+ 9 - 1
src/mol-repr/shape/loci/common.ts

@@ -7,9 +7,17 @@
 
 import { ParamDefinition as PD } from '../../../mol-util/param-definition';
 import { ColorNames } from '../../../mol-util/color/names';
+import { Text } from '../../../mol-geo/geometry/text/text';
 
 export const MeasurementRepresentationCommonTextParams = {
     customText: PD.Text('', { label: 'Text', description: 'Override the label with custom value.' }),
     textColor: PD.Color(ColorNames.black, { isEssential: true }),
     textSize: PD.Numeric(0.5, { min: 0.1, max: 5, step: 0.1 }, { isEssential: true }),
-};
+};
+
+export const LociLabelTextParams = {
+    ...Text.Params,
+    ...MeasurementRepresentationCommonTextParams,
+    borderWidth: PD.Numeric(0.2, { min: 0, max: 0.5, step: 0.01 })
+};
+export type LociLabelTextParams = typeof LociLabelTextParams

+ 3 - 10
src/mol-repr/shape/loci/dihedral.ts

@@ -23,7 +23,7 @@ import { Circle } from '../../../mol-geo/primitive/circle';
 import { transformPrimitive } from '../../../mol-geo/primitive/primitive';
 import { MarkerActions, MarkerAction } from '../../../mol-util/marker-action';
 import { dihedralLabel } from '../../../mol-theme/label';
-import { MeasurementRepresentationCommonTextParams } from './common';
+import { LociLabelTextParams } from './common';
 import { Sphere3D } from '../../../mol-math/geometry';
 
 export interface DihedralData {
@@ -66,20 +66,13 @@ const SectorParams = {
 };
 type SectorParams = typeof SectorParams
 
-const TextParams = {
-    ...Text.Params,
-    borderWidth: PD.Numeric(0.2, { min: 0, max: 0.5, step: 0.01 }),
-    ...MeasurementRepresentationCommonTextParams
-};
-type TextParams = typeof TextParams
-
 const DihedralVisuals = {
     'vectors': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<DihedralData, VectorsParams>) => ShapeRepresentation(getVectorsShape, Lines.Utils, { modifyState: s => ({ ...s, pickable: false }) }),
     'extenders': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<DihedralData, ExtendersParams>) => ShapeRepresentation(getExtendersShape, Lines.Utils, { modifyState: s => ({ ...s, pickable: false }) }),
     'connector': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<DihedralData, ExtendersParams>) => ShapeRepresentation(getConnectorShape, Lines.Utils, { modifyState: s => ({ ...s, pickable: false }) }),
     'arc': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<DihedralData, ArcParams>) => ShapeRepresentation(getArcShape, Lines.Utils, { modifyState: s => ({ ...s, pickable: false }) }),
     'sector': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<DihedralData, SectorParams>) => ShapeRepresentation(getSectorShape, Mesh.Utils, { modifyProps: p => ({ ...p, alpha: p.sectorOpacity }), modifyState: s => ({ ...s, markerActions: MarkerActions.Highlighting }) }),
-    'text': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<DihedralData, TextParams>) => ShapeRepresentation(getTextShape, Text.Utils, { modifyState: s => ({ ...s, markerActions: MarkerAction.None }) }),
+    'text': (ctx: RepresentationContext, getParams: RepresentationParamsGetter<DihedralData, LociLabelTextParams>) => ShapeRepresentation(getTextShape, Text.Utils, { modifyState: s => ({ ...s, markerActions: MarkerAction.None }) }),
 };
 
 export const DihedralParams = {
@@ -87,7 +80,7 @@ export const DihedralParams = {
     ...ExtendersParams,
     ...ArcParams,
     ...SectorParams,
-    ...TextParams,
+    ...LociLabelTextParams,
     visuals: PD.MultiSelect(['extenders', 'sector', 'text'], PD.objectToOptions(DihedralVisuals)),
 };
 export type DihedralParams = typeof DihedralParams

+ 2 - 4
src/mol-repr/shape/loci/distance.ts

@@ -18,7 +18,7 @@ import { TextBuilder } from '../../../mol-geo/geometry/text/text-builder';
 import { Vec3 } from '../../../mol-math/linear-algebra';
 import { MarkerActions, MarkerAction } from '../../../mol-util/marker-action';
 import { distanceLabel } from '../../../mol-theme/label';
-import { MeasurementRepresentationCommonTextParams } from './common';
+import { LociLabelTextParams } from './common';
 import { Sphere3D } from '../../../mol-math/geometry';
 
 export interface DistanceData {
@@ -40,10 +40,8 @@ const LineParams = {
 type LineParams = typeof LineParams
 
 const TextParams = {
-    ...Text.Params,
+    ...LociLabelTextParams,
     ...SharedParams,
-    borderWidth: PD.Numeric(0.2, { min: 0, max: 0.5, step: 0.01 }),
-    ...MeasurementRepresentationCommonTextParams
 };
 type TextParams = typeof TextParams
 

+ 4 - 5
src/mol-repr/shape/loci/label.ts

@@ -14,16 +14,14 @@ import { Shape } from '../../../mol-model/shape';
 import { TextBuilder } from '../../../mol-geo/geometry/text/text-builder';
 import { Sphere3D } from '../../../mol-math/geometry';
 import { lociLabel } from '../../../mol-theme/label';
-import { MeasurementRepresentationCommonTextParams } from './common';
+import { LociLabelTextParams } from './common';
 
 export interface LabelData {
     infos: { loci: Loci, label?: string }[]
 }
 
 const TextParams = {
-    ...Text.Params,
-    borderWidth: PD.Numeric(0.2, { min: 0, max: 0.5, step: 0.01 }),
-    ...MeasurementRepresentationCommonTextParams,
+    ...LociLabelTextParams,
     offsetZ: PD.Numeric(2, { min: 0, max: 10, step: 0.1 }),
 };
 type TextParams = typeof TextParams
@@ -34,6 +32,7 @@ const LabelVisuals = {
 
 export const LabelParams = {
     ...TextParams,
+    scaleByRadius: PD.Boolean(true),
     visuals: PD.MultiSelect(['text'], PD.objectToOptions(LabelVisuals)),
 };
 
@@ -62,7 +61,7 @@ function buildText(data: LabelData, props: LabelProps, text?: Text): Text {
         if (!sphere) continue;
         const { center, radius } = sphere;
         const text = label(info, true);
-        builder.add(text, center[0], center[1], center[2], radius / 0.9, Math.max(1, radius), i);
+        builder.add(text, center[0], center[1], center[2], props.scaleByRadius ? radius / 0.9 : 0, props.scaleByRadius ? Math.max(1, radius) : 1, i);
     }
     return builder.getText();
 }