mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-16 05:23:19 +01:00
fix fillet
This commit is contained in:
parent
34b2733807
commit
91ff0fbc8a
7 changed files with 61 additions and 77 deletions
|
|
@ -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")]
|
||||
}; },
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 + "";
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -77,4 +77,8 @@ export class MBrepShell extends MShell {
|
|||
}
|
||||
}
|
||||
|
||||
get topology(): TopoObject {
|
||||
return this.brepShell;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue