From a2acb1ec00be243a6755dc3490cec0942924dfba Mon Sep 17 00:00:00 2001 From: Mike Molinari Date: Thu, 17 Feb 2022 00:34:05 +0000 Subject: [PATCH] added multi face/multi body shell opperation. --- .../features/shell_tool/shell.operation.ts | 84 +++++++++++++++++++ modules/workbenches/modeler/index.ts | 2 + web/app/cad/part/uiConfigPlugin.js | 2 +- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 modules/workbenches/modeler/features/shell_tool/shell.operation.ts diff --git a/modules/workbenches/modeler/features/shell_tool/shell.operation.ts b/modules/workbenches/modeler/features/shell_tool/shell.operation.ts new file mode 100644 index 00000000..2cb6abc9 --- /dev/null +++ b/modules/workbenches/modeler/features/shell_tool/shell.operation.ts @@ -0,0 +1,84 @@ +import { roundValueForPresentation as r } from 'cad/craft/operationHelper'; +import { MFace } from "cad/model/mface"; +import { ApplicationContext } from "context"; +import { MDFCommand } from "cad/mdf/mdf"; +import { EntityKind } from "cad/model/entities"; + + +interface ShellParams { + thickness: number; + faces: [MFace]; +} + +const ShellOperation: MDFCommand = { + id: 'shell_tool', + label: 'Shell', + icon: 'img/cad/Shell', + info: 'Shells 2D sketch', + paramsInfo: ({ thickness }) => `(${r(thickness)})`, + run: (params: ShellParams, ctx: ApplicationContext) => { + console.log(params); + let occ = ctx.occService; + const oci = occ.commandInterface; + + + + + + var bodiesToShell = []; + var returnObject = { + consumed: [], + created: [] + }; + + //add all the edges and size to seperate arrays for each shell that edges are selected from + + params.faces.forEach((face) => { + if (!returnObject.consumed.includes(face.shell)) { + returnObject.consumed.push(face.shell); + bodiesToShell[face.shell.id] = []; + } + bodiesToShell[face.shell.id].push(face); + + }); + + //perform the opperations on each of the bodies. + Object.keys(bodiesToShell).forEach((shellToOpperateOnName) => { + var shellToOpperateOn = bodiesToShell[shellToOpperateOnName]; + var newShellName = shellToOpperateOnName + "f"; + + console.log(shellToOpperateOn); + + var bodyToPerformShellOpperationOn = shellToOpperateOn[0].shell; + oci.offsetshape(newShellName, bodyToPerformShellOpperationOn , params.thickness, "1.e-3", ...shellToOpperateOn) + + returnObject.created.push(occ.io.getShell(newShellName)); + }); + + console.log(returnObject); + + return returnObject; + + }, + form: [ + { + type: 'number', + name: 'thickness', + label: 'thickness', + defaultValue: 5, + }, + { + type: 'selection', + name: 'faces', + capture: [EntityKind.FACE], + label: 'faces', + multi: true, + defaultValue: { + usePreselection: true, + preselectionIndex: 0 + }, + }, + ], +} + +export default ShellOperation; \ No newline at end of file diff --git a/modules/workbenches/modeler/index.ts b/modules/workbenches/modeler/index.ts index f5b0c22e..e23e0381 100644 --- a/modules/workbenches/modeler/index.ts +++ b/modules/workbenches/modeler/index.ts @@ -8,6 +8,7 @@ import primitive_torus from './features/primitive_torus'; import hole_tool from './features/hole_tool'; import fillet_tool from './features/fillet_tool'; import boolean_tool from './features/boolean_tool/boolean.operation'; +import ShellOperation from './features/shell_tool/shell.operation'; export default { @@ -23,5 +24,6 @@ export default { fillet_tool, RevolveOperation, boolean_tool, + ShellOperation, ] } \ No newline at end of file diff --git a/web/app/cad/part/uiConfigPlugin.js b/web/app/cad/part/uiConfigPlugin.js index 56fed76a..56f2ee12 100644 --- a/web/app/cad/part/uiConfigPlugin.js +++ b/web/app/cad/part/uiConfigPlugin.js @@ -11,7 +11,7 @@ import {SelectionView} from "../dom/components/SelectionView"; import {GrSelect} from "react-icons/gr"; export const STANDARD_MODE_HEADS_UP_TOOLBAR = ['DATUM_CREATE', 'PLANE', 'EditFace', '-', "OCC_BOTTLE", '-', - "EXTRUDE", "Revolve", "-", "boolean_tool", + "EXTRUDE", "Revolve", "-", "boolean_tool", "shell_tool", "primitive_cylinder", "primitive_box", "primitive_cone", "primitive_sphere", "primitive_torus", "hole_tool", "fillet_tool"];