Skip to content

Commit 35ae844

Browse files
committed
Fix Symmetry Annotation controls not showing "Not Available"
1 parent da10f00 commit 35ae844

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

src/app/ui/symmetry-annotation-controls.tsx

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const DefaultSymmetryParams = {
1515
on: PD.Boolean(false, { isHidden: true }),
1616
/** Index of the currently selected symmetry (in case there a more symmetries for an assembly), regardless of whether visibility is on of off */
1717
symmetryIndex: PD.Select(0, [[0, 'Auto']]),
18-
/** `true` if symmetry data have been retrieved but do not contain any non-trivial symmetry */
19-
noSymmetries: PD.Boolean(false, { isHidden: true }),
18+
/** `true` if visibility is on and symmetry data have been retrieved and contain at least one non-trivial symmetry. */
19+
hasSymmetries: PD.Boolean(false, { isHidden: true }),
2020
};
2121

2222
type SymmetryParams = typeof DefaultSymmetryParams;
@@ -64,24 +64,24 @@ export class SymmetryAnnotationControls extends PurePluginUIComponent<{}, Symmet
6464
/** Synchronize parameters and values in UI with real parameters currently applied in `AssemblySymmetryProvider` */
6565
syncParams() {
6666
if (this.hasAssemblySymmetry3D()) {
67-
const noSymmetries = this.noSymmetriesAvailable();
67+
const hasSymmetries = this.hasSymmetriesAvailable();
6868
const realParams = this.getRealParams();
6969
const realValues = this.getRealValues();
70-
const options = noSymmetries ?
71-
[[0, 'None']] as const
72-
: realParams.symmetryIndex.options.filter(([index, label]) => index >= 0); // Removing the 'off' option (having index -1)
70+
const options = hasSymmetries ?
71+
realParams.symmetryIndex.options.filter(([index, label]) => index >= 0) // Removing the 'off' option (having index -1)
72+
: [[0, 'None']] as const;
7373
const params = {
7474
...this.state.params,
7575
symmetryIndex: PD.Select(0, options),
7676
};
77-
const values = (realValues.symmetryIndex >= 0) ? {
77+
const values: SymmetryProps = (realValues.symmetryIndex >= 0) ? {
7878
on: true,
7979
symmetryIndex: realValues.symmetryIndex,
80-
noSymmetries: noSymmetries,
80+
hasSymmetries,
8181
} : {
8282
on: false,
8383
symmetryIndex: this.state.values.symmetryIndex,
84-
noSymmetries: noSymmetries,
84+
hasSymmetries,
8585
};
8686
this.setState({ params, values });
8787
} else {
@@ -92,11 +92,11 @@ export class SymmetryAnnotationControls extends PurePluginUIComponent<{}, Symmet
9292
}
9393
}
9494

95-
/** Return `true` if symmetry data have been retrieved and do not contain any non-trivial symmetry. */
96-
noSymmetriesAvailable() {
95+
/** Return `true` if symmetry data have been retrieved and contain at least one non-trivial symmetry. */
96+
hasSymmetriesAvailable() {
9797
const structure = this.getPivotStructure()?.cell.obj?.data;
9898
const symmetryData = structure && AssemblySymmetryDataProvider.get(structure).value;
99-
return symmetryData !== undefined && symmetryData.filter(sym => sym.symbol !== 'C1').length === 0;
99+
return symmetryData !== undefined && symmetryData.filter(sym => sym.symbol !== 'C1').length > 0;
100100
}
101101

102102
/** Get the first loaded structure, if any. */
@@ -205,28 +205,20 @@ export class SymmetryAnnotationControls extends PurePluginUIComponent<{}, Symmet
205205
}
206206

207207
render() {
208-
const shortTitle = 'Assembly Symmetry' + (this.state.values.noSymmetries ? ' [Not Available]' : '');
209-
const title = 'Assembly Symmetry' + (this.state.values.noSymmetries ? ' [Not Available]\nSymmetry information for this assembly is not available' : '');
208+
const notAvailable = this.state.values.on && !this.state.values.hasSymmetries;
209+
const shortTitle = 'Assembly Symmetry' + (notAvailable ? ' [Not Available]' : '');
210+
const title = 'Assembly Symmetry' + (notAvailable ? ' [Not Available]\nSymmetry information for this assembly is not available' : '');
210211
return <>
211-
<SymmetryAnnotationRowControls shortTitle={shortTitle} title={title}
212+
<AnnotationRowControls shortTitle={shortTitle} title={title}
212213
applied={this.state.values.on} onChangeApplied={applied => this.apply(applied)}
213-
params={this.state.params} values={this.state.values} onChangeValues={v => this.changeParamValues(v)} />
214+
params={this.state.params} values={this.state.values} onChangeValues={v => this.changeParamValues(v)}
215+
errorMessage={!this.state.values.on ? 'First activate annotation to show options' : notAvailable ? 'Symmetry information not available' : undefined}
216+
/>
214217
</>;
215218
}
216219
}
217220

218221

219-
class SymmetryAnnotationRowControls extends AnnotationRowControls<SymmetryParams> {
220-
renderOptions() {
221-
if (this.props.values.noSymmetries) {
222-
return <div className='msp-row-text'>
223-
<div title='Symmetry information for this assembly is not available'>Symmetry information not available</div>
224-
</div>;
225-
}
226-
return super.renderOptions();
227-
}
228-
}
229-
230222
/** Get the first loaded structure, if any. */
231223
function getPivotStructure(plugin: PluginContext): StructureRef | undefined {
232224
return plugin.managers.structure.hierarchy.selection.structures[0];

0 commit comments

Comments
 (0)