Skip to content

Commit 529b533

Browse files
HaudinFlorencepre-commit-ci[bot]github-actions[bot]martinRenou
authored
Replace the dialogform by a toggle button for the exploded view (#722)
* Replace the dialogform by a toggle button for the exploded view. Add a slider to the view to set up the exploded view factor when the button is toggled. * Rename _handleExplosionChange into handleExplodedViewChange. Call _setupExplodedView in _handleExplodedViewChange method of MainView class to update the view after a factor change. * Propose an alternative overlay view for the case where both isTransformOrClipEnabled and this.state.explodedViewEnabled are true. Set max value to 10 for the exploded view factor. * Update the test related the exploded view in ui-spec.ts. * Take review commands into account. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Change the max value of the slider to 5 for the exploded view factor. Integrate the fix for the snapshots name through rebase with main inclundin PR 723. * Update Playwright Snapshots * Apply suggestions from code review Co-authored-by: martinRenou <[email protected]> * Update ui.spec.ts to try to have a more readable diff compared to main branch. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: martinRenou <[email protected]>
1 parent 4ae8467 commit 529b533

File tree

5 files changed

+87
-78
lines changed

5 files changed

+87
-78
lines changed

packages/base/src/3dview/mainview.tsx

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ interface IStates {
7777
wireframe: boolean;
7878
transform: boolean;
7979
clipEnabled: boolean;
80+
explodedViewEnabled: boolean;
81+
explodedViewFactor: number;
8082
rotationSnapValue: number;
8183
transformMode: string | undefined;
8284
}
@@ -124,6 +126,8 @@ export class MainView extends React.Component<IProps, IStates> {
124126
wireframe: false,
125127
transform: false,
126128
clipEnabled: false,
129+
explodedViewEnabled: false,
130+
explodedViewFactor: 0,
127131
rotationSnapValue: 10,
128132
transformMode: 'translate'
129133
};
@@ -1526,12 +1530,20 @@ export class MainView extends React.Component<IProps, IStates> {
15261530
}
15271531

15281532
if (change.key === 'explodedView') {
1529-
const explodedView = change.newValue as ExplodedView | undefined;
1533+
const explodedView = change.newValue as ExplodedView;
15301534

15311535
if (change.type !== 'remove' && explodedView) {
1532-
this._explodedView = explodedView;
1533-
1534-
this._setupExplodedView();
1536+
this.setState(
1537+
oldState => ({
1538+
...oldState,
1539+
explodedViewEnabled: explodedView.enabled,
1540+
explodedViewFactor: explodedView.factor
1541+
}),
1542+
() => {
1543+
this._explodedView = explodedView;
1544+
this._setupExplodedView();
1545+
}
1546+
);
15351547
}
15361548
}
15371549

@@ -1887,6 +1899,15 @@ export class MainView extends React.Component<IProps, IStates> {
18871899
}
18881900
};
18891901

1902+
private _handleExplodedViewChange = (
1903+
event: React.ChangeEvent<HTMLInputElement>
1904+
) => {
1905+
const newValue = parseFloat(event.target.value);
1906+
this.setState({ explodedViewFactor: newValue });
1907+
this._explodedView.factor = newValue;
1908+
this._setupExplodedView();
1909+
};
1910+
18901911
render(): JSX.Element {
18911912
const isTransformOrClipEnabled =
18921913
this.state.transform || this.state.clipEnabled;
@@ -1935,40 +1956,71 @@ export class MainView extends React.Component<IProps, IStates> {
19351956
height: 'calc(100%)'
19361957
}}
19371958
/>
1938-
{isTransformOrClipEnabled && (
1959+
1960+
{(isTransformOrClipEnabled || this.state.explodedViewEnabled) && (
19391961
<div
19401962
style={{
19411963
position: 'absolute',
19421964
bottom: '10px',
19431965
left: '10px',
1966+
display: 'flex',
1967+
flexDirection: 'column',
19441968
padding: '8px',
19451969
backgroundColor: 'rgba(0, 0, 0, 0.5)',
19461970
color: 'white',
19471971
borderRadius: '4px',
1948-
fontSize: '12px'
1972+
fontSize: '12px',
1973+
gap: '8px'
19491974
}}
19501975
>
1951-
<div style={{ marginBottom: '2px' }}>Press R to switch mode</div>
1952-
1953-
{this.state.transformMode === 'rotate' && (
1976+
{isTransformOrClipEnabled && (
19541977
<div>
1955-
<label style={{ marginRight: '8px' }}>Rotation Snap (°):</label>
1956-
<input
1957-
type="number"
1958-
value={this.state.rotationSnapValue}
1959-
onChange={this._handleSnapChange}
1960-
style={{
1961-
width: '50px',
1962-
padding: '4px',
1963-
borderRadius: '4px',
1964-
border: '1px solid #ccc',
1965-
fontSize: '12px'
1966-
}}
1967-
/>
1978+
<div style={{ marginBottom: '2px' }}>
1979+
Press R to switch mode
1980+
</div>
1981+
{this.state.transformMode === 'rotate' && (
1982+
<div>
1983+
<label style={{ marginRight: '8px' }}>
1984+
Rotation Snap (°):
1985+
</label>
1986+
<input
1987+
type="number"
1988+
value={this.state.rotationSnapValue}
1989+
onChange={this._handleSnapChange}
1990+
style={{
1991+
width: '50px',
1992+
padding: '4px',
1993+
borderRadius: '4px',
1994+
border: '1px solid #ccc',
1995+
fontSize: '12px'
1996+
}}
1997+
/>
1998+
</div>
1999+
)}
2000+
</div>
2001+
)}
2002+
{this.state.explodedViewEnabled && (
2003+
<div>
2004+
<div style={{ marginBottom: '4px' }}>Exploded view factor:</div>
2005+
<div style={{ display: 'flex', alignItems: 'center' }}>
2006+
<input
2007+
type="range"
2008+
min="0"
2009+
max="5"
2010+
step="0.1"
2011+
value={this.state.explodedViewFactor}
2012+
onChange={this._handleExplodedViewChange}
2013+
style={{ width: '120px', marginRight: '8px' }}
2014+
/>
2015+
<span style={{ minWidth: '30px', textAlign: 'right' }}>
2016+
{this.state.explodedViewFactor}
2017+
</span>
2018+
</div>
19682019
</div>
19692020
)}
19702021
</div>
19712022
)}
2023+
19722024
<div
19732025
id={'split-label-left'}
19742026
style={{

packages/base/src/commands.ts

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -554,40 +554,6 @@ const AXES_FORM = {
554554
}
555555
};
556556

557-
const EXPLODED_VIEW_FORM = {
558-
title: 'Exploded View Settings',
559-
schema: {
560-
type: 'object',
561-
required: ['Enabled', 'Factor'],
562-
additionalProperties: false,
563-
properties: {
564-
Enabled: {
565-
type: 'boolean',
566-
description: 'Whether the exploded view is enabled or not'
567-
},
568-
Factor: {
569-
type: 'number',
570-
description: 'The exploded view factor'
571-
}
572-
}
573-
},
574-
default: (panel: JupyterCadPanel) => {
575-
return {
576-
Enabled: panel.explodedView?.enabled ?? false,
577-
Factor: panel.explodedView?.factor ?? 0.5
578-
};
579-
},
580-
syncData: (panel: JupyterCadPanel) => {
581-
return (props: IDict) => {
582-
const { Enabled, Factor } = props;
583-
panel.explodedView = {
584-
enabled: Enabled,
585-
factor: Factor
586-
};
587-
};
588-
}
589-
};
590-
591557
const EXPORT_FORM = {
592558
title: 'Export to .jcad',
593559
schema: {
@@ -1038,17 +1004,13 @@ export function addCommands(
10381004
if (!current) {
10391005
return;
10401006
}
1007+
const panel = current.content;
10411008

1042-
const dialog = new FormDialog({
1043-
model: current.model,
1044-
title: EXPLODED_VIEW_FORM.title,
1045-
schema: EXPLODED_VIEW_FORM.schema,
1046-
sourceData: EXPLODED_VIEW_FORM.default(current.content),
1047-
syncData: EXPLODED_VIEW_FORM.syncData(current.content),
1048-
cancelButton: true
1049-
});
1050-
await dialog.launch();
1051-
1009+
if (panel.explodedView.enabled) {
1010+
panel.explodedView = { ...panel.explodedView, enabled: false };
1011+
} else {
1012+
panel.explodedView = { ...panel.explodedView, enabled: true };
1013+
}
10521014
commands.notifyCommandChanged(CommandIDs.updateExplodedView);
10531015

10541016
// Notify change so that toggle button for transform disables if needed

packages/base/src/widget.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ export class JupyterCadPanel extends SplitPanel {
115115
this._view = new ObservableMap<JSONValue>({});
116116
const cameraSettings: CameraSettings = { type: 'Perspective' };
117117
this._view.set('cameraSettings', cameraSettings);
118+
const explodedView: ExplodedView = { enabled: false, factor: 0 };
119+
this._view.set('explodedView', explodedView);
118120
this._mainViewModel = new MainViewModel({
119121
jcadModel: options.model,
120122
workerRegistry: options.workerRegistry,
@@ -168,12 +170,12 @@ export class JupyterCadPanel extends SplitPanel {
168170
this._view.set('axes', value || null);
169171
}
170172

171-
get explodedView(): ExplodedView | undefined {
172-
return this._view.get('explodedView') as ExplodedView | undefined;
173+
get explodedView(): ExplodedView {
174+
return this._view.get('explodedView') as ExplodedView;
173175
}
174176

175-
set explodedView(value: ExplodedView | undefined) {
176-
this._view.set('explodedView', value || null);
177+
set explodedView(value: ExplodedView) {
178+
this._view.set('explodedView', value);
177179
}
178180

179181
get cameraSettings(): CameraSettings {

ui-tests/tests/ui.spec.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,7 @@ test.describe('UI Test', () => {
280280
await page.sidebar.close('right');
281281
// Apply Exploded view
282282
await page.getByTitle('Exploded View').click();
283-
await page.getByLabel('Enabled').click();
284-
await page.locator('input#root_Factor').click();
285-
await page.locator('input#root_Factor').fill('3.5');
286-
await page
287-
.locator('div.jp-Dialog-buttonLabel', {
288-
hasText: 'Submit'
289-
})
290-
.click();
283+
await page.getByRole('slider').fill('3.5');
291284

292285
let main = await page.$('#jp-main-split-panel');
293286
if (main) {
2.05 KB
Loading

0 commit comments

Comments
 (0)