From c1c22d2118f516d9a0c50750d5afc0f91ea57f47 Mon Sep 17 00:00:00 2001 From: Duc Trung Le Date: Tue, 14 Nov 2023 02:49:14 +0100 Subject: [PATCH] Move jcad model to schema package --- .eslintignore | 1 + .prettierignore | 1 + packages/base/src/annotation/model.ts | 12 +- packages/base/src/annotation/view.tsx | 5 +- packages/base/src/commands.ts | 17 +- packages/base/src/factory.ts | 2 +- packages/base/src/fcplugin/modelfactory.ts | 8 +- packages/base/src/fcplugin/plugins.ts | 4 +- packages/base/src/formdialog.tsx | 11 +- packages/base/src/index.ts | 1 - packages/base/src/jcadplugin/modelfactory.ts | 7 +- packages/base/src/jcadplugin/plugins.ts | 21 +- packages/base/src/mainview.tsx | 20 +- packages/base/src/notebookrenderer/index.ts | 2 +- packages/base/src/panelview/annotations.tsx | 3 +- packages/base/src/panelview/leftpanel.tsx | 8 +- packages/base/src/panelview/model.ts | 8 +- .../base/src/panelview/objectproperties.tsx | 18 +- packages/base/src/panelview/objecttree.tsx | 30 +-- packages/base/src/panelview/rightpanel.tsx | 2 +- packages/base/src/sketcher/sketcherdialog.tsx | 3 +- packages/base/src/sketcher/sketchermodel.ts | 15 +- packages/base/src/token.ts | 3 +- packages/base/src/toolbar/usertoolbaritem.tsx | 4 +- packages/base/src/toolbar/widget.tsx | 16 +- packages/base/src/types.ts | 186 +----------------- packages/base/src/widget.tsx | 4 +- packages/opencascade/build.yml | 22 +-- packages/schema/package.json | 2 +- packages/schema/src/index.ts | 15 +- packages/schema/src/interfaces.ts | 180 +++++++++++++++++ packages/{base => schema}/src/model.ts | 9 +- packages/schema/src/types.ts | 15 ++ python/jupytercad-core/src/index.ts | 18 +- python/jupytercad-lab/src/index.ts | 2 +- .../src/jcadplugin/modelfactory.ts | 7 +- .../jupytercad-lab/src/jcadplugin/plugins.ts | 31 ++- 37 files changed, 357 insertions(+), 356 deletions(-) create mode 100644 packages/schema/src/interfaces.ts rename packages/{base => schema}/src/model.ts (98%) create mode 100644 packages/schema/src/types.ts diff --git a/.eslintignore b/.eslintignore index 006b5d57..3d799260 100644 --- a/.eslintignore +++ b/.eslintignore @@ -8,3 +8,4 @@ ui-tests **/build/ jupytercad/ examples/ +packages/opencascade/build.yml diff --git a/.prettierignore b/.prettierignore index 0655d411..7a2a3260 100644 --- a/.prettierignore +++ b/.prettierignore @@ -5,3 +5,4 @@ node_modules jupytercad **/*.d.ts **/*.js +packages/opencascade/build.yml diff --git a/packages/base/src/annotation/model.ts b/packages/base/src/annotation/model.ts index e6ff0931..9742722a 100644 --- a/packages/base/src/annotation/model.ts +++ b/packages/base/src/annotation/model.ts @@ -1,14 +1,12 @@ -import { DocumentRegistry } from '@jupyterlab/docregistry'; -import { User } from '@jupyterlab/services'; - -import { ISignal, Signal } from '@lumino/signaling'; - import { - IAnnotationModel, IAnnotation, IAnnotationContent, + IAnnotationModel, IJupyterCadModel -} from '../types'; +} from '@jupytercad/schema'; +import { DocumentRegistry } from '@jupyterlab/docregistry'; +import { User } from '@jupyterlab/services'; +import { ISignal, Signal } from '@lumino/signaling'; export class AnnotationModel implements IAnnotationModel { constructor(options: AnnotationModel.IOptions) { diff --git a/packages/base/src/annotation/view.tsx b/packages/base/src/annotation/view.tsx index 2960c628..8d701298 100644 --- a/packages/base/src/annotation/view.tsx +++ b/packages/base/src/annotation/view.tsx @@ -1,10 +1,9 @@ -import { caretRightIcon, closeIcon } from '@jupyterlab/ui-components'; +import { IAnnotationModel } from '@jupytercad/schema'; import { Dialog, showDialog } from '@jupyterlab/apputils'; - +import { caretRightIcon, closeIcon } from '@jupyterlab/ui-components'; import * as React from 'react'; import { minimizeIcon } from '../tools'; -import { IAnnotationModel } from '../types'; import { Message } from './message'; interface IAnnotationProps { diff --git a/packages/base/src/commands.ts b/packages/base/src/commands.ts index 6b419d39..fcea43ef 100644 --- a/packages/base/src/commands.ts +++ b/packages/base/src/commands.ts @@ -1,8 +1,18 @@ +import { + IDict, + IJCadObject, + IJupyterCadDoc, + IJupyterCadModel, + Parts +} from '@jupytercad/schema'; +import formSchema from '@jupytercad/schema/lib/_interface/forms.json'; import { JupyterFrontEnd } from '@jupyterlab/application'; import { showErrorMessage, WidgetTracker } from '@jupyterlab/apputils'; import { ITranslator } from '@jupyterlab/translation'; -import { SketcherDialog } from './sketcher/sketcherdialog'; +import { redoIcon, undoIcon } from '@jupyterlab/ui-components'; + import { FormDialog } from './formdialog'; +import { SketcherDialog } from './sketcher/sketcherdialog'; import { axesIcon, boxIcon, @@ -16,12 +26,7 @@ import { torusIcon, unionIcon } from './tools'; - -import { IDict, IJupyterCadDoc, IJupyterCadModel } from './types'; import { JupyterCadPanel, JupyterCadWidget } from './widget'; -import formSchema from '@jupytercad/schema/lib/_interface/forms.json'; -import { IJCadObject, Parts } from '@jupytercad/schema'; -import { redoIcon, undoIcon } from '@jupyterlab/ui-components'; const FORM_SCHEMA = {}; // Injecting "name" in the schema, as it's not part of the official schema but diff --git a/packages/base/src/factory.ts b/packages/base/src/factory.ts index d4fac893..91449491 100644 --- a/packages/base/src/factory.ts +++ b/packages/base/src/factory.ts @@ -1,7 +1,7 @@ +import { JupyterCadModel } from '@jupytercad/schema'; import { ABCWidgetFactory, DocumentRegistry } from '@jupyterlab/docregistry'; import { CommandRegistry } from '@lumino/commands'; -import { JupyterCadModel } from './model'; import { IJupyterCadTracker } from './token'; import { ToolbarWidget } from './toolbar/widget'; import { JupyterCadPanel, JupyterCadWidget } from './widget'; diff --git a/packages/base/src/fcplugin/modelfactory.ts b/packages/base/src/fcplugin/modelfactory.ts index 0872753e..acd80825 100644 --- a/packages/base/src/fcplugin/modelfactory.ts +++ b/packages/base/src/fcplugin/modelfactory.ts @@ -1,9 +1,11 @@ +import { + IAnnotationModel, + IJupyterCadDoc, + JupyterCadModel +} from '@jupytercad/schema'; import { DocumentRegistry } from '@jupyterlab/docregistry'; import { Contents } from '@jupyterlab/services'; -import { IAnnotationModel, IJupyterCadDoc } from '../types'; -import { JupyterCadModel } from '../model'; - /** * A Model factory to create new instances of JupyterCadModel. */ diff --git a/packages/base/src/fcplugin/plugins.ts b/packages/base/src/fcplugin/plugins.ts index 85e2da99..2f40e5fd 100644 --- a/packages/base/src/fcplugin/plugins.ts +++ b/packages/base/src/fcplugin/plugins.ts @@ -2,6 +2,7 @@ import { ICollaborativeDrive, SharedDocumentFactory } from '@jupyter/docprovider'; +import { IAnnotationModel, JupyterCadDoc } from '@jupytercad/schema'; import { JupyterFrontEnd, JupyterFrontEndPlugin @@ -17,10 +18,9 @@ import { ILauncher } from '@jupyterlab/launcher'; import { fileIcon } from '@jupyterlab/ui-components'; import { JupyterCadWidgetFactory } from '../factory'; -import { JupyterCadDoc } from '../model'; import { IAnnotationToken, IJupyterCadDocTracker } from '../token'; import { requestAPI } from '../tools'; -import { IAnnotationModel, IJupyterCadWidget } from '../types'; +import { IJupyterCadWidget } from '../types'; import { JupyterCadFCModelFactory } from './modelfactory'; const FACTORY = 'Jupytercad Freecad Factory'; diff --git a/packages/base/src/formdialog.tsx b/packages/base/src/formdialog.tsx index 806aebf1..e07c51f3 100644 --- a/packages/base/src/formdialog.tsx +++ b/packages/base/src/formdialog.tsx @@ -1,9 +1,14 @@ -import * as React from 'react'; +import { + IDict, + IJupyterCadClientState, + IJupyterCadModel +} from '@jupytercad/schema'; import { Dialog } from '@jupyterlab/apputils'; +import { DocumentRegistry } from '@jupyterlab/docregistry'; +import * as React from 'react'; + import { ObjectPropertiesForm } from './panelview/formbuilder'; -import { IDict, IJupyterCadClientState, IJupyterCadModel } from './types'; import { focusInputField, removeStyleFromProperty } from './tools'; -import { DocumentRegistry } from '@jupyterlab/docregistry'; export interface IFormDialogOptions { schema: IDict; diff --git a/packages/base/src/index.ts b/packages/base/src/index.ts index ff183c56..08e84fac 100644 --- a/packages/base/src/index.ts +++ b/packages/base/src/index.ts @@ -29,7 +29,6 @@ export * from './commands'; export * from './factory'; export * from './formdialog'; export * from './mainview'; -export * from './model'; export * from './token'; export * from './tools'; export * from './types'; diff --git a/packages/base/src/jcadplugin/modelfactory.ts b/packages/base/src/jcadplugin/modelfactory.ts index d02d5506..bc88c90c 100644 --- a/packages/base/src/jcadplugin/modelfactory.ts +++ b/packages/base/src/jcadplugin/modelfactory.ts @@ -1,8 +1,11 @@ import { DocumentRegistry } from '@jupyterlab/docregistry'; import { Contents } from '@jupyterlab/services'; -import { IAnnotationModel, IJupyterCadDoc } from '../types'; -import { JupyterCadModel } from '../model'; +import { + IAnnotationModel, + IJupyterCadDoc, + JupyterCadModel +} from '@jupytercad/schema'; /** * A Model factory to create new instances of JupyterCadModel. diff --git a/packages/base/src/jcadplugin/plugins.ts b/packages/base/src/jcadplugin/plugins.ts index 806558a2..e75b1c4e 100644 --- a/packages/base/src/jcadplugin/plugins.ts +++ b/packages/base/src/jcadplugin/plugins.ts @@ -1,30 +1,25 @@ +import { + ICollaborativeDrive, + SharedDocumentFactory +} from '@jupyter/docprovider'; +import { IAnnotationModel, JupyterCadDoc } from '@jupytercad/schema'; import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application'; - import { ICommandPalette, IThemeManager, WidgetTracker } from '@jupyterlab/apputils'; - -import { fileIcon } from '@jupyterlab/ui-components'; - import { IFileBrowserFactory } from '@jupyterlab/filebrowser'; - import { ILauncher } from '@jupyterlab/launcher'; +import { fileIcon } from '@jupyterlab/ui-components'; -import { - ICollaborativeDrive, - SharedDocumentFactory -} from '@jupyter/docprovider'; - -import { IAnnotationModel, IJupyterCadWidget } from '../types'; -import { IAnnotationToken, IJupyterCadDocTracker } from '../token'; import { JupyterCadWidgetFactory } from '../factory'; +import { IAnnotationToken, IJupyterCadDocTracker } from '../token'; +import { IJupyterCadWidget } from '../types'; import { JupyterCadJcadModelFactory } from './modelfactory'; -import { JupyterCadDoc } from '../model'; const FACTORY = 'Jupytercad Jcad Factory'; const PALETTE_CATEGORY = 'JupyterCAD'; diff --git a/packages/base/src/mainview.tsx b/packages/base/src/mainview.tsx index b32a0b1e..8165b50a 100644 --- a/packages/base/src/mainview.tsx +++ b/packages/base/src/mainview.tsx @@ -6,6 +6,14 @@ import { MainAction, WorkerAction } from '@jupytercad/occ-worker'; +import { + IAnnotation, + IDict, + IJcadObjectDocChange, + IJupyterCadClientState, + IJupyterCadDoc, + IJupyterCadModel +} from '@jupytercad/schema'; import { IObservableMap, ObservableMap } from '@jupyterlab/observables'; import { User } from '@jupyterlab/services'; import { CommandRegistry } from '@lumino/commands'; @@ -24,17 +32,7 @@ import { v4 as uuid } from 'uuid'; import { FloatingAnnotation } from './annotation/view'; import { getCSSVariableColor, throttle } from './tools'; -import { - AxeHelper, - CameraSettings, - ExplodedView, - IAnnotation, - IDict, - IJcadObjectDocChange, - IJupyterCadClientState, - IJupyterCadDoc, - IJupyterCadModel -} from './types'; +import { AxeHelper, CameraSettings, ExplodedView } from './types'; // Apply the BVH extension THREE.BufferGeometry.prototype.computeBoundsTree = computeBoundsTree; diff --git a/packages/base/src/notebookrenderer/index.ts b/packages/base/src/notebookrenderer/index.ts index 5fcf50f1..66e00ef2 100644 --- a/packages/base/src/notebookrenderer/index.ts +++ b/packages/base/src/notebookrenderer/index.ts @@ -19,7 +19,7 @@ import { IJupyterYWidget } from 'yjs-widgets'; -import { JupyterCadModel } from '../model'; +import { JupyterCadModel } from '@jupytercad/schema'; import { JupyterCadPanel } from '../widget'; export interface ICommMetadata { diff --git a/packages/base/src/panelview/annotations.tsx b/packages/base/src/panelview/annotations.tsx index 1685afe2..193d4eee 100644 --- a/packages/base/src/panelview/annotations.tsx +++ b/packages/base/src/panelview/annotations.tsx @@ -1,8 +1,7 @@ +import { IAnnotationModel } from '@jupytercad/schema'; import { PanelWithToolbar, ReactWidget } from '@jupyterlab/ui-components'; - import * as React from 'react'; -import { IAnnotationModel } from '../types'; import { Annotation } from '../annotation/view'; interface IProps { diff --git a/packages/base/src/panelview/leftpanel.tsx b/packages/base/src/panelview/leftpanel.tsx index 1159c4c2..a3ec55b5 100644 --- a/packages/base/src/panelview/leftpanel.tsx +++ b/packages/base/src/panelview/leftpanel.tsx @@ -1,11 +1,11 @@ +import { IAnnotationModel, JupyterCadDoc } from '@jupytercad/schema'; import { SidePanel } from '@jupyterlab/ui-components'; -import { JupyterCadDoc } from '../model'; -import { IControlPanelModel, IAnnotationModel } from '../types'; +import { IJupyterCadTracker } from '../token'; +import { IControlPanelModel } from '../types'; +import { Annotations } from './annotations'; import { ControlPanelHeader } from './header'; import { ObjectTree } from './objecttree'; -import { Annotations } from './annotations'; -import { IJupyterCadTracker } from '../token'; export class LeftPanelWidget extends SidePanel { constructor(options: LeftPanelWidget.IOptions) { diff --git a/packages/base/src/panelview/model.ts b/packages/base/src/panelview/model.ts index be8d1084..60a2180f 100644 --- a/packages/base/src/panelview/model.ts +++ b/packages/base/src/panelview/model.ts @@ -1,12 +1,8 @@ +import { IJupyterCadDoc, IJupyterCadModel } from '@jupytercad/schema'; import { ISignal } from '@lumino/signaling'; import { IJupyterCadTracker } from '../token'; -import { - IControlPanelModel, - IJupyterCadDoc, - IJupyterCadModel, - IJupyterCadWidget -} from '../types'; +import { IControlPanelModel, IJupyterCadWidget } from '../types'; export class ControlPanelModel implements IControlPanelModel { constructor(options: ControlPanelModel.IOptions) { diff --git a/packages/base/src/panelview/objectproperties.tsx b/packages/base/src/panelview/objectproperties.tsx index ecad9be0..dfa7ecd4 100644 --- a/packages/base/src/panelview/objectproperties.tsx +++ b/packages/base/src/panelview/objectproperties.tsx @@ -1,4 +1,11 @@ -import { IJCadModel } from '@jupytercad/schema'; +import { + IDict, + IJCadModel, + IJcadObjectDocChange, + IJupyterCadClientState, + IJupyterCadDoc, + IJupyterCadModel +} from '@jupytercad/schema'; import formSchema from '@jupytercad/schema/lib/_interface/forms.json'; import { ReactWidget } from '@jupyterlab/apputils'; import { PanelWithToolbar } from '@jupyterlab/ui-components'; @@ -11,14 +18,7 @@ import { itemFromName, removeStyleFromProperty } from '../tools'; -import { - IControlPanelModel, - IDict, - IJcadObjectDocChange, - IJupyterCadClientState, - IJupyterCadDoc, - IJupyterCadModel -} from '../types'; +import { IControlPanelModel } from '../types'; import { ObjectPropertiesForm } from './formbuilder'; export class ObjectProperties extends PanelWithToolbar { diff --git a/packages/base/src/panelview/objecttree.tsx b/packages/base/src/panelview/objecttree.tsx index 56e9467b..0eece05a 100644 --- a/packages/base/src/panelview/objecttree.tsx +++ b/packages/base/src/panelview/objecttree.tsx @@ -1,13 +1,20 @@ -import * as React from 'react'; -import { JSONObject } from '@lumino/coreutils'; - +import { + IDict, + IJCadModel, + IJCadObject, + IJcadObjectDocChange, + IJupyterCadClientState, + IJupyterCadDoc, + IJupyterCadModel +} from '@jupytercad/schema'; import { ReactWidget } from '@jupyterlab/apputils'; import { + closeIcon, LabIcon, PanelWithToolbar, - ToolbarButtonComponent, - closeIcon + ToolbarButtonComponent } from '@jupyterlab/ui-components'; +import { JSONObject } from '@lumino/coreutils'; import { Panel } from '@lumino/widgets'; import { ReactTree, @@ -15,19 +22,12 @@ import { TreeNodeId, TreeNodeList } from '@naisutech/react-tree'; +import * as React from 'react'; +import { v4 as uuid } from 'uuid'; import visibilitySvg from '../../style/icon/visibility.svg'; import visibilityOffSvg from '../../style/icon/visibilityOff.svg'; -import { IJCadModel, IJCadObject } from '@jupytercad/schema'; -import { - IControlPanelModel, - IDict, - IJcadObjectDocChange, - IJupyterCadClientState, - IJupyterCadDoc, - IJupyterCadModel -} from '../types'; -import { v4 as uuid } from 'uuid'; +import { IControlPanelModel } from '../types'; const visibilityIcon = new LabIcon({ name: 'jupytercad:visibilityIcon', diff --git a/packages/base/src/panelview/rightpanel.tsx b/packages/base/src/panelview/rightpanel.tsx index 501c2603..fe49a38b 100644 --- a/packages/base/src/panelview/rightpanel.tsx +++ b/packages/base/src/panelview/rightpanel.tsx @@ -1,6 +1,6 @@ +import { JupyterCadDoc } from '@jupytercad/schema'; import { SidePanel } from '@jupyterlab/ui-components'; -import { JupyterCadDoc } from '../model'; import { IControlPanelModel } from '../types'; import { ControlPanelHeader } from './header'; import { ObjectProperties } from './objectproperties'; diff --git a/packages/base/src/sketcher/sketcherdialog.tsx b/packages/base/src/sketcher/sketcherdialog.tsx index 6597fa0a..c1f0d953 100644 --- a/packages/base/src/sketcher/sketcherdialog.tsx +++ b/packages/base/src/sketcher/sketcherdialog.tsx @@ -1,6 +1,7 @@ +import { IDict, IJupyterCadDoc } from '@jupytercad/schema'; import { Dialog } from '@jupyterlab/apputils'; import * as React from 'react'; -import { IDict, IJupyterCadDoc } from '../types'; + import { SketcherModel } from './sketchermodel'; import { SketcherReactWidget } from './sketcherwidget'; diff --git a/packages/base/src/sketcher/sketchermodel.ts b/packages/base/src/sketcher/sketchermodel.ts index 670c49cd..5b9963e3 100644 --- a/packages/base/src/sketcher/sketchermodel.ts +++ b/packages/base/src/sketcher/sketchermodel.ts @@ -1,13 +1,17 @@ +import { + IDict, + IGeomCircle, + IGeomLineSegment, + IJCadObject, + IJupyterCadDoc +} from '@jupytercad/schema'; import { showErrorMessage } from '@jupyterlab/apputils'; import { v4 as uuid } from 'uuid'; -import { IDict, IJupyterCadDoc } from '../types'; - -import { IGeomCircle, IGeomLineSegment, IJCadObject } from '@jupytercad/schema'; - -import { distance } from './helper'; +import { Circle } from './elements/circle'; import { Line } from './elements/line'; import { Point } from './elements/point'; +import { distance } from './helper'; import { ICircle, ILine, @@ -17,7 +21,6 @@ import { IPosition, ISketcherModel } from './types'; -import { Circle } from './elements/circle'; // TODO Refactor this model to make use of the elemental classes (Point, Circle...) export class SketcherModel implements ISketcherModel { diff --git a/packages/base/src/token.ts b/packages/base/src/token.ts index 51d8efdd..8876c1c7 100644 --- a/packages/base/src/token.ts +++ b/packages/base/src/token.ts @@ -1,7 +1,8 @@ +import { IAnnotationModel } from '@jupytercad/schema'; import { IWidgetTracker } from '@jupyterlab/apputils'; import { Token } from '@lumino/coreutils'; -import { IJupyterCadWidget, IAnnotationModel } from './types'; +import { IJupyterCadWidget } from './types'; export type IJupyterCadTracker = IWidgetTracker; diff --git a/packages/base/src/toolbar/usertoolbaritem.tsx b/packages/base/src/toolbar/usertoolbaritem.tsx index 3efb7cc9..7cf1e698 100644 --- a/packages/base/src/toolbar/usertoolbaritem.tsx +++ b/packages/base/src/toolbar/usertoolbaritem.tsx @@ -1,7 +1,5 @@ +import { IUserData, JupyterCadModel } from '@jupytercad/schema'; import * as React from 'react'; -import { JupyterCadModel } from '../model'; - -import { IUserData } from '../types'; interface IProps { model: JupyterCadModel; diff --git a/packages/base/src/toolbar/widget.tsx b/packages/base/src/toolbar/widget.tsx index 109fc0ba..317a487a 100644 --- a/packages/base/src/toolbar/widget.tsx +++ b/packages/base/src/toolbar/widget.tsx @@ -1,18 +1,16 @@ -import * as React from 'react'; - -import { CommandRegistry } from '@lumino/commands'; -import { Widget } from '@lumino/widgets'; - +import { JupyterCadModel } from '@jupytercad/schema'; import { CommandToolbarButton } from '@jupyterlab/apputils'; import { - Toolbar, - undoIcon, + ReactWidget, redoIcon, - ReactWidget + Toolbar, + undoIcon } from '@jupyterlab/ui-components'; +import { CommandRegistry } from '@lumino/commands'; +import { Widget } from '@lumino/widgets'; +import * as React from 'react'; import { CommandIDs } from '../commands'; -import { JupyterCadModel } from '../model'; import { UsersItem } from './usertoolbaritem'; export const TOOLBAR_SEPARATOR_CLASS = 'jcad-Toolbar-Separator'; diff --git a/packages/base/src/types.ts b/packages/base/src/types.ts index 0ac19bb6..c77ac5d9 100644 --- a/packages/base/src/types.ts +++ b/packages/base/src/types.ts @@ -1,56 +1,12 @@ -import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry'; -import { IChangedArgs } from '@jupyterlab/coreutils'; +import { IDocumentWidget } from '@jupyterlab/docregistry'; import { ReactWidget } from '@jupyterlab/ui-components'; -import { User } from '@jupyterlab/services'; - -import { - MapChange, - YDocument, - StateChange, - DocumentChange -} from '@jupyter/ydoc'; - -import { ISignal, Signal } from '@lumino/signaling'; -import { JSONObject } from '@lumino/coreutils'; - +import { ISignal } from '@lumino/signaling'; +import { IJupyterCadModel, IJupyterCadDoc, IDict } from '@jupytercad/schema'; import { IJupyterCadTracker } from './token'; -import { - IJCadContent, - IJCadObject, - IJCadModel, - IJCadOptions -} from '@jupytercad/schema'; - -export interface IDict { - [key: string]: T; -} +export { IDict }; export type ValueOf = T[keyof T]; -export interface IUserData { - userId: number; - userData: User.IIdentity; -} - -/** - * User pointer in the 3D environment - */ -export type Pointer = { - parent: string; - x: number; - y: number; - z: number; -}; - -/** - * Position and orientation of the user Camera - */ -export type Camera = { - position: number[]; - rotation: number[]; - up: number[]; -}; - /** * Axe's dimensions */ @@ -74,108 +30,6 @@ export type CameraSettings = { type: 'Perspective' | 'Orthographic'; }; -export interface IJcadObjectDocChange { - objectChange?: Array<{ - name: string; - key: keyof IJCadObject; - newValue: IJCadObject | undefined; - }>; -} - -export interface IJupyterCadDocChange extends DocumentChange { - contextChange?: MapChange; - contentChange?: MapChange; - objectChange?: Array<{ - name: string; - key: string; - newValue: IJCadObject | undefined; - }>; - optionChange?: MapChange; - stateChange?: StateChange[]; -} - -export interface IJupyterCadDoc extends YDocument { - objects: Array; - options: JSONObject; - metadata: JSONObject; - - objectExists(name: string): boolean; - getObjectByName(name: string): IJCadObject | undefined; - removeObjectByName(name: string): void; - addObject(value: IJCadObject): void; - addObjects(value: Array): void; - updateObjectByName(name: string, key: string, value: any): void; - - getOption(key: keyof IJCadOptions): IDict | undefined; - setOption(key: keyof IJCadOptions, value: IDict): void; - setOptions(options: IJCadOptions): void; - - getMetadata(key: string): string | undefined; - setMetadata(key: string, value: string): void; - removeMetadata(key: string): void; - - setShapeMeta(key: string, meta?: IDict): void; - - metadataChanged: ISignal; - optionsChanged: ISignal; - objectsChanged: ISignal; -} - -export interface IJupyterCadClientState { - pointer: { value?: Pointer; emitter?: string | null }; - camera: { value?: Camera; emitter?: string | null }; - selected: { value?: string[]; emitter?: string | null }; - selectedPropField?: { - id: string | null; - value: any; - parentType: 'panel' | 'dialog'; - }; - user: User.IIdentity; - remoteUser?: number; - toolbarForm?: IDict; -} - -export interface IJupyterCadModel extends DocumentRegistry.IModel { - isDisposed: boolean; - sharedModel: IJupyterCadDoc; - annotationModel?: IAnnotationModel; - localState: IJupyterCadClientState | null; - - themeChanged: Signal< - IJupyterCadModel, - IChangedArgs - >; - clientStateChanged: ISignal< - IJupyterCadModel, - Map - >; - sharedMetadataChanged: ISignal; - sharedOptionsChanged: ISignal; - sharedObjectsChanged: ISignal; - - getWorker(): Worker; - getContent(): IJCadContent; - getAllObject(): IJCadModel; - - syncPointer(position: Pointer | undefined, emitter?: string): void; - syncCamera(camera: Camera | undefined, emitter?: string): void; - syncSelectedObject(name: string[], emitter?: string): void; - syncSelectedPropField(data: { - id: string | null; - value: any; - parentType: 'panel' | 'dialog'; - }); - setUserToFollow(userId?: number): void; - syncFormData(form: any): void; - - getClientId(): number; - - addMetadata(key: string, value: string): void; - removeMetadata(key: string): void; - - disposed: ISignal; -} - export type IJupyterCadWidget = IDocumentWidget; export interface IControlPanelModel { @@ -185,35 +39,3 @@ export interface IControlPanelModel { jcadModel: IJupyterCadModel | undefined; sharedModel: IJupyterCadDoc | undefined; } - -export interface IAnnotationContent { - user?: User.IIdentity; - value: string; -} - -export interface IAnnotation { - label: string; - position: [number, number, number]; - contents: IAnnotationContent[]; - parent: string; -} - -export interface IAnnotationModel { - updateSignal: ISignal; - user: User.IIdentity | undefined; - - context: DocumentRegistry.IContext | undefined; - contextChanged: ISignal; - - update(): void; - - getAnnotation(id: string): IAnnotation | undefined; - - getAnnotationIds(): string[]; - - addAnnotation(key: string, value: IAnnotation): void; - - removeAnnotation(key): void; - - addContent(id: string, value: string): void; -} diff --git a/packages/base/src/widget.tsx b/packages/base/src/widget.tsx index db2f4beb..e61ddf31 100644 --- a/packages/base/src/widget.tsx +++ b/packages/base/src/widget.tsx @@ -1,3 +1,4 @@ +import { IJupyterCadModel } from '@jupytercad/schema'; import { ReactWidget } from '@jupyterlab/apputils'; import { DocumentWidget } from '@jupyterlab/docregistry'; import { IObservableMap, ObservableMap } from '@jupyterlab/observables'; @@ -8,9 +9,8 @@ import * as React from 'react'; import { MainView } from './mainview'; import { AxeHelper, - ExplodedView, CameraSettings, - IJupyterCadModel, + ExplodedView, IJupyterCadWidget } from './types'; diff --git a/packages/opencascade/build.yml b/packages/opencascade/build.yml index 98c08327..3227eea5 100644 --- a/packages/opencascade/build.yml +++ b/packages/opencascade/build.yml @@ -89,16 +89,16 @@ mainBuild: - symbol: TopTools_IndexedMapOfShape - symbol: TopTools_ListOfShape emccFlags: - - '-flto' - - '-fexceptions' - - '-sDISABLE_EXCEPTION_CATCHING=1' - - '-O3' - - '-sEXPORT_ES6=1' - - '-sUSE_ES6_IMPORT_META=0' + - "-flto" + - "-fexceptions" + - "-sDISABLE_EXCEPTION_CATCHING=1" + - "-O3" + - "-sEXPORT_ES6=1" + - "-sUSE_ES6_IMPORT_META=0" - "-sEXPORTED_RUNTIME_METHODS=['FS']" - - '-sINITIAL_MEMORY=15MB' - - '-sMAXIMUM_MEMORY=4GB' - - '-sALLOW_MEMORY_GROWTH=1' - - '-sLLD_REPORT_UNDEFINED' - - '--no-entry' + - "-sINITIAL_MEMORY=15MB" + - "-sMAXIMUM_MEMORY=4GB" + - "-sALLOW_MEMORY_GROWTH=1" + - "-sLLD_REPORT_UNDEFINED" + - "--no-entry" - "-sENVIRONMENT='web'" diff --git a/packages/schema/package.json b/packages/schema/package.json index ed5a6967..e6df0adf 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -18,7 +18,7 @@ "style/**/*.{css,js,eot,gif,html,jpg,json,png,svg,woff2,ttf}" ], "main": "lib/index.js", - "types": "lib/index.d.ts", + "types": "lib/types.d.ts", "style": "style/index.css", "repository": { "type": "git", diff --git a/packages/schema/src/index.ts b/packages/schema/src/index.ts index fed2a654..f0a61ca0 100644 --- a/packages/schema/src/index.ts +++ b/packages/schema/src/index.ts @@ -1,13 +1,2 @@ -export * from './_interface/any'; -export * from './_interface/box'; -export * from './_interface/cone'; -export * from './_interface/cut'; -export * from './_interface/cylinder'; -export * from './_interface/extrusion'; -export * from './_interface/fuse'; -export * from './_interface/intersection'; -export * from './_interface/jcad'; -export * from './_interface/placement'; -export * from './_interface/sketch'; -export * from './_interface/sphere'; -export * from './_interface/torus'; +export * from './interfaces'; +export * from './model'; diff --git a/packages/schema/src/interfaces.ts b/packages/schema/src/interfaces.ts new file mode 100644 index 00000000..7e8f0488 --- /dev/null +++ b/packages/schema/src/interfaces.ts @@ -0,0 +1,180 @@ +import { + DocumentChange, + MapChange, + StateChange, + YDocument +} from '@jupyter/ydoc'; +import { IChangedArgs } from '@jupyterlab/coreutils'; +import { DocumentRegistry } from '@jupyterlab/docregistry'; +import { User } from '@jupyterlab/services'; +import { JSONObject } from '@lumino/coreutils'; +import { ISignal, Signal } from '@lumino/signaling'; + +import { + IJCadContent, + IJCadModel, + IJCadObject, + IJCadOptions +} from './_interface/jcad'; + +export interface IDict { + [key: string]: T; +} + +/** + * Position and orientation of the user Camera + */ +export type Camera = { + position: number[]; + rotation: number[]; + up: number[]; +}; + +export interface IAnnotationModel { + updateSignal: ISignal; + user: User.IIdentity | undefined; + + context: DocumentRegistry.IContext | undefined; + contextChanged: ISignal; + + update(): void; + + getAnnotation(id: string): IAnnotation | undefined; + + getAnnotationIds(): string[]; + + addAnnotation(key: string, value: IAnnotation): void; + + removeAnnotation(key): void; + + addContent(id: string, value: string): void; +} + +export interface IJcadObjectDocChange { + objectChange?: Array<{ + name: string; + key: keyof IJCadObject; + newValue: IJCadObject | undefined; + }>; +} + +export interface IJupyterCadClientState { + pointer: { value?: Pointer; emitter?: string | null }; + camera: { value?: Camera; emitter?: string | null }; + selected: { value?: string[]; emitter?: string | null }; + selectedPropField?: { + id: string | null; + value: any; + parentType: 'panel' | 'dialog'; + }; + user: User.IIdentity; + remoteUser?: number; + toolbarForm?: IDict; +} + +export interface IJupyterCadDoc extends YDocument { + objects: Array; + options: JSONObject; + metadata: JSONObject; + + objectExists(name: string): boolean; + getObjectByName(name: string): IJCadObject | undefined; + removeObjectByName(name: string): void; + addObject(value: IJCadObject): void; + addObjects(value: Array): void; + updateObjectByName(name: string, key: string, value: any): void; + + getOption(key: keyof IJCadOptions): IDict | undefined; + setOption(key: keyof IJCadOptions, value: IDict): void; + setOptions(options: IJCadOptions): void; + + getMetadata(key: string): string | undefined; + setMetadata(key: string, value: string): void; + removeMetadata(key: string): void; + + setShapeMeta(key: string, meta?: IDict): void; + + metadataChanged: ISignal; + optionsChanged: ISignal; + objectsChanged: ISignal; +} + +export interface IJupyterCadDocChange extends DocumentChange { + contextChange?: MapChange; + contentChange?: MapChange; + objectChange?: Array<{ + name: string; + key: string; + newValue: IJCadObject | undefined; + }>; + optionChange?: MapChange; + stateChange?: StateChange[]; +} + +export interface IJupyterCadModel extends DocumentRegistry.IModel { + isDisposed: boolean; + sharedModel: IJupyterCadDoc; + annotationModel?: IAnnotationModel; + localState: IJupyterCadClientState | null; + + themeChanged: Signal< + IJupyterCadModel, + IChangedArgs + >; + clientStateChanged: ISignal< + IJupyterCadModel, + Map + >; + sharedMetadataChanged: ISignal; + sharedOptionsChanged: ISignal; + sharedObjectsChanged: ISignal; + + getWorker(): Worker; + getContent(): IJCadContent; + getAllObject(): IJCadModel; + + syncPointer(position: Pointer | undefined, emitter?: string): void; + syncCamera(camera: Camera | undefined, emitter?: string): void; + syncSelectedObject(name: string[], emitter?: string): void; + syncSelectedPropField(data: { + id: string | null; + value: any; + parentType: 'panel' | 'dialog'; + }); + setUserToFollow(userId?: number): void; + syncFormData(form: any): void; + + getClientId(): number; + + addMetadata(key: string, value: string): void; + removeMetadata(key: string): void; + + disposed: ISignal; +} + +export interface IUserData { + userId: number; + userData: User.IIdentity; +} + +/** + * User pointer in the 3D environment + */ +export type Pointer = { + parent: string; + x: number; + y: number; + z: number; +}; + +export interface IAnnotationContent { + user?: User.IIdentity; + value: string; +} + +export interface IAnnotation { + label: string; + position: [number, number, number]; + contents: IAnnotationContent[]; + parent: string; +} diff --git a/packages/base/src/model.ts b/packages/schema/src/model.ts similarity index 98% rename from packages/base/src/model.ts rename to packages/schema/src/model.ts index 92b562cc..7d44ded1 100644 --- a/packages/base/src/model.ts +++ b/packages/schema/src/model.ts @@ -1,5 +1,6 @@ import { MapChange, YDocument } from '@jupyter/ydoc'; import { IChangedArgs } from '@jupyterlab/coreutils'; +import { DocumentRegistry } from '@jupyterlab/docregistry'; import { JSONExt, JSONObject, PartialJSONObject } from '@lumino/coreutils'; import { ISignal, Signal } from '@lumino/signaling'; import Ajv from 'ajv'; @@ -10,8 +11,8 @@ import { IJCadModel, IJCadObject, IJCadOptions -} from '@jupytercad/schema'; -import jcadSchema from '@jupytercad/schema/lib/schema/jcad.json'; +} from './_interface/jcad'; +import jcadSchema from './schema/jcad.json'; import { Camera, IAnnotationModel, @@ -23,9 +24,9 @@ import { IJupyterCadModel, IUserData, Pointer -} from './types'; -import { DocumentRegistry } from '@jupyterlab/docregistry'; +} from './interfaces'; +// import { IJCadContent, IJCadModel, IJCadObject, IJCadOptions } from './index'; export class JupyterCadModel implements IJupyterCadModel { constructor(options: JupyterCadModel.IOptions) { const { annotationModel, sharedModel } = options; diff --git a/packages/schema/src/types.ts b/packages/schema/src/types.ts new file mode 100644 index 00000000..500e06af --- /dev/null +++ b/packages/schema/src/types.ts @@ -0,0 +1,15 @@ +export * from './_interface/any'; +export * from './_interface/box'; +export * from './_interface/cone'; +export * from './_interface/cut'; +export * from './_interface/cylinder'; +export * from './_interface/extrusion'; +export * from './_interface/fuse'; +export * from './_interface/intersection'; +export * from './_interface/jcad'; +export * from './_interface/placement'; +export * from './_interface/sketch'; +export * from './_interface/sphere'; +export * from './_interface/torus'; +export * from './interfaces'; +export * from './model'; diff --git a/python/jupytercad-core/src/index.ts b/python/jupytercad-core/src/index.ts index af724c04..f7d9ee77 100644 --- a/python/jupytercad-core/src/index.ts +++ b/python/jupytercad-core/src/index.ts @@ -1,19 +1,19 @@ import { - JupyterFrontEnd, - JupyterFrontEndPlugin -} from '@jupyterlab/application'; -import { - IAnnotationModel, + AnnotationModel, IAnnotationToken, IJupyterCadDocTracker, IJupyterCadTracker, - JupyterCadModel, - AnnotationModel, JupyterCadWidget } from '@jupytercad/base'; -import { ITranslator } from '@jupyterlab/translation'; -import { IMainMenu } from '@jupyterlab/mainmenu'; +import { IAnnotationModel, JupyterCadModel } from '@jupytercad/schema'; +import { + JupyterFrontEnd, + JupyterFrontEndPlugin +} from '@jupyterlab/application'; import { WidgetTracker } from '@jupyterlab/apputils'; +import { IMainMenu } from '@jupyterlab/mainmenu'; +import { ITranslator } from '@jupyterlab/translation'; + const NAME_SPACE = 'jupytercad'; const plugin: JupyterFrontEndPlugin = { diff --git a/python/jupytercad-lab/src/index.ts b/python/jupytercad-lab/src/index.ts index 0f0de1db..61d082b5 100644 --- a/python/jupytercad-lab/src/index.ts +++ b/python/jupytercad-lab/src/index.ts @@ -17,12 +17,12 @@ import { IJupyterCadDocTracker, IJupyterCadTracker, jcLightIcon, - IAnnotationModel, addCommands, CommandIDs, JupyterCadWidget, IAnnotationToken } from '@jupytercad/base'; +import { IAnnotationModel } from '@jupytercad/schema'; import { WidgetTracker } from '@jupyterlab/apputils'; // import { yJupyterCADWidgetPlugin } from './notebookrenderer'; diff --git a/python/jupytercad-lab/src/jcadplugin/modelfactory.ts b/python/jupytercad-lab/src/jcadplugin/modelfactory.ts index e866be16..00275647 100644 --- a/python/jupytercad-lab/src/jcadplugin/modelfactory.ts +++ b/python/jupytercad-lab/src/jcadplugin/modelfactory.ts @@ -1,11 +1,10 @@ -import { DocumentRegistry } from '@jupyterlab/docregistry'; -import { Contents } from '@jupyterlab/services'; - import { IAnnotationModel, IJupyterCadDoc, JupyterCadModel -} from '@jupytercad/base'; +} from '@jupytercad/schema'; +import { DocumentRegistry } from '@jupyterlab/docregistry'; +import { Contents } from '@jupyterlab/services'; /** * A Model factory to create new instances of JupyterCadModel. diff --git a/python/jupytercad-lab/src/jcadplugin/plugins.ts b/python/jupytercad-lab/src/jcadplugin/plugins.ts index e7134229..cf37a69e 100644 --- a/python/jupytercad-lab/src/jcadplugin/plugins.ts +++ b/python/jupytercad-lab/src/jcadplugin/plugins.ts @@ -1,33 +1,26 @@ +import { + ICollaborativeDrive, + SharedDocumentFactory +} from '@jupyter/docprovider'; +import { + IAnnotationToken, + IJupyterCadDocTracker, + IJupyterCadWidget, + JupyterCadWidgetFactory +} from '@jupytercad/base'; +import { IAnnotationModel, JupyterCadDoc } from '@jupytercad/schema'; import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application'; - import { ICommandPalette, IThemeManager, WidgetTracker } from '@jupyterlab/apputils'; - -import { fileIcon } from '@jupyterlab/ui-components'; - import { IFileBrowserFactory } from '@jupyterlab/filebrowser'; - import { ILauncher } from '@jupyterlab/launcher'; - -import { - ICollaborativeDrive, - SharedDocumentFactory -} from '@jupyter/docprovider'; - -import { - IAnnotationModel, - IJupyterCadWidget, - IAnnotationToken, - IJupyterCadDocTracker, - JupyterCadWidgetFactory, - JupyterCadDoc -} from '@jupytercad/base'; +import { fileIcon } from '@jupyterlab/ui-components'; import { JupyterCadJcadModelFactory } from './modelfactory';