diff --git a/modules/workbenches/modeler/features/fillet_tool/index.ts b/modules/workbenches/modeler/features/fillet_tool/index.ts index 06a9c6a3..f81effa9 100644 --- a/modules/workbenches/modeler/features/fillet_tool/index.ts +++ b/modules/workbenches/modeler/features/fillet_tool/index.ts @@ -4,6 +4,7 @@ import { roundValueForPresentation as r } from 'cad/craft/operationHelper'; import { occ2brep } from 'cad/occ/occ2models'; import icon32 from './icon32.png'; import icon96 from './icon96.png'; +import {EntityKind} from "cad/model/entities"; export default { id: 'fillet_tool', @@ -22,93 +23,45 @@ export default { }, info: 'fillet_tool', mutualExclusiveFields: [], - paramsInfo: ({ sizeA, }) => `(${r(sizeA)} })`, - schema: { - edgeOperationType: { - type: 'string', - defaultValue: "FILLET", - label: 'Operation Type', - enum: [ - { - label: "Fillet", - value: "FILLET" - }, - { - label: "Champher", - value: "CHAMPHER" - }, - { - label: "2 Sided Champher", - value: "TWO_SIDED_CHAMPHER" - } - ], - }, - - edgeSelection: { + paramsInfo: ({ size, }) => `(${r(size)} })`, + form: [ + { type: 'number', - defaultValue: 280, - label: 'Edge Selection' + label: 'size', + name: 'size', + defaultValue: 5, + }, + { + type: 'selection', + name: 'edges', + capture: [EntityKind.EDGE], + label: 'edges', + multi: false, + defaultValue: { + usePreselection: true, + preselectionIndex: 0 + }, }, - sizeA: { - type: 'number', - defaultValue: 10, - label: 'radius' - }, - }, + ], - run: ({ edgeOperationType, edgeSelection, sizeA, }, ctx: ApplicationContext) => { - const oc = ctx.occService.occContext; + run: (params, ctx: ApplicationContext) => { - let myBody = new oc.BRepPrimAPI_MakeBox_1(200, 200, 200); - - //collection of edges to modify - let edgesToModify = []; - - - const anEdgeExplorer = new oc.TopExp_Explorer_2(myBody.Shape(), oc.TopAbs_ShapeEnum.TopAbs_EDGE, oc.TopAbs_ShapeEnum.TopAbs_SHAPE); - var anEdge = oc.TopoDS.Edge_1(anEdgeExplorer.Current()); - edgesToModify.push(anEdge); - - anEdgeExplorer.Next() - anEdge = oc.TopoDS.Edge_1(anEdgeExplorer.Current()); - edgesToModify.push(anEdge); - - - if (edgeOperationType.toUpperCase() == "FILLET") { - const mkFillet = new oc.BRepFilletAPI_MakeFillet(myBody.Shape(), oc.ChFi3d_FilletShape.ChFi3d_Rational); - - // Add edge to fillet - edgesToModify.forEach(async function (edgeToAdd) { - mkFillet.Add_2(sizeA, edgeToAdd); - }); - myBody = mkFillet; - - } else if (edgeOperationType.toUpperCase() == "CHAMPHER") { - const mkChampher = new oc.BRepFilletAPI_MakeChamfer(myBody.Shape()); - - // Add edge to champher - edgesToModify.forEach(async function (edgeToAdd) { - mkChampher.Add_2(sizeA, edgeToAdd); - }); - myBody = mkChampher; - } + let occ = ctx.occService; + const oci = occ.commandInterface; + // ctx.occService.io.pushModel(params.edges.shell, "bodyToBeFillet"); + // + // ctx.occService.io.pushModel(params.edges, "edgeToFillet"); - const aRes = new oc.TopoDS_Compound(); - const aBuilder = new oc.BRep_Builder(); - aBuilder.MakeCompound(aRes); - aBuilder.Add(aRes, myBody.Shape()); + oci.blend("b", params.edges.shell, params.size, params.edges); - - const mobject = new MBrepShell(occ2brep(aRes, ctx.occService.occContext)); return { - consumed: [], - created: [mobject] - }; - }, + consumed: [params.edges.shell], + created: [occ.io.getShell("b")] + }; }, } diff --git a/web/app/cad/craft/e0/occCommandInterface.ts b/web/app/cad/craft/e0/occCommandInterface.ts index c99e3e97..e5e67c32 100644 --- a/web/app/cad/craft/e0/occCommandInterface.ts +++ b/web/app/cad/craft/e0/occCommandInterface.ts @@ -1,7 +1,10 @@ import {CallCommand} from "cad/craft/e0/interact"; +import {MObject} from "cad/model/mobject"; export type OCCCommandInterface = OCCCommands; +const pushedModels = new Set(); + export const OCI: OCCCommandInterface = new Proxy({}, { get: function (target, prop: string, receiver) { return prop in target ? target[prop] : function() { @@ -9,6 +12,13 @@ export const OCI: OCCCommandInterface = new Proxy({}, { const args = Array.from(arguments).map(arg => { const type = typeof arg; if (type === 'object') { + if (arg instanceof MObject) { + if (!pushedModels.has(arg.id)) { + pushedModels.add(arg.id) + __CAD_APP.occService.io.pushModel(arg, arg.id); + } + return arg.id; + } return JSON.stringify(arg); } else { return arg + ""; diff --git a/web/app/cad/craft/e0/occIO.ts b/web/app/cad/craft/e0/occIO.ts index 961921a4..74731764 100644 --- a/web/app/cad/craft/e0/occIO.ts +++ b/web/app/cad/craft/e0/occIO.ts @@ -25,7 +25,7 @@ export function createOCCIO(ctx: CoreContext): OCCIO { } function pushModel(model: MObject, name: string) { - const ptr = model.brepShell?.data?.externals?.ptr; + const ptr = model.topology?.data?.externals?.ptr; if (!ptr) { return false; } diff --git a/web/app/cad/model/medge.ts b/web/app/cad/model/medge.ts index e27c2891..ff787e4d 100644 --- a/web/app/cad/model/medge.ts +++ b/web/app/cad/model/medge.ts @@ -3,6 +3,7 @@ import {MBrepShell} from "./mshell"; import {EntityKind} from "cad/model/entities"; import {Edge} from "brep/topo/edge"; import Vector from "math/vector"; +import {TopoObject} from "brep/topo/topo-object"; export class MEdge extends MObject { @@ -41,4 +42,8 @@ export class MEdge extends MObject { return this.brepEdge.halfEdge1.tangentAtStart(); }; + get topology(): TopoObject { + return this.brepEdge; + } + } \ No newline at end of file diff --git a/web/app/cad/model/mface.ts b/web/app/cad/model/mface.ts index 3b5d85c0..d361e2e3 100644 --- a/web/app/cad/model/mface.ts +++ b/web/app/cad/model/mface.ts @@ -11,6 +11,7 @@ import {Basis, BasisForPlane} from "math/basis"; import {Face} from "brep/topo/face"; import {EntityKind} from "cad/model/entities"; import {Matrix3x4} from "math/matrix"; +import {TopoObject} from "brep/topo/topo-object"; export class MFace extends MObject { @@ -177,6 +178,11 @@ export class MFace extends MObject { get favorablePoint() { return this.csys.origin; } + + get topology(): TopoObject { + return this.brepFace; + } + } export class MBrepFace extends MFace { diff --git a/web/app/cad/model/mobject.ts b/web/app/cad/model/mobject.ts index ee115ce8..e43eb190 100644 --- a/web/app/cad/model/mobject.ts +++ b/web/app/cad/model/mobject.ts @@ -1,6 +1,7 @@ import {IDENTITY_MATRIX, Matrix3x4} from "math/matrix"; import {EntityKind} from "cad/model/entities"; import Vector from "math/vector"; +import {TopoObject} from "brep/topo/topo-object"; export abstract class MObject { @@ -35,6 +36,11 @@ export abstract class MObject { get location() { return IDENTITY_MATRIX; } + + get topology(): TopoObject { + return null; + } + } export const MObjectIdGenerator = { diff --git a/web/app/cad/model/mshell.ts b/web/app/cad/model/mshell.ts index 38f2f86c..6a9530d0 100644 --- a/web/app/cad/model/mshell.ts +++ b/web/app/cad/model/mshell.ts @@ -77,4 +77,8 @@ export class MBrepShell extends MShell { } } + get topology(): TopoObject { + return this.brepShell; + } + }