Skip to content

Commit 8bb5c67

Browse files
Replace the FormDialog by a toggle button for the axes helper (#726)
* Replace the FormDialog by a toggle button for the axes helper. Set the material depthTest property to false in order to always render the axis on top of the shapes. * Add a renderOrder to the axesHelper and on the boudingBox too as for sake of safety. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove size property from AxeHelper type. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 45247d9 commit 8bb5c67

File tree

5 files changed

+39
-54
lines changed

5 files changed

+39
-54
lines changed

packages/base/src/3dview/helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ export function buildShape(options: {
353353
);
354354
boundingBox.position.copy(center);
355355
boundingBox.visible = false;
356+
boundingBox.renderOrder = 1;
356357
boundingBox.name = SELECTION_BOUNDING_BOX;
357358
meshGroup.add(boundingBox);
358359

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,10 +1521,15 @@ export class MainView extends React.Component<IProps, IStates> {
15211521
): void {
15221522
if (change.key === 'axes') {
15231523
this._sceneAxe?.removeFromParent();
1524-
const axe = change.newValue as AxeHelper | undefined;
1525-
1524+
const axe = change.newValue as AxeHelper;
15261525
if (change.type !== 'remove' && axe && axe.visible) {
1527-
this._sceneAxe = new THREE.AxesHelper(axe.size);
1526+
const axesHelper = new THREE.AxesHelper(
1527+
this._refLength ? this._refLength * 5 : 20
1528+
);
1529+
const material = axesHelper.material as THREE.LineBasicMaterial;
1530+
material.depthTest = false;
1531+
axesHelper.renderOrder = 1;
1532+
this._sceneAxe = axesHelper;
15281533
this._scene.add(this._sceneAxe);
15291534
}
15301535
}

packages/base/src/commands.ts

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ import {
4141
} from './tools';
4242
import keybindings from './keybindings.json';
4343
import { DEFAULT_MESH_COLOR } from './3dview/helpers';
44-
import { JupyterCadPanel, JupyterCadWidget } from './widget';
44+
import { JupyterCadWidget } from './widget';
4545
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 { CameraSettings, ExplodedView, JupyterCadTracker } from './types';
49+
import {
50+
AxeHelper,
51+
CameraSettings,
52+
ExplodedView,
53+
JupyterCadTracker
54+
} from './types';
5055
import { JSONObject } from '@lumino/coreutils';
5156
import { JupyterCadDocumentWidget } from './widget';
5257

@@ -520,40 +525,6 @@ const OPERATORS = {
520525
}
521526
};
522527

523-
const AXES_FORM = {
524-
title: 'Axes Helper',
525-
schema: {
526-
type: 'object',
527-
required: ['Size', 'Visible'],
528-
additionalProperties: false,
529-
properties: {
530-
Size: {
531-
type: 'number',
532-
description: 'Size of the axes'
533-
},
534-
Visible: {
535-
type: 'boolean',
536-
description: 'Whether the axes are visible or not'
537-
}
538-
}
539-
},
540-
default: (panel: JupyterCadPanel) => {
541-
return {
542-
Size: panel.axes?.size ?? 5,
543-
Visible: panel.axes?.visible ?? true
544-
};
545-
},
546-
syncData: (panel: JupyterCadPanel) => {
547-
return (props: IDict) => {
548-
const { Size, Visible } = props;
549-
panel.axes = {
550-
size: Size,
551-
visible: Visible
552-
};
553-
};
554-
}
555-
};
556-
557528
const EXPORT_FORM = {
558529
title: 'Export to .jcad',
559530
schema: {
@@ -968,22 +939,29 @@ export function addCommands(
968939
label: trans.__('Axes Helper'),
969940
isEnabled: () => Boolean(tracker.currentWidget),
970941
icon: axesIcon,
942+
isToggled: () => {
943+
const current = tracker.currentWidget?.content;
944+
return current?.axes.visible === true;
945+
},
946+
971947
execute: async () => {
972948
const current = tracker.currentWidget;
973949

974950
if (!current) {
975951
return;
976952
}
977-
978-
const dialog = new FormDialog({
979-
model: current.model,
980-
title: AXES_FORM.title,
981-
schema: AXES_FORM.schema,
982-
sourceData: AXES_FORM.default(current.content),
983-
syncData: AXES_FORM.syncData(current.content),
984-
cancelButton: true
985-
});
986-
await dialog.launch();
953+
const axes: AxeHelper = current.content.axes;
954+
if (axes.visible === true) {
955+
current.content.axes = {
956+
...current.content.axes,
957+
visible: false
958+
};
959+
} else {
960+
current.content.axes = {
961+
...current.content.axes,
962+
visible: true
963+
};
964+
}
987965
}
988966
});
989967

packages/base/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export type ValueOf<T> = T[keyof T];
1111
* Axe's dimensions
1212
*/
1313
export type AxeHelper = {
14-
size: number;
1514
visible: boolean;
1615
};
1716

packages/base/src/widget.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ export class JupyterCadPanel extends SplitPanel {
114114
}) {
115115
this._view = new ObservableMap<JSONValue>({});
116116
const cameraSettings: CameraSettings = { type: 'Perspective' };
117+
const axes: AxeHelper = { visible: false };
117118
this._view.set('cameraSettings', cameraSettings);
118119
const explodedView: ExplodedView = { enabled: false, factor: 0 };
119120
this._view.set('explodedView', explodedView);
121+
this._view.set('axes', axes);
120122
this._mainViewModel = new MainViewModel({
121123
jcadModel: options.model,
122124
workerRegistry: options.workerRegistry,
@@ -162,12 +164,12 @@ export class JupyterCadPanel extends SplitPanel {
162164
return this._mainViewModel;
163165
}
164166

165-
get axes(): AxeHelper | undefined {
166-
return this._view.get('axes') as AxeHelper | undefined;
167+
get axes(): AxeHelper {
168+
return this._view.get('axes') as AxeHelper;
167169
}
168170

169-
set axes(value: AxeHelper | undefined) {
170-
this._view.set('axes', value || null);
171+
set axes(value: AxeHelper) {
172+
this._view.set('axes', value);
171173
}
172174

173175
get explodedView(): ExplodedView {

0 commit comments

Comments
 (0)