From 12f4d5761e89e4b291effebcb28967e3d53d4d7f Mon Sep 17 00:00:00 2001 From: Mike Molinari Date: Sat, 26 Feb 2022 03:43:21 +0000 Subject: [PATCH] Added fully working mirror body and added start of sheet metal commands in inwork state --- .../mirrorBody/mirrorBody.operation.ts | 66 +++++++++++ .../features/smFlange/smFlange.operation.ts | 89 +++++++++++++++ .../modeler/features/smTab/smTab.operation.ts | 106 ++++++++++++++++++ modules/workbenches/modeler/index.ts | 13 ++- modules/workbenches/registry.ts | 2 +- web/img/cad/smFlange96.png | Bin 0 -> 604 bytes web/img/cad/smTab96.png | Bin 0 -> 431 bytes 7 files changed, 272 insertions(+), 4 deletions(-) create mode 100644 modules/workbenches/modeler/features/mirrorBody/mirrorBody.operation.ts create mode 100644 modules/workbenches/modeler/features/smFlange/smFlange.operation.ts create mode 100644 modules/workbenches/modeler/features/smTab/smTab.operation.ts create mode 100644 web/img/cad/smFlange96.png create mode 100644 web/img/cad/smTab96.png diff --git a/modules/workbenches/modeler/features/mirrorBody/mirrorBody.operation.ts b/modules/workbenches/modeler/features/mirrorBody/mirrorBody.operation.ts new file mode 100644 index 00000000..e7eaad61 --- /dev/null +++ b/modules/workbenches/modeler/features/mirrorBody/mirrorBody.operation.ts @@ -0,0 +1,66 @@ +import { roundValueForPresentation as r } from 'cad/craft/operationHelper'; +import { MFace } from "cad/model/mface"; +import { ApplicationContext } from "context"; +import { EntityKind } from "cad/model/entities"; +import Axis from "math/axis"; +import { OperationDescriptor } from "cad/craft/operationPlugin"; +import { MShell } from 'cad/model/mshell'; + +interface MirrorBodyParams { + inputBodies: MShell[]; + face:MFace; +} + +export const MirrorBodyOperation: OperationDescriptor = { + id: 'MIRROR_BODY', + label: 'Mirror Body', + icon: 'img/cad/MirrorBody', + info: 'Mirrors selected body along plane of symytry.', + paramsInfo: ({ }) => `(${r()})`, + run: (params: MirrorBodyParams, ctx: ApplicationContext) => { + console.log(params); + let occ = ctx.occService; + const oci = occ.commandInterface; + + let created =[]; + + params.inputBodies.forEach((shellToMirror) => { + const newShellName = shellToMirror.id + ":mirror"; + oci.copy(shellToMirror, newShellName); + params.face.csys.origin.data(); + oci.tmirror(newShellName, ...params.face.csys.origin.data(), ...params.face.csys.origin.normalize().data()); + created.push(occ.io.getShell(newShellName)); + }); + + return { + created, + consumed: [] + }; + + + }, + form: [ + { + type: 'selection', + name: 'face', + capture: [EntityKind.FACE], + label: 'Mirror Plane', + multi: false, + defaultValue: { + usePreselection: false, + preselectionIndex: 0 + }, + }, + { + type: 'selection', + name: 'inputBodies', + capture: [EntityKind.SHELL], + label: 'Bodies', + multi: true, + defaultValue: { + usePreselection: true, + preselectionIndex: 0 + }, + }, + ], +} diff --git a/modules/workbenches/modeler/features/smFlange/smFlange.operation.ts b/modules/workbenches/modeler/features/smFlange/smFlange.operation.ts new file mode 100644 index 00000000..41556d27 --- /dev/null +++ b/modules/workbenches/modeler/features/smFlange/smFlange.operation.ts @@ -0,0 +1,89 @@ +import { roundValueForPresentation as r } from 'cad/craft/operationHelper'; +import { MFace } from "cad/model/mface"; +import { ApplicationContext } from "context"; +import { EntityKind } from "cad/model/entities"; +import { BooleanDefinition } from "cad/craft/schema/common/BooleanDefinition"; +import Axis from "math/axis"; +import { OperationDescriptor } from "cad/craft/operationPlugin"; + +interface smFlangeParams { + angle: number; + face: MFace; + axis: Axis, + boolean: BooleanDefinition +} + +export const smFlangeOperation: OperationDescriptor = { + id: 'SM_FLANGE', + label: 'Flange', + icon: 'img/cad/smFlange', + info: 'Creates Sheet metal flange', + paramsInfo: ({ angle }) => `(${r(angle)})`, + run: (params: smFlangeParams, ctx: ApplicationContext) => { + console.log(params); + let occ = ctx.occService; + const oci = occ.commandInterface; + + const face = params.face; + + let occFaces = [face]; + + const tools = occFaces.map((faceName, i) => { + const shapeName = "Tool/" + i; + var args = [shapeName, faceName, ...params.axis.origin.data(), ...params.axis.direction.negate().data(), params.angle]; + oci.revol(...args); + + return shapeName; + }); + + + return occ.utils.applyBooleanModifier(tools, params.boolean); + + }, + form: [ + { + type: 'number', + label: 'angle', + name: 'angle', + defaultValue: 90, + }, + { + type: 'selection', + name: 'face', + capture: [EntityKind.FACE], + label: 'face', + multi: false, + defaultValue: { + usePreselection: true, + preselectionIndex: 0 + }, + }, + { + type: 'selection', + name: 'Edge', + capture: [EntityKind.EDGE], + label: 'Edge', + multi: false, + defaultValue: { + usePreselection: true, + preselectionIndex: 0 + }, + }, + + + { + type: 'axis', + name: 'axis', + label: 'axis', + optional: false + }, + { + type: 'boolean', + name: 'boolean', + label: 'boolean', + optional: true, + defaultValue: 'UNION' + } + + ], +} diff --git a/modules/workbenches/modeler/features/smTab/smTab.operation.ts b/modules/workbenches/modeler/features/smTab/smTab.operation.ts new file mode 100644 index 00000000..59bf7a3b --- /dev/null +++ b/modules/workbenches/modeler/features/smTab/smTab.operation.ts @@ -0,0 +1,106 @@ +import { roundValueForPresentation as r } from 'cad/craft/operationHelper'; +import { MFace } from "cad/model/mface"; +import { ApplicationContext } from "context"; +import { EntityKind } from "cad/model/entities"; +import { BooleanDefinition } from "cad/craft/schema/common/BooleanDefinition"; +import { UnitVector } from "math/vector"; +import { OperationDescriptor } from "cad/craft/operationPlugin"; + + +interface smTabParams { + thickness: number; + bendRadius: number; + kFactor: number; + flipper: boolean; + sketch: MFace; + boolean: BooleanDefinition; +} + +export const smTabOperation: OperationDescriptor = { + id: 'SM_TAB', + label: 'SM Tab', + icon: 'img/cad/smTab', + info: 'Create tab from sketch', + paramsInfo: ({ thickness, bendRadius }) => `(${r(thickness)} ${r(bendRadius)} )`, + run: (params: smTabParams, ctx: ApplicationContext) => { + + let occ = ctx.occService; + console.log(ctx.craftService.modifications$.value.history); + const oci = occ.commandInterface; + + const face = params.sketch; + + let sketch = ctx.sketchStorageService.readSketch(face.id); + if (!sketch) throw 'sketch not found for the face ' + face.id; + + const occFaces = occ.utils.sketchToFaces(sketch, face.csys); + + const dir: UnitVector= face.normal(); + + let extrusionVector =[]; + if(params.flipper == true){ + extrusionVector = dir.normalize()._multiply(params.thickness).data(); + }else{ + extrusionVector = dir.normalize()._multiply(params.thickness).negate().data(); + + } + + + const tools = occFaces.map((faceName, i) => { + const shapeName = "Tool/" + i; + const bla = oci.prism(shapeName, faceName, ...extrusionVector); + console.log(bla); + return shapeName; + }); + + + return occ.utils.applyBooleanModifier(tools, params.boolean); + + }, + + + form: [ + { + type: 'number', + label: 'Thickness', + name: 'thickness', + defaultValue: 1, + }, + { + type: 'number', + label: 'Bend Radius', + name: 'bendRadius', + defaultValue: 2, + }, + { + type: 'number', + label: 'K-Factor', + name: 'kFactor', + defaultValue: 0.35, + }, + { + type: 'checkbox', + label: 'flip', + name: 'flipper', + defaultValue: false, + }, + { + type: 'selection', + name: 'sketch', + capture: [EntityKind.FACE], + label: 'Sketch', + multi: false, + defaultValue: { + usePreselection: true, + preselectionIndex: 0 + }, + }, + { + type: 'boolean', + name: 'boolean', + label: 'boolean', + optional: true, + } + + ], +} diff --git a/modules/workbenches/modeler/index.ts b/modules/workbenches/modeler/index.ts index 7d97569d..1ae920e9 100644 --- a/modules/workbenches/modeler/index.ts +++ b/modules/workbenches/modeler/index.ts @@ -12,7 +12,10 @@ import { BooleanOperation } from "./features/boolean/boolean.operation"; import { RevolveOperation } from "./features/revolve/revolve.operation"; import { ShellOperation } from "./features/shell/shell.operation"; import { SweepOperation } from "./features/sweep/sweep.operation"; -import { offsetOperation } from "./features/offsetFace/offsetFace.operation" +import { offsetOperation } from "./features/offsetFace/offsetFace.operation"; +import { smTabOperation } from "./features/smTab/smTab.operation"; +import { smFlangeOperation } from "./features/smFlange/smFlange.operation"; +import { MirrorBodyOperation} from "./features/mirrorBody/mirrorBody.operation"; export const ModelerWorkspace: WorkbenchConfig = { @@ -31,7 +34,10 @@ export const ModelerWorkspace: WorkbenchConfig = { ShellOperation, LoftOperation, SweepOperation, - offsetOperation + offsetOperation, + smTabOperation, + smFlangeOperation, + MirrorBodyOperation ], actions: [], ui: { @@ -39,10 +45,11 @@ export const ModelerWorkspace: WorkbenchConfig = { 'DATUM_CREATE', 'PLANE', 'EditFace', '-', "EXTRUDE", "REVOLVE", "LOFT", "SWEEP", "-", "BOOLEAN", "-", - "SHELL_TOOL", "FILLET_TOOL", "OFFSET_TOOL", "-", + "SHELL_TOOL", "FILLET_TOOL", "OFFSET_TOOL", "MIRROR_BODY", "-", "PRIMITIVE_CYLINDER", "PRIMITIVE_BOX", "PRIMITIVE_CONE", "PRIMITIVE_SPHERE", "PRIMITIVE_TORUS", "-", "HOLE_TOOL", "-", "OCC_BOTTLE", '-', + "SM_TAB","SM_FLANGE" ] } } \ No newline at end of file diff --git a/modules/workbenches/registry.ts b/modules/workbenches/registry.ts index cba179ed..e11ae3e0 100644 --- a/modules/workbenches/registry.ts +++ b/modules/workbenches/registry.ts @@ -2,7 +2,7 @@ import {ModelerWorkspace} from "workbenches/modeler"; import {ExampleWorkspace} from "workbenches/examples"; import {WorkbenchConfig} from "cad/workbench/workbenchService"; + export const WorkbenchRegistry: WorkbenchConfig[] = [ ModelerWorkspace, - // ExampleWorkspace, ] \ No newline at end of file diff --git a/web/img/cad/smFlange96.png b/web/img/cad/smFlange96.png new file mode 100644 index 0000000000000000000000000000000000000000..0ee6289e71f517853e29f69cae1d68e15c3b4020 GIT binary patch literal 604 zcmV-i0;BzjP)TrR3`SwW4I1@2 zJ;E&NK}D)qclKQ(PQekfAm{05PLd@`1BvrzJKLuZ{9;4Wb-3O-dBKN>2Kba?4-jK_ zqi+IJ53>uw9*i*?A5@cPJ6p{aGlta|ri*DV2oEC#y+BxuhKeypqsJJdp{B%IjVKU< zbv46OutuYdH5$XcVwDDZrywgpG}P3v!XHe#vIexdLIc|O6&m-p&LVi%Ofcy&)!cAf zG^r+Oz>lmkOdAb;V*7SkLrt5g(F4`cSdDrR{|z5XHFh|#Q$%B%9qt>^0Oy{m8G9Af zvuD_hMgvyoEWWVT(4+G!jZLMottb0KR%+~5EEiL@(F>f*b~%U|JGh2r4IN_cNTZlF zU?mJSfAFD z4%V9W@SE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