diff --git a/modules/workbenches/modeler/features/boolean_tool/boolean.operation.ts b/modules/workbenches/modeler/features/boolean_tool/boolean.operation.ts new file mode 100644 index 00000000..9d9ee51e --- /dev/null +++ b/modules/workbenches/modeler/features/boolean_tool/boolean.operation.ts @@ -0,0 +1,53 @@ +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"; +import Vector from "math/vector"; +import { BooleanDefinition } from "cad/craft/schema/common/BooleanDefinition"; +import { MShell } from 'cad/model/mshell'; + +interface BooleanParams { + tools: []; + boolean: BooleanDefinition +} + +const BooleanOperation: MDFCommand = { + id: 'boolean_tool', + label: 'Boolean', + icon: 'img/cad/Boolean', + info: 'Booleans 2D sketch', + paramsInfo: ({ tools, boolean }) => `(${r(tools)} ${r(boolean)})`, + run: (params: BooleanParams, ctx: ApplicationContext) => { + console.log(params); + let occ = ctx.occService; + const oci = occ.commandInterface; + + console.log(params.tools, params.boolean); + + return occ.utils.applyBooleanModifier(params.tools, params.boolean); + + }, + form: [ + { + type: 'boolean', + name: 'boolean', + label: 'Targets', + optional: true, + defaultValue: 'UNION' + }, + { + type: 'selection', + name: 'tools', + capture: [EntityKind.SHELL], + label: 'Tools', + multi: true, + defaultValue: { + usePreselection: true, + preselectionIndex: 0 + }, + }, + ], +} + +export default BooleanOperation; \ No newline at end of file diff --git a/modules/workbenches/modeler/features/revolve_tool/revolve.operation.ts b/modules/workbenches/modeler/features/revolve_tool/revolve.operation.ts new file mode 100644 index 00000000..fd90d325 --- /dev/null +++ b/modules/workbenches/modeler/features/revolve_tool/revolve.operation.ts @@ -0,0 +1,94 @@ +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"; +import Vector from "math/vector"; +import { BooleanDefinition } from "cad/craft/schema/common/BooleanDefinition"; + +interface RevolveParams { + angle: number; + face: MFace; + direction?: Vector, + boolean: BooleanDefinition +} + +const RevolveOperation: MDFCommand = { + id: 'Revolve', + label: 'Revolve', + icon: 'img/cad/Revolve', + info: 'Revolves 2D sketch', + paramsInfo: ({ angle }) => `(${r(angle)})`, + mutualExclusiveFields: ['datumAxisVector', 'edgeVector', 'sketchSegmentVector'], + run: (params: RevolveParams, ctx: ApplicationContext) => { + console.log(params); + let occ = ctx.occService; + const oci = occ.commandInterface; + + const face = params.face; + + 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 = params.direction.normalize().data(); + + const point = params.direction; + console.log(params.direction); + + console.log(dir); + + const tools = occFaces.map((faceName, i) => { + const shapeName = "Tool/" + i; + var args = [shapeName, faceName, point.x, point.y, point.z, ...dir, params.angle]; + oci.revol(...args); + + return shapeName; + }); + + + + + + + + + return occ.utils.applyBooleanModifier(tools, params.boolean); + + }, + form: [ + { + type: 'number', + label: 'angle', + name: 'angle', + defaultValue: 360, + }, + { + type: 'selection', + name: 'face', + capture: [EntityKind.FACE], + label: 'face', + multi: false, + defaultValue: { + usePreselection: true, + preselectionIndex: 0 + }, + }, + { + type: 'vector', + name: 'direction', + label: 'direction', + optional: true + }, + { + type: 'boolean', + name: 'boolean', + label: 'boolean', + optional: true, + defaultValue: 'NONE' + } + + ], +} + +export default RevolveOperation; \ No newline at end of file diff --git a/modules/workbenches/modeler/index.ts b/modules/workbenches/modeler/index.ts index e4fafc40..f5b0c22e 100644 --- a/modules/workbenches/modeler/index.ts +++ b/modules/workbenches/modeler/index.ts @@ -1,4 +1,5 @@ import EXTRUDE from './features/extrude/extrude.operation'; +import RevolveOperation from './features/revolve_tool/revolve.operation'; import primitive_box from './features/primitive_box'; import primitive_cone from './features/primitive_cone'; import primitive_cylinder from './features/primitive_cylinder'; @@ -6,6 +7,7 @@ import primitive_sphere from './features/primitive_sphere'; 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'; export default { @@ -19,5 +21,7 @@ export default { primitive_torus, hole_tool, fillet_tool, + RevolveOperation, + boolean_tool, ] } \ No newline at end of file diff --git a/snipets for modeling api.js b/snipets for modeling api.js new file mode 100644 index 00000000..d310fd77 --- /dev/null +++ b/snipets for modeling api.js @@ -0,0 +1,165 @@ +//Make a pipe------------------------------------------------------------------------------------------------------ +const ctx = __CAD_APP; +const { commandInterface: oci, io } = ctx.occService; +oci.beziercurve("spine", "4", + "0", "0", "0", + "10", "0", "0", + "10", "10", "0", + "40", "10", "0", + "80", "60", "60" +); +oci.mkedge("spine", "spine"); +oci.wire("spine", "spine"); +oci.circle("profile", "0", "0", "0", "1", "0", "0", "2"); +oci.mkedge("profile", "profile"); +oci.wire("profile", "profile"); +oci.mkplane("profile", "profile"); +oci.pipe("p", "spine", "profile"); + +ctx.services.exposure.addOnScene(io.getShell("p")); + + + + +//Doing a sweep --------------------------------------------------------------------------------------------------- +const ctx = __CAD_APP; +const { commandInterface: oci, io } = ctx.occService; + +oci.beziercurve("p", "4", + "0", "0", "0", + "10", "0", "0", + "20", "10", "0", + "20", "10", "0"); +oci.mkedge("p", "p"); +oci.wire("p", "p"); + +//oci.circle("c","0","0","0","1","0","0","0.2") +oci.polyline("c", + "0", "0", "0", + "0", "0", "1", + "0", "2", "2", + "0", "1", "0", + "0", "0", "0"); + +oci.wire("w", "c"); + + +//dose not seem to work if I convert the profile in to a plane. +//Need to figure this out to get a body and not just surfaces. +//oci.mkplane("w", "w") + +oci.mksweep("p"); + +oci.addsweep("w"); + +oci.buildsweep("r", "-S"); +ctx.services.exposure.addOnScene(io.getShell("r")); + + + +//Revolve ------------------------------------------------------------------------------------------------------ +const ctx = __CAD_APP; +const { commandInterface: oci, io } = ctx.occService; + + +oci.polyline("p", "0", "0", "0", "1", "0", "0", "1", "2", "0", "0", "1", "0", "0", "0", "0"); +oci.mkplane("p", "p"); //make the input in to a face first so that we get capped ends +oci.revol("r", "p", "3", "0", "0", "0", "1", "0", "280"); + + +ctx.services.exposure.addOnScene(io.getShell("r")); + + + + +//fillet ------------------------------------------------------------------------------------------------------- +const ctx = __CAD_APP; +const { commandInterface: oci, io } = ctx.occService; + +oci.box("b", "20", "20", "20"); +oci.explode("b", "e"); +oci.blend("b", "b", "5", "b_2"); + + + +ctx.services.exposure.addOnScene(io.getShell("b")); + +//champher ---------------------------------------------------------------------------------------------------- +const ctx = __CAD_APP; +const { commandInterface: oci, io } = ctx.occService; + +oci.box("b", "1", "2", "3"); +oci.explode("b", "e"); +var bla = ["ch", "b", "b_1", "0.2", "b_2", "0.2"]; +oci.chamf.call(bla); + +ctx.services.exposure.addOnScene(io.getShell("ch")); + + +//shell ------------------------------------------------------------------------------------------------------- +const ctx = __CAD_APP; +const { commandInterface: oci, io } = ctx.occService; + +oci.box("b", "10", "20", "30"); + +oci.explode("b", "f") +oci.offsetshape("body", "b", "-1", "1.e-3", "b_2", "b_3") + +ctx.services.exposure.addOnScene(io.getShell("body")); + + + + +//loft -------------------------------------------------------------------------------------------------------- +const ctx = __CAD_APP; +const { commandInterface: oci, io } = ctx.occService; + +oci.polyline("w1", + "0", "0", "0", + "5", "0", "0", + "5", "5", "0", + "2", "3", "0", + "0", "0", "0", +); +oci.polyline("w2", + "0", "1", "3", + "4", "1", "3", + "4", "4", "3", + "1", "3", "3", + "0", "1", "3", +); +oci.polyline("w3", + "0", "0", "5", + "5", "0", "5", + "5", "5", "5", + "2", "3", "5", + "0", "0", "5", +); +//# create the shape + + +oci.thrusections("th", "issolid", "isruled", "w1", "w2", "w3"); + + +ctx.services.exposure.addOnScene(io.getShell("th")); + + + + + +//Boolean operations --------------------------------------------------------------------- + +const ctx = __CAD_APP; +const { commandInterface: oci, io } = ctx.occService; + +oci.box("b1", "10", "10", "10"); +oci.psphere("sp", "5"); + + + +oci.bop("b1", "sp"); +oci.bopcommon("result"); +//oci.bopfuse("result"); +//oci.bopcut("result"); + +ctx.services.exposure.addOnScene(io.getShell("result")); \ No newline at end of file diff --git a/web/app/cad/part/uiConfigPlugin.js b/web/app/cad/part/uiConfigPlugin.js index d6b4f2a2..56fed76a 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", "-", + "EXTRUDE", "Revolve", "-", "boolean_tool", "primitive_cylinder", "primitive_box", "primitive_cone", "primitive_sphere", "primitive_torus", "hole_tool", "fillet_tool"];