Skip to content

Commit c246bf2

Browse files
arjxn-pytrungleduc
andauthored
Fix placement for non-primitive shapes coming from freecad (#653)
* Fix placement for non-primitive shapes * Not required anymore * Update packages/occ-worker/src/occapi/index.ts Co-authored-by: Duc Trung Le <leductrungxf@gmail.com> --------- Co-authored-by: Duc Trung Le <leductrungxf@gmail.com>
1 parent 3b38e52 commit c246bf2

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

packages/occ-worker/src/actions.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ function buildModel(
3232
} else if (parameters['Shape']) {
3333
// Creating occ shape from brep file.
3434
const type = parameters['Type'] ?? 'brep';
35-
shapeData = ObjectFile({ content: parameters['Shape'], type }, model);
35+
shapeData = ObjectFile(
36+
{
37+
content: parameters['Shape'],
38+
type,
39+
placement: parameters?.Placement
40+
},
41+
model
42+
);
3643
} else if (shape.startsWith('Post::') && shapeMetadata) {
3744
const shapeFormat = (shapeMetadata.shapeFormat ??
3845
JCadWorkerSupportedFormat.BREP) as JCadWorkerSupportedFormat;

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { OCC } from '@jupytercad/opencascade';
22
import { IAny, IJCadContent } from '@jupytercad/schema';
33

4-
import { setShapePlacement } from './common';
54
import { _loadObjectFile } from './loadObjectFile';
65

76
export function _Any(
87
arg: IAny,
98
content: IJCadContent
109
): OCC.TopoDS_Shape | undefined {
1110
const { Content, Type, Placement } = arg;
12-
const result = _loadObjectFile({ content: Content, type: Type });
13-
if (result) {
14-
return setShapePlacement(result, Placement);
15-
}
11+
const result = _loadObjectFile({
12+
content: Content,
13+
type: Type,
14+
placement: Placement
15+
});
16+
return result;
1617
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export const Fillet = operatorCache<IFillet>('Part::Fillet', _Fillet);
6666
export const ObjectFile = operatorCache<{
6767
content: string;
6868
type: IAny['Type'];
69+
placement?: {
70+
Position: number[];
71+
Axis: number[];
72+
Angle: number;
73+
};
6974
}>('ObjectFile', _loadObjectFile);
7075

7176
export function initShapesFactory() {

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,36 @@ import { IAny } from '@jupytercad/schema';
44
import { _loadBrepFile } from './brepIO';
55
import { _loadStepFile } from './stepIO';
66
import { _loadStlFile } from './stlIO';
7+
import { setShapePlacement } from './common';
78

89
export function _loadObjectFile(arg: {
910
content: string;
1011
type: IAny['Type'];
12+
placement?: {
13+
Position: number[];
14+
Axis: number[];
15+
Angle: number;
16+
};
1117
}): OCC.TopoDS_Shape | undefined {
18+
let shape: OCC.TopoDS_Shape | undefined;
19+
1220
switch (arg.type.toLowerCase()) {
1321
case 'brep':
14-
return _loadBrepFile(arg.content);
22+
shape = _loadBrepFile(arg.content);
23+
break;
1524
case 'step':
16-
return _loadStepFile(arg.content);
25+
shape = _loadStepFile(arg.content);
26+
break;
1727
case 'stl':
18-
return _loadStlFile(arg.content);
28+
shape = _loadStlFile(arg.content);
29+
break;
1930
default:
2031
throw `${arg.type} file not supported`;
2132
}
33+
34+
if (shape) {
35+
setShapePlacement(shape, arg.placement);
36+
}
37+
38+
return shape;
2239
}

0 commit comments

Comments
 (0)