Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmooney committed Apr 15, 2024
1 parent 6d538a8 commit 6d291e9
Show file tree
Hide file tree
Showing 8 changed files with 12,671 additions and 4 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@
"watch:labextension": "jupyter labextension watch ."
},
"dependencies": {
"@jupytercad/base": "^1.0.1",
"@jupytercad/schema": "^1.0.1",
"@jupyterlab/application": "^4.0.0",
"@jupyterlab/settingregistry": "^4.0.0"
"@jupyterlab/settingregistry": "^4.0.0",
"@types/uuid": "^9.0.8",
"uuid": "^9.0.1"
},
"devDependencies": {
"@jupyterlab/builder": "^4.0.0",
Expand Down
45 changes: 45 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { IJupyterCadTracker } from '@jupytercad/schema';
import { JupyterFrontEnd } from '@jupyterlab/application';
import { ITranslator } from '@jupyterlab/translation';

import { IModelRegistry } from 'jupyterlab-gather';

Check failure on line 5 in src/command.ts

View workflow job for this annotation

GitHub Actions / check_release

Cannot find module 'jupyterlab-gather' or its corresponding type declarations.
import { exportIcon } from './icon';

export namespace CommandIDs {
export const exportGltf = 'jupytercad:gather:register';
}

export function addCommands(
app: JupyterFrontEnd,
tracker: IJupyterCadTracker,
modelRegistry: IModelRegistry,
translator: ITranslator
) {
const trans = translator.load('jupyterlab');
const { commands } = app;
commands.addCommand(CommandIDs.exportGltf, {
label: trans.__('Register GLTF'),
isEnabled: () => Boolean(tracker.currentWidget),
icon: exportIcon,
execute: Private.executeRegisterGltf(modelRegistry, tracker)
});
}

namespace Private {
export function executeRegisterGltf(
modelRegistry: IModelRegistry,
tracker: IJupyterCadTracker
) {
return async (args: any) => {
const current = tracker.currentWidget;

if (!current) {
return;
}

//TODO Updates types
//@ts-expect-error need to update types

Check failure on line 41 in src/command.ts

View workflow job for this annotation

GitHub Actions / check_release

Unused '@ts-expect-error' directive.
modelRegistry.registerModel('string');
};
}
}
7 changes: 7 additions & 0 deletions src/icon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { LabIcon } from '@jupyterlab/ui-components';
import exportIconStr from '../style/icon/grid.svg';

export const exportIcon = new LabIcon({
name: 'jupytercad:grid-icon',
svgstr: exportIconStr
});
51 changes: 48 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@ import {
JupyterFrontEndPlugin
} from '@jupyterlab/application';

import {
IJCadExternalCommandRegistry,
IJCadExternalCommandRegistryToken,
IJCadFormSchemaRegistry,
IJCadFormSchemaRegistryToken,
IJCadWorkerRegistry,
IJCadWorkerRegistryToken,
IJupyterCadDocTracker,
IJupyterCadTracker
} from '@jupytercad/schema';
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
import { IArPresentRegistryToken, IModelRegistry } from 'jupyterlab-gather';

Check failure on line 17 in src/index.ts

View workflow job for this annotation

GitHub Actions / check_release

Cannot find module 'jupyterlab-gather' or its corresponding type declarations.

import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { CommandIDs, addCommands } from './command';
import { GatherWorker } from './worker';

/**
* Initialization data for the jupytercad_gather extension.
Expand All @@ -12,20 +27,50 @@ const plugin: JupyterFrontEndPlugin<void> = {
id: 'jupytercad_gather:plugin',
description: 'A JupyterCAD plugin for the JupyterLab-Gather extenstion',
autoStart: true,
optional: [ISettingRegistry],
activate: (app: JupyterFrontEnd, settingRegistry: ISettingRegistry | null) => {
requires: [
IJCadWorkerRegistryToken,
IJCadFormSchemaRegistryToken,
IJupyterCadDocTracker,
IJCadExternalCommandRegistryToken,
IArPresentRegistryToken
],
optional: [ISettingRegistry, ITranslator],
activate: (
app: JupyterFrontEnd,
settingRegistry: ISettingRegistry | null,
workerRegistry: IJCadWorkerRegistry,
schemaRegistry: IJCadFormSchemaRegistry,
modelRegistry: IModelRegistry,
tracker: IJupyterCadTracker,
externalCommandRegistry: IJCadExternalCommandRegistry,
translator?: ITranslator
) => {
console.log('JupyterLab extension jupytercad_gather is activated!');

translator = translator ?? nullTranslator;

const worker = new GatherWorker({ modelRegistry, tracker });
workerRegistry.registerWorker('jupytercad-gatherLworker', worker);

if (settingRegistry) {
settingRegistry
.load(plugin.id)
.then(settings => {
console.log('jupytercad_gather settings loaded:', settings.composite);
})
.catch(reason => {
console.error('Failed to load settings for jupytercad_gather.', reason);
console.error(
'Failed to load settings for jupytercad_gather.',
reason
);
});
}

addCommands(app, tracker, modelRegistry, translator);
externalCommandRegistry.registerCommand({
name: 'Register GLTF Model',
id: CommandIDs.exportGltf
});
}
};

Expand Down
4 changes: 4 additions & 0 deletions src/svg.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.svg' {
const value: string;
export default value;
}
65 changes: 65 additions & 0 deletions src/worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
IJCadObject,
IJCadWorker,
IJupyterCadTracker,
IWorkerMessageBase,
WorkerAction
} from '@jupytercad/schema';
import { PromiseDelegate } from '@lumino/coreutils';
import { IModelRegistry } from 'jupyterlab-gather';

Check failure on line 9 in src/worker.ts

View workflow job for this annotation

GitHub Actions / check_release

Cannot find module 'jupyterlab-gather' or its corresponding type declarations.
import { v4 as uuid } from 'uuid';

export class GatherWorker implements IJCadWorker {
constructor(options: GatherWorker.IOptions) {
this._modelRegistry = options.modelRegistry;
}

get ready(): Promise<void> {
return this._ready.promise;
}

register(options: {
messageHandler: ((msg: any) => void) | ((msg: any) => Promise<void>);
thisArg?: any;
}): string {
const { messageHandler, thisArg } = options;
const id = uuid();
if (thisArg) {
messageHandler.bind(thisArg);
}
this._messageHandlers.set(id, messageHandler);
return id;
}

unregister(id: string): void {
this._messageHandlers.delete(id);
}

postMessage(msg: IWorkerMessageBase): void {
if (msg.action !== WorkerAction.POSTPROCESS) {
return;
}
if (msg.payload && Object.keys(msg.payload).length > 0) {
for (const key in msg.payload) {
const item = msg.payload[key] as {
occBrep: string;
jcObject: IJCadObject;
};

//TODO: Change this to based on whatever ends up getting exported
//@ts-expect-error WIP

Check failure on line 50 in src/worker.ts

View workflow job for this annotation

GitHub Actions / check_release

Unused '@ts-expect-error' directive.
this._modelRegistry.registerModel(item.occBrep);
}
}
}
private _ready = new PromiseDelegate<void>();
private _messageHandlers = new Map();
private _modelRegistry: IModelRegistry;
}

export namespace GatherWorker {
export interface IOptions {
tracker: IJupyterCadTracker;
modelRegistry: IModelRegistry;
}
}
6 changes: 6 additions & 0 deletions style/icon/export.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6d291e9

Please sign in to comment.