Skip to content

Commit 492e04b

Browse files
Replace the formDialog by a toggle button for CameraSettings (#717)
* Modify updateCameraSettings command to use a toogle button instead of a formDialog. Replace the camera icon by a video camera one. * Take review comments into account. * Update the label of updateCameraSettings command. * Removed the possibility for cameraSettings to be undefined in the getter and setter, and update updateCameraSettings command accordingly. * Update packages/base/src/commands.ts Co-authored-by: martinRenou <[email protected]> --------- Co-authored-by: martinRenou <[email protected]>
1 parent 2a3c010 commit 492e04b

File tree

7 files changed

+65
-65
lines changed

7 files changed

+65
-65
lines changed

examples/jcad.ipynb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,22 @@
1717
}
1818
],
1919
"metadata": {
20+
"kernelspec": {
21+
"display_name": "Python 3 (ipykernel)",
22+
"language": "python",
23+
"name": "python3"
24+
},
2025
"language_info": {
21-
"name": "python"
26+
"codemirror_mode": {
27+
"name": "ipython",
28+
"version": 3
29+
},
30+
"file_extension": ".py",
31+
"mimetype": "text/x-python",
32+
"name": "python",
33+
"nbconvert_exporter": "python",
34+
"pygments_lexer": "ipython3",
35+
"version": "3.13.3"
2236
}
2337
},
2438
"nbformat": 4,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ export class MainView extends React.Component<IProps, IStates> {
15361536
}
15371537

15381538
if (change.key === 'cameraSettings') {
1539-
const cameraSettings = change.newValue as CameraSettings | undefined;
1539+
const cameraSettings = change.newValue as CameraSettings;
15401540

15411541
if (change.type !== 'remove' && cameraSettings) {
15421542
this._cameraSettings = cameraSettings;

packages/base/src/commands.ts

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
wireframeIcon,
3838
transformIcon,
3939
pencilSolidIcon,
40-
cameraSolidIcon
40+
videoSolidIcon
4141
} from './tools';
4242
import keybindings from './keybindings.json';
4343
import { DEFAULT_MESH_COLOR } from './3dview/helpers';
@@ -46,7 +46,7 @@ import { PathExt } from '@jupyterlab/coreutils';
4646
import { MainViewModel } from './3dview/mainviewmodel';
4747
import { handleRemoveObject } from './panelview';
4848
import { v4 as uuid } from 'uuid';
49-
import { ExplodedView, JupyterCadTracker } from './types';
49+
import { CameraSettings, ExplodedView, JupyterCadTracker } from './types';
5050
import { JSONObject } from '@lumino/coreutils';
5151
import { JupyterCadDocumentWidget } from './widget';
5252

@@ -588,36 +588,6 @@ const EXPLODED_VIEW_FORM = {
588588
}
589589
};
590590

591-
const CAMERA_FORM = {
592-
title: 'Camera Settings',
593-
schema: {
594-
type: 'object',
595-
required: ['Type'],
596-
additionalProperties: false,
597-
properties: {
598-
Type: {
599-
title: 'Projection',
600-
description: 'The projection type',
601-
type: 'string',
602-
enum: ['Perspective', 'Orthographic']
603-
}
604-
}
605-
},
606-
default: (panel: JupyterCadPanel) => {
607-
return {
608-
Type: panel.cameraSettings?.type ?? 'Perspective'
609-
};
610-
},
611-
syncData: (panel: JupyterCadPanel) => {
612-
return (props: IDict) => {
613-
const { Type } = props;
614-
panel.cameraSettings = {
615-
type: Type
616-
};
617-
};
618-
}
619-
};
620-
621591
const EXPORT_FORM = {
622592
title: 'Export to .jcad',
623593
schema: {
@@ -1087,25 +1057,32 @@ export function addCommands(
10871057
});
10881058

10891059
commands.addCommand(CommandIDs.updateCameraSettings, {
1090-
label: trans.__('Camera Settings'),
1060+
label: () => {
1061+
const isOn =
1062+
tracker.currentWidget?.content?.cameraSettings?.type === 'Perspective';
1063+
return isOn
1064+
? trans.__('Perspective projection is on')
1065+
: trans.__('Orthographic projection is on');
1066+
},
10911067
isEnabled: () => Boolean(tracker.currentWidget),
1092-
icon: cameraSolidIcon,
1068+
icon: videoSolidIcon,
1069+
isToggled: () => {
1070+
const current = tracker.currentWidget?.content;
1071+
return current?.cameraSettings.type === 'Orthographic';
1072+
},
10931073
execute: async () => {
10941074
const current = tracker.currentWidget;
1095-
10961075
if (!current) {
10971076
return;
1077+
} else {
1078+
const currentSettings: CameraSettings = current.content.cameraSettings;
1079+
if (currentSettings.type === 'Perspective') {
1080+
current.content.cameraSettings.type = 'Orthographic';
1081+
} else {
1082+
current.content.cameraSettings.type = 'Perspective';
1083+
}
10981084
}
1099-
1100-
const dialog = new FormDialog({
1101-
model: current.model,
1102-
title: CAMERA_FORM.title,
1103-
schema: CAMERA_FORM.schema,
1104-
sourceData: CAMERA_FORM.default(current.content),
1105-
syncData: CAMERA_FORM.syncData(current.content),
1106-
cancelButton: true
1107-
});
1108-
await dialog.launch();
1085+
commands.notifyCommandChanged(CommandIDs.updateCameraSettings);
11091086
}
11101087
});
11111088

packages/base/src/tools.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import filletIconStr from '../style/icon/fillet.svg';
2525
import wireframeIconStr from '../style/icon/wireframe.svg';
2626
import chevronRightStr from '../style/icon/chevron-right.svg';
2727
import pencilSolidStr from '../style/icon/pencil-solid.svg';
28-
import cameraSolidStr from '../style/icon/camera-solid.svg';
28+
import videoSolidStr from '../style/icon/video-solid.svg';
2929
import terminalToolbarStr from '../style/icon/terminal-toolbar.svg';
3030

3131
import visibilitySvg from '../style/icon/visibility.svg';
@@ -150,9 +150,9 @@ export const pencilSolidIcon = new LabIcon({
150150
svgstr: pencilSolidStr
151151
});
152152

153-
export const cameraSolidIcon = new LabIcon({
154-
name: 'jupytercad:camera-solid-icon',
155-
svgstr: cameraSolidStr
153+
export const videoSolidIcon = new LabIcon({
154+
name: 'jupytercad:video-solid-icon',
155+
svgstr: videoSolidStr
156156
});
157157

158158
export const terminalToolbarIcon = new LabIcon({

packages/base/src/widget.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ export class JupyterCadPanel extends SplitPanel {
112112
model: IJupyterCadModel;
113113
workerRegistry: IJCadWorkerRegistry;
114114
}) {
115-
this._view = new ObservableMap<JSONValue>();
115+
this._view = new ObservableMap<JSONValue>({});
116+
const cameraSettings: CameraSettings = { type: 'Perspective' };
117+
this._view.set('cameraSettings', cameraSettings);
116118
this._mainViewModel = new MainViewModel({
117119
jcadModel: options.model,
118120
workerRegistry: options.workerRegistry,
@@ -174,12 +176,12 @@ export class JupyterCadPanel extends SplitPanel {
174176
this._view.set('explodedView', value || null);
175177
}
176178

177-
get cameraSettings(): CameraSettings | undefined {
178-
return this._view.get('cameraSettings') as CameraSettings | undefined;
179+
get cameraSettings(): CameraSettings {
180+
return this._view.get('cameraSettings') as CameraSettings;
179181
}
180182

181-
set cameraSettings(value: CameraSettings | undefined) {
182-
this._view.set('cameraSettings', value || null);
183+
set cameraSettings(value: CameraSettings) {
184+
this._view.set('cameraSettings', value);
183185
}
184186

185187
get clipView(): ClipSettings | undefined {

packages/base/style/icon/camera-solid.svg

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)