Skip to content

Commit

Permalink
Move notebook renderer to jupytercad-core
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Nov 15, 2023
1 parent 3038ba3 commit 8b03d05
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 98 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ examples/Untitled*.ipynb
jupytercad/_version.py

#Schema
jupytercad/notebook/objects/_schema
jupytercad/cadapp/static
jupytercad/cadapp/schemas
jupytercad/cadapp/themes
Expand Down
2 changes: 1 addition & 1 deletion packages/base/src/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export type BasicMesh = THREE.Mesh<
interface IProps {
view: ObservableMap<JSONValue>;
jcadModel: IJupyterCadModel;
workerRegistry?: IJCadWorkerRegistry;
workerRegistry: IJCadWorkerRegistry;
}

interface IStates {
Expand Down
4 changes: 2 additions & 2 deletions packages/base/src/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class JupyterCadPanel extends ReactWidget {
*/
constructor(options: {
model: IJupyterCadModel;
workerRegistry?: IJCadWorkerRegistry;
workerRegistry: IJCadWorkerRegistry;
}) {
super();
this.addClass('jp-jupytercad-panel');
Expand Down Expand Up @@ -107,6 +107,6 @@ export class JupyterCadPanel extends ReactWidget {
}

private _view: ObservableMap<JSONValue>;
private _workerRegistry: IJCadWorkerRegistry | undefined;
private _workerRegistry: IJCadWorkerRegistry;
private _jcadModel: IJupyterCadModel;
}
4 changes: 3 additions & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
},
"scripts": {
"build": "jlpm build:schema && jlpm run build:lib",
"build:schema": "json2ts -i src/schema -o src/_interface --no-unknownAny --unreachableDefinitions --cwd ./src/schema && cd src/schema && node ../../schema.js",
"build:schema": "jlpm build:schema:js && jlpm build:schema:py",
"build:schema:js": "json2ts -i src/schema -o src/_interface --no-unknownAny --unreachableDefinitions --cwd ./src/schema && cd src/schema && node ../../schema.js",
"build:schema:py": "datamodel-codegen --input ./src/schema --output ../../python/jupytercad-lab/jupytercad_lab/notebook/objects/_schema --output-model-type pydantic_v2.BaseModel --input-file-type jsonschema",
"build:prod": "jlpm run clean && jlpm build:schema && jlpm run build:lib",
"build:lib": "tsc",
"clean": "rimraf tsconfig.tsbuildinfo",
Expand Down
14 changes: 11 additions & 3 deletions python/jupytercad-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,27 @@
"build:worker:prod": "webpack --config worker.webpack.config.js --mode=production"
},
"dependencies": {
"@jupyter/docprovider": "^1.0.0",
"@jupytercad/base": "^0.3.3",
"@jupytercad/occ-worker": "^0.3.3",
"@jupytercad/opencascade": "^0.3.3",
"@jupytercad/schema": "^0.3.3",
"@jupyterlab/application": "^4.0.0",
"@jupyterlab/coreutils": "^6.0.0",
"@jupyterlab/services": "^7.0.0"
"@jupyterlab/apputils": "^4.0.0",
"@jupyterlab/docregistry": "^4.0.0",
"@jupyterlab/filebrowser": "^4.0.0",
"@jupyterlab/launcher": "^4.0.0",
"@jupyterlab/mainmenu": "^4.0.0",
"@jupyterlab/services": "^7.0.0",
"@jupyterlab/translation": "^4.0.0",
"@jupyterlab/ui-components": "^4.0.0",
"@lumino/commands": "^2.0.0"
},
"devDependencies": {
"@jupyterlab/builder": "^4.0.0",
"@types/json-schema": "^7.0.11",
"@types/react": "^18.0.26",
"@types/react-addons-linked-state-mixin": "^0.14.22",
"copy-webpack-plugin": "^10.0.0",
"css-loader": "^6.7.1",
"mkdirp": "^1.0.3",
"npm-run-all": "^4.1.5",
Expand Down
8 changes: 7 additions & 1 deletion python/jupytercad-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import jcadPlugin from './jcadplugin/plugins';
import {
annotationPlugin,
trackerPlugin,
Expand All @@ -6,4 +7,9 @@ import {

export * from './workerregistry';
export * from './factory';
export default [trackerPlugin, annotationPlugin, workerRegistryPlugin];
export default [
trackerPlugin,
annotationPlugin,
workerRegistryPlugin,
jcadPlugin
];
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
ICollaborativeDrive,
SharedDocumentFactory
} from '@jupyter/docprovider';
import { JupyterCadWidgetFactory } from '@jupytercad/jupytercad-core';
import {
IAnnotationModel,
IAnnotationToken,
Expand All @@ -25,6 +24,7 @@ import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
import { ILauncher } from '@jupyterlab/launcher';
import { fileIcon } from '@jupyterlab/ui-components';

import { JupyterCadWidgetFactory } from '../factory';
import { JupyterCadJcadModelFactory } from './modelfactory';

const FACTORY = 'Jupytercad Jcad Factory';
Expand Down Expand Up @@ -57,6 +57,7 @@ const activate = (

// Registering the widget factory
app.docRegistry.addWidgetFactory(widgetFactory);
console.log('activating jcad plugingf');

// Creating and registering the model factory for our custom DocumentModel
const modelFactory = new JupyterCadJcadModelFactory({
Expand Down
1 change: 1 addition & 0 deletions python/jupytercad-lab/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
jupytercad_lab/labextension
jupytercad_lab/_version.py
jupytercad_lab/notebook/objects/_schema
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from typing import Any, Dict, List, Optional, Union

import y_py as Y
from pydantic import BaseModel, Extra
from pydantic import BaseModel
from ypywidgets.ypywidgets import Widget

from jupytercad.freecad.loader import fc
from jupytercad.notebook.objects._schema.any import IAny
from .objects._schema.any import IAny
from uuid import uuid4

from .objects import (
Expand Down Expand Up @@ -80,10 +79,6 @@ def _path_to_comm(cls, filePath: Optional[str]) -> Dict:
except Exception:
raise ValueError("Can not detect file extension!")
if ext == "fcstd":
if fc is None:
msg = "FreeCAD is required to open FCStd files"
logger.warn(msg)
raise RuntimeError(msg)
format = "base64"
contentType = "FCStd"
elif ext == "jcad":
Expand Down Expand Up @@ -634,7 +629,7 @@ def _new_name(self, obj_type: str) -> str:
class PythonJcadObject(BaseModel):
class Config:
arbitrary_types_allowed = True
extra = Extra.allow
extra = "allow"

name: str
shape: Parts
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 1 addition & 20 deletions python/jupytercad-lab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,9 @@
"watch:labextension": "jupyter labextension watch ."
},
"dependencies": {
"@deathbeds/jupyterlab-rjsf": "^1.1.0",
"@jupyter/collaboration": "^1.0.0",
"@jupyter/docprovider": "^1.0.0",
"@jupyter/ydoc": "^0.3.4 || ^1.0.2",
"@jupytercad/base": "^0.3.3",
"@jupytercad/jupytercad-core": "^0.3.3",
"@jupytercad/occ-worker": "^0.3.3",
"@jupytercad/opencascade": "^0.3.3",
"@jupytercad/schema": "^0.3.3",
"@jupyterlab/application": "^4.0.0",
"@jupyterlab/apputils": "^4.0.0",
Expand All @@ -67,26 +62,12 @@
"@jupyterlab/filebrowser": "^4.0.0",
"@jupyterlab/launcher": "^4.0.0",
"@jupyterlab/mainmenu": "^4.0.0",
"@jupyterlab/notebook": "^4.0.0",
"@jupyterlab/observables": "^5.0.0",
"@jupyterlab/services": "^7.0.0",
"@jupyterlab/translation": "^4.0.0",
"@jupyterlab/ui-components": "^4.0.0",
"@lumino/commands": "^2.0.0",
"@lumino/coreutils": "^2.0.0",
"@lumino/signaling": "^2.0.0",
"@lumino/messaging": "^2.0.0",
"@lumino/widgets": "^2.0.0",
"@naisutech/react-tree": "^3.0.1",
"@rjsf/core": "^4.2.0",
"@types/d3-color": "^3.1.0",
"@types/three": "^0.134.0",
"d3-color": "^3.1.0",
"lib0": "^0.2.62",
"react": "^18.0.1",
"styled-components": "^5.3.6",
"three": "^0.135.0",
"three-mesh-bvh": "^0.5.17",
"uuid": "^8.3.2",
"yjs-widgets": "^0.3.3"
},
"devDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions python/jupytercad-lab/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ dependencies = [
"jupyter_server>=2.0.1,<3",
"jupyter_ydoc>=1.1.0,<2",
"y-py>=0.6.0,<0.7",
"jupyterlab>=4,<5",
"jupyter_collaboration>=1.0.0a9,<2",
"ypywidgets>=0.4.1,<0.5.0",
"yjs-widgets>=0.3.4,<0.4",
"comm>=0.1.2,<0.2.0",
"pydantic>=2,<3",
"jupytercad-core>=0.3,<0.4"
]
dynamic = ["version", "description", "authors", "urls", "keywords"]

Expand Down
4 changes: 2 additions & 2 deletions python/jupytercad-lab/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ITranslator, nullTranslator } from '@jupyterlab/translation';
import { IMainMenu } from '@jupyterlab/mainmenu';

// import fcplugin from './fcplugin/plugins';
import jcadPlugin from './jcadplugin/plugins';

import {
ControlPanelModel,
Expand All @@ -26,6 +25,7 @@ import {
IJupyterCadTracker
} from '@jupytercad/schema';
import { WidgetTracker } from '@jupyterlab/apputils';
import { notebookRenderePlugin } from './notebookrenderer';

// import { yJupyterCADWidgetPlugin } from './notebookrenderer';

Expand Down Expand Up @@ -108,4 +108,4 @@ function populateMenus(mainMenu: IMainMenu, isEnabled: () => boolean): void {
});
}

export default [plugin, controlPanel, jcadPlugin];
export default [plugin, controlPanel, notebookRenderePlugin];
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { MessageLoop } from '@lumino/messaging';
import { Panel, Widget } from '@lumino/widgets';

import { WebSocketProvider } from '@jupyter/docprovider';
import { JupyterCadPanel } from '@jupytercad/base';
import {
IJCadWorkerRegistry,
IJCadWorkerRegistryToken,
JupyterCadModel
} from '@jupytercad/schema';

import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { URLExt } from '@jupyterlab/coreutils';
import { ServerConnection, User } from '@jupyterlab/services';
import { ITranslator } from '@jupyterlab/translation';

import { ITranslator, nullTranslator } from '@jupyterlab/translation';
import { MessageLoop } from '@lumino/messaging';
import { Panel, Widget } from '@lumino/widgets';
import * as Y from 'yjs';

import {
JupyterYModel,
IJupyterYWidget,
IJupyterYWidgetManager,
IJupyterYWidget
JupyterYModel
} from 'yjs-widgets';

import { JupyterCadModel } from '@jupytercad/schema';
import { JupyterCadPanel } from '../widget';

export interface ICommMetadata {
create_ydoc: boolean;
path: string;
Expand All @@ -38,11 +38,14 @@ export class YJupyterCADModel extends JupyterYModel {
}

export class YJupyterCADLuminoWidget extends Panel {
constructor(model: JupyterCadModel) {
constructor(options: {
model: JupyterCadModel;
workerRegistry: IJCadWorkerRegistry;
}) {
super();

this.addClass(CLASS_NAME);
this._jcadWidget = new JupyterCadPanel({ model: model });
this._jcadWidget = new JupyterCadPanel(options);
this.addWidget(this._jcadWidget);
}

Expand All @@ -58,37 +61,22 @@ export class YJupyterCADLuminoWidget extends Panel {
private _jcadWidget: JupyterCadPanel;
}

class YJupyterCADWidget implements IJupyterYWidget {
constructor(yModel: YJupyterCADModel, node: HTMLElement) {
this.yModel = yModel;
this.node = node;

const widget = new YJupyterCADLuminoWidget(yModel.jupyterCADModel);
// Widget.attach(widget, node);

MessageLoop.sendMessage(widget, Widget.Msg.BeforeAttach);
node.appendChild(widget.node);
MessageLoop.sendMessage(widget, Widget.Msg.AfterAttach);
}

readonly yModel: YJupyterCADModel;
readonly node: HTMLElement;
}

export const yJupyterCADWidgetPlugin: JupyterFrontEndPlugin<void> = {
export const notebookRenderePlugin: JupyterFrontEndPlugin<void> = {
id: 'jupytercad:yjswidget-plugin',
autoStart: true,
requires: [ITranslator],
optional: [IJupyterYWidgetManager],
requires: [IJCadWorkerRegistryToken],
optional: [IJupyterYWidgetManager, ITranslator],
activate: (
app: JupyterFrontEnd,
translator: ITranslator,
yWidgetManager?: IJupyterYWidgetManager
workerRegistry: IJCadWorkerRegistry,
yWidgetManager?: IJupyterYWidgetManager,
translator?: ITranslator
): void => {
if (!yWidgetManager) {
console.error('Missing IJupyterYWidgetManager token!');
return;
}
const labTranslator = translator ?? nullTranslator;
class YJupyterCADModelFactory extends YJupyterCADModel {
ydocFactory(commMetadata: ICommMetadata): Y.Doc {
const { path, format, contentType } = commMetadata;
Expand All @@ -105,7 +93,7 @@ export const yJupyterCADWidgetPlugin: JupyterFrontEndPlugin<void> = {
contentType,
model: this.jupyterCADModel.sharedModel,
user,
translator: translator.load('jupyterlab')
translator: labTranslator.load('jupyterlab')
});
this.jupyterCADModel.disposed.connect(() => {
ywsProvider.dispose();
Expand All @@ -127,6 +115,27 @@ export const yJupyterCADWidgetPlugin: JupyterFrontEndPlugin<void> = {
}
}

class YJupyterCADWidget implements IJupyterYWidget {
constructor(yModel: YJupyterCADModel, node: HTMLElement) {
this.yModel = yModel;
this.node = node;

const widget = new YJupyterCADLuminoWidget({
model: yModel.jupyterCADModel,
workerRegistry
});
// Widget.attach(widget, node);

MessageLoop.sendMessage(widget, Widget.Msg.BeforeAttach);
node.appendChild(widget.node);
MessageLoop.sendMessage(widget, Widget.Msg.AfterAttach);
}

readonly yModel: YJupyterCADModel;
readonly node: HTMLElement;
}
console.log('yWidgetManager', yWidgetManager);

yWidgetManager.registerWidget(
'@jupytercad:widget',
YJupyterCADModelFactory,
Expand Down
Loading

0 comments on commit 8b03d05

Please sign in to comment.