mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 08:25:19 +01:00
Object info command to get volume and edge length
This commit is contained in:
parent
ead9e7773f
commit
409dcfb8a8
3 changed files with 77 additions and 44 deletions
|
|
@ -0,0 +1,71 @@
|
|||
import {MShell} from "cad/model/mshell";
|
||||
import {ApplicationContext} from "cad/context";
|
||||
import {EntityKind} from "cad/model/entities";
|
||||
import {ActionDefinition} from "cad/actions/actionSystemBundle";
|
||||
import { MEdge } from "cad/model/medge";
|
||||
|
||||
|
||||
interface GetInfoParams {
|
||||
targetBody: MShell | MEdge;
|
||||
}
|
||||
|
||||
export const GetInfo: any = {
|
||||
id: 'GET_INFO',
|
||||
label: 'OBJECT INFO',
|
||||
icon: 'img/cad/extrude',
|
||||
info: 'extrudes 2D sketch',
|
||||
path:__dirname,
|
||||
run: (params: GetInfoParams, ctx: ApplicationContext) => {
|
||||
console.log("this is it", this)
|
||||
const occ = ctx.occService;
|
||||
const oci = occ.commandInterface;
|
||||
|
||||
const targetBody = params.targetBody;
|
||||
|
||||
let resultingMessage = "";
|
||||
|
||||
|
||||
if (targetBody.TYPE === EntityKind.EDGE){
|
||||
resultingMessage = "Edge Length = "+ targetBody.brepEdge.curve.impl.verb.length().toFixed(4);
|
||||
}
|
||||
if (targetBody.TYPE === EntityKind.SHELL){
|
||||
let listOfOutputs = [];
|
||||
const out_old = out;
|
||||
out = function(msg) {
|
||||
listOfOutputs.push(msg);
|
||||
//alert(JSON.stringify(msg));
|
||||
out_old(msg);
|
||||
}
|
||||
|
||||
oci.vprops(params.targetBody);
|
||||
|
||||
out = out_old;
|
||||
|
||||
|
||||
const resultingVolumeArray = listOfOutputs.filter(function (str) { return str.includes("Mass") });
|
||||
resultingMessage = "Volume = " + resultingVolumeArray[0].trim().replace(' ', '').replace("Mass:","").trim();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
throw {userMessage: resultingMessage};
|
||||
return;
|
||||
},
|
||||
|
||||
|
||||
|
||||
form: [
|
||||
{
|
||||
type: 'selection',
|
||||
name: 'targetBody',
|
||||
capture: [EntityKind.SHELL, EntityKind.EDGE],
|
||||
label: 'Body',
|
||||
multi: false,
|
||||
defaultValue: {
|
||||
usePreselection: true,
|
||||
preselectionIndex: 0
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
import {MShell} from "cad/model/mshell";
|
||||
import {ApplicationContext} from "cad/context";
|
||||
import {EntityKind} from "cad/model/entities";
|
||||
import {ActionDefinition} from "cad/actions/actionSystemBundle";
|
||||
|
||||
|
||||
interface getVolumeParams {
|
||||
targetBody: MShell;
|
||||
}
|
||||
|
||||
export const GetVolume: any = {
|
||||
id: 'GET_VOLUME',
|
||||
label: 'VOLUME',
|
||||
icon: 'img/cad/extrude',
|
||||
info: 'extrudes 2D sketch',
|
||||
path:__dirname,
|
||||
run: (params: getVolumeParams, ctx: ApplicationContext) => {
|
||||
|
||||
const occ = ctx.services.OCCService;
|
||||
const oci = occ.commandInterface;
|
||||
|
||||
alert();
|
||||
|
||||
return;
|
||||
},
|
||||
|
||||
|
||||
|
||||
form: [
|
||||
{
|
||||
type: 'selection',
|
||||
name: 'targetBody',
|
||||
capture: [EntityKind.SHELL],
|
||||
label: 'Body',
|
||||
multi: false,
|
||||
defaultValue: {
|
||||
usePreselection: true,
|
||||
preselectionIndex: 0
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
@ -23,6 +23,8 @@ import {DeleteBodyOperation} from "./features/deleteBody/deleteBody.operation";
|
|||
import {DefeatureRemoveFaceOperation} from "./features/defeatureRemoveFace/defeatureRemoveFace.operation";
|
||||
import { WireLineOperation } from "./features/wireLine/wireLine";
|
||||
//imports of action type commands
|
||||
import {GetInfo} from "./actions/getInfo/getInfo.action";
|
||||
//import workbench icon
|
||||
import {GiCubes} from "react-icons/gi";
|
||||
|
||||
|
||||
|
|
@ -51,9 +53,11 @@ export const ModelerWorkspace: WorkbenchConfig = {
|
|||
DeleteBodyOperation,
|
||||
DefeatureRemoveFaceOperation,
|
||||
WireLineOperation,
|
||||
|
||||
GetInfo,
|
||||
],
|
||||
actions: [
|
||||
// GetVolume,
|
||||
//GetVolume,
|
||||
],
|
||||
ui: {
|
||||
toolbar: [
|
||||
|
|
@ -69,7 +73,7 @@ export const ModelerWorkspace: WorkbenchConfig = {
|
|||
|
||||
"CYLINDER", "BOX", "CONE", "SPHERE", "TORUS", "-",
|
||||
|
||||
"HOLE_TOOL", "-", 'GET_VOLUME', "IMPORT_MODEL", "DELETE_BODY", "-",
|
||||
"HOLE_TOOL", "-", 'GET_INFO', "IMPORT_MODEL", "DELETE_BODY", "-",
|
||||
|
||||
"WIRE_LINE"
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue