From 9250ccf55a5eebab5c6b97b8efcfb40cdee6a698 Mon Sep 17 00:00:00 2001 From: Mike Molinari Date: Sat, 4 Feb 2023 06:58:48 +0000 Subject: [PATCH] Add simplify body feature. --- .../modeler/features/simplify/SIMPLIFY.svg | 106 ++++++++++++++++++ .../modeler/features/simplify/docs/index.md | 7 ++ .../features/simplify/simplify.operation.ts | 58 ++++++++++ modules/workbenches/modeler/index.ts | 4 +- 4 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 modules/workbenches/modeler/features/simplify/SIMPLIFY.svg create mode 100644 modules/workbenches/modeler/features/simplify/docs/index.md create mode 100644 modules/workbenches/modeler/features/simplify/simplify.operation.ts diff --git a/modules/workbenches/modeler/features/simplify/SIMPLIFY.svg b/modules/workbenches/modeler/features/simplify/SIMPLIFY.svg new file mode 100644 index 00000000..096be670 --- /dev/null +++ b/modules/workbenches/modeler/features/simplify/SIMPLIFY.svg @@ -0,0 +1,106 @@ + diff --git a/modules/workbenches/modeler/features/simplify/docs/index.md b/modules/workbenches/modeler/features/simplify/docs/index.md new file mode 100644 index 00000000..d606129a --- /dev/null +++ b/modules/workbenches/modeler/features/simplify/docs/index.md @@ -0,0 +1,7 @@ +# Simplify shape +Simplify shape cleans up geometry and unifies adjacent coplanar faces. +Un-needed edges internal to a face are eliminated. +Connected edges with continuity are merged. + +Useful for cleaning up tricky geometry that has been imported or the result of difficult boolean operations. + diff --git a/modules/workbenches/modeler/features/simplify/simplify.operation.ts b/modules/workbenches/modeler/features/simplify/simplify.operation.ts new file mode 100644 index 00000000..f43141f6 --- /dev/null +++ b/modules/workbenches/modeler/features/simplify/simplify.operation.ts @@ -0,0 +1,58 @@ +import {roundValueForPresentation as r} from 'cad/craft/operationHelper'; +import {ApplicationContext} from "cad/context"; +import {EntityKind} from "cad/model/entities"; +import {OperationDescriptor} from "cad/craft/operationBundle"; +import icon from "./SIMPLIFY.svg"; +import { MShell } from 'cad/model/mshell'; +import {FromMObjectProductionAnalyzer} from "cad/craft/production/productionAnalyzer"; + +interface SimplifyParams { + tools: MShell[]; +} + +export const SimplifyOperation: OperationDescriptor = { + id: 'SIMPLIFY', + label: 'Simplify', + icon, + info: 'Simplify faces', + path:__dirname, + paramsInfo: ({tools, Simplify}) => `(${r(tools)} ${r(Simplify)})`, + run: (params: SimplifyParams, ctx: ApplicationContext) => { + const occ = ctx.occService; + const oci = occ.commandInterface; + + let created = []; + let consumed = []; + + + params.tools.forEach((bodyToSimplify) => { + const analyzer = new FromMObjectProductionAnalyzer([bodyToSimplify]); + oci.fixshape("SimplifiedShell", bodyToSimplify); + oci.unifysamedom("SimplifiedShell", "SimplifiedShell"); + + created.push(occ.io.getShell("SimplifiedShell", analyzer)); + consumed.push(bodyToSimplify) + }); + + + return { + created, + consumed + }; + + }, + form: [ + { + type: 'selection', + name: 'tools', + capture: [EntityKind.SHELL], + label: 'Body', + optional: false, + multi: true, + defaultValue: { + usePreselection: true, + preselectionIndex: 0 + }, + }, + ], +} diff --git a/modules/workbenches/modeler/index.ts b/modules/workbenches/modeler/index.ts index 6b0f0d56..71382bfa 100644 --- a/modules/workbenches/modeler/index.ts +++ b/modules/workbenches/modeler/index.ts @@ -11,6 +11,7 @@ import {PrimitiveTorusOperation} from "./features/primitiveTorus/PrimitiveTorus. import {HoleOperation} from "./features/hole/Hole.operation"; import {FilletOperation} from "./features/fillet/fillet.operation"; import {BooleanOperation} from "./features/boolean/boolean.operation"; +import {SimplifyOperation} from "./features/simplify/simplify.operation"; import {RevolveOperation} from "./features/revolve/revolve.operation"; import {ShellOperation} from "./features/shell/shell.operation"; import {SweepOperation} from "./features/sweep/sweep.operation"; @@ -56,6 +57,7 @@ export const ModelerWorkspace: WorkbenchConfig = { DefeatureRemoveFaceOperation, WireLineOperation, MoveBodyOperation, + SimplifyOperation, GetInfo, ExportBREP, @@ -69,7 +71,7 @@ export const ModelerWorkspace: WorkbenchConfig = { ["EXTRUDE", "CUT", "REVOLVE", "LOFT", "SWEEP"], - ["UNION", "SUBTRACT", "INTERSECT"], + ["UNION", "SUBTRACT", "INTERSECT", "SIMPLIFY"], ["SHELL_TOOL", "FILLET_TOOL", "SCALE_BODY", "DEFEATURE_REMOVE_FACE"],