Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the guidata option #413

Merged
merged 22 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bf3cfc8
Start removing `guidata` option
arjxn-py Sep 12, 2024
ed644fe
Remove guidata from `onSharedOptionsChanged` method
arjxn-py Sep 12, 2024
537c855
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 12, 2024
38b2a26
visibility toggling working again
arjxn-py Sep 12, 2024
9ebe49c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 12, 2024
3acd5d3
Merge branch 'main' into remove-guidata
arjxn-py Sep 12, 2024
a770481
Attempt to remove `guidata` fully from `mainview` & `commands`
arjxn-py Sep 13, 2024
88be028
Remove `guidata` from `build_shape`
arjxn-py Sep 13, 2024
cdb509c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 13, 2024
6e68f87
Remove `guidata` from `cad_document`
arjxn-py Sep 13, 2024
1684e10
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 13, 2024
938d03b
Remove logging
arjxn-py Sep 13, 2024
bce522d
Update Playwright Snapshots
github-actions[bot] Sep 13, 2024
9c9ab7d
Explicitly update the object visibility in the shared model
arjxn-py Sep 13, 2024
d913528
Merge branch 'main' into remove-guidata
arjxn-py Sep 14, 2024
6dc9ba6
Fix visibility toggling in `objectTree`
arjxn-py Sep 14, 2024
4c4e2f1
Update Playwright Snapshots
github-actions[bot] Sep 14, 2024
b92557f
Merge branch 'main' into remove-guidata
arjxn-py Sep 14, 2024
e04b7a1
Update packages/base/src/panelview/objecttree.tsx
arjxn-py Sep 14, 2024
da3bac8
Condense `setVisible` method
arjxn-py Sep 14, 2024
874b49f
Revert changes in python
arjxn-py Sep 14, 2024
ac1566c
Revert changes in python
arjxn-py Sep 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading