added multi face/multi body shell opperation.

This commit is contained in:
Mike Molinari 2022-02-17 00:34:05 +00:00 committed by Val Erastov
parent b71f4dd9ab
commit a2acb1ec00
3 changed files with 87 additions and 1 deletions

View file

@ -0,0 +1,84 @@
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";
interface ShellParams {
thickness: number;
faces: [MFace];
}
const ShellOperation: MDFCommand<ShellParams> = {
id: 'shell_tool',
label: 'Shell',
icon: 'img/cad/Shell',
info: 'Shells 2D sketch',
paramsInfo: ({ thickness }) => `(${r(thickness)})`,
run: (params: ShellParams, ctx: ApplicationContext) => {
console.log(params);
let occ = ctx.occService;
const oci = occ.commandInterface;
var bodiesToShell = [];
var returnObject = {
consumed: [],
created: []
};
//add all the edges and size to seperate arrays for each shell that edges are selected from
params.faces.forEach((face) => {
if (!returnObject.consumed.includes(face.shell)) {
returnObject.consumed.push(face.shell);
bodiesToShell[face.shell.id] = [];
}
bodiesToShell[face.shell.id].push(face);
});
//perform the opperations on each of the bodies.
Object.keys(bodiesToShell).forEach((shellToOpperateOnName) => {
var shellToOpperateOn = bodiesToShell[shellToOpperateOnName];
var newShellName = shellToOpperateOnName + "f";
console.log(shellToOpperateOn);
var bodyToPerformShellOpperationOn = shellToOpperateOn[0].shell;
oci.offsetshape(newShellName, bodyToPerformShellOpperationOn , params.thickness, "1.e-3", ...shellToOpperateOn)
returnObject.created.push(occ.io.getShell(newShellName));
});
console.log(returnObject);
return returnObject;
},
form: [
{
type: 'number',
name: 'thickness',
label: 'thickness',
defaultValue: 5,
},
{
type: 'selection',
name: 'faces',
capture: [EntityKind.FACE],
label: 'faces',
multi: true,
defaultValue: {
usePreselection: true,
preselectionIndex: 0
},
},
],
}
export default ShellOperation;

View file

@ -8,6 +8,7 @@ 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';
import ShellOperation from './features/shell_tool/shell.operation';
export default {
@ -23,5 +24,6 @@ export default {
fillet_tool,
RevolveOperation,
boolean_tool,
ShellOperation,
]
}

View file

@ -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", "Revolve", "-", "boolean_tool",
"EXTRUDE", "Revolve", "-", "boolean_tool", "shell_tool",
"primitive_cylinder", "primitive_box", "primitive_cone", "primitive_sphere", "primitive_torus", "hole_tool",
"fillet_tool"];