Skip to content

Commit

Permalink
Remove the guidata option (#413)
Browse files Browse the repository at this point in the history
* Start removing `guidata` option

* Remove guidata from `onSharedOptionsChanged` method
[visibility toggling not working now]

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* visibility toggling working again

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Attempt to remove `guidata` fully from `mainview` & `commands`

* Remove `guidata` from `build_shape`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove `guidata` from `cad_document`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove logging

* Update Playwright Snapshots

* Explicitly update the object visibility in the shared model

* Fix visibility toggling in `objectTree`

* Update Playwright Snapshots

* Update packages/base/src/panelview/objecttree.tsx

Co-authored-by: Duc Trung Le <[email protected]>

* Condense `setVisible` method

* Revert changes in python

* Revert changes in python

---------

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: Duc Trung Le <[email protected]>
  • Loading branch information
4 people committed Sep 16, 2024
1 parent 20fdf43 commit 482f0cf
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 100 deletions.
29 changes: 5 additions & 24 deletions packages/base/src/3dview/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IDict, IParsedShape } from '@jupytercad/schema';
import { IParsedShape } from '@jupytercad/schema';
import * as THREE from 'three';
import {
acceleratedRaycast,
Expand Down Expand Up @@ -113,22 +113,14 @@ export function buildShape(options: {
clippingPlanes: THREE.Plane[];
selected: boolean;
isSolid: boolean;
guidata?: IDict;
objColor?: THREE.Color | string | number;
}): {
meshGroup: THREE.Group;
mainMesh: THREE.Mesh<THREE.BufferGeometry, THREE.MeshPhongMaterial>;
edgesMeshes: LineSegments2[];
} | null {
const {
objName,
data,
guidata,
isSolid,
clippingPlanes,
selected,
objColor
} = options;
const { objName, data, isSolid, clippingPlanes, selected, objColor } =
options;
const { faceList, edgeList, jcObject } = data;

const vertices: Array<number> = [];
Expand Down Expand Up @@ -157,19 +149,8 @@ export function buildShape(options: {
vInd += vertexCoorLength / 3;
}

let color = objColor || DEFAULT_MESH_COLOR;
let visible = jcObject.visible;
if (guidata && guidata[objName]) {
const objdata = guidata[objName];

if (Object.prototype.hasOwnProperty.call(objdata, 'color')) {
color = new THREE.Color(color);
}

if (Object.prototype.hasOwnProperty.call(objdata, 'visibility')) {
visible = guidata[objName]['visibility'];
}
}
const color = objColor || DEFAULT_MESH_COLOR;
const visible = jcObject.visible;

// Compile the connected vertices and faces into a model
// And add to the scene
Expand Down
43 changes: 19 additions & 24 deletions packages/base/src/3dview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ export class MainView extends React.Component<IProps, IStates> {
this._scene.remove(this._clippingPlaneMesh);
}

const guidata = this._model.sharedModel.getOption('guidata');
const selectedNames = this._selectedMeshes.map(sel => sel.name);
this._selectedMeshes = [];

Expand All @@ -603,7 +602,6 @@ export class MainView extends React.Component<IProps, IStates> {
clippingPlanes: this._clippingPlanes,
selected,
isSolid,
guidata,
objColor
});

Expand Down Expand Up @@ -665,9 +663,6 @@ export class MainView extends React.Component<IProps, IStates> {
}
});

if (guidata) {
this._model.sharedModel?.setOption('guidata', guidata);
}
// Update the reflength
this._updateRefLength();
// Set the expoded view if it's enabled
Expand Down Expand Up @@ -1074,34 +1069,34 @@ export class MainView extends React.Component<IProps, IStates> {
sender: IJupyterCadDoc,
change: MapChange
): void {
const guidata = sender.getOption('guidata');
const objects = sender.objects;

if (guidata) {
for (const objName in guidata) {
if (objects) {
for (const objData of objects) {
const objName = objData.name;
const obj = this._meshGroup?.getObjectByName(objName) as
| BasicMesh
| undefined;
const objColor = obj?.material.color;

if (!obj) {
continue;
}
if (
Object.prototype.hasOwnProperty.call(guidata[objName], 'visibility')
) {
const explodedLineHelper =
this._explodedViewLinesHelperGroup?.getObjectByName(objName);
const objGuiData = guidata[objName];
if (objGuiData) {
obj.parent!.visible = objGuiData['visibility'];

if (explodedLineHelper) {
explodedLineHelper.visible = objGuiData['visibility'];
}
}

const isVisible = objData.visible;

const objColor = obj?.material.color;

obj.parent!.visible = isVisible;

const explodedLineHelper =
this._explodedViewLinesHelperGroup?.getObjectByName(objName);
if (explodedLineHelper) {
explodedLineHelper.visible = isVisible;
}

if (obj.material.color) {
if ('color' in guidata[objName]) {
const rgba = guidata[objName]['color'] as number[];
if ('color' in objData) {
const rgba = objData.color as number[];
const color = new THREE.Color(rgba[0], rgba[1], rgba[2]);
obj.material.color = color;
} else {
Expand Down
12 changes: 3 additions & 9 deletions packages/base/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,9 @@ export function setVisible(
name: string,
value: boolean
) {
const guidata = sharedModel.getOption('guidata') || {};

if (guidata && guidata[name]) {
guidata[name]['visibility'] = false;
} else {
guidata[name] = { visibility: false };
}

sharedModel.setOption('guidata', guidata);
sharedModel.updateObjectByName(name, {
data: { key: 'visible', value }
});
}

const PARTS = {
Expand Down
42 changes: 10 additions & 32 deletions packages/base/src/panelview/objecttree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class ObjectTreeReact extends React.Component<IProps, IStates> {
};

render(): React.ReactNode {
const { selectedNodes, openNodes, options } = this.state;
const { selectedNodes, openNodes } = this.state;
const data = this.stateToTree();

const selectedNodeIds: TreeNodeId[] = [];
Expand Down Expand Up @@ -375,21 +375,7 @@ class ObjectTreeReact extends React.Component<IProps, IStates> {
if (jcadObj) {
visible = jcadObj.visible;
}
if (
jcadObj &&
options &&
options['guidata'] &&
Object.prototype.hasOwnProperty.call(
options['guidata'],
jcadObj.name
) &&
Object.prototype.hasOwnProperty.call(
options['guidata'][jcadObj.name],
'visibility'
)
) {
visible = options['guidata'][jcadObj.name]['visibility'];
}

return (
<div
className={`jpcad-control-panel-tree ${
Expand Down Expand Up @@ -421,24 +407,16 @@ class ObjectTreeReact extends React.Component<IProps, IStates> {
className={'jp-ToolbarButtonComponent'}
onClick={() => {
const objectId = opts.node.parentId as string;

const guidata =
this.props.cpModel.sharedModel?.getOption(
'guidata'
) || { [objectId]: {} };

if (guidata) {
if (guidata[objectId]) {
guidata[objectId]['visibility'] = !visible;
} else {
guidata[objectId] = { visibility: !visible };
const obj = this.getObjectFromName(objectId);
if (obj) {
const sharedModel =
this.props.cpModel.jcadModel?.sharedModel;
if (sharedModel) {
sharedModel.updateObjectByName(objectId, {
data: { key: 'visible', value: !obj.visible }
});
}
}

this.props.cpModel.sharedModel?.setOption(
'guidata',
guidata
);
}}
icon={visible ? visibilityIcon : visibilityOffIcon}
/>
Expand Down
5 changes: 0 additions & 5 deletions packages/schema/src/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ export class JupyterCadDoc

if (this._objects.length > index) {
this._objects.delete(index);
const guidata = this.getOption('guidata');
if (guidata) {
delete guidata[name];
this.setOption('guidata', guidata);
}
this.removeOutput(name);
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/schema/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ export interface IParsedShape {
faceList: Array<IFace>;
edgeList: Array<IEdge>;
meta?: IDict;
guiData?: IDict;
}

export interface IPostOperatorInput {
Expand Down
6 changes: 1 addition & 5 deletions packages/schema/src/schema/jcad.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@
"type": "object",
"default": {},
"additionalProperties": false,
"properties": {
"guidata": {
"type": "object"
}
}
"properties": {}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 482f0cf

Please sign in to comment.