From afea788a99245de5673128dd92b06abaabf13f00 Mon Sep 17 00:00:00 2001 From: xiange Date: Tue, 28 May 2024 21:47:31 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20Split=20and=20Section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chili-core/src/command/commandKeys.ts | 2 ++ packages/chili-core/src/i18n/en.ts | 2 ++ packages/chili-core/src/i18n/keys.ts | 2 ++ packages/chili-core/src/i18n/zh-cn.ts | 2 ++ packages/chili-ui/src/profile/ribbon.ts | 11 ++++++-- packages/chili/src/commands/create/index.ts | 1 + packages/chili/src/commands/create/section.ts | 27 +++++++++++++++++++ packages/chili/src/commands/modify/index.ts | 1 + packages/chili/src/commands/modify/split.ts | 27 +++++++++++++++++++ public/iconfont.js | 2 +- 10 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 packages/chili/src/commands/create/section.ts create mode 100644 packages/chili/src/commands/modify/split.ts diff --git a/packages/chili-core/src/command/commandKeys.ts b/packages/chili-core/src/command/commandKeys.ts index b0f64004..807d953b 100644 --- a/packages/chili-core/src/command/commandKeys.ts +++ b/packages/chili-core/src/command/commandKeys.ts @@ -24,6 +24,7 @@ export type CommandKeys = | "create.group" | "create.polygon" | "create.offset" + | "create.section" | "convert.toWire" | "convert.toFace" | "convert.prism" @@ -35,5 +36,6 @@ export type CommandKeys = | "modify.rotate" | "modify.mirror" | "modify.delete" + | "modify.split" | "workingPlane.alignToPlane" | "workingPlane.set"; diff --git a/packages/chili-core/src/i18n/en.ts b/packages/chili-core/src/i18n/en.ts index 79268eb3..063e26ec 100644 --- a/packages/chili-core/src/i18n/en.ts +++ b/packages/chili-core/src/i18n/en.ts @@ -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", diff --git a/packages/chili-core/src/i18n/keys.ts b/packages/chili-core/src/i18n/keys.ts index c3c80112..7a17f554 100644 --- a/packages/chili-core/src/i18n/keys.ts +++ b/packages/chili-core/src/i18n/keys.ts @@ -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" diff --git a/packages/chili-core/src/i18n/zh-cn.ts b/packages/chili-core/src/i18n/zh-cn.ts index 5e960588..c680069a 100644 --- a/packages/chili-core/src/i18n/zh-cn.ts +++ b/packages/chili-core/src/i18n/zh-cn.ts @@ -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": "圆心", diff --git a/packages/chili-ui/src/profile/ribbon.ts b/packages/chili-ui/src/profile/ribbon.ts index be689ec8..2ef41d6f 100644 --- a/packages/chili-ui/src/profile/ribbon.ts +++ b/packages/chili-ui/src/profile/ribbon.ts @@ -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", @@ -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", diff --git a/packages/chili/src/commands/create/index.ts b/packages/chili/src/commands/create/index.ts index 51e6f332..8f298937 100644 --- a/packages/chili/src/commands/create/index.ts +++ b/packages/chili/src/commands/create/index.ts @@ -12,4 +12,5 @@ export * from "./polygon"; export * from "./prism"; export * from "./rect"; export * from "./revolve"; +export * from "./section"; export * from "./sweep"; diff --git a/packages/chili/src/commands/create/section.ts b/packages/chili/src/commands/create/section.ts new file mode 100644 index 00000000..617126c5 --- /dev/null +++ b/packages/chili/src/commands/create/section.ts @@ -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), + ]; + } +} diff --git a/packages/chili/src/commands/modify/index.ts b/packages/chili/src/commands/modify/index.ts index 6b47ade6..9f92b8bb 100644 --- a/packages/chili/src/commands/modify/index.ts +++ b/packages/chili/src/commands/modify/index.ts @@ -4,3 +4,4 @@ export * from "./array"; export * from "./mirror"; export * from "./move"; export * from "./rotate"; +export * from "./split"; diff --git a/packages/chili/src/commands/modify/split.ts b/packages/chili/src/commands/modify/split.ts new file mode 100644 index 00000000..0143fd0d --- /dev/null +++ b/packages/chili/src/commands/modify/split.ts @@ -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), + ]; + } +} diff --git a/public/iconfont.js b/public/iconfont.js index 23eb0304..91595985 100644 --- a/public/iconfont.js +++ b/public/iconfont.js @@ -1 +1 @@ -window._iconfont_svg_string_3585225='',function(v){var h=(h=document.getElementsByTagName("script"))[h.length-1],l=h.getAttribute("data-injectcss"),h=h.getAttribute("data-disable-injectsvg");if(!h){var z,a,m,t,i,c=function(h,l){l.parentNode.insertBefore(h,l)};if(l&&!v.__iconfont__svg__cssinject__){v.__iconfont__svg__cssinject__=!0;try{document.write("")}catch(h){console&&console.log(h)}}z=function(){var h,l=document.createElement("div");l.innerHTML=v._iconfont_svg_string_3585225,(l=l.getElementsByTagName("svg")[0])&&(l.setAttribute("aria-hidden","true"),l.style.position="absolute",l.style.width=0,l.style.height=0,l.style.overflow="hidden",l=l,(h=document.body).firstChild?c(l,h.firstChild):h.appendChild(l))},document.addEventListener?~["complete","loaded","interactive"].indexOf(document.readyState)?setTimeout(z,0):(a=function(){document.removeEventListener("DOMContentLoaded",a,!1),z()},document.addEventListener("DOMContentLoaded",a,!1)):document.attachEvent&&(m=z,t=v.document,i=!1,p(),t.onreadystatechange=function(){"complete"==t.readyState&&(t.onreadystatechange=null,o())})}function o(){i||(i=!0,m())}function p(){try{t.documentElement.doScroll("left")}catch(h){return void setTimeout(p,50)}o()}}(window); \ No newline at end of file +window._iconfont_svg_string_3585225='',function(v){var h=(h=document.getElementsByTagName("script"))[h.length-1],l=h.getAttribute("data-injectcss"),h=h.getAttribute("data-disable-injectsvg");if(!h){var z,a,t,m,i,c=function(h,l){l.parentNode.insertBefore(h,l)};if(l&&!v.__iconfont__svg__cssinject__){v.__iconfont__svg__cssinject__=!0;try{document.write("")}catch(h){console&&console.log(h)}}z=function(){var h,l=document.createElement("div");l.innerHTML=v._iconfont_svg_string_3585225,(l=l.getElementsByTagName("svg")[0])&&(l.setAttribute("aria-hidden","true"),l.style.position="absolute",l.style.width=0,l.style.height=0,l.style.overflow="hidden",l=l,(h=document.body).firstChild?c(l,h.firstChild):h.appendChild(l))},document.addEventListener?~["complete","loaded","interactive"].indexOf(document.readyState)?setTimeout(z,0):(a=function(){document.removeEventListener("DOMContentLoaded",a,!1),z()},document.addEventListener("DOMContentLoaded",a,!1)):document.attachEvent&&(t=z,m=v.document,i=!1,p(),m.onreadystatechange=function(){"complete"==m.readyState&&(m.onreadystatechange=null,o())})}function o(){i||(i=!0,t())}function p(){try{m.documentElement.doScroll("left")}catch(h){return void setTimeout(p,50)}o()}}(window); \ No newline at end of file