Skip to content

Commit

Permalink
Fix placement for non-primitive shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
arjxn-py committed Dec 13, 2024
1 parent 3b38e52 commit 3a055cc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/occ-worker/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function buildModel(
} else if (parameters['Shape']) {
// Creating occ shape from brep file.
const type = parameters['Type'] ?? 'brep';
shapeData = ObjectFile({ content: parameters['Shape'], type }, model);
shapeData = ObjectFile({ content: parameters['Shape'], type, placement: parameters?.Placement }, model);
} else if (shape.startsWith('Post::') && shapeMetadata) {
const shapeFormat = (shapeMetadata.shapeFormat ??
JCadWorkerSupportedFormat.BREP) as JCadWorkerSupportedFormat;
Expand Down
2 changes: 1 addition & 1 deletion packages/occ-worker/src/occapi/any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function _Any(
content: IJCadContent
): OCC.TopoDS_Shape | undefined {
const { Content, Type, Placement } = arg;
const result = _loadObjectFile({ content: Content, type: Type });
const result = _loadObjectFile({ content: Content, type: Type, placement: Placement });
if (result) {
return setShapePlacement(result, Placement);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/occ-worker/src/occapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export const Fillet = operatorCache<IFillet>('Part::Fillet', _Fillet);
export const ObjectFile = operatorCache<{
content: string;
type: IAny['Type'];
placement: {
Position: number[];
Axis: number[];
Angle: number;
}
}>('ObjectFile', _loadObjectFile);

export function initShapesFactory() {
Expand Down
23 changes: 20 additions & 3 deletions packages/occ-worker/src/occapi/loadObjectFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,36 @@ import { IAny } from '@jupytercad/schema';
import { _loadBrepFile } from './brepIO';
import { _loadStepFile } from './stepIO';
import { _loadStlFile } from './stlIO';
import { setShapePlacement } from './common';

export function _loadObjectFile(arg: {
content: string;
type: IAny['Type'];
placement?: {
Position: number[];
Axis: number[];
Angle: number;
}
}): OCC.TopoDS_Shape | undefined {
let shape: OCC.TopoDS_Shape | undefined;

switch (arg.type.toLowerCase()) {
case 'brep':
return _loadBrepFile(arg.content);
shape = _loadBrepFile(arg.content);
break;
case 'step':
return _loadStepFile(arg.content);
shape = _loadStepFile(arg.content);
break;
case 'stl':
return _loadStlFile(arg.content);
shape = _loadStlFile(arg.content);
break;
default:
throw `${arg.type} file not supported`;
}

if (shape){
setShapePlacement(shape, arg.placement);
}

return shape;
}

0 comments on commit 3a055cc

Please sign in to comment.