Skip to content

Commit a556001

Browse files
cxh1378xiangechen
authored andcommitted
feat:Add curve projection function
1 parent 865ae9e commit a556001

File tree

12 files changed

+75
-2
lines changed

12 files changed

+75
-2
lines changed

cpp/src/factory.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#include "shared.hpp"
3838

39+
#include <BRepProj_Projection.hxx>
40+
3941
using namespace emscripten;
4042

4143
struct ShapeResult {
@@ -568,6 +570,15 @@ class ShapeFactory {
568570
}
569571
return ShapeResult { makeChamfer.Shape(), true, "" };
570572
}
573+
574+
static ShapeResult curveProjection(const TopoDS_Shape& curve, const TopoDS_Shape& targetFace, const gp_Dir& dir)
575+
{
576+
BRepProj_Projection curveProjection(curve, targetFace, dir);
577+
if (!curveProjection.IsDone()) {
578+
return ShapeResult { TopoDS_Shape(), false, "Failed to create curve projection" };
579+
}
580+
return ShapeResult { curveProjection.Shape(), true, "" };
581+
}
571582
};
572583

573584
EMSCRIPTEN_BINDINGS(ShapeFactory)
@@ -608,5 +619,6 @@ EMSCRIPTEN_BINDINGS(ShapeFactory)
608619
.class_function("booleanFuse", &ShapeFactory::booleanFuse)
609620
.class_function("combine", &ShapeFactory::combine)
610621
.class_function("fillet", &ShapeFactory::fillet)
611-
.class_function("chamfer", &ShapeFactory::chamfer);
622+
.class_function("chamfer", &ShapeFactory::chamfer)
623+
.class_function("curveProjection", &ShapeFactory::curveProjection);
612624
}

packages/chili-builder/src/ribbon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const DefaultRibbon: RibbonTab[] = [
3838
"convert.sweep",
3939
"convert.revol",
4040
"convert.toWire",
41+
"convert.curveProjection",
4142
["convert.toFace", "convert.toShell", "convert.toSolid"],
4243
],
4344
},

packages/chili-core/src/i18n/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default {
5656
"command.convert.toShell": "ToShell",
5757
"command.convert.toSolid": "ToSolid",
5858
"command.convert.toWire": "ToWire",
59+
"command.convert.curveProjection": "CurveProjection",
5960
"command.create.arc": "Arc",
6061
"command.create.bezier": "Bezier",
6162
"command.create.box": "Box",
@@ -121,6 +122,7 @@ export default {
121122
"common.confirm": "Confirm",
122123
"common.general": "General",
123124
"common.length": "Length",
125+
"common.dir": "Direction",
124126
"common.material": "Material",
125127
"common.matrix": "Matrix",
126128
"common.name": "Name",

packages/chili-core/src/i18n/keys.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const I18N_KEYS = [
5151
"command.convert.toShell",
5252
"command.convert.toSolid",
5353
"command.convert.toWire",
54+
"command.convert.curveProjection",
5455
"command.create.arc",
5556
"command.create.bezier",
5657
"command.create.box",
@@ -116,6 +117,7 @@ const I18N_KEYS = [
116117
"common.confirm",
117118
"common.general",
118119
"common.length",
120+
"common.dir",
119121
"common.material",
120122
"common.matrix",
121123
"common.name",

packages/chili-core/src/i18n/zh-cn.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default {
5656
"command.convert.toShell": "转为壳",
5757
"command.convert.toSolid": "转为体",
5858
"command.convert.toWire": "转多段线",
59+
"command.convert.curveProjection": "曲线投影",
5960
"command.create.arc": "圆弧",
6061
"command.create.bezier": "贝塞尔",
6162
"command.create.box": "立方体",
@@ -121,6 +122,7 @@ export default {
121122
"common.confirm": "确定",
122123
"common.general": "常规",
123124
"common.length": "长度",
125+
"common.dir": "方向",
124126
"common.material": "材质",
125127
"common.matrix": "矩阵",
126128
"common.name": "名称",

packages/chili-core/src/shape/shapeFactory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ export interface IShapeFactory {
4747
removeFeature(shape: IShape, faces: IFace[]): Result<IShape>;
4848
removeSubShape(shape: IShape, subShapes: IShape[]): IShape;
4949
replaceSubShape(shape: IShape, subShape: IShape, newSubShape: IShape): IShape;
50+
curveProjection(curve: IEdge | IWire, targetFace: IFace, vec: XYZ): Result<IShape>;
5051
}

packages/chili-wasm/lib/chili-wasm.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ interface EmbindModule {
586586
ShapeResult: {};
587587
ShapeFactory: {
588588
makeThickSolidBySimple(_0: TopoDS_Shape, _1: number): ShapeResult;
589+
curveProjection(_0: TopoDS_Shape, _1: TopoDS_Shape, _2: gp_Dir): ShapeResult;
589590
polygon(_0: Array<Vector3>): ShapeResult;
590591
bezier(_0: Array<Vector3>, _1: Array<number>): ShapeResult;
591592
fillet(_0: TopoDS_Shape, _1: Array<number>, _2: number): ShapeResult;
5.1 KB
Binary file not shown.

packages/chili-wasm/src/factory.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,13 @@ export class ShapeFactory implements IShapeFactory {
285285
),
286286
);
287287
}
288+
curveProjection(curve: IEdge | IWire, targetFace: IFace, vec: XYZ): Result<IShape> {
289+
return convertShapeResult(
290+
wasm.ShapeFactory.curveProjection(
291+
ensureOccShape(curve)[0],
292+
ensureOccShape(targetFace)[0],
293+
new wasm.gp_Dir(vec.x, vec.y, vec.z),
294+
),
295+
);
296+
}
288297
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Part of the Chili3d Project, under the AGPL-3.0 License.
2+
// See LICENSE file in the project root for full license information.
3+
4+
import { command, EditableShapeNode, I18n, IEdge, IFace, IWire, Property, ShapeType, XYZ } from "chili-core";
5+
import { IStep, SelectShapeStep } from "../../step";
6+
import { CreateCommand } from "../createCommand";
7+
8+
@command({
9+
key: "convert.curveProjection",
10+
icon: "icon-curveProjection",
11+
})
12+
export class CurveProjectionCommand extends CreateCommand {
13+
@Property.define("common.dir")
14+
get dir() {
15+
return this.getPrivateValue("dir", "0,0,-1");
16+
}
17+
18+
set dir(value: string) {
19+
this.setProperty("dir", value);
20+
}
21+
22+
protected override geometryNode() {
23+
let shape = this.stepDatas[0].shapes[0].shape as IEdge | IWire;
24+
let face = this.stepDatas[1].shapes[0].shape as IFace;
25+
const [x, y, z] = this.dir.split(",").map(Number);
26+
let dir = new XYZ(x, y, z).normalize() as XYZ;
27+
28+
let curveProjection = this.application.shapeFactory.curveProjection(shape, face, dir);
29+
return new EditableShapeNode(
30+
this.document,
31+
I18n.translate("command.convert.curveProjection"),
32+
curveProjection.value,
33+
);
34+
}
35+
36+
protected override getSteps(): IStep[] {
37+
return [
38+
new SelectShapeStep(ShapeType.Edge | ShapeType.Wire, "prompt.select.shape"),
39+
new SelectShapeStep(ShapeType.Face, "prompt.select.faces"),
40+
];
41+
}
42+
}

0 commit comments

Comments
 (0)