-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
12,671 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
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 GitHub Actions / check_release
|
||
modelRegistry.registerModel('string'); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module '*.svg' { | ||
const value: string; | ||
export default value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
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 GitHub Actions / check_release
|
||
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; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.