Skip to content

Commit a88be8d

Browse files
authored
Fix dry-run logic so that it does not run on the first load of the file (#366)
1 parent ee3ed26 commit a88be8d

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

packages/occ-worker/src/actions.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,15 @@ function buildModel(
6363
return outputModel;
6464
}
6565

66-
function loadFile(payload: { content: IJCadContent }): IDict | null {
66+
function loadFile(
67+
payload: { content: IJCadContent },
68+
raiseOnFailure = false
69+
): IDict | null {
6770
const { content } = payload;
6871
const outputModel = buildModel(content);
6972

7073
const parser = new OccParser(outputModel);
71-
const result = parser.execute();
74+
const result = parser.execute(raiseOnFailure);
7275
const postResult: IDict<IPostOperatorInput> = {};
7376
outputModel.forEach(item => {
7477
if (item.jcObject.shape?.startsWith('Post::')) {
@@ -82,9 +85,14 @@ function loadFile(payload: { content: IJCadContent }): IDict | null {
8285
return { result, postResult };
8386
}
8487

88+
function dryRun(payload: { content: IJCadContent }) {
89+
return loadFile(payload, true);
90+
}
91+
8592
const WorkerHandler: {
8693
[key in WorkerAction]: (payload: any) => any;
8794
} = {} as any;
8895
WorkerHandler[WorkerAction.LOAD_FILE] = loadFile;
96+
WorkerHandler[WorkerAction.DRY_RUN] = dryRun;
8997

9098
export default WorkerHandler;

packages/occ-worker/src/occapi/operatorCache.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ export function operatorCache<T>(
154154
return (
155155
args: T,
156156
content: IJCadContent
157-
): { occShape: OCC.TopoDS_Shape; metadata?: IShapeMetadata | undefined } => {
157+
):
158+
| { occShape: OCC.TopoDS_Shape; metadata?: IShapeMetadata | undefined }
159+
| undefined => {
158160
const expandedArgs = expand_operator(name, args, content);
159161
const hash = `${hashCode(JSON.stringify(expandedArgs))}`;
160162
if (SHAPE_CACHE.has(hash)) {
@@ -168,10 +170,6 @@ export function operatorCache<T>(
168170
};
169171
SHAPE_CACHE.set(hash, cacheData);
170172
return cacheData;
171-
} else {
172-
throw new Error(
173-
`Unknown error while creating ${name}: ${JSON.stringify(content)}`
174-
);
175173
}
176174
}
177175
};

packages/occ-worker/src/occparser.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@ interface IShapeList {
1111
export class OccParser {
1212
private _shapeList: IShapeList[];
1313
private _occ: OCC.OpenCascadeInstance = (self as any).occ;
14+
1415
constructor(shapeList: IShapeList[]) {
1516
this._shapeList = shapeList;
1617
}
1718

18-
execute(): IDict<IParsedShape> {
19+
execute(raiseOnFailure = false): IDict<IParsedShape> {
1920
const maxDeviation = 0.1;
2021
const threejsData: IDict<IParsedShape> = {};
2122
this._shapeList.forEach(data => {
2223
const { shapeData, jcObject } = data;
2324
const { occShape, metadata } = shapeData;
2425
if (!occShape) {
25-
return;
26+
if (raiseOnFailure) {
27+
throw Error('Unknown failure');
28+
} else {
29+
return;
30+
}
2631
}
2732
new this._occ.BRepMesh_IncrementalMesh_2(
2833
occShape,

packages/occ-worker/src/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ self.onmessage = async (event: MessageEvent): Promise<void> => {
5757
}
5858
case WorkerAction.DRY_RUN: {
5959
try {
60-
WorkerHandler[WorkerAction.LOAD_FILE](message.payload);
60+
WorkerHandler[WorkerAction.DRY_RUN](message.payload);
6161
} catch (e) {
6262
let msg = '';
6363

0 commit comments

Comments
 (0)