Skip to content

Commit e9cf29c

Browse files
authored
Update occ API (#330)
* Create makeShapeOnMesh function * Restructure occ api * Add stlIO functions
1 parent 7352a16 commit e9cf29c

27 files changed

+823
-498
lines changed

packages/occ-worker/src/actions.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { OCC } from '@jupytercad/opencascade';
21
import {
32
IDict,
43
IJCadContent,
@@ -7,20 +6,11 @@ import {
76
WorkerAction
87
} from '@jupytercad/schema';
98

10-
import { ObjectFile, ShapesFactory } from './occapi';
9+
import { ObjectFile, getShapesFactory } from './occapi';
1110

1211
import { OccParser } from './occparser';
1312
import { IOperatorArg, IOperatorFuncOutput } from './types';
1413

15-
let occ: OCC.OpenCascadeInstance;
16-
17-
export function getOcc(): OCC.OpenCascadeInstance {
18-
if (!occ) {
19-
occ = (self as any).occ as OCC.OpenCascadeInstance;
20-
}
21-
return occ;
22-
}
23-
2414
function buildModel(
2515
model: IJCadContent
2616
): { shapeData: IOperatorFuncOutput; jcObject: IJCadObject }[] {
@@ -35,18 +25,18 @@ function buildModel(
3525
if (!shape || !parameters) {
3626
return;
3727
}
38-
28+
const shapeFactory = getShapesFactory();
3929
let shapeData: IOperatorFuncOutput | undefined = undefined;
40-
if (ShapesFactory[shape]) {
41-
shapeData = ShapesFactory[shape](parameters as IOperatorArg, model);
30+
if (shapeFactory[shape]) {
31+
shapeData = shapeFactory[shape]?.(parameters as IOperatorArg, model);
4232
} else if (parameters['Shape'] && parameters['Type']) {
4333
// Creating occ shape from brep file.
4434
shapeData = ObjectFile(
4535
{ content: parameters['Shape'], type: parameters['Type'] },
4636
model
4737
);
4838
} else if (shape.startsWith('Post::')) {
49-
shapeData = ShapesFactory['Post::Operator'](
39+
shapeData = shapeFactory['Post::Operator']?.(
5040
parameters as IOperatorArg,
5141
model
5242
);

0 commit comments

Comments
 (0)