Skip to content

Commit

Permalink
✨ feat: add Split and Section
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangechen committed May 28, 2024
1 parent 47768af commit afea788
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/chili-core/src/command/commandKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type CommandKeys =
| "create.group"
| "create.polygon"
| "create.offset"
| "create.section"
| "convert.toWire"
| "convert.toFace"
| "convert.prism"
Expand All @@ -35,5 +36,6 @@ export type CommandKeys =
| "modify.rotate"
| "modify.mirror"
| "modify.delete"
| "modify.split"
| "workingPlane.alignToPlane"
| "workingPlane.set";
2 changes: 2 additions & 0 deletions packages/chili-core/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export default {
"command.import": "Import",
"command.export.iges": "Export IGS",
"command.export.step": "Export STP",
"command.section": "Section",
"command.split": "Split",
"snap.end": "End",
"snap.mid": "Middle",
"snap.center": "Center",
Expand Down
2 changes: 2 additions & 0 deletions packages/chili-core/src/i18n/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export type I18nKeys =
| "command.import"
| "command.export.iges"
| "command.export.step"
| "command.split"
| "command.section"
| "operate.pickFistPoint"
| "operate.pickNextPoint"
| "operate.pickCircleCenter"
Expand Down
2 changes: 2 additions & 0 deletions packages/chili-core/src/i18n/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export default {
"command.import": "导入",
"command.export.iges": "导出IGS",
"command.export.step": "导出STP",
"command.split": "分割",
"command.section": "相交线",
"snap.end": "端点",
"snap.mid": "中点",
"snap.center": "圆心",
Expand Down
11 changes: 9 additions & 2 deletions packages/chili-ui/src/profile/ribbon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ export const DefaultRibbon: RibbonTabProfile[] = [
},
{
groupName: "ribbon.group.modify",
items: ["modify.move", "modify.rotate", "modify.mirror", "modify.delete", "create.offset"],
items: [
"modify.move",
"modify.rotate",
"modify.mirror",
"modify.delete",
"create.offset",
"modify.split",
],
},
{
groupName: "ribbon.group.converter",
Expand All @@ -42,7 +49,7 @@ export const DefaultRibbon: RibbonTabProfile[] = [
},
{
groupName: "ribbon.group.boolean",
items: ["boolean.common", "boolean.cut", "boolean.fuse"],
items: ["boolean.common", "boolean.cut", "boolean.fuse", "create.section"],
},
{
groupName: "ribbon.group.workingPlane",
Expand Down
1 change: 1 addition & 0 deletions packages/chili/src/commands/create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export * from "./polygon";
export * from "./prism";
export * from "./rect";
export * from "./revolve";
export * from "./section";
export * from "./sweep";
27 changes: 27 additions & 0 deletions packages/chili/src/commands/create/section.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license.

import { EditableGeometryEntity, GeometryEntity, ShapeType, command } from "chili-core";
import { IStep } from "../../step";
import { SelectShapeStep } from "../../step/selectStep";
import { CreateCommand } from "../createCommand";

@command({
name: "create.section",
display: "command.section",
icon: "icon-section",
})
export class Section extends CreateCommand {
protected override geometryEntity(): GeometryEntity {
let shape = this.stepDatas[0].shapes[0].shape;
let path = this.stepDatas[1].shapes[0].shape;
let section = shape.section(path);
return new EditableGeometryEntity(this.document, section);
}

protected override getSteps(): IStep[] {
return [
new SelectShapeStep(ShapeType.Shape, "prompt.select.shape", false),
new SelectShapeStep(ShapeType.Shape, "prompt.select.shape", false),
];
}
}
1 change: 1 addition & 0 deletions packages/chili/src/commands/modify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./array";
export * from "./mirror";
export * from "./move";
export * from "./rotate";
export * from "./split";
27 changes: 27 additions & 0 deletions packages/chili/src/commands/modify/split.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license.

import { EditableGeometryEntity, GeometryEntity, IEdge, ShapeType, command } from "chili-core";
import { IStep } from "../../step";
import { SelectShapeStep } from "../../step/selectStep";
import { CreateCommand } from "../createCommand";

@command({
name: "modify.split",
display: "command.split",
icon: "icon-split",
})
export class Split extends CreateCommand {
protected override geometryEntity(): GeometryEntity {
let shape1 = this.stepDatas[0].shapes[0].shape;
let edges = this.stepDatas[1].shapes.map((x) => x.shape) as IEdge[];
let shapes = shape1.split(edges);
return new EditableGeometryEntity(this.document, shapes);
}

protected override getSteps(): IStep[] {
return [
new SelectShapeStep(ShapeType.Shape, "prompt.select.shape", false),
new SelectShapeStep(ShapeType.Edge, "prompt.select.shape", true),
];
}
}
2 changes: 1 addition & 1 deletion public/iconfont.js

Large diffs are not rendered by default.

0 comments on commit afea788

Please sign in to comment.