Skip to content

Commit 6f3ee22

Browse files
committed
Add support for opening STL and STEP files in JupyterLite
1 parent 427b97f commit 6f3ee22

File tree

14 files changed

+61
-19
lines changed

14 files changed

+61
-19
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ jobs:
239239
working-directory: lite
240240
run: |
241241
set -eux
242-
mkdir -p content && cp ../examples/test.jcad ./content
242+
mkdir -p content && cp ../examples/*.jcad ../examples/*.STEP ../examples/*.stl ./content
243243
jupyter lite build --contents content --output-dir dist
244244
245245
- name: Upload github-pages artifact

packages/schema/src/model.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ export class JupyterCadModel implements IJupyterCadModel {
2626
if (sharedModel) {
2727
this._sharedModel = sharedModel;
2828
} else {
29-
this._sharedModel = JupyterCadDoc.create();
29+
this._sharedModel = this.createSharedModel();
3030
this._sharedModel.changed.connect(this._onSharedModelChanged);
3131
}
3232
this.sharedModel.awareness.on('change', this._onClientStateChanged);
3333
this.annotationModel = annotationModel;
3434
}
3535

36+
protected createSharedModel(): IJupyterCadDoc {
37+
return JupyterCadDoc.create();
38+
}
39+
3640
private _onSharedModelChanged = (sender: any, changes: any): void => {
3741
if (changes && changes?.objectChange?.length) {
3842
this._contentChanged.emit(void 0);

python/jupytercad_core/src/jcadplugin/modelfactory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class JupyterCadJcadModelFactory
3737
* @returns The content type
3838
*/
3939
get contentType(): Contents.ContentType {
40-
return 'JupyterCAD';
40+
return 'jcad';
4141
}
4242

4343
/**

python/jupytercad_core/src/jcadplugin/plugins.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { JupyterCadJcadModelFactory } from './modelfactory';
3434
import { MimeDocumentFactory } from '@jupyterlab/docregistry';
3535

3636
const FACTORY = 'JupyterCAD';
37+
const CONTENT_TYPE = 'jcad';
3738
const PALETTE_CATEGORY = 'JupyterCAD';
3839

3940
namespace CommandIDs {
@@ -59,8 +60,8 @@ const activate = (
5960
const widgetFactory = new JupyterCadWidgetFactory({
6061
name: FACTORY,
6162
modelName: 'jupytercad-jcadmodel',
62-
fileTypes: [FACTORY],
63-
defaultFor: [FACTORY],
63+
fileTypes: [CONTENT_TYPE],
64+
defaultFor: [CONTENT_TYPE],
6465
tracker,
6566
commands: app.commands,
6667
workerRegistry,
@@ -81,7 +82,7 @@ const activate = (
8182
modelName: 'jupytercad-jcadmodel',
8283
name: 'JSON Editor',
8384
primaryFileType: app.docRegistry.getFileType('json'),
84-
fileTypes: [FACTORY]
85+
fileTypes: [CONTENT_TYPE]
8586
});
8687
app.docRegistry.addWidgetFactory(factory);
8788

@@ -92,12 +93,12 @@ const activate = (
9293
app.docRegistry.addModelFactory(modelFactory);
9394
// register the filetype
9495
app.docRegistry.addFileType({
95-
name: FACTORY,
96+
name: CONTENT_TYPE,
9697
displayName: FACTORY,
9798
mimeTypes: ['text/json'],
9899
extensions: ['.jcad', '.JCAD'],
99100
fileFormat: 'text',
100-
contentType: FACTORY,
101+
contentType: CONTENT_TYPE,
101102
icon: logoIcon
102103
});
103104

python/jupytercad_core/src/stepplugin/model.ts

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export class JupyterCadStepDoc extends JupyterCadDoc {
1717
this._source.observeDeep(this._sourceObserver);
1818
}
1919

20+
set source(value: string) {
21+
this._source.insert(0, value);
22+
}
23+
2024
get version(): string {
2125
return '0.1.0';
2226
}

python/jupytercad_core/src/stepplugin/modelfactory.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import { IJupyterCadDoc, JupyterCadModel } from '@jupytercad/schema';
22
import { DocumentRegistry } from '@jupyterlab/docregistry';
33
import { Contents } from '@jupyterlab/services';
4+
import { JupyterCadStepDoc } from './model';
5+
6+
class JupyterCadStepModel extends JupyterCadModel {
7+
fromString(data: string): void {
8+
(this.sharedModel as JupyterCadStepDoc).source = data;
9+
this.dirty = true;
10+
}
11+
12+
protected createSharedModel(): IJupyterCadDoc {
13+
return JupyterCadStepDoc.create();
14+
}
15+
}
416

517
/**
618
* A Model factory to create new instances of JupyterCadModel.
@@ -68,14 +80,14 @@ export class JupyterCadStepModelFactory
6880
}
6981

7082
/**
71-
* Create a new instance of JupyterCadModel.
83+
* Create a new instance of JupyterCadStepModel.
7284
*
7385
* @returns The model
7486
*/
7587
createNew(
7688
options: DocumentRegistry.IModelOptions<IJupyterCadDoc>
77-
): JupyterCadModel {
78-
const model = new JupyterCadModel({
89+
): JupyterCadStepModel {
90+
const model = new JupyterCadStepModel({
7991
sharedModel: options.sharedModel,
8092
languagePreference: options.languagePreference
8193
});

python/jupytercad_core/src/stepplugin/plugins.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const activate = (
5151
app.docRegistry.addFileType({
5252
name: 'step',
5353
displayName: 'STEP',
54-
mimeTypes: ['text/json'],
54+
mimeTypes: ['text/plain'],
5555
extensions: ['.step', '.STEP'],
5656
fileFormat: 'text',
5757
contentType: 'step',

python/jupytercad_core/src/stlplugin/model.ts

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export class JupyterCadStlDoc extends JupyterCadDoc {
1717
this._source.observeDeep(this._sourceObserver);
1818
}
1919

20+
set source(value: string) {
21+
this._source.insert(0, value);
22+
}
23+
2024
get version(): string {
2125
return '0.1.0';
2226
}

python/jupytercad_core/src/stlplugin/modelfactory.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
import { IJupyterCadDoc, JupyterCadModel } from '@jupytercad/schema';
22
import { DocumentRegistry } from '@jupyterlab/docregistry';
33
import { Contents } from '@jupyterlab/services';
4+
import { JupyterCadStlDoc } from './model';
5+
6+
class JupyterCadStlModel extends JupyterCadModel {
7+
fromString(data: string): void {
8+
(this.sharedModel as JupyterCadStlDoc).source = data;
9+
this.dirty = true;
10+
}
11+
12+
protected createSharedModel(): IJupyterCadDoc {
13+
return JupyterCadStlDoc.create();
14+
}
15+
}
416

517
/**
6-
* A Model factory to create new instances of JupyterCadModel.
18+
* A Model factory to create new instances of JupyterCadSTLModel.
719
*/
820
export class JupyterCadStlModelFactory
9-
implements DocumentRegistry.IModelFactory<JupyterCadModel>
21+
implements DocumentRegistry.IModelFactory<JupyterCadStlModel>
1022
{
1123
/**
1224
* Whether the model is collaborative or not.
@@ -68,14 +80,14 @@ export class JupyterCadStlModelFactory
6880
}
6981

7082
/**
71-
* Create a new instance of JupyterCadModel.
83+
* Create a new instance of JupyterCadSTLModel.
7284
*
7385
* @returns The model
7486
*/
7587
createNew(
7688
options: DocumentRegistry.IModelOptions<IJupyterCadDoc>
77-
): JupyterCadModel {
78-
const model = new JupyterCadModel({
89+
): JupyterCadStlModel {
90+
const model = new JupyterCadStlModel({
7991
sharedModel: options.sharedModel,
8092
languagePreference: options.languagePreference
8193
});

python/jupytercad_core/src/stlplugin/plugins.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const activate = (
5151
app.docRegistry.addFileType({
5252
name: 'stl',
5353
displayName: 'STL',
54-
mimeTypes: ['text/json'],
54+
mimeTypes: ['text/plain'],
5555
extensions: ['.stl', '.STL'],
5656
fileFormat: 'text',
5757
contentType: 'stl',

python/jupyverse/fps_jupytercad/routes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def check_backend(
2525
except ImportError:
2626
fc_installed = False
2727
return Install(installed=fc_installed)
28-
elif backend == "JCAD":
28+
elif backend == "jcad":
2929
return Install(installed=True)
3030
else:
3131
return Install(installed=False)

ui-tests/tests/sketcher.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test.describe('Sketcher test', () => {
99
page.setViewportSize({ width: 1920, height: 1080 });
1010
page.on('console', message => {
1111
if (message.type() === 'error') {
12+
console.log('ERROR MSG', message.text());
1213
errors += 1;
1314
}
1415
});

ui-tests/tests/tree.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test.describe('Tree UI test', () => {
99
page.setViewportSize({ width: 1920, height: 1080 });
1010
page.on('console', message => {
1111
if (message.type() === 'error') {
12+
console.log('ERROR MSG', message.text());
1213
errors += 1;
1314
}
1415
});

ui-tests/tests/ui.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ test.describe('UI Test', () => {
1414
const logs: string[] = [];
1515

1616
page.on('console', message => {
17+
console.log('CONSOLE MSG', message.text());
1718
logs.push(message.text());
1819
});
1920

@@ -38,6 +39,7 @@ test.describe('UI Test', () => {
3839
page.setViewportSize({ width: 1920, height: 1080 });
3940
page.on('console', message => {
4041
if (message.type() === 'error') {
42+
console.log('ERROR MSG', message.text());
4143
errors += 1;
4244
}
4345
});
@@ -87,6 +89,7 @@ test.describe('UI Test', () => {
8789
page.setViewportSize({ width: 1920, height: 1080 });
8890
page.on('console', message => {
8991
if (message.type() === 'error') {
92+
console.log('ERROR MSG', message.text());
9093
errors += 1;
9194
}
9295
});

0 commit comments

Comments
 (0)