From 8fc6d904f7e8f3635bafe83e5d4a55725cf43fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mal=C3=BD?= <michal.maly@ibt.cas.cz> Date: Sat, 12 Nov 2022 16:52:20 +0100 Subject: [PATCH] ReDNATCO plugin stage 36 --- src/apps/rednatco/controls.tsx | 6 ++++- src/apps/rednatco/density-map-controls.tsx | 2 ++ src/apps/rednatco/index.tsx | 28 ++++++---------------- src/apps/rednatco/viewer.ts | 8 +++---- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/apps/rednatco/controls.tsx b/src/apps/rednatco/controls.tsx index d625c8cf6..f2f8977c3 100644 --- a/src/apps/rednatco/controls.tsx +++ b/src/apps/rednatco/controls.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { stof } from './util'; +import { numDecimals, stof } from './util'; const Zero = '0'.charCodeAt(0); const Nine = '9'.charCodeAt(0); @@ -142,6 +142,9 @@ export class SpinBox extends React.Component<SpinBox.Props, SpinBoxState> { } private handleChange(value: string) { + if (this.props.maxNumDecimals !== undefined && numDecimals(value) > this.props.maxNumDecimals) + return; + const n = stof(value); if ( @@ -224,5 +227,6 @@ export namespace SpinBox { className?: string; classNameDisabled?: string; formatter?: Formatter; + maxNumDecimals?: number; } } diff --git a/src/apps/rednatco/density-map-controls.tsx b/src/apps/rednatco/density-map-controls.tsx index 293e719c1..ef6a10ba8 100644 --- a/src/apps/rednatco/density-map-controls.tsx +++ b/src/apps/rednatco/density-map-controls.tsx @@ -48,6 +48,7 @@ export class DensityMapControls extends React.Component<DensityMapControls.Props min={this.props.isoMin} max={this.props.isoMax} step={this.props.isoStep} + maxNumDecimals={Math.log10(this.props.isoStep) >= 0 ? 0 : -Math.log10(this.props.isoStep)} value={isoToFixed(this.props.iso, this.props.isoStep)} onChange={(n) => this.props.changeIso(n)} pathPrefix='' @@ -76,6 +77,7 @@ export class DensityMapControls extends React.Component<DensityMapControls.Props min={0} max={1} step={0.1} + maxNumDecimals={1} value={(1.0 - this.props.alpha)} onChange={(n) => this.props.changeAlpha(1.0 - n)} pathPrefix='' diff --git a/src/apps/rednatco/index.tsx b/src/apps/rednatco/index.tsx index 68a2625cf..65e8e3a62 100644 --- a/src/apps/rednatco/index.tsx +++ b/src/apps/rednatco/index.tsx @@ -368,13 +368,8 @@ export class ReDNATCOMsp extends React.Component<ReDNATCOMsp.Props, State> { enabled={ready} switchedOn={this.state.display.structures.showPyramids} onClick={() => { - const display: Display = { - ...this.state.display, - structures: { - ...this.state.display.structures, - showPyramids: !this.state.display.structures.showPyramids, - } - }; + const display = { ...this.state.display }; + display.structures.showPyramids = !display.structures.showPyramids; this.viewer!.changePyramids(display); this.setState({ ...this.state, display }); }} @@ -385,13 +380,8 @@ export class ReDNATCOMsp extends React.Component<ReDNATCOMsp.Props, State> { text={this.state.display.structures.pyramidsTransparent ? 'Transparent' : 'Solid'} enabled={this.state.display.structures.showPyramids} onClick={() => { - const display: Display = { - ...this.state.display, - structures: { - ...this.state.display.structures, - pyramidsTransparent: !this.state.display.structures.pyramidsTransparent, - } - }; + const display = { ...this.state.display }; + display.structures.pyramidsTransparent = !display.structures.pyramidsTransparent; this.viewer!.changePyramids(display); this.setState({ ...this.state, display }); }} @@ -412,13 +402,9 @@ export class ReDNATCOMsp extends React.Component<ReDNATCOMsp.Props, State> { text={this.state.display.structures.ballsTransparent ? 'Transparent' : 'Solid'} enabled={this.state.display.structures.showBalls} onClick={() => { - const display: Display = { - ...this.state.display, - structures: { - ...this.state.display.structures, - ballsTransparent: !this.state.display.structures.ballsTransparent, - }, - }; + const display = { ...this.state.display }; + display.structures.showBalls = !display.structures.showBalls; + /* No balls today... */ this.setState({ ...this.state, display }); }} diff --git a/src/apps/rednatco/viewer.ts b/src/apps/rednatco/viewer.ts index 63514a690..aacf7a673 100644 --- a/src/apps/rednatco/viewer.ts +++ b/src/apps/rednatco/viewer.ts @@ -847,7 +847,7 @@ export class ReDNATCOMspViewer { } isReady() { - return this.has('structure', '', BaseRef); + return this.has('entire-structure', '', BaseRef); } async loadStructure( @@ -967,6 +967,9 @@ export class ReDNATCOMspViewer { const bounds = isoBounds(isoRange.min, isoRange.max); const iso = prettyIso(((isoRange.max - isoRange.min) / 2) + isoRange.min, bounds.step); + display.densityMap.representations = ['wireframe']; + display.densityMap.isoValue = iso; + await this.plugin.state.data.build().to(IDs.DensityID('volume', BaseRef)) .apply( StateTransforms.Representation.VolumeRepresentation3D, @@ -974,9 +977,6 @@ export class ReDNATCOMspViewer { { ref: IDs.DensityID('visual', BaseRef) } ) .commit(); - - display.densityMap.representations = ['wireframe']; - display.densityMap.isoValue = iso; } this.haveMultipleModels = this.getModelCount() > 1; -- GitLab