From a5de7d85abad2ba78c3048565db5fac3de98a074 Mon Sep 17 00:00:00 2001 From: Mike Molinari Date: Mon, 21 Feb 2022 02:02:43 +0000 Subject: [PATCH] Updated primitive cylinder to be created with the new widget toolkit --- .../features/primitive_cylinder/index.ts | 122 +++++++++--------- 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/modules/workbenches/modeler/features/primitive_cylinder/index.ts b/modules/workbenches/modeler/features/primitive_cylinder/index.ts index 368b273a..875ff745 100644 --- a/modules/workbenches/modeler/features/primitive_cylinder/index.ts +++ b/modules/workbenches/modeler/features/primitive_cylinder/index.ts @@ -1,64 +1,70 @@ import { ApplicationContext } from 'context'; -import { MBrepShell } from 'cad/model/mshell'; import { roundValueForPresentation as r } from 'cad/craft/operationHelper'; -import { occ2brep } from 'cad/occ/occ2models'; -import icon32 from './icon32.png'; -import icon96 from './icon96.png'; - -export default { - id: 'primitive_cylinder', - label: 'primitive_cylinder', - icon: { - iconSet: { - medium: { - iconType: 'image', - iconContent: icon32 - }, - large: { - iconType: 'image', - iconContent: icon96 - } - }, - }, - info: 'primitive_cylinder', - mutualExclusiveFields: [], - paramsInfo: ({ diameter, height }) => `(${r(diameter)} ${r(height)})`, - run: ({ diameter, height, }, ctx: ApplicationContext) => { - //const occObj = createCylinder(diameter, height, ctx.occService.occContext); - const oc = ctx.occService.occContext; - - const myLocation = new oc.gp_Pnt_3(0, 0, 0); - const cylinderCenterline = oc.gp.DZ(); - const cylinderOrientationAndLocation = new oc.gp_Ax2_3(myLocation, cylinderCenterline); +import { EntityKind } from "cad/model/entities"; +import { BooleanDefinition } from "cad/craft/schema/common/BooleanDefinition"; +import { OperationDescriptor } from "cad/craft/operationPlugin"; - let myBody = new oc.BRepPrimAPI_MakeCylinder_3(cylinderOrientationAndLocation, diameter, height,); - //let myBody = new oc.BRepPrimAPI_Make - - const aRes = new oc.TopoDS_Compound(); - const aBuilder = new oc.BRep_Builder(); - aBuilder.MakeCompound(aRes); - aBuilder.Add(aRes, myBody.Shape()); - - - - const mobject = new MBrepShell(occ2brep(aRes, ctx.occService.occContext)); - return { - consumed: [], - created: [mobject] - }; - }, - schema: { - diameter: { - type: 'number', - defaultValue: 200, - label: 'diameter' - }, - height: { - type: 'number', - defaultValue: 280, - label: 'height' - }, - } +interface PrimitiveCylinderParams { + diameter: number, + height: number, + locations: {}, + boolean: BooleanDefinition, } +const PrimitiveCylinderOperation: OperationDescriptor = { + id: 'primitive_cylinder', + label: 'Primitive cylinder', + icon: 'img/cad/cylinder', + info: 'Primitive Box', + paramsInfo: ({ height, diameter}) => `(${r(height)} , ${r(diameter)} )`, + form: [ + { + type: 'number', + label: 'Diameter', + name: 'diameter', + defaultValue: 50, + }, + { + type: 'number', + label: 'Height', + name: 'height', + defaultValue: 50, + }, + { + type: 'selection', + name: 'locations', + capture: [EntityKind.DATUM], + label: 'locations', + multi: false, + optional: true, + defaultValue: { + usePreselection: true, + preselectionIndex: 0 + }, + }, + + { + type: 'boolean', + name: 'boolean', + label: 'boolean', + optional: true, + } + + ], + + + run: (params: PrimitiveCylinderParams, ctx: ApplicationContext) => { + + let occ = ctx.occService; + const oci = occ.commandInterface; + + //pcylinder cy 5 10 + oci.pcylinder("cy", params.diameter/2, params.height); + + return occ.utils.applyBooleanModifier(["cy"], params.boolean); + + }, +} + +export default PrimitiveCylinderOperation; \ No newline at end of file