Skip to content

Commit fa205e0

Browse files
authored
Add Torus (#15)
1 parent 00b253c commit fa205e0

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

src/schema/jcad.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"Part::Cylinder",
2020
"Part::Sphere",
2121
"Part::Cone",
22+
"Part::Torus",
2223
"Part::Cut"
2324
]
2425
},

src/schema/torus.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"type": "object",
3+
"description": "Part::Torus",
4+
"title": "ITorus",
5+
"required": ["Radius1", "Radius2", "Angle1", "Angle2", "Angle3", "Placement"],
6+
"additionalProperties": false,
7+
"properties": {
8+
"Radius1": {
9+
"type": "number",
10+
"description": "The radius of the torus"
11+
},
12+
"Radius2": {
13+
"type": "number",
14+
"description": "The radius of the torus"
15+
},
16+
"Angle1": {
17+
"type": "number",
18+
"description": "The angle of the torus"
19+
},
20+
"Angle2": {
21+
"type": "number",
22+
"description": "The angle of the torus"
23+
},
24+
"Angle3": {
25+
"type": "number",
26+
"description": "The angle of the torus"
27+
},
28+
"Placement": {
29+
"$ref": "./placement.json"
30+
}
31+
}
32+
}

src/toolbar/parttoolbar.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ export class PartToolbarReact extends React.Component<IProps> {
5959
Angle: 360,
6060
Placement: { Position: [0, 0, 0], Axis: [0, 0, 1], Angle: 0 }
6161
}
62+
},
63+
TORUS: {
64+
title: 'Torus parameters',
65+
shape: 'Part::Torus',
66+
schema: this.props.toolbarModel.formSchema['Part::Torus'],
67+
default: {
68+
Radius1: 10,
69+
Radius2: 2,
70+
Angle1: -180,
71+
Angle2: 180,
72+
Angle3: 360,
73+
Placement: { Position: [0, 0, 0], Axis: [0, 0, 1], Angle: 0 }
74+
}
6275
}
6376
};
6477

src/worker/occapi.ts

+17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IBox } from '../_interface/box';
77
import { ICylinder } from '../_interface/cylinder';
88
import { ISphere } from '../_interface/sphere';
99
import { ICone } from '../_interface/cone';
10+
import { ITorus } from '../_interface/torus';
1011
import { ICut } from '../_interface/cut';
1112

1213
const SHAPE_CACHE = new Map<string, TopoDS_Shape>();
@@ -103,6 +104,20 @@ function _Cone(arg: ICone, _: IJCadContent): TopoDS_Shape | undefined {
103104
return setShapePlacement(shape, Placement);
104105
}
105106

107+
function _Torus(arg: ITorus, _: IJCadContent): TopoDS_Shape | undefined {
108+
const { Radius1, Radius2, Angle1, Angle2, Angle3, Placement } = arg;
109+
const oc = getOcc();
110+
const torus = new oc.BRepPrimAPI_MakeTorus_4(
111+
Radius1,
112+
Radius2,
113+
toRad(Angle1),
114+
toRad(Angle2),
115+
toRad(Angle3)
116+
);
117+
const shape = torus.Shape();
118+
return setShapePlacement(shape, Placement);
119+
}
120+
106121
function _Cut(arg: ICut, content: IJCadContent): TopoDS_Shape | undefined {
107122
const { Placement, Base, Tool } = arg;
108123
const oc = getOcc();
@@ -140,6 +155,7 @@ const Box = operatorCache<IBox>('Box', _Box);
140155
const Cylinder = operatorCache<ICylinder>('Cylinder', _Cylinder);
141156
const Sphere = operatorCache<ISphere>('Sphere', _Sphere);
142157
const Cone = operatorCache<ICone>('Cone', _Cone);
158+
const Torus = operatorCache<ITorus>('Torus', _Torus);
143159
// const Cut = operatorCache<ICut>('Cut', _Cut);
144160

145161
export const ShapesFactory: {
@@ -149,5 +165,6 @@ export const ShapesFactory: {
149165
'Part::Cylinder': Cylinder,
150166
'Part::Sphere': Sphere,
151167
'Part::Cone': Cone,
168+
'Part::Torus': Torus,
152169
'Part::Cut': _Cut
153170
};

src/worker/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IBox } from '../_interface/box';
44
import { ICylinder } from '../_interface/cylinder';
55
import { ISphere } from '../_interface/sphere';
66
import { ICone } from '../_interface/cone';
7+
import { ITorus } from '../_interface/torus';
78
import { ICut } from '../_interface/cut';
89

910
type IOperatorFunc<T> = (
@@ -16,5 +17,6 @@ export type IAllOperatorFunc =
1617
| IOperatorFunc<ICylinder>
1718
| IOperatorFunc<ISphere>
1819
| IOperatorFunc<ICone>
20+
| IOperatorFunc<ITorus>
1921
| IOperatorFunc<ICut>;
20-
export type IOperatorArg = IBox & ICylinder & ISphere & ICone & ICut;
22+
export type IOperatorArg = IBox & ICylinder & ISphere & ICone & ITorus & ICut;

0 commit comments

Comments
 (0)