Cleanup and refactor hole tool

This commit is contained in:
Mike Molinari 2021-09-23 03:09:10 +00:00 committed by GitHub
parent 6c96cf1c59
commit 12ebf17588
3 changed files with 82 additions and 180 deletions

View file

@ -10,59 +10,20 @@ export default {
icon,
info: 'hole_tool',
mutualExclusiveFields: [],
paramsInfo: ({ diameter,
depth,
counterBoreDiameter,
counterBoreDepth,
countersinkDiameter,
countersinkAngle,
holeType, }) => `(${r(depth)} ${r(counterBoreDiameter)}) ${r(counterBoreDepth)})`,
run: ({
diameter,
depth,
counterBoreDiameter,
counterBoreDepth,
countersinkDiameter,
countersinkAngle,
holeType,
}, ctx: ApplicationContext) => {
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);
let myBody = new oc.BRepPrimAPI_MakeCylinder_3(cylinderOrientationAndLocation, diameter / 2, depth,);
if (holeType == "counterbore") {
let counterboreItem = new oc.BRepPrimAPI_MakeCylinder_3(cylinderOrientationAndLocation, counterBoreDiameter, counterBoreDepth,);
myBody = new oc.BRepAlgoAPI_Fuse_3(myBody.Shape(), counterboreItem.Shape());
}
if (holeType == "countersink") {
let heightFromDiameterAndAngle = (countersinkDiameter - diameter) / (2 * Math.tan((countersinkAngle / 180 * Math.PI) / 2));
let countersinkItem = new oc.BRepPrimAPI_MakeCone_1(countersinkDiameter / 2, diameter / 2, heightFromDiameterAndAngle);
myBody = new oc.BRepAlgoAPI_Fuse_3(myBody.Shape(), countersinkItem.Shape());
}
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]
};
},
paramsInfo: ({ diameter, depth, counterBoreDiameter, counterBoreDepth, countersinkDiameter, countersinkAngle, holeType, }) => `(${r(depth)} ${r(counterBoreDiameter)}) ${r(counterBoreDepth)})`,
schema: {
holeType: {
type: 'TextField',
defaultValue: "counterbore",
label: 'HoleType',
children: [
"counterbore",
"countersink",
"normal",
],
},
diameter: {
type: 'number',
defaultValue: 10,
@ -75,17 +36,6 @@ export default {
},
holeType: {
type: 'TextField',
defaultValue: "counterbore",
label: 'HoleType',
children: [
"counterbore",
"countersink",
"normal",
],
},
counterBoreDiameter: {
type: 'number',
@ -110,21 +60,54 @@ export default {
defaultValue: 90,
label: '⌵ Angle'
},
}
},
run: ({
diameter,
depth,
counterBoreDiameter,
counterBoreDepth,
countersinkDiameter,
countersinkAngle,
holeType,
}, ctx: ApplicationContext) => {
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);
let myBody = new oc.BRepPrimAPI_MakeCylinder_3(cylinderOrientationAndLocation, diameter / 2, depth,);
if (holeType.toUpperCase() == "counterbore") {
let counterboreItem = new oc.BRepPrimAPI_MakeCylinder_3(cylinderOrientationAndLocation, counterBoreDiameter, counterBoreDepth,);
myBody = new oc.BRepAlgoAPI_Fuse_3(myBody.Shape(), counterboreItem.Shape());
}
if (holeType.toUpperCase() == "countersink") {
let heightFromDiameterAndAngle = (countersinkDiameter - diameter) / (2 * Math.tan((countersinkAngle / 180 * Math.PI) / 2));
let countersinkItem = new oc.BRepPrimAPI_MakeCone_1(countersinkDiameter / 2, diameter / 2, heightFromDiameterAndAngle);
myBody = new oc.BRepAlgoAPI_Fuse_3(myBody.Shape(), countersinkItem.Shape());
}
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]
};
},
}

View file

@ -1,82 +0,0 @@
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 icon from './icon.svg';
export default {
id: 'hole',
label: 'hole',
icon,
info: 'hole',
mutualExclusiveFields: [],
paramsInfo: ({ diameter, depth, counterBoreDiameter, counterBoreDepth, countersinkDiameter, countersinkAngle,}) => `(${r(diameter)} ${r(depth)})`,
run: ({ diameter, depth, counterBoreDiameter, counterBoreDepth, countersinkDiameter, countersinkAngle, }, 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);
let primaryHole = new oc.BRepPrimAPI_MakeCylinder_3(cylinderOrientationAndLocation, diameter, depth,);
//let myBody = new oc.BRepPrimAPI_Make
const aRes = new oc.TopoDS_Compound();
const aBuilder = new oc.BRep_Builder();
aBuilder.MakeCompound(aRes);
aBuilder.Add(aRes, primaryHole.Shape());
const mobject = new MBrepShell(occ2brep(aRes, ctx.occService.occContext));
return {
consumed: [],
created: [mobject]
};
},
schema: {
diameter: {
type: 'number',
defaultValue: 10,
label: 'diameter'
},
depth: {
type: 'number',
defaultValue: 100,
label: 'depth'
},
counterBoreDiameter: {
type: 'number',
defaultValue: 200,
label: 'diameter'
},
counterBoreDepth: {
type: 'number',
defaultValue: 280,
label: 'counterBoreDepth'
},
countersinkDiameter: {
type: 'number',
defaultValue: 200,
label: 'countersinkDiameter'
},
countersinkAngle: {
type: 'number',
defaultValue: 90,
label: 'Countersink Angle'
},
}
}

View file

@ -10,42 +10,43 @@ export default {
icon,
info: 'primitive_cone',
mutualExclusiveFields: [],
paramsInfo: ({ diameter, height }) => `(${r(diameter)} ${r(height)})`,
run: ({ diameter, height, }, ctx: ApplicationContext) => {
//const occObj = createcone(diameter, height, ctx.occService.occContext);
paramsInfo: ({ diameter_A, diameter_B, height }) => `(${r(diameter_A)} ${r(diameter_A)} ${r(height)})`,
schema: {
diameter_A: {
type: 'number',
defaultValue: 50,
label: 'Diameter A'
},
diameter_B: {
type: 'number',
defaultValue: 100,
label: 'Diameter B'
},
height: {
type: 'number',
defaultValue: 200,
label: 'height'
},
},
run: ({ diameter_A, diameter_B, height, }, ctx: ApplicationContext) => {
const oc = ctx.occService.occContext;
const myLocation = new oc.gp_Pnt_3(0, 0, 0);
const coneCenterline = oc.gp.DZ();
const coneOrientationAndLocation = new oc.gp_Ax2_3(myLocation, coneCenterline);
let myBody = new oc.BRepPrimAPI_MakeCone_1(10,20,100);
//let myBody = new oc.BRepPrimAPI_Make
let myBody = new oc.BRepPrimAPI_MakeCone_1(diameter_A, diameter_B, height);
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'
},
}
}