Skip to content

Commit 85c0dde

Browse files
Implement clipping (#333)
* Clip view forms * Clipping implementation * Keyboard event * Use stencil for filling the holes: Step 1 * Stencil buffer: Part 2 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Change clip plane color * Update clip plane material * Take clipplane into consideration when it comes to mesh picking * Shall we be smart? * Rename clip plane mesh * Show clipping plane * Remove outdated comment * Update icon * Fix exploded view * Add showClipPlane option * [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 234f9bf commit 85c0dde

File tree

8 files changed

+379
-34
lines changed

8 files changed

+379
-34
lines changed

packages/base/src/commands.ts

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import {
2525
requestAPI,
2626
sphereIcon,
2727
torusIcon,
28-
unionIcon
28+
unionIcon,
29+
clippingIcon
2930
} from './tools';
3031
import { JupyterCadPanel, JupyterCadWidget } from './widget';
3132
import { DocumentRegistry } from '@jupyterlab/docregistry';
@@ -407,6 +408,40 @@ const CAMERA_FORM = {
407408
}
408409
};
409410

411+
const CLIP_VIEW_FORM = {
412+
title: 'Clip View Settings',
413+
schema: {
414+
type: 'object',
415+
required: ['Enabled'],
416+
additionalProperties: false,
417+
properties: {
418+
Enabled: {
419+
type: 'boolean',
420+
description: 'Whether the clip view is enabled or not'
421+
},
422+
ShowClipPlane: {
423+
type: 'boolean',
424+
description: 'Whether the clip plane should be rendered or not'
425+
}
426+
}
427+
},
428+
default: (panel: JupyterCadPanel) => {
429+
return {
430+
Enabled: panel.clipView?.enabled ?? false,
431+
ShowClipPlane: panel.clipView?.showClipPlane ?? true
432+
};
433+
},
434+
syncData: (panel: JupyterCadPanel) => {
435+
return (props: IDict) => {
436+
const { Enabled, ShowClipPlane } = props;
437+
panel.clipView = {
438+
enabled: Enabled,
439+
showClipPlane: ShowClipPlane
440+
};
441+
};
442+
}
443+
};
444+
410445
const EXPORT_FORM = {
411446
title: 'Export to .jcad',
412447
schema: {
@@ -686,6 +721,29 @@ export function addCommands(
686721
}
687722
});
688723

724+
commands.addCommand(CommandIDs.updateClipView, {
725+
label: trans.__('Clipping'),
726+
isEnabled: () => Boolean(tracker.currentWidget),
727+
icon: clippingIcon,
728+
execute: async () => {
729+
const current = tracker.currentWidget;
730+
731+
if (!current) {
732+
return;
733+
}
734+
735+
const dialog = new FormDialog({
736+
context: current.context,
737+
title: CLIP_VIEW_FORM.title,
738+
schema: CLIP_VIEW_FORM.schema,
739+
sourceData: CLIP_VIEW_FORM.default(current.content),
740+
syncData: CLIP_VIEW_FORM.syncData(current.content),
741+
cancelButton: true
742+
});
743+
await dialog.launch();
744+
}
745+
});
746+
689747
commands.addCommand(CommandIDs.exportJcad, {
690748
label: trans.__('Export to .jcad'),
691749
isEnabled: () => {
@@ -737,6 +795,7 @@ export namespace CommandIDs {
737795
export const updateAxes = 'jupytercad:updateAxes';
738796
export const updateExplodedView = 'jupytercad:updateExplodedView';
739797
export const updateCameraSettings = 'jupytercad:updateCameraSettings';
798+
export const updateClipView = 'jupytercad:updateClipView';
740799

741800
export const exportJcad = 'jupytercad:exportJcad';
742801
}

0 commit comments

Comments
 (0)